Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --os.pullEvent = os.pullEventRaw
- turtlelist = "turtles.txt"
- services = "services.txt"
- serverID = 9
- local function serverCoroutine(filename, whitelist, itemlist)
- while true do
- gsuccess = false
- -- Listen for incoming messages
- local senderId, message = rednet.receive()
- success, command, line = pcall(twoInputStrip, message)
- if success and line ~= nil then
- if command == "UPS" then
- success, command, nusername, npassword, recipientaddress = pcall(fourInputStrip, message)
- if success and nusername ~= nil and npassword ~= nil and recipientaddress ~= nil then
- dusername, dpassword = searchDatabase(nusername, filename)
- if tostring(dusername) ~= nil and tostring(dpassword) ~= nil then
- if npassword == dpassword then
- if tonumber(balancechange) >= 0 and tonumber(getValue(nusername, filename)) >= tonumber(balancechange) then
- nv = tonumber(getValue(nusername, filename)) - tonumber(balancechange)
- changeValue(nusername, nv, filename)
- rednet.send(senderId, getValue(nusername, filename))
- gsuccess = true
- end
- end
- end
- end
- elseif command == "delivery" then
- success, command, nusername, npassword = pcall(fourInputStrip, message)
- if success and nusername ~= nil and npassword ~= nil then
- dusername, dpassword = searchDatabase(nusername, filename)
- if tostring(dusername) ~= nil and tostring(dpassword) ~= nil then
- if npassword == dpassword then
- rednet.send(senderId, getValue(nusername, filename))
- gsuccess = true
- end
- end
- end
- elseif command == "package" then
- success, command, nusername, npassword, recipientlocation = pcall(fourInputStrip, message)
- if success and nusername ~= nil and npassword ~= nil and balancechange ~= nil and nusername2 ~= nil then
- dusername, dpassword = searchDatabase(nusername, filename)
- nusername2 = searchDatabase(nusername2, filename)
- if tostring(dusername) ~= nil and tostring(dpassword) ~= nil then
- if npassword == dpassword then
- if nusername2 ~= nil then
- if tonumber(balancechange) > 0 and tonumber(balancechange) <= tonumber(getValue(nusername, filename)) then
- nv = tonumber(getValue(nusername, filename) - tonumber(balancechange))
- nv2 = tonumber(getValue(nusername2, filename) + tonumber(balancechange))
- changeValue(nusername, nv, filename)
- changeValue(nusername2, nv2, filename)
- rednet.send(senderId, tonumber(getValue(nusername, filename)))
- gsuccess = true
- end
- end
- end
- end
- end
- elseif command == "items" then
- rednet.send(senderId, getAllItems(itemlist))
- gsuccess = true
- end
- log(senderId, message, gsuccess)
- if gsuccess == false then
- rednet.send(senderId, "false")
- end
- end
- end
- end
- if fs.exists(filename) then
- rednet.open("top")
- parallel.waitForAny(
- function() loginCoroutine(filename, whitelist, itemlist) end,
- function() serverCoroutine(filename, whitelist, itemlist) end
- )
- else
- print("No File to Protect")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement