Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file = fs.open("database", "r")
- tLines = {}
- line = "a"
- while line ~= nil do
- line = file.readLine()
- table.insert(tLines, line)
- end
- function check(table, value1, value2)
- for k,v in pairs(table) do
- print(v)
- if string.find(v, value1) and string.find(v, value2) then
- print("Value: " .. v)
- balance = string.sub(v, #value1+#value2+3, #v)
- print("balance")
- print(balance)
- return balance
- end
- end
- return false
- end
- function checkUserEx(table, value1, value2)
- for k,v in pairs(table) do
- if string.find(v, value1) and string.find(v, value2) then
- return true
- end
- end
- return false
- end
- function codeCheck(table, code)
- for k,v in pairs(table) do
- if string.find(v, code) then
- balance = string.sub(v, #code+2, #v)
- return balance
- end
- end
- return false
- end
- function deleteLine(del)
- for k,v in pairs(tLines) do
- if string.find(v, del) then
- tLines[k] = "USED CODE"
- writeData()
- end
- end
- end
- function changeLine(content1, content2, change)
- for k,v in pairs(tLines) do
- if string.find(v, content1) and string.find(v, content2) then
- print("found line")
- tLines[k] = change
- writeData()
- return true
- end
- end
- return false
- end
- function writeData()
- file.close()
- file = fs.open("database", "w")
- for _,v in pairs(tLines) do
- file.writeLine(v)
- end
- file.close()
- os.reboot()
- end
- rednet.open("back")
- while true do
- id, msg = rednet.receive()
- if msg[1] == "newUser" then
- if checkUserEx(tLines, msg[2], msg[3]) then
- rednet.send(id, false)
- os.reboot()
- else
- rednet.send(id, true)
- print("sent true")
- table.insert(tLines, msg[2] .. "-" .. msg[3] .. "-" .. "0")
- writeData()
- sleep(5)
- os.reboot()
- end
- end
- if msg[1] == "newCode" then
- table.insert(tLines, msg[2] .. "-" .. msg[3])
- writeData()
- os.reboot()
- end
- if msg[1] == "balance" then
- print("Balance")
- newLine = msg[2] .. "-" .. msg[3] .. "-" .. msg[4]
- if changeLine(msg[2], msg[3], newLine) then
- print("CHANGED")
- else
- print(msg[2] .. "-" .. msg[3])
- print(msg[2] .. "-" .. msg[3] .. "-" .. msg[4])
- end
- sleep(34)
- end
- if msg[1] == "code" then
- print("Code")
- codeBal = codeCheck(tLines,msg[2])
- if codeBal == false then
- rednet.send(id, false)
- else
- rednet.send(id, codeBal)
- deleteLine(msg[2])
- end
- end
- if msg[1] == "usercred" then
- if msg[2] == "USED" then
- rednet.send(id, false)
- os.reboot()
- end
- print("usercred")
- print(msg[2].."-"..msg[3])
- balance = check(tLines, msg[2], msg[3])
- if balance == false then
- rednet.send(id, false)
- os.reboot()
- else
- rednet.send(id, balance)
- os.reboot()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement