Changeset - r25621:b453557b6e79
[Not reviewed]
master
0 3 0
rubidium42 - 3 years ago 2021-05-30 11:34:58
rubidium@openttd.org
Codechange: [Network] Use std::string to get a NewGRF's name
3 files changed with 5 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/network/network_udp.cpp
Show inline comments
 
@@ -412,21 +412,20 @@ void ClientNetworkUDPSocketHandler::Rece
 
	DEBUG(net, 7, "NewGRF data reply from %s", client_addr->GetAddressAsString().c_str());
 

	
 
	num_grfs = p->Recv_uint8 ();
 
	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
 
		 * overwritten with the name from the reply. */
 
		GRFTextWrapper unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false);
 
		if (unknown_name && strcmp(GetGRFStringFromGRFText(unknown_name), UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
src/newgrf_text.cpp
Show inline comments
 
@@ -536,16 +536,16 @@ void AddGRFTextToList(GRFTextWrapper &li
 
/**
 
 * Add a GRFText to a GRFText list. The text should  not contain any text-codes.
 
 * The text will be added as a 'default language'-text.
 
 * @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);
 
}
 

	
 
/**
 
 * Add the new read string into our structure.
 
 */
 
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string)
src/newgrf_text.h
Show inline comments
 
@@ -39,13 +39,13 @@ const char *GetGRFStringFromGRFText(cons
 
const char *GetGRFStringPtr(uint16 stringid);
 
void CleanUpStrings();
 
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);
 

	
 
void StartTextRefStackUsage(const struct GRFFile *grffile, byte numEntries, const uint32 *values = nullptr);
 
void StopTextRefStackUsage();
 
void RewindTextRefStack();
0 comments (0 inline, 0 general)