diff options
author | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-08 10:19:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-08 10:19:42 +0200 |
commit | e2774354b4f64a46992a74b399fb882aa075cfac (patch) | |
tree | 7e1930026642cc847fca437e7c2ea414de0fc4af /src/network | |
parent | a87999601294af97d8d914db232f24525d9248ce (diff) | |
download | openttd-e2774354b4f64a46992a74b399fb882aa075cfac.tar.xz |
Codechange: [Network] Change ChatMessage's message to std::string and simplify some code
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network.cpp | 2 | ||||
-rw-r--r-- | src/network/network_chat_gui.cpp | 15 | ||||
-rw-r--r-- | src/network/network_func.h | 2 |
3 files changed, 5 insertions, 14 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index bbf6bb5de..3965c200f 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -262,7 +262,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, DEBUG(desync, 1, "msg: %08x; %02x; %s", _date, _date_fract, message); IConsolePrintF(colour, "%s", message); - NetworkAddChatMessage((TextColour)colour, _settings_client.gui.network_chat_timeout, "%s", message); + NetworkAddChatMessage((TextColour)colour, _settings_client.gui.network_chat_timeout, message); } /* Calculate the frame-lag of a client */ diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 14edc1503..e8fbf0f12 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -39,7 +39,7 @@ static const uint NETWORK_CHAT_LINE_SPACING = 3; /** Container for a message. */ struct ChatMessage { - char message[DRAW_STRING_BUFFER]; ///< The action message. + std::string message; ///< The action message. TextColour colour; ///< The colour of the message. std::chrono::steady_clock::time_point remove_time; ///< The time to remove the message. }; @@ -87,23 +87,14 @@ static inline bool HaveChatMessages(bool show_all) * @param duration The duration of the chat message in seconds * @param message message itself in printf() style */ -void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...) +void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message) { - char buf[DRAW_STRING_BUFFER]; - va_list va; - - va_start(va, message); - vseprintf(buf, lastof(buf), message, va); - va_end(va); - - Utf8TrimString(buf, DRAW_STRING_BUFFER); - if (_chatmsg_list.size() == MAX_CHAT_MESSAGES) { _chatmsg_list.pop_back(); } ChatMessage *cmsg = &_chatmsg_list.emplace_front(); - strecpy(cmsg->message, buf, lastof(cmsg->message)); + cmsg->message = message; cmsg->colour = (colour & TC_IS_PALETTE_COLOUR) ? colour : TC_WHITE; cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration); diff --git a/src/network/network_func.h b/src/network/network_func.h index ef81b0fb1..e7709d307 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -84,7 +84,7 @@ uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason); uint NetworkServerKickOrBanIP(const char *ip, bool ban, const char *reason); void NetworkInitChatMessage(); -void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...) WARN_FORMAT(3, 4); +void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message); void NetworkUndrawChatMessage(); void NetworkChatMessageLoop(); |