OpenTTD
Functions | Variables
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 <stdarg.h>
#include "safeguards.h"

Go to the source code of this file.

Functions

void IConsoleInit ()
 
static void IConsoleWriteToLogFile (const char *string)
 
bool CloseConsoleLogIfActive ()
 
void IConsoleFree ()
 
void IConsolePrint (TextColour colour_code, const char *string)
 Handle the printing of text entered into the console or redirected there by any other means. More...
 
void CDECL IConsolePrintF (TextColour colour_code, const char *format,...)
 Handle the printing of text entered into the console or redirected there by any other means. More...
 
void IConsoleDebug (const char *dbg, const char *string)
 It is possible to print debugging information to the console, which is achieved by using this function. More...
 
void IConsoleWarning (const char *string)
 It is possible to print warnings to the console. More...
 
void IConsoleError (const char *string)
 It is possible to print error information to the console. More...
 
bool GetArgumentInteger (uint32 *value, const char *arg)
 Change a string into its number representation. More...
 
template<class T >
void IConsoleAddSorted (T **base, T *item_new)
 Add an item to an alphabetically sorted list. More...
 
char * RemoveUnderscores (char *name)
 Remove underscores from a string; the string will be modified! More...
 
void IConsoleCmdRegister (const char *name, IConsoleCmdProc *proc, IConsoleHook *hook)
 Register a new command to be used in the console. More...
 
IConsoleCmdIConsoleCmdGet (const char *name)
 Find the command pointed to by its string. More...
 
void IConsoleAliasRegister (const char *name, const char *cmd)
 Register a an alias for an already existing command in the console. More...
 
IConsoleAliasIConsoleAliasGet (const char *name)
 Find the alias pointed to by its string. More...
 
static void IConsoleAliasExec (const IConsoleAlias *alias, byte tokencount, char *tokens[ICON_TOKEN_COUNT])
 An alias is just another name for a command, or for more commands Execute it as well. More...
 
void IConsoleCmdExec (const char *cmdstr)
 Execute a given command passed to us. More...
 

Variables

static const uint ICON_TOKEN_COUNT = 20
 Maximum number of tokens in one command.
 
IConsoleCmd_iconsole_cmds
 list of registered commands More...
 
IConsoleAlias_iconsole_aliases
 list of registered aliases More...
 
FILE * _iconsole_output_file
 

Detailed Description

Handling of the in-game console.

Definition in file console.cpp.

Function Documentation

◆ GetArgumentInteger()

bool GetArgumentInteger ( uint32 *  value,
const char *  arg 
)

Change a string into its number representation.

Supports decimal and hexadecimal numbers as well as 'on'/'off' 'true'/'false'

Parameters
*valuethe variable a successful conversion will be put in
*argthe string to be converted
Returns
Return true on success or false on failure

Definition at line 187 of file console.cpp.

Referenced by DEF_CONSOLE_CMD().

◆ IConsoleAddSorted()

template<class T >
void IConsoleAddSorted ( T **  base,
T *  item_new 
)

Add an item to an alphabetically sorted list.

Parameters
basefirst item of the list
item_newthe item to add

Definition at line 210 of file console.cpp.

Referenced by IConsoleAliasRegister().

◆ IConsoleAliasExec()

