Advertisement
oli414

[CC] Shooting Range Client

Jun 28th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. local serverid = 559
  2. local sessionName = ""
  3. local sessionData = {}
  4.  
  5. function verify()
  6.     rednet.open("bottom")
  7.     rednet.send(serverid, ":verify")
  8.     local id, msg = rednet.receive(2)
  9.     if id~=nil then
  10.         return true
  11.     end
  12.     return false
  13. end
  14.  
  15. function isUser(name)
  16.     rednet.open("bottom")
  17.     rednet.send(serverid, ":user")
  18.     rednet.receive(2)
  19.     rednet.send(serverid, name)
  20.     local id, msg = rednet.receive(2)
  21.     if id~=nil then
  22.         return msg
  23.     end
  24.     return nil
  25. end
  26.  
  27. function getUserData(name)
  28.     rednet.open("bottom")
  29.     rednet.send(serverid, ":data")
  30.     rednet.receive(2)
  31.     rednet.send(serverid, name)
  32.     local id, msg = rednet.receive(2)
  33.     sessionData = textutils.unserialize(msg)
  34. end
  35.  
  36. function session()
  37.     print("Please enter your name:")
  38.     sessionName = read()
  39.     print("Please wait...")
  40.     local data = isUser(sessionName)
  41.     if data ~= nil then
  42.         if data == ":newUser" then
  43.             print("Welcome to the shooting range!")
  44.         else
  45.             print("Welcome back "..sessionName.."!")
  46.         end
  47.     else
  48.         return
  49.     end
  50.     getUserData(sessionName)
  51.     print("Your highscore is: "..sessionData.highscore)
  52. end
  53.  
  54. function main()
  55.     print("Welcome!")
  56.     print("Please wait...")
  57.     if not verify() then
  58.         print("Make sure the computer on the back is on.")
  59.     end
  60.     while not verify() do
  61.         sleep(1)
  62.     end
  63.     session()
  64. end
  65.  
  66. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement