(svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.

This commit is contained in:
rubidium 2008-05-24 10:35:15 +00:00
parent 6c20f77330
commit 6884f9cb41
9 changed files with 144 additions and 149 deletions

View File

@ -36,12 +36,7 @@ IConsoleCmd *_iconsole_cmds; ///< list of registred commands
IConsoleVar *_iconsole_vars; ///< list of registred vars IConsoleVar *_iconsole_vars; ///< list of registred vars
IConsoleAlias *_iconsole_aliases; ///< list of registred aliases IConsoleAlias *_iconsole_aliases; ///< list of registred aliases
/* console colors/modes */ /* console modes */
byte _icolour_def;
byte _icolour_err;
byte _icolour_warn;
byte _icolour_dbg;
byte _icolour_cmd;
IConsoleModes _iconsole_mode; IConsoleModes _iconsole_mode;
/* ** main console ** */ /* ** main console ** */
@ -111,11 +106,11 @@ struct IConsoleWindow : Window
/* If the text is longer than the window, don't show the starting ']' */ /* If the text is longer than the window, don't show the starting ']' */
delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH; delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
if (delta > 0) { if (delta > 0) {
DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, _icolour_cmd); DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
delta = 0; delta = 0;
} }
DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, _icolour_cmd); DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
if (_iconsole_cmdline.caret) { if (_iconsole_cmdline.caret) {
DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, this->height - ICON_LINE_HEIGHT, TC_WHITE); DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, this->height - ICON_LINE_HEIGHT, TC_WHITE);
@ -181,7 +176,7 @@ struct IConsoleWindow : Window
break; break;
case WKC_RETURN: case WKC_NUM_ENTER: case WKC_RETURN: case WKC_NUM_ENTER:
IConsolePrintF(_icolour_cmd, "] %s", _iconsole_cmdline.buf); IConsolePrintF(CC_COMMAND, "] %s", _iconsole_cmdline.buf);
IConsoleHistoryAdd(_iconsole_cmdline.buf); IConsoleHistoryAdd(_iconsole_cmdline.buf);
IConsoleCmdExec(_iconsole_cmdline.buf); IConsoleCmdExec(_iconsole_cmdline.buf);
@ -254,11 +249,6 @@ static const WindowDesc _iconsole_window_desc = {
void IConsoleInit() void IConsoleInit()
{ {
_iconsole_output_file = NULL; _iconsole_output_file = NULL;
_icolour_def = 1;
_icolour_err = 3;
_icolour_warn = 13;
_icolour_dbg = 5;
_icolour_cmd = TC_GOLD;
_iconsole_historypos = ICON_HISTORY_SIZE - 1; _iconsole_historypos = ICON_HISTORY_SIZE - 1;
_iconsole_mode = ICONSOLE_CLOSED; _iconsole_mode = ICONSOLE_CLOSED;
@ -272,10 +262,10 @@ void IConsoleInit()
_iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it _iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it
_iconsole_cmdline.maxlength = ICON_CMDLN_SIZE; _iconsole_cmdline.maxlength = ICON_CMDLN_SIZE;
IConsolePrintF(13, "OpenTTD Game Console Revision 7 - %s", _openttd_revision); IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
IConsolePrint(12, "------------------------------------"); IConsolePrint(CC_WHITE, "------------------------------------");
IConsolePrint(12, "use \"help\" for more information"); IConsolePrint(CC_WHITE, "use \"help\" for more information");
IConsolePrint(12, ""); IConsolePrint(CC_WHITE, "");
IConsoleStdLibRegister(); IConsoleStdLibRegister();
IConsoleClearCommand(); IConsoleClearCommand();
IConsoleHistoryAdd(""); IConsoleHistoryAdd("");
@ -304,7 +294,7 @@ static void IConsoleWriteToLogFile(const char *string)
fwrite("\n", 1, 1, _iconsole_output_file) != 1) { fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
fclose(_iconsole_output_file); fclose(_iconsole_output_file);
_iconsole_output_file = NULL; _iconsole_output_file = NULL;
IConsolePrintF(_icolour_def, "cannot write to log file"); IConsolePrintF(CC_DEFAULT, "cannot write to log file");
} }
} }
} }
@ -312,7 +302,7 @@ static void IConsoleWriteToLogFile(const char *string)
bool CloseConsoleLogIfActive() bool CloseConsoleLogIfActive()
{ {
if (_iconsole_output_file != NULL) { if (_iconsole_output_file != NULL) {
IConsolePrintF(_icolour_def, "file output complete"); IConsolePrintF(CC_DEFAULT, "file output complete");
fclose(_iconsole_output_file); fclose(_iconsole_output_file);
_iconsole_output_file = NULL; _iconsole_output_file = NULL;
return true; return true;
@ -412,7 +402,7 @@ static void IConsoleHistoryNavigate(int direction)
* @param color_code the colour of the command. Red in case of errors, etc. * @param color_code the colour of the command. Red in case of errors, etc.
* @param string the message entered or output on the console (notice, error, etc.) * @param string the message entered or output on the console (notice, error, etc.)
*/ */
void IConsolePrint(uint16 color_code, const char *string) void IConsolePrint(ConsoleColour color_code, const char *string)
{ {
char *str; char *str;
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
@ -456,7 +446,7 @@ void IConsolePrint(uint16 color_code, const char *string)
* by any other means. Uses printf() style format, for more information look * by any other means. Uses printf() style format, for more information look
* at IConsolePrint() * at IConsolePrint()
*/ */
void CDECL IConsolePrintF(uint16 color_code, const char *s, ...) void CDECL IConsolePrintF(ConsoleColour color_code, const char *s, ...)
{ {
va_list va; va_list va;
char buf[ICON_MAX_STREAMSIZE]; char buf[ICON_MAX_STREAMSIZE];
@ -479,7 +469,7 @@ void CDECL IConsolePrintF(uint16 color_code, const char *s, ...)
void IConsoleDebug(const char *dbg, const char *string) void IConsoleDebug(const char *dbg, const char *string)
{ {
if (_stdlib_developer > 1) if (_stdlib_developer > 1)
IConsolePrintF(_icolour_dbg, "dbg: [%s] %s", dbg, string); IConsolePrintF(CC_DEBUG, "dbg: [%s] %s", dbg, string);
} }
/** /**
@ -490,7 +480,7 @@ void IConsoleDebug(const char *dbg, const char *string)
void IConsoleWarning(const char *string) void IConsoleWarning(const char *string)
{ {
if (_stdlib_developer > 0) if (_stdlib_developer > 0)
IConsolePrintF(_icolour_warn, "WARNING: %s", string); IConsolePrintF(CC_WARNING, "WARNING: %s", string);
} }
/** /**
@ -499,7 +489,7 @@ void IConsoleWarning(const char *string)
*/ */
void IConsoleError(const char *string) void IConsoleError(const char *string)
{ {
IConsolePrintF(_icolour_err, "ERROR: %s", string); IConsolePrintF(CC_ERROR, "ERROR: %s", string);
} }
/** /**
@ -748,7 +738,7 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
memset(&aliasstream, 0, sizeof(aliasstream)); memset(&aliasstream, 0, sizeof(aliasstream));
if (_stdlib_con_developer) if (_stdlib_con_developer)
IConsolePrintF(_icolour_dbg, "condbg: requested command is an alias; parsing..."); IConsolePrintF(CC_DEBUG, "condbg: requested command is an alias; parsing...");
aliases[0] = aliasstream; aliases[0] = aliasstream;
for (cmdptr = alias->cmdline, a_index = 0, astream_i = 0; *cmdptr != '\0'; cmdptr++) { for (cmdptr = alias->cmdline, a_index = 0, astream_i = 0; *cmdptr != '\0'; cmdptr++) {
@ -788,7 +778,7 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
if (param < 0 || param >= tokencount) { if (param < 0 || param >= tokencount) {
IConsoleError("too many or wrong amount of parameters passed to alias, aborting"); IConsoleError("too many or wrong amount of parameters passed to alias, aborting");
IConsolePrintF(_icolour_warn, "Usage of alias '%s': %s", alias->name, alias->cmdline); IConsolePrintF(CC_WARNING, "Usage of alias '%s': %s", alias->name, alias->cmdline);
return; return;
} }
@ -1001,7 +991,7 @@ void IConsoleVarPrintGetValue(const IConsoleVar *var)
} }
value = IConsoleVarGetStringValue(var); value = IConsoleVarGetStringValue(var);
IConsolePrintF(_icolour_warn, "Current value for '%s' is: %s", var->name, value); IConsolePrintF(CC_WARNING, "Current value for '%s' is: %s", var->name, value);
} }
/** /**
@ -1011,7 +1001,7 @@ void IConsoleVarPrintGetValue(const IConsoleVar *var)
void IConsoleVarPrintSetValue(const IConsoleVar *var) void IConsoleVarPrintSetValue(const IConsoleVar *var)
{ {
char *value = IConsoleVarGetStringValue(var); char *value = IConsoleVarGetStringValue(var);
IConsolePrintF(_icolour_warn, "'%s' changed to: %s", var->name, value); IConsolePrintF(CC_WARNING, "'%s' changed to: %s", var->name, value);
} }
/** /**
@ -1028,7 +1018,7 @@ void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[ICON_T
uint32 value; uint32 value;
if (_stdlib_con_developer) if (_stdlib_con_developer)
IConsolePrintF(_icolour_dbg, "condbg: requested command is a variable"); IConsolePrintF(CC_DEBUG, "condbg: requested command is a variable");
if (tokencount == 0) { /* Just print out value */ if (tokencount == 0) { /* Just print out value */
IConsoleVarPrintGetValue(var); IConsoleVarPrintGetValue(var);
@ -1105,13 +1095,13 @@ void IConsoleCmdExec(const char *cmdstr)
for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) { for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) {
if (!IsValidChar(*cmdptr, CS_ALPHANUMERAL)) { if (!IsValidChar(*cmdptr, CS_ALPHANUMERAL)) {
IConsoleError("command contains malformed characters, aborting"); IConsoleError("command contains malformed characters, aborting");
IConsolePrintF(_icolour_err, "ERROR: command was: '%s'", cmdstr); IConsolePrintF(CC_ERROR, "ERROR: command was: '%s'", cmdstr);
return; return;
} }
} }
if (_stdlib_con_developer) if (_stdlib_con_developer)
IConsolePrintF(_icolour_dbg, "condbg: executing cmdline: '%s'", cmdstr); IConsolePrintF(CC_DEBUG, "condbg: executing cmdline: '%s'", cmdstr);
memset(&tokens, 0, sizeof(tokens)); memset(&tokens, 0, sizeof(tokens));
memset(&tokenstream, 0, sizeof(tokenstream)); memset(&tokenstream, 0, sizeof(tokenstream));
@ -1159,7 +1149,7 @@ void IConsoleCmdExec(const char *cmdstr)
uint i; uint i;
for (i = 0; tokens[i] != NULL; i++) { for (i = 0; tokens[i] != NULL; i++) {
IConsolePrintF(_icolour_dbg, "condbg: token %d is: '%s'", i, tokens[i]); IConsolePrintF(CC_DEBUG, "condbg: token %d is: '%s'", i, tokens[i]);
} }
} }

View File

@ -107,7 +107,7 @@ DEF_CONSOLE_HOOK(ConHookNoNetwork)
static void IConsoleHelp(const char *str) static void IConsoleHelp(const char *str)
{ {
IConsolePrintF(_icolour_warn, "- %s", str); IConsolePrintF(CC_WARNING, "- %s", str);
} }
DEF_CONSOLE_CMD(ConResetEngines) DEF_CONSOLE_CMD(ConResetEngines)
@ -165,7 +165,7 @@ DEF_CONSOLE_CMD(ConScrollToTile)
uint32 result; uint32 result;
if (GetArgumentInteger(&result, argv[1])) { if (GetArgumentInteger(&result, argv[1])) {
if (result >= MapSize()) { if (result >= MapSize()) {
IConsolePrint(_icolour_err, "Tile does not exist"); IConsolePrint(CC_ERROR, "Tile does not exist");
return true; return true;
} }
ScrollMainWindowToTile((TileIndex)result); ScrollMainWindowToTile((TileIndex)result);
@ -189,12 +189,12 @@ DEF_CONSOLE_CMD(ConSave)
if (argc == 2) { if (argc == 2) {
char *filename = str_fmt("%s.sav", argv[1]); char *filename = str_fmt("%s.sav", argv[1]);
IConsolePrint(_icolour_def, "Saving map..."); IConsolePrint(CC_DEFAULT, "Saving map...");
if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) { if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) {
IConsolePrint(_icolour_err, "Saving map failed"); IConsolePrint(CC_ERROR, "Saving map failed");
} else { } else {
IConsolePrintF(_icolour_def, "Map sucessfully saved to %s", filename); IConsolePrintF(CC_DEFAULT, "Map sucessfully saved to %s", filename);
} }
free(filename); free(filename);
return true; return true;
@ -212,7 +212,7 @@ DEF_CONSOLE_CMD(ConSaveConfig)
} }
SaveToConfig(); SaveToConfig();
IConsolePrint(_icolour_def, "Saved config."); IConsolePrint(CC_DEFAULT, "Saved config.");
return true; return true;
} }
@ -262,10 +262,10 @@ DEF_CONSOLE_CMD(ConLoad)
ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name)); ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title)); ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
} break; } break;
default: IConsolePrintF(_icolour_err, "%s: Not a savegame.", file); default: IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
} }
} else { } else {
IConsolePrintF(_icolour_err, "%s: No such file or directory.", file); IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
} }
FiosFreeSavegameList(); FiosFreeSavegameList();
@ -289,9 +289,9 @@ DEF_CONSOLE_CMD(ConRemove)
item = GetFiosItem(file); item = GetFiosItem(file);
if (item != NULL) { if (item != NULL) {
if (!FiosDelete(item->name)) if (!FiosDelete(item->name))
IConsolePrintF(_icolour_err, "%s: Failed to delete file", file); IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
} else { } else {
IConsolePrintF(_icolour_err, "%s: No such file or directory.", file); IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
} }
FiosFreeSavegameList(); FiosFreeSavegameList();
@ -313,7 +313,7 @@ DEF_CONSOLE_CMD(ConListFiles)
for (i = 0; i < _fios_num; i++) { for (i = 0; i < _fios_num; i++) {
const FiosItem *item = &_fios_list[i]; const FiosItem *item = &_fios_list[i];
IConsolePrintF(_icolour_def, "%d) %s", i, item->title); IConsolePrintF(CC_DEFAULT, "%d) %s", i, item->title);
} }
FiosFreeSavegameList(); FiosFreeSavegameList();
@ -340,10 +340,10 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT: case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
FiosBrowseTo(item); FiosBrowseTo(item);
break; break;
default: IConsolePrintF(_icolour_err, "%s: Not a directory.", file); default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
} }
} else { } else {
IConsolePrintF(_icolour_err, "%s: No such file or directory.", file); IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
} }
FiosFreeSavegameList(); FiosFreeSavegameList();
@ -364,7 +364,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
FiosFreeSavegameList(); FiosFreeSavegameList();
FiosGetDescText(&path, NULL); FiosGetDescText(&path, NULL);
IConsolePrint(_icolour_def, path); IConsolePrint(CC_DEFAULT, path);
return true; return true;
} }
@ -427,9 +427,9 @@ DEF_CONSOLE_CMD(ConBan)
if (ci != NULL) { if (ci != NULL) {
banip = inet_ntoa(*(struct in_addr *)&ci->client_ip); banip = inet_ntoa(*(struct in_addr *)&ci->client_ip);
SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED); SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
IConsolePrint(_icolour_def, "Client banned"); IConsolePrint(CC_DEFAULT, "Client banned");
} else { } else {
IConsolePrint(_icolour_def, "Client not online, banned IP"); IConsolePrint(CC_DEFAULT, "Client not online, banned IP");
} }
/* Add user to ban-list */ /* Add user to ban-list */
@ -464,12 +464,12 @@ DEF_CONSOLE_CMD(ConUnBan)
if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) { if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) {
free(_network_ban_list[i]); free(_network_ban_list[i]);
_network_ban_list[i] = NULL; _network_ban_list[i] = NULL;
IConsolePrint(_icolour_def, "IP unbanned."); IConsolePrint(CC_DEFAULT, "IP unbanned.");
return true; return true;
} }
} }
IConsolePrint(_icolour_def, "IP not in ban-list."); IConsolePrint(CC_DEFAULT, "IP not in ban-list.");
return true; return true;
} }
@ -482,11 +482,11 @@ DEF_CONSOLE_CMD(ConBanList)
return true; return true;
} }
IConsolePrint(_icolour_def, "Banlist: "); IConsolePrint(CC_DEFAULT, "Banlist: ");
for (i = 0; i < lengthof(_network_ban_list); i++) { for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] != NULL) if (_network_ban_list[i] != NULL)
IConsolePrintF(_icolour_def, " %d) %s", i + 1, _network_ban_list[i]); IConsolePrintF(CC_DEFAULT, " %d) %s", i + 1, _network_ban_list[i]);
} }
return true; return true;
@ -501,9 +501,9 @@ DEF_CONSOLE_CMD(ConPauseGame)
if (_pause_game == 0) { if (_pause_game == 0) {
DoCommandP(0, 1, 0, NULL, CMD_PAUSE); DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
IConsolePrint(_icolour_def, "Game paused."); IConsolePrint(CC_DEFAULT, "Game paused.");
} else { } else {
IConsolePrint(_icolour_def, "Game is already paused."); IConsolePrint(CC_DEFAULT, "Game is already paused.");
} }
return true; return true;
@ -518,9 +518,9 @@ DEF_CONSOLE_CMD(ConUnPauseGame)
if (_pause_game != 0) { if (_pause_game != 0) {
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
IConsolePrint(_icolour_def, "Game unpaused."); IConsolePrint(CC_DEFAULT, "Game unpaused.");
} else { } else {
IConsolePrint(_icolour_def, "Game is already unpaused."); IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
} }
return true; return true;
@ -570,7 +570,7 @@ DEF_CONSOLE_CMD(ConStatus)
const char* status; const char* status;
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown"); status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
IConsolePrintF(8, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'", IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
cs->index, ci->client_name, status, lag, cs->index, ci->client_name, status, lag,
ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0), ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
GetPlayerIP(ci), ci->unique_id); GetPlayerIP(ci), ci->unique_id);
@ -590,9 +590,9 @@ DEF_CONSOLE_CMD(ConServerInfo)
} }
gi = &_network_game_info; gi = &_network_game_info;
IConsolePrintF(_icolour_def, "Current/maximum clients: %2d/%2d", gi->clients_on, gi->clients_max); IConsolePrintF(CC_DEFAULT, "Current/maximum clients: %2d/%2d", gi->clients_on, gi->clients_max);
IConsolePrintF(_icolour_def, "Current/maximum companies: %2d/%2d", ActivePlayerCount(), gi->companies_max); IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", ActivePlayerCount(), gi->companies_max);
IConsolePrintF(_icolour_def, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), gi->spectators_max); IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), gi->spectators_max);
return true; return true;
} }
@ -693,7 +693,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
/* Check valid range */ /* Check valid range */
if (!IsValidPlayer(index)) { if (!IsValidPlayer(index)) {
IConsolePrintF(_icolour_err, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS); IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
return true; return true;
} }
@ -725,7 +725,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
/* It is safe to remove this company */ /* It is safe to remove this company */
DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL); DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
IConsolePrint(_icolour_def, "Company deleted."); IConsolePrint(CC_DEFAULT, "Company deleted.");
return true; return true;
} }
@ -740,7 +740,7 @@ DEF_CONSOLE_CMD(ConNetworkClients)
} }
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) { FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
IConsolePrintF(8, "Client #%1d name: '%s' company: %1d IP: %s", IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_index, ci->client_name, ci->client_index, ci->client_name,
ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0), ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
GetPlayerIP(ci)); GetPlayerIP(ci));
@ -773,10 +773,10 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
ParseConnectionString(&player, &port, ip); ParseConnectionString(&player, &port, ip);
IConsolePrintF(_icolour_def, "Connecting to %s...", ip); IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
if (player != NULL) { if (player != NULL) {
_network_playas = (PlayerID)atoi(player); _network_playas = (PlayerID)atoi(player);
IConsolePrintF(_icolour_def, " player-no: %d", _network_playas); IConsolePrintF(CC_DEFAULT, " player-no: %d", _network_playas);
/* From a user pov 0 is a new player, internally it's different and all /* From a user pov 0 is a new player, internally it's different and all
* players are offset by one to ease up on users (eg players 1-8 not 0-7) */ * players are offset by one to ease up on users (eg players 1-8 not 0-7) */
@ -787,7 +787,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
} }
if (port != NULL) { if (port != NULL) {
rport = atoi(port); rport = atoi(port);
IConsolePrintF(_icolour_def, " port: %s", port); IConsolePrintF(CC_DEFAULT, " port: %s", port);
} }
NetworkClientConnectGame(ip, rport); NetworkClientConnectGame(ip, rport);
@ -870,7 +870,7 @@ DEF_CONSOLE_CMD(ConScript)
if (!CloseConsoleLogIfActive()) { if (!CloseConsoleLogIfActive()) {
if (argc < 2) return false; if (argc < 2) return false;
IConsolePrintF(_icolour_def, "file output started to: %s", argv[1]); IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
_iconsole_output_file = fopen(argv[1], "ab"); _iconsole_output_file = fopen(argv[1], "ab");
if (_iconsole_output_file == NULL) IConsoleError("could not open file"); if (_iconsole_output_file == NULL) IConsoleError("could not open file");
} }
@ -887,7 +887,7 @@ DEF_CONSOLE_CMD(ConEcho)
} }
if (argc < 2) return false; if (argc < 2) return false;
IConsolePrint(_icolour_def, argv[1]); IConsolePrint(CC_DEFAULT, argv[1]);
return true; return true;
} }
@ -899,7 +899,7 @@ DEF_CONSOLE_CMD(ConEchoC)
} }
if (argc < 3) return false; if (argc < 3) return false;
IConsolePrint(atoi(argv[1]), argv[2]); IConsolePrint((ConsoleColour)atoi(argv[1]), argv[2]);
return true; return true;
} }
@ -940,7 +940,7 @@ DEF_CONSOLE_CMD(ConGetSeed)
return true; return true;
} }
IConsolePrintF(_icolour_def, "Generation Seed: %u", _patches.generation_seed); IConsolePrintF(CC_DEFAULT, "Generation Seed: %u", _patches.generation_seed);
return true; return true;
} }
@ -953,7 +953,7 @@ DEF_CONSOLE_CMD(ConGetDate)
YearMonthDay ymd; YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd); ConvertDateToYMD(_date, &ymd);
IConsolePrintF(_icolour_def, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year); IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
return true; return true;
} }
@ -1019,9 +1019,9 @@ DEF_CONSOLE_CMD(ConInfoVar)
return true; return true;
} }
IConsolePrintF(_icolour_def, "variable name: %s", var->name); IConsolePrintF(CC_DEFAULT, "variable name: %s", var->name);
IConsolePrintF(_icolour_def, "variable type: %s", _icon_vartypes[var->type]); IConsolePrintF(CC_DEFAULT, "variable type: %s", _icon_vartypes[var->type]);
IConsolePrintF(_icolour_def, "variable addr: 0x%X", var->addr); IConsolePrintF(CC_DEFAULT, "variable addr: 0x%X", var->addr);
if (var->hook.access) IConsoleWarning("variable is access hooked"); if (var->hook.access) IConsoleWarning("variable is access hooked");
if (var->hook.pre) IConsoleWarning("variable is pre hooked"); if (var->hook.pre) IConsoleWarning("variable is pre hooked");
@ -1047,8 +1047,8 @@ DEF_CONSOLE_CMD(ConInfoCmd)
return true; return true;
} }
IConsolePrintF(_icolour_def, "command name: %s", cmd->name); IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
IConsolePrintF(_icolour_def, "command proc: 0x%X", cmd->proc); IConsolePrintF(CC_DEFAULT, "command proc: 0x%X", cmd->proc);
if (cmd->hook.access) IConsoleWarning("command is access hooked"); if (cmd->hook.access) IConsoleWarning("command is access hooked");
if (cmd->hook.pre) IConsoleWarning("command is pre hooked"); if (cmd->hook.pre) IConsoleWarning("command is pre hooked");
@ -1068,7 +1068,7 @@ DEF_CONSOLE_CMD(ConDebugLevel)
if (argc > 2) return false; if (argc > 2) return false;
if (argc == 1) { if (argc == 1) {
IConsolePrintF(_icolour_def, "Current debug-level: '%s'", GetDebugString()); IConsolePrintF(CC_DEFAULT, "Current debug-level: '%s'", GetDebugString());
} else { } else {
SetDebugString(argv[1]); SetDebugString(argv[1]);
} }
@ -1122,7 +1122,7 @@ DEF_CONSOLE_CMD(ConHelp)
cmd->proc(0, NULL); cmd->proc(0, NULL);
return true; return true;
} }
IConsolePrintF(_icolour_err, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline); IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
return true; return true;
} }
@ -1136,18 +1136,18 @@ DEF_CONSOLE_CMD(ConHelp)
return true; return true;
} }
IConsolePrint(13, " ---- OpenTTD Console Help ---- "); IConsolePrint(CC_WARNING, " ---- OpenTTD Console Help ---- ");
IConsolePrint( 1, " - variables: [command to list all variables: list_vars]"); IConsolePrint(CC_DEFAULT, " - variables: [command to list all variables: list_vars]");
IConsolePrint( 1, " set value with '<var> = <value>', use '++/--' to in-or decrement"); IConsolePrint(CC_DEFAULT, " set value with '<var> = <value>', use '++/--' to in-or decrement");
IConsolePrint( 1, " or omit '=' and just '<var> <value>'. get value with typing '<var>'"); IConsolePrint(CC_DEFAULT, " or omit '=' and just '<var> <value>'. get value with typing '<var>'");
IConsolePrint( 1, " - commands: [command to list all commands: list_cmds]"); IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
IConsolePrint( 1, " call commands with '<command> <arg2> <arg3>...'"); IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
IConsolePrint( 1, " - to assign strings, or use them as arguments, enclose it within quotes"); IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes");
IConsolePrint( 1, " like this: '<command> \"string argument with spaces\"'"); IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'");
IConsolePrint( 1, " - use 'help <command> | <variable>' to get specific information"); IConsolePrint(CC_DEFAULT, " - use 'help <command> | <variable>' to get specific information");
IConsolePrint( 1, " - scroll console output with shift + (up | down) | (pageup | pagedown))"); IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down) | (pageup | pagedown))");
IConsolePrint( 1, " - scroll console input history with the up | down arrows"); IConsolePrint(CC_DEFAULT, " - scroll console input history with the up | down arrows");
IConsolePrint( 1, ""); IConsolePrint(CC_DEFAULT, "");
return true; return true;
} }
@ -1165,7 +1165,7 @@ DEF_CONSOLE_CMD(ConListCommands)
for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) { for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) { if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) {
IConsolePrintF(_icolour_def, "%s", cmd->name); IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
} }
} }
@ -1186,7 +1186,7 @@ DEF_CONSOLE_CMD(ConListVariables)
for (var = _iconsole_vars; var != NULL; var = var->next) { for (var = _iconsole_vars; var != NULL; var = var->next) {
if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0) if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
IConsolePrintF(_icolour_def, "%s", var->name); IConsolePrintF(CC_DEFAULT, "%s", var->name);
} }
return true; return true;
@ -1206,7 +1206,7 @@ DEF_CONSOLE_CMD(ConListAliases)
for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) { for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0) if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0)
IConsolePrintF(_icolour_def, "%s => %s", alias->name, alias->cmdline); IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
} }
return true; return true;
@ -1250,7 +1250,7 @@ DEF_CONSOLE_CMD(ConPlayers)
const NetworkPlayerInfo *npi = &_network_player_info[p->index]; const NetworkPlayerInfo *npi = &_network_player_info[p->index];
GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index], lastof(buffer)); GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index], lastof(buffer));
IConsolePrintF(8, "#:%d(%s) Company Name: '%s' Year Founded: %d Money: %" OTTD_PRINTF64 "d Loan: %" OTTD_PRINTF64 "d Value: %" OTTD_PRINTF64 "d (T:%d, R:%d, P:%d, S:%d) %sprotected", IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s' Year Founded: %d Money: %" OTTD_PRINTF64 "d Loan: %" OTTD_PRINTF64 "d Value: %" OTTD_PRINTF64 "d (T:%d, R:%d, P:%d, S:%d) %sprotected",
p->index + 1, buffer, npi->company_name, p->inaugurated_year, (int64)p->player_money, (int64)p->current_loan, (int64)CalculateCompanyValue(p), p->index + 1, buffer, npi->company_name, p->inaugurated_year, (int64)p->player_money, (int64)p->current_loan, (int64)CalculateCompanyValue(p),
/* trains */ npi->num_vehicle[0], /* trains */ npi->num_vehicle[0],
/* lorry + bus */ npi->num_vehicle[1] + npi->num_vehicle[2], /* lorry + bus */ npi->num_vehicle[1] + npi->num_vehicle[2],
@ -1273,7 +1273,7 @@ DEF_CONSOLE_CMD(ConSayPlayer)
if (argc != 3) return false; if (argc != 3) return false;
if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) { if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) {
IConsolePrintF(_icolour_def, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS); IConsolePrintF(CC_DEFAULT, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
return true; return true;
} }
@ -1335,7 +1335,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
{ {
if (argc == 0) { if (argc == 0) {
if (!IsValidPlayer(_local_player)) return true; // dedicated server if (!IsValidPlayer(_local_player)) return true; // dedicated server
IConsolePrintF(_icolour_warn, "Current value for 'company_pw': %s", _network_player_info[_local_player].password); IConsolePrintF(CC_WARNING, "Current value for 'company_pw': %s", _network_player_info[_local_player].password);
return true; return true;
} }
@ -1356,7 +1356,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
HashCurrentCompanyPassword(); HashCurrentCompanyPassword();
} }
IConsolePrintF(_icolour_warn, "'company_pw' changed to: %s", _network_player_info[_local_player].password); IConsolePrintF(CC_WARNING, "'company_pw' changed to: %s", _network_player_info[_local_player].password);
return true; return true;
} }
@ -1373,7 +1373,7 @@ DEF_CONSOLE_HOOK(ConProcPlayerName)
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name); SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name);
} else { } else {
if (NetworkFindName(_network_player_name)) { if (NetworkFindName(_network_player_name)) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", _network_player_name); NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _network_player_name);
ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name)); ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX); NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
} }
@ -1400,7 +1400,7 @@ DEF_CONSOLE_HOOK(ConHookServerAdvertise)
DEF_CONSOLE_CMD(ConProcServerIP) DEF_CONSOLE_CMD(ConProcServerIP)
{ {
if (argc == 0) { if (argc == 0) {
IConsolePrintF(_icolour_warn, "Current value for 'server_ip': %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip)); IConsolePrintF(CC_WARNING, "Current value for 'server_ip': %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
return true; return true;
} }
@ -1408,7 +1408,7 @@ DEF_CONSOLE_CMD(ConProcServerIP)
_network_server_bind_ip = (strcmp(argv[0], "all") == 0) ? inet_addr("0.0.0.0") : inet_addr(argv[0]); _network_server_bind_ip = (strcmp(argv[0], "all") == 0) ? inet_addr("0.0.0.0") : inet_addr(argv[0]);
snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip)); snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
IConsolePrintF(_icolour_warn, "'server_ip' changed to: %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip)); IConsolePrintF(CC_WARNING, "'server_ip' changed to: %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
return true; return true;
} }
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -7,12 +7,7 @@
#include "console_type.h" #include "console_type.h"
/* console colors/modes */ /* console modes */
extern byte _icolour_def;
extern byte _icolour_err;
extern byte _icolour_warn;
extern byte _icolour_dbg;
extern byte _icolour_cmd;
extern IConsoleModes _iconsole_mode; extern IConsoleModes _iconsole_mode;
/* console functions */ /* console functions */
@ -21,8 +16,8 @@ void IConsoleFree();
void IConsoleClose(); void IConsoleClose();
/* console output */ /* console output */
void IConsolePrint(uint16 color_code, const char *string); void IConsolePrint(ConsoleColour color_code, const char *string);
void CDECL IConsolePrintF(uint16 color_code, const char *s, ...); void CDECL IConsolePrintF(ConsoleColour color_code, const char *s, ...);
void IConsoleDebug(const char *dbg, const char *string); void IConsoleDebug(const char *dbg, const char *string);
/* Parser */ /* Parser */