static void IConsoleAliasExec ( const IConsoleAlias alias,
byte  tokencount,
char *  tokens[ICON_TOKEN_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 327 of file console.cpp.

References CC_WARNING, IConsoleAlias::cmdline, DEBUG, ICON_MAX_STREAMSIZE, IConsoleCmdExec(), IConsoleError(), IConsolePrintF(), lastof, IConsoleAlias::name, and strecpy().

Referenced by IConsoleCmdExec().

◆ IConsoleAliasGet()

IConsoleAlias* IConsoleAliasGet ( const char *  name)

Find the alias pointed to by its string.

Parameters
namealias to be found
Returns
return Aliasstruct of the found alias, or NULL on failure

Definition at line 310 of file console.cpp.

References IConsoleAlias::name, and IConsoleAlias::next.

Referenced by IConsoleAliasRegister(), and IConsoleCmdExec().

◆ IConsoleAliasRegister()

void IConsoleAliasRegister ( const char *  name,
const char *  cmd 
)

Register a an alias for an already existing command in the console.

Parameters
namename of the alias that will be used
cmdname of the command that 'name' will be alias of

Definition at line 287 of file console.cpp.

References IConsoleAlias::cmdline, IConsoleAddSorted(), IConsoleAliasGet(), IConsoleError(), IConsoleAlias::name, IConsoleAlias::next, RemoveUnderscores(), and stredup().

◆ IConsoleCmdExec()

void IConsoleCmdExec ( const char *  cmdstr)

Execute a given command passed to us.

First chop it up into individual tokens (separated by spaces), then execute it if possible

Parameters
cmdstrstring to be parsed and executed

Definition at line 409 of file console.cpp.

References CC_ERROR, CHR_ALLOW, CHR_DISALLOW, CHR_HIDE, CS_ALPHANUMERAL, DEBUG, IConsoleCmd::hook, ICON_MAX_STREAMSIZE, ICON_TOKEN_COUNT, IConsoleAliasExec(), IConsoleAliasGet(), IConsoleCmdGet(), IConsoleError(), IConsolePrintF(), IsValidChar(), lengthof, IConsoleCmd::proc, RemoveUnderscores(), and StrEmpty().

Referenced by IConsoleAliasExec(), and TCPClientConnecter::OnConnect().

◆ IConsoleCmdGet()

IConsoleCmd* IConsoleCmdGet ( const char *  name)

Find the command pointed to by its string.

Parameters
namecommand to be found
Returns
return Cmdstruct of the found command, or NULL on failure

Definition at line 272 of file console.cpp.

References IConsoleCmd::name, and IConsoleCmd::next.

Referenced by IConsoleCmdExec().

◆ IConsoleCmdRegister()

void IConsoleCmdRegister ( const char *  name,
IConsoleCmdProc proc,
IConsoleHook *  hook 
)

Register a new command to be used in the console.

Parameters
namename of the command that will be used
procfunction that will be called upon execution of command

Definition at line 256 of file console.cpp.

◆ IConsoleDebug()

void IConsoleDebug ( const char *  dbg,
const char *  string 
)

It is possible to print debugging information to the console, which is achieved by using this function.

Can only be used by debug() in debug.cpp. You need at least a level 2 (developer) for debugging messages to show up

Parameters
dbgdebugging category
stringdebugging message

Definition at line 154 of file console.cpp.

References _settings_client, CC_DEBUG, GUISettings::developer, ClientSettings::gui, and IConsolePrintF().

◆ IConsoleError()

void IConsoleError ( const char *  string)

It is possible to print error information to the console.

This can include game errors, or errors in general you would want the user to notice

Definition at line 175 of file console.cpp.

References CC_ERROR, and IConsolePrintF().

Referenced by DEF_CONSOLE_HOOK(), IConsoleAliasExec(), IConsoleAliasRegister(), IConsoleCmdExec(), and NetworkAvailable().

◆ IConsolePrint()

void IConsolePrint ( TextColour  colour_code,
const char *  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. Red in case of errors, etc.
stringthe message entered or output on the console (notice, error, etc.)

Definition at line 88 of file console.cpp.

Referenced by DEF_CONSOLE_CMD(), and ClientNetworkGameSocketHandler::Receive_SERVER_RCON().

◆ IConsolePrintF()

void CDECL IConsolePrintF ( TextColour  colour_code,
const char *  format,
  ... 
)

◆ IConsoleWarning()

void IConsoleWarning ( const char *  string)

It is possible to print warnings to the console.

These are mostly errors or mishaps, but non-fatal. You need at least a level 1 (developer) for debugging messages to show up

Definition at line 165 of file console.cpp.

References _settings_client, CC_WARNING, GUISettings::developer, ClientSettings::gui, and IConsolePrintF().

◆ RemoveUnderscores()

char* RemoveUnderscores ( char *  name)

Remove underscores from a string; the string will be modified!

Parameters
nameThe string to remove the underscores from.
Returns
#name.

Definition at line 241 of file console.cpp.

References CompanyProperties::name.

Referenced by IConsoleAliasRegister(), and IConsoleCmdExec().

Variable Documentation

◆ _iconsole_aliases

IConsoleAlias* _iconsole_aliases

list of registered aliases

List of registered aliases.

Definition at line 29 of file console.cpp.

◆ _iconsole_cmds

IConsoleCmd* _iconsole_cmds

list of registered commands

List of registered commands.

Definition at line 28 of file console.cpp.