Changeset - r25485:a78d3ba0b5ae
[Not reviewed]
master
0 4 0
rubidium42 - 3 years ago 2021-05-14 16:12:37
rubidium@openttd.org
Codechange: [Network] Let NetworkTextMessage use std::string
4 files changed with 10 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/network/network.cpp
Show inline comments
 
@@ -214,7 +214,7 @@ bool NetworkCompanyIsPassworded(CompanyI
 
/* This puts a text-message to the console, or in the future, the chat-box,
 
 *  (to keep it all a bit more general)
 
 * If 'self_send' is true, this is the client who is sending the message */
 
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str, int64 data)
 
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str, int64 data)
 
{
 
	StringID strid;
 
	switch (action) {
 
@@ -369,7 +369,7 @@ void NetworkHandlePauseChange(PauseMode 
 

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

	
src/network/network_client.cpp
Show inline comments
 
@@ -1078,7 +1078,7 @@ NetworkRecvStatus ClientNetworkGameSocke
 

	
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci != nullptr) {
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, nullptr, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "", GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
 
		delete ci;
 
	}
 

	
 
@@ -1095,7 +1095,7 @@ NetworkRecvStatus ClientNetworkGameSocke
 

	
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
	if (ci != nullptr) {
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "", STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 
		delete ci;
 
	} else {
 
		DEBUG(net, 1, "Unknown client (%d) is leaving the game", client_id);
src/network/network_internal.h
Show inline comments
 
@@ -114,7 +114,7 @@ void NetworkFreeLocalCommandQueue();
 
void NetworkSyncCommandQueue(NetworkClientSocket *cs);
 

	
 
void ShowNetworkError(StringID error_string);
 
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
 
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str = "", int64 data = 0);
 
uint NetworkCalculateLag(const NetworkClientSocket *cs);
 
StringID GetNetworkErrorMsg(NetworkErrorCode err);
 
bool NetworkFindName(char *new_name, const char *last);
src/network/network_server.cpp
Show inline comments
 
@@ -262,7 +262,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

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

	
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, nullptr, STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
 

	
 
		/* Inform other clients of this... strange leaving ;) */
 
		for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
@@ -453,7 +453,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		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, nullptr, strid);
 
			NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", strid);
 
		}
 

	
 
		for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
@@ -1021,7 +1021,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

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

	
 
		NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, nullptr, this->client_id);
 
		NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, "", this->client_id);
 
		InvalidateWindowData(WC_CLIENT_LIST, 0);
 

	
 
		/* Mark the client as pre-active, and wait for an ACK
 
@@ -1144,7 +1144,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

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

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

	
 
	for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
		if (new_cs->status >= STATUS_AUTHORIZED) {
 
@@ -1170,7 +1170,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

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

	
 
	NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 
	NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 

	
 
	for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
		if (new_cs->status >= STATUS_AUTHORIZED && new_cs != this) {
0 comments (0 inline, 0 general)