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>
Go to the source code of this file.
Defines | |
#define | ICON_BUFFER 79 |
#define | ICON_HISTORY_SIZE 20 |
#define | ICON_LINE_HEIGHT 12 |
#define | ICON_RIGHT_BORDERWIDTH 10 |
#define | ICON_BOTTOM_BORDERWIDTH 12 |
#define | ICON_MAX_ALIAS_LINES 40 |
#define | ICON_TOKEN_COUNT 20 |
Functions | |
void | IConsoleInit () |
static void | IConsoleWriteToLogFile (const char *string) |
bool | CloseConsoleLogIfActive () |
void | IConsoleFree () |
void | IConsolePrint (ConsoleColour colour_code, const char *string) |
Handle the printing of text entered into the console or redirected there by any other means. | |
void CDECL | IConsolePrintF (ConsoleColour colour_code, const char *format,...) |
Handle the printing of text entered into the console or redirected there by any other means. | |
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. | |
void | IConsoleWarning (const char *string) |
It is possible to print warnings to the console. | |
void | IConsoleError (const char *string) |
It is possible to print error information to the console. | |
bool | GetArgumentInteger (uint32 *value, const char *arg) |
Change a string into its number representation. | |
template<class T > | |
void | IConsoleAddSorted (T **base, T *item_new) |
Add an item to an alphabetically sorted list. | |
char * | RemoveUnderscores (char *name) |
Remove underscores from a string; the string will be modified! | |
void | IConsoleCmdRegister (const char *name, IConsoleCmdProc *proc, IConsoleHook *hook) |
Register a new command to be used in the console. | |
IConsoleCmd * | IConsoleCmdGet (const char *name) |
Find the command pointed to by its string. | |
void | IConsoleAliasRegister (const char *name, const char *cmd) |
Register a an alias for an already existing command in the console. | |
IConsoleAlias * | IConsoleAliasGet (const char *name) |
Find the alias pointed to by its string. | |
static int | IConsoleCopyInParams (char *dst, const char *src, uint bufpos) |
copy in an argument into the aliasstream | |
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. | |
void | IConsoleCmdExec (const char *cmdstr) |
Execute a given command passed to us. | |
Variables | |
IConsoleCmd * | _iconsole_cmds |
list of registered commands | |
IConsoleAlias * | _iconsole_aliases |
list of registered aliases | |
FILE * | _iconsole_output_file |
Handling of the in-game console.
Definition in file console.cpp.
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'
*value | the variable a successful conversion will be put in | |
*arg | the string to be converted |
Definition at line 187 of file console.cpp.
void IConsoleAddSorted | ( | T ** | base, | |
T * | item_new | |||
) | [inline] |
Add an item to an alphabetically sorted list.
base | first item of the list | |
item_new | the item to add |
Definition at line 210 of file console.cpp.
Referenced by IConsoleAliasRegister(), and IConsoleCmdRegister().
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.
*alias | is the alias of the command | |
tokencount | the number of parameters passed | |
*tokens | are the parameters given to the original command (0 is the first param) |
Definition at line 338 of file console.cpp.
References IConsoleAlias::cmdline, DEBUG, ICON_MAX_STREAMSIZE, IConsoleCmdExec(), IConsoleCopyInParams(), IConsoleError(), IConsolePrintF(), lengthof, and IConsoleAlias::name.
Referenced by IConsoleCmdExec().
IConsoleAlias* IConsoleAliasGet | ( | const char * | name | ) |
Find the alias pointed to by its string.
name | alias to be found |
Definition at line 310 of file console.cpp.
References IConsoleAlias::name, and IConsoleAlias::next.
Referenced by IConsoleAliasRegister(), and IConsoleCmdExec().
void IConsoleAliasRegister | ( | const char * | name, | |
const char * | cmd | |||
) |
Register a an alias for an already existing command in the console.
name | name of the alias that will be used | |
cmd | name 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, and RemoveUnderscores().
void IConsoleCmdExec | ( | const char * | cmdstr | ) |
Execute a given command passed to us.
First chop it up into individual tokens (seperated by spaces), then execute it if possible
cmdstr | string to be parsed and executed |
Definition at line 419 of file console.cpp.
References CHR_ALLOW, CHR_DISALLOW, CHR_HIDE, CS_ALPHANUMERAL, DEBUG, IConsoleCmd::hook, ICON_MAX_STREAMSIZE, IConsoleAliasExec(), IConsoleAliasGet(), IConsoleCmdGet(), IConsoleError(), IConsolePrintF(), IsValidChar(), lengthof, IConsoleCmd::proc, and RemoveUnderscores().
Referenced by IConsoleAliasExec(), TCPClientConnecter::OnConnect(), and IConsoleWindow::OnKeyPress().
IConsoleCmd* IConsoleCmdGet | ( | const char * | name | ) |
Find the command pointed to by its string.
name | command to be found |
Definition at line 272 of file console.cpp.
References IConsoleCmd::name, and IConsoleCmd::next.
Referenced by IConsoleCmdExec().
void IConsoleCmdRegister | ( | const char * | name, | |
IConsoleCmdProc * | proc, | |||
IConsoleHook * | hook | |||
) |
Register a new command to be used in the console.
name | name of the command that will be used | |
proc | function that will be called upon execution of command |
Definition at line 256 of file console.cpp.
References IConsoleCmd::hook, IConsoleAddSorted(), IConsoleCmd::name, IConsoleCmd::next, IConsoleCmd::proc, and RemoveUnderscores().
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
dbg | debugging category | |
string | debugging message |
Definition at line 154 of file console.cpp.
References _settings_client, GUISettings::developer, ClientSettings::gui, and IConsolePrintF().
Referenced by debug_print().
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 IConsolePrintF().
Referenced by IConsoleAliasExec(), IConsoleAliasRegister(), IConsoleCmdExec(), and ShowErrorMessage().
void IConsolePrint | ( | ConsoleColour | 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
colour_code | the colour of the command. Red in case of errors, etc. | |
string | the message entered or output on the console (notice, error, etc.) |
Definition at line 92 of file console.cpp.
References _network_dedicated, _redirect_console_to_admin, GetLogPrefix(), IConsoleGUIPrint(), INVALID_ADMIN_ID, INVALID_CLIENT_ID, NetworkAdminConsole(), NetworkServerSendAdminRcon(), str_strip_colours(), and str_validate().
Referenced by IConsolePrintF(), and ShowErrorMessage().
void CDECL IConsolePrintF | ( | ConsoleColour | colour_code, | |
const char * | format, | |||
... | ||||
) |
Handle the printing of text entered into the console or redirected there by any other means.
Uses printf() style format, for more information look at IConsolePrint()
Definition at line 134 of file console.cpp.
References ICON_MAX_STREAMSIZE, and IConsolePrint().
Referenced by DEF_GAME_RECEIVE_COMMAND(), IConsoleAliasExec(), IConsoleCmdExec(), IConsoleDebug(), IConsoleError(), IConsoleGetSetting(), IConsoleListSettings(), IConsoleWarning(), NetworkPrintClients(), ConsoleContentCallback::OnConnect(), ConsoleContentCallback::OnDisconnect(), ConsoleContentCallback::OnDownloadComplete(), and IConsoleWindow::OnKeyPress().
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, GUISettings::developer, ClientSettings::gui, and IConsolePrintF().
char* RemoveUnderscores | ( | char * | name | ) |
Remove underscores from a string; the string will be modified!
name | The string to remove the underscores from. |
Definition at line 241 of file console.cpp.
Referenced by IConsoleAliasRegister(), IConsoleCmdExec(), and IConsoleCmdRegister().