Advertisement
M0T3X

CE_User_Interface

Oct 10th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.01 KB | None | 0 0
  1. local function callfunc(func,parameter)
  2.     h = http.post("http://mc.ve1121.venus.fastwebserver.de/index.php", "func="..textutils.urlEncode(tostring(func)).."&".."parameter="..textutils.urlEncode(tostring(parameter)))
  3.     return h.readLine()
  4. end
  5.  
  6. local function register_user()
  7.     term.setCursorPos(1,1)
  8.     term.clear()
  9.     print("Register User")
  10.     print("___________________________________________________")
  11.     print("")
  12.     print("User:")
  13.     user = read()
  14.     print("")
  15.     print("Password:")
  16.     pass = read()
  17.     if callfunc("register_user", user..","..pass) == "1" then
  18.         term.setCursorPos(1,1)
  19.         term.clear()
  20.         print("User "..user.." successfully registered.")
  21.         print("")
  22.         print("Press Enter to proceed..")
  23.         read()
  24.         return true
  25.     else
  26.         return false
  27.     end
  28. end
  29.  
  30. local function login_user()
  31.     term.setCursorPos(1,1)
  32.     term.clear()
  33.     print("Login User")
  34.     print("___________________________________________________")
  35.     print("")
  36.     print("User:")
  37.     user = read()
  38.     print("")
  39.     print("Password:")
  40.     pass = read()
  41.     if callfunc("login_user", user..","..pass) == "1" then
  42.         CE_user = user
  43.         term.setCursorPos(1,1)
  44.         term.clear()
  45.         print("User "..CE_user.." successfully logged in..")
  46.         print("")
  47.         print("Press Enter to proceed..")
  48.         read()
  49.         return true
  50.     end
  51. end
  52.  
  53. local function logout_user()
  54.     if callfunc("logout_user", CE_user) == "1" then
  55.         term.setCursorPos(1,1)
  56.         term.clear()
  57.         print("User "..CE_user.." successfully logged out.")
  58.         print("")
  59.         print("Press Enter to proceed..")
  60.         read()
  61.         return false
  62.     end
  63. end
  64.  
  65. local function wallet_amount()
  66.     return callfunc("wallet_amount", CE_user)
  67. end
  68.  
  69. local function wallet_id()
  70.     return callfunc("wallet_id", CE_user)
  71. end
  72.  
  73. local function wallet_send_money()
  74.     term.setCursorPos(1,1)
  75.     term.clear()
  76.     print("User-Wallet: Send CC")
  77.     print("___________________________________________________")
  78.     print("")
  79.     print("Wallet-Amount: "..wallet_amount().." CC")
  80.     print("")
  81.     print("")
  82.     print("Wallet-ID:")
  83.     id = read()
  84.     print("")
  85.     print("CC amount:")
  86.     amount = read()
  87.     res = callfunc("wallet_send", CE_user..","..id..","..amount)
  88.     if res == "0" then
  89.         term.setCursorPos(1,1)
  90.         term.clear()
  91.         print("Not enough Corner-Credits on Wallet")
  92.         print("")
  93.         print("Press Enter to proceed..")
  94.         read()
  95.     end
  96.     if res == "1" then
  97.         term.setCursorPos(1,1)
  98.         term.clear()
  99.         print("Wallet-ID not found.")
  100.         print("")
  101.         print("Press Enter to proceed..")
  102.         read()
  103.     end
  104.     if res == "2" then
  105.         term.setCursorPos(1,1)
  106.         term.clear()
  107.         print("Send "..amount.." CC to Wallet-ID "..id)
  108.         print("")
  109.         print("Press Enter to proceed..")
  110.         read()
  111.     end
  112. end
  113.  
  114. CE_user = ""
  115. online = false
  116.  
  117. while true do
  118.     term.setCursorPos(1,1)
  119.     term.clear()
  120.     print("Welcome to Corner-Economy Mod v1.0")
  121.     print("___________________________________________________")
  122.     print("")
  123.     print("1. Register")
  124.     print("2. Login")
  125.     print("3. Exit")
  126.     print("")
  127.     print("")
  128.     print("")
  129.     local input1 = read()
  130.     if input1 == "1" then
  131.         register_user()
  132.     end
  133.     if input1 == "2" then
  134.         online = login_user()
  135.         while online do
  136.             term.setCursorPos(1,1)
  137.             term.clear()
  138.             print("Corner-Economy v1.0")
  139.             print("___________________________________________________")
  140.             print("")
  141.             print("User "..CE_user.." logged in.")
  142.             print("")
  143.             print("1. Wallet")
  144.             print("2. Logout")
  145.             print("")
  146.             print("")
  147.             print("")
  148.             local input2 = read()
  149.             if input2 == "1" then
  150.                 local back = false
  151.                 while back == false do
  152.                     term.setCursorPos(1,1)
  153.                     term.clear()
  154.                     print("Wallet-ID "..wallet_id()..": "..wallet_amount().." CC")
  155.                     print("___________________________________________________")
  156.                     print("")
  157.                     print("1. Send CC")
  158.                     print("2. Back")
  159.                     print("")
  160.                     print("")
  161.                     print("")
  162.                     local input3 = read()
  163.                     if input3 == "1" then
  164.                         wallet_send_money()
  165.                     end
  166.                     if input3 == "2" then
  167.                         back = true
  168.                     end
  169.                 end
  170.             end
  171.             if input2 == "2" then
  172.                 online = logout_user()
  173.             end
  174.         end
  175.     end
  176.     if input1 == "3" then
  177.         term.setCursorPos(1,1)
  178.         term.clear()
  179.         break
  180.     end
  181. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement