Add option to not prepend "Server -!- " to messages sent with minetest.chat_send_player()
authorShadowNinja <noreply@gmail.com>
Sat, 30 Mar 2013 03:28:13 +0000 (23:28 -0400)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 23 Apr 2013 06:47:08 +0000 (09:47 +0300)
builtin/chatcommands.lua
doc/lua_api.txt
src/scriptapi.cpp
src/server.cpp
src/server.h

index 9f14749f44db6e8c5205871b78071b23964b75b8..f548fb01df037065d8d61cabc496503714f39c84 100644 (file)
@@ -675,7 +675,7 @@ minetest.register_chatcommand("msg", {
                if found then
                        if minetest.env:get_player_by_name(sendto) then
                                minetest.log("action", "PM from "..name.." to "..sendto..": "..message)
-                               minetest.chat_send_player(sendto, "PM from "..name..": "..message)
+                               minetest.chat_send_player(sendto, "PM from "..name..": "..message, false)
                                minetest.chat_send_player(name, "Message sent")
                        else
                                minetest.chat_send_player(name, "The player "..sendto.." is not online")
index 76f687f8e007a413e1b27e4a4a5c2f6b6be8ccc3..38e12882d1f0705de82a45c79258217b91cb06aa 100644 (file)
@@ -1005,7 +1005,8 @@ minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
 
 Chat:
 minetest.chat_send_all(text)
-minetest.chat_send_player(name, text)
+minetest.chat_send_player(name, text, prepend)
+^ prepend: optional, if it is set to false "Server -!- " will not be prepended to the message
 
 Inventory:
 minetest.get_inventory(location) -> InvRef
index 8d472e6b874ceb5571b9fc788547c53250cfb955..3b0c15f8ad5d1ada792b96f9f2e744cca7749156 100644 (file)
@@ -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;
 }
 
index dda2165c8c85ae8b3ae377e55add60e86ca5e108..62c1900366c0e20c581015a82a44cee190e6f5d0 100644 (file)
@@ -4606,12 +4606,15 @@ void Server::saveConfig()
                g_settings->updateConfigFile(m_path_config.c_str());
 }
 
-void Server::notifyPlayer(const char *name, const std::wstring msg)
+void Server::notifyPlayer(const char *name, const std::wstring msg, const bool prepend = true)
 {
        Player *player = m_env->getPlayer(name);
        if(!player)
                return;
-       SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg);
+       if (prepend)
+               SendChatMessage(player->peer_id, std::wstring(L"Server -!- ")+msg);
+       else
+               SendChatMessage(player->peer_id, msg);
 }
 
 bool Server::showFormspec(const char *playername, const std::string &formspec, const std::string &formname)
index 52606b0cb75f7fc2d6255e4e273bb344b6229f01..b668ecae49017a6a18657188d2a7d1e70baba134 100644 (file)
@@ -456,7 +456,7 @@ public:
        }
 
        // Envlock and conlock should be locked when calling this
-       void notifyPlayer(const char *name, const std::wstring msg);
+       void notifyPlayer(const char *name, const std::wstring msg, const bool prepend);
        void notifyPlayers(const std::wstring msg);
        void spawnParticle(const char *playername,
                v3f pos, v3f velocity, v3f acceleration,