# HG changeset patch # User Darkvater # Date 1160956114 0 # Node ID f28bfa84f9ade851b34048f87587d3256c5bc0f0 # Parent 217cdf845a1245270a1fc9c6c7cf5d79685dc935 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a new player instead of a 0. diff -r 217cdf845a12 -r f28bfa84f9ad console_cmds.c --- a/console_cmds.c Sun Oct 15 23:42:18 2006 +0000 +++ b/console_cmds.c Sun Oct 15 23:48:34 2006 +0000 @@ -739,7 +739,8 @@ if (argc == 0) { IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect '"); - IConsoleHelp("IP can contain port and player: 'IP#Player:Port', eg: 'server.ottd.org#2:443'"); + IConsoleHelp("IP can contain port and player: 'IP[[#Player]:Port]', eg: 'server.ottd.org#2:443'"); + IConsoleHelp("Player #0 is new company, #255 is spectator all others are a certain company"); return true; } @@ -749,14 +750,25 @@ NetworkDisconnect(); ip = argv[1]; + /* Default settings: default port and new company */ rport = NETWORK_DEFAULT_PORT; + _network_playas = PLAYER_NEW_COMPANY; ParseConnectionString(&player, &port, ip); IConsolePrintF(_icolour_def, "Connecting to %s...", ip); if (player != NULL) { _network_playas = atoi(player); - IConsolePrintF(_icolour_def, " player-no: %s", player); + IConsolePrintF(_icolour_def, " player-no: %d", _network_playas); + + /* From a user pov 0 is a new player, internally it's different and all + * players are offset by one to ease up on users (eg players 1-8 not 0-7) */ + if (_network_playas == 0) _network_playas = PLAYER_NEW_COMPANY; + if (!IsValidPlayer(_network_playas - 1) && + (_network_playas != PLAYER_SPECTATOR && + _network_playas != PLAYER_NEW_COMPANY)) { + return false; + } } if (port != NULL) { rport = atoi(port); diff -r 217cdf845a12 -r f28bfa84f9ad network_client.c --- a/network_client.c Sun Oct 15 23:42:18 2006 +0000 +++ b/network_client.c Sun Oct 15 23:48:34 2006 +0000 @@ -511,7 +511,8 @@ // Say we received the map and loaded it correctly! SEND_COMMAND(PACKET_CLIENT_MAP_OK)(); - if (_network_playas == 0 || _network_playas > MAX_PLAYERS || + // new company/spectator (invalid player) or company we want to join is not active + if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayer(_network_playas - 1) || !GetPlayer(_network_playas - 1)->is_active) { if (_network_playas == PLAYER_SPECTATOR) { diff -r 217cdf845a12 -r f28bfa84f9ad network_gui.c --- a/network_gui.c Sun Oct 15 23:42:18 2006 +0000 +++ b/network_gui.c Sun Oct 15 23:48:34 2006 +0000 @@ -929,7 +929,7 @@ } break; case 8: /* New company */ - _network_playas = 0; + _network_playas = PLAYER_NEW_COMPANY; NetworkClientConnectGame(_network_last_host, _network_last_port); break; case 9: /* Spectate game */ @@ -1195,7 +1195,7 @@ _clientlist_proc[i++] = &ClientList_SpeakToAll; if (_network_own_client_index != ci->client_index) { - if (_network_playas >= 1 && _network_playas <= MAX_PLAYERS) { + if (IsValidPlayer(_network_playas - 1)) { // We are no spectator if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) { GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY); diff -r 217cdf845a12 -r f28bfa84f9ad network_server.c --- a/network_server.c Sun Oct 15 23:42:18 2006 +0000 +++ b/network_server.c Sun Oct 15 23:48:34 2006 +0000 @@ -596,7 +596,7 @@ // join another company does not affect these values switch (playas) { - case 0: /* New company */ + case PLAYER_NEW_COMPANY: /* New company */ if (ActivePlayerCount() >= _network_game_info.companies_max) { SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL); return; @@ -608,6 +608,12 @@ return; } break; + default: /* Join another company (companies 1-8) */ + if (!IsValidPlayer(playas - 1)) { + SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH); + return; + } + break; } // We need a valid name.. make it Player diff -r 217cdf845a12 -r f28bfa84f9ad openttd.c --- a/openttd.c Sun Oct 15 23:42:18 2006 +0000 +++ b/openttd.c Sun Oct 15 23:48:34 2006 +0000 @@ -480,7 +480,10 @@ ParseConnectionString(&player, &port, network_conn); - if (player != NULL) _network_playas = atoi(player); + if (player != NULL) { + _network_playas = atoi(player); + if (_network_playas == 0) _network_playas = PLAYER_NEW_COMPANY; + } if (port != NULL) rport = atoi(port); LoadIntroGame(); diff -r 217cdf845a12 -r f28bfa84f9ad player.h --- a/player.h Sun Oct 15 23:42:18 2006 +0000 +++ b/player.h Sun Oct 15 23:48:34 2006 +0000 @@ -213,7 +213,8 @@ /* Player identifiers All players below MAX_PLAYERS are playable * players, above, they are special, computer controlled players */ -enum { +enum Players { + PLAYER_NEW_COMPANY = 254, ///< Command 'player' in Multiplayer to create a new company PLAYER_SPECTATOR = 255, ///< Spectator in Multiplayer or the player in the scenario editor MAX_PLAYERS = 8, };