Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modems = { }
- ports = { }
- local old_message
- -- "", { a = {a = abc},a = abc,a = abc,a = {a ={a = abc},a = abc} }, "", 1
- -- [a] > a:abc; < a:abc; a:abc; [a] > [a] >> a:abc; << a:abc; <
- siit = function(tbl, nd)
- local str = ""
- for i, v in pairs(tbl) do
- if type(v) == "table" then
- str = str.."["..i.."]"..string.rep(">", nd).." "..siit(v, nd + 1)..string.rep("<", nd).." "
- else
- str = str..i..":"..v.."; "
- end
- end
- return str
- end
- client = function()
- if pcall( loadfile("client.cfg") ) then
- local tconfig = loadfile("client.cfg")()
- local native_pullEvent = os.pullEventRaw
- local save_file = false
- local modem_names = false
- if type(tconfig.whitelist) == "table" then
- end
- if type(tconfig.blacklist) == "table" then
- end
- if tconfig.file.save then
- if type(tconfig.file.name) == "string" then
- local savetype = tconfig.file.saveType or "w"
- save_file = true
- -- local file = fs.open(tconfig.fileName, savetype)
- else
- error("fileName in \"client.cfg\" expected", 0)
- end
- else
- term.clear()
- term.setCursorPos(1, 1)
- term.setCursorBlink(false)
- end
- if tconfig.modem.useNames then
- modem_names = tconfig.modem.names
- end
- if tconfig.modem.differentNetworks then
- for i, modem in pairs(modems) do
- for _i, port in pairs(ports) do
- modem.open(port)
- end
- end
- else
- for i=0, math.floor(#ports / 128) do
- for i=1, 128 do
- modems[i + 1].open( i*128 + i )
- end
- end
- end -- ...
- os.pullEventRaw = function(str)
- local tEvent = { native_pullEvent(raw) }
- if tEvent[1] == "modem_message" then
- local message = {}
- if modem_names then
- message["Network"] = modem_names[tEvent[2]]
- end
- message["Port"] = tEvent[3]
- message["ReplyChannel"] = tEvent[4]
- message["Message"] = tEvent[5]
- message["Distance"] = tEvent[6]
- local sMessage = siit( message, 1 )
- if not tconfig["disable_doubleMessageFilter"] then
- if sMessage == old_message then
- return table.unpack(tEvent)
- else
- old_message = sMessage
- end
- end
- do
- local bbreak = false
- local bcont = false
- if tconfig["whitelist"] then
- for i, v in pairs(tconfig.whitelist) do
- if sMessage:find(v) then
- bcont = true
- end
- end
- else
- bcont = true
- end
- if tconfig["blacklist"] then
- for i, v in pairs(tconfig.blacklist) do
- if sMessage:find(v) then
- bbreak = true
- end
- end
- end
- if bbreak or not bcont then
- return table.unpack(tEvent)
- end
- end
- if tconfig.file.save then
- file = fs.open(tconfig.file.name, tconfig.file.saveType)
- file.write(sMessage)
- file.close()
- else
- print(sMessage)
- end
- end
- return table.unpack(tEvent)
- end
- else
- error("Config file \"client.cfg\" expected", 0)
- end
- end
- local server = function()
- if pcall( loadfile("server.cfg") ) then
- local tconfig = loadfile("server.cfg")()
- else
- error("Config file \"server.cfg\" expected", 0)
- end
- end
- for i, v in pairs( peripheral.getNames() ) do
- if peripheral.getType(v) == "modem" then
- table.insert(modems, peripheral.wrap(v))
- modems[#modems].closeAll()
- end
- end
- if pcall( loadfile("ports.n") ) then
- local raw_ports = loadfile("ports.n")()
- for i, v in pairs( raw_ports ) do
- table.insert(ports, tonumber(v))
- end
- else
- error("Port file \"ports.n\" expected", 0)
- end
- do
- local args = { ... }
- if #args == 1 and (args[1] == "server" or args[1] == "client") then
- if #modems == 0 then
- error("Modem expected", 0)
- elseif #ports == 0 then
- error("Portss expected", 0)
- elseif #modems * 128 < #ports then
- error("There cant be opened more PORTS than "..tostring(#modems * 128), 0)
- end
- if args[1] == "server" then
- server()
- elseif args[1] == "client" then
- client()
- end
- else
- printError("Use:")
- printError("spy server or")
- error("spy client", 0)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement