OpenTTD Source
20241108-master-g80f628063a
|
Implementation of the console hooks. More...
#include "stdafx.h"
#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 "table/strings.h"
#include "3rdparty/fmt/chrono.h"
#include "company_cmd.h"
#include "misc_cmd.h"
#include <sstream>
#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... | |
Macros | |
#define | DEF_CONSOLE_CMD(function) static bool function([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) |
#define | DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo) |
Enumerations | |
enum | ConNetworkAuthorizedKeyAction { CNAKA_LIST , CNAKA_ADD , CNAKA_REMOVE } |
Functions | |
static bool | NetworkAvailable (bool echo) |
Check network availability and inform in console about failure of detection. More... | |
DEF_CONSOLE_HOOK (ConHookServerOnly) | |
Check whether we are a server. More... | |
DEF_CONSOLE_HOOK (ConHookClientOnly) | |
Check whether we are a client in a network game. More... | |
DEF_CONSOLE_HOOK (ConHookNeedNetwork) | |
Check whether we are in a multiplayer game. More... | |
DEF_CONSOLE_HOOK (ConHookNeedNonDedicatedNetwork) | |
Check whether we are in a multiplayer game and are playing, i.e. More... | |
DEF_CONSOLE_HOOK (ConHookNoNetwork) | |
Check whether we are in singleplayer mode. More... | |
DEF_CONSOLE_HOOK (ConHookServerOrNoNetwork) | |
Check if are either in singleplayer or a server. More... | |
DEF_CONSOLE_HOOK (ConHookNewGRFDeveloperTool) | |
DEF_CONSOLE_CMD (ConResetEngines) | |
Reset status of all engines. More... | |
DEF_CONSOLE_CMD (ConResetEnginePool) | |
Reset status of the engine pool. More... | |
DEF_CONSOLE_CMD (ConZoomToLevel) | |
Zoom map to given level. More... | |
DEF_CONSOLE_CMD (ConScrollToTile) | |
Scroll to a tile on the map. More... | |
DEF_CONSOLE_CMD (ConSave) | |
Save the map to a file. More... | |
DEF_CONSOLE_CMD (ConSaveConfig) | |
Explicitly save the configuration. More... | |
DEF_CONSOLE_CMD (ConLoad) | |
DEF_CONSOLE_CMD (ConLoadScenario) | |
DEF_CONSOLE_CMD (ConLoadHeightmap) | |
DEF_CONSOLE_CMD (ConRemove) | |
DEF_CONSOLE_CMD (ConListFiles) | |
DEF_CONSOLE_CMD (ConListScenarios) | |
DEF_CONSOLE_CMD (ConListHeightmaps) | |
DEF_CONSOLE_CMD (ConChangeDirectory) | |
DEF_CONSOLE_CMD (ConPrintWorkingDirectory) | |
DEF_CONSOLE_CMD (ConClearBuffer) | |
static bool | ConKickOrBan (const char *argv, bool ban, const std::string &reason) |
DEF_CONSOLE_CMD (ConKick) | |
DEF_CONSOLE_CMD (ConBan) | |
DEF_CONSOLE_CMD (ConUnBan) | |
DEF_CONSOLE_CMD (ConBanList) | |
DEF_CONSOLE_CMD (ConPauseGame) | |
DEF_CONSOLE_CMD (ConUnpauseGame) | |
DEF_CONSOLE_CMD (ConRcon) | |
DEF_CONSOLE_CMD (ConStatus) | |
DEF_CONSOLE_CMD (ConServerInfo) | |
DEF_CONSOLE_CMD (ConClientNickChange) | |
DEF_CONSOLE_CMD (ConJoinCompany) | |
DEF_CONSOLE_CMD (ConMoveClient) | |
DEF_CONSOLE_CMD (ConResetCompany) | |
DEF_CONSOLE_CMD (ConNetworkClients) | |
DEF_CONSOLE_CMD (ConNetworkReconnect) | |
DEF_CONSOLE_CMD (ConNetworkConnect) | |
DEF_CONSOLE_CMD (ConExec) | |
DEF_CONSOLE_CMD (ConSchedule) | |
DEF_CONSOLE_CMD (ConReturn) | |
bool | CloseConsoleLogIfActive () |
const std::vector< GRFFile * > & | GetAllGRFFiles () |
void | ConPrintFramerate () |
Print performance statistics to game console. | |
void | ShowFramerateWindow () |
Open the general framerate window. | |
DEF_CONSOLE_CMD (ConScript) | |
DEF_CONSOLE_CMD (ConEcho) | |
DEF_CONSOLE_CMD (ConEchoC) | |
DEF_CONSOLE_CMD (ConNewGame) | |
DEF_CONSOLE_CMD (ConRestart) | |
DEF_CONSOLE_CMD (ConReload) | |
static void | PrintLineByLine (const std::string &full_string) |
Print a text buffer line by line to the console. More... | |
template<typename F , typename ... Args> | |
bool | PrintList (F list_function, Args... args) |
DEF_CONSOLE_CMD (ConListAILibs) | |
DEF_CONSOLE_CMD (ConListAI) | |
DEF_CONSOLE_CMD (ConListGameLibs) | |
DEF_CONSOLE_CMD (ConListGame) | |
DEF_CONSOLE_CMD (ConStartAI) | |
DEF_CONSOLE_CMD (ConReloadAI) | |
DEF_CONSOLE_CMD (ConStopAI) | |
DEF_CONSOLE_CMD (ConRescanAI) | |
DEF_CONSOLE_CMD (ConRescanGame) | |
DEF_CONSOLE_CMD (ConRescanNewGRF) | |
DEF_CONSOLE_CMD (ConGetSeed) | |
DEF_CONSOLE_CMD (ConGetDate) | |
DEF_CONSOLE_CMD (ConGetSysDate) | |
DEF_CONSOLE_CMD (ConAlias) | |
DEF_CONSOLE_CMD (ConScreenShot) | |
DEF_CONSOLE_CMD (ConInfoCmd) | |
DEF_CONSOLE_CMD (ConDebugLevel) | |
DEF_CONSOLE_CMD (ConExit) | |
DEF_CONSOLE_CMD (ConPart) | |
DEF_CONSOLE_CMD (ConHelp) | |
DEF_CONSOLE_CMD (ConListCommands) | |
DEF_CONSOLE_CMD (ConListAliases) | |
DEF_CONSOLE_CMD (ConCompanies) | |
DEF_CONSOLE_CMD (ConSay) | |
DEF_CONSOLE_CMD (ConSayCompany) | |
DEF_CONSOLE_CMD (ConSayClient) | |
static void | PerformNetworkAuthorizedKeyAction (std::string_view name, NetworkAuthorizedKeys *authorized_keys, ConNetworkAuthorizedKeyAction action, const std::string &authorized_key, CompanyID company=INVALID_COMPANY) |
DEF_CONSOLE_CMD (ConNetworkAuthorizedKey) | |
static ContentType | StringToContentType (const char *str) |
Resolve a string to a content type. | |
static void | OutputContentState (const ContentInfo *const ci) |
Outputs content state information to console. More... | |
DEF_CONSOLE_CMD (ConContent) | |
DEF_CONSOLE_CMD (ConFont) | |
DEF_CONSOLE_CMD (ConSetting) | |
DEF_CONSOLE_CMD (ConSettingNewgame) | |
DEF_CONSOLE_CMD (ConListSettings) | |
DEF_CONSOLE_CMD (ConGamelogPrint) | |
DEF_CONSOLE_CMD (ConNewGRFReload) | |
DEF_CONSOLE_CMD (ConListDirs) | |
DEF_CONSOLE_CMD (ConNewGRFProfile) | |
DEF_CONSOLE_CMD (ConFramerate) | |
DEF_CONSOLE_CMD (ConFramerateWindow) | |
static std::string | FormatLabel (uint32_t label) |
Format a label as a string. More... | |
static void | ConDumpRoadTypes () |
static void | ConDumpRailTypes () |
static void | ConDumpCargoTypes () |
DEF_CONSOLE_CMD (ConDumpInfo) | |
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. More... | |
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. More... | |
Implementation of the console hooks.
Definition in file console_cmds.cpp.
DEF_CONSOLE_CMD | ( | ConListDirs | ) |
< Index of subdirectory type
< UI name for the directory
< Whether only the default (first existing) directory for this is interesting
Definition at line 2365 of file console_cmds.cpp.
References AI_DIR, AI_LIBRARY_DIR, AUTOSAVE_DIR, BASESET_DIR, CC_HELP, GAME_DIR, GAME_LIBRARY_DIR, HEIGHTMAP_DIR, IConsolePrint(), NEWGRF_DIR, SAVE_DIR, SCENARIO_DIR, SCREENSHOT_DIR, SOCIAL_INTEGRATION_DIR, and StrEqualsIgnoreCase().
DEF_CONSOLE_CMD | ( | ConResetEnginePool | ) |
Reset status of the engine pool.
Definition at line 249 of file console_cmds.cpp.
References CC_HELP, and IConsolePrint().
DEF_CONSOLE_CMD | ( | ConResetEngines | ) |
Reset status of all engines.
Definition at line 233 of file console_cmds.cpp.
References CC_HELP, IConsolePrint(), and StartupEngines().
DEF_CONSOLE_CMD | ( | ConSave | ) |
Save the map to a file.
param filename the filename to save the map to.
Definition at line 413 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.
DEF_CONSOLE_CMD | ( | ConSaveConfig | ) |
Explicitly save the configuration.
Definition at line 440 of file console_cmds.cpp.
References CC_DEFAULT, CC_HELP, IConsolePrint(), and SaveToConfig().
DEF_CONSOLE_CMD | ( | ConScrollToTile | ) |
Scroll to a tile on the map.
param x tile number or tile x coordinate. param y optional y coordinate.
Definition at line 359 of file console_cmds.cpp.
References CC_HELP, and IConsolePrint().
DEF_CONSOLE_CMD | ( | ConZoomToLevel | ) |
Zoom map to given level.
param level As defined by ZoomLevel and as limited by zoom_min/zoom_max from GUISettings.
Definition at line 300 of file console_cmds.cpp.
References _settings_client, CC_ERROR, CC_HELP, DoZoomInOutWindow(), GetArgumentInteger(), GetMainWindow(), ClientSettings::gui, IConsolePrint(), Window::viewport, Viewport::zoom, ZOOM_IN, ZOOM_LVL_MAX, ZOOM_LVL_MIN, GUISettings::zoom_max, GUISettings::zoom_min, and ZOOM_OUT.
DEF_CONSOLE_HOOK | ( | ConHookClientOnly | ) |
Check whether we are a client in a network game.
Definition at line 150 of file console_cmds.cpp.
References _network_server, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), and NetworkAvailable().
DEF_CONSOLE_HOOK | ( | ConHookNeedNetwork | ) |
Check whether we are in a multiplayer game.
Definition at line 165 of file console_cmds.cpp.
References _network_server, _networking, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), ClientNetworkGameSocketHandler::IsConnected(), and NetworkAvailable().
DEF_CONSOLE_HOOK | ( | ConHookNeedNonDedicatedNetwork | ) |
Check whether we are in a multiplayer game and are playing, i.e.
we are not the dedicated server.
Definition at line 180 of file console_cmds.cpp.
References _network_dedicated, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), and NetworkAvailable().
DEF_CONSOLE_HOOK | ( | ConHookNoNetwork | ) |
Check whether we are in singleplayer mode.
Definition at line 195 of file console_cmds.cpp.
References _networking, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, and IConsolePrint().
DEF_CONSOLE_HOOK | ( | ConHookServerOnly | ) |
Check whether we are a server.
Definition at line 135 of file console_cmds.cpp.
References _network_server, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, IConsolePrint(), and NetworkAvailable().
DEF_CONSOLE_HOOK | ( | ConHookServerOrNoNetwork | ) |
Check if are either in singleplayer or a server.
Definition at line 208 of file console_cmds.cpp.
References _network_server, _networking, CC_ERROR, CHR_ALLOW, CHR_DISALLOW, and IConsolePrint().
|
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 2599 of file console_cmds.cpp.
|
inlinestatic |
Check network availability and inform in console about failure of detection.
Definition at line 122 of file console_cmds.cpp.
References _network_available, CC_ERROR, and IConsolePrint().
Referenced by DEF_CONSOLE_HOOK().
|
static |
Outputs content state information to console.
ci | the content info |
Definition at line 2133 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 |
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 1327 of file console_cmds.cpp.
References CC_DEFAULT, and IConsolePrint().
|
static |
All the known authorized keys with their name.
Definition at line 1956 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.