Advertisement
SirMongoose

SirChat [protocol error]

Jul 29th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. --SirChat v1.1.0 -Created by Sir.Mongoose
  2.  
  3. local ex = false
  4. local ID = os.getComputerID()
  5. local cl = false
  6. local line = 3
  7.  
  8. function receive()
  9.     local senderID, message, protocol = rednet.receive("sirchat")
  10.     term.clearLine()
  11.     term.setCursorPos(1,line)
  12.     print("<ID#"..senderID.."> "..(tostring(message)))
  13.     line = line + 1
  14. end
  15.  
  16. function send()
  17.     term.write("<ID#"..ID.."> ")
  18.     local mesg = read()
  19.     if mesg == "/exit" then
  20.         ex = true
  21.         term.clear()
  22.         term.setCursorPos(1,1)
  23.     elseif mesg == "/commands" then
  24.         print("> '/exit' terminates the program.")
  25.         print("> '/clear' clears chat completely.")
  26.         print("> '/connect' connects you to a different ID.")
  27.         print("> '/info' Tells you about SirChat.")
  28.         line = line + 5
  29.     elseif mesg == "/clear" then
  30.         cl = true
  31.     elseif mesg == "/connect" then
  32.         connect()
  33.     elseif mesg == "/info" then
  34.         print("> SirChat was a program made by Sir.Mongoose.")
  35.         print("> SirChat is currently in version 1.1.")
  36.     elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
  37.         rednet.send((tonumber(targetID)), (tostring(mesg)), "sirchat")
  38.         line = line + 1
  39.     end
  40. end
  41.  
  42. function chat()
  43.     term.clear()
  44.     term.setCursorPos(1,1)
  45.     print("**Connected with ComputerID#"..(tostring(targetID)).."**")
  46.     print("**Type '/commands' for the list of commands**")
  47.     while ex == false do
  48.         parallel.waitForAny(receive, send)
  49.         if cl == true then
  50.             term.clear()
  51.             term.setCursorPos(1,1)
  52.             print("**Connected with ComputerID#"..(tostring(targetID)).."**")
  53.             print("**Type '/commands' for the list of commands**")
  54.             line = 3
  55.             cl = false
  56.         end
  57.     end
  58. end
  59.  
  60. function numCheck(a)
  61.   if ((tonumber(a)) == nil) == true then
  62.     return false
  63.   else
  64.     return true
  65.    end
  66. end
  67.  
  68. function connect()
  69.   term.clear()
  70.   term.setCursorPos(1,1)
  71.   print("**Enter the ComputerID you want to connect to**")
  72.   targetID = read()
  73.  
  74.   if numCheck(targetID) == true then
  75.     chat()
  76.   else
  77.     while numCheck(targetID) == false do
  78.         term.setCursorPos(1,2)
  79.         term.clearLine()
  80.         targetID = read()
  81.     end
  82.     chat()
  83.   end
  84. end
  85.  
  86. function connectModem()
  87. term.clear()
  88. term.setCursorPos(1,1)
  89.  
  90.   if peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
  91.     rednet.open("back")
  92.     connect()
  93.   elseif peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
  94.     rednet.open("front")
  95.     connect()
  96.   elseif peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
  97.     rednet.open("left")
  98.     connect()
  99.   elseif peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
  100.     rednet.open("right")
  101.     connect()  
  102.   elseif peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
  103.     rednet.open("top")
  104.     connect()
  105.   elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
  106.     rednet.open("bottom")
  107.     connect()
  108.   else
  109.     print("**No modem connected, please place one on an available side and press enter**")
  110.     read()
  111.     connectModem()
  112.    end
  113. end
  114.  
  115. connectModem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement