summaryrefslogtreecommitdiff
path: root/console_cmds.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-10-17 22:16:46 +0000
committerDarkvater <darkvater@openttd.org>2006-10-17 22:16:46 +0000
commitfbc724c6cb0847c765ebc95d0598f608474c7476 (patch)
tree3c5e7e6bcdb563a73452b3392ed9da9e30aa513c /console_cmds.c
parent821df34b6ea306b19c64555f478910cacc44c48e (diff)
downloadopenttd-fbc724c6cb0847c765ebc95d0598f608474c7476.tar.xz
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
correctly handle this ci->client_playas - 1 was used all over the code making it pretty confusing at times. Use proper one-on-one values now. Special handling is only needed for user-output to not to confuse users.
Diffstat (limited to 'console_cmds.c')
-rw-r--r--console_cmds.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/console_cmds.c b/console_cmds.c
index eccf45258..c2e984abe 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -551,7 +551,9 @@ DEF_CONSOLE_CMD(ConStatus)
status = (cs->status < lengthof(stat_str) ? stat_str[cs->status] : "unknown");
IConsolePrintF(8, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
- cs->index, ci->client_name, status, lag, ci->client_playas, GetPlayerIP(ci), ci->unique_id);
+ cs->index, ci->client_name, status, lag,
+ ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
+ GetPlayerIP(ci), ci->unique_id);
}
return true;
@@ -669,16 +671,15 @@ DEF_CONSOLE_CMD(ConResetCompany)
if (argc != 2) return false;
- index = atoi(argv[1]);
+ index = atoi(argv[1]) - 1;
/* Check valid range */
- if (index < 1 || index > MAX_PLAYERS) {
+ if (!IsValidPlayer(index)) {
IConsolePrintF(_icolour_err, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
return true;
}
/* Check if company does exist */
- index--;
p = GetPlayer(index);
if (!p->is_active) {
IConsoleError("Company does not exist.");
@@ -693,13 +694,13 @@ DEF_CONSOLE_CMD(ConResetCompany)
/* Check if the company has active players */
FOR_ALL_CLIENTS(cs) {
ci = DEREF_CLIENT_INFO(cs);
- if (ci->client_playas - 1 == index) {
+ if (ci->client_playas == index) {
IConsoleError("Cannot remove company: a client is connected to that company.");
return true;
}
}
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
- if (ci->client_playas - 1 == index) {
+ if (ci->client_playas == index) {
IConsoleError("Cannot remove company: the server is connected to that company.");
return true;
}
@@ -723,7 +724,9 @@ DEF_CONSOLE_CMD(ConNetworkClients)
for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
if (ci->client_index != NETWORK_EMPTY_INDEX) {
IConsolePrintF(8, "Client #%1d name: '%s' company: %1d IP: %s",
- ci->client_index, ci->client_name, ci->client_playas, GetPlayerIP(ci));
+ ci->client_index, ci->client_name,
+ ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
+ GetPlayerIP(ci));
}
}
@@ -740,7 +743,7 @@ 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("Player #0 is new company, #255 is spectator all others are a certain company");
+ IConsoleHelp("Player #255 is spectator all others are a certain company with Company 1 being #1");
return true;
}
@@ -763,11 +766,9 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
/* 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 (_network_playas != PLAYER_SPECTATOR) {
+ _network_playas--;
+ if (!IsValidPlayer(_network_playas)) return false;
}
}
if (port != NULL) {