Stary2001

card-server

Sep 4th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("bottom")
  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,rooms in string.gmatch(s,"(.-)|(.-)|(.-)|") do
  10. print(name,"|",pass)
  11. names[name]={pass,rooms}
  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[1]==pass then
  27.           ok=v[2]
  28.           break
  29.         end
  30.       end
  31.     end
  32.     if ok then rednet.send(id,"CARD|OK|"..ok) else
  33.       rednet.send(id,"CARD|BAD")
  34.     end
  35.   elseif data:sub(1,8)=="CARD|ADD|" and id== then
  36.     print("adding card " .. data:sub(8).. " from id "..id)
  37.     local f=fs.open("/card-index","a")
  38.     f.write(data:sub(9))
  39.    end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment