Function for "player exists"?

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

Function for "player exists"?

by Sokomine » Fri Oct 26, 2012 15:59

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?
A list of my mods can be found here.
 

minetestpro
New member
 
Posts: 8
Joined: Mon Feb 18, 2013 22:04

by minetestpro » Mon Feb 18, 2013 22:24

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
Last edited by minetestpro on Mon Feb 18, 2013 22:25, edited 1 time in total.
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Mon Feb 18, 2013 23:13

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)
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

User avatar
Traxie21
Member
 
Posts: 753
Joined: Mon Dec 31, 2012 10:48

by Traxie21 » Mon Feb 18, 2013 23:28

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)
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Tue Feb 19, 2013 00:04

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.
Last edited by rarkenin on Tue Feb 19, 2013 00:04, edited 1 time in total.
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

User avatar
Traxie21
Member
 
Posts: 753
Joined: Mon Dec 31, 2012 10:48

by Traxie21 » Tue Feb 19, 2013 00:52

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.
 

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

by addi » Tue Feb 19, 2013 04:24

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
 

User avatar
0gb.us
Member
 
Posts: 841
Joined: Sun Sep 16, 2012 01:55

by 0gb.us » Tue Feb 19, 2013 08:51

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.
Last edited by 0gb.us on Tue Feb 19, 2013 08:52, edited 1 time in total.
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

by Sokomine » Wed Feb 20, 2013 03:08

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 list of my mods can be found here.
 

User avatar
Topywo
Member
 
Posts: 1718
Joined: Fri May 18, 2012 20:27

by Topywo » Wed Feb 20, 2013 10:46

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.
 

User avatar
0gb.us
Member
 
Posts: 841
Joined: Sun Sep 16, 2012 01:55

by 0gb.us » Wed Feb 20, 2013 13:00

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.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Wed Feb 20, 2013 13:10

I have added this function to Commonlib
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 14 guests

cron