summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-07 21:03:41 +0000
committerrubidium <rubidium@openttd.org>2009-09-07 21:03:41 +0000
commit673df8c5c79d5a9e6e0eb3525b19b74a4e7843e6 (patch)
tree888023a40c34277c649646367de90047aec7eda0 /src
parent2e2d00bee7291156b9ff963b71abf3b177563869 (diff)
downloadopenttd-673df8c5c79d5a9e6e0eb3525b19b74a4e7843e6.tar.xz
(svn r17466) -Feature: reconnect console command (based on patch of bilbo)
Diffstat (limited to 'src')
-rw-r--r--src/console_cmds.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 5f528c374..a646793c0 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -789,6 +789,39 @@ DEF_CONSOLE_CMD(ConNetworkClients)
return true;
}
+DEF_CONSOLE_CMD(ConNetworkReconnect)
+{
+ if (argc == 0) {
+ IConsoleHelp("Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'");
+ IConsoleHelp("Company 255 is spectator (default, if not specified), 0 means creating new company.");
+ IConsoleHelp("All others are a certain company with Company 1 being #1");
+ return true;
+ }
+
+ CompanyID playas = (argc >= 2) ? (CompanyID)atoi(argv[1]) : COMPANY_SPECTATOR;
+ switch (playas) {
+ case 0: playas = COMPANY_NEW_COMPANY; break;
+ case COMPANY_SPECTATOR: /* nothing to do */ break;
+ default:
+ /* From a user pov 0 is a new company, internally it's different and all
+ * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
+ playas--;
+ if (playas < COMPANY_FIRST || playas >= MAX_COMPANIES) return false;
+ break;
+ }
+
+ if (StrEmpty(_settings_client.network.last_host)) {
+ IConsolePrint(CC_DEFAULT, "No server for reconnecting.");
+ return true;
+ }
+
+ /* Don't resolve the address first, just print it directly as it comes from the config file. */
+ IConsolePrintF(CC_DEFAULT, "Reconnecting to %s:%d...", _settings_client.network.last_host, _settings_client.network.last_port);
+
+ NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), playas);
+ return true;
+};
+
DEF_CONSOLE_CMD(ConNetworkConnect)
{
if (argc == 0) {
@@ -1831,6 +1864,8 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("server_info", ConServerInfo);
IConsoleCmdHookAdd("server_info", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("info", "server_info");
+ IConsoleCmdRegister("reconnect", ConNetworkReconnect);
+ IConsoleCmdHookAdd("reconnect", ICONSOLE_HOOK_ACCESS, ConHookClientOnly);
IConsoleCmdRegister("rcon", ConRcon);
IConsoleCmdHookAdd("rcon", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);