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 DEF_CONSOLE_CMD(ConRestart)
01053 {
01054   if (argc == 0) {
01055     IConsoleHelp("Restart game. Usage: 'restart'");
01056     IConsoleHelp("Restarts a game. It tries to reproduce the exact same map as the game started with.");
01057     IConsoleHelp("However:");
01058     IConsoleHelp(" * restarting games started in another version might create another map due to difference in map generation");
01059     IConsoleHelp(" * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame");
01060     return true;
01061   }
01062 
01063   /* Don't copy the _newgame pointers to the real pointers, so call SwitchToMode directly */
01064   _settings_game.game_creation.map_x = MapLogX();
01065   _settings_game.game_creation.map_y = FindFirstBit(MapSizeY());
01066   _switch_mode = SM_RESTARTGAME;
01067   return true;
01068 }
01069 
01075 static void PrintLineByLine(char *buf)
01076 {
01077   char *p = buf;
01078   /* Print output line by line */
01079   for (char *p2 = buf; *p2 != '\0'; p2++) {
01080     if (*p2 == '\n') {
01081       *p2 = '\0';
01082       IConsolePrintF(CC_DEFAULT, "%s", p);
01083       p = p2 + 1;
01084     }
01085   }
01086 }
01087 
01088 DEF_CONSOLE_CMD(ConListAILibs)
01089 {
01090   char buf[4096];
01091   AI::GetConsoleLibraryList(buf, lastof(buf));
01092 
01093   PrintLineByLine(buf);
01094 
01095   return true;
01096 }
01097 
01098 DEF_CONSOLE_CMD(ConListAI)
01099 {
01100   char buf[4096];
01101   AI::GetConsoleList(buf, lastof(buf));
01102 
01103   PrintLineByLine(buf);
01104 
01105   return true;
01106 }
01107 
01108 DEF_CONSOLE_CMD(ConStartAI)
01109 {
01110   if (argc == 0 || argc > 3) {
01111     IConsoleHelp("Start a new AI. Usage: 'start_ai [<AI>] [<settings>]'");
01112     IConsoleHelp("Start a new AI. If <AI> is given, it starts that specific AI (if found).");
01113     IConsoleHelp("If <settings> is given, it is parsed and the AI settings are set to that.");
01114     return true;
01115   }
01116 
01117   if (_game_mode != GM_NORMAL) {
01118     IConsoleWarning("AIs can only be managed in a game.");
01119     return true;
01120   }
01121 
01122   if (Company::GetNumItems() == CompanyPool::MAX_SIZE) {
01123     IConsoleWarning("Can't start a new AI (no more free slots).");
01124     return true;
01125   }
01126   if (_networking && !_network_server) {
01127     IConsoleWarning("Only the server can start a new AI.");
01128     return true;
01129   }
01130   if (_networking && !_settings_game.ai.ai_in_multiplayer) {
01131     IConsoleWarning("AIs are not allowed in multiplayer by configuration.");
01132     IConsoleWarning("Switch AI -> AI in multiplayer to True.");
01133     return true;
01134   }
01135   if (!AI::CanStartNew()) {
01136     IConsoleWarning("Can't start a new AI.");
01137     return true;
01138   }
01139 
01140   int n = 0;
01141   Company *c;
01142   /* Find the next free slot */
01143   FOR_ALL_COMPANIES(c) {
01144     if (c->index != n) break;
01145     n++;
01146   }
01147 
01148   AIConfig *config = AIConfig::GetConfig((CompanyID)n);
01149   if (argc >= 2) {
01150     config->Change(argv[1], -1, true);
01151     if (!config->HasScript()) {
01152       IConsoleWarning("Failed to load the specified AI");
01153       return true;
01154     }
01155     if (argc == 3) {
01156       config->StringToSettings(argv[2]);
01157     }
01158   }
01159 
01160   /* Start a new AI company */
01161   DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
01162 
01163   return true;
01164 }
01165 
01166 DEF_CONSOLE_CMD(ConReloadAI)
01167 {
01168   if (argc != 2) {
01169     IConsoleHelp("Reload an AI. Usage: 'reload_ai <company-id>'");
01170     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.");
01171     return true;
01172   }
01173 
01174   if (_game_mode != GM_NORMAL) {
01175     IConsoleWarning("AIs can only be managed in a game.");
01176     return true;
01177   }
01178 
01179   if (_networking && !_network_server) {
01180     IConsoleWarning("Only the server can reload an AI.");
01181     return true;
01182   }
01183 
01184   CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
01185   if (!Company::IsValidID(company_id)) {
01186     IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
01187     return true;
01188   }
01189 
01190   if (Company::IsHumanID(company_id)) {
01191     IConsoleWarning("Company is not controlled by an AI.");
01192     return true;
01193   }
01194 
01195   /* First kill the company of the AI, then start a new one. This should start the current AI again */
01196   DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
01197   DoCommandP(0, 1 | company_id << 16, 0, CMD_COMPANY_CTRL);
01198   IConsolePrint(CC_DEFAULT, "AI reloaded.");
01199 
01200   return true;
01201 }
01202 
01203 DEF_CONSOLE_CMD(ConStopAI)
01204 {
01205   if (argc != 2) {
01206     IConsoleHelp("Stop an AI. Usage: 'stop_ai <company-id>'");
01207     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.");
01208     return true;
01209   }
01210 
01211   if (_game_mode != GM_NORMAL) {
01212     IConsoleWarning("AIs can only be managed in a game.");
01213     return true;
01214   }
01215 
01216   if (_networking && !_network_server) {
01217     IConsoleWarning("Only the server can stop an AI.");
01218     return true;
01219   }
01220 
01221   CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
01222   if (!Company::IsValidID(company_id)) {
01223     IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
01224     return true;
01225   }
01226 
01227   if (Company::IsHumanID(company_id)) {
01228     IConsoleWarning("Company is not controlled by an AI.");
01229     return true;
01230   }
01231 
01232   /* Now kill the company of the AI. */
01233   DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
01234   IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
01235 
01236   return true;
01237 }
01238 
01239 DEF_CONSOLE_CMD(ConRescanAI)
01240 {
01241   if (argc == 0) {
01242     IConsoleHelp("Rescan the AI dir for scripts. Usage: 'rescan_ai'");
01243     return true;
01244   }
01245 
01246   if (_networking && !_network_server) {
01247     IConsoleWarning("Only the server can rescan the AI dir for scripts.");
01248     return true;
01249   }
01250 
01251   AI::Rescan();
01252 
01253   return true;
01254 }
01255 
01256 DEF_CONSOLE_CMD(ConRescanNewGRF)
01257 {
01258   if (argc == 0) {
01259     IConsoleHelp("Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'");
01260     return true;
01261   }
01262 
01263   ScanNewGRFFiles(NULL);
01264 
01265   return true;
01266 }
01267 
01268 DEF_CONSOLE_CMD(ConGetSeed)
01269 {
01270   if (argc == 0) {
01271     IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
01272     IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
01273     return true;
01274   }
01275 
01276   IConsolePrintF(CC_DEFAULT, "Generation Seed: %u", _settings_game.game_creation.generation_seed);
01277   return true;
01278 }
01279 
01280 DEF_CONSOLE_CMD(ConGetDate)
01281 {
01282   if (argc == 0) {
01283     IConsoleHelp("Returns the current date (day-month-year) of the game. Usage: 'getdate'");
01284     return true;
01285   }
01286 
01287   YearMonthDay ymd;
01288   ConvertDateToYMD(_date, &ymd);
01289   IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
01290   return true;
01291 }
01292 
01293 
01294 DEF_CONSOLE_CMD(ConAlias)
01295 {
01296   IConsoleAlias *alias;
01297 
01298   if (argc == 0) {
01299     IConsoleHelp("Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'");
01300     return true;
01301   }
01302 
01303   if (argc < 3) return false;
01304 
01305   alias = IConsoleAliasGet(argv[1]);
01306   if (alias == NULL) {
01307     IConsoleAliasRegister(argv[1], argv[2]);
01308   } else {
01309     free(alias->cmdline);
01310     alias->cmdline = strdup(argv[2]);
01311   }
01312   return true;
01313 }
01314 
01315 DEF_CONSOLE_CMD(ConScreenShot)
01316 {
01317   if (argc == 0) {
01318     IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | giant | no_con] [file name]'");
01319     IConsoleHelp("'big' makes a zoomed-in screenshot of the visible area, 'giant' makes a screenshot of the "
01320         "whole map, 'no_con' hides the console to create the screenshot. 'big' or 'giant' "
01321         "screenshots are always drawn without console");
01322     return true;
01323   }
01324 
01325   if (argc > 3) return false;
01326 
01327   ScreenshotType type = SC_VIEWPORT;
01328   const char *name = NULL;
01329 
01330   if (argc > 1) {
01331     if (strcmp(argv[1], "big") == 0) {
01332       /* screenshot big [filename] */
01333       type = SC_ZOOMEDIN;
01334       if (argc > 2) name = argv[2];
01335     } else if (strcmp(argv[1], "giant") == 0) {
01336       /* screenshot giant [filename] */
01337       type = SC_WORLD;
01338       if (argc > 2) name = argv[2];
01339     } else if (strcmp(argv[1], "no_con") == 0) {
01340       /* screenshot no_con [filename] */
01341       IConsoleClose();
01342       if (argc > 2) name = argv[2];
01343     } else if (argc == 2) {
01344       /* screenshot filename */
01345       name = argv[1];
01346     } else {
01347       /* screenshot argv[1] argv[2] - invalid */
01348       return false;
01349     }
01350   }
01351 
01352   MakeScreenshot(type, name);
01353   return true;
01354 }
01355 
01356 DEF_CONSOLE_CMD(ConInfoCmd)
01357 {
01358   if (argc == 0) {
01359     IConsoleHelp("Print out debugging information about a command. Usage: 'info_cmd <cmd>'");
01360     return true;
01361   }
01362 
01363   if (argc < 2) return false;
01364 
01365   const IConsoleCmd *cmd = IConsoleCmdGet(argv[1]);
01366   if (cmd == NULL) {
01367     IConsoleError("the given command was not found");
01368     return true;
01369   }
01370 
01371   IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
01372   IConsolePrintF(CC_DEFAULT, "command proc: %p", cmd->proc);
01373 
01374   if (cmd->hook != NULL) IConsoleWarning("command is hooked");
01375 
01376   return true;
01377 }
01378 
01379 DEF_CONSOLE_CMD(ConDebugLevel)
01380 {
01381   if (argc == 0) {
01382     IConsoleHelp("Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'");
01383     IConsoleHelp("Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
01384     return true;
01385   }
01386 
01387   if (argc > 2) return false;
01388 
01389   if (argc == 1) {
01390     IConsolePrintF(CC_DEFAULT, "Current debug-level: '%s'", GetDebugString());
01391   } else {
01392     SetDebugString(argv[1]);
01393   }
01394 
01395   return true;
01396 }
01397 
01398 DEF_CONSOLE_CMD(ConExit)
01399 {
01400   if (argc == 0) {
01401     IConsoleHelp("Exit the game. Usage: 'exit'");
01402     return true;
01403   }
01404 
01405   if (_game_mode == GM_NORMAL && _settings_client.gui.autosave_on_exit) DoExitSave();
01406 
01407   _exit_game = true;
01408   return true;
01409 }
01410 
01411 DEF_CONSOLE_CMD(ConPart)
01412 {
01413   if (argc == 0) {
01414     IConsoleHelp("Leave the currently joined/running game (only ingame). Usage: 'part'");
01415     return true;
01416   }
01417 
01418   if (_game_mode != GM_NORMAL) return false;
01419 
01420   _switch_mode = SM_MENU;
01421   return true;
01422 }
01423 
01424 DEF_CONSOLE_CMD(ConHelp)
01425 {
01426   if (argc == 2) {
01427     const IConsoleCmd *cmd;
01428     const IConsoleAlias *alias;
01429 
01430     RemoveUnderscores(argv[1]);
01431     cmd = IConsoleCmdGet(argv[1]);
01432     if (cmd != NULL) {
01433       cmd->proc(0, NULL);
01434       return true;
01435     }
01436 
01437     alias = IConsoleAliasGet(argv[1]);
01438     if (alias != NULL) {
01439       cmd = IConsoleCmdGet(alias->cmdline);
01440       if (cmd != NULL) {
01441         cmd->proc(0, NULL);
01442         return true;
01443       }
01444       IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
01445       return true;
01446     }
01447 
01448     IConsoleError("command not found");
01449     return true;
01450   }
01451 
01452   IConsolePrint(CC_WARNING, " ---- OpenTTD Console Help ---- ");
01453   IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
01454   IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
01455   IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes");
01456   IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'");
01457   IConsolePrint(CC_DEFAULT, " - use 'help <command>' to get specific information");
01458   IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down | pageup | pagedown)");
01459   IConsolePrint(CC_DEFAULT, " - scroll console input history with the up or down arrows");
01460   IConsolePrint(CC_DEFAULT, "");
01461   return true;
01462 }
01463 
01464 DEF_CONSOLE_CMD(ConListCommands)
01465 {
01466   if (argc == 0) {
01467     IConsoleHelp("List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
01468     return true;
01469   }
01470 
01471   for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
01472     if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) {
01473       if (cmd->hook == NULL || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
01474     }
01475   }
01476 
01477   return true;
01478 }
01479 
01480 DEF_CONSOLE_CMD(ConListAliases)
01481 {
01482   if (argc == 0) {
01483     IConsoleHelp("List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
01484     return true;
01485   }
01486 
01487   for (const IConsoleAlias *alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
01488     if (argv[1] == NULL || strstr(alias->name, argv[1]) != NULL) {
01489       IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
01490     }
01491   }
01492 
01493   return true;
01494 }
01495 
01496 #ifdef ENABLE_NETWORK
01497 
01498 DEF_CONSOLE_CMD(ConSay)
01499 {
01500   if (argc == 0) {
01501     IConsoleHelp("Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
01502     return true;
01503   }
01504 
01505   if (argc != 2) return false;
01506 
01507   if (!_network_server) {
01508     NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
01509   } else {
01510     bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
01511     NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER, from_admin);
01512   }
01513 
01514   return true;
01515 }
01516 
01517 DEF_CONSOLE_CMD(ConCompanies)
01518 {
01519   if (argc == 0) {
01520     IConsoleHelp("List the in-game details of all clients connected to the server. Usage 'companies'");
01521     return true;
01522   }
01523   NetworkCompanyStats company_stats[MAX_COMPANIES];
01524   NetworkPopulateCompanyStats(company_stats);
01525 
01526   Company *c;
01527   FOR_ALL_COMPANIES(c) {
01528     /* Grab the company name */
01529     char company_name[NETWORK_COMPANY_NAME_LENGTH];
01530     SetDParam(0, c->index);
01531     GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
01532 
01533     char buffer[512];
01534     const NetworkCompanyStats *stats = &company_stats[c->index];
01535 
01536     GetString(buffer, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(buffer));
01537     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",
01538       c->index + 1, buffer, company_name, c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
01539       /* trains      */ stats->num_vehicle[0],
01540       /* lorry + bus */ stats->num_vehicle[1] + stats->num_vehicle[2],
01541       /* planes      */ stats->num_vehicle[3],
01542       /* ships       */ stats->num_vehicle[4],
01543       /* protected   */ StrEmpty(_network_company_states[c->index].password) ? "un" : "");
01544   }
01545 
01546   return true;
01547 }
01548 
01549 DEF_CONSOLE_CMD(ConSayCompany)
01550 {
01551   if (argc == 0) {
01552     IConsoleHelp("Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
01553     IConsoleHelp("CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
01554     return true;
01555   }
01556 
01557   if (argc != 3) return false;
01558 
01559   CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
01560   if (!Company::IsValidID(company_id)) {
01561     IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
01562     return true;
01563   }
01564 
01565   if (!_network_server) {
01566     NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2]);
01567   } else {
01568     bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
01569     NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2], CLIENT_ID_SERVER, from_admin);
01570   }
01571 
01572   return true;
01573 }
01574 
01575 DEF_CONSOLE_CMD(ConSayClient)
01576 {
01577   if (argc == 0) {
01578     IConsoleHelp("Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
01579     IConsoleHelp("For client-id's, see the command 'clients'");
01580     return true;
01581   }
01582 
01583   if (argc != 3) return false;
01584 
01585   if (!_network_server) {
01586     NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
01587   } else {
01588     bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
01589     NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], CLIENT_ID_SERVER, from_admin);
01590   }
01591 
01592   return true;
01593 }
01594 
01595 DEF_CONSOLE_CMD(ConCompanyPassword)
01596 {
01597   if (argc == 0) {
01598     const char *helpmsg;
01599 
01600     if (_network_dedicated) {
01601       helpmsg = "Change the password of a company. Usage: 'company_pw <company-no> \"<password>\"";
01602     } else if (_network_server) {
01603       helpmsg = "Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'";
01604     } else {
01605       helpmsg = "Change the password of your company. Usage: 'company_pw \"<password>\"'";
01606     }
01607 
01608     IConsoleHelp(helpmsg);
01609     IConsoleHelp("Use \"*\" to disable the password.");
01610     return true;
01611   }
01612 
01613   CompanyID company_id;
01614   const char *password;
01615   const char *errormsg;
01616 
01617   if (argc == 2) {
01618     company_id = _local_company;
01619     password = argv[1];
01620     errormsg = "You have to own a company to make use of this command.";
01621   } else if (argc == 3 && _network_server) {
01622     company_id = (CompanyID)(atoi(argv[1]) - 1);
01623     password = argv[2];
01624     errormsg = "You have to specify the ID of a valid human controlled company.";
01625   } else {
01626     return false;
01627   }
01628 
01629   if (!Company::IsValidHumanID(company_id)) {
01630     IConsoleError(errormsg);
01631     return false;
01632   }
01633 
01634   password = NetworkChangeCompanyPassword(company_id, password);
01635 
01636   if (StrEmpty(password)) {
01637     IConsolePrintF(CC_WARNING, "Company password cleared");
01638   } else {
01639     IConsolePrintF(CC_WARNING, "Company password changed to: %s", password);
01640   }
01641 
01642   return true;
01643 }
01644 
01645 /* Content downloading only is available with ZLIB */
01646 #if defined(WITH_ZLIB)
01647 #include "network/network_content.h"
01648 
01650 static ContentType StringToContentType(const char *str)
01651 {
01652   static const char * const inv_lookup[] = { "", "base", "newgrf", "ai", "ailib", "scenario", "heightmap" };
01653   for (uint i = 1 /* there is no type 0 */; i < lengthof(inv_lookup); i++) {
01654     if (strcasecmp(str, inv_lookup[i]) == 0) return (ContentType)i;
01655   }
01656   return CONTENT_TYPE_END;
01657 }
01658 
01660 struct ConsoleContentCallback : public ContentCallback {
01661   void OnConnect(bool success)
01662   {
01663     IConsolePrintF(CC_DEFAULT, "Content server connection %s", success ? "established" : "failed");
01664   }
01665 
01666   void OnDisconnect()
01667   {
01668     IConsolePrintF(CC_DEFAULT, "Content server connection closed");
01669   }
01670 
01671   void OnDownloadComplete(ContentID cid)
01672   {
01673     IConsolePrintF(CC_DEFAULT, "Completed download of %d", cid);
01674   }
01675 };
01676 
01677 DEF_CONSOLE_CMD(ConContent)
01678 {
01679   static ContentCallback *cb = NULL;
01680   if (cb == NULL) {
01681     cb = new ConsoleContentCallback();
01682     _network_content_client.AddCallback(cb);
01683   }
01684 
01685   if (argc <= 1) {
01686     IConsoleHelp("Query, select and download content. Usage: 'content update|upgrade|select [all|id]|unselect [all|id]|state|download'");
01687     IConsoleHelp("  update: get a new list of downloadable content; must be run first");
01688     IConsoleHelp("  upgrade: select all items that are upgrades");
01689     IConsoleHelp("  select: select a specific item given by its id or 'all' to select all");
01690     IConsoleHelp("  unselect: unselect a specific item given by its id or 'all' to unselect all");
01691     IConsoleHelp("  state: show the download/select state of all downloadable content");
01692     IConsoleHelp("  download: download all content you've selected");
01693     return true;
01694   }
01695 
01696   if (strcasecmp(argv[1], "update") == 0) {
01697     _network_content_client.RequestContentList((argc > 2) ? StringToContentType(argv[2]) : CONTENT_TYPE_END);
01698     return true;
01699   }
01700 
01701   if (strcasecmp(argv[1], "upgrade") == 0) {
01702     _network_content_client.SelectUpgrade();
01703     return true;
01704   }
01705 
01706   if (strcasecmp(argv[1], "select") == 0) {
01707     if (argc <= 2) {
01708       IConsoleError("You must enter the id.");
01709       return false;
01710     }
01711     if (strcasecmp(argv[2], "all") == 0) {
01712       _network_content_client.SelectAll();
01713     } else {
01714       _network_content_client.Select((ContentID)atoi(argv[2]));
01715     }
01716     return true;
01717   }
01718 
01719   if (strcasecmp(argv[1], "unselect") == 0) {
01720     if (argc <= 2) {
01721       IConsoleError("You must enter the id.");
01722       return false;
01723     }
01724     if (strcasecmp(argv[2], "all") == 0) {
01725       _network_content_client.UnselectAll();
01726     } else {
01727       _network_content_client.Unselect((ContentID)atoi(argv[2]));
01728     }
01729     return true;
01730   }
01731 
01732   if (strcasecmp(argv[1], "state") == 0) {
01733     IConsolePrintF(CC_WHITE, "id, type, state, name");
01734     for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
01735       static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music" };
01736       assert_compile(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
01737       static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" };
01738       static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR };
01739 
01740       const ContentInfo *ci = *iter;
01741       IConsolePrintF(state_to_colour[ci->state], "%d, %s, %s, %s", ci->id, types[ci->type - 1], states[ci->state], ci->name);
01742     }
01743     return true;
01744   }
01745 
01746   if (strcasecmp(argv[1], "download") == 0) {
01747     uint files;
01748     uint bytes;
01749     _network_content_client.DownloadSelectedContent(files, bytes);
01750     IConsolePrintF(CC_DEFAULT, "Downloading %d file(s) (%d bytes)", files, bytes);
01751     return true;
01752   }
01753 
01754   return false;
01755 }
01756 #endif /* defined(WITH_ZLIB) */
01757 #endif /* ENABLE_NETWORK */
01758 
01759 DEF_CONSOLE_CMD(ConSetting)
01760 {
01761   if (argc == 0) {
01762     IConsoleHelp("Change setting for all clients. Usage: 'setting <name> [<value>]'");
01763     IConsoleHelp("Omitting <value> will print out the current value of the setting.");
01764     return true;
01765   }
01766 
01767   if (argc == 1 || argc > 3) return false;
01768 
01769   if (argc == 2) {
01770     IConsoleGetSetting(argv[1]);
01771   } else {
01772     IConsoleSetSetting(argv[1], argv[2]);
01773   }
01774 
01775   return true;
01776 }
01777 
01778 DEF_CONSOLE_CMD(ConSettingNewgame)
01779 {
01780   if (argc == 0) {
01781     IConsoleHelp("Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'");
01782     IConsoleHelp("Omitting <value> will print out the current value of the setting.");
01783     return true;
01784   }
01785 
01786   if (argc == 1 || argc > 3) return false;
01787 
01788   if (argc == 2) {
01789     IConsoleGetSetting(argv[1], true);
01790   } else {
01791     IConsoleSetSetting(argv[1], argv[2], true);
01792   }
01793 
01794   return true;
01795 }
01796 
01797 DEF_CONSOLE_CMD(ConListSettings)
01798 {
01799   if (argc == 0) {
01800     IConsoleHelp("List settings. Usage: 'list_settings [<pre-filter>]'");
01801     return true;
01802   }
01803 
01804   if (argc > 2) return false;
01805 
01806   IConsoleListSettings((argc == 2) ? argv[1] : NULL);
01807   return true;
01808 }
01809 
01810 DEF_CONSOLE_CMD(ConGamelogPrint)
01811 {
01812   GamelogPrintConsole();
01813   return true;
01814 }
01815 
01816 DEF_CONSOLE_CMD(ConNewGRFReload)
01817 {
01818   if (argc == 0) {
01819     IConsoleHelp("Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD!");
01820     return true;
01821   }
01822 
01823   ReloadNewGRFData();
01824   return true;
01825 }
01826 
01827 #ifdef _DEBUG
01828 /******************
01829  *  debug commands
01830  ******************/
01831 
01832 static void IConsoleDebugLibRegister()
01833 {
01834   IConsoleCmdRegister("resettile",        ConResetTile);
01835   IConsoleAliasRegister("dbg_echo",       "echo %A; echo %B");
01836   IConsoleAliasRegister("dbg_echo2",      "echo %!");
01837 }
01838 #endif
01839 
01840 /*******************************
01841  * console command registration
01842  *******************************/
01843 
01844 void IConsoleStdLibRegister()
01845 {
01846   IConsoleCmdRegister("debug_level",  ConDebugLevel);
01847   IConsoleCmdRegister("echo",         ConEcho);
01848   IConsoleCmdRegister("echoc",        ConEchoC);
01849   IConsoleCmdRegister("exec",         ConExec);
01850   IConsoleCmdRegister("exit",         ConExit);
01851   IConsoleCmdRegister("part",         ConPart);
01852   IConsoleCmdRegister("help",         ConHelp);
01853   IConsoleCmdRegister("info_cmd",     ConInfoCmd);
01854   IConsoleCmdRegister("list_cmds",    ConListCommands);
01855   IConsoleCmdRegister("list_aliases", ConListAliases);
01856   IConsoleCmdRegister("newgame",      ConNewGame);
01857   IConsoleCmdRegister("restart",      ConRestart);
01858   IConsoleCmdRegister("getseed",      ConGetSeed);
01859   IConsoleCmdRegister("getdate",      ConGetDate);
01860   IConsoleCmdRegister("quit",         ConExit);
01861   IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
01862   IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
01863   IConsoleCmdRegister("return",       ConReturn);
01864   IConsoleCmdRegister("screenshot",   ConScreenShot);
01865   IConsoleCmdRegister("script",       ConScript);
01866   IConsoleCmdRegister("scrollto",     ConScrollToTile);
01867   IConsoleCmdRegister("alias",        ConAlias);
01868   IConsoleCmdRegister("load",         ConLoad);
01869   IConsoleCmdRegister("rm",           ConRemove);
01870   IConsoleCmdRegister("save",         ConSave);
01871   IConsoleCmdRegister("saveconfig",   ConSaveConfig);
01872   IConsoleCmdRegister("ls",           ConListFiles);
01873   IConsoleCmdRegister("cd",           ConChangeDirectory);
01874   IConsoleCmdRegister("pwd",          ConPrintWorkingDirectory);
01875   IConsoleCmdRegister("clear",        ConClearBuffer);
01876   IConsoleCmdRegister("setting",      ConSetting);
01877   IConsoleCmdRegister("setting_newgame", ConSettingNewgame);
01878   IConsoleCmdRegister("list_settings",ConListSettings);
01879   IConsoleCmdRegister("gamelog",      ConGamelogPrint);
01880   IConsoleCmdRegister("rescan_newgrf", ConRescanNewGRF);
01881 
01882   IConsoleAliasRegister("dir",          "ls");
01883   IConsoleAliasRegister("del",          "rm %+");
01884   IConsoleAliasRegister("newmap",       "newgame");
01885   IConsoleAliasRegister("patch",        "setting %+");
01886   IConsoleAliasRegister("set",          "setting %+");
01887   IConsoleAliasRegister("set_newgame",  "setting_newgame %+");
01888   IConsoleAliasRegister("list_patches", "list_settings %+");
01889   IConsoleAliasRegister("developer",    "setting developer %+");
01890 
01891   IConsoleCmdRegister("list_ai_libs", ConListAILibs);
01892   IConsoleCmdRegister("list_ai",      ConListAI);
01893   IConsoleCmdRegister("reload_ai",    ConReloadAI);
01894   IConsoleCmdRegister("rescan_ai",    ConRescanAI);
01895   IConsoleCmdRegister("start_ai",     ConStartAI);
01896   IConsoleCmdRegister("stop_ai",      ConStopAI);
01897 
01898   /* networking functions */
01899 #ifdef ENABLE_NETWORK
01900 /* Content downloading is only available with ZLIB */
01901 #if defined(WITH_ZLIB)
01902   IConsoleCmdRegister("content",         ConContent);
01903 #endif /* defined(WITH_ZLIB) */
01904 
01905   /*** Networking commands ***/
01906   IConsoleCmdRegister("say",             ConSay, ConHookNeedNetwork);
01907   IConsoleCmdRegister("companies",       ConCompanies, ConHookServerOnly);
01908   IConsoleAliasRegister("players",       "companies");
01909   IConsoleCmdRegister("say_company",     ConSayCompany, ConHookNeedNetwork);
01910   IConsoleAliasRegister("say_player",    "say_company %+");
01911   IConsoleCmdRegister("say_client",      ConSayClient, ConHookNeedNetwork);
01912 
01913   IConsoleCmdRegister("connect",         ConNetworkConnect, ConHookClientOnly);
01914   IConsoleCmdRegister("clients",         ConNetworkClients, ConHookNeedNetwork);
01915   IConsoleCmdRegister("status",          ConStatus, ConHookServerOnly);
01916   IConsoleCmdRegister("server_info",     ConServerInfo, ConHookServerOnly);
01917   IConsoleAliasRegister("info",          "server_info");
01918   IConsoleCmdRegister("reconnect",       ConNetworkReconnect, ConHookClientOnly);
01919   IConsoleCmdRegister("rcon",            ConRcon, ConHookNeedNetwork);
01920 
01921   IConsoleCmdRegister("join",            ConJoinCompany, ConHookNeedNetwork);
01922   IConsoleAliasRegister("spectate",      "join 255");
01923   IConsoleCmdRegister("move",            ConMoveClient, ConHookServerOnly);
01924   IConsoleCmdRegister("reset_company",   ConResetCompany, ConHookServerOnly);
01925   IConsoleAliasRegister("clean_company", "reset_company %A");
01926   IConsoleCmdRegister("client_name",     ConClientNickChange, ConHookServerOnly);
01927   IConsoleCmdRegister("kick",            ConKick, ConHookServerOnly);
01928   IConsoleCmdRegister("ban",             ConBan, ConHookServerOnly);
01929   IConsoleCmdRegister("unban",           ConUnBan, ConHookServerOnly);
01930   IConsoleCmdRegister("banlist",         ConBanList, ConHookServerOnly);
01931 
01932   IConsoleCmdRegister("pause",           ConPauseGame, ConHookServerOnly);
01933   IConsoleCmdRegister("unpause",         ConUnpauseGame, ConHookServerOnly);
01934 
01935   IConsoleCmdRegister("company_pw",      ConCompanyPassword, ConHookNeedNetwork);
01936   IConsoleAliasRegister("company_password",      "company_pw %+");
01937 
01938   IConsoleAliasRegister("net_frame_freq",        "setting frame_freq %+");
01939   IConsoleAliasRegister("net_sync_freq",         "setting sync_freq %+");
01940   IConsoleAliasRegister("server_pw",             "setting server_password %+");
01941   IConsoleAliasRegister("server_password",       "setting server_password %+");
01942   IConsoleAliasRegister("rcon_pw",               "setting rcon_password %+");
01943   IConsoleAliasRegister("rcon_password",         "setting rcon_password %+");
01944   IConsoleAliasRegister("name",                  "setting client_name %+");
01945   IConsoleAliasRegister("server_name",           "setting server_name %+");
01946   IConsoleAliasRegister("server_port",           "setting server_port %+");
01947   IConsoleAliasRegister("server_advertise",      "setting server_advertise %+");
01948   IConsoleAliasRegister("max_clients",           "setting max_clients %+");
01949   IConsoleAliasRegister("max_companies",         "setting max_companies %+");
01950   IConsoleAliasRegister("max_spectators",        "setting max_spectators %+");
01951   IConsoleAliasRegister("max_join_time",         "setting max_join_time %+");
01952   IConsoleAliasRegister("pause_on_join",         "setting pause_on_join %+");
01953   IConsoleAliasRegister("autoclean_companies",   "setting autoclean_companies %+");
01954   IConsoleAliasRegister("autoclean_protected",   "setting autoclean_protected %+");
01955   IConsoleAliasRegister("autoclean_unprotected", "setting autoclean_unprotected %+");
01956   IConsoleAliasRegister("restart_game_year",     "setting restart_game_year %+");
01957   IConsoleAliasRegister("min_players",           "setting min_active_clients %+");
01958   IConsoleAliasRegister("reload_cfg",            "setting reload_cfg %+");
01959 #endif /* ENABLE_NETWORK */
01960 
01961   /* debugging stuff */
01962 #ifdef _DEBUG
01963   IConsoleDebugLibRegister();
01964 #endif
01965 
01966   /* NewGRF development stuff */
01967   IConsoleCmdRegister("reload_newgrfs",  ConNewGRFReload, ConHookNewGRFDeveloperTool);
01968 }