summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-15 08:35:45 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-16 10:07:51 +0200
commit83679c0e57cb3e13de6d6c5ec33735bc4070da40 (patch)
tree4bb7833ae6f3e2d48a3b225b6260ab146a54afc9
parente90b2649b651e3ede41a2a40e70ab79ea4270dfe (diff)
downloadopenttd-83679c0e57cb3e13de6d6c5ec33735bc4070da40.tar.xz
Codechange: [Network] Use std::string to populate the client list for company stats
-rw-r--r--src/network/network_server.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index f5cd91bd1..0d5eb83fd 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -372,13 +372,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
NetworkPopulateCompanyStats(company_stats);
/* Make a list of all clients per company */
- char clients[MAX_COMPANIES][NETWORK_CLIENTS_LENGTH];
- memset(clients, 0, sizeof(clients));
+ std::string clients[MAX_COMPANIES];
/* Add the local player (if not dedicated) */
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
if (ci != nullptr && Company::IsValidID(ci->client_playas)) {
- strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas]));
+ clients[ci->client_playas] = ci->client_name;
}
for (NetworkClientSocket *csi : NetworkClientSocket::Iterate()) {
@@ -388,11 +387,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
ci = csi->GetInfo();
if (ci != nullptr && Company::IsValidID(ci->client_playas)) {
- if (!StrEmpty(clients[ci->client_playas])) {
- strecat(clients[ci->client_playas], ", ", lastof(clients[ci->client_playas]));
+ if (!clients[ci->client_playas].empty()) {
+ clients[ci->client_playas] += ", ";
}
- strecat(clients[ci->client_playas], client_name, lastof(clients[ci->client_playas]));
+ clients[ci->client_playas] += client_name;
}
}
@@ -407,7 +406,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
p->Send_bool (true);
this->SendCompanyInformation(p, company, &company_stats[company->index]);
- if (StrEmpty(clients[company->index])) {
+ if (clients[company->index].empty()) {
p->Send_string("<none>");
} else {
p->Send_string(clients[company->index]);