summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-01-29 14:03:27 +0100
committersfan5 <sfan5@live.de>2021-02-02 20:46:08 +0100
commitc834d2ab25694ef2d67dc24f85f304269d202c8e (patch)
treec62a57d0cdbca950b9c7cb1a58666b6b77760bc2 /src/server.cpp
parent5e392cf34f8e062dd0533619921223656e32598a (diff)
downloadminetest-c834d2ab25694ef2d67dc24f85f304269d202c8e.tar.gz
minetest-c834d2ab25694ef2d67dc24f85f304269d202c8e.tar.bz2
minetest-c834d2ab25694ef2d67dc24f85f304269d202c8e.zip
Drop wide/narrow conversion functions
The only valid usecase for these is interfacing with OS APIs that want a locale/OS-specific multibyte encoding. But they weren't used for that anywhere, instead UTF-8 is pretty much assumed when it comes to that. Since these are only a potential source of bugs and do not fulfil their purpose at all, drop them entirely.
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp61
1 files changed, 23 insertions, 38 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 90496129e..907bc6d24 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2955,7 +2955,7 @@ void Server::handleChatInterfaceEvent(ChatEvent *evt)
}
}
-std::wstring Server::handleChat(const std::string &name, const std::wstring &wname,
+std::wstring Server::handleChat(const std::string &name,
std::wstring wmessage, bool check_shout_priv, RemotePlayer *player)
{
// If something goes wrong, this player is to blame
@@ -2993,7 +2993,7 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
auto message = trim(wide_to_utf8(wmessage));
if (message.find_first_of("\n\r") != std::wstring::npos) {
- return L"New lines are not permitted in chat messages";
+ return L"Newlines are not permitted in chat messages";
}
// Run script hook, exit if script ate the chat message
@@ -3014,10 +3014,10 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
the Cyrillic alphabet and some characters on older Android devices
*/
#ifdef __ANDROID__
- line += L"<" + wname + L"> " + wmessage;
+ line += L"<" + utf8_to_wide(name) + L"> " + wmessage;
#else
- line += narrow_to_wide(m_script->formatChatMessage(name,
- wide_to_narrow(wmessage)));
+ line += utf8_to_wide(m_script->formatChatMessage(name,
+ wide_to_utf8(wmessage)));
#endif
}
@@ -3030,35 +3030,23 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
/*
Send the message to others
*/
- actionstream << "CHAT: " << wide_to_narrow(unescape_enriched(line)) << std::endl;
+ actionstream << "CHAT: " << wide_to_utf8(unescape_enriched(line)) << std::endl;
- std::vector<session_t> clients = m_clients.getClientIDs();
-
- /*
- Send the message back to the inital sender
- if they are using protocol version >= 29
- */
-
- session_t peer_id_to_avoid_sending =
- (player ? player->getPeerId() : PEER_ID_INEXISTENT);
+ ChatMessage chatmsg(line);
- if (player && player->protocol_version >= 29)
- peer_id_to_avoid_sending = PEER_ID_INEXISTENT;
+ std::vector<session_t> clients = m_clients.getClientIDs();
+ for (u16 cid : clients)
+ SendChatMessage(cid, chatmsg);
- for (u16 cid : clients) {
- if (cid != peer_id_to_avoid_sending)
- SendChatMessage(cid, ChatMessage(line));
- }
return L"";
}
void Server::handleAdminChat(const ChatEventChat *evt)
{
std::string name = evt->nick;
- std::wstring wname = utf8_to_wide(name);
std::wstring wmessage = evt->evt_msg;
- std::wstring answer = handleChat(name, wname, wmessage);
+ std::wstring answer = handleChat(name, wmessage);
// If asked to send answer to sender
if (!answer.empty()) {
@@ -3095,46 +3083,43 @@ PlayerSAO *Server::getPlayerSAO(session_t peer_id)
return player->getPlayerSAO();
}
-std::wstring Server::getStatusString()
+std::string Server::getStatusString()
{
- std::wostringstream os(std::ios_base::binary);
- os << L"# Server: ";
+ std::ostringstream os(std::ios_base::binary);
+ os << "# Server: ";
// Version
- os << L"version=" << narrow_to_wide(g_version_string);
+ os << "version=" << g_version_string;
// Uptime
- os << L", uptime=" << m_uptime_counter->get();
+ os << ", uptime=" << m_uptime_counter->get();
// Max lag estimate
- os << L", max_lag=" << (m_env ? m_env->getMaxLagEstimate() : 0);
+ os << ", max_lag=" << (m_env ? m_env->getMaxLagEstimate() : 0);
// Information about clients
bool first = true;
- os << L", clients={";
+ os << ", clients={";
if (m_env) {
std::vector<session_t> clients = m_clients.getClientIDs();
for (session_t client_id : clients) {
RemotePlayer *player = m_env->getPlayer(client_id);
// Get name of player
- std::wstring name = L"unknown";
- if (player)
- name = narrow_to_wide(player->getName());
+ const char *name = player ? player->getName() : "<unknown>";
// Add name to information string
if (!first)
- os << L", ";
+ os << ", ";
else
first = false;
-
os << name;
}
}
- os << L"}";
+ os << "}";
if (m_env && !((ServerMap*)(&m_env->getMap()))->isSavingEnabled())
- os << std::endl << L"# Server: " << " WARNING: Map saving is disabled.";
+ os << std::endl << "# Server: " << " WARNING: Map saving is disabled.";
if (!g_settings->get("motd").empty())
- os << std::endl << L"# Server: " << narrow_to_wide(g_settings->get("motd"));
+ os << std::endl << "# Server: " << g_settings->get("motd");
return os.str();
}