summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--date.c4
-rw-r--r--gui.h3
-rw-r--r--intro_gui.c5
-rw-r--r--main_gui.c15
-rw-r--r--network.h26
-rw-r--r--network_gui.c2
-rw-r--r--network_gui.h19
-rw-r--r--network_server.h6
-rw-r--r--network_udp.h2
-rw-r--r--openttd.c15
-rw-r--r--player_gui.c12
11 files changed, 55 insertions, 54 deletions
diff --git a/date.c b/date.c
index 685c31871..c9b02d013 100644
--- a/date.c
+++ b/date.c
@@ -254,9 +254,7 @@ void IncreaseDate(void)
TownsMonthlyLoop();
IndustryMonthlyLoop();
StationMonthlyLoop();
-#ifdef ENABLE_NETWORK
if (_network_server) NetworkServerMonthlyLoop();
-#endif /* ENABLE_NETWORK */
}
/* check if we entered a new year? */
@@ -269,9 +267,7 @@ void IncreaseDate(void)
RoadVehiclesYearlyLoop();
AircraftYearlyLoop();
ShipsYearlyLoop();
-#ifdef ENABLE_NETWORK
if (_network_server) NetworkServerYearlyLoop();
-#endif /* ENABLE_NETWORK */
/* check if we reached end of the game */
if (_cur_year == _patches.ending_year) {
diff --git a/gui.h b/gui.h
index bc74bccd3..af7028c5d 100644
--- a/gui.h
+++ b/gui.h
@@ -120,9 +120,6 @@ void SetFiosType(const byte fiostype);
/* FIOS_TYPE_FILE, FIOS_TYPE_OLDFILE etc. different colours */
extern const byte _fios_colors[];
-/* network gui */
-void ShowNetworkGameWindow(void);
-
/* bridge_gui.c */
void ShowBuildBridgeWindow(uint start, uint end, byte type);
diff --git a/intro_gui.c b/intro_gui.c
index 0134b053c..8e2d8190e 100644
--- a/intro_gui.c
+++ b/intro_gui.c
@@ -13,6 +13,7 @@
#include "settings.h"
#include "heightmap.h"
#include "genworld.h"
+#include "network_gui.h"
static const Widget _select_game_widgets[] = {
{ WWT_CAPTION, RESIZE_NONE, 13, 0, 335, 0, 13, STR_0307_OPENTTD, STR_NULL},
@@ -66,15 +67,11 @@ static void SelectGameWndProc(Window *w, WindowEvent *e)
case 5: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
case 6: ShowCreateScenario(); break;
case 7:
-#ifdef ENABLE_NETWORK
if (!_network_available) {
ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
} else {
ShowNetworkGameWindow();
}
-#else
- ShowErrorMessage(INVALID_STRING_ID ,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
-#endif
break;
case 8: case 9: case 10: case 11:
RaiseWindowWidget(w, _opt_newgame.landscape + 8);
diff --git a/main_gui.c b/main_gui.c
index 9726239c3..2d5a5b535 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -38,6 +38,7 @@
#include "network_data.h"
#include "network_client.h"
#include "network_server.h"
+#include "network_gui.h"
static int _rename_id;
static int _rename_what;
@@ -221,23 +222,16 @@ static void MenuClickFinances(int index)
ShowPlayerFinances(index);
}
-#ifdef ENABLE_NETWORK
-extern void ShowClientList(void);
-#endif /* ENABLE_NETWORK */
-
static void MenuClickCompany(int index)
{
if (_networking && index == 0) {
-#ifdef ENABLE_NETWORK
ShowClientList();
-#endif /* ENABLE_NETWORK */
} else {
if (_networking) index--;
ShowPlayerCompany(index);
}
}
-
static void MenuClickGraphs(int index)
{
switch (index) {
@@ -308,15 +302,12 @@ static void MenuClickBuildAir(int index)
}
#ifdef ENABLE_NETWORK
-
-void ShowNetworkGiveMoneyWindow(byte player)
+void ShowNetworkGiveMoneyWindow(PlayerID player)
{
_rename_id = player;
_rename_what = 3;
ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, 1, 0, CS_NUMERAL);
}
-
-
#endif /* ENABLE_NETWORK */
void ShowRenameSignWindow(const Sign *si)
@@ -2320,9 +2311,7 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
case '1' | WKC_ALT: /* Gimme money */
/* Server can not cheat in advertise mode either! */
-#ifdef ENABLE_NETWORK
if (!_networking || !_network_server || !_network_advertise)
-#endif
DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
break;
diff --git a/network.h b/network.h
index af7aeb405..20a4a5df8 100644
--- a/network.h
+++ b/network.h
@@ -197,7 +197,6 @@ VARDEF uint16 _network_udp_broadcast;
VARDEF byte _network_lan_internet;
-VARDEF bool _network_advertise;
VARDEF bool _network_need_advertise;
VARDEF uint32 _network_last_advertise_frame;
VARDEF uint8 _network_advertise_retries;
@@ -233,13 +232,26 @@ bool NetworkServerStart(void);
bool NetworkClientConnectGame(const char* host, unsigned short port);
void NetworkReboot(void);
void NetworkDisconnect(void);
+
+VARDEF bool _networking; ///< are we in networking mode?
+VARDEF bool _network_server; ///< network-server is active
+VARDEF bool _network_available; ///< is network mode available?
+
+#else /* ENABLE_NETWORK */
+/* Network function stubs when networking is disabled */
+
+static inline void NetworkStartUp(void) {}
+static inline void NetworkShutDown(void) {}
+
+#define _networking 0
+#define _network_server 0
+#define _network_available 0
+
#endif /* ENABLE_NETWORK */
-// Those variables must always be registered!
-VARDEF bool _networking;
-VARDEF bool _network_available; // is network mode available?
-VARDEF bool _network_server; // network-server is active
-VARDEF bool _network_dedicated; // are we a dedicated server?
-VARDEF PlayerID _network_playas; // an id to play as..
+/* These variables must always be registered! */
+VARDEF bool _network_dedicated; ///< are we a dedicated server?
+VARDEF bool _network_advertise; ///< is the server advertising to the master server?
+VARDEF PlayerID _network_playas; ///< an id to play as..
#endif /* NETWORK_H */
diff --git a/network_gui.c b/network_gui.c
index 142105fa9..ed78584a0 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -1720,6 +1720,4 @@ void ShowNetworkChatQueryWindow(byte desttype, byte dest)
UpdateTextBufferSize(&WP(w, querystr_d).text);
}
-#else
-void ShowJoinStatusWindowAfterJoin(void) {}
#endif /* ENABLE_NETWORK */
diff --git a/network_gui.h b/network_gui.h
index e0aee1cb7..a861cec7b 100644
--- a/network_gui.h
+++ b/network_gui.h
@@ -3,6 +3,25 @@
#ifndef NETWORK_GUI_H
#define NETWORK_GUI_H
+#ifdef ENABLE_NETWORK
+
+#include "network_data.h"
+
void ShowNetworkNeedPassword(NetworkPasswordType npt);
+void ShowNetworkGiveMoneyWindow(byte player); // PlayerID
+void ShowNetworkChatQueryWindow(byte desttype, byte dest);
+void ShowJoinStatusWindowAfterJoin(void);
+void ShowNetworkGameWindow(void);
+void ShowClientList(void);
+
+#else /* ENABLE_NETWORK */
+/* Network function stubs when networking is disabled */
+
+static inline void ShowNetworkChatQueryWindow(byte desttype, byte dest) {}
+static inline void ShowClientList(void) {}
+static inline void ShowJoinStatusWindowAfterJoin(void) {}
+static inline void ShowNetworkGameWindow(void) {}
+
+#endif /* ENABLE_NETWORK */
#endif /* NETWORK_GUI_H */
diff --git a/network_server.h b/network_server.h
index 4b98bf31b..66ea4704e 100644
--- a/network_server.h
+++ b/network_server.h
@@ -28,6 +28,12 @@ static inline const char* GetPlayerIP(const NetworkClientInfo* ci)
return inet_ntoa(addr);
}
+#else /* ENABLE_NETWORK */
+/* Network function stubs when networking is disabled */
+
+static inline void NetworkServerMonthlyLoop(void) {}
+static inline void NetworkServerYearlyLoop(void) {}
+
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_SERVER_H */
diff --git a/network_udp.h b/network_udp.h
index ecf91b2cb..b7814d3b2 100644
--- a/network_udp.h
+++ b/network_udp.h
@@ -14,6 +14,6 @@ NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port);
void NetworkUDPAdvertise(void);
void NetworkUDPRemoveAdvertise(void);
-#endif
+#endif /* ENABLE_NETWORK */
#endif /* NETWORK_UDP_H */
diff --git a/openttd.c b/openttd.c
index 02ea57537..e46b6a14c 100644
--- a/openttd.c
+++ b/openttd.c
@@ -453,10 +453,7 @@ int ttd_main(int argc, char *argv[])
// restore saved music volume
_music_driver->set_volume(msf.music_vol);
-#ifdef ENABLE_NETWORK
- // initialize network-core
- NetworkStartUp();
-#endif /* ENABLE_NETWORK */
+ NetworkStartUp(); // initialize network-core
_opt_ptr = &_opt_newgame;
@@ -505,12 +502,7 @@ int ttd_main(int argc, char *argv[])
WaitTillSaved();
IConsoleFree();
-#ifdef ENABLE_NETWORK
- if (_network_available) {
- // Shut down the network and close any open connections
- NetworkDisconnect();
- }
-#endif /* ENABLE_NETWORK */
+ if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
_video_driver->stop();
_music_driver->stop();
@@ -986,8 +978,7 @@ void GameLoop(void)
#ifdef ENABLE_NETWORK
// Check for UDP stuff
- if (_network_available)
- NetworkUDPGameLoop();
+ if (_network_available) NetworkUDPGameLoop();
if (_networking && !IsGeneratingWorld()) {
// Multiplayer
diff --git a/player_gui.c b/player_gui.c
index 801aeb104..133ef5148 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -18,15 +18,11 @@
#include "train.h"
#include "date.h"
#include "newgrf.h"
-
-#ifdef ENABLE_NETWORK
#include "network_data.h"
#include "network_client.h"
-#endif
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
-
static void DrawPlayerEconomyStats(const Player *p, byte mode)
{
int x,y,i,j,year;
@@ -811,15 +807,15 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
break;
+ #ifdef ENABLE_NETWORK
case PCW_WIDGET_COMPANY_PASSWORD:
- #ifdef ENABLE_NETWORK
if (w->window_number == _local_player) {
WP(w,def_d).byte_1 = 2;
ShowQueryString(BindCString(_network_player_info[_local_player].password),
STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w->window_class, w->window_number, CS_ALPHANUMERAL);
}
- #endif
break;
+ #endif /* ENABLE_NETWORK */
}
break;
@@ -857,12 +853,12 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
case 1: /* Change company name */
DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
break;
+ #ifdef ENABLE_NETWORK
case 2: /* Change company password */
- #ifdef ENABLE_NETWORK
if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
NetworkChangeCompanyPassword(1, &b);
- #endif
break;
+ #endif /* ENABLE_NETWORK */
}
break;
}