Advertisement
Guest User

Client

a guest
Apr 19th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local LastUpdateTime = "April 19, 2016";
  2. local Protocol       = "CCCS Login";
  3. local Domain         = "SystematicLoop.net/CCCS Server";
  4.  
  5. local function open()
  6.     local bOpen, sFreeSide = false, nil
  7.     for n,sSide in pairs(rs.getSides()) do 
  8.         if peripheral.getType( sSide ) == "modem" then
  9.             sFreeSide = sSide
  10.             if rednet.isOpen( sSide ) then
  11.                 bOpen = true
  12.                 break
  13.             end
  14.         end
  15.     end
  16.    
  17.     if not bOpen then
  18.         if sFreeSide then
  19.             print( "No modem active. Opening "..sFreeSide.." modem" )
  20.             rednet.open( sFreeSide )
  21.             return true
  22.         else
  23.             print( "No modem attached" )
  24.             return false
  25.         end
  26.     end
  27.     return true
  28. end
  29.  
  30. term.clear ();
  31. term.setCursorPos (1, 1);
  32. print ("CCCS Client Version 1.1 Loading...");
  33. print ("Last updated "..LastUpdateTime);
  34.  
  35. open ();
  36. local ServerIP = rednet.lookup (Protocol, Domain);
  37.  
  38. if (ServerIP) then
  39.     print ("Found Server with address: "..tostring (ServerIP));
  40.     write ("Username: ");
  41.     local Username = read ();
  42.     print ();
  43.     write ("Password: ");
  44.     local Password = read ("*");
  45.     print ("Validating access...");
  46.     rednet.send (ServerIP, Username, Protocol);
  47.     local SenderID, Message, _ = rednet.receive (Protocol);
  48.     if (SenderID == ServerIP) then
  49.         if (Message == Password) then
  50.             print ("Access Granted!");
  51.         else
  52.             print ("Access Denied!");
  53.             rednet.close ();
  54.             shell.run ("startup");
  55.         end
  56.     end
  57. else
  58.     print ("A connection to the server could not be established.");
  59.     print ("Check modem connections, weather conditions, address, and try again");
  60.     print ("Program will automatically restart in 10 seconds...");
  61.     sleep (10);
  62.     shell.run ("startup");
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement