TrumpetMiner

BlueBank Server 3.5

May 10th, 2015
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. --[ Welcome to BlueBank made by TrumpetMiner v3.5
  2. --[ pastebin get VkYYSbR4 server
  3. --[ To Setup Your Server, Edit The Following
  4.     -- Authorization Code
  5. authSet = 3
  6. function authF()
  7.  authSet = authSet * 2 + 7
  8. end
  9. side = "top" -- Rednet Modem sidem (End of Setup)
  10. rednet.open(side)
  11. -- Functions
  12. function drawStart()
  13.  term.clear()
  14.  cur(1,1)
  15.  print "BlueBank Server 3.0 Status: Online"
  16.  print "--------------------------------------"
  17.  cur(3,4)
  18.  print("Current Auth Code > "..authSet)
  19.  id, message = rednet.receive()
  20.  if type(message) == "string" then
  21.   if message == "Login" then
  22.     login()
  23.   elseif message == "Balance" then
  24.     balance()
  25.   elseif message == "Transfer" then
  26.     transfer()
  27.   elseif message == "Create" then
  28.     create()
  29.   elseif message == "Delete" then
  30.     delete()
  31.   elseif message == "Rename" then
  32.     rename()
  33.   elseif message == "Passcode" then
  34.     passcode()
  35.   elseif message == "Add" then
  36.     add()
  37.   elseif message == "Auth" then
  38.     auth()
  39.   else
  40.    rednet.send(id,"Command Not Found")
  41.    drawStart()
  42.   end
  43.  else
  44.   rednet.send(id,"Data is Not String")
  45.  end
  46. end
  47. function login()
  48.  id, user = rednet.receive()
  49.  id, pass = rednet.receive()
  50.  if type(pass) == "string" then
  51.   if type(user) == "string" then
  52.    if fs.exists("user/"..user) == true then
  53.      h = fs.open("user/"..user, "r")
  54.      passReal = h.readAll()
  55.      h.close()
  56.      if pass == passReal then
  57.        rednet.send(id,"Login Successful")
  58.        drawStart()
  59.      else
  60.        rednet.send(id,"Password Incorrect")
  61.        drawStart()
  62.      end
  63.    else
  64.      rednet.send(id,"Unknown User")
  65.      drawStart()
  66.    end
  67.   else
  68.    rednet.send(id,"User Is Not String")  
  69.   end
  70.  else
  71.    rednet.send(id,"Password Is Not String")
  72.  end
  73. end
  74. function balance()
  75.  id, user = rednet.receive()
  76.  if type(user) == "string" then
  77.   h = fs.open("$/"..user, "r")
  78.   bal = h.readAll()
  79.   h.close()
  80.   rednet.send(id,bal)
  81.   drawStart()
  82.  else
  83.   rednet.send(id,"User is Not String")
  84.  end
  85. end
  86. function transfer()
  87.  id, user1 = rednet.receive()
  88.  id, user2 = rednet.receive()
  89.  id, am = rednet.receive()
  90.  if type(user1) == "string" and type(user2) == "string" and type(am) == "string" then
  91.    if fs.exists("user/"..user1) and fs.exists("user/"..user2)then
  92.     h = fs.open("$/"..user1, "r")
  93.     bal1 = h.readAll()
  94.     h.close()
  95.     if tonumber(bal1) >= tonumber(am) then
  96.       h = fs.open("$/"..user2, "r")
  97.       bal2 = h.readAll()
  98.       h.close()
  99.       bal1 = bal1 - am
  100.       bal2 = bal2 + am
  101.       h = fs.open("$/"..user1, "w")
  102.       h.write(bal1)
  103.       h.close()
  104.       h = fs.open("$/"..user2, "w")
  105.       h.write(bal2)
  106.       h.close()
  107.       rednet.send(id,"Funds Transfered")
  108.       drawStart()
  109.     elseif bal1 <= am then
  110.       rednet.send(id,"Not Enough Funds")
  111.       --term.setCursorPos(1,3)
  112.       --print(user1)
  113.       --print(user2)
  114.       --print(bal1)
  115.       --print(bal2)
  116.       --print(am)
  117.       drawStart()
  118.     else
  119.       rednet.send(id,"An Error Occurred")
  120.       drawStart()
  121.     end
  122.   else
  123.     rednet.send(id," User(s) Not Found")
  124.     drawStart()
  125.   end
  126.  else
  127.    rednet.send(id,"Data Is Not String")
  128.  end
  129. end
  130. function create()
  131.  id, user = rednet.receive()
  132.  id, pass = rednet.receive()
  133.  if type(user) == "string" and type(pass) then
  134.   if fs.exists("user/"..user) then
  135.     rednet.send(id,"User Exists")
  136.   else
  137.     h = fs.open("user/"..user,"w")
  138.     h.write(pass)
  139.     h.close()
  140.     h = fs.open("$/"..user,"w")
  141.     h.write("0")
  142.     h.close()
  143.     rednet.send(id,"Account Created")
  144.     drawStart()
  145.   end
  146.  else
  147.   rednet.send(id,"Data Is Not String")
  148.  end
  149.  drawStart()
  150. end
  151. function delete()
  152. end
  153. function rename()
  154. end
  155. function passcode()
  156. end
  157. function add()
  158.  id, user = rednet.receive()
  159.  id, amt = rednet.receive()
  160.  id, auth1 = rednet.receive()
  161.  if type(user) == "string" and type(amt) == "string" and type(auth1) == "string" then
  162.   if tonumber(auth1) == authSet then
  163.    if fs.exists("user/"..user) then
  164.      h = fs.open("$/"..user, "r")
  165.      bal = h.readAll()
  166.      h.close()
  167.      balNew = bal + amt
  168.      h = fs.open("$/"..user, "w")
  169.      h.write(balNew)
  170.      h.close()
  171.      rednet.send(id,"$"..amt.." Added to "..user)
  172.      drawStart()
  173.    else
  174.      rednet.send(id,"No Such User")
  175.      drawStart()
  176.    end
  177.   else
  178.    rednet.send(id,"Authorization Code Not Accepted")
  179.    drawStart()
  180.   end
  181.  else
  182.   rednet.send(id,"Data Is Not String")
  183.  end
  184. end
  185. function auth()
  186.  authF()
  187.  rednet.send(id,"New Auth Code Found")
  188.  drawStart()
  189. end
  190. function cur(cX,cY)
  191.  term.setCursorPos(cX,cY)
  192. end
  193. -- Program
  194. drawStart()
Add Comment
Please, Sign In to add comment