src/network/core/udp.cpp
changeset 5799 29f786132792
parent 5765 27dbbe543fcf
child 5810 d24e5ce302b9
equal deleted inserted replaced
5798:7fe5fecbb2d8 5799:29f786132792
   243  * @param p    the packet to read the data from
   243  * @param p    the packet to read the data from
   244  * @param info the NetworkGameInfo to deserialize into
   244  * @param info the NetworkGameInfo to deserialize into
   245  */
   245  */
   246 void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *info)
   246 void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *info)
   247 {
   247 {
       
   248 	static const Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
       
   249 
   248 	info->game_info_version = NetworkRecv_uint8(this, p);
   250 	info->game_info_version = NetworkRecv_uint8(this, p);
   249 
   251 
   250 	/*
   252 	/*
   251 	 *              Please observe the order.
   253 	 *              Please observe the order.
   252 	 * The parts must be read in the same order as they are sent!
   254 	 * The parts must be read in the same order as they are sent!
   270 				*dst = c;
   272 				*dst = c;
   271 				dst = &c->next;
   273 				dst = &c->next;
   272 			}
   274 			}
   273 		} /* Fallthrough */
   275 		} /* Fallthrough */
   274 		case 3:
   276 		case 3:
   275 			info->game_date      = NetworkRecv_uint32(this, p);
   277 			info->game_date      = clamp(NetworkRecv_uint32(this, p), 0, MAX_DATE);
   276 			info->start_date     = NetworkRecv_uint32(this, p);
   278 			info->start_date     = clamp(NetworkRecv_uint32(this, p), 0, MAX_DATE);
   277 			/* Fallthrough */
   279 			/* Fallthrough */
   278 		case 2:
   280 		case 2:
   279 			info->companies_max  = NetworkRecv_uint8 (this, p);
   281 			info->companies_max  = NetworkRecv_uint8 (this, p);
   280 			info->companies_on   = NetworkRecv_uint8 (this, p);
   282 			info->companies_on   = NetworkRecv_uint8 (this, p);
   281 			info->spectators_max = NetworkRecv_uint8 (this, p);
   283 			info->spectators_max = NetworkRecv_uint8 (this, p);
   282 			/* Fallthrough */
   284 			/* Fallthrough */
   283 		case 1:
   285 		case 1:
   284 			NetworkRecv_string(this, p, info->server_name,     sizeof(info->server_name));
   286 			NetworkRecv_string(this, p, info->server_name,     sizeof(info->server_name));
   285 			NetworkRecv_string(this, p, info->server_revision, sizeof(info->server_revision));
   287 			NetworkRecv_string(this, p, info->server_revision, sizeof(info->server_revision));
   286 			info->server_lang    = NetworkRecv_uint8 (this, p);
   288 			info->server_lang    = NetworkRecv_uint8 (this, p);
   287 			info->use_password   = NetworkRecv_uint8 (this, p);
   289 			info->use_password   = (NetworkRecv_uint8 (this, p) != 0);
   288 			info->clients_max    = NetworkRecv_uint8 (this, p);
   290 			info->clients_max    = NetworkRecv_uint8 (this, p);
   289 			info->clients_on     = NetworkRecv_uint8 (this, p);
   291 			info->clients_on     = NetworkRecv_uint8 (this, p);
   290 			info->spectators_on  = NetworkRecv_uint8 (this, p);
   292 			info->spectators_on  = NetworkRecv_uint8 (this, p);
   291 			if (info->game_info_version < 3) { // 16 bits dates got scrapped and are read earlier
   293 			if (info->game_info_version < 3) { // 16 bits dates got scrapped and are read earlier
   292 				info->game_date    = NetworkRecv_uint16(this, p) + DAYS_TILL_ORIGINAL_BASE_YEAR;
   294 				info->game_date    = NetworkRecv_uint16(this, p) + DAYS_TILL_ORIGINAL_BASE_YEAR;
   295 			NetworkRecv_string(this, p, info->map_name, sizeof(info->map_name));
   297 			NetworkRecv_string(this, p, info->map_name, sizeof(info->map_name));
   296 			info->map_width      = NetworkRecv_uint16(this, p);
   298 			info->map_width      = NetworkRecv_uint16(this, p);
   297 			info->map_height     = NetworkRecv_uint16(this, p);
   299 			info->map_height     = NetworkRecv_uint16(this, p);
   298 			info->map_set        = NetworkRecv_uint8 (this, p);
   300 			info->map_set        = NetworkRecv_uint8 (this, p);
   299 			info->dedicated      = (NetworkRecv_uint8(this, p) != 0);
   301 			info->dedicated      = (NetworkRecv_uint8(this, p) != 0);
       
   302 
       
   303 			if (info->server_lang >= NETWORK_NUM_LANGUAGES) info->server_lang = 0;
       
   304 			if (info->map_set     >= NUM_LANDSCAPE)         info->map_set     = 0;
   300 	}
   305 	}
   301 }
   306 }
   302 
   307 
   303 /* Defines a simple (switch) case for each network packet */
   308 /* Defines a simple (switch) case for each network packet */
   304 #define UDP_COMMAND(type) case type: this->NetworkPacketReceive_ ## type ## _command(p, client_addr); break;
   309 #define UDP_COMMAND(type) case type: this->NetworkPacketReceive_ ## type ## _command(p, client_addr); break;