OpenTTD Source 20250426-master-gbb1d561369
console.cpp File Reference

Handling of the in-game console. More...

#include "stdafx.h"
#include "console_internal.h"
#include "network/network.h"
#include "network/network_func.h"
#include "network/network_admin.h"
#include "debug.h"
#include "console_func.h"
#include "settings_type.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

void IConsoleInit ()
 
static void IConsoleWriteToLogFile (const std::string &string)
 
bool CloseConsoleLogIfActive ()
 
void IConsoleFree ()
 
void IConsolePrint (TextColour colour_code, const std::string &string)
 Handle the printing of text entered into the console or redirected there by any other means.
 
static std::string RemoveUnderscores (std::string name)
 Creates a copy of a string with underscores removed from it.
 
static void IConsoleAliasExec (const IConsoleAlias *alias, uint8_t tokencount, char *tokens[ICON_TOKEN_COUNT], const uint recurse_count)
 An alias is just another name for a command, or for more commands Execute it as well.
 
void IConsoleCmdExec (const std::string &command_string, const uint recurse_count)
 Execute a given command passed to us.
 

Variables

static const uint ICON_TOKEN_COUNT = 20
 Maximum number of tokens in one command.
 
static const uint ICON_MAX_RECURSE = 10
 Maximum number of recursion.
 
std::optional< FileHandle_iconsole_output_file
 

Detailed Description

Handling of the in-game console.

Definition in file console.cpp.

Function Documentation

◆ CloseConsoleLogIfActive()

bool CloseConsoleLogIfActive ( )

Definition at line 63 of file console.cpp.

◆ IConsoleAliasExec()

static void IConsoleAliasExec ( const IConsoleAlias alias,
uint8_t  tokencount,
char *  tokens[ICON_TOKEN_COUNT],
const uint  recurse_count 
)
static

An alias is just another name for a command, or for more commands Execute it as well.

Parameters
*aliasis the alias of the command
tokencountthe number of parameters passed
*tokensare the parameters given to the original command (0 is the first param)

Definition at line 183 of file console.cpp.

References CC_ERROR, CC_HELP, IConsoleAlias::cmdline, Debug, ICON_MAX_RECURSE, ICON_MAX_STREAMSIZE, IConsoleCmdExec(), IConsolePrint(), and IConsoleAlias::name.

Referenced by IConsoleCmdExec().

◆ IConsoleCmdExec()

void IConsoleCmdExec ( const std::string &  command_string,
const uint  recurse_count 
)

◆ IConsoleFree()

void IConsoleFree ( )

Definition at line 74 of file console.cpp.

◆ IConsoleInit()

void IConsoleInit ( )

Definition at line 39 of file console.cpp.

◆ IConsolePrint()

void IConsolePrint ( TextColour  colour_code,
const std::string &  string 
)

Handle the printing of text entered into the console or redirected there by any other means.

Text can be redirected to other clients in a network game as well as to a logfile. If the network server is a dedicated server, all activities are also logged. All lines to print are added to a temporary buffer which can be used as a history to print them onscreen

Parameters
colour_codeThe colour of the command.
stringThe message to output on the console (notice, error, etc.)

Definition at line 89 of file console.cpp.

References _network_dedicated, _redirect_console_to_admin, _redirect_console_to_client, GetLogPrefix(), IConsoleGUIPrint(), INVALID_CLIENT_ID, IsValidConsoleColour(), NetworkAdminConsole(), NetworkServerSendAdminRcon(), NetworkServerSendRcon(), and StrMakeValid().

Referenced by IConsole::AliasRegister(), ConHookClientOnly(), ConHookNeedNetwork(), ConHookNeedNonDedicatedNetwork(), ConHookNoNetwork(), ConHookServerOnly(), ConHookServerOrNoNetwork(), ConListDirs(), ConPrintFramerate(), ConResetEnginePool(), ConResetEngines(), ConSave(), ConSaveConfig(), ConScrollToTile(), ConZoomToLevel(), DebugSendRemoteMessages(), IConsoleAliasExec(), IConsoleCmdExec(), IConsoleGetSetting(), IConsoleListSettings(), IConsolePrint(), NetworkAutoCleanCompanies(), NetworkAvailable(), NetworkPrintClients(), NetworkServer_Tick(), NetworkServerShowStatusToConsole(), ConsoleContentCallback::OnConnect(), ConsoleContentCallback::OnDisconnect(), ConsoleContentCallback::OnDownloadComplete(), IConsoleWindow::OnKeyPress(), OutputContentState(), Gamelog::PrintConsole(), PrintLineByLine(), ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(), ClientNetworkGameSocketHandler::Receive_SERVER_RCON(), and ShowErrorMessage().

◆ IConsoleWriteToLogFile()

static void IConsoleWriteToLogFile ( const std::string &  string)
static

Definition at line 50 of file console.cpp.

◆ RemoveUnderscores()

static std::string RemoveUnderscores ( std::string  name)
static

Creates a copy of a string with underscores removed from it.

Parameters
nameString to remove the underscores from.
Returns
A copy of name, without underscores.

Definition at line 125 of file console.cpp.

Referenced by IConsole::AliasGet(), IConsole::AliasRegister(), IConsole::CmdGet(), and IConsole::CmdRegister().

Variable Documentation

◆ _iconsole_output_file

std::optional<FileHandle> _iconsole_output_file

Definition at line 37 of file console.cpp.

◆ ICON_MAX_RECURSE

const uint ICON_MAX_RECURSE = 10
static

Maximum number of recursion.

Definition at line 22 of file console.cpp.

Referenced by IConsoleAliasExec().

◆ ICON_TOKEN_COUNT

const uint ICON_TOKEN_COUNT = 20
static

Maximum number of tokens in one command.

Definition at line 21 of file console.cpp.

Referenced by IConsoleCmdExec().