Advertisement
CelticCoder

turtleServer

May 14th, 2024 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.01 KB | None | 0 0
  1. --os.pullEvent = os.pullEventRaw
  2.  
  3.  
  4. turtlelist = "turtles.txt"
  5. services = "services.txt"
  6. serverID = 9
  7.  
  8.  
  9.  
  10.  
  11. local function serverCoroutine(filename, whitelist, itemlist)
  12.     while true do
  13.         gsuccess = false
  14.         -- Listen for incoming messages
  15.         local senderId, message = rednet.receive()
  16.         success, command, line = pcall(twoInputStrip, message)
  17.         if success and line ~= nil then
  18.             if command == "UPS" then
  19.                 success, command, nusername, npassword, recipientaddress = pcall(fourInputStrip, message)
  20.                 if success and nusername ~= nil and npassword ~= nil and recipientaddress ~= nil then
  21.                     dusername, dpassword = searchDatabase(nusername, filename)
  22.                     if tostring(dusername) ~= nil and tostring(dpassword) ~= nil then
  23.                         if npassword == dpassword then
  24.                             if tonumber(balancechange) >= 0 and tonumber(getValue(nusername, filename)) >= tonumber(balancechange) then
  25.                                 nv = tonumber(getValue(nusername, filename)) - tonumber(balancechange)
  26.                                 changeValue(nusername, nv, filename)
  27.                                 rednet.send(senderId, getValue(nusername, filename))
  28.                                 gsuccess = true
  29.                             end
  30.                         end
  31.                     end
  32.                 end
  33.             elseif command == "delivery" then
  34.                 success, command, nusername, npassword = pcall(fourInputStrip, message)
  35.                 if success and nusername ~= nil and npassword ~= nil then
  36.                     dusername, dpassword = searchDatabase(nusername, filename)
  37.                     if tostring(dusername) ~= nil and tostring(dpassword) ~= nil then
  38.                         if npassword == dpassword then
  39.                             rednet.send(senderId, getValue(nusername, filename))
  40.                             gsuccess = true
  41.                         end
  42.                     end
  43.                 end
  44.             elseif command == "package" then
  45.                 success, command, nusername, npassword, recipientlocation = pcall(fourInputStrip, message)
  46.                 if success and nusername ~= nil and npassword ~= nil and balancechange ~= nil and nusername2 ~= nil then
  47.                     dusername, dpassword = searchDatabase(nusername, filename)
  48.                     nusername2 = searchDatabase(nusername2, filename)
  49.                     if tostring(dusername) ~= nil and tostring(dpassword) ~= nil then
  50.                         if npassword == dpassword then
  51.                             if nusername2 ~= nil then
  52.                                 if tonumber(balancechange) > 0 and tonumber(balancechange) <= tonumber(getValue(nusername, filename)) then
  53.                                     nv = tonumber(getValue(nusername, filename) - tonumber(balancechange))
  54.                                     nv2 = tonumber(getValue(nusername2, filename) + tonumber(balancechange))
  55.                                     changeValue(nusername, nv, filename)
  56.                                     changeValue(nusername2, nv2, filename)
  57.                                     rednet.send(senderId, tonumber(getValue(nusername, filename)))
  58.                                     gsuccess = true
  59.                                 end
  60.                             end
  61.                         end
  62.                     end
  63.                 end
  64.             elseif command == "items" then
  65.                 rednet.send(senderId, getAllItems(itemlist))
  66.                 gsuccess = true
  67.             end
  68.         log(senderId, message, gsuccess)
  69.         if gsuccess == false then
  70.             rednet.send(senderId, "false")
  71.         end
  72.         end
  73.     end
  74. end
  75.  
  76. if fs.exists(filename) then
  77.     rednet.open("top")
  78.     parallel.waitForAny(
  79.         function() loginCoroutine(filename, whitelist, itemlist) end,
  80.         function() serverCoroutine(filename, whitelist, itemlist) end
  81.     )
  82. else
  83.     print("No File to Protect")
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement