Skip to content
Permalink
Browse files

Remove: ENABLE_NETWORK switch

This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.

Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.

A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.

With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.

All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
  • Loading branch information...
TrueBrain committed Mar 20, 2019
1 parent 72c5f2b commit e3c639a09f1d2251477f69496120d057dd8320a9
Showing with 29 additions and 600 deletions.
  1. +1 −2 Doxyfile
  2. +5 −26 config.lib
  3. +0 −2 src/ai/ai.hpp
  4. +0 −4 src/ai/ai_core.cpp
  5. +0 −2 src/ai/ai_gui.cpp
  6. +0 −17 src/base_media_func.h
  7. +3 −3 src/bootstrap_gui.cpp
  8. +0 −6 src/command.cpp
  9. +0 −2 src/command_func.h
  10. +0 −12 src/company_cmd.cpp
  11. +0 −8 src/company_gui.cpp
  12. +0 −6 src/console.cpp
  13. +2 −22 src/console_cmds.cpp
  14. +0 −8 src/date.cpp
  15. +0 −6 src/debug.cpp
  16. +0 −9 src/dedicated.cpp
  17. +0 −2 src/economy.cpp
  18. +0 −9 src/fileio.cpp
  19. +4 −8 src/fios.cpp
  20. +0 −4 src/fios_gui.cpp
  21. +0 −2 src/game/game.hpp
  22. +0 −4 src/game/game_core.cpp
  23. +0 −4 src/gfx.cpp
  24. +0 −8 src/goal.cpp
  25. +0 −2 src/intro_gui.cpp
  26. +1 −1 src/lang/english.txt
  27. +9 −19 src/main_gui.cpp
  28. +0 −2 src/misc.cpp
  29. +0 −6 src/misc_cmd.cpp
  30. +0 −4 src/network/core/address.cpp
  31. +0 −3 src/network/core/address.h
  32. +0 −4 src/network/core/core.cpp
  33. +0 −4 src/network/core/core.h
  34. +0 −4 src/network/core/game.h
  35. +0 −4 src/network/core/host.cpp
  36. +0 −4 src/network/core/os_abstraction.h
  37. +0 −4 src/network/core/packet.cpp
  38. +0 −4 src/network/core/packet.h
  39. +0 −4 src/network/core/tcp.cpp
  40. +0 −4 src/network/core/tcp.h
  41. +0 −4 src/network/core/tcp_admin.cpp
  42. +0 −4 src/network/core/tcp_admin.h
  43. +0 −4 src/network/core/tcp_connect.cpp
  44. +0 −4 src/network/core/tcp_content.cpp
  45. +0 −4 src/network/core/tcp_content.h
  46. +0 −4 src/network/core/tcp_game.cpp
  47. +0 −4 src/network/core/tcp_game.h
  48. +0 −4 src/network/core/tcp_http.cpp
  49. +0 −4 src/network/core/tcp_http.h
  50. +0 −4 src/network/core/tcp_listen.h
  51. +0 −4 src/network/core/udp.cpp
  52. +0 −4 src/network/core/udp.h
  53. +0 −4 src/network/network.cpp
  54. +0 −18 src/network/network.h
  55. +0 −4 src/network/network_admin.cpp
  56. +0 −3 src/network/network_admin.h
  57. +0 −3 src/network/network_base.h
  58. +0 −4 src/network/network_chat_gui.cpp
  59. +0 −4 src/network/network_client.cpp
  60. +0 −4 src/network/network_client.h
  61. +0 −4 src/network/network_command.cpp
  62. +0 −4 src/network/network_content.cpp
  63. +0 −6 src/network/network_content.h
  64. +0 −3 src/network/network_content_gui.cpp
  65. +0 −3 src/network/network_func.h
  66. +0 −4 src/network/network_gamelist.cpp
  67. +0 −3 src/network/network_gui.cpp
  68. +0 −12 src/network/network_gui.h
  69. +0 −3 src/network/network_internal.h
  70. +0 −4 src/network/network_server.cpp
  71. +0 −10 src/network/network_server.h
  72. +0 −3 src/network/network_type.h
  73. +0 −4 src/network/network_udp.cpp
  74. +0 −4 src/network/network_udp.h
  75. +0 −7 src/newgrf_config.cpp
  76. +0 −2 src/newgrf_config.h
  77. +0 −4 src/newgrf_gui.cpp
  78. +1 −38 src/openttd.cpp
  79. +0 −4 src/order_backup.cpp
  80. +0 −2 src/script/api/script_admin.cpp
  81. +0 −18 src/script/api/script_client.cpp
  82. +0 −4 src/script/api/script_clientlist.cpp
  83. +0 −4 src/script/api/script_game.cpp
  84. +0 −4 src/script/api/script_goal.cpp
  85. +0 −2 src/script/api/script_object.cpp
  86. +0 −6 src/script/script_scanner.cpp
  87. +0 −10 src/settings.cpp
  88. +0 −4 src/settings_func.h
  89. +0 −5 src/settings_type.h
  90. +1 −9 src/strings.cpp
  91. +0 −2 src/table/gameopt_settings.ini
  92. +1 −45 src/table/settings.ini
  93. +0 −10 src/toolbar_gui.cpp
  94. +0 −4 src/video/dedicated_v.cpp
  95. +0 −4 src/viewport.cpp
  96. +1 −4 src/window.cpp
@@ -289,8 +289,7 @@ EXPAND_ONLY_PREDEF = YES
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = ENABLE_NETWORK \
WITH_ZLIB \
PREDEFINED = WITH_ZLIB \
WITH_LZO \
WITH_LIBLZMA \
WITH_SDL \
@@ -52,7 +52,6 @@ set_default() {
enable_profiling="0"
enable_lto="0"
enable_dedicated="0"
enable_network="1"
enable_static="1"
enable_translator="0"
enable_unicode="1"
@@ -130,7 +129,6 @@ set_default() {
enable_profiling
enable_lto
enable_dedicated
enable_network
enable_static
enable_translator
enable_unicode
@@ -289,9 +287,6 @@ detect_params() {
--enable-ipo=*) enable_lto="$optarg";;
--enable-dedicated) enable_dedicated="1";;
--enable-dedicated=*) enable_dedicated="$optarg";;
--enable-network) enable_network="2";;
--enable-network=*) enable_network="$optarg";;
--disable-network) enable_network="0";;
--disable-static) enable_static="0";;
--enable-static) enable_static="2";;
--enable-static=*) enable_static="$optarg";;
@@ -749,11 +744,6 @@ check_params() {
if [ "$enable_dedicated" != "0" ]; then
log 1 "checking GDI video driver... dedicated server, skipping"
log 1 "checking dedicated... found"

if [ "$enable_network" = "0" ]; then
log 1 "configure: error: building a dedicated server without network support is pointless"
exit 1
fi
else
if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
log 1 "checking GDI video driver... found"
@@ -784,12 +774,6 @@ check_params() {
log 1 "checking console application... enabled"
fi

if [ "$enable_network" != "0" ]; then
log 1 "checking network... found"
else
log 1 "checking network... disabled"
fi

log 1 "checking squirrel... found"
SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include"

@@ -1833,16 +1817,12 @@ make_cflags_and_ldflags() {
CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
fi

if [ "$enable_network" != "0" ]; then
CFLAGS="$CFLAGS -DENABLE_NETWORK"

if [ "$os" = "HAIKU" ]; then
LDFLAGS="$LDFLAGS -lnetwork"
fi
if [ "$os" = "HAIKU" ]; then
LDFLAGS="$LDFLAGS -lnetwork"
fi

if [ "$os" = "SUNOS" ]; then
LDFLAGS="$LDFLAGS -lnsl -lsocket"
fi
if [ "$os" = "SUNOS" ]; then
LDFLAGS="$LDFLAGS -lnsl -lsocket"
fi

if [ "$enable_static" != "0" ]; then
@@ -3499,7 +3479,6 @@ showhelp() {
echo " --enable-console compile as a console application instead of as a GUI application."
echo " If this setting is active, debug output will appear in the same"
echo " console instead of opening a new window. (Win32 ONLY)"
echo " --disable-network disable network support"
echo " --disable-assert disable asserts (continue on errors)"
echo " --enable-strip enable any possible stripping"
echo " --without-osx-sysroot disable the automatic adding of sysroot "
@@ -164,11 +164,9 @@ class AI {
/** Gets the ScriptScanner instance that is used to find AI Libraries */
static AIScannerLibrary *GetScannerLibrary();

#if defined(ENABLE_NETWORK)
/** Wrapper function for AIScanner::HasAI */
static bool HasAI(const struct ContentInfo *ci, bool md5sum);
static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
#endif
private:
static uint frame_counter; ///< Tick counter for the AI code
static class AIScannerInfo *scanner_info; ///< ScriptScanner instance that is used to find AIs
@@ -362,8 +362,6 @@
InvalidateWindowClassesData(WC_AI_SETTINGS);
}

#if defined(ENABLE_NETWORK)

/**
* Check whether we have an AI (library) with the exact characteristics as ci.
* @param ci the characteristics to search on (shortname and md5sum)
@@ -380,8 +378,6 @@
return AI::scanner_library->HasScript(ci, md5sum);
}

#endif /* defined(ENABLE_NETWORK) */

/* static */ AIScannerInfo *AI::GetScannerInfo()
{
return AI::scanner_info;
@@ -928,9 +928,7 @@ struct AIConfigWindow : public Window {
if (!_network_available) {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
} else {
#if defined(ENABLE_NETWORK)
ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI, CONTENT_TYPE_GAME);
#endif
}
break;
}
@@ -277,7 +277,6 @@ template <class Tbase_set>
return p;
}

#if defined(ENABLE_NETWORK)
#include "network/network_content.h"

template <class Tbase_set> const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s)
@@ -307,22 +306,6 @@ template <class Tbase_set>
(TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != NULL);
}

#else

template <class Tbase_set>
const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s)
{
return NULL;
}

template <class Tbase_set>
/* static */ bool BaseMedia<Tbase_set>::HasSet(const ContentInfo *ci, bool md5sum)
{
return false;
}

#endif /* ENABLE_NETWORK */

/**
* Count the number of available graphics sets.
* @return the number of sets
@@ -13,7 +13,7 @@
#include "base_media_base.h"
#include "blitter/factory.hpp"

#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE)
#if defined(WITH_FREETYPE)

#include "core/geometry_func.hpp"
#include "fontcache.h"
@@ -204,7 +204,7 @@ class BootstrapAskForDownloadWindow : public Window, ContentCallback {
}
};

#endif /* defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) */
#endif /* defined(WITH_FREETYPE) */

/**
* Handle all procedures for bootstrapping OpenTTD without a base graphics set.
@@ -220,7 +220,7 @@ bool HandleBootstrap()
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;

/* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(_WIN32) || defined(__APPLE__))
#if defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(_WIN32) || defined(__APPLE__))
if (!_network_available) goto failure;

/* First tell the game we're bootstrapping. */
@@ -573,10 +573,8 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
return false;
}

#ifdef ENABLE_NETWORK
/* Only set p2 when the command does not come from the network. */
if (!(cmd & CMD_NETWORK_COMMAND) && GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = CLIENT_ID_SERVER;
#endif

CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only);
if (res.Failed()) {
@@ -646,10 +644,8 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
/* Flags get send to the DoCommand */
DoCommandFlag flags = CommandFlagsToDCFlags(cmd_flags);

#ifdef ENABLE_NETWORK
/* Make sure p2 is properly set to a ClientID. */
assert(!(cmd_flags & CMD_CLIENT_ID) || p2 != 0);
#endif

/* Do not even think about executing out-of-bounds tile-commands */
if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (cmd_flags & CMD_ALL_TILES) == 0))) return_dcpi(CMD_ERROR);
@@ -696,7 +692,6 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
return_dcpi(res);
}

#ifdef ENABLE_NETWORK
/*
* If we are in network, and the command is not from the network
* send it to the command-queue and abort execution
@@ -711,7 +706,6 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
* reset the storages as we've not executed the command. */
return_dcpi(CommandCost());
}
#endif /* ENABLE_NETWORK */
DEBUG(desync, 1, "cmd: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));

/* Actually try and execute the command. If no cost-type is given
@@ -42,9 +42,7 @@ bool DoCommandP(const CommandContainer *container, bool my_cmd = true);

CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only);

#ifdef ENABLE_NETWORK
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
#endif /* ENABLE_NETWORK */

extern Money _additional_cash_required;

@@ -104,10 +104,8 @@ void SetLocalCompany(CompanyID new_company)
/* company could also be COMPANY_SPECTATOR or OWNER_NONE */
assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);

#ifdef ENABLE_NETWORK
/* Delete the chat window, if you were team chatting. */
InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company);
#endif

assert(IsLocalCompany());

@@ -597,9 +595,7 @@ void StartupCompanies()
/** Start a new competitor company if possible. */
static bool MaybeStartNewCompany()
{
#ifdef ENABLE_NETWORK
if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return false;
#endif /* ENABLE_NETWORK */

Company *c;

@@ -792,9 +788,7 @@ void CompanyNewsInformation::FillData(const Company *c, const Company *other)
*/
void CompanyAdminUpdate(const Company *company)
{
#ifdef ENABLE_NETWORK
if (_network_server) NetworkAdminCompanyUpdate(company);
#endif /* ENABLE_NETWORK */
}

/**
@@ -804,9 +798,7 @@ void CompanyAdminUpdate(const Company *company)
*/
void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
{
#ifdef ENABLE_NETWORK
if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason);
#endif /* ENABLE_NETWORK */
}

/**
@@ -832,7 +824,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* This command is only executed in a multiplayer game */
if (!_networking) return CMD_ERROR;

#ifdef ENABLE_NETWORK
/* Has the network client a correct ClientIndex? */
if (!(flags & DC_EXEC)) return CommandCost();

@@ -876,7 +867,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}

NetworkServerNewCompany(c, ci);
#endif /* ENABLE_NETWORK */
break;
}

@@ -885,9 +875,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3

if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
Company *c = DoStartupNewCompany(true, company_id);
#ifdef ENABLE_NETWORK
if (c != NULL) NetworkServerNewCompany(c, NULL);
#endif /* ENABLE_NETWORK */
break;
}

@@ -2387,11 +2387,9 @@ struct CompanyWindow : Window
break;
}

#ifdef ENABLE_NETWORK
case WID_C_HAS_PASSWORD:
*size = maxdim(*size, GetSpriteSize(SPR_LOCK));
break;
#endif /* ENABLE_NETWORK */
}
}

@@ -2498,13 +2496,11 @@ struct CompanyWindow : Window
break;
}

#ifdef ENABLE_NETWORK
case WID_C_HAS_PASSWORD:
if (_networking && NetworkCompanyIsPassworded(c->index)) {
DrawSprite(SPR_LOCK, PAL_NONE, r.left, r.top);
}
break;
#endif /* ENABLE_NETWORK */
}
}

@@ -2594,7 +2590,6 @@ struct CompanyWindow : Window
DoCommandP(0, this->window_number, 0, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_ERROR_CAN_T_SELL_25_SHARE_IN));
break;

#ifdef ENABLE_NETWORK
case WID_C_COMPANY_PASSWORD:
if (this->window_number == _local_company) ShowNetworkCompanyPasswordWindow(this);
break;
@@ -2614,7 +2609,6 @@ struct CompanyWindow : Window
}
break;
}
#endif /* ENABLE_NETWORK */
}
}

@@ -2652,11 +2646,9 @@ struct CompanyWindow : Window
DoCommandP(0, 0, 0, CMD_RENAME_COMPANY | CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME), NULL, str);
break;

#ifdef ENABLE_NETWORK
case WID_C_COMPANY_JOIN:
NetworkClientRequestMove((CompanyID)this->window_number, str);
break;
#endif /* ENABLE_NETWORK */
}
}

@@ -33,10 +33,8 @@ FILE *_iconsole_output_file;
void IConsoleInit()
{
_iconsole_output_file = NULL;
#ifdef ENABLE_NETWORK /* Initialize network only variables */
_redirect_console_to_client = INVALID_CLIENT_ID;
_redirect_console_to_admin = INVALID_ADMIN_ID;
#endif

IConsoleGUIInit();

@@ -90,7 +88,6 @@ void IConsolePrint(TextColour colour_code, const char *string)
assert(IsValidConsoleColour(colour_code));

char *str;
#ifdef ENABLE_NETWORK
if (_redirect_console_to_client != INVALID_CLIENT_ID) {
/* Redirect the string to the client */
NetworkServerSendRcon(_redirect_console_to_client, colour_code, string);
@@ -101,7 +98,6 @@ void IConsolePrint(TextColour colour_code, const char *string)
NetworkServerSendAdminRcon(_redirect_console_to_admin, colour_code, string);
return;
}
#endif

/* Create a copy of the string, strip if of colours and invalid
* characters and (when applicable) assign it to the console buffer */
@@ -110,9 +106,7 @@ void IConsolePrint(TextColour colour_code, const char *string)
str_validate(str, str + strlen(str));

if (_network_dedicated) {
#ifdef ENABLE_NETWORK
NetworkAdminConsole("console", str);
#endif /* ENABLE_NETWORK */
fprintf(stdout, "%s%s\n", GetLogPrefix(), str);
fflush(stdout);
IConsoleWriteToLogFile(str);
Oops, something went wrong.

0 comments on commit e3c639a

Please sign in to comment.
You can’t perform that action at this time.