Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local printHelp = function()
- print("Usage: mpc <modem> <device> <command> [parm]")
- print(" modem = modem side")
- print(" device = 'client'/'server'")
- print(" Client Commands:")
- print(" - spoof_id <sPort> <uPort>")
- print(" - get_port <sPort> <uID>")
- print(" - get_server_port <uPort>")
- print(" - get_name <sPort> <uPort> <uID>")
- print(" - set_name <sPort> <uPort> <uID> <name>")
- print(" - kick <sPort> <uPort> <uID>")
- print(" - logout <sPort> <uPort> <uID>")
- print(" - public_write <sPort> <uPort> <uID> <text>")
- print(" - private_write <sPort> <uPort> <uID> <text>")
- print(" - user_list <sPort> <uPort> <uID> <uName>")
- print(" Server Commands:")
- print(" - get_port <sName>")
- print(" - get_all")
- print(" - dos <sPort>")
- print(" - user_overflow <sPort>")
- print(" - get_all_uid <sPort>")
- end
- local modem
- if #tArgs >= 2 then
- modem = tArgs[1]
- else
- if #tArgs == 2 then
- error("Modem not found")
- else
- printHelp()
- end
- end
- if peripheral.getType(modem) ~= "modem" then
- error("Modem not found")
- else
- peripheral.call(modem, "closeAll")
- end
- local command_list = {
- server = {
- caget_port = 1,
- get_port = function(sName)
- rednet.open(modem)
- local hname = rednet.lookup("chat", sName)
- if hname then
- return hname
- else
- term.setTextColor(colors.red)
- return "Host not found"
- end
- end,
- caget_all = 0,
- get_all = function()
- rednet.open(modem)
- local hname = { rednet.lookup("chat") }
- if hname then
- table.sort(hname)
- return table.unpack(hname)
- else
- term.setTextColor(colors.red)
- return "No hosts found"
- end
- end,
- cados = 1,
- dos = function(sPort)
- -- Maybe in some time
- end,
- causer_overflow = 1,
- user_overflow = function(sPort)
- -- Maybe in some time
- end,
- caget_all_uid = 1,
- get_all_uid = function(sPort)
- sPort = tonumber(sPort)
- local tUser = { }
- local modem = peripheral.wrap(modem)
- modem.open(sPort)
- local timer = os.startTimer(15)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == sPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.nUserID) == "number"
- then
- local doSave = true
- for _, id in pairs(tUser) do
- if id == message.message.nUserID then
- doSave = false
- break
- end
- end
- if doSave then
- table.insert(tUser, message.message.nUserID)
- end
- elseif event == "timer" and data == timer then
- break
- end
- end
- if #tUser > 0 then
- return table.unpack( tUser )
- else
- term.setTextColor(colors.red)
- return "No users found"
- end
- end
- },
- client = {
- caspoof_id = 2,
- spoof_user_id = function(sPort, uPort)
- uPort = tonumber(uPort)
- sPort = tonumber(sPort)
- local modem = peripheral.wrap(modem)
- modem.open(uPort)
- local timer = os.startTimer(15)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == uPort
- and reply == sPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.nUserID) == "number"
- then
- return message.message.nUserID
- elseif event == "timer" and data == timer then
- term.setTextColor(colors.red)
- return "User not found"
- end
- end
- end,
- caget_port = 2,
- get_port = function(sPort, uID)
- sPort = tonumber(sPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(sPort)
- local timer = os.startTimer(15)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == sPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.nUserID) == "number"
- and message.message.nUserID == uID
- then
- return reply
- elseif event == "timer" and data == timer then
- term.setTextColor(colors.red)
- return "Unable to get port"
- end
- end
- end,
- caget_server_port = 1,
- get_server_port = function(uPort)
- end,
- caget_name = 3,
- get_name = function(sPort, uPort, uID)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(uPort)
- modem.open(sPort)
- modem.transmit(sPort, uPort,
- {
- nRecipient = sPort,
- message = {
- sType = "chat",
- sText = "",
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- local timer = os.startTimer(1)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == uPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.sText) == "string"
- then
- return string.match(message.message.sText, "^<(.+)>")
- elseif event == "timer" and data == timer then
- term.setTextColor(colors.red)
- return "User not found"
- end
- end
- end,
- caset_name = 4,
- set_name = function(sPort, uPort, uID, uName)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(sPort)
- modem.open(uPort)
- modem.transmit(sPort, uPort,
- {
- nRecipient = sPort,
- message = {
- sType = "chat",
- sText = "/nick "..uName,
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- os.startTimer(1)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == uPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.sText) == "string"
- and string.match(message.message.sText, "^*.+is now known as.+$")
- then
- return "Successfully changed name to '"..uName.."'"
- elseif event == "timer" and data == timer then
- term.setTextColor(colors.red)
- return "Unable to change name"
- end
- end
- end,
- cakick = 3,
- kick = function(sPort, uPort, uID)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(sPort)
- modem.transmit(uPort, sPort,
- {
- nRecipient = uPort,
- message = {
- sType = "kick",
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- return "Kick was send"
- end,
- calogout = 3,
- logout = function(sPort, uPort, uID)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(uPort)
- modem.transmit(sPort, uPort,
- {
- nRecipient = sPort,
- message = {
- sType = "logout",
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- return "Logout was send"
- end,
- capublic_write = 4,
- public_write = function(sPort, uPort, uID, text)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(uPort)
- modem.open(sPort)
- modem.transmit(sPort, uPort,
- {
- nRecipient = sPort,
- message = {
- sType = "chat",
- sText = text,
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- os.startTimer(1)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == uPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.sText) == "string"
- and string.match(message.message.sText, ".+> "..text)
- then
- return "Successfully send message"
- elseif event == "timer" and data == timer then
- term.setTextColor(colors.red)
- return "Unable to send message"
- end
- end
- end,
- caprivate_write = 4,
- private_write = function(sPort, uPort, uID, text)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(sPort)
- modem.transmit(uPort, sPort,
- {
- nRecipient = uPort,
- message = {
- sType = "text",
- sText = text,
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- return "Message was send"
- end,
- causer_list = 4,
- user_list = function(sPort, uPort, uID, uName)
- sPort = tonumber(sPort)
- uPort = tonumber(uPort)
- uID = tonumber(uID)
- local modem = peripheral.wrap(modem)
- modem.open(uPort)
- modem.open(sPort)
- modem.transmit(sPort, uPort,
- {
- nRecipient = sPort,
- message = {
- sType = "chat",
- sText = "/users",
- nUserID = uID
- },
- nMessageID = math.random(1, 2147483647),
- sProtocol = "chat"
- })
- os.startTimer(1)
- while true do
- local event, data, port, reply, message = os.pullEvent()
- if event == "modem_message"
- and port == uPort
- and type(message) == "table"
- and type(message.message) == "table"
- and type(message.message.sText) == "string"
- and string.match(message.message.sText, "^\* .*"..uName..".*$")
- then
- return string.match(message.message.sText, "^\* (.*"..uName..".*)$")
- elseif event == "timer" and data == timer then
- term.setTextColor(colors.red)
- return "Unable to receive user list"
- end
- end
- end,
- }
- }
- if #tArgs == 2 and tArgs[2] == "load-lib" then
- return command_list
- end
- if #tArgs < 3 then
- return printHelp()
- end
- local device = tArgs[2]
- local command = tArgs[3]
- local param = { }
- for i = 4, #tArgs do
- table.insert(param, tArgs[i])
- end
- if command_list[device]
- and command_list[device][command]
- and #tArgs - 3 == command_list[device]["ca"..command]
- then
- term.setTextColor(colors.lime)
- print( command_list[device][command](table.unpack( param )) )
- else
- return printHelp()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement