diff --git a/src/network/core/config.h b/src/network/core/config.h index 2914245ddb..2df6162e23 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -15,58 +15,58 @@ #define NETWORK_CORE_CONFIG_H /** DNS hostname of the masterserver */ -#define NETWORK_MASTER_SERVER_HOST "master.openttd.org" +static const char * const NETWORK_MASTER_SERVER_HOST = "master.openttd.org"; /** DNS hostname of the content server */ -#define NETWORK_CONTENT_SERVER_HOST "content.openttd.org" +static const char * const NETWORK_CONTENT_SERVER_HOST = "content.openttd.org"; /** DNS hostname of the HTTP-content mirror server */ -#define NETWORK_CONTENT_MIRROR_HOST "binaries.openttd.org" +static const char * const NETWORK_CONTENT_MIRROR_HOST = "binaries.openttd.org"; /** URL of the HTTP mirror system */ -#define NETWORK_CONTENT_MIRROR_URL "/bananas" +static const char * const NETWORK_CONTENT_MIRROR_URL = "/bananas"; /** Message sent to the masterserver to 'identify' this client as OpenTTD */ -#define NETWORK_MASTER_SERVER_WELCOME_MESSAGE "OpenTTDRegister" +static const char * const NETWORK_MASTER_SERVER_WELCOME_MESSAGE = "OpenTTDRegister"; -enum { - NETWORK_MASTER_SERVER_PORT = 3978, ///< The default port of the master server (UDP) - NETWORK_CONTENT_SERVER_PORT = 3978, ///< The default port of the content server (TCP) - NETWORK_CONTENT_MIRROR_PORT = 80, ///< The default port of the content mirror (TCP) - NETWORK_DEFAULT_PORT = 3979, ///< The default port of the game server (TCP & UDP) - NETWORK_DEFAULT_DEBUGLOG_PORT = 3982, ///< The default port debug-log is sent too (TCP) +static const uint16 NETWORK_MASTER_SERVER_PORT = 3978; ///< The default port of the master server (UDP) +static const uint16 NETWORK_CONTENT_SERVER_PORT = 3978; ///< The default port of the content server (TCP) +static const uint16 NETWORK_CONTENT_MIRROR_PORT = 80; ///< The default port of the content mirror (TCP) +static const uint16 NETWORK_DEFAULT_PORT = 3979; ///< The default port of the game server (TCP & UDP) +static const uint16 NETWORK_DEFAULT_DEBUGLOG_PORT = 3982; ///< The default port debug-log is sent too (TCP) - SEND_MTU = 1460, ///< Number of bytes we can pack in a single packet +static const uint16 SEND_MTU = 1460; ///< Number of bytes we can pack in a single packet - NETWORK_GAME_INFO_VERSION = 4, ///< What version of game-info do we use? - NETWORK_COMPANY_INFO_VERSION = 6, ///< What version of company info is this? - NETWORK_MASTER_SERVER_VERSION = 2, ///< What version of master-server-protocol do we use? +static const byte NETWORK_GAME_INFO_VERSION = 4; ///< What version of game-info do we use? +static const byte NETWORK_COMPANY_INFO_VERSION = 6; ///< What version of company info is this? +static const byte NETWORK_MASTER_SERVER_VERSION = 2; ///< What version of master-server-protocol do we use? - NETWORK_NAME_LENGTH = 80, ///< The maximum length of the server name and map name, in bytes including '\0' - NETWORK_COMPANY_NAME_LENGTH = 31, ///< The maximum length of the company name, in bytes including '\0' - NETWORK_HOSTNAME_LENGTH = 80, ///< The maximum length of the host name, in bytes including '\0' - NETWORK_SERVER_ID_LENGTH = 33, ///< The maximum length of the network id of the servers, in bytes including '\0' - NETWORK_REVISION_LENGTH = 15, ///< The maximum length of the revision, in bytes including '\0' - NETWORK_PASSWORD_LENGTH = 33, ///< The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH) - NETWORK_CLIENTS_LENGTH = 200, ///< The maximum length for the list of clients that controls a company, in bytes including '\0' - NETWORK_CLIENT_NAME_LENGTH = 25, ///< The maximum length of a client's name, in bytes including '\0' - NETWORK_RCONCOMMAND_LENGTH = 500, ///< The maximum length of a rconsole command, in bytes including '\0' - NETWORK_CHAT_LENGTH = 900, ///< The maximum length of a chat message, in bytes including '\0' +static const uint NETWORK_NAME_LENGTH = 80; ///< The maximum length of the server name and map name, in bytes including '\0' +static const uint NETWORK_COMPANY_NAME_LENGTH = 31; ///< The maximum length of the company name, in bytes including '\0' +static const uint NETWORK_HOSTNAME_LENGTH = 80; ///< The maximum length of the host name, in bytes including '\0' +static const uint NETWORK_SERVER_ID_LENGTH = 33; ///< The maximum length of the network id of the servers, in bytes including '\0' +static const uint NETWORK_REVISION_LENGTH = 15; ///< The maximum length of the revision, in bytes including '\0' +static const uint NETWORK_PASSWORD_LENGTH = 33; ///< The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH) +static const uint NETWORK_CLIENTS_LENGTH = 200; ///< The maximum length for the list of clients that controls a company, in bytes including '\0' +static const uint NETWORK_CLIENT_NAME_LENGTH = 25; ///< The maximum length of a client's name, in bytes including '\0' +static const uint NETWORK_RCONCOMMAND_LENGTH = 500; ///< The maximum length of a rconsole command, in bytes including '\0' +static const uint NETWORK_CHAT_LENGTH = 900; ///< The maximum length of a chat message, in bytes including '\0' - NETWORK_GRF_NAME_LENGTH = 80, ///< Maximum length of the name of a GRF - /** - * Maximum number of GRFs that can be sent. - * This value is related to number of handles (files) OpenTTD can open. - * This is currently 64. Two are used for configuration and sound. - */ - NETWORK_MAX_GRF_COUNT = 62, +static const uint NETWORK_GRF_NAME_LENGTH = 80; ///< Maximum length of the name of a GRF - NETWORK_NUM_LANGUAGES = 36, ///< Number of known languages (to the network protocol) + 1 for 'any'. - /** - * The number of landscapes in OpenTTD. - * This number must be equal to NUM_LANDSCAPE, but as this number is used - * within the network code and that the network code is shared with the - * masterserver/updater, it has to be declared in here too. In network.cpp - * there is a compile assertion to check that this NUM_LANDSCAPE is equal - * to NETWORK_NUM_LANDSCAPES. - */ - NETWORK_NUM_LANDSCAPES = 4, -}; +/** + * Maximum number of GRFs that can be sent. + * This value is related to number of handles (files) OpenTTD can open. + * This is currently 64. Two are used for configuration and sound. + */ +static const uint NETWORK_MAX_GRF_COUNT = 62; + +static const uint NETWORK_NUM_LANGUAGES = 36; ///< Number of known languages (to the network protocol) + 1 for 'any'. + +/** + * The number of landscapes in OpenTTD. + * This number must be equal to NUM_LANDSCAPE, but as this number is used + * within the network code and that the network code is shared with the + * masterserver/updater, it has to be declared in here too. In network.cpp + * there is a compile assertion to check that this NUM_LANDSCAPE is equal + * to NETWORK_NUM_LANDSCAPES. + */ +static const uint NETWORK_NUM_LANDSCAPES = 4; #endif /* NETWORK_CORE_CONFIG_H */ diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index c5f56486e0..70a261d08d 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -27,7 +27,7 @@ * it protects old clients from joining newer servers * (because SERVER_ERROR is the respond to a wrong revision) */ -enum { +enum TCPPacketType { PACKET_SERVER_FULL, PACKET_SERVER_BANNED, PACKET_CLIENT_JOIN, diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 19f07ae643..89086451a0 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -423,10 +423,12 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) company_info->income = p->Recv_uint64(); company_info->performance = p->Recv_uint16(); company_info->use_password = p->Recv_bool(); - for (int i = 0; i < NETWORK_VEHICLE_TYPES; i++) + for (uint i = 0; i < NETWORK_VEHICLE_TYPES; i++) { company_info->num_vehicle[i] = p->Recv_uint16(); - for (int i = 0; i < NETWORK_STATION_TYPES; i++) + } + for (uint i = 0; i < NETWORK_STATION_TYPES; i++) { company_info->num_station[i] = p->Recv_uint16(); + } company_info->ai = p->Recv_bool(); p->Recv_string(company_info->clients, sizeof(company_info->clients)); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 93f5d06c3b..6f1f3b4b5c 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1375,11 +1375,11 @@ void NetworkSocketHandler::Send_CompanyInformation(Packet *p, const Company *c, /* Send 1 if there is a passord for the company else send 0 */ p->Send_bool (!StrEmpty(_network_company_states[c->index].password)); - for (int i = 0; i < NETWORK_VEHICLE_TYPES; i++) { + for (uint i = 0; i < NETWORK_VEHICLE_TYPES; i++) { p->Send_uint16(stats->num_vehicle[i]); } - for (int i = 0; i < NETWORK_STATION_TYPES; i++) { + for (uint i = 0; i < NETWORK_STATION_TYPES; i++) { p->Send_uint16(stats->num_station[i]); } diff --git a/src/network/network_type.h b/src/network/network_type.h index f023fe985c..08bd7756d7 100644 --- a/src/network/network_type.h +++ b/src/network/network_type.h @@ -16,21 +16,20 @@ #ifdef ENABLE_NETWORK -enum { - /** How many clients can we have */ - MAX_CLIENTS = 255, +/** How many clients can we have */ +static const uint MAX_CLIENTS = 255; - /** - * The number of slots; must be at least 1 more than MAX_CLIENTS. It must - * furthermore be less than or equal to 256 as client indices (sent over - * the network) are 8 bits. It needs 1 more for the dedicated server. - */ - MAX_CLIENT_SLOTS = 256, +/** + * The number of slots; must be at least 1 more than MAX_CLIENTS. It must + * furthermore be less than or equal to 256 as client indices (sent over + * the network) are 8 bits. It needs 1 more for the dedicated server. + */ +static const uint MAX_CLIENT_SLOTS = 256; - /** How many vehicle/station types we put over the network */ - NETWORK_VEHICLE_TYPES = 5, - NETWORK_STATION_TYPES = 5, -}; +/** How many vehicle types we put over the network */ +static const uint NETWORK_VEHICLE_TYPES = 5; +/** How many station types we put over the network */ +static const uint NETWORK_STATION_TYPES = 5; /** 'Unique' identifier to be given to clients */ enum ClientID {