View File

@ -11,4 +11,14 @@ enum IConsoleModes {
ICONSOLE_CLOSED ICONSOLE_CLOSED
}; };
enum ConsoleColour {
CC_DEFAULT = 1,
CC_ERROR = 3,
CC_WARNING = 13,
CC_INFO = 8,
CC_DEBUG = 5,
CC_COMMAND = 2,
CC_WHITE = 12,
};
#endif /* CONSOLE_TYPE_H */ #endif /* CONSOLE_TYPE_H */

View File

@ -141,7 +141,7 @@ byte NetworkSpectatorCount()
// This puts a text-message to the console, or in the future, the chat-box, // This puts a text-message to the console, or in the future, the chat-box,
// (to keep it all a bit more general) // (to keep it all a bit more general)
// If 'self_send' is true, this is the client who is sending the message // If 'self_send' is true, this is the client who is sending the message
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send, const char *name, const char *str, ...) void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...)
{ {
char buf[1024]; char buf[1024];
va_list va; va_list va;
@ -155,16 +155,16 @@ void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send
switch (action) { switch (action) {
case NETWORK_ACTION_SERVER_MESSAGE: case NETWORK_ACTION_SERVER_MESSAGE:
color = 1; color = CC_DEFAULT;
snprintf(message, sizeof(message), "*** %s", buf); snprintf(message, sizeof(message), "*** %s", buf);
break; break;
case NETWORK_ACTION_JOIN: case NETWORK_ACTION_JOIN:
color = 1; color = CC_DEFAULT;
GetString(temp, STR_NETWORK_CLIENT_JOINED, lastof(temp)); GetString(temp, STR_NETWORK_CLIENT_JOINED, lastof(temp));
snprintf(message, sizeof(message), "*** %s %s", name, temp); snprintf(message, sizeof(message), "*** %s %s", name, temp);
break; break;
case NETWORK_ACTION_LEAVE: case NETWORK_ACTION_LEAVE:
color = 1; color = CC_DEFAULT;
GetString(temp, STR_NETWORK_ERR_LEFT, lastof(temp)); GetString(temp, STR_NETWORK_ERR_LEFT, lastof(temp));
snprintf(message, sizeof(message), "*** %s %s (%s)", name, temp, buf); snprintf(message, sizeof(message), "*** %s %s (%s)", name, temp, buf);
break; break;
@ -651,7 +651,7 @@ void NetworkCloseClient(NetworkTCPSocketHandler *cs)
GetNetworkErrorMsg(str, errorno, lastof(str)); GetNetworkErrorMsg(str, errorno, lastof(str));
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
// Inform other clients of this... strange leaving ;) // Inform other clients of this... strange leaving ;)
FOR_ALL_CLIENTS(new_cs) { FOR_ALL_CLIENTS(new_cs) {

View File

@ -414,7 +414,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
if (ci != NULL) { if (ci != NULL) {
if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) { if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
// Client name changed, display the change // Client name changed, display the change
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", name); NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", name);
} else if (playas != ci->client_playas) { } else if (playas != ci->client_playas) {
// The player changed from client-player.. // The player changed from client-player..
// Do not display that for now // Do not display that for now
@ -761,7 +761,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
} }
if (ci != NULL) if (ci != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg); NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg);
return NETWORK_RECV_STATUS_OKAY; return NETWORK_RECV_STATUS_OKAY;
} }
@ -776,7 +776,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
ci = NetworkFindClientInfoFromIndex(index); ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) { if (ci != NULL) {
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, "%s", str); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
// The client is gone, give the NetworkClientInfo free // The client is gone, give the NetworkClientInfo free
ci->client_index = NETWORK_EMPTY_INDEX; ci->client_index = NETWORK_EMPTY_INDEX;
@ -798,7 +798,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
ci = NetworkFindClientInfoFromIndex(index); ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) { if (ci != NULL) {
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, "%s", str); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
// The client is gone, give the NetworkClientInfo free // The client is gone, give the NetworkClientInfo free
ci->client_index = NETWORK_EMPTY_INDEX; ci->client_index = NETWORK_EMPTY_INDEX;
@ -821,7 +821,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN)
ci = NetworkFindClientInfoFromIndex(index); ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) if (ci != NULL)
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, ci->client_name, ""); NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name, "");
InvalidateWindow(WC_CLIENT_LIST, 0); InvalidateWindow(WC_CLIENT_LIST, 0);
@ -850,9 +850,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON) DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON)
{ {
char rcon_out[NETWORK_RCONCOMMAND_LENGTH]; char rcon_out[NETWORK_RCONCOMMAND_LENGTH];
uint16 color_code;
color_code = p->Recv_uint16(); ConsoleColour color_code = (ConsoleColour)p->Recv_uint16();
p->Recv_string(rcon_out, sizeof(rcon_out)); p->Recv_string(rcon_out, sizeof(rcon_out));
IConsolePrint(color_code, rcon_out); IConsolePrint(color_code, rcon_out);

View File

@ -6,6 +6,7 @@
#define NETWORK_DATA_H #define NETWORK_DATA_H
#include "../openttd.h" #include "../openttd.h"
#include "../console_type.h"
#include "network.h" #include "network.h"
#include "network_internal.h" #include "network_internal.h"
@ -105,7 +106,7 @@ void NetworkAddCommandQueue(NetworkTCPSocketHandler *cs, CommandPacket *cp);
// from network.c // from network.c
void NetworkCloseClient(NetworkTCPSocketHandler *cs); void NetworkCloseClient(NetworkTCPSocketHandler *cs);
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send, const char *name, const char *str, ...); void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...);
void NetworkGetClientName(char *clientname, size_t size, const NetworkTCPSocketHandler *cs); void NetworkGetClientName(char *clientname, size_t size, const NetworkTCPSocketHandler *cs);
uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs); uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs);
byte NetworkGetCurrentLanguageIndex(); byte NetworkGetCurrentLanguageIndex();

