1
0
Fork 0

Codechange: [Network] Use std::string to populate the client list for company stats

pull/9276/head
rubidium42 2021-05-15 08:35:45 +02:00 committed by rubidium42
parent e90b2649b6
commit 83679c0e57
1 changed files with 6 additions and 7 deletions

View File

@ -372,13 +372,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
NetworkPopulateCompanyStats(company_stats); NetworkPopulateCompanyStats(company_stats);
/* Make a list of all clients per company */ /* Make a list of all clients per company */
char clients[MAX_COMPANIES][NETWORK_CLIENTS_LENGTH]; std::string clients[MAX_COMPANIES];
memset(clients, 0, sizeof(clients));
/* Add the local player (if not dedicated) */ /* Add the local player (if not dedicated) */
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
if (ci != nullptr && Company::IsValidID(ci->client_playas)) { 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()) { for (NetworkClientSocket *csi : NetworkClientSocket::Iterate()) {
@ -388,11 +387,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
ci = csi->GetInfo(); ci = csi->GetInfo();
if (ci != nullptr && Company::IsValidID(ci->client_playas)) { if (ci != nullptr && Company::IsValidID(ci->client_playas)) {
if (!StrEmpty(clients[ci->client_playas])) { if (!clients[ci->client_playas].empty()) {
strecat(clients[ci->client_playas], ", ", lastof(clients[ci->client_playas])); 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); p->Send_bool (true);
this->SendCompanyInformation(p, company, &company_stats[company->index]); this->SendCompanyInformation(p, company, &company_stats[company->index]);
if (StrEmpty(clients[company->index])) { if (clients[company->index].empty()) {
p->Send_string("<none>"); p->Send_string("<none>");
} else { } else {
p->Send_string(clients[company->index]); p->Send_string(clients[company->index]);