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 */
| 232 | * (to keep it all a bit more general) |
| 233 | * If 'self_send' is true, this is the client who is sending the message */ |
| 234 | void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, std::string_view name, std::string_view str, StringParameter &&data) |
| 235 | { |
| 236 | std::string message; |
| 237 | StringBuilder builder(message); |
| 238 | |
| 239 | /* All of these strings start with "***". These characters are interpreted as both left-to-right and |
| 240 | * right-to-left characters depending on the context. As the next text might be an user's name, the |
| 241 | * user name's characters will influence the direction of the "***" instead of the language setting |
| 242 | * of the game. Manually set the direction of the "***" by inserting a text-direction marker. */ |
| 243 | builder.PutUtf8(_current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM); |
| 244 | |
| 245 | switch (action) { |
| 246 | case NETWORK_ACTION_SERVER_MESSAGE: |
| 247 | /* Ignore invalid messages */ |
| 248 | builder += GetString(STR_NETWORK_SERVER_MESSAGE, str); |
| 249 | colour = CC_DEFAULT; |
| 250 | break; |
| 251 | case NETWORK_ACTION_COMPANY_SPECTATOR: |
| 252 | colour = CC_DEFAULT; |
| 253 | builder += GetString(STR_NETWORK_MESSAGE_CLIENT_COMPANY_SPECTATE, name); |
| 254 | break; |
| 255 | case NETWORK_ACTION_COMPANY_JOIN: |
| 256 | colour = CC_DEFAULT; |
| 257 | builder += GetString(STR_NETWORK_MESSAGE_CLIENT_COMPANY_JOIN, name, str); |
| 258 | break; |
| 259 | case NETWORK_ACTION_COMPANY_NEW: |
| 260 | colour = CC_DEFAULT; |
| 261 | builder += GetString(STR_NETWORK_MESSAGE_CLIENT_COMPANY_NEW, name, std::move(data)); |
| 262 | break; |
| 263 | case NETWORK_ACTION_JOIN: |
| 264 | /* Show the Client ID for the server but not for the client. */ |
| 265 | builder += _network_server ? |
| 266 | GetString(STR_NETWORK_MESSAGE_CLIENT_JOINED_ID, name, std::move(data)) : |
| 267 | GetString(STR_NETWORK_MESSAGE_CLIENT_JOINED, name); |
| 268 | break; |
| 269 | case NETWORK_ACTION_LEAVE: builder += GetString(STR_NETWORK_MESSAGE_CLIENT_LEFT, name, std::move(data)); break; |
| 270 | case NETWORK_ACTION_NAME_CHANGE: builder += GetString(STR_NETWORK_MESSAGE_NAME_CHANGE, name, str); break; |
| 271 | case NETWORK_ACTION_GIVE_MONEY: builder += GetString(STR_NETWORK_MESSAGE_GIVE_MONEY, name, std::move(data), str); break; |
| 272 | case NETWORK_ACTION_KICKED: builder += GetString(STR_NETWORK_MESSAGE_KICKED, name, str); break; |
| 273 | case NETWORK_ACTION_CHAT_COMPANY: builder += GetString(self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY, name, str); break; |
| 274 | case NETWORK_ACTION_CHAT_CLIENT: builder += GetString(self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT, name, str); break; |
| 275 | case NETWORK_ACTION_EXTERNAL_CHAT: builder += GetString(STR_NETWORK_CHAT_EXTERNAL, std::move(data), name, str); break; |
| 276 | default: builder += GetString(STR_NETWORK_CHAT_ALL, name, str); break; |
| 277 | } |
| 278 | |
| 279 | Debug(desync, 1, "msg: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, message); |
| 280 | IConsolePrint(colour, message); |
| 281 | NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message); |
| 282 | } |
| 283 | |
| 284 | /* Calculate the frame-lag of a client */ |
| 285 | uint NetworkCalculateLag(const NetworkClientSocket *cs) |
no test coverage detected