View File

@ -160,7 +160,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs,
DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str); DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
FOR_ALL_CLIENTS(new_cs) { FOR_ALL_CLIENTS(new_cs) {
if (new_cs->status > STATUS_AUTH && new_cs != cs) { if (new_cs->status > STATUS_AUTH && new_cs != cs) {
@ -779,7 +779,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
NetworkGetClientName(client_name, sizeof(client_name), cs); NetworkGetClientName(client_name, sizeof(client_name), cs);
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, client_name, ""); NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, "");
// Mark the client as pre-active, and wait for an ACK // Mark the client as pre-active, and wait for an ACK
// so we know he is done loading and in sync with us // so we know he is done loading and in sync with us
@ -822,17 +822,17 @@ static bool CheckCommandFlags(const CommandPacket *cp, const NetworkClientInfo *
byte flags = GetCommandFlags(cp->cmd); byte flags = GetCommandFlags(cp->cmd);
if (flags & CMD_SERVER && ci->client_index != NETWORK_SERVER_INDEX) { if (flags & CMD_SERVER && ci->client_index != NETWORK_SERVER_INDEX) {
IConsolePrintF(_icolour_err, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci)); IConsolePrintF(CC_ERROR, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
return false; return false;
} }
if (flags & CMD_OFFLINE) { if (flags & CMD_OFFLINE) {
IConsolePrintF(_icolour_err, "WARNING: offline only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci)); IConsolePrintF(CC_ERROR, "WARNING: offline only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
return false; return false;
} }
if (cp->cmd != CMD_PLAYER_CTRL && !IsValidPlayer(cp->player) && ci->client_index != NETWORK_SERVER_INDEX) { if (cp->cmd != CMD_PLAYER_CTRL && !IsValidPlayer(cp->player) && ci->client_index != NETWORK_SERVER_INDEX) {
IConsolePrintF(_icolour_err, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci)); IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
return false; return false;
} }
@ -875,7 +875,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
/* Check if cp->cmd is valid */ /* Check if cp->cmd is valid */
if (!IsValidCommand(cp->cmd)) { if (!IsValidCommand(cp->cmd)) {
IConsolePrintF(_icolour_err, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci)); IConsolePrintF(CC_ERROR, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci));
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
free(cp); free(cp);
return; return;
@ -892,7 +892,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
* something pretty naughty (or a bug), and will be kicked * something pretty naughty (or a bug), and will be kicked
*/ */
if (!(cp->cmd == CMD_PLAYER_CTRL && cp->p1 == 0) && ci->client_playas != cp->player) { if (!(cp->cmd == CMD_PLAYER_CTRL && cp->p1 == 0) && ci->client_playas != cp->player) {
IConsolePrintF(_icolour_err, "WARNING: player %d (IP: %s) tried to execute a command as player %d, kicking...", IConsolePrintF(CC_ERROR, "WARNING: player %d (IP: %s) tried to execute a command as player %d, kicking...",
ci->client_playas + 1, GetPlayerIP(ci), cp->player + 1); ci->client_playas + 1, GetPlayerIP(ci), cp->player + 1);
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH); SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
free(cp); free(cp);
@ -969,7 +969,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str); DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
FOR_ALL_CLIENTS(new_cs) { FOR_ALL_CLIENTS(new_cs) {
if (new_cs->status > STATUS_AUTH) { if (new_cs->status > STATUS_AUTH) {
@ -998,7 +998,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
NetworkGetClientName(client_name, sizeof(client_name), cs); NetworkGetClientName(client_name, sizeof(client_name), cs);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
FOR_ALL_CLIENTS(new_cs) { FOR_ALL_CLIENTS(new_cs) {
if (new_cs->status > STATUS_AUTH) { if (new_cs->status > STATUS_AUTH) {
@ -1052,7 +1052,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
ci = NetworkFindClientInfoFromIndex(from_index); ci = NetworkFindClientInfoFromIndex(from_index);
/* Display the text locally, and that is it */ /* Display the text locally, and that is it */
if (ci != NULL) if (ci != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg); NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
} else { } else {
/* Else find the client to send the message to */ /* Else find the client to send the message to */
FOR_ALL_CLIENTS(cs) { FOR_ALL_CLIENTS(cs) {
@ -1069,7 +1069,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
ci = NetworkFindClientInfoFromIndex(from_index); ci = NetworkFindClientInfoFromIndex(from_index);
ci_to = NetworkFindClientInfoFromIndex(dest); ci_to = NetworkFindClientInfoFromIndex(dest);
if (ci != NULL && ci_to != NULL) if (ci != NULL && ci_to != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), true, ci_to->client_name, "%s", msg); NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), true, ci_to->client_name, "%s", msg);
} else { } else {
FOR_ALL_CLIENTS(cs) { FOR_ALL_CLIENTS(cs) {
if (cs->index == from_index) { if (cs->index == from_index) {
@ -1097,7 +1097,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
ci = NetworkFindClientInfoFromIndex(from_index); ci = NetworkFindClientInfoFromIndex(from_index);
ci_own = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); ci_own = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) { if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg); NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
if (from_index == NETWORK_SERVER_INDEX) show_local = false; if (from_index == NETWORK_SERVER_INDEX) show_local = false;
ci_to = ci_own; ci_to = ci_own;
} }
@ -1112,7 +1112,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
StringID str = IsValidPlayer(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS; StringID str = IsValidPlayer(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
SetDParam(0, ci_to->client_playas); SetDParam(0, ci_to->client_playas);
GetString(name, str, lastof(name)); GetString(name, str, lastof(name));
NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg); NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
} else { } else {
FOR_ALL_CLIENTS(cs) { FOR_ALL_CLIENTS(cs) {
if (cs->index == from_index) { if (cs->index == from_index) {
@ -1132,7 +1132,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
} }
ci = NetworkFindClientInfoFromIndex(from_index); ci = NetworkFindClientInfoFromIndex(from_index);
if (ci != NULL) if (ci != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg); NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
break; break;
} }
} }
@ -1175,7 +1175,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
if (ci != NULL) { if (ci != NULL) {
// Display change // Display change
if (NetworkFindName(client_name)) { if (NetworkFindName(client_name)) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", client_name); NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", client_name);
ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name)); ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name));
NetworkUpdateClientInfo(ci->client_index); NetworkUpdateClientInfo(ci->client_index);
} }
@ -1412,13 +1412,13 @@ static void NetworkAutoCleanCompanies()
if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') { if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') {
/* Shut the company down */ /* Shut the company down */
DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL); DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL);
IConsolePrintF(_icolour_def, "Auto-cleaned company #%d", p->index + 1); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", p->index + 1);
} }
/* Is the compnay empty for autoclean_protected-months, and there is a protection? */ /* Is the compnay empty for autoclean_protected-months, and there is a protection? */
if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') { if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') {
/* Unprotect the company */ /* Unprotect the company */
_network_player_info[p->index].password[0] = '\0'; _network_player_info[p->index].password[0] = '\0';
IConsolePrintF(_icolour_def, "Auto-removed protection from company #%d", p->index+1); IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", p->index+1);
_network_player_info[p->index].months_empty = 0; _network_player_info[p->index].months_empty = 0;
} }
} else { } else {
@ -1527,14 +1527,14 @@ void NetworkServer_Tick(bool send_frame)
if (lag > 3) { if (lag > 3) {
// Client did still not report in after 4 game-day, drop him // Client did still not report in after 4 game-day, drop him
// (that is, the 3 of above, + 1 before any lag is counted) // (that is, the 3 of above, + 1 before any lag is counted)
IConsolePrintF(_icolour_err,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->index); IConsolePrintF(CC_ERROR,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->index);
NetworkCloseClient(cs); NetworkCloseClient(cs);
continue; continue;
} }
// Report once per time we detect the lag // Report once per time we detect the lag
if (cs->lag_test == 0) { if (cs->lag_test == 0) {
IConsolePrintF(_icolour_warn,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->index); IConsolePrintF(CC_WARNING,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->index);
cs->lag_test = 1; cs->lag_test = 1;
} }
} else { } else {
@ -1543,13 +1543,13 @@ void NetworkServer_Tick(bool send_frame)
} else if (cs->status == STATUS_PRE_ACTIVE) { } else if (cs->status == STATUS_PRE_ACTIVE) {
int lag = NetworkCalculateLag(cs); int lag = NetworkCalculateLag(cs);
if (lag > _network_max_join_time) { if (lag > _network_max_join_time) {
IConsolePrintF(_icolour_err,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _network_max_join_time); IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _network_max_join_time);
NetworkCloseClient(cs); NetworkCloseClient(cs);
} }
} else if (cs->status == STATUS_INACTIVE) { } else if (cs->status == STATUS_INACTIVE) {
int lag = NetworkCalculateLag(cs); int lag = NetworkCalculateLag(cs);
if (lag > 4 * DAY_TICKS) { if (lag > 4 * DAY_TICKS) {
IConsolePrintF(_icolour_err,"Client #%d is dropped because it took longer than %d ticks to start the joining process", cs->index, 4 * DAY_TICKS); IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks to start the joining process", cs->index, 4 * DAY_TICKS);
NetworkCloseClient(cs); NetworkCloseClient(cs);
} }
} }

View File

@ -1992,7 +1992,7 @@ bool IConsoleSetPatchSetting(const char *name, int32 value)
void *ptr; void *ptr;
if (sd == NULL) { if (sd == NULL) {
IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name); IConsolePrintF(CC_WARNING, "'%s' is an unknown patch setting.", name);
return true; return true;
} }
@ -2011,7 +2011,7 @@ void IConsoleGetPatchSetting(const char *name)
const void *ptr; const void *ptr;
if (sd == NULL) { if (sd == NULL) {
IConsolePrintF(_icolour_warn, "'%s' is an unknown patch setting.", name); IConsolePrintF(CC_WARNING, "'%s' is an unknown patch setting.", name);
return; return;
} }
@ -2023,13 +2023,13 @@ void IConsoleGetPatchSetting(const char *name)
snprintf(value, sizeof(value), "%d", (int32)ReadValue(ptr, sd->save.conv)); snprintf(value, sizeof(value), "%d", (int32)ReadValue(ptr, sd->save.conv));
} }
IConsolePrintF(_icolour_warn, "Current value for '%s' is: '%s' (min: %s%d, max: %d)", IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %d)",
name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max); name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max);
} }
void IConsoleListPatches() void IConsoleListPatches()
{ {
IConsolePrintF(_icolour_warn, "All patches with their current value:"); IConsolePrintF(CC_WARNING, "All patches with their current value:");
for (const SettingDesc *sd = _patch_settings; sd->save.cmd != SL_END; sd++) { for (const SettingDesc *sd = _patch_settings; sd->save.cmd != SL_END; sd++) {
char value[80]; char value[80];
@ -2040,10 +2040,10 @@ void IConsoleListPatches()
} else { } else {
snprintf(value, lengthof(value), "%d", (uint32)ReadValue(ptr, sd->save.conv)); snprintf(value, lengthof(value), "%d", (uint32)ReadValue(ptr, sd->save.conv));
} }
IConsolePrintF(_icolour_def, "%s = %s", sd->desc.name, value); IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value);
} }
IConsolePrintF(_icolour_warn, "Use 'patch' command to change a value"); IConsolePrintF(CC_WARNING, "Use 'patch' command to change a value");
} }
/** Save and load handler for patches/settings /** Save and load handler for patches/settings