summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-05-17 01:00:56 +0000
committersmatz <smatz@openttd.org>2009-05-17 01:00:56 +0000
commit871107f52952ee59c353feab933126ed206e60bf (patch)
tree482884dfedc1700bddb8812f1de755212ed8bb22 /src/network
parented1e54bd84074412ea9f273b7cd86aed42d844ce (diff)
downloadopenttd-871107f52952ee59c353feab933126ed206e60bf.tar.xz
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/tcp_game.h5
-rw-r--r--src/network/network.cpp4
-rw-r--r--src/network/network_base.h5
-rw-r--r--src/network/network_client.cpp12
-rw-r--r--src/network/network_gui.cpp6
-rw-r--r--src/network/network_server.cpp34
6 files changed, 28 insertions, 38 deletions
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index 48abc996d..3bbb3ac0a 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -108,11 +108,6 @@ public:
void Send_Command(Packet *p, const CommandPacket *cp);
};
-static inline bool IsValidNetworkClientSocketIndex(ClientIndex index)
-{
- return (uint)index < NetworkClientSocket::GetPoolSize() && NetworkClientSocket::Get(index)->IsValid();
-}
-
#define FOR_ALL_CLIENT_SOCKETS_FROM(d, start) for (d = NetworkClientSocket::Get(start); d != NULL; d = (d->index + 1U < NetworkClientSocket::GetPoolSize()) ? NetworkClientSocket::Get(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_CLIENT_SOCKETS(d) FOR_ALL_CLIENT_SOCKETS_FROM(d, 0)
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 95ff34dcc..c661e1a98 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -97,7 +97,7 @@ extern void StateGameLoop();
*/
NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index)
{
- return IsValidNetworkClientInfoIndex(index) ? NetworkClientInfo::Get(index) : NULL;
+ return NetworkClientInfo::IsValidID(index) ? NetworkClientInfo::Get(index) : NULL;
}
/**
@@ -339,7 +339,7 @@ static uint NetworkCountActiveClients()
uint count = 0;
FOR_ALL_CLIENT_INFOS(ci) {
- if (IsValidCompanyID(ci->client_playas)) count++;
+ if (Company::IsValidID(ci->client_playas)) count++;
}
return count;
diff --git a/src/network/network_base.h b/src/network/network_base.h
index 3044de7a1..929c4b7ba 100644
--- a/src/network/network_base.h
+++ b/src/network/network_base.h
@@ -27,11 +27,6 @@ struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkCli
inline bool IsValid() const { return client_id != INVALID_CLIENT_ID; }
};
-static inline bool IsValidNetworkClientInfoIndex(ClientIndex index)
-{
- return (uint)index < NetworkClientInfo::GetPoolSize() && NetworkClientInfo::Get(index)->IsValid();
-}
-
#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (d = NetworkClientInfo::Get(start); d != NULL; d = (d->index + 1U < NetworkClientInfo::GetPoolSize()) ? NetworkClientInfo::Get(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_CLIENT_INFOS(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0)
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 4a6897bf3..db25c8f7a 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -620,7 +620,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
/* New company/spectator (invalid company) or company we want to join is not active
* Switch local company to spectator and await the server's judgement */
- if (_network_playas == COMPANY_NEW_COMPANY || !IsValidCompanyID(_network_playas)) {
+ if (_network_playas == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_playas)) {
SetLocalCompany(COMPANY_SPECTATOR);
if (_network_playas != COMPANY_SPECTATOR) {
@@ -723,10 +723,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
/* For speaking to company or giving money, we need the company-name */
case NETWORK_ACTION_GIVE_MONEY:
- if (!IsValidCompanyID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
+ if (!Company::IsValidID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
/* fallthrough */
case NETWORK_ACTION_CHAT_COMPANY: {
- StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
+ 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));
@@ -842,7 +842,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MOVE)
if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
/* if not valid player, force spectator, else check player exists */
- if (!IsValidCompanyID(company_id)) company_id = COMPANY_SPECTATOR;
+ if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
if (client_id == _network_own_client_id) {
_network_playas = company_id;
@@ -1006,7 +1006,7 @@ void NetworkClientSetPassword(const char *password)
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
{
/* Only companies actually playing can speak to team. Eg spectators cannot */
- if (!_settings_client.gui.prefer_teamchat || !IsValidCompanyID(cio->client_playas)) return false;
+ if (!_settings_client.gui.prefer_teamchat || !Company::IsValidID(cio->client_playas)) return false;
const NetworkClientInfo *ci;
FOR_ALL_CLIENT_INFOS(ci) {
@@ -1044,7 +1044,7 @@ void NetworkPrintClients()
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_id,
ci->client_name,
- ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
+ ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
GetClientIP(ci));
}
}
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 6256adc10..23cdec35d 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1808,7 +1808,7 @@ struct NetworkClientListPopupWindow : Window {
this->proc[i++] = &ClientList_SpeakToClient;
}
- if (IsValidCompanyID(ci->client_playas) || ci->client_playas == COMPANY_SPECTATOR) {
+ if (Company::IsValidID(ci->client_playas) || ci->client_playas == COMPANY_SPECTATOR) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, lastof(this->action[i]));
this->proc[i++] = &ClientList_SpeakToCompany;
}
@@ -1817,7 +1817,7 @@ struct NetworkClientListPopupWindow : Window {
if (_network_own_client_id != ci->client_id) {
/* We are no spectator and the company we want to give money to is no spectator and money gifts are allowed */
- if (IsValidCompanyID(_network_playas) && IsValidCompanyID(ci->client_playas) && _settings_game.economy.give_money) {
+ if (Company::IsValidID(_network_playas) && Company::IsValidID(ci->client_playas) && _settings_game.economy.give_money) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(this->action[i]));
this->proc[i++] = &ClientList_GiveMoney;
}
@@ -2013,7 +2013,7 @@ struct NetworkClientListWindow : Window
}
/* Filter out spectators */
- if (IsValidCompanyID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
+ if (Company::IsValidID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
DrawString(81, this->width - 2, y, ci->client_name, colour);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 9b29070a9..e48137547 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -76,7 +76,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
/* Add the local player (if not dedicated) */
const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
- if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
+ if (ci != NULL && Company::IsValidID(ci->client_playas)) {
strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas]));
}
@@ -86,7 +86,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
NetworkGetClientName(client_name, sizeof(client_name), csi);
ci = csi->GetInfo();
- if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
+ if (ci != NULL && Company::IsValidID(ci->client_playas)) {
if (!StrEmpty(clients[ci->client_playas])) {
strecat(clients[ci->client_playas], ", ", lastof(clients[ci->client_playas]));
}
@@ -632,7 +632,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
if (!StrEmpty(_settings_client.network.server_password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD);
} else {
- if (IsValidCompanyID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
+ if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
} else {
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs);
@@ -686,7 +686,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
}
break;
default: // Join another company (companies 1-8 (index 0-7))
- if (!IsValidCompanyID(playas) || !IsHumanCompany(playas)) {
+ if (!Company::IsValidID(playas) || !IsHumanCompany(playas)) {
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_COMPANY_MISMATCH);
return;
}
@@ -710,7 +710,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
ci->client_lang = client_lang;
/* Make sure companies to which people try to join are not autocleaned */
- if (IsValidCompanyID(playas)) _network_company_states[playas].months_empty = 0;
+ if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
if (_grfconfig == NULL) {
RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)(cs, NULL);
@@ -738,7 +738,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
ci = cs->GetInfo();
- if (IsValidCompanyID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
+ if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
return;
}
@@ -872,7 +872,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
return;
}
- if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !IsValidCompanyID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
+ if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_KICKED);
return;
@@ -1100,7 +1100,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
if (ci != NULL && show_local) {
if (from_id == CLIENT_ID_SERVER) {
char name[NETWORK_NAME_LENGTH];
- StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
+ 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));
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColour(ci_own->client_playas), true, name, msg, data);
@@ -1147,7 +1147,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
NetworkClientInfo *ci = cs->GetInfo();
switch (action) {
case NETWORK_ACTION_GIVE_MONEY:
- if (!IsValidCompanyID(ci->client_playas)) break;
+ if (!Company::IsValidID(ci->client_playas)) break;
/* Fall-through */
case NETWORK_ACTION_CHAT:
case NETWORK_ACTION_CHAT_CLIENT:
@@ -1175,7 +1175,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD)
p->Recv_string(password, sizeof(password));
ci = cs->GetInfo();
- if (IsValidCompanyID(ci->client_playas)) {
+ if (Company::IsValidID(ci->client_playas)) {
strecpy(_network_company_states[ci->client_playas].password, password, lastof(_network_company_states[ci->client_playas].password));
NetworkServerUpdateCompanyPassworded(ci->client_playas, !StrEmpty(_network_company_states[ci->client_playas].password));
}
@@ -1235,7 +1235,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MOVE)
CompanyID company_id = (Owner)p->Recv_uint8();
/* Check if the company is valid */
- if (!IsValidCompanyID(company_id) && company_id != COMPANY_SPECTATOR) return;
+ if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) return;
/* We don't allow moving to AI companies */
if (company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai) return;
@@ -1364,7 +1364,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
/* Go through all vehicles and count the type of vehicles */
FOR_ALL_VEHICLES(v) {
- if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
+ if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
byte type = 0;
switch (v->type) {
case VEH_TRAIN: type = 0; break;
@@ -1378,7 +1378,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
/* Go through all stations and count the types of stations */
FOR_ALL_STATIONS(s) {
- if (IsValidCompanyID(s->owner)) {
+ if (Company::IsValidID(s->owner)) {
NetworkCompanyStats *npi = &stats[s->owner];
if (s->facilities & FACIL_TRAIN) npi->num_station[0]++;
@@ -1431,12 +1431,12 @@ static void NetworkAutoCleanCompanies()
/* Detect the active companies */
FOR_ALL_CLIENT_INFOS(ci) {
- if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
+ if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
if (!_network_dedicated) {
ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
- if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
+ if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
if (_settings_client.network.autoclean_novehicles != 0) {
@@ -1444,7 +1444,7 @@ static void NetworkAutoCleanCompanies()
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
- if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
+ if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
vehicles_in_company[v->owner]++;
}
}
@@ -1710,7 +1710,7 @@ void NetworkServerShowStatusToConsole()
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
cs->client_id, ci->client_name, status, lag,
- ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
+ ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
GetClientIP(ci), ci->unique_id);
}
}