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

Generated on Sun Jun 5 04:19:55 2011 for OpenTTD by  doxygen 1.6.1