summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/company_cmd.cpp1
-rw-r--r--src/console_cmds.cpp1
-rw-r--r--src/main_gui.cpp1
-rw-r--r--src/network/core/tcp.h3
-rw-r--r--src/network/network.cpp2
-rw-r--r--src/network/network_base.h39
-rw-r--r--src/network/network_chat_gui.cpp4
-rw-r--r--src/network/network_func.h2
-rw-r--r--src/network/network_internal.h3
-rw-r--r--src/network/network_type.h10
10 files changed, 48 insertions, 18 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 525c95967..16c2610bf 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -14,6 +14,7 @@
#include "command_func.h"
#include "network/network.h"
#include "network/network_func.h"
+#include "network/network_base.h"
#include "variables.h"
#include "cheat_func.h"
#include "ai/ai.h"
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 20954a39f..c1dc954d7 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -12,6 +12,7 @@
#include "variables.h"
#include "network/network.h"
#include "network/network_func.h"
+#include "network/network_base.h"
#include "command_func.h"
#include "settings_func.h"
#include "fios.h"
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 9630b3acf..ca4a0e736 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -36,6 +36,7 @@
#include "network/network.h"
#include "network/network_func.h"
#include "network/network_gui.h"
+#include "network/network_base.h"
#include "table/sprites.h"
#include "table/strings.h"
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index 716d219af..f720e0de0 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -113,9 +113,8 @@ public:
inline NetworkClientInfo *GetInfo() const
{
- extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
extern NetworkClientSocket _clients[MAX_CLIENTS];
- return &_network_client_info[this - _clients];
+ return GetNetworkClientInfo(this - _clients);
}
};
diff --git a/src/network/network.cpp b/src/network/network.cpp
index ac49cb08b..58826e1e3 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -107,7 +107,7 @@ extern void StateGameLoop();
*/
NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index)
{
- return &_network_client_info[index];
+ return IsValidNetworkClientInfoIndex(index) ? GetNetworkClientInfo(index) : NULL;
}
/**
diff --git a/src/network/network_base.h b/src/network/network_base.h
new file mode 100644
index 000000000..225528852
--- /dev/null
+++ b/src/network/network_base.h
@@ -0,0 +1,39 @@
+/* $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"
+
+struct NetworkClientInfo {
+ 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)
+ uint32 client_ip; ///< IP-address of the client (so he can be banned)
+ 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
+
+ inline bool IsValid() const { return client_id != INVALID_CLIENT_ID; }
+};
+
+static NetworkClientInfo *GetNetworkClientInfo(int ci)
+{
+ extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
+ return &_network_client_info[ci];
+}
+
+static inline bool IsValidNetworkClientInfoIndex(ClientIndex index)
+{
+ return (uint)index < MAX_CLIENT_INFO && 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(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0)
+
+#endif /* ENABLE_NETWORK */
+#endif /* NETWORK_BASE_H */
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 108209cf3..739ef6454 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -301,8 +301,8 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
/* First, try clients */
if (*item < MAX_CLIENT_INFO) {
/* Skip inactive clients */
- while (_network_client_info[*item].client_id == INVALID_CLIENT_ID && *item < MAX_CLIENT_INFO) (*item)++;
- if (*item < MAX_CLIENT_INFO) return _network_client_info[*item].client_name;
+ while (GetNetworkClientInfo(*item)->client_id == INVALID_CLIENT_ID && *item < MAX_CLIENT_INFO) (*item)++;
+ if (*item < MAX_CLIENT_INFO) return GetNetworkClientInfo(*item)->client_name;
}
/* Then, try townnames */
diff --git a/src/network/network_func.h b/src/network/network_func.h
index e05d0f952..32f0265a0 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -64,7 +64,5 @@ void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *messa
void NetworkUndrawChatMessage();
void NetworkChatMessageDailyLoop();
-#define FOR_ALL_CLIENT_INFOS(ci) for (ci = _network_client_info; ci != endof(_network_client_info); ci++) if (ci->client_id != INVALID_CLIENT_ID)
-
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_FUNC_H */
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index fdf44d249..3f247fb2e 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -9,6 +9,7 @@
#include "network.h"
#include "network_func.h"
+#include "network_base.h"
#include "core/os_abstraction.h"
#include "core/core.h"
#include "core/config.h"
@@ -91,8 +92,6 @@ enum NetworkLanguage {
NETLANG_COUNT
};
-extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
-
extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
extern uint32 _frame_counter_max; // To where we may go with our clients
diff --git a/src/network/network_type.h b/src/network/network_type.h
index 3c5365d74..5302e2542 100644
--- a/src/network/network_type.h
+++ b/src/network/network_type.h
@@ -53,15 +53,7 @@ struct NetworkCompanyState {
uint16 months_empty; ///< How many months the company is empty
};
-struct NetworkClientInfo {
- 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)
- uint32 client_ip; ///< IP-address of the client (so he can be banned)
- 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
-};
+struct NetworkClientInfo;
enum NetworkPasswordType {
NETWORK_GAME_PASSWORD,