(svn r22369) -Codechange: allocate ClientInfo when needed, i.e. don't allocate it for clients that are there to just get a list of companies. This means that these short lived clients won't be seen by the admin network in their client queries anymore

This commit is contained in:
rubidium 2011-04-22 16:05:05 +00:00
parent 2cae0cd54c
commit cdfc0ec4a3
2 changed files with 12 additions and 13 deletions

View File

@ -208,9 +208,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID clien
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs)
{
/* Only send data when we're a proper client, not just someone trying to query the server. */
const NetworkClientInfo *ci = cs->GetInfo();
if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_INFO);
const NetworkClientInfo *ci = cs->GetInfo();
p->Send_uint32(ci->client_id);
p->Send_string(const_cast<NetworkAddress &>(cs->client_address).GetHostname());
p->Send_string(ci->client_name);

View File

@ -161,12 +161,6 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
* each Socket will be associated with at most one Info object. As
* such if the Socket was allocated the Info object can as well. */
assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
assert(NetworkClientInfo::CanAllocateItem());
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
this->SetInfo(ci);
ci->client_playas = COMPANY_INACTIVE_CLIENT;
ci->join_date = _date;
}
/**
@ -794,7 +788,6 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_JOIN)
}
char name[NETWORK_CLIENT_NAME_LENGTH];
NetworkClientInfo *ci;
CompanyID playas;
NetworkLanguage client_lang;
char client_revision[NETWORK_REVISION_LENGTH];
@ -840,8 +833,10 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_JOIN)
return this->SendError(NETWORK_ERROR_NAME_IN_USE);
}
ci = this->GetInfo();
assert(NetworkClientInfo::CanAllocateItem());
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
this->SetInfo(ci);
ci->join_date = _date;
strecpy(ci->client_name, name, lastof(ci->client_name));
ci->client_playas = playas;
ci->client_lang = client_lang;
@ -1221,7 +1216,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci_to = NULL;
FOR_ALL_CLIENT_SOCKETS(cs) {
ci = cs->GetInfo();
if (ci->client_playas == (CompanyID)dest) {
if (ci != NULL && ci->client_playas == (CompanyID)dest) {
cs->SendChat(action, from_id, false, msg, data);
if (cs->client_id == from_id) show_local = false;
ci_to = ci; // Remember a client that is in the company for company-name
@ -1834,8 +1829,9 @@ void NetworkServerShowStatusToConsole()
NetworkClientSocket *cs;
FOR_ALL_CLIENT_SOCKETS(cs) {
uint lag = NetworkCalculateLag(cs);
NetworkClientInfo *ci = cs->GetInfo();
if (ci == NULL) continue;
uint lag = NetworkCalculateLag(cs);
const char *status;
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
@ -1967,7 +1963,7 @@ void ServerNetworkGameSocketHandler::GetClientName(char *client_name, size_t siz
{
const NetworkClientInfo *ci = this->GetInfo();
if (StrEmpty(ci->client_name)) {
if (ci == NULL || StrEmpty(ci->client_name)) {
snprintf(client_name, size, "Client #%4d", this->client_id);
} else {
ttd_strlcpy(client_name, ci->client_name, size);