1
0
Fork 0

Codechange: Use parameterised GetString for NetworkTextMessage

pull/13678/head
Rubidium 2025-03-01 11:45:16 +01:00 committed by rubidium42
parent 6d2f17b92f
commit 8886503ba9
5 changed files with 29 additions and 31 deletions

View File

@ -2567,7 +2567,7 @@ STR_NETWORK_CHAT_TO_COMPANY :[Team] To {RAW_
STR_NETWORK_CHAT_CLIENT :[Private] {RAW_STRING}: {WHITE}{RAW_STRING}
STR_NETWORK_CHAT_TO_CLIENT :[Private] To {RAW_STRING}: {WHITE}{RAW_STRING}
STR_NETWORK_CHAT_ALL :[All] {RAW_STRING}: {WHITE}{RAW_STRING}
STR_NETWORK_CHAT_EXTERNAL :[{3:RAW_STRING}] {0:RAW_STRING}: {WHITE}{1:RAW_STRING}
STR_NETWORK_CHAT_EXTERNAL :[{RAW_STRING}] {RAW_STRING}: {WHITE}{RAW_STRING}
STR_NETWORK_CHAT_OSKTITLE :{BLACK}Enter text for network chat
# Network messages
@ -2625,7 +2625,7 @@ STR_NETWORK_ERROR_CLIENT_TIMEOUT_JOIN :processing map
STR_NETWORK_ERROR_CLIENT_INVALID_CLIENT_NAME :invalid client name
# Network related errors
STR_NETWORK_SERVER_MESSAGE :*** {1:RAW_STRING}
STR_NETWORK_SERVER_MESSAGE :*** {RAW_STRING}
###length 12
STR_NETWORK_SERVER_MESSAGE_GAME_PAUSED :Game paused ({STRING})
@ -2643,13 +2643,13 @@ STR_NETWORK_SERVER_MESSAGE_GAME_REASON_LINK_GRAPH :waiting for lin
STR_NETWORK_MESSAGE_CLIENT_LEAVING :leaving
STR_NETWORK_MESSAGE_CLIENT_JOINED :*** {RAW_STRING} has joined the game
STR_NETWORK_MESSAGE_CLIENT_JOINED_ID :*** {0:RAW_STRING} has joined the game (Client #{2:NUM})
STR_NETWORK_MESSAGE_CLIENT_JOINED_ID :*** {RAW_STRING} has joined the game (Client #{NUM})
STR_NETWORK_MESSAGE_CLIENT_COMPANY_JOIN :*** {RAW_STRING} has joined {RAW_STRING}
STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE :*** {RAW_STRING} has joined spectators
STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW :*** {0:RAW_STRING} has started a new company (#{2:NUM})
STR_NETWORK_MESSAGE_CLIENT_LEFT :*** {0:RAW_STRING} has left the game ({2:STRING})
STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW :*** {RAW_STRING} has started a new company (#{NUM})
STR_NETWORK_MESSAGE_CLIENT_LEFT :*** {RAW_STRING} has left the game ({STRING})
STR_NETWORK_MESSAGE_NAME_CHANGE :*** {RAW_STRING} has changed their name to {RAW_STRING}
STR_NETWORK_MESSAGE_GIVE_MONEY :*** {0:RAW_STRING} gave {2:CURRENCY_LONG} to {1:RAW_STRING}
STR_NETWORK_MESSAGE_GIVE_MONEY :*** {RAW_STRING} gave {CURRENCY_LONG} to {RAW_STRING}
STR_NETWORK_MESSAGE_SERVER_SHUTDOWN :{WHITE}The server closed the session
STR_NETWORK_MESSAGE_SERVER_REBOOT :{WHITE}The server is restarting...{}Please wait...
STR_NETWORK_MESSAGE_KICKED :*** {RAW_STRING} was kicked. Reason: ({RAW_STRING})

View File

@ -229,46 +229,43 @@ uint8_t NetworkSpectatorCount()
/* This puts a text-message to the console, or in the future, the chat-box,
* (to keep it all a bit more general)
* If 'self_send' is true, this is the client who is sending the message */
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str, int64_t data, const std::string &data_str)
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str, StringParameter &&data)
{
StringID strid;
std::string string;
switch (action) {
case NETWORK_ACTION_SERVER_MESSAGE:
/* Ignore invalid messages */
strid = STR_NETWORK_SERVER_MESSAGE;
string = GetString(STR_NETWORK_SERVER_MESSAGE, str);
colour = CC_DEFAULT;
break;
case NETWORK_ACTION_COMPANY_SPECTATOR:
colour = CC_DEFAULT;
strid = STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE;
string = GetString(STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE, name);
break;
case NETWORK_ACTION_COMPANY_JOIN:
colour = CC_DEFAULT;
strid = STR_NETWORK_MESSAGE_CLIENT_COMPANY_JOIN;
string = GetString(STR_NETWORK_MESSAGE_CLIENT_COMPANY_JOIN, name, str);
break;
case NETWORK_ACTION_COMPANY_NEW:
colour = CC_DEFAULT;
strid = STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW;
string = GetString(STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW, name, std::move(data));
break;
case NETWORK_ACTION_JOIN:
/* Show the Client ID for the server but not for the client. */
strid = _network_server ? STR_NETWORK_MESSAGE_CLIENT_JOINED_ID : STR_NETWORK_MESSAGE_CLIENT_JOINED;
string = _network_server ?
GetString(STR_NETWORK_MESSAGE_CLIENT_JOINED_ID, name, std::move(data)) :
GetString(STR_NETWORK_MESSAGE_CLIENT_JOINED, name);
break;
case NETWORK_ACTION_LEAVE: strid = STR_NETWORK_MESSAGE_CLIENT_LEFT; break;
case NETWORK_ACTION_NAME_CHANGE: strid = STR_NETWORK_MESSAGE_NAME_CHANGE; break;
case NETWORK_ACTION_GIVE_MONEY: strid = STR_NETWORK_MESSAGE_GIVE_MONEY; break;
case NETWORK_ACTION_CHAT_COMPANY: strid = self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY; break;
case NETWORK_ACTION_CHAT_CLIENT: strid = self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT; break;
case NETWORK_ACTION_KICKED: strid = STR_NETWORK_MESSAGE_KICKED; break;
case NETWORK_ACTION_EXTERNAL_CHAT: strid = STR_NETWORK_CHAT_EXTERNAL; break;
default: strid = STR_NETWORK_CHAT_ALL; break;
case NETWORK_ACTION_LEAVE: string = GetString(STR_NETWORK_MESSAGE_CLIENT_LEFT, name, std::move(data)); break;
case NETWORK_ACTION_NAME_CHANGE: string = GetString(STR_NETWORK_MESSAGE_NAME_CHANGE, name, str); break;
case NETWORK_ACTION_GIVE_MONEY: string = GetString(STR_NETWORK_MESSAGE_GIVE_MONEY, name, std::move(data), str); break;
case NETWORK_ACTION_KICKED: string = GetString(STR_NETWORK_MESSAGE_KICKED, name, str); break;
case NETWORK_ACTION_CHAT_COMPANY: string = GetString(self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY, name, str); break;
case NETWORK_ACTION_CHAT_CLIENT: string = GetString(self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT, name, str); break;
case NETWORK_ACTION_EXTERNAL_CHAT: string = GetString(STR_NETWORK_CHAT_EXTERNAL, std::move(data), name, str); break;
default: string = GetString(STR_NETWORK_CHAT_ALL, name, str); break;
}
SetDParamStr(0, name);
SetDParamStr(1, str);
SetDParam(2, data);
SetDParamStr(3, data_str);
/* All of these strings start with "***". These characters are interpreted as both left-to-right and
* right-to-left characters depending on the context. As the next text might be an user's name, the
* user name's characters will influence the direction of the "***" instead of the language setting
@ -276,7 +273,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
std::ostringstream stream;
std::ostreambuf_iterator<char> iterator(stream);
Utf8Encode(iterator, _current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM);
std::string message = stream.str() + GetString(strid);
std::string message = stream.str() + string;
Debug(desync, 1, "msg: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, message);
IConsolePrint(colour, message);

View File

@ -1004,7 +1004,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(P
if (!IsValidConsoleColour(colour)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, source);
return NETWORK_RECV_STATUS_OKAY;
}

View File

@ -17,6 +17,7 @@
#include "../command_type.h"
#include "../command_func.h"
#include "../misc/endian_buffer.hpp"
#include "../strings_type.h"
#ifdef RANDOM_DEBUG
/**
@ -110,7 +111,7 @@ void NetworkSyncCommandQueue(NetworkClientSocket *cs);
void NetworkReplaceCommandClientId(CommandPacket &cp, ClientID client_id);
void ShowNetworkError(StringID error_string);
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str = "", int64_t data = 0, const std::string &data_str = "");
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str = "", StringParameter &&data = {});
uint NetworkCalculateLag(const NetworkClientSocket *cs);
StringID GetNetworkErrorMsg(NetworkErrorCode err);
bool NetworkMakeClientNameUnique(std::string &new_name);

View File

@ -1352,7 +1352,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci = NetworkClientInfo::GetByClientID(from_id);
if (ci != nullptr) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data, "");
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
}
break;
}
@ -1370,7 +1370,7 @@ void NetworkServerSendExternalChat(const std::string &source, TextColour colour,
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) cs->SendExternalChat(source, colour, user, msg);
}
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, source);
}
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet &p)