@@ -2955,7 +2955,7 @@ void Server::handleChatInterfaceEvent(ChatEvent *evt)
2955
2955
}
2956
2956
}
2957
2957
2958
- std::wstring Server::handleChat (const std::string &name, const std::wstring &wname,
2958
+ std::wstring Server::handleChat (const std::string &name,
2959
2959
std::wstring wmessage, bool check_shout_priv, RemotePlayer *player)
2960
2960
{
2961
2961
// 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
2993
2993
2994
2994
auto message = trim (wide_to_utf8 (wmessage));
2995
2995
if (message.find_first_of (" \n\r " ) != std::wstring::npos) {
2996
- return L" New lines are not permitted in chat messages" ;
2996
+ return L" Newlines are not permitted in chat messages" ;
2997
2997
}
2998
2998
2999
2999
// 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
3014
3014
the Cyrillic alphabet and some characters on older Android devices
3015
3015
*/
3016
3016
#ifdef __ANDROID__
3017
- line += L" <" + wname + L" > " + wmessage;
3017
+ line += L" <" + utf8_to_wide (name) + L" > " + wmessage;
3018
3018
#else
3019
- line += narrow_to_wide (m_script->formatChatMessage (name,
3020
- wide_to_narrow (wmessage)));
3019
+ line += utf8_to_wide (m_script->formatChatMessage (name,
3020
+ wide_to_utf8 (wmessage)));
3021
3021
#endif
3022
3022
}
3023
3023
@@ -3030,35 +3030,23 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
3030
3030
/*
3031
3031
Send the message to others
3032
3032
*/
3033
- actionstream << " CHAT: " << wide_to_narrow (unescape_enriched (line)) << std::endl;
3033
+ actionstream << " CHAT: " << wide_to_utf8 (unescape_enriched (line)) << std::endl;
3034
3034
3035
- std::vector<session_t > clients = m_clients.getClientIDs ();
3036
-
3037
- /*
3038
- Send the message back to the inital sender
3039
- if they are using protocol version >= 29
3040
- */
3041
-
3042
- session_t peer_id_to_avoid_sending =
3043
- (player ? player->getPeerId () : PEER_ID_INEXISTENT);
3035
+ ChatMessage chatmsg (line);
3044
3036
3045
- if (player && player->protocol_version >= 29 )
3046
- peer_id_to_avoid_sending = PEER_ID_INEXISTENT;
3037
+ std::vector<session_t > clients = m_clients.getClientIDs ();
3038
+ for (u16 cid : clients)
3039
+ SendChatMessage (cid, chatmsg);
3047
3040
3048
- for (u16 cid : clients) {
3049
- if (cid != peer_id_to_avoid_sending)
3050
- SendChatMessage (cid, ChatMessage (line));
3051
- }
3052
3041
return L" " ;
3053
3042
}
3054
3043
3055
3044
void Server::handleAdminChat (const ChatEventChat *evt)
3056
3045
{
3057
3046
std::string name = evt->nick ;
3058
- std::wstring wname = utf8_to_wide (name);
3059
3047
std::wstring wmessage = evt->evt_msg ;
3060
3048
3061
- std::wstring answer = handleChat (name, wname, wmessage);
3049
+ std::wstring answer = handleChat (name, wmessage);
3062
3050
3063
3051
// If asked to send answer to sender
3064
3052
if (!answer.empty ()) {
@@ -3095,46 +3083,43 @@ PlayerSAO *Server::getPlayerSAO(session_t peer_id)
3095
3083
return player->getPlayerSAO ();
3096
3084
}
3097
3085
3098
- std::wstring Server::getStatusString ()
3086
+ std::string Server::getStatusString ()
3099
3087
{
3100
- std::wostringstream os (std::ios_base::binary);
3101
- os << L " # Server: " ;
3088
+ std::ostringstream os (std::ios_base::binary);
3089
+ os << " # Server: " ;
3102
3090
// Version
3103
- os << L " version=" << narrow_to_wide ( g_version_string) ;
3091
+ os << " version=" << g_version_string;
3104
3092
// Uptime
3105
- os << L " , uptime=" << m_uptime_counter->get ();
3093
+ os << " , uptime=" << m_uptime_counter->get ();
3106
3094
// Max lag estimate
3107
- os << L " , max_lag=" << (m_env ? m_env->getMaxLagEstimate () : 0 );
3095
+ os << " , max_lag=" << (m_env ? m_env->getMaxLagEstimate () : 0 );
3108
3096
3109
3097
// Information about clients
3110
3098
bool first = true ;
3111
- os << L " , clients={" ;
3099
+ os << " , clients={" ;
3112
3100
if (m_env) {
3113
3101
std::vector<session_t > clients = m_clients.getClientIDs ();
3114
3102
for (session_t client_id : clients) {
3115
3103
RemotePlayer *player = m_env->getPlayer (client_id);
3116
3104
3117
3105
// Get name of player
3118
- std::wstring name = L" unknown" ;
3119
- if (player)
3120
- name = narrow_to_wide (player->getName ());
3106
+ const char *name = player ? player->getName () : " <unknown>" ;
3121
3107
3122
3108
// Add name to information string
3123
3109
if (!first)
3124
- os << L " , " ;
3110
+ os << " , " ;
3125
3111
else
3126
3112
first = false ;
3127
-
3128
3113
os << name;
3129
3114
}
3130
3115
}
3131
- os << L " }" ;
3116
+ os << " }" ;
3132
3117
3133
3118
if (m_env && !((ServerMap*)(&m_env->getMap ()))->isSavingEnabled ())
3134
- os << std::endl << L " # Server: " << " WARNING: Map saving is disabled." ;
3119
+ os << std::endl << " # Server: " << " WARNING: Map saving is disabled." ;
3135
3120
3136
3121
if (!g_settings->get (" motd" ).empty ())
3137
- os << std::endl << L " # Server: " << narrow_to_wide ( g_settings->get (" motd" ) );
3122
+ os << std::endl << " # Server: " << g_settings->get (" motd" );
3138
3123
3139
3124
return os.str ();
3140
3125
}
0 commit comments