computercam

CC_Domain_Apis_ServerConnector

Feb 29th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. serverID = 0
  2. function TestConnection(debug)
  3.     if debug == "true" then
  4.         print("Debug: sending ping")
  5.         function ping()
  6.             rednet.send(serverID, "ping")
  7.             local senderID, message, distance = rednet.receive(5)
  8.             if message == "server_busy" then
  9.                 print("Server is busy, Retrying in 10 seconds")
  10.                 sleep(10)
  11.                 ping()
  12.             end
  13.             if message == "pong" then
  14.             else
  15.                 error("The server didn't respond, the server may be out dated, not online, or you don't have a strong enough connection.")
  16.             end
  17.         end
  18.         ping()
  19.         print("Debug: Server: ", senderID, " Connecion Message: ", message)
  20.         sleep(0.5)
  21.     else
  22.         rednet.send(serverID, "ping")
  23.         local senderID, message, distance = rednet.receive()
  24.         sleep(0.5)
  25.     end
  26. end
  27. function connect(loginName, loginPass)
  28.     rednet.send(serverID, "domain_connect")
  29.     sleep(0.5)
  30.     rednet.send(serverID, loginName)
  31.     sleep(0.5)
  32.     rednet.send(serverID, loginPass)
  33. end
  34. function disconnect()
  35.     print("Attempting safe disconnection.")
  36.     rednet.send(serverID, "domain_disconnect")
  37.     local senderID, message, distance = rednet.receive()
  38.     if message == "disconnected" then
  39.         print("Logout complete! Killing rednet modem.", " ", senderID, message, distance)
  40.         rednet.close("top")
  41.     else
  42.         print("Failed safe disconnection, killing connection.")
  43.         rednet.close("top")
  44.     end
  45. end
Add Comment
Please, Sign In to add comment