|
@@ -545,26 +545,29 @@ void NetworkCloseClient(NetworkClientSta
|
|
|
|
|
|
while (cs->command_queue != NULL) {
|
|
|
CommandPacket *p = cs->command_queue->next;
|
|
|
free(cs->command_queue);
|
|
|
cs->command_queue = p;
|
|
|
}
|
|
|
|
|
|
// Close the gap in the client-list
|
|
|
ci = DEREF_CLIENT_INFO(cs);
|
|
|
|
|
|
if (_network_server) {
|
|
|
// We just lost one client :(
|
|
|
if (cs->status > STATUS_INACTIVE)
|
|
|
if (cs->status > STATUS_INACTIVE) {
|
|
|
_network_game_info.clients_on--;
|
|
|
if (DEREF_CLIENT_INFO(cs)->client_playas == OWNER_SPECTATOR)
|
|
|
_network_game_info.spectators_on--;
|
|
|
}
|
|
|
_network_clients_connected--;
|
|
|
|
|
|
while ((cs + 1) != DEREF_CLIENT(MAX_CLIENTS) && (cs + 1)->socket != INVALID_SOCKET) {
|
|
|
*cs = *(cs + 1);
|
|
|
*ci = *(ci + 1);
|
|
|
cs++;
|
|
|
ci++;
|
|
|
}
|
|
|
|
|
|
InvalidateWindow(WC_CLIENT_LIST, 0);
|
|
|
}
|
|
|
|
|
@@ -775,27 +778,26 @@ static void NetworkInitialize(void)
|
|
|
|
|
|
_local_command_queue = NULL;
|
|
|
|
|
|
// Clean all client-sockets
|
|
|
memset(_clients, 0, sizeof(_clients));
|
|
|
for (cs = _clients; cs != &_clients[MAX_CLIENTS]; cs++) {
|
|
|
cs->socket = INVALID_SOCKET;
|
|
|
cs->status = STATUS_INACTIVE;
|
|
|
cs->command_queue = NULL;
|
|
|
}
|
|
|
|
|
|
// Clean the client_info memory
|
|
|
memset(_network_client_info, 0, sizeof(_network_client_info));
|
|
|
memset(_network_player_info, 0, sizeof(_network_player_info));
|
|
|
_network_lobby_company_count = 0;
|
|
|
memset(&_network_client_info, 0, sizeof(_network_client_info));
|
|
|
memset(&_network_player_info, 0, sizeof(_network_player_info));
|
|
|
|
|
|
_sync_frame = 0;
|
|
|
_network_first_time = true;
|
|
|
|
|
|
_network_reconnect = 0;
|
|
|
|
|
|
NetworkUDPInitialize();
|
|
|
}
|
|
|
|
|
|
// Query a server to fetch his game-info
|
|
|
// If game_info is true, only the gameinfo is fetched,
|
|
|
// else only the client_info is fetched
|
|
@@ -905,34 +907,39 @@ bool NetworkClientConnectGame(const char
|
|
|
}
|
|
|
|
|
|
static void NetworkInitGameInfo(void)
|
|
|
{
|
|
|
NetworkClientInfo *ci;
|
|
|
|
|
|
ttd_strlcpy(_network_game_info.server_name, _network_server_name, sizeof(_network_game_info.server_name));
|
|
|
ttd_strlcpy(_network_game_info.server_password, _network_server_password, sizeof(_network_server_password));
|
|
|
ttd_strlcpy(_network_game_info.rcon_password, _network_rcon_password, sizeof(_network_rcon_password));
|
|
|
if (_network_game_info.server_name[0] == '\0')
|
|
|
snprintf(_network_game_info.server_name, sizeof(_network_game_info.server_name), "Unnamed Server");
|
|
|
|
|
|
ttd_strlcpy(_network_game_info.server_revision, _openttd_revision, sizeof(_network_game_info.server_revision));
|
|
|
|
|
|
// The server is a client too ;)
|
|
|
if (_network_dedicated) {
|
|
|
_network_game_info.clients_on = 0;
|
|
|
_network_game_info.companies_on = 0;
|
|
|
_network_game_info.dedicated = true;
|
|
|
} else {
|
|
|
_network_game_info.clients_on = 1;
|
|
|
_network_game_info.companies_on = 1;
|
|
|
_network_game_info.dedicated = false;
|
|
|
}
|
|
|
ttd_strlcpy(_network_game_info.server_revision, _openttd_revision, sizeof(_network_game_info.server_revision));
|
|
|
|
|
|
_network_game_info.spectators_on = 0;
|
|
|
|
|
|
_network_game_info.game_date = _date;
|
|
|
_network_game_info.start_date = ConvertIntDate(_patches.starting_date);
|
|
|
_network_game_info.map_width = MapSizeX();
|
|
|
_network_game_info.map_height = MapSizeY();
|
|
|
_network_game_info.map_set = _opt.landscape;
|
|
|
|
|
|
_network_game_info.use_password = (_network_server_password[0] != '\0');
|
|
|
|
|
|
// We use _network_client_info[MAX_CLIENT_INFO - 1] to store the server-data in it
|
|
|
// The index is NETWORK_SERVER_INDEX ( = 1)
|
|
|
ci = &_network_client_info[MAX_CLIENT_INFO - 1];
|
|
|
memset(ci, 0, sizeof(*ci));
|
|
@@ -1323,32 +1330,30 @@ void NetworkStartUp(void)
|
|
|
_network_available = true;
|
|
|
_network_dedicated = false;
|
|
|
_network_last_advertise_frame = 0;
|
|
|
_network_need_advertise = true;
|
|
|
_network_advertise_retries = 0;
|
|
|
|
|
|
/* Load the ip from the openttd.cfg */
|
|
|
_network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
|
|
|
/* And put the data back in it in case it was an invalid ip */
|
|
|
snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
|
|
|
|
|
|
/* Generate an unique id when there is none yet */
|
|
|
if (_network_unique_id[0] == '\0')
|
|
|
NetworkGenerateUniqueId();
|
|
|
if (_network_unique_id[0] == '\0') NetworkGenerateUniqueId();
|
|
|
|
|
|
memset(&_network_game_info, 0, sizeof(_network_game_info));
|
|
|
|
|
|
/* XXX - Hard number here, because the strings can currently handle no more
|
|
|
than 10 clients -- TrueLight */
|
|
|
_network_game_info.clients_max = 10;
|
|
|
_network_game_info.clients_max = 10; // XXX - hardcoded, string limiation -- TrueLight
|
|
|
_network_game_info.companies_max = MAX_PLAYERS;
|
|
|
_network_game_info.spectators_max = _network_game_info.clients_max;
|
|
|
|
|
|
// Let's load the network in windows
|
|
|
#if defined(WIN32)
|
|
|
{
|
|
|
WSADATA wsa;
|
|
|
DEBUG(net, 3) ("[NET][Core] Loading windows socket library");
|
|
|
if (WSAStartup(MAKEWORD(2,0), &wsa) != 0) {
|
|
|
DEBUG(net, 0) ("[NET][Core] Error: WSAStartup failed. Network not available.");
|
|
|
_network_available = false;
|
|
|
return;
|
|
|
}
|
|
|
}
|