summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defaultsettings.cpp1
-rw-r--r--src/gettime.h1
-rw-r--r--src/script/cpp_api/s_server.cpp22
-rw-r--r--src/script/cpp_api/s_server.h12
-rw-r--r--src/server.cpp40
5 files changed, 50 insertions, 26 deletions
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 4c39a44e1..b6ab7c9a0 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -356,6 +356,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("kick_msg_crash", "This server has experienced an internal error. You will now be disconnected.");
settings->setDefault("ask_reconnect_on_crash", "false");
+ settings->setDefault("chat_message_format", "<@name> @message");
settings->setDefault("profiler_print_interval", "0");
settings->setDefault("active_object_send_range_blocks", "4");
settings->setDefault("active_block_range", "3");
diff --git a/src/gettime.h b/src/gettime.h
index f20728dfd..66efef1d7 100644
--- a/src/gettime.h
+++ b/src/gettime.h
@@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
-#include "irrlichttypes.h"
#include <ctime>
#include <string>
diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp
index 3b461a2a3..1ce2f9d45 100644
--- a/src/script/cpp_api/s_server.cpp
+++ b/src/script/cpp_api/s_server.cpp
@@ -168,3 +168,25 @@ void ScriptApiServer::on_shutdown()
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
}
+std::string ScriptApiServer::formatChatMessage(const std::string &name,
+ const std::string &message)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Push function onto stack
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "format_chat_message");
+
+ // Push arguments onto stack
+ lua_pushstring(L, name.c_str());
+ lua_pushstring(L, message.c_str());
+
+ // Actually call the function
+ lua_call(L, 2, 1);
+
+ // Fetch return value
+ std::string ret = lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ return ret;
+}
diff --git a/src/script/cpp_api/s_server.h b/src/script/cpp_api/s_server.h
index 769939d3f..a4cede84d 100644
--- a/src/script/cpp_api/s_server.h
+++ b/src/script/cpp_api/s_server.h
@@ -36,14 +36,18 @@ public:
// Calls on_shutdown handlers
void on_shutdown();
+ // Calls core.format_chat_message
+ std::string formatChatMessage(const std::string &name,
+ const std::string &message);
+
/* auth */
bool getAuth(const std::string &playername,
- std::string *dst_password,
- std::set<std::string> *dst_privs);
+ std::string *dst_password,
+ std::set<std::string> *dst_privs);
void createAuth(const std::string &playername,
- const std::string &password);
+ const std::string &password);
bool setPassword(const std::string &playername,
- const std::string &password);
+ const std::string &password);
private:
void getAuthHandler();
void readPrivileges(int index, std::set<std::string> &result);
diff --git a/src/server.cpp b/src/server.cpp
index 7e6208711..27388e666 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1571,7 +1571,7 @@ void Server::SendChatMessage(session_t peer_id, const ChatMessage &message)
}
void Server::SendShowFormspecMessage(session_t peer_id, const std::string &formspec,
- const std::string &formname)
+ const std::string &formname)
{
NetworkPacket pkt(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id);
if (formspec.empty()){
@@ -2863,28 +2863,28 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
{
// If something goes wrong, this player is to blame
RollbackScopeActor rollback_scope(m_rollback,
- std::string("player:") + name);
+ std::string("player:") + name);
if (g_settings->getBool("strip_color_codes"))
wmessage = unescape_enriched(wmessage);
if (player) {
switch (player->canSendChatMessage()) {
- case RPLAYER_CHATRESULT_FLOODING: {
- std::wstringstream ws;
- ws << L"You cannot send more messages. You are limited to "
- << g_settings->getFloat("chat_message_limit_per_10sec")
- << L" messages per 10 seconds.";
- return ws.str();
- }
- case RPLAYER_CHATRESULT_KICK:
- DenyAccess_Legacy(player->getPeerId(),
- L"You have been kicked due to message flooding.");
- return L"";
- case RPLAYER_CHATRESULT_OK:
- break;
- default:
- FATAL_ERROR("Unhandled chat filtering result found.");
+ case RPLAYER_CHATRESULT_FLOODING: {
+ std::wstringstream ws;
+ ws << L"You cannot send more messages. You are limited to "
+ << g_settings->getFloat("chat_message_limit_per_10sec")
+ << L" messages per 10 seconds.";
+ return ws.str();
+ }
+ case RPLAYER_CHATRESULT_KICK:
+ DenyAccess_Legacy(player->getPeerId(),
+ L"You have been kicked due to message flooding.");
+ return L"";
+ case RPLAYER_CHATRESULT_OK:
+ break;
+ default:
+ FATAL_ERROR("Unhandled chat filtering result found.");
}
}
@@ -2912,10 +2912,8 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
line += L"-!- You don't have permission to shout.";
broadcast_line = false;
} else {
- line += L"<";
- line += wname;
- line += L"> ";
- line += wmessage;
+ line += narrow_to_wide(m_script->formatChatMessage(name,
+ wide_to_narrow(wmessage)));
}
/*