Guest User

card-server

a guest
Sep 3rd, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. rednet.open("top")
  2.  
  3. local names={}
  4. local f=fs.open("/card-index","r")
  5. if f then
  6.  
  7. local s=f.readLine()
  8. while s do
  9. for name,pass in string.gmatch(s,"(.-)|(.-)|") do
  10. print(name,"|",pass)
  11. names[name]=pass
  12. end
  13. s=f.readLine()
  14. end
  15. f.close()
  16. end
  17.  
  18. while true do
  19.   local id,data=rednet.receive()
  20.  
  21.   if data:sub(1,11)=="CARD|CHECK|" then
  22.     local ok=false
  23.     print("Checking "..data:sub(11).." from id "..id)
  24.     for name,pass in string.gmatch(data:sub(11),"|(.-)|(.-)|") do
  25.       for k,v in pairs(names) do
  26.         if k==name and v==pass then
  27.           ok=true
  28.           break
  29.         end
  30.       end
  31.     end
  32.     print(ok)
  33.     if ok then rednet.send(id,"CARD|OK") else
  34.       rednet.send(id,"CARD|BAD")
  35.     end
  36.   elseif data:sub(1,8)=="CARD|ADD|" then
  37.     print("adding card " .. data:sub(8).. " from id "..id)
  38.     local f=fs.open("/card-index","a")
  39.     f.write(data:sub(9))
  40.   elseif id~=176 then print(data) end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment