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.
This commit is contained in:
Patric Stout
2019-03-20 17:01:13 +01:00
parent 72c5f2b3ee
commit e3c639a09f
96 changed files with 29 additions and 600 deletions

View File

@@ -11,8 +11,6 @@
#include "../../stdafx.h"
#ifdef ENABLE_NETWORK
#include "address.h"
#include "../../debug.h"
@@ -433,5 +431,3 @@ void NetworkAddress::Listen(int socktype, SocketList *sockets)
default: return "unsupported";
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,8 +17,6 @@
#include "../../string_func.h"
#include "../../core/smallmap_type.hpp"
#ifdef ENABLE_NETWORK
class NetworkAddress;
typedef SmallVector<NetworkAddress, 4> NetworkAddressList; ///< Type for a list of addresses.
typedef SmallMap<NetworkAddress, SOCKET, 4> SocketList; ///< Type for a mapping between address and socket.
@@ -192,5 +190,4 @@ public:
static const char *AddressFamilyAsString(int family);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_ADDRESS_H */

View File

@@ -11,8 +11,6 @@
* @file core.cpp Functions used to initialize/shut down the core network
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
#include "os_abstraction.h"
@@ -80,5 +78,3 @@ void NetworkSocketHandler::ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
grf->md5sum[j] = p->Recv_uint8();
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,8 +17,6 @@
#include "../../newgrf_config.h"
#include "config.h"
#ifdef ENABLE_NETWORK
bool NetworkCoreInitialize();
void NetworkCoreShutdown();
@@ -80,6 +78,4 @@ public:
void SendCompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len = NETWORK_COMPANY_NAME_LENGTH);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_CORE_H */

View File

@@ -19,8 +19,6 @@
#include "../../newgrf_config.h"
#include "../../date_type.h"
#ifdef ENABLE_NETWORK
/**
* The game information that is not generated on-the-fly and has to
* be sent to the clients.
@@ -58,6 +56,4 @@ struct NetworkGameInfo : NetworkServerGameInfo {
const char * GetNetworkRevisionString();
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_GAME_H */

View File

@@ -9,8 +9,6 @@
/** @file host.cpp Functions related to getting host specific data (IPs). */
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
#include "address.h"
@@ -207,5 +205,3 @@ void NetworkFindBroadcastIPs(NetworkAddressList *broadcast)
DEBUG(net, 3, "%d) %s", i++, addr->GetHostname());
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -18,8 +18,6 @@
/* Include standard stuff per OS */
#ifdef ENABLE_NETWORK
/* Windows stuff */
#if defined(_WIN32)
#include <errno.h>
@@ -172,6 +170,4 @@ static inline bool SetNoDelay(SOCKET d)
assert_compile(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
assert_compile(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_OS_ABSTRACTION_H */

View File

@@ -11,8 +11,6 @@
* @file packet.cpp Basic functions to create, fill and read packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../string_func.h"
@@ -310,5 +308,3 @@ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings set
str_validate(bufp, last, settings);
}
#endif /* ENABLE_NETWORK */

View File

@@ -18,8 +18,6 @@
#include "core.h"
#include "../../string_type.h"
#ifdef ENABLE_NETWORK
typedef uint16 PacketSize; ///< Size of the whole packet.
typedef uint8 PacketType; ///< Identifier for the packet
@@ -87,6 +85,4 @@ public:
void Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_PACKET_H */

View File

@@ -11,8 +11,6 @@
* @file tcp.cpp Basic functions to receive and send TCP packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
@@ -243,5 +241,3 @@ bool NetworkTCPSocketHandler::CanSendReceive()
this->writable = !!FD_ISSET(this->sock, &write_fd);
return FD_ISSET(this->sock, &read_fd) != 0;
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,8 +17,6 @@
#include "address.h"
#include "packet.h"
#ifdef ENABLE_NETWORK
/** The states of sending the packets. */
enum SendPacketsState {
SPS_CLOSED, ///< The connection got closed.
@@ -99,6 +97,4 @@ public:
static void KillAll();
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_admin.cpp Basic functions to receive and send TCP packets to and from the admin network.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../network_internal.h"
@@ -172,5 +170,3 @@ NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_NAMES(Packet *p)
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_LOGGING(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_LOGGING); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON_END(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON_END); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PONG(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PONG); }
#endif /* ENABLE_NETWORK */

View File

@@ -19,8 +19,6 @@
#include "../network_type.h"
#include "../../core/pool_type.hpp"
#ifdef ENABLE_NETWORK
/**
* Enum with types of TCP packets specific to the admin network.
* This protocol may only be extended to ensure stability.
@@ -500,6 +498,4 @@ public:
}
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_ADMIN_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_connect.cpp Basic functions to create connections without blocking.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../thread/thread.h"
@@ -97,5 +95,3 @@ void TCPConnecter::Connect()
{
for (TCPConnecter **iter = _tcp_connecters.Begin(); iter != _tcp_connecters.End(); iter++) (*iter)->killed = true;
}
#endif /* ENABLE_NETWORK */

View File

@@ -11,8 +11,6 @@
* @file tcp_content.cpp Basic functions to receive and send Content packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#ifndef OPENTTD_MSU
#include "../../textfile_gui.h"
@@ -266,5 +264,3 @@ Subdirectory GetContentInfoSubDir(ContentType type)
}
}
#endif /* OPENTTD_MSU */
#endif /* ENABLE_NETWORK */

View File

@@ -19,8 +19,6 @@
#include "packet.h"
#include "../../debug.h"
#ifdef ENABLE_NETWORK
/** The values in the enum are important; they are used as database 'keys' */
enum ContentType {
CONTENT_TYPE_BEGIN = 1, ///< Helper to mark the begin of the types
@@ -213,6 +211,4 @@ public:
Subdirectory GetContentInfoSubDir(ContentType type);
#endif /* OPENTTD_MSU */
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_CONTENT_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_game.cpp Basic functions to receive and send TCP packets for game purposes.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../network.h"
@@ -199,5 +197,3 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p) { ret
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MOVE); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_UPDATE); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
#endif /* ENABLE_NETWORK */

View File

@@ -19,8 +19,6 @@
#include "../network_type.h"
#include "../../core/pool_type.hpp"
#ifdef ENABLE_NETWORK
/**
* Enum with all types of TCP packets.
* For the exact meaning, look at #NetworkGameSocketHandler.
@@ -558,6 +556,4 @@ public:
void SendCommand(Packet *p, const CommandPacket *cp);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_GAME_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_http.cpp Basic functions to receive and send HTTP TCP packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
#include "../../rev.h"
@@ -331,5 +329,3 @@ int NetworkHTTPSocketHandler::Receive()
iter++;
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -16,8 +16,6 @@
#include "tcp.h"
#ifdef ENABLE_NETWORK
/** Callback for when the HTTP handler has something to tell us. */
struct HTTPCallback {
/**
@@ -122,6 +120,4 @@ public:
}
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_HTTP_H */

View File

@@ -20,8 +20,6 @@
#include "../../debug.h"
#include "table/strings.h"
#ifdef ENABLE_NETWORK
/**
* Template for TCP listeners.
* @param Tsocket The class we create sockets for.
@@ -173,6 +171,4 @@ public:
template <class Tsocket, PacketType Tfull_packet, PacketType Tban_packet> SocketList TCPListenHandler<Tsocket, Tfull_packet, Tban_packet>::sockets;
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_LISTEN_H */

View File

@@ -11,8 +11,6 @@
* @file core/udp.cpp Basic functions to receive and send UDP packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../date_func.h"
#include "../../debug.h"
@@ -347,5 +345,3 @@ void NetworkUDPSocketHandler::Receive_SERVER_UNREGISTER(Packet *p, NetworkAddres
void NetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_GET_NEWGRFS, client_addr); }
void NetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_NEWGRFS, client_addr); }
void NetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_MASTER_SESSION_KEY, client_addr); }
#endif /* ENABLE_NETWORK */

View File

@@ -18,8 +18,6 @@
#include "game.h"
#include "packet.h"
#ifdef ENABLE_NETWORK
/** Enum with all types of UDP packets. The order MUST not be changed **/
enum PacketUDPType {
PACKET_UDP_CLIENT_FIND_SERVER, ///< Queries a game server for game information
@@ -246,6 +244,4 @@ public:
void ReceiveNetworkGameInfo(Packet *p, NetworkGameInfo *info);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_UDP_H */