From 3d4d0cb5749a68436cccd08b7a135f9bb7527038 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 29 Mar 2013 23:28:13 -0400 Subject: Add option to not prepend "Server -!- " to messages sent with minetest.chat_send_player() --- src/scriptapi.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 8d472e6b8..3b0c15f8a 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -754,15 +754,18 @@ static int l_chat_send_all(lua_State *L) return 0; } -// chat_send_player(name, text) +// chat_send_player(name, text, prepend) static int l_chat_send_player(lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *text = luaL_checkstring(L, 2); + bool prepend = true; + if (lua_isboolean(L, 3)) + prepend = lua_toboolean(L, 3); // Get server from registry Server *server = get_server(L); // Send - server->notifyPlayer(name, narrow_to_wide(text)); + server->notifyPlayer(name, narrow_to_wide(text), prepend); return 0; } -- cgit v1.2.3 From 4a9b8aae5e54e4cb6395771868a83bfd0f72c11a Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 4 Apr 2013 04:28:21 -0400 Subject: Add minetest.get_player_ip() --- doc/lua_api.txt | 1 + src/scriptapi.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src/scriptapi.cpp') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 38e12882d..531a40b29 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1002,6 +1002,7 @@ minetest.auth_reload() ^ These call the authentication handler minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs ^ A quickhand for checking privileges +minetest.get_player_ip(name) -> IP address string Chat: minetest.chat_send_all(text) diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 3b0c15f8a..f0fe1950e 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -788,6 +788,31 @@ static int l_get_player_privs(lua_State *L) return 1; } +// get_player_ip() +static int l_get_player_ip(lua_State *L) +{ + const char * name = luaL_checkstring(L, 1); + Player *player = get_env(L)->getPlayer(name); + if(player == NULL) + { + lua_pushnil(L); // no such player + return 1; + } + try + { + Address addr = get_server(L)->getPeerAddress(get_env(L)->getPlayer(name)->peer_id); + std::string ip_str = addr.serializeString(); + lua_pushstring(L, ip_str.c_str()); + return 1; + } + catch(con::PeerNotFoundException) // unlikely + { + dstream << __FUNCTION_NAME << ": peer was not found" << std::endl; + lua_pushnil(L); // error + return 1; + } +} + // get_ban_list() static int l_get_ban_list(lua_State *L) { @@ -1084,6 +1109,7 @@ static const struct luaL_Reg minetest_f [] = { {"chat_send_all", l_chat_send_all}, {"chat_send_player", l_chat_send_player}, {"get_player_privs", l_get_player_privs}, + {"get_player_ip", l_get_player_ip}, {"get_ban_list", l_get_ban_list}, {"get_ban_description", l_get_ban_description}, {"ban_player", l_ban_player}, -- cgit v1.2.3