Changeset - r25487:e8c958a8b290
[Not reviewed]
master
0 5 0
rubidium42 - 4 years ago 2021-05-14 16:45:54
rubidium@openttd.org
Codechange: Use std::string GetString where convenient
5 files changed with 18 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -1217,19 +1217,17 @@ CommandCost CmdGiveMoney(TileIndex tile,
 
		/* Add money to company */
 
		Backup<CompanyID> cur_company(_current_company, dest_company, FILE_LINE);
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
 
		cur_company.Restore();
 

	
 
		if (_networking) {
 
			char dest_company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
 
			SetDParam(0, dest_company);
 
			GetString(dest_company_name, STR_COMPANY_NAME, lastof(dest_company_name));
 
			std::string dest_company_name = GetString(STR_COMPANY_NAME);
 

	
 
			char from_company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
 
			SetDParam(0, _current_company);
 
			GetString(from_company_name, STR_COMPANY_NAME, lastof(from_company_name));
 
			std::string from_company_name = GetString(STR_COMPANY_NAME);
 

	
 
			NetworkTextMessage(NETWORK_ACTION_GIVE_MONEY, GetDrawStringCompanyColour(_current_company), false, from_company_name, dest_company_name, amount.GetCost());
 
		}
 
	}
 

	
 
	/* Subtract money from local-company */
src/network/network.cpp
Show inline comments
 
@@ -364,15 +364,13 @@ void NetworkHandlePauseChange(PauseMode 
 
					case PM_PAUSED_LINK_GRAPH:     SetDParam(0, STR_NETWORK_SERVER_MESSAGE_GAME_REASON_LINK_GRAPH); break;
 
					default: NOT_REACHED();
 
				}
 
				str = paused ? STR_NETWORK_SERVER_MESSAGE_GAME_PAUSED : STR_NETWORK_SERVER_MESSAGE_GAME_UNPAUSED;
 
			}
 

	
 
			char buffer[DRAW_STRING_BUFFER];
 
			GetString(buffer, str, lastof(buffer));
 
			NetworkTextMessage(NETWORK_ACTION_SERVER_MESSAGE, CC_DEFAULT, false, "", buffer);
 
			NetworkTextMessage(NETWORK_ACTION_SERVER_MESSAGE, CC_DEFAULT, false, "", GetString(str));
 
			break;
 
		}
 

	
 
		default:
 
			return;
 
	}
src/network/network_admin.cpp
Show inline comments
 
@@ -130,17 +130,15 @@ NetworkRecvStatus ServerNetworkAdminSock
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_ERROR);
 

	
 
	p->Send_uint8(error);
 
	this->SendPacket(p);
 

	
 
	char str[100];
 
	StringID strid = GetNetworkErrorMsg(error);
 
	GetString(str, strid, lastof(str));
 
	std::string error_message = GetString(GetNetworkErrorMsg(error));
 

	
 
	DEBUG(net, 1, "[admin] The admin '%s' (%s) made an error and has been disconnected: '%s'", this->admin_name, this->admin_version, str);
 
	DEBUG(net, 1, "[admin] The admin '%s' (%s) made an error and has been disconnected: '%s'", this->admin_name, this->admin_version, error_message.c_str());
 

	
 
	return this->CloseConnection(true);
 
}
 

	
 
