summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-01-22 21:38:16 +0000
committerrubidium <rubidium@openttd.org>2007-01-22 21:38:16 +0000
commit3e10a726e5dc4d404c345d315e7cc842f0a89aae (patch)
treee33e67b3ace7674df99e3280245f93ee27408126 /src/network
parent5f72bb18caff46471382d84ad54c5ddae631f83b (diff)
downloadopenttd-3e10a726e5dc4d404c345d315e7cc842f0a89aae.tar.xz
(svn r8361) -Codechange: make sure the range of the dates coming from the network are valid in OpenTTD
-Codechange: use_password is a boolean variable -Codechange: move range checking for server_lang and map_set to Recv_NetworkGameInfo
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/game.h2
-rw-r--r--src/network/core/udp.cpp11
-rw-r--r--src/network/network_udp.cpp3
3 files changed, 9 insertions, 7 deletions
diff --git a/src/network/core/game.h b/src/network/core/game.h
index 2c0a0178b..6c96527fb 100644
--- a/src/network/core/game.h
+++ b/src/network/core/game.h
@@ -27,7 +27,7 @@ typedef struct NetworkGameInfo {
bool version_compatible; ///< Can we connect to this server or not? (based on server_revision)
bool compatible; ///< Can we connect to this server or not? (based on server_revision _and_ grf_match
byte server_lang; ///< Language of the server (we should make a nice table for this)
- byte use_password; ///< Is set to != 0 if it uses a password
+ bool use_password; ///< Is this server passworded?
char server_password[NETWORK_PASSWORD_LENGTH]; ///< On the server: the game password, on the client: != "" if server has password
byte clients_max; ///< Max clients allowed on server
byte clients_on; ///< Current count of clients on server
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 8474c65f3..38309d326 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -245,6 +245,8 @@ void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameI
*/
void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *info)
{
+ static const Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
+
info->game_info_version = NetworkRecv_uint8(this, p);
/*
@@ -272,8 +274,8 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
}
} /* Fallthrough */
case 3:
- info->game_date = NetworkRecv_uint32(this, p);
- info->start_date = NetworkRecv_uint32(this, p);
+ info->game_date = clamp(NetworkRecv_uint32(this, p), 0, MAX_DATE);
+ info->start_date = clamp(NetworkRecv_uint32(this, p), 0, MAX_DATE);
/* Fallthrough */
case 2:
info->companies_max = NetworkRecv_uint8 (this, p);
@@ -284,7 +286,7 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
NetworkRecv_string(this, p, info->server_name, sizeof(info->server_name));
NetworkRecv_string(this, p, info->server_revision, sizeof(info->server_revision));
info->server_lang = NetworkRecv_uint8 (this, p);
- info->use_password = NetworkRecv_uint8 (this, p);
+ info->use_password = (NetworkRecv_uint8 (this, p) != 0);
info->clients_max = NetworkRecv_uint8 (this, p);
info->clients_on = NetworkRecv_uint8 (this, p);
info->spectators_on = NetworkRecv_uint8 (this, p);
@@ -297,6 +299,9 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
info->map_height = NetworkRecv_uint16(this, p);
info->map_set = NetworkRecv_uint8 (this, p);
info->dedicated = (NetworkRecv_uint8(this, p) != 0);
+
+ if (info->server_lang >= NETWORK_NUM_LANGUAGES) info->server_lang = 0;
+ if (info->map_set >= NUM_LANDSCAPE) info->map_set = 0;
}
}
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 08a145717..2b7fe7d94 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -330,9 +330,6 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE)
}
}
- if (item->info.server_lang >= NETWORK_NUM_LANGUAGES) item->info.server_lang = 0;
- if (item->info.map_set >= NUM_LANDSCAPE ) item->info.map_set = 0;
-
if (item->info.hostname[0] == '\0')
snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr));