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
 
@@ -1220,13 +1220,11 @@ CommandCost CmdGiveMoney(TileIndex tile,
 
		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());
 
		}
src/network/network.cpp
Show inline comments
 
@@ -367,9 +367,7 @@ void NetworkHandlePauseChange(PauseMode 
 
				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;
 
		}
 

	
src/network/network_admin.cpp
Show inline comments
 
@@ -133,11 +133,9 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	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);
 
}
 
@@ -316,20 +314,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
 */
 
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);
 
@@ -352,20 +343,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
 */
 
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
src/network/network_server.cpp
Show inline comments
 
@@ -432,7 +432,6 @@ NetworkRecvStatus ServerNetworkGameSocke
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, const char *reason)
 
{
 
	char str[100];
 
	Packet *p = new Packet(PACKET_SERVER_ERROR);
 

	
 
	p->Send_uint8(error);
 
@@ -440,7 +439,6 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	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) {
 
@@ -448,7 +446,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

	
 
		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);
 
@@ -469,7 +467,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

	
 
		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! */
 
@@ -1128,7 +1126,6 @@ NetworkRecvStatus ServerNetworkGameSocke
 
{
 
	/* 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();
 

	
 
@@ -1140,9 +1137,8 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	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);
 

	
 
@@ -1317,10 +1313,9 @@ void NetworkServerSendChat(NetworkAction
 
			/* 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()) {
src/newgrf.cpp
Show inline comments
 
@@ -7759,9 +7759,7 @@ static void TranslateGRFStrings(ByteRead
 
		 * 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;
 
	}
0 comments (0 inline, 0 general)