File diff r4325:5bd2a8c976a4 → r4326:7102aa7f4fb2
network_udp.c
Show inline comments
 
@@ -60,12 +60,16 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	_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 */
 
@@ -73,14 +77,12 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	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);
 

	
 
@@ -111,12 +113,16 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVE
 
	// 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:
 
@@ -124,14 +130,16 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVE
 
			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);
 

	
 
@@ -182,13 +190,13 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
		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 */
 
@@ -209,23 +217,23 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
			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);
 
	}
 

	
 
@@ -234,23 +242,23 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
		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);