|
@@ -54,39 +54,41 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
|
|
|
return;
|
|
|
|
|
|
packet = NetworkSend_Init(PACKET_UDP_SERVER_RESPONSE);
|
|
|
|
|
|
// Update some game_info
|
|
|
_network_game_info.game_date = _date;
|
|
|
_network_game_info.map_width = MapSizeX();
|
|
|
_network_game_info.map_height = MapSizeY();
|
|
|
_network_game_info.map_set = _opt.landscape;
|
|
|
|
|
|
NetworkSend_uint8 (packet, NETWORK_GAME_INFO_VERSION);
|
|
|
|
|
|
/* NETWORK_GAME_INFO_VERSION = 3 */
|
|
|
NetworkSend_uint32(packet, _network_game_info.game_date);
|
|
|
NetworkSend_uint32(packet, _network_game_info.start_date);
|
|
|
|
|
|
/* NETWORK_GAME_INFO_VERSION = 2 */
|
|
|
NetworkSend_uint8 (packet, _network_game_info.companies_max);
|
|
|
NetworkSend_uint8 (packet, ActivePlayerCount());
|
|
|
NetworkSend_uint8 (packet, _network_game_info.spectators_max);
|
|
|
|
|
|
/* NETWORK_GAME_INFO_VERSION = 1 */
|
|
|
NetworkSend_string(packet, _network_game_info.server_name);
|
|
|
NetworkSend_string(packet, _network_game_info.server_revision);
|
|
|
NetworkSend_uint8 (packet, _network_game_info.server_lang);
|
|
|
NetworkSend_uint8 (packet, _network_game_info.use_password);
|
|
|
NetworkSend_uint8 (packet, _network_game_info.clients_max);
|
|
|
NetworkSend_uint8 (packet, _network_game_info.clients_on);
|
|
|
NetworkSend_uint8 (packet, NetworkSpectatorCount());
|
|
|
NetworkSend_uint16(packet, _network_game_info.game_date);
|
|
|
NetworkSend_uint16(packet, _network_game_info.start_date);
|
|
|
NetworkSend_string(packet, _network_game_info.map_name);
|
|
|
NetworkSend_uint16(packet, _network_game_info.map_width);
|
|
|
NetworkSend_uint16(packet, _network_game_info.map_height);
|
|
|
NetworkSend_uint8 (packet, _network_game_info.map_set);
|
|
|
NetworkSend_uint8 (packet, _network_game_info.dedicated);
|
|
|
|
|
|
// Let the client know that we are here
|
|
|
NetworkSendUDP_Packet(_udp_server_socket, packet, client_addr);
|
|
|
|
|
|
free(packet);
|
|
|
|
|
|
DEBUG(net, 2)("[NET][UDP] Queried from %s", inet_ntoa(client_addr->sin_addr));
|
|
@@ -105,39 +107,45 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVE
|
|
|
game_info_version = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
|
|
|
if (_udp_cs.quited) return;
|
|
|
|
|
|
DEBUG(net, 6)("[NET][UDP] Server response from %s:%d", inet_ntoa(client_addr->sin_addr),ntohs(client_addr->sin_port));
|
|
|
|
|
|
// Find next item
|
|
|
item = NetworkGameListAddItem(inet_addr(inet_ntoa(client_addr->sin_addr)), ntohs(client_addr->sin_port));
|
|
|
|
|
|
/* Please observer the order. In the order in which packets are sent
|
|
|
* they are to be received */
|
|
|
switch (game_info_version) {
|
|
|
case 3:
|
|
|
item->info.game_date = NetworkRecv_uint32(&_udp_cs, p);
|
|
|
item->info.start_date = NetworkRecv_uint32(&_udp_cs, p);
|
|
|
/* Fallthrough */
|
|
|
case 2:
|
|
|
item->info.companies_max = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.companies_on = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.spectators_max = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
/* Fallthrough */
|
|
|
case 1:
|
|
|
NetworkRecv_string(&_udp_cs, p, item->info.server_name, sizeof(item->info.server_name));
|
|
|
NetworkRecv_string(&_udp_cs, p, item->info.server_revision, sizeof(item->info.server_revision));
|
|
|
item->info.server_lang = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.use_password = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.clients_max = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.clients_on = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.spectators_on = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.game_date = NetworkRecv_uint16(&_udp_cs, p);
|
|
|
item->info.start_date = NetworkRecv_uint16(&_udp_cs, p);
|
|
|
if (game_info_version < 3) { // 16 bits dates got scrapped and are read earlier
|
|
|
item->info.game_date = NetworkRecv_uint16(&_udp_cs, p) + DAYS_TILL_ORIGINAL_BASE_YEAR;
|
|
|
item->info.start_date = NetworkRecv_uint16(&_udp_cs, p) + DAYS_TILL_ORIGINAL_BASE_YEAR;
|
|
|
}
|
|
|
NetworkRecv_string(&_udp_cs, p, item->info.map_name, sizeof(item->info.map_name));
|
|
|
item->info.map_width = NetworkRecv_uint16(&_udp_cs, p);
|
|
|
item->info.map_height = NetworkRecv_uint16(&_udp_cs, p);
|
|
|
item->info.map_set = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
item->info.dedicated = NetworkRecv_uint8(&_udp_cs, p);
|
|
|
|
|
|
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));
|
|
|
|
|
@@ -176,25 +184,25 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
|
|
|
|
|
|
/* Go through all the players */
|
|
|
FOR_ALL_PLAYERS(player) {
|
|
|
/* Skip non-active players */
|
|
|
if (!player->is_active) continue;
|
|
|
|
|
|
current++;
|
|
|
|
|
|
/* Send the information */
|
|
|
NetworkSend_uint8(packet, current);
|
|
|
|
|
|
NetworkSend_string(packet, _network_player_info[player->index].company_name);
|
|
|
NetworkSend_uint8 (packet, _network_player_info[player->index].inaugurated_year);
|
|
|
NetworkSend_uint32(packet, _network_player_info[player->index].inaugurated_year);
|
|
|
NetworkSend_uint64(packet, _network_player_info[player->index].company_value);
|
|
|
NetworkSend_uint64(packet, _network_player_info[player->index].money);
|
|
|
NetworkSend_uint64(packet, _network_player_info[player->index].income);
|
|
|
NetworkSend_uint16(packet, _network_player_info[player->index].performance);
|
|
|
|
|
|
/* Send 1 if there is a passord for the company else send 0 */
|
|
|
if (_network_player_info[player->index].password[0] != '\0') {
|
|
|
NetworkSend_uint8(packet, 1);
|
|
|
} else {
|
|
|
NetworkSend_uint8(packet, 0);
|
|
|
}
|
|
|
|
|
@@ -203,60 +211,60 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
|
|
|
|
|
|
for (i = 0; i < NETWORK_STATION_TYPES; i++)
|
|
|
NetworkSend_uint16(packet, _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 - 1 == player->index) {
|
|
|
/* The uint8 == 1 indicates that a client is following */
|
|
|
NetworkSend_uint8(packet, 1);
|
|
|
NetworkSend_string(packet, ci->client_name);
|
|
|
NetworkSend_string(packet, ci->unique_id);
|
|
|
NetworkSend_uint16(packet, ci->join_date);
|
|
|
NetworkSend_uint32(packet, ci->join_date);
|
|
|
}
|
|
|
}
|
|
|
/* Also check for the server itself */
|
|
|
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
|
|
if (ci->client_playas - 1 == player->index) {
|
|
|
/* The uint8 == 1 indicates that a client is following */
|
|
|
NetworkSend_uint8(packet, 1);
|
|
|
NetworkSend_string(packet, ci->client_name);
|
|
|
NetworkSend_string(packet, ci->unique_id);
|
|
|
NetworkSend_uint16(packet, ci->join_date);
|
|
|
NetworkSend_uint32(packet, ci->join_date);
|
|
|
}
|
|
|
|
|
|
/* Indicates end of client list */
|
|
|
NetworkSend_uint8(packet, 0);
|
|
|
}
|
|
|
|
|
|
/* And check if we have any spectators */
|
|
|
FOR_ALL_CLIENTS(cs) {
|
|
|
ci = DEREF_CLIENT_INFO(cs);
|
|
|
if (ci->client_playas - 1 > MAX_PLAYERS) {
|
|
|
/* The uint8 == 1 indicates that a client is following */
|
|
|
NetworkSend_uint8(packet, 1);
|
|
|
NetworkSend_string(packet, ci->client_name);
|
|
|
NetworkSend_string(packet, ci->unique_id);
|
|
|
NetworkSend_uint16(packet, ci->join_date);
|
|
|
NetworkSend_uint32(packet, ci->join_date);
|
|
|
}
|
|
|
}
|
|
|
/* Also check for the server itself */
|
|
|
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
|
|
if (ci->client_playas - 1 > MAX_PLAYERS) {
|
|
|
/* The uint8 == 1 indicates that a client is following */
|
|
|
NetworkSend_uint8(packet, 1);
|
|
|
NetworkSend_string(packet, ci->client_name);
|
|
|
NetworkSend_string(packet, ci->unique_id);
|
|
|
NetworkSend_uint16(packet, ci->join_date);
|
|
|
NetworkSend_uint32(packet, ci->join_date);
|
|
|
}
|
|
|
|
|
|
/* Indicates end of client list */
|
|
|
NetworkSend_uint8(packet, 0);
|
|
|
|
|
|
NetworkSendUDP_Packet(_udp_server_socket, packet, client_addr);
|
|
|
|
|
|
free(packet);
|
|
|
}
|
|
|
|
|
|
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST)
|
|
|
{
|