Posted 14 November 2013 - 11:43 AM
On a multiplayer server, I have been creating a system whereby each door in a building has a player detector attached, and thereby only allowed players can open them. Each door has a computer which talks to a main server, holding the disk, and then the server returns either true/false if the user is allowed. The code appears to work, however it will only read the first line of the 'Allowed Users' file. I think this is a simple fix, however I cannot for the life of me see where it is. Any help would be much appreciated.
Client (Computer on Door):
Server (With disk):
Client (Computer on Door):
rednet.open("bottom")
function allowed(player,authServer)
rednet.send(authServer,player)
id, message, distance = rednet.receive()
if message then
return true
else
return false
end
end
function door(player,authServer)
if allowed(player,authServer) then
redstone.setOutput("top",true)
sleep(4)
redstone.setOutput("top",false)
return true
else
return false
end
end
function logger(player,logServer,state)
if state then
rednet.send(logServer,player.." was granted access "..os.time.." via computer "..os.getComputerID())
else
rednet.send(logServer,player.." tried to get in at "..os.time.." via computer "..os.getComputerID())
end
end
function getPlayer()
event, name = os.pullEvent("player")
return name
end
function main()
local authServer = 330
local logServer = 331
local player = getPlayer()
if door(player,authServer) then
logger(player,logServer,true)
else
logger(player,logServer,false)
end
end
while true do
main()
end
Server (With disk):
rednet.open("bottom")
function authorise(request)
players = fs.open("disk/allowed","r")
for player in players:lines() do
if request == player then
return true
else
return false
end
end
end
function receiveRequest()
id, request, distance = rednet.receive()
return id, request
end
function allowPlayer(door,state)
rednet.send(door,state)
end
function main()
local id, player = receiveRequest()
if authorise(player) then
allowPlayer(id,true)
else
allowPlayer(id,false)
end
end
while true do
main()
end