2008-12-23 11:06:52 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/** @file network_base.h Base core network types and some helper functions to access them. */
|
|
|
|
|
|
|
|
#ifndef NETWORK_BASE_H
|
|
|
|
#define NETWORK_BASE_H
|
|
|
|
|
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
|
|
|
|
#include "network_type.h"
|
2008-12-23 20:52:27 +00:00
|
|
|
#include "../oldpool.h"
|
2008-12-23 11:06:52 +00:00
|
|
|
|
2008-12-23 20:52:27 +00:00
|
|
|
DECLARE_OLD_POOL(NetworkClientInfo, NetworkClientInfo, NCI_BITS_PER_POOL_BLOCK, MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK);
|
|
|
|
|
|
|
|
struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkClientInfo_pool> {
|
2008-12-23 11:06:52 +00:00
|
|
|
ClientID client_id; ///< Client identifier (same as ClientState->client_id)
|
|
|
|
char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< Name of the client
|
|
|
|
byte client_lang; ///< The language of the client
|
|
|
|
CompanyID client_playas; ///< As which company is this client playing (CompanyID)
|
2009-04-04 00:48:48 +00:00
|
|
|
NetworkAddress client_address; ///< IP-address of the client (so he can be banned)
|
2008-12-23 11:06:52 +00:00
|
|
|
Date join_date; ///< Gamedate the client has joined
|
|
|
|
char unique_id[NETWORK_UNIQUE_ID_LENGTH]; ///< Every play sends an unique id so we can indentify him
|
|
|
|
|
2008-12-23 20:52:27 +00:00
|
|
|
NetworkClientInfo(ClientID client_id = INVALID_CLIENT_ID) : client_id(client_id) {}
|
|
|
|
~NetworkClientInfo() { client_id = INVALID_CLIENT_ID; }
|
|
|
|
|
2008-12-23 11:06:52 +00:00
|
|
|
inline bool IsValid() const { return client_id != INVALID_CLIENT_ID; }
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool IsValidNetworkClientInfoIndex(ClientIndex index)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
return (uint)index < GetNetworkClientInfoPoolSize() && NetworkClientInfo::Get(index)->IsValid();
|
2008-12-23 11:06:52 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (d = NetworkClientInfo::Get(start); d != NULL; d = (d->index + 1U < GetNetworkClientInfoPoolSize()) ? NetworkClientInfo::Get(d->index + 1U) : NULL) if (d->IsValid())
|
2008-12-23 11:06:52 +00:00
|
|
|
#define FOR_ALL_CLIENT_INFOS(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0)
|
|
|
|
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
#endif /* NETWORK_BASE_H */
|