mirror of https://github.com/OpenTTD/OpenTTD
(svn r13713) -Fix: possible crash on creating a network packet.
parent
2e4f32023c
commit
60a6582590
|
@ -20,7 +20,7 @@ enum {
|
||||||
SEND_MTU = 1460, ///< Number of bytes we can pack in a single packet
|
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_GAME_INFO_VERSION = 4, ///< What version of game-info do we use?
|
||||||
NETWORK_COMPANY_INFO_VERSION = 4, ///< What version of company info is this?
|
NETWORK_COMPANY_INFO_VERSION = 5, ///< What version of company info is this?
|
||||||
NETWORK_MASTER_SERVER_VERSION = 1, ///< What version of master-server-protocol do we use?
|
NETWORK_MASTER_SERVER_VERSION = 1, ///< 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_NAME_LENGTH = 80, ///< The maximum length of the server name and map name, in bytes including '\0'
|
||||||
|
|
|
@ -108,12 +108,6 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_FIND_SERVER)
|
||||||
|
|
||||||
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
|
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
|
||||||
{
|
{
|
||||||
NetworkTCPSocketHandler *cs;
|
|
||||||
NetworkClientInfo *ci;
|
|
||||||
Player *player;
|
|
||||||
byte current = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// Just a fail-safe.. should never happen
|
// Just a fail-safe.. should never happen
|
||||||
if (!_network_udp_server) return;
|
if (!_network_udp_server) return;
|
||||||
|
|
||||||
|
@ -126,6 +120,8 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
|
||||||
/* Fetch the latest version of everything */
|
/* Fetch the latest version of everything */
|
||||||
NetworkPopulateCompanyInfo();
|
NetworkPopulateCompanyInfo();
|
||||||
|
|
||||||
|
Player *player;
|
||||||
|
byte current = 0;
|
||||||
/* Go through all the players */
|
/* Go through all the players */
|
||||||
FOR_ALL_PLAYERS(player) {
|
FOR_ALL_PLAYERS(player) {
|
||||||
/* Skip non-active players */
|
/* Skip non-active players */
|
||||||
|
@ -146,58 +142,15 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
|
||||||
/* Send 1 if there is a passord for the company else send 0 */
|
/* Send 1 if there is a passord for the company else send 0 */
|
||||||
packet.Send_bool (!StrEmpty(_network_player_info[player->index].password));
|
packet.Send_bool (!StrEmpty(_network_player_info[player->index].password));
|
||||||
|
|
||||||
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
|
for (int i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
|
||||||
packet.Send_uint16(_network_player_info[player->index].num_vehicle[i]);
|
packet.Send_uint16(_network_player_info[player->index].num_vehicle[i]);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < NETWORK_STATION_TYPES; i++)
|
for (int i = 0; i < NETWORK_STATION_TYPES; i++) {
|
||||||
packet.Send_uint16(_network_player_info[player->index].num_station[i]);
|
packet.Send_uint16(_network_player_info[player->index].num_station[i]);
|
||||||
|
|
||||||
/* Find the clients that are connected to this player */
|
|
||||||
FOR_ALL_CLIENTS(cs) {
|
|
||||||
ci = DEREF_CLIENT_INFO(cs);
|
|
||||||
if (ci->client_playas == player->index) {
|
|
||||||
packet.Send_bool (true);
|
|
||||||
packet.Send_string(ci->client_name);
|
|
||||||
packet.Send_string(ci->unique_id);
|
|
||||||
packet.Send_uint32(ci->join_date);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Also check for the server itself */
|
|
||||||
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
|
||||||
if (ci->client_playas == player->index) {
|
|
||||||
packet.Send_bool (true);
|
|
||||||
packet.Send_string(ci->client_name);
|
|
||||||
packet.Send_string(ci->unique_id);
|
|
||||||
packet.Send_uint32(ci->join_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indicates end of client list */
|
|
||||||
packet.Send_bool(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And check if we have any spectators */
|
|
||||||
FOR_ALL_CLIENTS(cs) {
|
|
||||||
ci = DEREF_CLIENT_INFO(cs);
|
|
||||||
if (!IsValidPlayer(ci->client_playas)) {
|
|
||||||
packet.Send_bool (true);
|
|
||||||
packet.Send_string(ci->client_name);
|
|
||||||
packet.Send_string(ci->unique_id);
|
|
||||||
packet.Send_uint32(ci->join_date);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Also check for the server itself */
|
|
||||||
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
|
||||||
if (!IsValidPlayer(ci->client_playas)) {
|
|
||||||
packet.Send_bool (true);
|
|
||||||
packet.Send_string(ci->client_name);
|
|
||||||
packet.Send_string(ci->unique_id);
|
|
||||||
packet.Send_uint32(ci->join_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indicates end of client list */
|
|
||||||
packet.Send_bool(false);
|
|
||||||
|
|
||||||
this->SendPacket(&packet, client_addr);
|
this->SendPacket(&packet, client_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue