console_cmds.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "console_internal.h"
00014 #include "debug.h"
00015 #include "engine_func.h"
00016 #include "landscape.h"
00017 #include "saveload/saveload.h"
00018 #include "network/network.h"
00019 #include "network/network_func.h"
00020 #include "network/network_base.h"
00021 #include "network/network_admin.h"
00022 #include "network/network_client.h"
00023 #include "command_func.h"
00024 #include "settings_func.h"
00025 #include "fios.h"
00026 #include "fileio_func.h"
00027 #include "screenshot.h"
00028 #include "genworld.h"
00029 #include "strings_func.h"
00030 #include "viewport_func.h"
00031 #include "window_func.h"
00032 #include "date_func.h"
00033 #include "company_func.h"
00034 #include "gamelog.h"
00035 #include "ai/ai.hpp"
00036 #include "ai/ai_config.hpp"
00037 #include "newgrf.h"
00038 #include "console_func.h"
00039 #include "engine_base.h"
00040 
00041 #ifdef ENABLE_NETWORK
00042   #include "table/strings.h"
00043 #endif /* ENABLE_NETWORK */
00044 
00045 /* scriptfile handling */
00046 static bool _script_running; 
00047 
00048 /* console command defines */
00049 #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
00050 #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
00051 
00052 
00053 /****************
00054  * command hooks
00055  ****************/
00056 
00057 #ifdef ENABLE_NETWORK
00058 
00063 static inline bool NetworkAvailable(bool echo)
00064 {
00065   if (!_network_available) {
00066     if (echo) IConsoleError("You cannot use this command because there is no network available.");
00067     return false;
00068   }
00069   return true;
00070 }
00071 
00076 DEF_CONSOLE_HOOK(ConHookServerOnly)
00077 {
00078   if (!NetworkAvailable(echo)) return CHR_DISALLOW;
00079 
00080   if (!_network_server) {
00081     if (echo) IConsoleError("This command is only available to a network server.");
00082     return CHR_DISALLOW;
00083   }
00084   return CHR_ALLOW;
00085 }
00086 
00091 DEF_CONSOLE_HOOK(ConHookClientOnly)
00092 {
00093   if (!NetworkAvailable(echo)) return CHR_DISALLOW;
00094 
00095   if (_network_server) {
00096     if (echo) IConsoleError("This command is not available to a network server.");
00097     return CHR_DISALLOW;
00098   }
00099   return CHR_ALLOW;
00100 }
00101 
00106 DEF_CONSOLE_HOOK(ConHookNeedNetwork)
00107 {
00108   if (!NetworkAvailable(echo)) return CHR_DISALLOW;
00109 
00110   if (!_networking || (!_network_server && !MyClient::IsConnected())) {
00111     if (echo) IConsoleError("Not connected. This command is only available in multiplayer.");
00112     return CHR_DISALLOW;
00113   }
00114   return CHR_ALLOW;
00115 }
00116 
00121 DEF_CONSOLE_HOOK(ConHookNoNetwork)
00122 {
00123   if (_networking) {
00124     if (echo) IConsoleError("This command is forbidden in multiplayer.");
00125     return CHR_DISALLOW;
00126   }
00127   return CHR_ALLOW;
00128 }
00129 
00130 #else
00131 # define ConHookNoNetwork NULL
00132 #endif /* ENABLE_NETWORK */
00133 
00134 DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
00135 {
00136   if (_settings_client.gui.newgrf_developer_tools) {
00137     if (_game_mode == GM_MENU) {
00138       if (echo) IConsoleError("This command is only available in game and editor.");
00139       return CHR_DISALLOW;
00140     }
00141 #ifdef ENABLE_NETWORK
00142     return ConHookNoNetwork(echo);
00143 #else
00144     return CHR_ALLOW;
00145 #endif
00146   }
00147   return CHR_HIDE;
00148 }
00149 
00154 static void IConsoleHelp(const char *str)
00155 {
00156   IConsolePrintF(CC_WARNING, "- %s", str);
00157 }
00158 
00163 DEF_CONSOLE_CMD(ConResetEngines)
00164 {
00165   if (argc == 0) {
00166     IConsoleHelp("Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'");
00167     return true;
00168   }
00169 
00170   StartupEngines();
00171   return true;
00172 }
00173 
00179 DEF_CONSOLE_CMD(ConResetEnginePool)
00180 {
00181   if (argc == 0) {
00182     IConsoleHelp("Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
00183     return true;
00184   }
00185 
00186   if (_game_mode == GM_MENU) {
00187     IConsoleError("This command is only available in game and editor.");
00188     return true;
00189   }
00190 
00191   if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) {
00192     IConsoleError("This can only be done when there are no vehicles in the game.");
00193     return true;
00194   }
00195 
00196   return true;
00197 }
00198 
00199 #ifdef _DEBUG
00200 
00205 DEF_CONSOLE_CMD(ConResetTile)
00206 {
00207   if (argc == 0) {
00208     IConsoleHelp("Reset a tile to bare land. Usage: 'resettile <tile>'");
00209     IConsoleHelp("Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
00210     return true;
00211   }
00212 
00213   if (argc == 2) {
00214     uint32 result;
00215     if (GetArgumentInteger(&result, argv[1])) {
00216       DoClearSquare((TileIndex)result);
00217       return true;
00218     }
00219   }
00220 
00221   return false;
00222 }
00223 #endif /* _DEBUG */
00224 
00234 DEF_CONSOLE_CMD(ConScrollToTile)
00235 {
00236   switch (argc) {
00237     case 0:
00238       IConsoleHelp("Center the screen on a given tile.");
00239       IConsoleHelp("Usage: 'scrollto <tile>' or 'scrollto <x> <y>'");
00240       IConsoleHelp("Numbers can be either decimal (34161) or hexadecimal (0x4a5B).");
00241       return true;
00242 
00243     case 2: {
00244       uint32 result;
00245       if (GetArgumentInteger(&result, argv[1])) {
00246         if (result >= MapSize()) {
00247           IConsolePrint(CC_ERROR, "Tile does not exist");
00248           return true;
00249         }
00250         ScrollMainWindowToTile((TileIndex)result);
00251         return true;
00252       }
00253       break;
00254     }
00255 
00256     case 3: {
00257       uint32 x, y;
00258       if (GetArgumentInteger(&x, argv[1]) && GetArgumentInteger(&y, argv[2])) {
00259         if (x >= MapSizeX() || y >= MapSizeY()) {
00260           IConsolePrint(CC_ERROR, "Tile does not exist");
00261           return true;
00262         }
00263         ScrollMainWindowToTile(TileXY(x, y));
00264         return true;
00265       }
00266       break;
00267     }
00268   }
00269 
00270   return false;
00271 }
00272 
00278 DEF_CONSOLE_CMD(ConSave)
00279 {
00280   if (argc == 0) {
00281     IConsoleHelp("Save the current game. Usage: 'save <filename>'");
00282     return true;
00283   }
00284 
00285   if (argc == 2) {
00286     char *filename = str_fmt("%s.sav", argv[1]);
00287     IConsolePrint(CC_DEFAULT, "Saving map...");
00288 
00289     if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) {
00290       IConsolePrint(CC_ERROR, "Saving map failed");
00291     } else {
00292       IConsolePrintF(CC_DEFAULT, "Map successfully saved to %s", filename);
00293     }
00294     free(filename);
00295     return true;
00296   }
00297 
00298   return false;
00299 }
00300 
00305 DEF_CONSOLE_CMD(ConSaveConfig)
00306 {
00307   if (argc == 0) {
00308     IConsoleHelp("Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
00309     IConsoleHelp("It does not save the configuration of the current game to the configuration file.");
00310     return true;
00311   }
00312 
00313   SaveToConfig();
00314   IConsolePrint(CC_DEFAULT, "Saved config.");
00315   return true;
00316 }
00317 
00324 static const FiosItem *GetFiosItem(const char *file)
00325 {
00326   _saveload_mode = SLD_LOAD_GAME;
00327   BuildFileList();
00328 
00329   for (const FiosItem *item = _fios_items.Begin(); item != _fios_items.End(); item++) {
00330     if (strcmp(file, item->name) == 0) return item;
00331     if (strcmp(file, item->title) == 0) return item;
00332   }
00333 
00334   /* If no name matches, try to parse it as number */
00335   char *endptr;
00336   int i = strtol(file, &endptr, 10);
00337   if (file == endptr || *endptr != '\0') i = -1;
00338 
00339   if (IsInsideMM(i, 0, _fios_items.Length())) return _fios_items.Get(i);
00340 
00341   /* As a last effort assume it is an OpenTTD savegame and
00342    * that the ".sav" part was not given. */
00343   char long_file[MAX_PATH];
00344   seprintf(long_file, lastof(long_file), "%s.sav", file);
00345   for (const FiosItem *item = _fios_items.Begin(); item != _fios_items.End(); item++) {
00346     if (strcmp(long_file, item->name) == 0) return item;
00347     if (strcmp(long_file, item->title) == 0) return item;
00348   }
00349 
00350   return NULL;
00351 }
00352 
00353 
00354 DEF_CONSOLE_CMD(ConLoad)
00355 {
00356   if (argc == 0) {
00357     IConsoleHelp("Load a game by name or index. Usage: 'load <file | number>'");
00358     return true;
00359   }
00360 
00361   if (argc != 2) return false;
00362 
00363   const char *file = argv[1];
00364   const FiosItem *item = GetFiosItem(file);
00365   if (item != NULL) {
00366     switch (item->type) {
00367       case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
00368         _switch_mode = SM_LOAD_GAME;
00369         SetFiosType(item->type);
00370 
00371         strecpy(_file_to_saveload.name, FiosBrowseTo(item), lastof(_file_to_saveload.name));
00372         strecpy(_file_to_saveload.title, item->title, lastof(_file_to_saveload.title));
00373         break;
00374       }
00375       default: IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
00376     }
00377   } else {
00378     IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
00379   }
00380 
00381   FiosFreeSavegameList();
00382   return true;
00383 }
00384 
00385 
00386 DEF_CONSOLE_CMD(ConRemove)
00387 {
00388   if (argc == 0) {
00389     IConsoleHelp("Remove a savegame by name or index. Usage: 'rm <file | number>'");
00390     return true;
00391   }
00392 
00393   if (argc != 2) return false;
00394 
00395   const char *file = argv[1];
00396   const FiosItem *item = GetFiosItem(file);
00397   if (item != NULL) {
00398     if (!FiosDelete(item->name)) {
00399       IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
00400     }
00401   } else {
00402     IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
00403   }
00404 
00405   FiosFreeSavegameList();
00406   return true;
00407 }
00408 
00409 
00410 /* List all the files in the current dir via console */
00411 DEF_CONSOLE_CMD(ConListFiles)
00412 {
00413   if (argc == 0) {
00414     IConsoleHelp("List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'");
00415     return true;
00416   }
00417 
00418   BuildFileList();
00419 
00420   for (uint i = 0; i < _fios_items.Length(); i++) {
00421     IConsolePrintF(CC_DEFAULT, "%d) %s", i, _fios_items[i].title);
00422   }
00423 
00424   FiosFreeSavegameList();
00425   return true;
00426 }
00427 
00428 /* Change the dir via console */
00429 DEF_CONSOLE_CMD(ConChangeDirectory)
00430 {
00431   if (argc == 0) {
00432     IConsoleHelp("Change the dir via console. Usage: 'cd <directory | number>'");
00433     return true;
00434   }
00435 
00436   if (argc != 2) return false;
00437 
00438   const char *file = argv[1];
00439   const FiosItem *item = GetFiosItem(file);
00440   if (item != NULL) {
00441     switch (item->type) {
00442       case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
00443         FiosBrowseTo(item);
00444         break;
00445       default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
00446     }
00447   } else {
00448     IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
00449   }
00450 
00451   FiosFreeSavegameList();
00452   return true;
00453 }
00454 
00455 DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
00456 {
00457   const char *path;
00458 
00459   if (argc == 0) {
00460     IConsoleHelp("Print out the current working directory. Usage: 'pwd'");
00461     return true;
00462   }
00463 
00464   /* XXX - Workaround for broken file handling */
00465   FiosGetSavegameList(SLD_LOAD_GAME);
00466   FiosFreeSavegameList();
00467 
00468   FiosGetDescText(&path, NULL);
00469   IConsolePrint(CC_DEFAULT, path);
00470   return true;
00471 }
00472 
00473 DEF_CONSOLE_CMD(ConClearBuffer)
00474 {
00475   if (argc == 0) {
00476     IConsoleHelp("Clear the console buffer. Usage: 'clear'");
00477     return true;
00478   }
00479 
00480   IConsoleClearBuffer();
00481   SetWindowDirty(WC_CONSOLE, 0);
00482   return true;
00483 }
00484 
00485 
00486 /**********************************
00487  * Network Core Console Commands
00488  **********************************/
00489 #ifdef ENABLE_NETWORK
00490 
00491 static bool ConKickOrBan(const char *argv, bool ban)
00492 {
00493   uint n;
00494 
00495   if (strchr(argv, '.') == NULL && strchr(argv, ':') == NULL) { // banning with ID
00496     ClientID client_id = (ClientID)atoi(argv);
00497 
00498     /* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
00499      * kicking frees closes and subsequently free the connection related instances, which we
00500      * would be reading from and writing to after returning. So we would read or write data
00501      * from freed memory up till the segfault triggers. */
00502     if (client_id == CLIENT_ID_SERVER || client_id == _redirect_console_to_client) {
00503       IConsolePrintF(CC_ERROR, "ERROR: Silly boy, you can not %s yourself!", ban ? "ban" : "kick");
00504       return true;
00505     }
00506 
00507     NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
00508     if (ci == NULL) {
00509       IConsoleError("Invalid client");
00510       return true;
00511     }
00512 
00513     if (!ban) {
00514       /* Kick only this client, not all clients with that IP */
00515       NetworkServerKickClient(client_id);
00516       return true;
00517     }
00518 
00519     /* When banning, kick+ban all clients with that IP */
00520     n = NetworkServerKickOrBanIP(client_id, ban);
00521   } else {
00522     n = NetworkServerKickOrBanIP(argv, ban);
00523   }
00524 
00525   if (n == 0) {
00526     IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found");
00527   } else {
00528     IConsolePrintF(CC_DEFAULT, "%sed %u client(s)", ban ? "Bann" : "Kick", n);
00529   }
00530 
00531   return true;
00532 }
00533 
00534 DEF_CONSOLE_CMD(ConKick)
00535 {
00536   if (argc == 0) {
00537     IConsoleHelp("Kick a client from a network game. Usage: 'kick <ip | client-id>'");
00538     IConsoleHelp("For client-id's, see the command 'clients'");
00539     return true;
00540   }
00541 
00542   if (argc != 2) return false;
00543 
00544   return ConKickOrBan(argv[1], false);
00545 }
00546 
00547 DEF_CONSOLE_CMD(ConBan)
00548 {
00549   if (argc == 0) {
00550     IConsoleHelp("Ban a client from a network game. Usage: 'ban <ip | client-id>'");
00551     IConsoleHelp("For client-id's, see the command 'clients'");
00552     IConsoleHelp("If the client is no longer online, you can still ban his/her IP");
00553     return true;
00554   }
00555 
00556   if (argc != 2) return false;
00557 
00558   return ConKickOrBan(argv[1], true);
00559 }
00560 
00561 DEF_CONSOLE_CMD(ConUnBan)
00562 {
00563 
00564   if (argc == 0) {
00565     IConsoleHelp("Unban a client from a network game. Usage: 'unban <ip | client-id>'");
00566     IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
00567     return true;
00568   }
00569 
00570   if (argc != 2) return false;
00571 
00572   uint index = (strchr(argv[1], '.') == NULL) ? atoi(argv[1]) : 0;
00573   index--;
00574   uint i = 0;
00575 
00576   for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++, i++) {
00577     if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) {
00578       free(_network_ban_list[i]);
00579       _network_ban_list.Erase(iter);
00580       IConsolePrint(CC_DEFAULT, "IP unbanned.");
00581       return true;
00582     }
00583   }
00584 
00585   IConsolePrint(CC_DEFAULT, "IP not in ban-list.");
00586   return true;
00587 }
00588 
00589 DEF_CONSOLE_CMD(ConBanList)
00590 {
00591   if (argc == 0) {
00592     IConsoleHelp("List the IP's of banned clients: Usage 'banlist'");
00593     return true;
00594   }
00595 
00596   IConsolePrint(CC_DEFAULT, "Banlist: ");
00597 
00598   uint i = 1;
00599   for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++, i++) {
00600     IConsolePrintF(CC_DEFAULT, "  %d) %s", i, *iter);
00601   }
00602 
00603   return true;
00604 }
00605 
00606 DEF_CONSOLE_CMD(ConPauseGame)
00607 {
00608   if (argc == 0) {
00609     IConsoleHelp("Pause a network game. Usage: 'pause'");
00610     return true;
00611   }
00612 
00613   if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
00614     DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
00615     if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused.");
00616   } else {
00617     IConsolePrint(CC_DEFAULT, "Game is already paused.");
00618   }
00619 
00620   return true;
00621 }
00622 
00623 DEF_CONSOLE_CMD(ConUnpauseGame)
00624 {
00625   if (argc == 0) {
00626     IConsoleHelp("Unpause a network game. Usage: 'unpause'");
00627     return true;
00628   }
00629 
00630   if ((_pause_mode & PM_PAUSED_NORMAL) != PM_UNPAUSED) {
00631     DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
00632     if (!_networking) IConsolePrint(CC_DEFAULT, "Game unpaused.");
00633   } else if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED) {
00634     IConsolePrint(CC_DEFAULT, "Game is in error state and cannot be unpaused via console.");
00635   } else if (_pause_mode != PM_UNPAUSED) {
00636     IConsolePrint(CC_DEFAULT, "Game cannot be unpaused manually; disable pause_on_join/min_active_clients.");
00637   } else {
00638     IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
00639   }
00640 
00641   return true;
00642 }
00643 
00644 DEF_CONSOLE_CMD(ConRcon)
00645 {
00646   if (argc == 0) {
00647     IConsoleHelp("Remote control the server from another client. Usage: 'rcon <password> <command>'");
00648     IConsoleHelp("Remember to enclose the command in quotes, otherwise only the first parameter is sent");
00649     return true;
00650   }
00651 
00652   if (argc < 3) return false;
00653 
00654   if (_network_server) {
00655     IConsoleCmdExec(argv[2]);
00656   } else {
00657     NetworkClientSendRcon(argv[1], argv[2]);
00658   }
00659   return true;
00660 }
00661 
00662 DEF_CONSOLE_CMD(ConStatus)
00663 {
00664   if (argc == 0) {
00665     IConsoleHelp("List the status of all clients connected to the server. Usage 'status'");
00666     return true;
00667   }
00668 
00669   NetworkServerShowStatusToConsole();
00670   return true;
00671 }
00672 
00673 DEF_CONSOLE_CMD(ConServerInfo)
00674 {
00675   if (argc == 0) {
00676     IConsoleHelp("List current and maximum client/company limits. Usage 'server_info'");
00677     IConsoleHelp("You can change these values by modifying settings 'network.max_clients', 'network.max_companies' and 'network.max_spectators'");
00678     return true;
00679   }
00680 
00681   IConsolePrintF(CC_DEFAULT, "Current/maximum clients:    %2d/%2d", _network_game_info.clients_on, _settings_client.network.max_clients);
00682   IConsolePrintF(CC_DEFAULT, "Current/maximum companies:  %2d/%2d", (int)Company::GetNumItems(), _settings_client.network.max_companies);
00683   IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), _settings_client.network.max_spectators);
00684 
00685   return true;
00686 }
00687 
00688 DEF_CONSOLE_CMD(ConClientNickChange)
00689 {
00690   if (argc != 3) {
00691     IConsoleHelp("Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'");
00692     IConsoleHelp("For client-id's, see the command 'clients'");
00693     return true;
00694   }
00695 
00696   ClientID client_id = (ClientID)atoi(argv[1]);
00697 
00698   if (client_id == CLIENT_ID_SERVER) {
00699     IConsoleError("Please use the command 'name' to change your own name!");
00700     return true;
00701   }
00702 
00703   if (NetworkClientInfo::GetByClientID(client_id) == NULL) {
00704     IConsoleError("Invalid client");
00705     return true;
00706   }
00707 
00708   if (!NetworkServerChangeClientName(client_id, argv[2])) {
00709     IConsoleError("Cannot give a client a duplicate name");
00710   }
00711 
00712   return true;
00713 }
00714 
00715 DEF_CONSOLE_CMD(ConJoinCompany)
00716 {
00717   if (argc < 2) {
00718     IConsoleHelp("Request joining another company. Usage: join <company-id> [<password>]");
00719     IConsoleHelp("For valid company-id see company list, use 255 for spectator");
00720     return true;
00721   }
00722 
00723   CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
00724 
00725   /* Check we have a valid company id! */
00726   if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
00727     IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
00728     return true;
00729   }
00730 
00731   if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
00732     IConsoleError("You are already there!");
00733     return true;
00734   }
00735 
00736   if (company_id == COMPANY_SPECTATOR && NetworkMaxSpectatorsReached()) {
00737     IConsoleError("Cannot join spectators, maximum number of spectators reached.");
00738     return true;
00739   }
00740 
00741   if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
00742     IConsoleError("Cannot join AI company.");
00743     return true;
00744   }
00745 
00746   /* Check if the company requires a password */
00747   if (NetworkCompanyIsPassworded(company_id) && argc < 3) {
00748     IConsolePrintF(CC_ERROR, "Company %d requires a password to join.", company_id + 1);
00749     return true;
00750   }
00751 
00752   /* non-dedicated server may just do the move! */
00753   if (_network_server) {
00754     NetworkServerDoMove(CLIENT_ID_SERVER, company_id);
00755   } else {
00756     NetworkClientRequestMove(company_id, NetworkCompanyIsPassworded(company_id) ? argv[2] : "");
00757   }
00758 
00759   return true;
00760 }
00761 
00762 DEF_CONSOLE_CMD(ConMoveClient)
00763 {
00764   if (argc < 3) {
00765     IConsoleHelp("Move a client to another company. Usage: move <client-id> <company-id>");
00766     IConsoleHelp("For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators");
00767     return true;
00768   }
00769 
00770   const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)atoi(argv[1]));
00771   CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
00772 
00773   /* check the client exists */
00774   if (ci == NULL) {
00775     IConsoleError("Invalid client-id, check the command 'clients' for valid client-id's.");
00776     return true;
00777   }
00778 
00779   if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
00780     IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
00781     return true;
00782   }
00783 
00784   if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
00785     IConsoleError("You cannot move clients to AI companies.");
00786     return true;
00787   }
00788 
00789   if (ci->client_id == CLIENT_ID_SERVER && _network_dedicated) {
00790     IConsoleError("Silly boy, you cannot move the server!");
00791     return true;
00792   }
00793 
00794   if (ci->client_playas == company_id) {
00795     IConsoleError("You cannot move someone to where he/she already is!");
00796     return true;
00797   }
00798 
00799   /* we are the server, so force the update */
00800   NetworkServerDoMove(ci->client_id, company_id);
00801 
00802   return true;
00803 }
00804 
00805 DEF_CONSOLE_CMD(ConResetCompany)
00806 {
00807   if (argc == 0) {
00808     IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
00809     IConsoleHelp("For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
00810     return true;
00811   }
00812 
00813   if (argc != 2) return false;
00814 
00815   CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
00816 
00817   /* Check valid range */
00818   if (!Company::IsValidID(index)) {
00819     IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
00820     return true;
00821   }
00822 
00823   if (!Company::IsHumanID(index)) {
00824     IConsoleError("Company is owned by an AI.");
00825     return true;
00826   }
00827 
00828   if (NetworkCompanyHasClients(index)) {
00829     IConsoleError("Cannot remove company: a client is connected to that company.");
00830     return false;
00831   }
00832   const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
00833   if (ci->client_playas == index) {
00834     IConsoleError("Cannot remove company: the server is connected to that company.");
00835     return true;
00836   }
00837 
00838   /* It is safe to remove this company */
00839   DoCommandP(0, 2 | index << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
00840   IConsolePrint(CC_DEFAULT, "Company deleted.");
00841 
00842   return true;
00843 }
00844 
00845 DEF_CONSOLE_CMD(ConNetworkClients)
00846 {
00847   if (argc == 0) {
00848     IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
00849     return true;
00850   }
00851 
00852   NetworkPrintClients();
00853 
00854   return true;
00855 }
00856 
00857 DEF_CONSOLE_CMD(ConNetworkReconnect)
00858 {
00859   if (argc == 0) {
00860     IConsoleHelp("Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'");
00861     IConsoleHelp("Company 255 is spectator (default, if not specified), 0 means creating new company.");
00862     IConsoleHelp("All others are a certain company with Company 1 being #1");
00863     return true;
00864   }
00865 
00866   CompanyID playas = (argc >= 2) ? (CompanyID)atoi(argv[1]) : COMPANY_SPECTATOR;
00867   switch (playas) {
00868     case 0: playas = COMPANY_NEW_COMPANY; break;
00869     case COMPANY_SPECTATOR: /* nothing to do */ break;
00870     default:
00871       /* From a user pov 0 is a new company, internally it's different and all
00872        * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
00873       playas--;
00874       if (playas < COMPANY_FIRST || playas >= MAX_COMPANIES) return false;
00875       break;
00876   }
00877 
00878   if (StrEmpty(_settings_client.network.last_host)) {
00879     IConsolePrint(CC_DEFAULT, "No server for reconnecting.");
00880     return true;
00881   }
00882 
00883   /* Don't resolve the address first, just print it directly as it comes from the config file. */
00884   IConsolePrintF(CC_DEFAULT, "Reconnecting to %s:%d...", _settings_client.network.last_host, _settings_client.network.last_port);
00885 
00886   NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), playas);
00887   return true;
00888 }
00889 
00890 DEF_CONSOLE_CMD(ConNetworkConnect)
00891 {
00892   if (argc == 0) {
00893     IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
00894     IConsoleHelp("IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'");
00895     IConsoleHelp("Company #255 is spectator all others are a certain company with Company 1 being #1");
00896     return true;
00897   }
00898 
00899   if (argc < 2) return false;
00900   if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
00901 
00902   const char *port = NULL;
00903   const char *company = NULL;
00904   char *ip = argv[1];
00905   /* Default settings: default port and new company */
00906   uint16 rport = NETWORK_DEFAULT_PORT;
00907   CompanyID join_as = COMPANY_NEW_COMPANY;
00908 
00909   ParseConnectionString(&company, &port, ip);
00910 
00911   IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
00912   if (company != NULL) {
00913     join_as = (CompanyID)atoi(company);
00914     IConsolePrintF(CC_DEFAULT, "    company-no: %d", join_as);
00915 
00916     /* From a user pov 0 is a new company, internally it's different and all
00917      * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
00918     if (join_as != COMPANY_SPECTATOR) {
00919       if (join_as > MAX_COMPANIES) return false;
00920       join_as--;
00921     }
00922   }
00923   if (port != NULL) {
00924     rport = atoi(port);
00925     IConsolePrintF(CC_DEFAULT, "    port: %s", port);
00926   }
00927 
00928   NetworkClientConnectGame(NetworkAddress(ip, rport), join_as);
00929 
00930   return true;
00931 }
00932 
00933 #endif /* ENABLE_NETWORK */
00934 
00935 /*********************************
00936  *  script file console commands
00937  *********************************/
00938 
00939 DEF_CONSOLE_CMD(ConExec)
00940 {
00941   if (argc == 0) {
00942     IConsoleHelp("Execute a local script file. Usage: 'exec <script> <?>'");
00943     return true;
00944   }
00945 
00946   if (argc < 2) return false;
00947 
00948   FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
00949 
00950   if (script_file == NULL) {
00951     if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
00952     return true;
00953   }
00954 
00955   _script_running = true;
00956 
00957   char cmdline[ICON_CMDLN_SIZE];
00958   while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != NULL) {
00959     /* Remove newline characters from the executing script */
00960     for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
00961       if (*cmdptr == '\n' || *cmdptr == '\r') {
00962         *cmdptr = '\0';
00963         break;
00964       }
00965     }
00966     IConsoleCmdExec(cmdline);
00967   }
00968 
00969   if (ferror(script_file)) {
00970     IConsoleError("Encountered errror while trying to read from script file");
00971   }
00972 
00973   _script_running = false;
00974   FioFCloseFile(script_file);
00975   return true;
00976 }
00977 
00978 DEF_CONSOLE_CMD(ConReturn)
00979 {
00980   if (argc == 0) {
00981     IConsoleHelp("Stop executing a running script. Usage: 'return'");
00982     return true;
00983   }
00984 
00985   _script_running = false;
00986   return true;
00987 }
00988 
00989 /*****************************
00990  *  default console commands
00991  ******************************/
00992 extern bool CloseConsoleLogIfActive();
00993 
00994 DEF_CONSOLE_CMD(ConScript)
00995 {
00996   extern FILE *_iconsole_output_file;
00997 
00998   if (argc == 0) {
00999     IConsoleHelp("Start or stop logging console output to a file. Usage: 'script <filename>'");
01000     IConsoleHelp("If filename is omitted, a running log is stopped if it is active");
01001     return true;
01002   }
01003 
01004   if (!CloseConsoleLogIfActive()) {
01005     if (argc < 2) return false;
01006 
01007     IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
01008     _iconsole_output_file = fopen(argv[1], "ab");
01009     if (_iconsole_output_file == NULL) IConsoleError("could not open file");
01010   }
01011 
01012   return true;
01013 }
01014 
01015 
01016 DEF_CONSOLE_CMD(ConEcho)
01017 {
01018   if (argc == 0) {
01019     IConsoleHelp("Print back the first argument to the console. Usage: 'echo <arg>'");
01020     return true;
01021   }
01022 
01023   if (argc < 2) return false;
01024   IConsolePrint(CC_DEFAULT, argv[1]);
01025   return true;
01026 }
01027 
01028 DEF_CONSOLE_CMD(ConEchoC)
01029 {
01030   if (argc == 0) {
01031     IConsoleHelp("Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
01032     return true;
01033   }
01034 
01035   if (argc < 3) return false;
01036   IConsolePrint((TextColour)Clamp(atoi(argv[1]), TC_BEGIN, TC_END - 1), argv[2]);
01037   return true;
01038 }
01039 
01040 DEF_CONSOLE_CMD(ConNewGame)
01041 {
01042   if (argc == 0) {
01043     IConsoleHelp("Start a new game. Usage: 'newgame [seed]'");
01044     IConsoleHelp("The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game.");
01045     return true;
01046   }
01047 
01048   StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], NULL, 10) : GENERATE_NEW_SEED);
01049   return true;
01050 }
01051 
01052 extern void SwitchToMode(SwitchMode new_mode);
01053 
01054 DEF_CONSOLE_CMD(ConRestart)
01055 {
01056   if (argc == 0) {
01057     IConsoleHelp("Restart game. Usage: 'restart'");
01058     IConsoleHelp("Restarts a game. It tries to reproduce the exact same map as the game started with.");
01059     IConsoleHelp("However:");
01060     IConsoleHelp(" * restarting games started in another version might create another map due to difference in map generation");
01061     IConsoleHelp(" * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame");
01062     return true;
01063   }
01064 
01065   /* Don't copy the _newgame pointers to the real pointers, so call SwitchToMode directly */
01066   _settings_game.game_creation.map_x = MapLogX();
01067   _settings_game.game_creation.map_y = FindFirstBit(MapSizeY());
01068   _switch_mode = SM_RESTARTGAME;
01069   return true;
01070 }
01071 
01077 static void PrintLineByLine(char *buf)
01078 {
01079   char *p = buf;
01080   /* Print output line by line */
01081   for (char *p2 = buf; *p2 != '\0'; p2++) {
01082     if (*p2 == '\n') {
01083       *p2 = '\0';
01084       IConsolePrintF(CC_DEFAULT, "%s", p);
01085       p = p2 + 1;
01086     }
01087   }
01088 }
01089 
01090 DEF_CONSOLE_CMD(ConListAILibs)
01091 {
01092   char buf[4096];
01093   AI::GetConsoleLibraryList(buf, lastof(buf));
01094 
01095   PrintLineByLine(buf);
01096 
01097   return true;
01098 }
01099 
01100 DEF_CONSOLE_CMD(ConListAI)
01101 {
01102   char buf[4096];
01103   AI::GetConsoleList(buf, lastof(buf));
01104 
01105   PrintLineByLine(buf);
01106 
01107   return true;
01108 }
01109 
01110 DEF_CONSOLE_CMD(ConStartAI)
01111 {
01112   if (argc == 0 || argc > 3) {
01113     IConsoleHelp("Start a new AI. Usage: 'start_ai [<AI>] [<settings>]'");
01114     IConsoleHelp("Start a new AI. If <AI> is given, it starts that specific AI (if found).");
01115     IConsoleHelp("If <settings> is given, it is parsed and the AI settings are set to that.");
01116     return true;
01117   }
01118 
01119   if (_game_mode != GM_NORMAL) {
01120     IConsoleWarning("AIs can only be managed in a game.");
01121     return true;
01122   }
01123 
01124   if (Company::GetNumItems() == CompanyPool::MAX_SIZE) {
01125     IConsoleWarning("Can't start a new AI (no more free slots).");
01126     return true;
01127   }
01128   if (_networking && !_network_server) {
01129     IConsoleWarning("Only the server can start a new AI.");
01130     return true;
01131   }
01132   if (_networking && !_settings_game.ai.ai_in_multiplayer) {
01133     IConsoleWarning("AIs are not allowed in multiplayer by configuration.");
01134     IConsoleWarning("Switch AI -> AI in multiplayer to True.");
01135     return true;
01136   }
01137   if (!AI::CanStartNew()) {
01138     IConsoleWarning("Can't start a new AI.");
01139     return true;
01140   }
01141 
01142   int n = 0;
01143   Company *c;
01144   /* Find the next free slot */
01145   FOR_ALL_COMPANIES(c) {
01146     if (c->index != n) break;
01147     n++;
01148   }
01149 
01150   AIConfig *config = AIConfig::GetConfig((CompanyID)n);
01151   if (argc >= 2) {
01152     config->Change(argv[1], -1, true);
01153     if (!config->HasScript()) {
01154       IConsoleWarning("Failed to load the specified AI");
01155       return true;
01156     }
01157     if (argc == 3) {
01158       config->StringToSettings(argv[2]);
01159     }
01160   }
01161 
01162   /* Start a new AI company */
01163   DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
01164 
01165   return true;
01166 }
01167 
01168 DEF_CONSOLE_CMD(ConReloadAI)
01169 {
01170   if (argc != 2) {
01171     IConsoleHelp("Reload an AI. Usage: 'reload_ai <company-id>'");
01172     IConsoleHelp("Reload the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
01173     return true;
01174   }
01175 
01176   if (_game_mode != GM_NORMAL) {
01177     IConsoleWarning("AIs can only be managed in a game.");
01178     return true;
01179   }
01180 
01181   if (_networking && !_network_server) {
01182     IConsoleWarning("Only the server can reload an AI.");
01183     return true;
01184   }
01185 
01186   CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
01187   if (!Company::IsValidID(company_id)) {
01188     IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
01189     return true;
01190   }
01191 
01192   if (Company::IsHumanID(company_id)) {
01193     IConsoleWarning("Company is not controlled by an AI.");
01194     return true;
01195   }
01196 
01197   /* First kill the company of the AI, then start a new one. This should start the current AI again */
01198   DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
01199   DoCommandP(0, 1 | company_id << 16, 0, CMD_COMPANY_CTRL);
01200   IConsolePrint(CC_DEFAULT, "AI reloaded.");
01201 
01202   return true;
01203 }
01204 
01205 DEF_CONSOLE_CMD(ConStopAI)
01206 {
01207   if (argc != 2) {
01208     IConsoleHelp("Stop an AI. Usage: 'stop_ai <company-id>'");
01209     IConsoleHelp("Stop the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
01210     return true;
01211   }
01212 
01213   if (_game_mode != GM_NORMAL) {
01214     IConsoleWarning("AIs can only be managed in a game.");
01215     return true;
01216   }
01217 
01218   if (_networking && !_network_server) {
01219     IConsoleWarning("Only the server can stop an AI.");
01220     return true;
01221   }
01222 
01223   CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
01224   if (!Company::IsValidID(company_id)) {
01225     IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
01226     return true;
01227   }
01228 
01229   if (Company::IsHumanID(company_id)) {
01230     IConsoleWarning("Company is not controlled by an AI.");
01231     return true;
01232   }
01233 
01234   /* Now kill the company of the AI. */
01235   DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
01236   IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
01237 
01238   return true;
01239 }
01240 
01241 DEF_CONSOLE_CMD(ConRescanAI)
01242 {
01243   if (argc == 0) {
01244     IConsoleHelp("Rescan the AI dir for scripts. Usage: 'rescan_ai'");
01245     return true;
01246   }
01247 
01248   if (_networking && !_network_server) {
01249     IConsoleWarning("Only the server can rescan the AI dir for scripts.");
01250     return true;
01251   }
01252 
01253   AI::Rescan();
01254 
01255   return true;
01256 }
01257 
01258 DEF_CONSOLE_CMD(ConRescanNewGRF)
01259 {
01260   if (argc == 0) {
01261     IConsoleHelp("Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'");
01262     return true;
01263   }
01264 
01265   ScanNewGRFFiles(NULL);
01266 
01267   return true;
01268 }
01269 
01270 DEF_CONSOLE_CMD(ConGetSeed)
01271 {
01272   if (argc == 0) {
01273     IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
01274     IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
01275     return true;
01276   }
01277 
01278   IConsolePrintF(CC_DEFAULT, "Generation Seed: %u", _settings_game.game_creation.generation_seed);
01279   return true;
01280 }
01281 
01282 DEF_CONSOLE_CMD(ConGetDate)
01283 {
01284   if (argc == 0) {
01285     IConsoleHelp("Returns the current date (day-month-year) of the game. Usage: 'getdate'");
01286     return true;
01287   }
01288 
01289   YearMonthDay ymd;
01290   ConvertDateToYMD(_date, &ymd);
01291   IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
01292   return true;
01293 }
01294 
01295 
01296 DEF_CONSOLE_CMD(ConAlias)
01297 {
01298   IConsoleAlias *alias;
01299 
01300   if (argc == 0) {
01301     IConsoleHelp("Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'");
01302     return true;
01303   }
01304 
01305   if (argc < 3) return false;
01306 
01307   alias = IConsoleAliasGet(argv[1]);
01308   if (alias == NULL) {
01309     IConsoleAliasRegister(argv[1], argv[2]);
01310   } else {
01311     free(alias->cmdline);
01312     alias->cmdline = strdup(argv[2]);
01313   }
01314   return true;
01315 }
01316 
01317 DEF_CONSOLE_CMD(ConScreenShot)
01318 {
01319   if (argc == 0) {
01320     IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | giant | no_con] [file name]'");
01321     IConsoleHelp("'big' makes a zoomed-in screenshot of the visible area, 'giant' makes a screenshot of the "
01322         "whole map, 'no_con' hides the console to create the screenshot. 'big' or 'giant' "
01323         "screenshots are always drawn without console");
01324     return true;
01325   }
01326 
01327   if (argc > 3) return false;
01328 
01329   ScreenshotType type = SC_VIEWPORT;
01330   const char *name = NULL;
01331 
01332   if (argc > 1) {
01333     if (strcmp(argv[1], "big") == 0) {
01334       /* screenshot big [filename] */
01335       type = SC_ZOOMEDIN;
01336       if (argc > 2) name = argv[2];
01337     } else if (strcmp(argv[1], "giant") == 0) {
01338       /* screenshot giant [filename] */
01339       type = SC_WORLD;
01340       if (argc > 2) name = argv[2];
01341     } else if (strcmp(argv[1], "no_con") == 0) {
01342       /* screenshot no_con [filename] */
01343       IConsoleClose();
01344       if (argc > 2) name = argv[2];
01345     } else if (argc == 2) {
01346       /* screenshot filename */
01347       name = argv[1];
01348     } else {
01349       /* screenshot argv[1] argv[2] - invalid */
01350       return false;
01351     }
01352   }
01353 
01354   MakeScreenshot(type, name);
01355   return true;
01356 }
01357 
01358 DEF_CONSOLE_CMD(ConInfoCmd)
01359 {
01360   if (argc == 0) {
01361     IConsoleHelp("Print out debugging information about a command. Usage: 'info_cmd <cmd>'");
01362     return true;
01363   }
01364 
01365   if (argc < 2) return false;
01366 
01367   const IConsoleCmd *cmd = IConsoleCmdGet(argv[1]);
01368   if (cmd == NULL) {
01369     IConsoleError("the given command was not found");
01370     return true;
01371   }
01372 
01373   IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
01374   IConsolePrintF(CC_DEFAULT, "command proc: %p", cmd->proc);
01375 
01376   if (cmd->hook != NULL) IConsoleWarning("command is hooked");
01377 
01378   return true;
01379 }
01380 
01381 DEF_CONSOLE_CMD(ConDebugLevel)
01382 {
01383   if (argc == 0) {
01384     IConsoleHelp("Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'");
01385     IConsoleHelp("Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
01386     return true;
01387   }
01388 
01389   if (argc > 2) return false;
01390 
01391   if (argc == 1) {
01392     IConsolePrintF(CC_DEFAULT, "Current debug-level: '%s'", GetDebugString());
01393   } else {
01394     SetDebugString(argv[1]);
01395   }
01396 
01397   return true;
01398 }
01399 
01400 DEF_CONSOLE_CMD(ConExit)
01401 {
01402   if (argc == 0) {
01403     IConsoleHelp("Exit the game. Usage: 'exit'");
01404     return true;
01405   }
01406 
01407   if (_game_mode == GM_NORMAL && _settings_client.gui.autosave_on_exit) DoExitSave();
01408 
01409   _exit_game = true;
01410   return true;
01411 }
01412 
01413 DEF_CONSOLE_CMD(ConPart)
01414 {
01415   if (argc == 0) {
01416     IConsoleHelp("Leave the currently joined/running game (only ingame). Usage: 'part'");
01417     return true;
01418   }
01419 
01420   if (_game_mode != GM_NORMAL) return false;
01421 
01422   _switch_mode = SM_MENU;
01423   return true;
01424 }
01425 
01426 DEF_CONSOLE_CMD(ConHelp)
01427 {
01428   if (argc == 2) {
01429     const IConsoleCmd *cmd;
01430     const IConsoleAlias *alias;
01431 
01432     RemoveUnderscores(argv[1]);
01433     cmd = IConsoleCmdGet(argv[1]);
01434     if (cmd != NULL) {
01435       cmd->proc(0, NULL);
01436       return true;
01437     }
01438 
01439     alias = IConsoleAliasGet(argv[1]);
01440     if (alias != NULL) {
01441       cmd = IConsoleCmdGet(alias->cmdline);
01442       if (cmd != NULL) {
01443         cmd->proc(0, NULL);
01444         return true;
01445       }
01446       IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
01447       return true;
01448     }
01449 
01450     IConsoleError("command not found");
01451     return true;
01452   }
01453 
01454   IConsolePrint(CC_WARNING, " ---- OpenTTD Console Help ---- ");
01455   IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
01456   IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
01457   IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes");
01458   IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'");
01459   IConsolePrint(CC_DEFAULT, " - use 'help <command>' to get specific information");
01460   IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down | pageup | pagedown)");
01461   IConsolePrint(CC_DEFAULT, " - scroll console input history with the up or down arrows");
01462   IConsolePrint(CC_DEFAULT, "");
01463   return true;
01464 }
01465 
01466 DEF_CONSOLE_CMD(ConListCommands)
01467 {
01468   if (argc == 0) {
01469     IConsoleHelp("List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
01470     return true;
01471   }
01472 
01473   for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
01474     if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) {
01475       if (cmd->hook == NULL || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
01476     }
01477   }
01478 
01479   return true;
01480 }
01481 
01482 DEF_CONSOLE_CMD(ConListAliases)
01483 {
01484   if (argc == 0) {
01485     IConsoleHelp("List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
01486     return true;
01487   }
01488 
01489   for (const IConsoleAlias *alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
01490     if (argv[1] == NULL || strstr(alias->name, argv[1]) != NULL) {
01491       IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
01492     }
01493   }
01494 
01495   return true;
01496 }
01497 
01498 #ifdef ENABLE_NETWORK
01499 
01500 DEF_CONSOLE_CMD(ConSay)
01501 {
01502   if (argc == 0) {
01503     IConsoleHelp("Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
01504     return true;
01505   }
01506 
01507   if (argc != 2) return false;
01508 
01509   if (!_network_server) {
01510     NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
01511   } else {
01512     bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
01513     NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER, from_admin);
01514   }
01515 
01516   return true;
01517 }
01518 
01519 DEF_CONSOLE_CMD(ConCompanies)
01520 {
01521   if (argc == 0) {
01522     IConsoleHelp("List the in-game details of all clients connected to the server. Usage 'companies'");
01523     return true;
01524   }
01525   NetworkCompanyStats company_stats[MAX_COMPANIES];
01526   NetworkPopulateCompanyStats(company_stats);
01527 
01528   Company *c;
01529   FOR_ALL_COMPANIES(c) {
01530     /* Grab the company name */
01531     char company_name[NETWORK_COMPANY_NAME_LENGTH];
01532     SetDParam(0, c->index);
01533     GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
01534 
01535     char buffer[512];
01536     const NetworkCompanyStats *stats = &company_stats[c->index];
01537 
01538     GetString(buffer, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(buffer));
01539     IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s'  Year Founded: %d  Money: " OTTD_PRINTF64 "  Loan: " OTTD_PRINTF64 "  Value: " OTTD_PRINTF64 "  (T:%d, R:%d, P:%d, S:%d) %sprotected",
01540       c->index + 1, buffer, company_name, c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
01541       /* trains      */ stats->num_vehicle[0],
01542       /* lorry + bus */ stats->num_vehicle[1] + stats->num_vehicle[2],
01543       /* planes      */ stats->num_vehicle[3],
01544       /* ships       */ stats->num_vehicle[4],
01545       /* protected   */ StrEmpty(_network_company_states[c->index].password) ? "un" : "");
01546   }
01547 
01548   return true;
01549 }
01550 
01551 DEF_CONSOLE_CMD(ConSayCompany)
01552 {
01553   if (argc == 0) {
01554     IConsoleHelp("Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
01555     IConsoleHelp("CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
01556     return true;
01557   }
01558 
01559   if (argc != 3) return false;
01560 
01561   CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
01562   if (!Company::IsValidID(company_id)) {
01563     IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
01564     return true;
01565   }
01566 
01567   if (!_network_server) {
01568     NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2]);
01569   } else {
01570     bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
01571     NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2], CLIENT_ID_SERVER, from_admin);
01572   }
01573 
01574   return true;
01575 }
01576 
01577 DEF_CONSOLE_CMD(ConSayClient)
01578 {
01579   if (argc == 0) {
01580     IConsoleHelp("Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
01581     IConsoleHelp("For client-id's, see the command 'clients'");
01582     return true;
01583   }
01584 
01585   if (argc != 3) return false;
01586 
01587   if (!_network_server) {
01588     NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
01589   } else {
01590     bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
01591     NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], CLIENT_ID_SERVER, from_admin);
01592   }
01593 
01594   return true;
01595 }
01596 
01597 DEF_CONSOLE_CMD(ConCompanyPassword)
01598 {
01599   if (argc == 0) {
01600     const char *helpmsg;
01601 
01602     if (_network_dedicated) {
01603       helpmsg = "Change the password of a company. Usage: 'company_pw <company-no> \"<password>\"";
01604     } else if (_network_server) {
01605       helpmsg = "Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'";
01606     } else {
01607       helpmsg = "Change the password of your company. Usage: 'company_pw \"<password>\"'";
01608     }
01609 
01610     IConsoleHelp(helpmsg);
01611     IConsoleHelp("Use \"*\" to disable the password.");
01612     return true;
01613   }
01614 
01615   CompanyID company_id;
01616   const char *password;
01617   const char *errormsg;
01618 
01619   if (argc == 2) {
01620     company_id = _local_company;
01621     password = argv[1];
01622     errormsg = "You have to own a company to make use of this command.";
01623   } else if (argc == 3 && _network_server) {
01624     company_id = (CompanyID)(atoi(argv[1]) - 1);
01625     password = argv[2];
01626     errormsg = "You have to specify the ID of a valid human controlled company.";
01627   } else {
01628     return false;
01629   }
01630 
01631   if (!Company::IsValidHumanID(company_id)) {
01632     IConsoleError(errormsg);
01633     return false;
01634   }
01635 
01636   password = NetworkChangeCompanyPassword(company_id, password);
01637 
01638   if (StrEmpty(password)) {
01639     IConsolePrintF(CC_WARNING, "Company password cleared");
01640   } else {
01641     IConsolePrintF(CC_WARNING, "Company password changed to: %s", password);
01642   }
01643 
01644   return true;
01645 }
01646 
01647 /* Content downloading only is available with ZLIB */
01648 #if defined(WITH_ZLIB)
01649 #include "network/network_content.h"
01650 
01652 static ContentType StringToContentType(const char *str)
01653 {
01654   static const char * const inv_lookup[] = { "", "base", "newgrf", "ai", "ailib", "scenario", "heightmap" };
01655   for (uint i = 1 /* there is no type 0 */; i < lengthof(inv_lookup); i++) {
01656     if (strcasecmp(str, inv_lookup[i]) == 0) return (ContentType)i;
01657   }
01658   return CONTENT_TYPE_END;
01659 }
01660 
01662 struct ConsoleContentCallback : public ContentCallback {
01663   void OnConnect(bool success)
01664   {
01665     IConsolePrintF(CC_DEFAULT, "Content server connection %s", success ? "established" : "failed");
01666   }
01667 
01668   void OnDisconnect()
01669   {
01670     IConsolePrintF(CC_DEFAULT, "Content server connection closed");
01671   }
01672 
01673   void OnDownloadComplete(ContentID cid)
01674   {
01675     IConsolePrintF(CC_DEFAULT, "Completed download of %d", cid);
01676   }
01677 };
01678 
01679 DEF_CONSOLE_CMD(ConContent)
01680 {
01681   static ContentCallback *cb = NULL;
01682   if (cb == NULL) {
01683     cb = new ConsoleContentCallback();
01684     _network_content_client.AddCallback(cb);
01685   }
01686 
01687   if (argc <= 1) {
01688     IConsoleHelp("Query, select and download content. Usage: 'content update|upgrade|select [all|id]|unselect [all|id]|state|download'");
01689     IConsoleHelp("  update: get a new list of downloadable content; must be run first");
01690     IConsoleHelp("  upgrade: select all items that are upgrades");
01691     IConsoleHelp("  select: select a specific item given by its id or 'all' to select all");
01692     IConsoleHelp("  unselect: unselect a specific item given by its id or 'all' to unselect all");
01693     IConsoleHelp("  state: show the download/select state of all downloadable content");
01694     IConsoleHelp("  download: download all content you've selected");
01695     return true;
01696   }
01697 
01698   if (strcasecmp(argv[1], "update") == 0) {
01699     _network_content_client.RequestContentList((argc > 2) ? StringToContentType(argv[2]) : CONTENT_TYPE_END);
01700     return true;
01701   }
01702 
01703   if (strcasecmp(argv[1], "upgrade") == 0) {
01704     _network_content_client.SelectUpgrade();
01705     return true;
01706   }
01707 
01708   if (strcasecmp(argv[1], "select") == 0) {
01709     if (argc <= 2) {
01710       IConsoleError("You must enter the id.");
01711       return false;
01712     }
01713     if (strcasecmp(argv[2], "all") == 0) {
01714       _network_content_client.SelectAll();
01715     } else {
01716       _network_content_client.Select((ContentID)atoi(argv[2]));
01717     }
01718     return true;
01719   }
01720 
01721   if (strcasecmp(argv[1], "unselect") == 0) {
01722     if (argc <= 2) {
01723       IConsoleError("You must enter the id.");
01724       return false;
01725     }
01726     if (strcasecmp(argv[2], "all") == 0) {
01727       _network_content_client.UnselectAll();
01728     } else {
01729       _network_content_client.Unselect((ContentID)atoi(argv[2]));
01730     }
01731     return true;
01732   }
01733 
01734   if (strcasecmp(argv[1], "state") == 0) {
01735     IConsolePrintF(CC_WHITE, "id, type, state, name");
01736     for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
01737       static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music" };
01738       assert_compile(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
01739       static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" };
01740       static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR };
01741 
01742       const ContentInfo *ci = *iter;
01743       IConsolePrintF(state_to_colour[ci->state], "%d, %s, %s, %s", ci->id, types[ci->type - 1], states[ci->state], ci->name);
01744     }
01745     return true;
01746   }
01747 
01748   if (strcasecmp(argv[1], "download") == 0) {
01749     uint files;
01750     uint bytes;
01751     _network_content_client.DownloadSelectedContent(files, bytes);
01752     IConsolePrintF(CC_DEFAULT, "Downloading %d file(s) (%d bytes)", files, bytes);
01753     return true;
01754   }
01755 
01756   return false;
01757 }
01758 #endif /* defined(WITH_ZLIB) */
01759 #endif /* ENABLE_NETWORK */
01760 
01761 DEF_CONSOLE_CMD(ConSetting)
01762 {
01763   if (argc == 0) {
01764     IConsoleHelp("Change setting for all clients. Usage: 'setting <name> [<value>]'");
01765     IConsoleHelp("Omitting <value> will print out the current value of the setting.");
01766     return true;
01767   }
01768 
01769   if (argc == 1 || argc > 3) return false;
01770 
01771   if (argc == 2) {
01772     IConsoleGetSetting(argv[1]);
01773   } else {
01774     IConsoleSetSetting(argv[1], argv[2]);
01775   }
01776 
01777   return true;
01778 }
01779 
01780 DEF_CONSOLE_CMD(ConSettingNewgame)
01781 {
01782   if (argc == 0) {
01783     IConsoleHelp("Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'");
01784     IConsoleHelp("Omitting <value> will print out the current value of the setting.");
01785     return true;
01786   }
01787 
01788   if (argc == 1 || argc > 3) return false;
01789 
01790   if (argc == 2) {
01791     IConsoleGetSetting(argv[1], true);
01792   } else {
01793     IConsoleSetSetting(argv[1], argv[2], true);
01794   }
01795 
01796   return true;
01797 }
01798 
01799 DEF_CONSOLE_CMD(ConListSettings)
01800 {
01801   if (argc == 0) {
01802     IConsoleHelp("List settings. Usage: 'list_settings [<pre-filter>]'");
01803     return true;
01804   }
01805 
01806   if (argc > 2) return false;
01807 
01808   IConsoleListSettings((argc == 2) ? argv[1] : NULL);
01809   return true;
01810 }
01811 
01812 DEF_CONSOLE_CMD(ConGamelogPrint)
01813 {
01814   GamelogPrintConsole();
01815   return true;
01816 }
01817 
01818 DEF_CONSOLE_CMD(ConNewGRFReload)
01819 {
01820   if (argc == 0) {
01821     IConsoleHelp("Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD!");
01822     return true;
01823   }
01824 
01825   ReloadNewGRFData();
01826   return true;
01827 }
01828 
01829 #ifdef _DEBUG
01830 /******************
01831  *  debug commands
01832  ******************/
01833 
01834 static void IConsoleDebugLibRegister()
01835 {
01836   IConsoleCmdRegister("resettile",        ConResetTile);
01837   IConsoleAliasRegister("dbg_echo",       "echo %A; echo %B");
01838   IConsoleAliasRegister("dbg_echo2",      "echo %!");
01839 }
01840 #endif
01841 
01842 /*******************************
01843  * console command registration
01844  *******************************/
01845 
01846 void IConsoleStdLibRegister()
01847 {
01848   IConsoleCmdRegister("debug_level",  ConDebugLevel);
01849   IConsoleCmdRegister("echo",         ConEcho);
01850   IConsoleCmdRegister("echoc",        ConEchoC);
01851   IConsoleCmdRegister("exec",         ConExec);
01852   IConsoleCmdRegister("exit",         ConExit);
01853   IConsoleCmdRegister("part",         ConPart);
01854   IConsoleCmdRegister("help",         ConHelp);
01855   IConsoleCmdRegister("info_cmd",     ConInfoCmd);
01856   IConsoleCmdRegister("list_cmds",    ConListCommands);
01857   IConsoleCmdRegister("list_aliases", ConListAliases);
01858   IConsoleCmdRegister("newgame",      ConNewGame);
01859   IConsoleCmdRegister("restart",      ConRestart);
01860   IConsoleCmdRegister("getseed",      ConGetSeed);
01861   IConsoleCmdRegister("getdate",      ConGetDate);
01862   IConsoleCmdRegister("quit",         ConExit);
01863   IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
01864   IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
01865   IConsoleCmdRegister("return",       ConReturn);
01866   IConsoleCmdRegister("screenshot",   ConScreenShot);
01867   IConsoleCmdRegister("script",       ConScript);
01868   IConsoleCmdRegister("scrollto",     ConScrollToTile);
01869   IConsoleCmdRegister("alias",        ConAlias);
01870   IConsoleCmdRegister("load",         ConLoad);
01871   IConsoleCmdRegister("rm",           ConRemove);
01872   IConsoleCmdRegister("save",         ConSave);
01873   IConsoleCmdRegister("saveconfig",   ConSaveConfig);
01874   IConsoleCmdRegister("ls",           ConListFiles);
01875   IConsoleCmdRegister("cd",           ConChangeDirectory);
01876   IConsoleCmdRegister("pwd",          ConPrintWorkingDirectory);
01877   IConsoleCmdRegister("clear",        ConClearBuffer);
01878   IConsoleCmdRegister("setting",      ConSetting);
01879   IConsoleCmdRegister("setting_newgame", ConSettingNewgame);
01880   IConsoleCmdRegister("list_settings",ConListSettings);
01881   IConsoleCmdRegister("gamelog",      ConGamelogPrint);
01882   IConsoleCmdRegister("rescan_newgrf", ConRescanNewGRF);
01883 
01884   IConsoleAliasRegister("dir",          "ls");
01885   IConsoleAliasRegister("del",          "rm %+");
01886   IConsoleAliasRegister("newmap",       "newgame");
01887   IConsoleAliasRegister("patch",        "setting %+");
01888   IConsoleAliasRegister("set",          "setting %+");
01889   IConsoleAliasRegister("set_newgame",  "setting_newgame %+");
01890   IConsoleAliasRegister("list_patches", "list_settings %+");
01891   IConsoleAliasRegister("developer",    "setting developer %+");
01892 
01893   IConsoleCmdRegister("list_ai_libs", ConListAILibs);
01894   IConsoleCmdRegister("list_ai",      ConListAI);
01895   IConsoleCmdRegister("reload_ai",    ConReloadAI);
01896   IConsoleCmdRegister("rescan_ai",    ConRescanAI);
01897   IConsoleCmdRegister("start_ai",     ConStartAI);
01898   IConsoleCmdRegister("stop_ai",      ConStopAI);
01899 
01900   /* networking functions */
01901 #ifdef ENABLE_NETWORK
01902 /* Content downloading is only available with ZLIB */
01903 #if defined(WITH_ZLIB)
01904   IConsoleCmdRegister("content",         ConContent);
01905 #endif /* defined(WITH_ZLIB) */
01906 
01907   /*** Networking commands ***/
01908   IConsoleCmdRegister("say",             ConSay, ConHookNeedNetwork);
01909   IConsoleCmdRegister("companies",       ConCompanies, ConHookServerOnly);
01910   IConsoleAliasRegister("players",       "companies");
01911   IConsoleCmdRegister("say_company",     ConSayCompany, ConHookNeedNetwork);
01912   IConsoleAliasRegister("say_player",    "say_company %+");
01913   IConsoleCmdRegister("say_client",      ConSayClient, ConHookNeedNetwork);
01914 
01915   IConsoleCmdRegister("connect",         ConNetworkConnect, ConHookClientOnly);
01916   IConsoleCmdRegister("clients",         ConNetworkClients, ConHookNeedNetwork);
01917   IConsoleCmdRegister("status",          ConStatus, ConHookServerOnly);
01918   IConsoleCmdRegister("server_info",     ConServerInfo, ConHookServerOnly);
01919   IConsoleAliasRegister("info",          "server_info");
01920   IConsoleCmdRegister("reconnect",       ConNetworkReconnect, ConHookClientOnly);
01921   IConsoleCmdRegister("rcon",            ConRcon, ConHookNeedNetwork);
01922 
01923   IConsoleCmdRegister("join",            ConJoinCompany, ConHookNeedNetwork);
01924   IConsoleAliasRegister("spectate",      "join 255");
01925   IConsoleCmdRegister("move",            ConMoveClient, ConHookServerOnly);
01926   IConsoleCmdRegister("reset_company",   ConResetCompany, ConHookServerOnly);
01927   IConsoleAliasRegister("clean_company", "reset_company %A");
01928   IConsoleCmdRegister("client_name",     ConClientNickChange, ConHookServerOnly);
01929   IConsoleCmdRegister("kick",            ConKick, ConHookServerOnly);
01930   IConsoleCmdRegister("ban",             ConBan, ConHookServerOnly);
01931   IConsoleCmdRegister("unban",           ConUnBan, ConHookServerOnly);
01932   IConsoleCmdRegister("banlist",         ConBanList, ConHookServerOnly);
01933 
01934   IConsoleCmdRegister("pause",           ConPauseGame, ConHookServerOnly);
01935   IConsoleCmdRegister("unpause",         ConUnpauseGame, ConHookServerOnly);
01936 
01937   IConsoleCmdRegister("company_pw",      ConCompanyPassword, ConHookNeedNetwork);
01938   IConsoleAliasRegister("company_password",      "company_pw %+");
01939 
01940   IConsoleAliasRegister("net_frame_freq",        "setting frame_freq %+");
01941   IConsoleAliasRegister("net_sync_freq",         "setting sync_freq %+");
01942   IConsoleAliasRegister("server_pw",             "setting server_password %+");
01943   IConsoleAliasRegister("server_password",       "setting server_password %+");
01944   IConsoleAliasRegister("rcon_pw",               "setting rcon_password %+");
01945   IConsoleAliasRegister("rcon_password",         "setting rcon_password %+");
01946   IConsoleAliasRegister("name",                  "setting client_name %+");
01947   IConsoleAliasRegister("server_name",           "setting server_name %+");
01948   IConsoleAliasRegister("server_port",           "setting server_port %+");
01949   IConsoleAliasRegister("server_advertise",      "setting server_advertise %+");
01950   IConsoleAliasRegister("max_clients",           "setting max_clients %+");
01951   IConsoleAliasRegister("max_companies",         "setting max_companies %+");
01952   IConsoleAliasRegister("max_spectators",        "setting max_spectators %+");
01953   IConsoleAliasRegister("max_join_time",         "setting max_join_time %+");
01954   IConsoleAliasRegister("pause_on_join",         "setting pause_on_join %+");
01955   IConsoleAliasRegister("autoclean_companies",   "setting autoclean_companies %+");
01956   IConsoleAliasRegister("autoclean_protected",   "setting autoclean_protected %+");
01957   IConsoleAliasRegister("autoclean_unprotected", "setting autoclean_unprotected %+");
01958   IConsoleAliasRegister("restart_game_year",     "setting restart_game_year %+");
01959   IConsoleAliasRegister("min_players",           "setting min_active_clients %+");
01960   IConsoleAliasRegister("reload_cfg",            "setting reload_cfg %+");
01961 #endif /* ENABLE_NETWORK */
01962 
01963   /* debugging stuff */
01964 #ifdef _DEBUG
01965   IConsoleDebugLibRegister();
01966 #endif
01967 
01968   /* NewGRF development stuff */
01969   IConsoleCmdRegister("reload_newgrfs",  ConNewGRFReload, ConHookNewGRFDeveloperTool);
01970 }