OpenTTD Source 20250517-master-g617169c1c9
|
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 const 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 const std::initializer_list< 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 2045 of file console_cmds.cpp.
|
extern |
Definition at line 64 of file console.cpp.
|
static |
Definition at line 1680 of file console_cmds.cpp.
|
static |
Definition at line 738 of file console_cmds.cpp.
|
static |
Definition at line 794 of file console_cmds.cpp.
|
static |
Definition at line 607 of file console_cmds.cpp.
|
static |
Definition at line 651 of file console_cmds.cpp.
|
static |
Definition at line 906 of file console_cmds.cpp.
|
static |
Definition at line 1937 of file console_cmds.cpp.
|
static |
Definition at line 2226 of file console_cmds.cpp.
|
static |
Definition at line 1814 of file console_cmds.cpp.
|
static |
Definition at line 2776 of file console_cmds.cpp.
|
static |
Definition at line 2834 of file console_cmds.cpp.
|
static |
Definition at line 2738 of file console_cmds.cpp.
|
static |
Definition at line 2701 of file console_cmds.cpp.
|
static |
Definition at line 1280 of file console_cmds.cpp.
|
static |
Definition at line 1292 of file console_cmds.cpp.
|
static |
Definition at line 1160 of file console_cmds.cpp.
|
static |
Definition at line 1833 of file console_cmds.cpp.
|
static |
Definition at line 2315 of file console_cmds.cpp.
|
static |
Definition at line 2658 of file console_cmds.cpp.
|
static |
Definition at line 2669 of file console_cmds.cpp.
|
static |
Definition at line 2430 of file console_cmds.cpp.
|
static |
Definition at line 1657 of file console_cmds.cpp.
|
static |
Definition at line 1645 of file console_cmds.cpp.
|
static |
Definition at line 1669 of file console_cmds.cpp.
|
static |
Definition at line 1864 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 1792 of file console_cmds.cpp.
|
static |
Definition at line 950 of file console_cmds.cpp.
|
static |
Definition at line 715 of file console_cmds.cpp.
|
static |
Definition at line 668 of file console_cmds.cpp.
|
static |
Definition at line 1408 of file console_cmds.cpp.
|
static |
Definition at line 1398 of file console_cmds.cpp.
|
static |
Definition at line 1920 of file console_cmds.cpp.
|
static |
Definition at line 1903 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 2452 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 559 of file console_cmds.cpp.
|
static |
Definition at line 1428 of file console_cmds.cpp.
|
static |
Definition at line 1418 of file console_cmds.cpp.
|
static |
Definition at line 591 of file console_cmds.cpp.
|
static |
Definition at line 575 of file console_cmds.cpp.
|
static |
Definition at line 2417 of file console_cmds.cpp.
|
static |
Definition at line 455 of file console_cmds.cpp.
|
static |
Definition at line 507 of file console_cmds.cpp.
|
static |
Definition at line 481 of file console_cmds.cpp.
|
static |
Definition at line 1001 of file console_cmds.cpp.
|
static |
Definition at line 2091 of file console_cmds.cpp.
|
static |
Definition at line 1099 of file console_cmds.cpp.
|
static |
Definition at line 1142 of file console_cmds.cpp.
|
static |
Definition at line 1111 of file console_cmds.cpp.
|
static |
Definition at line 1311 of file console_cmds.cpp.
|
static |
Definition at line 2521 of file console_cmds.cpp.
|
static |
Definition at line 2441 of file console_cmds.cpp.
|
static |
Definition at line 1846 of file console_cmds.cpp.
|
static |
Definition at line 812 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 636 of file console_cmds.cpp.
|
static |
Definition at line 860 of file console_cmds.cpp.
|
static |
Definition at line 1354 of file console_cmds.cpp.
|
static |
Definition at line 1512 of file console_cmds.cpp.
|
static |
Definition at line 533 of file console_cmds.cpp.
|
static |
Definition at line 1597 of file console_cmds.cpp.
|
static |
Definition at line 1614 of file console_cmds.cpp.
|
static |
Definition at line 1631 of file console_cmds.cpp.
|
static |
Definition at line 1054 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 1333 of file console_cmds.cpp.
|
static |
Definition at line 1237 of file console_cmds.cpp.
|
static |
Save the map to a file.
param filename the filename to save the map to.
Definition at line 416 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 442 of file console_cmds.cpp.
References CC_DEFAULT, CC_HELP, IConsolePrint(), and SaveToConfig().
|
static |
Definition at line 1962 of file console_cmds.cpp.
|
static |
Definition at line 2012 of file console_cmds.cpp.
|
static |
Definition at line 1981 of file console_cmds.cpp.
|
static |
Definition at line 1208 of file console_cmds.cpp.
|
static |
Definition at line 1700 of file console_cmds.cpp.
|
static |
Definition at line 1256 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 361 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 890 of file console_cmds.cpp.
|
static |
Definition at line 2379 of file console_cmds.cpp.
|
static |
Definition at line 2398 of file console_cmds.cpp.
|
static |
Definition at line 1438 of file console_cmds.cpp.
|
static |
Definition at line 879 of file console_cmds.cpp.
|
static |
Definition at line 1555 of file console_cmds.cpp.
|
static |
Definition at line 762 of file console_cmds.cpp.
|
static |
Definition at line 834 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, Begin, CC_ERROR, CC_HELP, DoZoomInOutWindow(), End, GetMainWindow(), ClientSettings::gui, IConsolePrint(), IsInsideMM(), Max, Min, Window::viewport, Viewport::zoom, ZOOM_IN, 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 2692 of file console_cmds.cpp.
References GB().
|
extern |
Definition at line 63 of file newgrf.cpp.
void IConsoleStdLibRegister | ( | ) |
Definition at line 2865 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 2216 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 943 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 2051 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 1378 of file console_cmds.cpp.
References CC_DEFAULT, and IConsolePrint().
bool PrintList | ( | F | list_function, |
Args... | args | ||
) |
Definition at line 1388 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 2178 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 2039 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.