/** Send the protocol version to the admin. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol()
 
@@ -313,26 +311,19 @@ NetworkRecvStatus ServerNetworkAdminSock
 
/**
 
 * Send the admin some information about a company.
 
 * @param c The company to send the information about.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company *c)
 
{
 
	char company_name[NETWORK_COMPANY_NAME_LENGTH];
 
	char manager_name[NETWORK_COMPANY_NAME_LENGTH];
 

	
 
	SetDParam(0, c->index);
 
	GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
	SetDParam(0, c->index);
 
	GetString(manager_name, STR_PRESIDENT_NAME, lastof(manager_name));
 

	
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_INFO);
 

	
 
	p->Send_uint8 (c->index);
 
	p->Send_string(company_name);
 
	p->Send_string(manager_name);
 
	SetDParam(0, c->index);
 
	p->Send_string(GetString(STR_COMPANY_NAME));
 
	SetDParam(0, c->index);
 
	p->Send_string(GetString(STR_PRESIDENT_NAME));
 
	p->Send_uint8 (c->colour);
 
	p->Send_bool  (NetworkCompanyIsPassworded(c->index));
 
	p->Send_uint32(c->inaugurated_year);
 
	p->Send_bool  (c->is_ai);
 
	p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy
 

	
 
@@ -349,26 +340,19 @@ NetworkRecvStatus ServerNetworkAdminSock
 
/**
 
 * Send an update about a company.
 
 * @param c The company to send the update of.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Company *c)
 
{
 
	char company_name[NETWORK_COMPANY_NAME_LENGTH];
 
	char manager_name[NETWORK_COMPANY_NAME_LENGTH];
 

	
 
	SetDParam(0, c->index);
 
	GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
	SetDParam(0, c->index);
 
	GetString(manager_name, STR_PRESIDENT_NAME, lastof(manager_name));
 

	
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_UPDATE);
 

	
 
	p->Send_uint8 (c->index);
 
	p->Send_string(company_name);
 
	p->Send_string(manager_name);
 
	SetDParam(0, c->index);
 
	p->Send_string(GetString(STR_COMPANY_NAME));
 
	SetDParam(0, c->index);
 
	p->Send_string(GetString(STR_PRESIDENT_NAME));
 
	p->Send_uint8 (c->colour);
 
	p->Send_bool  (NetworkCompanyIsPassworded(c->index));
 
	p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy
 

	
 
	for (size_t i = 0; i < lengthof(c->share_owners); i++) {
 
		p->Send_uint8(c->share_owners[i]);
src/network/network_server.cpp
Show inline comments
 
@@ -429,29 +429,27 @@ NetworkRecvStatus ServerNetworkGameSocke
 
 * Send an error to the client, and close its connection.
 
 * @param error The error to disconnect for.
 
 * @param reason In case of kicking a client, specifies the reason for kicking the client.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, const char *reason)
 
{
 
	char str[100];
 
	Packet *p = new Packet(PACKET_SERVER_ERROR);
 

	
 
	p->Send_uint8(error);
 
	if (reason != nullptr) p->Send_string(reason);
 
	this->SendPacket(p);
 

	
 
	StringID strid = GetNetworkErrorMsg(error);
 
	GetString(str, strid, lastof(str));
 

	
 
	/* Only send when the current client was in game */
 
	if (this->status > STATUS_AUTHORIZED) {
 
		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 

	
 
		this->GetClientName(client_name, lastof(client_name));
 

	
 
		DEBUG(net, 1, "'%s' made an error and has been disconnected: %s", client_name, str);
 
		DEBUG(net, 1, "'%s' made an error and has been disconnected: %s", client_name, GetString(strid).c_str());
 

	
 
		if (error == NETWORK_ERROR_KICKED && reason != nullptr) {
 
			NetworkTextMessage(NETWORK_ACTION_KICKED, CC_DEFAULT, false, client_name, reason, strid);
 
		} else {
 
			NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", strid);
 
		}
 
@@ -466,13 +464,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
				new_cs->SendErrorQuit(this->client_id, error);
 
			}
 
		}
 

	
 
		NetworkAdminClientError(this->client_id, error);
 
	} else {
 
		DEBUG(net, 1, "Client %d made an error and has been disconnected: %s", this->client_id, str);
 
		DEBUG(net, 1, "Client %d made an error and has been disconnected: %s", this->client_id, GetString(strid).c_str());
 
	}
 

	
 
	/* The client made a mistake, so drop the connection now! */
 
	return this->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
 
}
 

	
 
@@ -1125,27 +1123,25 @@ NetworkRecvStatus ServerNetworkGameSocke
 
}
 

	
 
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p)
 
{
 
	/* This packets means a client noticed an error and is reporting this
 
	 *  to us. Display the error and report it to the other clients */
 
	char str[100];
 
	char client_name[NETWORK_CLIENT_NAME_LENGTH];
 
	NetworkErrorCode errorno = (NetworkErrorCode)p->Recv_uint8();
 

	
 
	/* The client was never joined.. thank the client for the packet, but ignore it */
 
	if (this->status < STATUS_DONE_MAP || this->HasClientQuit()) {
 
		return this->CloseConnection(NETWORK_RECV_STATUS_CLIENT_QUIT);
 
	}
 

	
 
	this->GetClientName(client_name, lastof(client_name));
 

	
 
	StringID strid = GetNetworkErrorMsg(errorno);
 
	GetString(str, strid, lastof(str));
 

	
 
	DEBUG(net, 1, "'%s' reported an error and is closing its connection: %s", client_name, str);
 
	DEBUG(net, 1, "'%s' reported an error and is closing its connection: %s", client_name, GetString(strid).c_str());
 

	
 
	NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", strid);
 

	
 
	for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
		if (new_cs->status >= STATUS_AUTHORIZED) {
 
			new_cs->SendErrorQuit(this->client_id, errorno);
 
@@ -1314,16 +1310,15 @@ void NetworkServerSendChat(NetworkAction
 
			/* There is no such client */
 
			if (ci_to == nullptr) break;
 

	
 
			/* Display the message locally (so you know you have sent it) */
 
			if (ci != nullptr && show_local) {
 
				if (from_id == CLIENT_ID_SERVER) {
 
					char name[NETWORK_NAME_LENGTH];
 
					StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
 
					SetDParam(0, ci_to->client_playas);
 
					GetString(name, str, lastof(name));
 
					std::string name = GetString(str);
 
					NetworkTextMessage(action, GetDrawStringCompanyColour(ci_own->client_playas), true, name, msg, data);
 
				} else {
 
					for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
 
						if (cs->client_id == from_id) {
 
							cs->SendChat(action, ci_to->client_id, true, msg, data);
 
						}
src/newgrf.cpp
Show inline comments
 
@@ -7756,15 +7756,13 @@ static void TranslateGRFStrings(ByteRead
 

	
 
	if (c->status == GCS_INITIALISED) {
 
		/* If the file is not active but will be activated later, give an error
 
		 * and disable this file. */
 
		GRFError *error = DisableGrf(STR_NEWGRF_ERROR_LOAD_AFTER);
 

	
 
		char tmp[256];
 
		GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
 
		error->data = tmp;
 
		error->data = GetString(STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE);
 

	
 
		return;
 
	}
 

	
 
	/* Since no language id is supplied for with version 7 and lower NewGRFs, this string has
 
	 * to be added as a generic string, thus the language id of 0x7F. For this to work
0 comments (0 inline, 0 general)