OpenTTD Source 20250502-master-ge0a9c7d818
|
Implementation of the console hooks. More...
#include "stdafx.h"
#include "core/string_consumer.hpp"
#include "console_internal.h"
#include "debug.h"
#include "engine_func.h"
#include "landscape.h"
#include "saveload/saveload.h"
#include "network/core/network_game_info.h"
#include "network/network.h"
#include "network/network_func.h"
#include "network/network_base.h"
#include "network/network_admin.h"
#include "network/network_client.h"
#include "command_func.h"
#include "settings_func.h"
#include "fios.h"
#include "fileio_func.h"
#include "fontcache.h"
#include "screenshot.h"
#include "genworld.h"
#include "strings_func.h"
#include "viewport_func.h"
#include "window_func.h"
#include "timer/timer.h"
#include "company_func.h"
#include "gamelog.h"
#include "ai/ai.hpp"
#include "ai/ai_config.hpp"
#include "newgrf.h"
#include "newgrf_profiling.h"
#include "console_func.h"
#include "engine_base.h"
#include "road.h"
#include "rail.h"
#include "game/game.hpp"
#include "3rdparty/fmt/chrono.h"
#include "company_cmd.h"
#include "misc_cmd.h"
#include "table/strings.h"
#include "safeguards.h"
#include "network/network_content.h"
Go to the source code of this file.
Data Structures | |
class | ConsoleFileList |
File list storage for the console, for caching the last 'ls' command. More... | |
struct | ConsoleContentCallback |
Asynchronous callback. More... | |
Enumerations | |
enum | ConNetworkAuthorizedKeyAction : uint8_t { CNAKA_LIST , CNAKA_ADD , CNAKA_REMOVE } |
Functions | |
template<typename T > | |
static std::optional< T > | ParseType (std::string_view arg) |
Parse an integer using ParseInteger and convert it to the requested type. | |
static bool | NetworkAvailable (bool echo) |
Check network availability and inform in console about failure of detection. | |
static ConsoleHookResult | ConHookServerOnly (bool echo) |
Check whether we are a server. | |
static ConsoleHookResult | ConHookClientOnly (bool echo) |
Check whether we are a client in a network game. | |
static ConsoleHookResult | ConHookNeedNetwork (bool echo) |
Check whether we are in a multiplayer game. | |
static ConsoleHookResult | ConHookNeedNonDedicatedNetwork (bool echo) |
Check whether we are in a multiplayer game and are playing, i.e. | |
static ConsoleHookResult | ConHookNoNetwork (bool echo) |
Check whether we are in singleplayer mode. | |
static ConsoleHookResult | ConHookServerOrNoNetwork (bool echo) |
Check if are either in singleplayer or a server. | |
static ConsoleHookResult | ConHookNewGRFDeveloperTool (bool echo) |
static bool | ConResetEngines (std::span< std::string_view > argv) |
Reset status of all engines. | |
static bool | ConResetEnginePool (std::span< std::string_view > argv) |
Reset status of the engine pool. | |
static bool | ConZoomToLevel (std::span< std::string_view > argv) |
Zoom map to given level. | |
static bool | ConScrollToTile (std::span< std::string_view > argv) |
Scroll to a tile on the map. | |
static bool | ConSave (std::span< std::string_view > argv) |
Save the map to a file. | |
static bool | ConSaveConfig (std::span< std::string_view > argv) |
Explicitly save the configuration. | |
static bool | ConLoad (std::span< std::string_view > argv) |
static bool | ConLoadScenario (std::span< std::string_view > argv) |
static bool | ConLoadHeightmap (std::span< std::string_view > argv) |
static bool | ConRemove (std::span< std::string_view > argv) |
static bool | ConListFiles (std::span< std::string_view > argv) |
static bool | ConListScenarios (std::span< std::string_view > argv) |
static bool | ConListHeightmaps (std::span< std::string_view > argv) |
static bool | ConChangeDirectory (std::span< std::string_view > argv) |
static bool | ConPrintWorkingDirectory (std::span< std::string_view > argv) |
static bool | ConClearBuffer (std::span< std::string_view > argv) |
static bool | ConKickOrBan (std::string_view arg, bool ban, std::string_view reason) |
static bool | ConKick (std::span< std::string_view > argv) |
static bool | ConBan (std::span< std::string_view > argv) |
static bool | ConUnBan (std::span< std::string_view > argv) |
static bool | ConBanList (std::span< std::string_view > argv) |
static bool | ConPauseGame (std::span< std::string_view > argv) |
static bool | ConUnpauseGame (std::span< std::string_view > argv) |
static bool | ConRcon (std::span< std::string_view > argv) |
static bool | ConStatus (std::span< std::string_view > argv) |
static bool | ConServerInfo (std::span< std::string_view > argv) |
static bool | ConClientNickChange (std::span< std::string_view > argv) |
static std::optional< CompanyID > | ParseCompanyID (std::string_view arg) |
static bool | ConJoinCompany (std::span< std::string_view > argv) |
static bool | ConMoveClient (std::span< std::string_view > argv) |
static bool | ConResetCompany (std::span< std::string_view > argv) |
static bool | ConNetworkClients (std::span< std::string_view > argv) |
static bool | ConNetworkReconnect (std::span< std::string_view > argv) |
static bool | ConNetworkConnect (std::span< std::string_view > argv) |
static bool | ConExec (std::span< std::string_view > argv) |
static bool | ConSchedule (std::span< std::string_view > argv) |
static bool | ConReturn (std::span< std::string_view > argv) |
bool | CloseConsoleLogIfActive () |
std::span< const GRFFile > | GetAllGRFFiles () |
void | ConPrintFramerate () |
Print performance statistics to game console. | |
void | ShowFramerateWindow () |
Open the general framerate window. | |
static bool | ConScript (std::span< std::string_view > argv) |
static bool | ConEcho (std::span< std::string_view > argv) |
static bool | ConEchoC (std::span< std::string_view > argv) |
static bool | ConNewGame (std::span< std::string_view > argv) |
static bool | ConRestart (std::span< std::string_view > argv) |
static bool | ConReload (std::span< std::string_view > argv) |
static void | PrintLineByLine (const std::string &full_string) |
Print a text buffer line by line to the console. | |
template<typename F , typename ... Args> | |
bool | PrintList (F list_function, Args... args) |
static bool | ConListAILibs (std::span< std::string_view > argv) |
static bool | ConListAI (std::span< std::string_view > argv) |
static bool | ConListGameLibs (std::span< std::string_view > argv) |
static bool | ConListGame (std::span< std::string_view > argv) |
static bool | ConStartAI (std::span< std::string_view > argv) |
static bool | ConReloadAI (std::span< std::string_view > argv) |
static bool | ConStopAI (std::span< std::string_view > argv) |
static bool | ConRescanAI (std::span< std::string_view > argv) |
static bool | ConRescanGame (std::span< std::string_view > argv) |
static bool | ConRescanNewGRF (std::span< std::string_view > argv) |
static bool | ConGetSeed (std::span< std::string_view > argv) |
static bool | ConGetDate (std::span< std::string_view > argv) |
static bool | ConGetSysDate (std::span< std::string_view > argv) |
static bool | ConAlias (std::span< std::string_view > argv) |
static bool | ConScreenShot (std::span< std::string_view > argv) |
static bool | ConInfoCmd (std::span< std::string_view > argv) |
static bool | ConDebugLevel (std::span< std::string_view > argv) |
static bool | ConExit (std::span< std::string_view > argv) |
static bool | ConPart (std::span< std::string_view > argv) |
static bool | ConHelp (std::span< std::string_view > argv) |
static bool | ConListCommands (std::span< std::string_view > argv) |
static bool | ConListAliases (std::span< std::string_view > argv) |
static bool | ConCompanies (std::span< std::string_view > argv) |
static bool | ConSay (std::span< std::string_view > argv) |
static bool | ConSayCompany (std::span< std::string_view > argv) |
static bool | ConSayClient (std::span< std::string_view > argv) |
static void | PerformNetworkAuthorizedKeyAction (std::string_view name, NetworkAuthorizedKeys *authorized_keys, ConNetworkAuthorizedKeyAction action, const std::string &authorized_key, CompanyID company=CompanyID::Invalid()) |
static bool | ConNetworkAuthorizedKey (std::span< std::string_view > argv) |
static ContentType | StringToContentType (std::string_view str) |
Resolve a string to a content type. | |
static void | OutputContentState (const ContentInfo &ci) |
Outputs content state information to console. | |
static bool | ConContent (std::span< std::string_view > argv) |
static bool | ConFont (std::span< std::string_view > argv) |
static bool | ConSetting (std::span< std::string_view > argv) |
static bool | ConSettingNewgame (std::span< std::string_view > argv) |
static bool | ConListSettings (std::span< std::string_view > argv) |
static bool | ConGamelogPrint (std::span< std::string_view > argv) |
static bool | ConNewGRFReload (std::span< std::string_view > argv) |
static bool | ConListDirs (std::span< std::string_view > argv) |
static bool | ConNewGRFProfile (std::span< std::string_view > argv) |
static bool | ConFramerate (std::span< std::string_view > argv) |
static bool | ConFramerateWindow (std::span< std::string_view > argv) |
static std::string | FormatLabel (uint32_t label) |
Format a label as a string. | |
static void | ConDumpRoadTypes () |
static void | ConDumpRailTypes () |
static void | ConDumpCargoTypes () |
static bool | ConDumpInfo (std::span< std::string_view > argv) |
void | IConsoleStdLibRegister () |
Variables | |
static uint | _script_current_depth |
Depth of scripts running (used to abort execution when ConReturn is encountered). | |
static std::string | _scheduled_monthly_script |
Script scheduled to execute by the 'schedule' console command (empty if no script is scheduled). | |
static IntervalTimer< TimerGameCalendar > | _scheduled_monthly_timer |
Timer that runs every month of game time for the 'schedule' console command. | |
static ConsoleFileList | _console_file_list_savegame {FT_SAVEGAME, true} |
File storage cache for savegames. | |
static ConsoleFileList | _console_file_list_scenario {FT_SCENARIO, false} |
File storage cache for scenarios. | |
static ConsoleFileList | _console_file_list_heightmap {FT_HEIGHTMAP, false} |
File storage cache for heightmaps. | |
static std::vector< std::pair< std::string_view, NetworkAuthorizedKeys * > > | _console_cmd_authorized_keys |
All the known authorized keys with their name. | |
Implementation of the console hooks.
Definition in file console_cmds.cpp.
enum ConNetworkAuthorizedKeyAction : uint8_t |
Definition at line 2053 of file console_cmds.cpp.
|
extern |
Definition at line 64 of file console.cpp.
|
static |
Definition at line 1688 of file console_cmds.cpp.
|
static |
Definition at line 745 of file console_cmds.cpp.
|
static |
Definition at line 801 of file console_cmds.cpp.
|
static |
Definition at line 614 of file console_cmds.cpp.
|
static |
Definition at line 658 of file console_cmds.cpp.
|
static |
Definition at line 913 of file console_cmds.cpp.
|
static |
Definition at line 1945 of file console_cmds.cpp.
|
static |
Definition at line 2234 of file console_cmds.cpp.
|
static |
Definition at line 1822 of file console_cmds.cpp.
|
static |
Definition at line 2784 of file console_cmds.cpp.
|
static |
Definition at line 2842 of file console_cmds.cpp.
|
static |
Definition at line 2746 of file console_cmds.cpp.
|
static |
Definition at line 2709 of file console_cmds.cpp.
|
static |
Definition at line 1288 of file console_cmds.cpp.
|
static |
Definition at line 1300 of file console_cmds.cpp.
|
static |
Definition at line 1168 of file console_cmds.cpp.
|
static |
Definition at line 1841 of file console_cmds.cpp.
|
static |
Definition at line 2323 of file console_cmds.cpp.
|
static |
Definition at line 2666 of file console_cmds.cpp.
|
static |
Definition at line 2677 of file console_cmds.cpp.
|
static |
Definition at line 2438 of file console_cmds.cpp.
|
static |
Definition at line 1665 of file console_cmds.cpp.
|
static |
Definition at line 1653 of file console_cmds.cpp.
|
static |
Definition at line 1677 of file console_cmds.cpp.
|
static |
Definition at line 1872 of file console_cmds.cpp.
|
static |
Check whether we are a client in a network game.
Definition at line 159 of file console_cmds.cpp.
References _network_server, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), and NetworkAvailable().
|
static |
Check whether we are in a multiplayer game.
Definition at line 174 of file console_cmds.cpp.
References _network_server, _networking, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), ClientNetworkGameSocketHandler::IsConnected(), and NetworkAvailable().
|
static |
Check whether we are in a multiplayer game and are playing, i.e.
we are not the dedicated server.
Definition at line 189 of file console_cmds.cpp.
References _network_dedicated, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), and NetworkAvailable().
|
static |
Definition at line 226 of file console_cmds.cpp.
|
static |
Check whether we are in singleplayer mode.
Definition at line 204 of file console_cmds.cpp.
References _networking, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, and IConsolePrint().
|
static |
Check whether we are a server.
Definition at line 144 of file console_cmds.cpp.
References _network_server, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), and NetworkAvailable().
|
static |
Check if are either in singleplayer or a server.
Definition at line 217 of file console_cmds.cpp.
References _network_server, _networking, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, and IConsolePrint().
|
static |
Definition at line 1800 of file console_cmds.cpp.
|
static |
Definition at line 958 of file console_cmds.cpp.
|
static |
Definition at line 722 of file console_cmds.cpp.
|
static |
Definition at line 675 of file console_cmds.cpp.
|
static |
Definition at line 1416 of file console_cmds.cpp.
|
static |
Definition at line 1406 of file console_cmds.cpp.
|
static |
Definition at line 1928 of file console_cmds.cpp.
|
static |
Definition at line 1911 of file console_cmds.cpp.
|
static |
< Index of subdirectory type
< UI name for the directory
< Whether only the default (first existing) directory for this is interesting
Definition at line 2460 of file console_cmds.cpp.
References AI_DIR, AI_LIBRARY_DIR, AUTOSAVE_DIR, BASESET_DIR, CC_DEFAULT, CC_ERROR, CC_HELP, CC_INFO, FileExists(), GAME_DIR, GAME_LIBRARY_DIR, HEIGHTMAP_DIR, IConsolePrint(), NEWGRF_DIR, SAVE_DIR, SCENARIO_DIR, SCREENSHOT_DIR, SOCIAL_INTEGRATION_DIR, and StrEqualsIgnoreCase().
|
static |
Definition at line 566 of file console_cmds.cpp.
|
static |
Definition at line 1436 of file console_cmds.cpp.
|
static |
Definition at line 1426 of file console_cmds.cpp.
|
static |
Definition at line 598 of file console_cmds.cpp.
|
static |
Definition at line 582 of file console_cmds.cpp.
|
static |
Definition at line 2425 of file console_cmds.cpp.
|
static |
Definition at line 462 of file console_cmds.cpp.
|
static |
Definition at line 514 of file console_cmds.cpp.
|
static |
Definition at line 488 of file console_cmds.cpp.
|
static |
Definition at line 1009 of file console_cmds.cpp.
|
static |
Definition at line 2099 of file console_cmds.cpp.
|
static |
Definition at line 1107 of file console_cmds.cpp.
|
static |
Definition at line 1150 of file console_cmds.cpp.
|
static |
Definition at line 1119 of file console_cmds.cpp.
|
static |
Definition at line 1319 of file console_cmds.cpp.
|
static |
Definition at line 2529 of file console_cmds.cpp.
|
static |
Definition at line 2449 of file console_cmds.cpp.
|
static |
Definition at line 1854 of file console_cmds.cpp.
|
static |
Definition at line 819 of file console_cmds.cpp.
|
extern |
Print performance statistics to game console.
Definition at line 999 of file framerate_gui.cpp.
References anonymous_namespace{framerate_gui.cpp}::_pf_data, CC_ERROR, IConsolePrint(), anonymous_namespace{framerate_gui.cpp}::NUM_FRAMERATE_POINTS, PFE_AI0, PFE_DRAWING, PFE_GAMELOOP, PFE_MAX, and PFE_VIDEO.
|
static |
Definition at line 643 of file console_cmds.cpp.
|
static |
Definition at line 867 of file console_cmds.cpp.
|
static |
Definition at line 1362 of file console_cmds.cpp.
|
static |
Definition at line 1520 of file console_cmds.cpp.
|
static |
Definition at line 540 of file console_cmds.cpp.
|
static |
Definition at line 1605 of file console_cmds.cpp.
|
static |
Definition at line 1622 of file console_cmds.cpp.
|
static |
Definition at line 1639 of file console_cmds.cpp.
|
static |
Definition at line 1062 of file console_cmds.cpp.
|
static |
Reset status of the engine pool.
Definition at line 258 of file console_cmds.cpp.
References CC_ERROR, CC_HELP, IConsolePrint(), and EngineOverrideManager::ResetToCurrentNewGRFConfig().
|
static |
Reset status of all engines.
Definition at line 242 of file console_cmds.cpp.
References CC_HELP, IConsolePrint(), and StartupEngines().
|
static |
Definition at line 1341 of file console_cmds.cpp.
|
static |
Definition at line 1245 of file console_cmds.cpp.
|
static |
Save the map to a file.
param filename the filename to save the map to.
Definition at line 423 of file console_cmds.cpp.
References CC_DEFAULT, CC_ERROR, CC_HELP, CC_INFO, DFT_GAME_FILE, IConsolePrint(), SAVE_DIR, SaveOrLoad(), SL_OK, and SLO_SAVE.
|
static |
Explicitly save the configuration.
Definition at line 449 of file console_cmds.cpp.
References CC_DEFAULT, CC_HELP, IConsolePrint(), and SaveToConfig().
|
static |
Definition at line 1970 of file console_cmds.cpp.
|
static |
Definition at line 2020 of file console_cmds.cpp.
|
static |
Definition at line 1989 of file console_cmds.cpp.
|
static |
Definition at line 1216 of file console_cmds.cpp.
|
static |
Definition at line 1708 of file console_cmds.cpp.
|
static |
Definition at line 1264 of file console_cmds.cpp.
|
static |
Scroll to a tile on the map.
param x tile number or tile x coordinate. param y optional y coordinate.
Definition at line 368 of file console_cmds.cpp.
References CC_ERROR, CC_HELP, IConsolePrint(), ParseInteger(), ScrollMainWindowToTile(), Map::Size(), Map::SizeX(), Map::SizeY(), and TileXY().
|
static |
Definition at line 897 of file console_cmds.cpp.
|
static |
Definition at line 2387 of file console_cmds.cpp.
|
static |
Definition at line 2406 of file console_cmds.cpp.
|
static |
Definition at line 1446 of file console_cmds.cpp.
|
static |
Definition at line 886 of file console_cmds.cpp.
|
static |
Definition at line 1563 of file console_cmds.cpp.
|
static |
Definition at line 769 of file console_cmds.cpp.
|
static |
Definition at line 841 of file console_cmds.cpp.
|
static |
Zoom map to given level.
param level As defined by ZoomLevel and as limited by zoom_min/zoom_max from GUISettings.
Definition at line 309 of file console_cmds.cpp.
References _settings_client, CC_ERROR, CC_HELP, DoZoomInOutWindow(), GetMainWindow(), ClientSettings::gui, IConsolePrint(), ParseInteger(), Window::viewport, Viewport::zoom, ZOOM_IN, ZOOM_LVL_MAX, ZOOM_LVL_MIN, GUISettings::zoom_max, GUISettings::zoom_min, and ZOOM_OUT.
|
static |
Format a label as a string.
If all elements are visible ASCII (excluding space) then the label will be formatted as a string of 4 characters, otherwise it will be output as an 8-digit hexadecimal value.
label | Label to format. |
Definition at line 2700 of file console_cmds.cpp.
References GB().
|
extern |
Definition at line 63 of file newgrf.cpp.
void IConsoleStdLibRegister | ( | ) |
Definition at line 2873 of file console_cmds.cpp.
|
inlinestatic |
Check network availability and inform in console about failure of detection.
Definition at line 131 of file console_cmds.cpp.
References _network_available, CC_ERROR, and IConsolePrint().
Referenced by ConHookClientOnly(), ConHookNeedNetwork(), ConHookNeedNonDedicatedNetwork(), and ConHookServerOnly().
|
static |
Outputs content state information to console.
ci | the content info |
Definition at line 2224 of file console_cmds.cpp.
References CC_COMMAND, CC_ERROR, CC_INFO, CC_WHITE, CONTENT_TYPE_BEGIN, CONTENT_TYPE_END, FormatArrayAsHex(), IConsolePrint(), ContentInfo::id, lengthof, ContentInfo::md5sum, ContentInfo::name, ContentInfo::state, ContentInfo::type, and ContentInfo::unique_id.
|
static |
Definition at line 951 of file console_cmds.cpp.
|
static |
Parse an integer using ParseInteger and convert it to the requested type.
arg | The string to be converted. |
T | The type to return. |
Definition at line 81 of file console_cmds.cpp.
References ParseInteger().
|
static |
Definition at line 2059 of file console_cmds.cpp.
|
static |
Print a text buffer line by line to the console.
Lines are separated by '
'.
full_string | The multi-line string to print. |
Definition at line 1386 of file console_cmds.cpp.
References CC_DEFAULT, and IConsolePrint().
bool PrintList | ( | F | list_function, |
Args... | args | ||
) |
Definition at line 1396 of file console_cmds.cpp.
|
extern |
Open the general framerate window.
Definition at line 986 of file framerate_gui.cpp.
Referenced by MenuClickHelp().
|
static |
Resolve a string to a content type.
Definition at line 2186 of file console_cmds.cpp.
References CONTENT_TYPE_AI, CONTENT_TYPE_AI_LIBRARY, CONTENT_TYPE_BASE_GRAPHICS, CONTENT_TYPE_END, CONTENT_TYPE_HEIGHTMAP, CONTENT_TYPE_NEWGRF, CONTENT_TYPE_SCENARIO, and StrEqualsIgnoreCase().
|
static |
All the known authorized keys with their name.
Definition at line 2047 of file console_cmds.cpp.
|
static |
File storage cache for heightmaps.
Definition at line 121 of file console_cmds.cpp.
|
static |
File storage cache for savegames.
Definition at line 119 of file console_cmds.cpp.
|
static |
File storage cache for scenarios.
Definition at line 120 of file console_cmds.cpp.
|
static |
Script scheduled to execute by the 'schedule' console command (empty if no script is scheduled).
Definition at line 57 of file console_cmds.cpp.
|
static |
Timer that runs every month of game time for the 'schedule' console command.
Definition at line 60 of file console_cmds.cpp.
|
static |
Depth of scripts running (used to abort execution when ConReturn is encountered).
Definition at line 54 of file console_cmds.cpp.