Advertisement
johnnic431

WIP_ChatCom_Server

Jun 3rd, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.36 KB | None | 0 0
  1. local modem = peripheral.wrap("right")
  2. local monitor = peripheral.wrap("top")
  3. local tArgs = { ... }
  4. RNPR = shell.getRunningProgram()
  5. modemC = tonumber(tArgs[1])
  6. adminPass = tArgs[2]
  7. serverName = tArgs[3]
  8. shell.run("clear")
  9. clientSlot1 = false
  10. clientSlot2 = false
  11. clientSlot3 = false
  12. clientSlot4 = false
  13. adminSlot1 = false
  14. clientSlot1Coords = {0, 0, 0}
  15. clientSlot2Coords = {0, 0, 0}
  16. clientSlot3Coords = {0, 0, 0}
  17. clientSlot4Coords = {0, 0, 0}
  18. clientSlot1Nick = " "
  19. clientSlot2Nick = " "
  20. clientSlot3Nick = " "
  21. clientSlot4Nick = " "
  22. adminSlot1Nick = " "
  23. modem.open(2919)
  24. curr = 0
  25. totalOpenSlots = 4
  26. bannedNames = {"Guest", "Bot", "Notch", "Jeb", "Nil", " ", "  ", "   "}
  27. Ma_B_N = 4
  28. Mi_B_N = 9
  29. R_C_N = 18
  30. B_B_N = 84
  31. function modemT(Chn, Str)
  32.     modem.transmit(modemC, tonumber(Chn), Str)
  33. end
  34. function mR()
  35.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  36. end
  37. function drawScreen()
  38.     shell.run("monitor top clear")
  39.     monitor.setCursorPos(1,1)
  40.     monitor.write("Client Slot 1 Nick: "..clientSlot1Nick)
  41.     monitor.setCursorPos(1,2)
  42.     monitor.write("Client Slot 2 Nick: "..clientSlot2Nick)
  43.     monitor.setCursorPos(1,3)
  44.     monitor.write("Client Slot 3 Nick: "..clientSlot3Nick)
  45.     monitor.setCursorPos(1,4)
  46.     monitor.write("Client Slot 4 Nick: "..clientSlot4Nick)
  47.     monitor.setCursorPos(1,5)
  48.     monitor.write("Admin1 Nick: "..adminSlot1Nick)
  49.     monitor.setCursorPos(1, 12)
  50.     monitor.write("Version: IRC Beta "..Ma_B_N.."."..Mi_B_N.."."..R_C_N.."."..B_B_N)
  51. end
  52. curr = 1
  53. function checkNames()
  54.     print("Number: "..curr)
  55.     while curr <= #bannedNames do
  56.         if message == bannedNames[curr] then
  57.             v = 1
  58.         end
  59.         curr = curr + 1
  60.     end
  61.     print("Done")
  62. end
  63. drawScreen()
  64.  
  65. if #tArgs < 3 then
  66.     print("Usage: "..RNPR.." <port> <adminPassword> <serverName>")
  67.     return
  68. end
  69. if modemC > 5999 and modemC < 13968 then
  70.     modem.open(65012)
  71.     modem.transmit(65012, modemC, "ChkChn")
  72.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  73.     if message == "chnOpn" then
  74.         modem.open(modemC)
  75.     else
  76.         print("This channel is in use. Press any key to exit.")
  77.         os.pullEvent("char")
  78.         return
  79.     end
  80. else
  81.     print("Number not in range 6000-7974, 8001-9976, 10001-11962, 12001-13968. Press any key to exit.")
  82.     return
  83.     term.isColour()
  84. end
  85. while true do
  86.     print("Startyz")
  87.     if adminSlot1 then
  88.         AO = true
  89.     end
  90.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  91.     checkNames()
  92.     if replyChannel == 12123 then
  93.         if v == 0 then
  94.             if clientSlot1 == false then
  95.                 clientSlot1Nick = message
  96.                 clientSlot1 = true
  97.                 modem.transmit(modemC, 1, "/accept")
  98.                 modem.transmit(modemC, modemC, "User "..clientSlot1Nick.." has joined.")
  99.                 totalOpenSlots = totalOpenSlots - 1
  100.                 drawScreen()
  101.             elseif clientSlot2 == false then
  102.                 clientSlot2Nick = message
  103.                 clientSlot2 = true
  104.                 modem.transmit(modemC, 2, "/accept")
  105.                 modem.transmit(modemC, modemC, "User "..clientSlot2Nick.." has joined.")
  106.                 totalOpenSlots = totalOpenSlots - 1
  107.                 drawScreen()
  108.             elseif clientSlot3 == false then
  109.                 clientSlot3Nick = message
  110.                 clientSlot3 = true
  111.                 modem.transmit(modemC, 3, "/accept")
  112.                 modem.transmit(modemC, modemC, "User "..clientSlot3Nick.." has joined.")
  113.                 totalOpenSlots = totalOpenSlots - 1
  114.                 drawScreen()
  115.             elseif clientSlot4 == false then
  116.                 clientSlot4Nick = message
  117.                 clientSlot4 = true
  118.                 modem.transmit(modemC, 4, "/accept")
  119.                 modem.transmit(modemC, modemC, "User "..clientSlot4Nick.." has joined.")
  120.                 totalOpenSlots = totalOpenSlots - 1
  121.                 drawScreen()
  122.             else
  123.                 modemT(modemC, "/full")
  124.             end
  125.         elseif v == 1 then
  126.             modemT(modemC, "Banned name attempted connect.")
  127.         else
  128.             modem.transmit(modemC, modemC, "/full")
  129.         end
  130.     elseif replyChannel == 12124 and message == adminPass then
  131.         if adminSlot1 == false then
  132.             local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  133.             adminSlot1 = true
  134.             adminSlot1Nick = message
  135.             modem.transmit(modemC, 5, "/accept")
  136.             drawScreen()
  137.         else
  138.             modem.transmit(modemC, 5, "/ADFull")
  139.         end
  140.     elseif message == "/ping" then
  141.         modem.transmit(2919, modemC, serverName)
  142.     elseif replyChannel == 12125 and AO then
  143.         if message == "1" then
  144.             clientSlot1 = false
  145.             modem.transmit(modemC, modemC, "User "..clientSlot1Nick.." disconnected. [Connection ended.]")
  146.             totalOpenSlots = totalOpenSlots - 1
  147.             clientSlot1Nick = " "
  148.             drawScreen()
  149.         elseif message == "2" then
  150.             clientSlot2 = false
  151.             modem.transmit(modemC, modemC, "User "..clientSlot2Nick.." disconnected. [Connection ended.]")
  152.             totalOpenSlots = totalOpenSlots - 1
  153.             clientSlot2Nick = " "
  154.             drawScreen()
  155.         elseif message == "3" then
  156.             clientSlot3 = false
  157.             modem.transmit(modemC, modemC, "User "..clientSlot3Nick.." disconnected. [Connection ended.]")
  158.             totalOpenSlots = totalOpenSlots - 1
  159.             clientSlot3Nick = " "
  160.             drawScreen()
  161.         elseif message == "4" then
  162.             clientSlot4 = false
  163.             modem.transmit(modemC, modemC, "User "..clientSlot4Nick.." disconnected. [Connection ended.]")
  164.             totalOpenSlots = - 1
  165.             clientSlot4Nick = " "
  166.             drawScreen()
  167.         elseif message == adminPass then
  168.             adminSlot1 = false
  169.             modem.transmit(modemC, modemC, "User "..adminSlot1Nick.." disconnected. [Connection ended.]")
  170.             adminSlot1Nick = " "
  171.             drawScreen()
  172.         else
  173.         end
  174.     elseif replyChannel == 50148 and message == adminPass and AO then
  175.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  176.         if message == "/kick" then
  177.             if replyChannel == 1 then
  178.                 local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  179.                 clientSlot1 = false
  180.                 clientSlot1Nick = " "
  181.                 modem.transmit(modemC, modemC, "User "..clientSlot1Nick.." disconnected. [User kicked: "..message..".]")
  182.                 drawScreen()
  183.             elseif replyChannel == 2 then
  184.                 local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  185.                 clientSlot2 = false
  186.                 clientSlot2Nick = " "
  187.                 modem.transmit(modemC, modemC, "User "..clientSlot2Nick.." disconnected. [User kicked: "..message..".]")
  188.                 drawScreen()
  189.             elseif replyChannel == 3 then
  190.                 local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  191.                 clientSlot3 = false
  192.                 clientSlot3Nick = " "
  193.                 modem.transmit(modemC, modemC, "User "..clientSlot3Nick.." disconnected. [User kicked: "..message..".]")
  194.                 drawScreen()
  195.             elseif replyChannel == 4 then
  196.                 local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  197.                 clientSlot4 = false
  198.                 clientSlot4Nick = " "
  199.                 modem.transmit(modemC, modemC, "User "..clientSlot4Nick.." disconnected. [User kicked: "..message..".]")
  200.                 drawScreen()
  201.             end
  202.         elseif message == "/ban" then
  203.             if replyChannel == 1 then
  204.                 clientSlot1 = false
  205.                 table.insert(bannedNames, clientSlot1Nick)
  206.                 clientSlot1Nick = " "
  207.                 modem.transmit(modemC, modemC, "User "..clientSlot1Nick.." foreplyChanneled disconnect. [User banned: "..message..".]")
  208.                 drawScreen()
  209.             elseif replyChannel == 2 then
  210.                 clientSlot2 = false
  211.                 table.insert(bannedNames, clientSlot2Nick)
  212.                 clientSlot2Nick = " "
  213.                 modem.transmit(modemC, modemC, "User "..clientSlot2Nick.." foreplyChanneled disconnect. [User banned: "..message..".]")
  214.                 drawScreen()
  215.             elseif replyChannel == 3 then
  216.                 clientSlot3 = false
  217.                 table.insert(bannedNames, clientSlot3Nick)
  218.                 clientSlot3Nick = " "
  219.                 modem.transmit(modemC, modemC, "User "..clientSlot3Nick.." foreplyChanneled disconnect. [User banned: "..message..".]")
  220.                 drawScreen()
  221.             elseif replyChannel == 4 then
  222.                 clientSlot4 = false
  223.                 table.insert(bannedNames, clientSlot4Nick)
  224.                 clientSlot4Nick = " "
  225.                 modem.transmit(modemC, modemC, "User "..clientSlot4Nick.." foreplyChanneled disconnect. [User banned: "..message..".]")
  226.                 drawScreen()
  227.             end
  228.         elseif message == "/restart" then
  229.             h = fs.open("SRestart", "w")
  230.             h.write("shell.run(\""..RNPR.." "..modemC.." "..adminPass.." "..serverName.."\"")
  231.             modemT(5000, "Saving banned names...")
  232.             sleep(2)
  233.             modemT(5000, "Disconnecting users...")
  234.             clientSlot1 = false
  235.             clientSlot1Nick = " "
  236.             clientSlot2 = false
  237.             clientSlot2Nick = " "
  238.             clientSlot3 = false
  239.             clientSlot3Nick = " "
  240.             clientSlot4 = false
  241.             clientSlot4Nick = " "
  242.             modemT(5000, "Disconnected users. Full reboot initializing...")
  243.             shell.run("SRestart")
  244.             return
  245.         elseif message == "/shutdown" then
  246.             modemT(5000, "Saving banned names...")
  247.             sleep(2)
  248.             modemT(5000, "Disconnecting users...")
  249.             clientSlot1 = false
  250.             clientSlot1Nick = " "
  251.             clientSlot2 = false
  252.             clientSlot2Nick = " "
  253.             clientSlot3 = false
  254.             clientSlot3Nick = " "
  255.             clientSlot4 = false
  256.             clientSlot4Nick = " "
  257.             drawScreen()
  258.             modemT(5000, "Disconnected users. Full shutdown initializing...")
  259.             os.shutdown()
  260.             return
  261.         end
  262.     else
  263.         if replyChannel == 1 and clientSlot1 == true then
  264.             modem.transmit(modemC, 1, clientSlot1Nick..": "..message)
  265.             print(clientSlot1Nick..": "..message)
  266.         elseif replyChannel == 2 and clientSlot2 == true then
  267.             modem.transmit(modemC, 2, clientSlot2Nick..": "..message)
  268.             print(clientSlot2Nick..": "..message)
  269.         elseif replyChannel == 3 and clientSlot3 == true then
  270.             modem.transmit(modemC, 3, clientSlot3Nick..": "..message)
  271.             print(clientSlot3Nick..": "..message)
  272.         elseif replyChannel == 4 and clientSlot4 == true then
  273.             modem.transmit(modemC, 4, clientSlot4Nick..": "..message)
  274.             print(clientSlot4Nick..": "..message)
  275.         elseif replyChannel == 65 and adminSlot1 == true and message == adminPass then
  276.             local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  277.             modem.transmit(modemC, 65, adminSlot1Nick..": "..message)
  278.             print(adminSlot1Nick..": "..message)
  279.         elseif replyChannel == 66 and adminSlot2 == true and message == adminPass then
  280.             local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  281.             modem.transmit(modemC, 65, adminSlot2Nick..": "..message)
  282.             print(adminSlot2Nick..": "..message)
  283.         else
  284.             modem.transmit(modemC, modemC, "Unknown entity: "..message)
  285.             print("Unknown entity: "..message)
  286.         end
  287.     end
  288.     replyChannel = 0
  289.     message = " "
  290.     curr = 1
  291. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement