Page 1 of 1

Function for "player exists"?

PostPosted: Fri Oct 26, 2012 15:59
by Sokomine
Is there any function that can tell me if a player exists? I'm not only intrested in players logged in right now - I want to check all players. Is there a better way than through the filesystem? Finding players whose names starts with a given prefix (case-insensitve search) might also be quite useful.

Further question: Which characters are legal for player names?

PostPosted: Mon Feb 18, 2013 22:24
by minetestpro
try the help on the commands in minetest i think theres something u can use their

Edit: first response to dis post gettin there XD

PostPosted: Mon Feb 18, 2013 23:13
by rarkenin
minetestpro wrote:try the help on the commands in minetest i think theres something u can use their

Edit: first response to dis post gettin there XD


No, that's probably not going to help, since /status only works for players logged in(and also only from chat, not Lua)

PostPosted: Mon Feb 18, 2013 23:28
by Traxie21
You can try to write names to a file in a table format so that you can loop through the contents in that file.
eg . {name1 = true, name2 = true}]
using minetest.register_on_newplayer(player)

PostPosted: Tue Feb 19, 2013 00:04
by rarkenin
You can look at files in the "players" subdirectory of the world directory(i.e. minetest.getworldpath()). If the file exists, the player should exist. You can also read auth.txt.

PostPosted: Tue Feb 19, 2013 00:52
by Traxie21
Yes, your method would be more reliable, but you could not do anything but searching, listing would be hard. It all depends on what you intend to do.

PostPosted: Tue Feb 19, 2013 04:24
by addi
Why so complicated?

the internal auth handler saves all the players in the variable minetest.auth_table [playername]

u need to check only if the name in the table.

(i dont know but maybe lua has a search function that searches the table)


btw: it stores the privs here and the password hashes
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.auth_table[playername].privs
minetest.auth_table[playername].password

PostPosted: Tue Feb 19, 2013 08:51
by 0gb.us
rarkenin wrote:You can look at files in the "players" subdirectory of the world directory(i.e. minetest.getworldpath()). If the file exists, the player should exist. You can also read auth.txt.


That works if you are using a decent file system, but not if you aren't. Windows, in all it's stupidity, is case insensitive, so checking for a file for RARKENIN would return true if rarkenin was a player, not only is RARKENIN was. I have considered this before, to try to fix /sharearea in my land claims.

addi wrote:Why so complicated?

the internal auth handler saves all the players in the variable minetest.auth_table [playername]

u need to check only if the name in the table.

(i dont know but maybe lua has a search function that searches the table)


btw: it stores the privs here and the password hashes
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.auth_table[playername].privs
minetest.auth_table[playername].password


Awesome, thanks! You just fixed my /sharearea command.

PostPosted: Wed Feb 20, 2013 03:08
by Sokomine
Oh, almost forgot about this thread. I solved the problem in a similar way addi was suggesting:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 -- check if the player exists
         local privs = minetest.get_player_privs( name );
f( not( privs ) or not( privs.interact )) then
            minetest.chat_send_player(name, "Player ""..name.."" not found or has no interact privs.");
            return;
         end


That's another function that ought to be part of a general lib.

PostPosted: Wed Feb 20, 2013 10:46
by Topywo
Sokomine wrote:Oh, almost forgot about this thread. I solved the problem in a similar way addi was suggesting:

-- check if the player exists
local privs = minetest.get_player_privs( name );
f( not( privs ) or not( privs.interact )) then
minetest.chat_send_player(name, "Player ""..name.."" not found or has no interact privs.");
return;
end

That's another function that ought to be part of a general lib.


f --> if ?

You probably already corrected it, but to be sure.

PostPosted: Wed Feb 20, 2013 13:00
by 0gb.us
Sokomine wrote:Oh, almost forgot about this thread. I solved the problem in a similar way addi was suggesting:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 -- check if the player exists
         local privs = minetest.get_player_privs( name );
f( not( privs ) or not( privs.interact )) then
            minetest.chat_send_player(name, "Player ""..name.."" not found or has no interact privs.");
            return;
         end


That's another function that ought to be part of a general lib.


A player can exist without having interact. It makes no sense to check specifically for that privilege, especially since you had to check to see if the player had a privilege array already before checking for that one index. If added to the general library, " or not( privs.interact )" should be removed.

PostPosted: Wed Feb 20, 2013 13:10
by rubenwardy
I have added this function to Commonlib