summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-30 13:34:58 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-06-10 21:53:19 +0200
commitab9b937ab7a80562b88d72ec17c6b2a6b3ed2b61 (patch)
tree6970eadafbf87b5ba319def028eb0641138f030b
parent849a10520cc26a98d91981a7705775a2481beef2 (diff)
downloadopenttd-ab9b937ab7a80562b88d72ec17c6b2a6b3ed2b61.tar.xz
Codechange: [Network] Use std::string to get a NewGRF's name
-rw-r--r--src/network/network_udp.cpp5
-rw-r--r--src/newgrf_text.cpp4
-rw-r--r--src/newgrf_text.h2
3 files changed, 5 insertions, 6 deletions
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 0da5a8b26..a0d9ae136 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -415,15 +415,14 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(Packet *p, NetworkAdd
if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
for (i = 0; i < num_grfs; i++) {
- char name[NETWORK_GRF_NAME_LENGTH];
GRFIdentifier c;
DeserializeGRFIdentifier(p, &c);
- p->Recv_string(name, sizeof(name));
+ std::string name = p->Recv_string(NETWORK_GRF_NAME_LENGTH);
/* An empty name is not possible under normal circumstances
* and causes problems when showing the NewGRF list. */
- if (StrEmpty(name)) continue;
+ if (name.empty()) continue;
/* Try to find the GRFTextWrapper for the name of this GRF ID and MD5sum tuple.
* If it exists and not resolved yet, then name of the fake GRF is
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index f1fac8b51..2bb8fd636 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -539,10 +539,10 @@ void AddGRFTextToList(GRFTextWrapper &list, byte langid, uint32 grfid, bool allo
* @param list The list where the text should be added to.
* @param text_to_add The text to add to the list.
*/
-void AddGRFTextToList(GRFTextWrapper &list, const char *text_to_add)
+void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add)
{
if (!list) list.reset(new GRFTextList());
- AddGRFTextToList(*list, GRFLX_UNSPECIFIED, std::string(text_to_add));
+ AddGRFTextToList(*list, GRFLX_UNSPECIFIED, text_to_add);
}
/**
diff --git a/src/newgrf_text.h b/src/newgrf_text.h
index 2c7eb731d..dc33710a4 100644
--- a/src/newgrf_text.h
+++ b/src/newgrf_text.h
@@ -42,7 +42,7 @@ void SetCurrentGrfLangID(byte language_id);
std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newlines, const std::string &str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID);
void AddGRFTextToList(GRFTextList &list, byte langid, uint32 grfid, bool allow_newlines, const char *text_to_add);
void AddGRFTextToList(GRFTextWrapper &list, byte langid, uint32 grfid, bool allow_newlines, const char *text_to_add);
-void AddGRFTextToList(GRFTextWrapper &list, const char *text_to_add);
+void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add);
bool CheckGrfLangID(byte lang_id, byte grf_version);