SHOW:
|
|
- or go back to the newest paste.
1 | - | --Unnamed message forwarding |
1 | + | --Unnamed message forwarding |
2 | - | --This is WTFPL, just change the name, OK? |
2 | + | --This is WTFPL, just change the name, OK? |
3 | - | --Version 1.0 - this means it's the most broken yet |
3 | + | --Version 1.0 - this means it's the most broken yet |
4 | - | --I commented out all they annoying text outputs. You people love me. |
4 | + | --I commented out all they annoying text outputs. You people love me. |
5 | - | |
5 | + | |
6 | - | local component = require "component" |
6 | + | local component = require "component" |
7 | - | local event = require "event" |
7 | + | local event = require "event" |
8 | - | local text = require "text" |
8 | + | local text = require "text" |
9 | - | local shell = require "shell" |
9 | + | local shell = require "shell" |
10 | - | local serial = require "serialization" |
10 | + | local serial = require "serialization" |
11 | - | |
11 | + | |
12 | - | modem = component.modem |
12 | + | modem = component.modem |
13 | - | local modemPower = 400 |
13 | + | local modemPower = 400 |
14 | - | local msgBuffer = {} |
14 | + | local msgBuffer = {} |
15 | - | nodeAddr = "derp3" |
15 | + | nodeAddr = "derp3" |
16 | - | local magicNumbers = {} |
16 | + | local magicNumbers = {} |
17 | - | |
17 | + | |
18 | - | local function extractPath(path) |
18 | + | local function extractPath(path) |
19 | - | if path:find("!") ~= nil then |
19 | + | if path:find("!") ~= nil then |
20 | - | return path:sub(1,path:find("!")-1), path:sub(path:find("!")+1,path:len()) |
20 | + | return path:sub(1,path:find("!")-1), path:sub(path:find("!")+1,path:len()) |
21 | - | else |
21 | + | else |
22 | - | return path, path |
22 | + | return path, path |
23 | - | end |
23 | + | end |
24 | - | end |
24 | + | end |
25 | - | |
25 | + | |
26 | - | function recvMsg(name,user,message) |
26 | + | function recvMsg(name,user,message) |
27 | - | local f = io.open("/home/"..user.."/mail/"..name,"ab") |
27 | + | local f = io.open("/home/"..user.."/mail/"..name,"ab") |
28 | - | if f ~= nil then |
28 | + | if f ~= nil then |
29 | - | f:write(message) |
29 | + | f:write(message) |
30 | - | f:close() |
30 | + | f:close() |
31 | - | end |
31 | + | end |
32 | - | end |
32 | + | end |
33 | - | |
33 | + | |
34 | - | local function sks_send(path,retPath,name,user,message) |
34 | + | local function sks_send(path,retPath,name,user,message) |
35 | - | local toAddr, contPath = extractPath(path) |
35 | + | local toAddr, contPath = extractPath(path) |
36 | - | --print(toAddr,contPath) |
36 | + | --print(toAddr,contPath) |
37 | - | modem.broadcast(42,toAddr,contPath,retPath,name,user,message,math.random(0,65535)) |
37 | + | modem.broadcast(42,toAddr,contPath,retPath,name,user,message,math.random(0,65535)) |
38 | - | end |
38 | + | end |
39 | - | |
39 | + | |
40 | - | local function store(path,retPath,name,user,message) |
40 | + | local function store(path,retPath,name,user,message) |
41 | - | table.insert(msgBuffer,{path,retPath,name,user,message}) |
41 | + | table.insert(msgBuffer,{path,retPath,name,user,message}) |
42 | - | end |
42 | + | end |
43 | - | |
43 | + | |
44 | - | function msgListener(_,_,from,port,_,toAddr,path,retPath,name,user,message,magNum) |
44 | + | function msgListener(_,_,from,port,_,toAddr,path,retPath,name,user,message,magNum) |
45 | - | local hBR = false |
45 | + | local hBR = false |
46 | - | for i = 1, #magicNumbers do |
46 | + | for i = 1, #magicNumbers do |
47 | - | if magicNumbers[i] == magNum then |
47 | + | if magicNumbers[i] == magNum then |
48 | - | hBR = true |
48 | + | hBR = true |
49 | - | end |
49 | + | end |
50 | - | end |
50 | + | end |
51 | - | if not hBR then |
51 | + | if not hBR then |
52 | - | if port == 42 and path ~= nodeAddr and toAddr == nodeAddr then |
52 | + | if port == 42 and path ~= nodeAddr and toAddr == nodeAddr then |
53 | - | store(path,retPath,name,user,message) |
53 | + | store(path,retPath,name,user,message) |
54 | - | --print "routed" |
54 | + | --print "routed" |
55 | - | elseif port == 42 and path == nodeAddr and toAddr == nodeAddr then |
55 | + | elseif port == 42 and path == nodeAddr and toAddr == nodeAddr then |
56 | - | --print "Mail recieved!" |
56 | + | --print "Mail recieved!" |
57 | - | recvMsg(name,user,message) |
57 | + | recvMsg(name,user,message) |
58 | - | end |
58 | + | end |
59 | - | end |
59 | + | end |
60 | - | end |
60 | + | end |
61 | - | |
61 | + | |
62 | - | local function sendTimer() |
62 | + | local function sendTimer() |
63 | - | --print "Send timer activated" |
63 | + | --print "Send timer activated" |
64 | - | if #msgBuffer > 0 then |
64 | + | if #msgBuffer > 0 then |
65 | - | for i = 1, #msgBuffer do |
65 | + | for i = 1, #msgBuffer do |
66 | - | sks_send(msgBuffer[i][1],msgBuffer[i][2],msgBuffer[i][3],msgBuffer[i][4],msgBuffer[i][5]) |
66 | + | sks_send(msgBuffer[i][1],msgBuffer[i][2],msgBuffer[i][3],msgBuffer[i][4],msgBuffer[i][5]) |
67 | - | end |
67 | + | end |
68 | - | msgBuffer = {} |
68 | + | msgBuffer = {} |
69 | - | --print "Messages sent!" |
69 | + | --print "Messages sent!" |
70 | - | else |
70 | + | else |
71 | - | --print "No messages sent!" |
71 | + | --print "No messages sent!" |
72 | - | end |
72 | + | end |
73 | - | end |
73 | + | end |
74 | - | |
74 | + | |
75 | - | local function loadConfig() |
75 | + | local function loadConfig() |
76 | - | local f = io.open("/etc/net.cfg") |
76 | + | local f = io.open("/etc/net.cfg") |
77 | - | local configTab = serial.unserialize(f:read("*a")) |
77 | + | local configTab = serial.unserialize(f:read("*a")) |
78 | - | f:close() |
78 | + | f:close() |
79 | - | nodeAddr = configTab.nodeName |
79 | + | nodeAddr = configTab.nodeName |
80 | - | modemPower = configTab.modemPower |
80 | + | modemPower = configTab.modemPower |
81 | - | end |
81 | + | end |
82 | - | |
82 | + | |
83 | - | local function setup() |
83 | + | local function setup() |
84 | - | modem.open(42) |
84 | + | modem.open(42) |
85 | - | --loadConfig() |
85 | + | --loadConfig() |
86 | - | --pcall(modem.setStrength(modemPower)) |
86 | + | --pcall(modem.setStrength(modemPower)) |
87 | - | print("netnode.d v1.0 running; nodename: " .. nodeAddr) |
87 | + | print("netnode.d v1.0 running; nodename: " .. nodeAddr) |
88 | - | event.listen("modem_message",msgListener) |
88 | + | event.listen("modem_message",msgListener) |
89 | - | event.timer(1,sendTimer,math.huge) |
89 | + | event.timer(1,sendTimer,math.huge) |
90 | - | sendTimer() |
90 | + | sendTimer() |
91 | - | end |
91 | + | end |
92 | - | |
92 | + | |
93 | setup() |