Skip to content

Commit 4a9b8aa

Browse files
ShadowNinjaceleron55
authored andcommittedApr 23, 2013
Add minetest.get_player_ip()
1 parent 3d4d0cb commit 4a9b8aa

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 

‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ minetest.auth_reload()
10021002
^ These call the authentication handler
10031003
minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
10041004
^ A quickhand for checking privileges
1005+
minetest.get_player_ip(name) -> IP address string
10051006

10061007
Chat:
10071008
minetest.chat_send_all(text)

‎src/scriptapi.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,31 @@ static int l_get_player_privs(lua_State *L)
788788
return 1;
789789
}
790790

791+
// get_player_ip()
792+
static int l_get_player_ip(lua_State *L)
793+
{
794+
const char * name = luaL_checkstring(L, 1);
795+
Player *player = get_env(L)->getPlayer(name);
796+
if(player == NULL)
797+
{
798+
lua_pushnil(L); // no such player
799+
return 1;
800+
}
801+
try
802+
{
803+
Address addr = get_server(L)->getPeerAddress(get_env(L)->getPlayer(name)->peer_id);
804+
std::string ip_str = addr.serializeString();
805+
lua_pushstring(L, ip_str.c_str());
806+
return 1;
807+
}
808+
catch(con::PeerNotFoundException) // unlikely
809+
{
810+
dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
811+
lua_pushnil(L); // error
812+
return 1;
813+
}
814+
}
815+
791816
// get_ban_list()
792817
static int l_get_ban_list(lua_State *L)
793818
{
@@ -1084,6 +1109,7 @@ static const struct luaL_Reg minetest_f [] = {
10841109
{"chat_send_all", l_chat_send_all},
10851110
{"chat_send_player", l_chat_send_player},
10861111
{"get_player_privs", l_get_player_privs},
1112+
{"get_player_ip", l_get_player_ip},
10871113
{"get_ban_list", l_get_ban_list},
10881114
{"get_ban_description", l_get_ban_description},
10891115
{"ban_player", l_ban_player},

0 commit comments

Comments
 (0)
Please sign in to comment.