summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_admin.cpp7
-rw-r--r--src/network/network_admin.h4
-rw-r--r--src/network/network_chat_gui.cpp4
-rw-r--r--src/network/network_client.cpp14
-rw-r--r--src/network/network_client.h2
-rw-r--r--src/network/network_func.h4
-rw-r--r--src/network/network_server.cpp7
-rw-r--r--src/network/network_server.h2
8 files changed, 21 insertions, 23 deletions
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index 419de71d1..09b039485 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -450,7 +450,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
* @param msg The actual message.
* @param data Arbitrary extra data.
*/
-NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64 data)
{
Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT);
@@ -769,8 +769,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
DestType desttype = (DestType)p->Recv_uint8();
int dest = p->Recv_uint32();
- char msg[NETWORK_CHAT_LENGTH];
- p->Recv_string(msg, NETWORK_CHAT_LENGTH);
+ std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
switch (action) {
case NETWORK_ACTION_CHAT:
@@ -902,7 +901,7 @@ void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bc
/**
* Send chat to the admin network (if they did opt in for the respective update).
*/
-void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data, bool from_admin)
+void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64 data, bool from_admin)
{
if (from_admin) return;
diff --git a/src/network/network_admin.h b/src/network/network_admin.h
index cf6cf6e7c..0e443d08f 100644
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -61,7 +61,7 @@ public:
NetworkRecvStatus SendCompanyEconomy();
NetworkRecvStatus SendCompanyStats();
- NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
+ NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64 data);
NetworkRecvStatus SendRcon(uint16 colour, const char *command);
NetworkRecvStatus SendConsole(const char *origin, const char *command);
NetworkRecvStatus SendGameScript(const char *json);
@@ -106,7 +106,7 @@ void NetworkAdminCompanyInfo(const Company *company, bool new_company);
void NetworkAdminCompanyUpdate(const Company *company);
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
-void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
+void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64 data = 0, bool from_admin = false);
void NetworkAdminUpdate(AdminUpdateFrequency freq);
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
void NetworkAdminConsole(const char *origin, const char *string);
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 82d9a819b..f8eaf3bda 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -259,9 +259,9 @@ void NetworkDrawChatMessage()
* @param type The type of destination.
* @param dest The actual destination index.
*/
-static void SendChat(const char *buf, DestType type, int dest)
+static void SendChat(const std::string &buf, DestType type, int dest)
{
- if (StrEmpty(buf)) return;
+ if (buf.empty()) return;
if (!_network_server) {
MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
} else {
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index ba9b16d85..8cbe76e18 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -450,7 +450,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacke
}
/** Send a chat-packet over the network */
-NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
+NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data)
{
Packet *p = new Packet(PACKET_CLIENT_CHAT);
@@ -1025,13 +1025,13 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
{
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
- char name[NETWORK_NAME_LENGTH], msg[NETWORK_CHAT_LENGTH];
+ std::string name;
const NetworkClientInfo *ci = nullptr, *ci_to;
NetworkAction action = (NetworkAction)p->Recv_uint8();
ClientID client_id = (ClientID)p->Recv_uint32();
bool self_send = p->Recv_bool();
- p->Recv_string(msg, NETWORK_CHAT_LENGTH);
+ std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
int64 data = p->Recv_uint64();
ci_to = NetworkClientInfo::GetByClientID(client_id);
@@ -1042,7 +1042,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
switch (action) {
case NETWORK_ACTION_CHAT_CLIENT:
/* For speaking to client we need the client-name */
- seprintf(name, lastof(name), "%s", ci_to->client_name);
+ name = ci_to->client_name;
ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
break;
@@ -1051,7 +1051,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
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));
+ name = GetString(str);
ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
break;
}
@@ -1060,7 +1060,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
}
} else {
/* Display message from somebody else */
- seprintf(name, lastof(name), "%s", ci_to->client_name);
+ name = ci_to->client_name;
ci = ci_to;
}
@@ -1385,7 +1385,7 @@ void NetworkUpdateClientName()
* @param msg The actual message.
* @param data Arbitrary extra data.
*/
-void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
+void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data)
{
MyClient::SendChat(action, type, dest, msg, data);
}
diff --git a/src/network/network_client.h b/src/network/network_client.h
index 7d0d22810..169820d96 100644
--- a/src/network/network_client.h
+++ b/src/network/network_client.h
@@ -93,7 +93,7 @@ public:
static NetworkRecvStatus SendGamePassword(const std::string &password);
static NetworkRecvStatus SendCompanyPassword(const std::string &password);
- static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
+ static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data);
static NetworkRecvStatus SendSetPassword(const std::string &password);
static NetworkRecvStatus SendSetName(const char *name);
static NetworkRecvStatus SendRCon(const std::string &password, const char *command);
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 82a5deb45..1c5916eda 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -55,7 +55,7 @@ bool NetworkClientConnectGame(const std::string &connection_string, CompanyID de
void NetworkClientJoinGame();
void NetworkClientRequestMove(CompanyID company, const std::string &pass = "");
void NetworkClientSendRcon(const std::string &password, const char *command);
-void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
+void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data = 0);
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
bool NetworkCompanyIsPassworded(CompanyID company_id);
bool NetworkMaxCompaniesReached();
@@ -77,7 +77,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
-void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0, bool from_admin = false);
+void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data = 0, bool from_admin = false);
void NetworkServerKickClient(ClientID client_id, const char *reason);
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 71173a8d5..f5cd91bd1 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -719,7 +719,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacke
* @param msg The actual message.
* @param data Arbitrary extra data.
*/
-NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
+NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, ClientID client_id, bool self_send, const std::string &msg, int64 data)
{
if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY;
@@ -1235,7 +1235,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p)
* @param data Arbitrary data.
* @param from_admin Whether the origin is an admin or not.
*/
-void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data, bool from_admin)
+void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const std::string &msg, ClientID from_id, int64 data, bool from_admin)
{
const NetworkClientInfo *ci, *ci_own, *ci_to;
@@ -1356,9 +1356,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p)
NetworkAction action = (NetworkAction)p->Recv_uint8();
DestType desttype = (DestType)p->Recv_uint8();
int dest = p->Recv_uint32();
- char msg[NETWORK_CHAT_LENGTH];
- p->Recv_string(msg, NETWORK_CHAT_LENGTH);
+ std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
int64 data = p->Recv_uint64();
NetworkClientInfo *ci = this->GetInfo();
diff --git a/src/network/network_server.h b/src/network/network_server.h
index f8f58d1e3..98b2f9b6e 100644
--- a/src/network/network_server.h
+++ b/src/network/network_server.h
@@ -94,7 +94,7 @@ public:
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
NetworkRecvStatus SendError(NetworkErrorCode error, const char *reason = nullptr);
- NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data);
+ NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const std::string &msg, int64 data);
NetworkRecvStatus SendJoin(ClientID client_id);
NetworkRecvStatus SendFrame();
NetworkRecvStatus SendSync();