1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-21 21:49:10 +00:00

(svn r14725) -Change: make it clearer why (and that) MAX_CLIENTS isn't the amount of slots in the array, but one less as a dedicated server takes a slot too.

This commit is contained in:
rubidium
2008-12-23 11:55:46 +00:00
parent 52fb6b7d7c
commit f8f7febe41
5 changed files with 15 additions and 16 deletions

View File

@@ -50,7 +50,7 @@ bool _network_available; ///< is network mode available?
bool _network_dedicated; ///< are we a dedicated server?
bool _is_network_server; ///< Does this client wants to be a network-server?
NetworkServerGameInfo _network_game_info;
NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
NetworkClientInfo _network_client_info[MAX_CLIENT_SLOTS];
NetworkCompanyState *_network_company_states = NULL;
ClientID _network_own_client_id;
ClientID _redirect_console_to_client;
@@ -827,9 +827,9 @@ static void NetworkInitGameInfo()
_network_game_info.clients_on = _network_dedicated ? 0 : 1;
_network_game_info.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
// We use _network_client_info[MAX_CLIENT_INFO - 1] to store the server-data in it
// We use _network_client_info[MAX_CLIENT_SLOTS - 1] to store the server-data in it
// The client identifier is CLIENT_ID_SERVER ( = 1)
ci = &_network_client_info[MAX_CLIENT_INFO - 1];
ci = &_network_client_info[MAX_CLIENT_SLOTS - 1];
memset(ci, 0, sizeof(*ci));
ci->client_id = CLIENT_ID_SERVER;

View File

@@ -23,16 +23,16 @@ struct NetworkClientInfo {
static NetworkClientInfo *GetNetworkClientInfo(int ci)
{
extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
extern NetworkClientInfo _network_client_info[MAX_CLIENT_SLOTS];
return &_network_client_info[ci];
}
static inline bool IsValidNetworkClientInfoIndex(ClientIndex index)
{
return (uint)index < MAX_CLIENT_INFO && GetNetworkClientInfo(index)->IsValid();
return (uint)index < MAX_CLIENT_SLOTS && GetNetworkClientInfo(index)->IsValid();
}
#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (ci = GetNetworkClientInfo(start); ci != GetNetworkClientInfo(MAX_CLIENT_INFO); ci++) if (ci->IsValid())
#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (ci = GetNetworkClientInfo(start); ci != GetNetworkClientInfo(MAX_CLIENT_SLOTS); ci++) if (ci->IsValid())
#define FOR_ALL_CLIENT_INFOS(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0)
#endif /* ENABLE_NETWORK */

View File

@@ -299,19 +299,19 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
static char chat_tab_temp_buffer[64];
/* First, try clients */
if (*item < MAX_CLIENT_INFO) {
if (*item < MAX_CLIENT_SLOTS) {
/* Skip inactive clients */
while (GetNetworkClientInfo(*item)->client_id == INVALID_CLIENT_ID && *item < MAX_CLIENT_INFO) (*item)++;
if (*item < MAX_CLIENT_INFO) return GetNetworkClientInfo(*item)->client_name;
while (GetNetworkClientInfo(*item)->client_id == INVALID_CLIENT_ID && *item < MAX_CLIENT_SLOTS) (*item)++;
if (*item < MAX_CLIENT_SLOTS) return GetNetworkClientInfo(*item)->client_name;
}
/* Then, try townnames */
/* Not that the following assumes all town indices are adjacent, ie no
* towns have been deleted. */
if (*item <= (uint)MAX_CLIENT_INFO + GetMaxTownIndex()) {
if (*item <= (uint)MAX_CLIENT_SLOTS + GetMaxTownIndex()) {
const Town *t;
FOR_ALL_TOWNS_FROM(t, *item - MAX_CLIENT_INFO) {
FOR_ALL_TOWNS_FROM(t, *item - MAX_CLIENT_SLOTS) {
/* Get the town-name via the string-system */
SetDParam(0, t->index);
GetString(chat_tab_temp_buffer, STR_TOWN, lastof(chat_tab_temp_buffer));

View File

@@ -37,8 +37,8 @@ enum ClientID {
/** Indices into the client tables */
enum ClientIndex {
/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */
MAX_CLIENT_INFO = MAX_CLIENTS + 1,
/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1. This due to the (dedicated) server taking one slot. */
MAX_CLIENT_SLOTS = MAX_CLIENTS + 1,
};
/** Simple calculated statistics of a company */