summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console_cmds.c16
-rw-r--r--network_client.c3
-rw-r--r--network_gui.c4
-rw-r--r--network_server.c8
-rw-r--r--openttd.c5
-rw-r--r--player.h3
6 files changed, 31 insertions, 8 deletions
diff --git a/console_cmds.c b/console_cmds.c
index f49537ff0..eccf45258 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -739,7 +739,8 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
if (argc == 0) {
IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
- 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 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
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 --git a/network_client.c b/network_client.c
index 836c0611d..f9cec7feb 100644
--- a/network_client.c
+++ b/network_client.c
@@ -511,7 +511,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
// 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 --git a/network_gui.c b/network_gui.c
index c841eae42..cd6ab6d99 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -929,7 +929,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
}
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 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
_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 --git a/network_server.c b/network_server.c
index 51c11ba83..42fc6efe0 100644
--- a/network_server.c
+++ b/network_server.c
@@ -596,7 +596,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
// 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 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
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 --git a/openttd.c b/openttd.c
index 7bbd25023..dc046c9ab 100644
--- a/openttd.c
+++ b/openttd.c
@@ -480,7 +480,10 @@ int ttd_main(int argc, char *argv[])
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 --git a/player.h b/player.h
index 0b17c3d4b..5d560d442 100644
--- a/player.h
+++ b/player.h
@@ -213,7 +213,8 @@ VARDEF PlayerID _current_player;
/* 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,
};