This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lasere123456's profile picture

access level server

Started by Lasere123456, 03 April 2013 - 05:39 AM
Lasere123456 #1
Posted 03 April 2013 - 07:39 AM
ok, so so i am trying to make a server for my computers to confirm players accsess level.
my computers have player detectors form mics peripheral. They send a message to the server
and the server is supposed to tell the computer the player's access level.
but i am having problems whit finding out the sec level of the players.

Would anyone be so kind to point me in the right direction?
Engineer #2
Posted 03 April 2013 - 08:00 AM
So you send the playername to the server? If so you could do something like this:

playerLevels = { -- Table of players with security level.
   [1] = {player1 = 1},
   [2] = {player2 = 2},
}
local id, message = rednet.receive()
local level = nil

for i = 1, #playerLevels do -- Loop through the table
   if playerLevels[i][message] then -- Check if the player's name is valid
	  level = i
	  break --break out of the loop, not neccessary but the other things wont hit, unless you have somebody twice in it
   end
end

if level then -- To check if level is nil or not
	if stuff then
	   -- do stuff
	end
end

I hope I helped :)/>

Edit: Providied some more info
Edited on 03 April 2013 - 06:16 AM
JokerRH #3
Posted 03 April 2013 - 08:01 AM
but i am having problems whit finding out the sec level of the players.

I totally agree with you if you haven't defined it :P/>
Simply create a table like this:

local secLevel = {
  Player1 = 1,
  Player2 = 3,
  Player3 = 2
}

print(secLevel.Player1)
--Or
print(secLevel["Player1"])

Edit: Again too late? wow, I don't have any luck today :D/>

Edit2:

local secLevel = {
  Player1 = 1,
  Player2 = 3,
  Player3 = 2
}

while true do
  local id, player = rednet.receive()
  rednet.send(id, secLevel[player] or 0)
end
JokerRH #4
Posted 03 April 2013 - 08:06 AM

playerLevels = { -- Table of players with security level.
   player1 = 1,
   player2 = 2,
}

-- [...]

for i = 1, #playerLevels do -- Loop through the table
   if playerLevels[message] then -- Check if the player's name is valid
	  level = i
	  break --break out of the loop, not neccessary but the other things wont hit, unless you have somebody twice in it
   end
end

--[...]

I don't think that'll work.
If you set a string as an index for a table you can't adress it with a number :P/>
(So #tab won't work)
Lasere123456 #5
Posted 03 April 2013 - 08:12 AM
thanks
Engineer #6
Posted 03 April 2013 - 08:16 AM

playerLevels = { -- Table of players with security level.
   player1 = 1,
   player2 = 2,
}

-- [...]

for i = 1, #playerLevels do -- Loop through the table
   if playerLevels[message] then -- Check if the player's name is valid
	  level = i
	  break --break out of the loop, not neccessary but the other things wont hit, unless you have somebody twice in it
   end
end

--[...]

I don't think that'll work.
If you set a string as an index for a table you can't adress it with a number :P/>
(So #tab won't work)
Now it does!:P/>
Lasere123456 #7
Posted 03 April 2013 - 09:11 AM
OK, so i used the code you gave me and made this:

http://pastebin.com/eutyzbdf

then i sendt it this message ("rednet.send(117, "_TheSettler_", true )
but it only returns the sender id and message not the accsess level…
Engineer #8
Posted 03 April 2013 - 09:17 AM
Try this code: http://pastebin.com/7dLwVKws

And where is true part for in your rednet.send(–blabla)?
Or are you using channels?

Edit: Oops.. Try this one: http://pastebin.com/1bJCSNQC
Edited on 03 April 2013 - 07:20 AM
Lasere123456 #9
Posted 03 April 2013 - 09:29 AM
Error on line 26

(added the missing s in access, still don't work)
Engineer #10
Posted 03 April 2013 - 09:36 AM
Lol Im an herp-a-derp today: http://pastebin.com/Rz1r8e36
Lasere123456 #11
Posted 03 April 2013 - 09:40 AM
error on line 28…. nill value error
JokerRH #12
Posted 03 April 2013 - 10:25 AM
Try this:

server

rednet.open("back")

local secLevel = {
  Player1 = 1,
  Player2 = 3,
  Player3 = 2
}

while true do
  local id, player = rednet.receive()
  rednet.send(id, secLevel[player] or 0)
end

client:

local id, player = ...
id = tonumber(id)

rednet.open("right")
rednet.send(id, player)

local _, lvl = rednet.receive()
print(lvl)

Save both to a file on your computer (for example the serverprogramm to server and the clientprogram to client)
then type
server
to run the server and
client <id> <player>
(id is the id of your server computer)
to run the client
Engineer #13
Posted 03 April 2013 - 10:32 AM
Damn now I feel like a nub again. Its better to use jokeRH's way. I modified it a little bit; ["name"] are neccesary because name can start with a number. This works, I have tested it. pastebin.com/uf3gq346

Edit: Sorry for the program previously not to work. I was like: Herp-a-Derp!
Lasere123456 #14
Posted 03 April 2013 - 10:45 AM
Thanks to all of you.