Changeset - r25663:71ee4e3ec0e8
[Not reviewed]
master
0 4 0
rubidium42 - 3 years ago 2021-06-12 19:07:04
rubidium@openttd.org
Change: unify the style of console error messages and convert to fmt

Always start with a capital, do not add "ERROR: " in front of it.
4 files changed with 66 insertions and 70 deletions:
0 comments (0 inline, 0 general)
src/console.cpp
Show inline comments
 
@@ -226,13 +226,13 @@ static std::string RemoveUnderscores(std
 
 * @param name name of the alias that will be used
 
 * @param cmd name of the command that 'name' will be alias of
 
 */
 
/* static */ void IConsole::AliasRegister(const std::string &name, const std::string &cmd)
 
{
 
	auto result = IConsole::Aliases().try_emplace(RemoveUnderscores(name), name, cmd);
 
	if (!result.second) IConsoleError("an alias with this name already exists; insertion aborted");
 
	if (!result.second) IConsolePrint(CC_ERROR, "An alias with the name '{}' already exists.", name);
 
}
 

	
 
/**
 
 * Find the alias pointed to by its string
 
 * @param name alias to be found
 
 * @return return Aliasstruct of the found alias, or nullptr on failure
 
@@ -256,13 +256,13 @@ static void IConsoleAliasExec(const ICon
 
	char  alias_buffer[ICON_MAX_STREAMSIZE] = { '\0' };
 
	char *alias_stream = alias_buffer;
 

	
 
	Debug(console, 6, "Requested command is an alias; parsing...");
 

	
 
	if (recurse_count > ICON_MAX_RECURSE) {
 
		IConsoleError("Too many alias expansions, recursion limit reached. Aborting");
 
		IConsolePrint(CC_ERROR, "Too many alias expansions, recursion limit reached.");
 
		return;
 
	}
 

	
 
	for (const char *cmdptr = alias->cmdline.c_str(); *cmdptr != '\0'; cmdptr++) {
 
		switch (*cmdptr) {
 
			case '\'': // ' will double for ""
 
@@ -302,14 +302,14 @@ static void IConsoleAliasExec(const ICon
 
					}
 

	
 
					default: { // One specific parameter: %A = [param 1] %B = [param 2] ...
 
						int param = *cmdptr - 'A';
 

	
 
						if (param < 0 || param >= tokencount) {
 
							IConsoleError("too many or wrong amount of parameters passed to alias, aborting");
 
							IConsolePrintF(CC_WARNING, "Usage of alias '%s': %s", alias->name.c_str(), alias->cmdline.c_str());
 
							IConsolePrint(CC_ERROR, "Too many or wrong amount of parameters passed to alias.");
 
							IConsolePrint(CC_HELP, "Usage of alias '{}': {}", alias->name, alias->cmdline);
 
							return;
 
						}
 

	
 
						alias_stream = strecpy(alias_stream, "\"", lastof(alias_buffer));
 
						alias_stream = strecpy(alias_stream, tokens[param], lastof(alias_buffer));
 
						alias_stream = strecpy(alias_stream, "\"", lastof(alias_buffer));
 
@@ -322,13 +322,13 @@ static void IConsoleAliasExec(const ICon
 
				*alias_stream++ = *cmdptr;
 
				*alias_stream = '\0';
 
				break;
 
		}
 

	
 
		if (alias_stream >= lastof(alias_buffer) - 1) {
 
			IConsoleError("Requested alias execution would overflow execution buffer");
 
			IConsolePrint(CC_ERROR, "Requested alias execution would overflow execution buffer.");
 
			return;
 
		}
 
	}
 

	
 
	IConsoleCmdExec(alias_buffer, recurse_count);
 
}
 
@@ -348,14 +348,13 @@ void IConsoleCmdExec(const char *cmdstr,
 
	bool foundtoken = false;
 

	
 
	if (cmdstr[0] == '#') return; // comments
 

	
 
	for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) {
 
		if (!IsValidChar(*cmdptr, CS_ALPHANUMERAL)) {
 
			IConsoleError("command contains malformed characters, aborting");
 
			IConsolePrintF(CC_ERROR, "ERROR: command was: '%s'", cmdstr);
 
			IConsolePrint(CC_ERROR, "Command '{}' contains malformed characters.", cmdstr);
 
			return;
 
		}
 
	}
 

	
 
	Debug(console, 4, "Executing cmdline: '{}'", cmdstr);
 

	
 
@@ -364,13 +363,13 @@ void IConsoleCmdExec(const char *cmdstr,
 

	
 
	/* 1. Split up commandline into tokens, separated by spaces, commands
 
	 * enclosed in "" are taken as one token. We can only go as far as the amount
 
	 * of characters in our stream or the max amount of tokens we can handle */
 
	for (cmdptr = cmdstr, t_index = 0, tstream_i = 0; *cmdptr != '\0'; cmdptr++) {
 
		if (tstream_i >= lengthof(tokenstream)) {
 
			IConsoleError("command line too long");
 
			IConsolePrint(CC_ERROR, "Command line too long.");
 
			return;
 
		}
 

	
 
		switch (*cmdptr) {
 
		case ' ': // Token separator
 
			if (!foundtoken) break;
 
@@ -385,13 +384,13 @@ void IConsoleCmdExec(const char *cmdstr,
 
			tstream_i++;
 
			break;
 
		case '"': // Tokens enclosed in "" are one token
 
			longtoken = !longtoken;
 
			if (!foundtoken) {
 
				if (t_index >= lengthof(tokens)) {
 
					IConsoleError("command line too long");
 
					IConsolePrint(CC_ERROR, "Command line too long.");
 
					return;
 
				}
 
				tokens[t_index++] = &tokenstream[tstream_i];
 
				foundtoken = true;
 
			}
 
			break;
 
@@ -403,13 +402,13 @@ void IConsoleCmdExec(const char *cmdstr,
 
			FALLTHROUGH;
 
		default: // Normal character
 
			tokenstream[tstream_i++] = *cmdptr;
 

	
 
			if (!foundtoken) {
 
				if (t_index >= lengthof(tokens)) {
 
					IConsoleError("command line too long");
 
					IConsolePrint(CC_ERROR, "Command line too long.");
 
					return;
 
				}
 
				tokens[t_index++] = &tokenstream[tstream_i - 1];
 
				foundtoken = true;
 
			}
 
			break;
 
@@ -444,8 +443,8 @@ void IConsoleCmdExec(const char *cmdstr,
 
	IConsoleAlias *alias = IConsole::AliasGet(tokens[0]);
 
	if (alias != nullptr) {
 
		IConsoleAliasExec(alias, t_index, &tokens[1], recurse_count + 1);
 
		return;
 
	}
 

	
 
	IConsoleError("command not found");
 
	IConsolePrint(CC_ERROR, "Command '{}' not found.", tokens[0]);
 
}
src/console_cmds.cpp
Show inline comments
 
@@ -93,13 +93,13 @@ static ConsoleFileList _console_file_lis
 
 * Check network availability and inform in console about failure of detection.
 
 * @return Network availability.
 
 */
 
static inline bool NetworkAvailable(bool echo)
 
{
 
	if (!_network_available) {
 
		if (echo) IConsoleError("You cannot use this command because there is no network available.");
 
		if (echo) IConsolePrint(CC_ERROR, "You cannot use this command because there is no network available.");
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
/**
 
@@ -108,13 +108,13 @@ static inline bool NetworkAvailable(bool
 
 */
 
DEF_CONSOLE_HOOK(ConHookServerOnly)
 
{
 
	if (!NetworkAvailable(echo)) return CHR_DISALLOW;
 

	
 
	if (!_network_server) {
 
		if (echo) IConsoleError("This command is only available to a network server.");
 
		if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
/**
 
@@ -123,13 +123,13 @@ DEF_CONSOLE_HOOK(ConHookServerOnly)
 
 */
 
DEF_CONSOLE_HOOK(ConHookClientOnly)
 
{
 
	if (!NetworkAvailable(echo)) return CHR_DISALLOW;
 

	
 
	if (_network_server) {
 
		if (echo) IConsoleError("This command is not available to a network server.");
 
		if (echo) IConsolePrint(CC_ERROR, "This command is not available to a network server.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
/**
 
@@ -138,49 +138,49 @@ DEF_CONSOLE_HOOK(ConHookClientOnly)
 
 */
 
DEF_CONSOLE_HOOK(ConHookNeedNetwork)
 
{
 
	if (!NetworkAvailable(echo)) return CHR_DISALLOW;
 

	
 
	if (!_networking || (!_network_server && !MyClient::IsConnected())) {
 
		if (echo) IConsoleError("Not connected. This command is only available in multiplayer.");
 
		if (echo) IConsolePrint(CC_ERROR, "Not connected. This command is only available in multiplayer.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
/**
 
 * Check whether we are in singleplayer mode.
 
 * @return True when no network is active.
 
 */
 
DEF_CONSOLE_HOOK(ConHookNoNetwork)
 
{
 
	if (_networking) {
 
		if (echo) IConsoleError("This command is forbidden in multiplayer.");
 
		if (echo) IConsolePrint(CC_ERROR, "This command is forbidden in multiplayer.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
/**
 
 * Check if are either in singleplayer or a server.
 
 * @return True iff we are either in singleplayer or a server.
 
 */
 
DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork)
 
{
 
	if (_networking && !_network_server) {
 
		if (echo) IConsoleError("This command is only available to a network server.");
 
		if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server.");
 
		return CHR_DISALLOW;
 
	}
 
	return CHR_ALLOW;
 
}
 

	
 
DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
 
{
 
	if (_settings_client.gui.newgrf_developer_tools) {
 
		if (_game_mode == GM_MENU) {
 
			if (echo) IConsoleError("This command is only available in-game and in the editor.");
 
			if (echo) IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
 
			return CHR_DISALLOW;
 
		}
 
		return ConHookNoNetwork(echo);
 
	}
 
	return CHR_HIDE;
 
}
 
@@ -219,18 +219,18 @@ DEF_CONSOLE_CMD(ConResetEnginePool)
 
	if (argc == 0) {
 
		IConsoleHelp("Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
 
		return true;
 
	}
 

	
 
	if (_game_mode == GM_MENU) {
 
		IConsoleError("This command is only available in-game and in the editor.");
 
		IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
 
		return true;
 
	}
 

	
 
	if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) {
 
		IConsoleError("This can only be done when there are no vehicles in the game.");
 
		IConsolePrint(CC_ERROR, "This can only be done when there are no vehicles in the game.");
 
		return true;
 
	}
 

	
 
	return true;
 
}
 

	
 
@@ -369,16 +369,16 @@ DEF_CONSOLE_CMD(ConLoad)
 
		if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
 
			_switch_mode = SM_LOAD_GAME;
 
			_file_to_saveload.SetMode(item->type);
 
			_file_to_saveload.SetName(FiosBrowseTo(item));
 
			_file_to_saveload.SetTitle(item->title);
 
		} else {
 
			IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
 
			IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
 
		}
 
	} else {
 
		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
 
		IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
 
	}
 

	
 
	return true;
 
}
 

	
 

	
 
@@ -393,16 +393,16 @@ DEF_CONSOLE_CMD(ConRemove)
 

	
 
	const char *file = argv[1];
 
	_console_file_list.ValidateFileList();
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	if (item != nullptr) {
 
		if (!FiosDelete(item->name)) {
 
			IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
 
			IConsolePrint(CC_ERROR, "Failed to delete '{}'.", file);
 
		}
 
	} else {
 
		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
 
		IConsolePrint(CC_ERROR, "'{}' could not be found.", file);
 
	}
 

	
 
	_console_file_list.InvalidateFileList();
 
	return true;
 
}
 

	
 
@@ -438,16 +438,16 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	if (item != nullptr) {
 
		switch (item->type) {
 
			case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
 
				FiosBrowseTo(item);
 
				break;
 
			default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
 
			default: IConsolePrint(CC_ERROR, "{}: Not a directory.", file);
 
		}
 
	} else {
 
		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
 
		IConsolePrint(CC_ERROR, "{}: No such file or directory.", file);
 
	}
 

	
 
	_console_file_list.InvalidateFileList();
 
	return true;
 
}
 

	
 
@@ -495,19 +495,19 @@ static bool ConKickOrBan(const char *arg
 

	
 
		/* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
 
		 * kicking frees closes and subsequently free the connection related instances, which we
 
		 * would be reading from and writing to after returning. So we would read or write data
 
		 * from freed memory up till the segfault triggers. */
 
		if (client_id == CLIENT_ID_SERVER || client_id == _redirect_console_to_client) {
 
			IConsolePrintF(CC_ERROR, "ERROR: You can not %s yourself!", ban ? "ban" : "kick");
 
			IConsolePrint(CC_ERROR, "You can not {} yourself!", ban ? "ban" : "kick");
 
			return true;
 
		}
 

	
 
		NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
		if (ci == nullptr) {
 
			IConsoleError("Invalid client");
 
			IConsolePrint(CC_ERROR, "Invalid client ID.");
 
			return true;
 
		}
 

	
 
		if (!ban) {
 
			/* Kick only this client, not all clients with that IP */
 
			NetworkServerKickClient(client_id, reason);
 
@@ -518,15 +518,15 @@ static bool ConKickOrBan(const char *arg
 
		n = NetworkServerKickOrBanIP(client_id, ban, reason);
 
	} else {
 
		n = NetworkServerKickOrBanIP(argv, ban, reason);
 
	}
 

	
 
	if (n == 0) {
 
		IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found");
 
		IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist." : "Client not found.");
 
	} else {
 
		IConsolePrintF(CC_DEFAULT, "%sed %u client(s)", ban ? "Bann" : "Kick", n);
 
		IConsolePrintF(CC_DEFAULT, "%sed %u client(s).", ban ? "Bann" : "Kick", n);
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConKick)
 
@@ -542,13 +542,13 @@ DEF_CONSOLE_CMD(ConKick)
 
	/* No reason supplied for kicking */
 
	if (argc == 2) return ConKickOrBan(argv[1], false, {});
 

	
 
	/* Reason for kicking supplied */
 
	size_t kick_message_length = strlen(argv[2]);
 
	if (kick_message_length >= 255) {
 
		IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE " characters.", kick_message_length);
 
		IConsolePrint(CC_ERROR, "Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
 
		return false;
 
	} else {
 
		return ConKickOrBan(argv[1], false, argv[2]);
 
	}
 
}
 

	
 
@@ -566,13 +566,13 @@ DEF_CONSOLE_CMD(ConBan)
 
	/* No reason supplied for kicking */
 
	if (argc == 2) return ConKickOrBan(argv[1], true, {});
 

	
 
	/* Reason for kicking supplied */
 
	size_t kick_message_length = strlen(argv[2]);
 
	if (kick_message_length >= 255) {
 
		IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE " characters.", kick_message_length);
 
		IConsolePrint(CC_ERROR, "Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
 
		return false;
 
	} else {
 
		return ConKickOrBan(argv[1], true, argv[2]);
 
	}
 
}
 

	
 
@@ -633,13 +633,13 @@ DEF_CONSOLE_CMD(ConPauseGame)
 
	if (argc == 0) {
 
		IConsoleHelp("Pause a network game. Usage: 'pause'");
 
		return true;
 
	}
 

	
 
	if (_game_mode == GM_MENU) {
 
		IConsoleError("This command is only available in-game and in the editor.");
 
		IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
 
		return true;
 
	}
 

	
 
	if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
 
		DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
 
		if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused.");
 
@@ -655,13 +655,13 @@ DEF_CONSOLE_CMD(ConUnpauseGame)
 
	if (argc == 0) {
 
		IConsoleHelp("Unpause a network game. Usage: 'unpause'");
 
		return true;
 
	}
 

	
 
	if (_game_mode == GM_MENU) {
 
		IConsoleError("This command is only available in-game and in the editor.");
 
		IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
 
		return true;
 
	}
 

	
 
	if ((_pause_mode & PM_PAUSED_NORMAL) != PM_UNPAUSED) {
 
		DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
 
		if (!_networking) IConsolePrint(CC_DEFAULT, "Game unpaused.");
 
@@ -728,30 +728,30 @@ DEF_CONSOLE_CMD(ConClientNickChange)
 
		return true;
 
	}
 

	
 
	ClientID client_id = (ClientID)atoi(argv[1]);
 

	
 
	if (client_id == CLIENT_ID_SERVER) {
 
		IConsoleError("Please use the command 'name' to change your own name!");
 
		IConsolePrint(CC_ERROR, "Please use the command 'name' to change your own name!");
 
		return true;
 
	}
 

	
 
	if (NetworkClientInfo::GetByClientID(client_id) == nullptr) {
 
		IConsoleError("Invalid client");
 
		IConsolePrint(CC_ERROR, "Invalid client ID.");
 
		return true;
 
	}
 

	
 
	std::string client_name(argv[2]);
 
	StrTrimInPlace(client_name);
 
	if (!NetworkIsValidClientName(client_name)) {
 
		IConsoleError("Cannot give a client an empty name");
 
		IConsolePrint(CC_ERROR, "Cannot give a client an empty name.");
 
		return true;
 
	}
 

	
 
	if (!NetworkServerChangeClientName(client_id, client_name)) {
 
		IConsoleError("Cannot give a client a duplicate name");
 
		IConsolePrint(CC_ERROR, "Cannot give a client a duplicate name.");
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConJoinCompany)
 
@@ -763,34 +763,34 @@ DEF_CONSOLE_CMD(ConJoinCompany)
 
	}
 

	
 
	CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
 

	
 
	/* Check we have a valid company id! */
 
	if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
 
		IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
 
		IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
 
		return true;
 
	}
 

	
 
	if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
 
		IConsoleError("You are already there!");
 
		IConsolePrint(CC_ERROR, "You are already there!");
 
		return true;
 
	}
 

	
 
	if (company_id == COMPANY_SPECTATOR && NetworkMaxSpectatorsReached()) {
 
		IConsoleError("Cannot join spectators, maximum number of spectators reached.");
 
		IConsolePrint(CC_ERROR, "Cannot join spectators, maximum number of spectators reached.");
 
		return true;
 
	}
 

	
 
	if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
 
		IConsoleError("Cannot join AI company.");
 
		IConsolePrint(CC_ERROR, "Cannot join AI company.");
 
		return true;
 
	}
 

	
 
	/* Check if the company requires a password */
 
	if (NetworkCompanyIsPassworded(company_id) && argc < 3) {
 
		IConsolePrintF(CC_ERROR, "Company %d requires a password to join.", company_id + 1);
 
		IConsolePrint(CC_ERROR, "Company {} requires a password to join.", company_id + 1);
 
		return true;
 
	}
 

	
 
	/* non-dedicated server may just do the move! */
 
	if (_network_server) {
 
		NetworkServerDoMove(CLIENT_ID_SERVER, company_id);
 
@@ -811,33 +811,33 @@ DEF_CONSOLE_CMD(ConMoveClient)
 

	
 
	const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)atoi(argv[1]));
 
	CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
 

	
 
	/* check the client exists */
 
	if (ci == nullptr) {
 
		IConsoleError("Invalid client-id, check the command 'clients' for valid client-id's.");
 
		IConsolePrint(CC_ERROR, "Invalid client-id, check the command 'clients' for valid client-id's.");
 
		return true;
 
	}
 

	
 
	if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
 
		IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
 
		IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
 
		return true;
 
	}
 

	
 
	if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
 
		IConsoleError("You cannot move clients to AI companies.");
 
		IConsolePrint(CC_ERROR, "You cannot move clients to AI companies.");
 
		return true;
 
	}
 

	
 
	if (ci->client_id == CLIENT_ID_SERVER && _network_dedicated) {
 
		IConsoleError("You cannot move the server!");
 
		IConsolePrint(CC_ERROR, "You cannot move the server!");
 
		return true;
 
	}
 

	
 
	if (ci->client_playas == company_id) {
 
		IConsoleError("You cannot move someone to where they already are!");
 
		IConsolePrint(CC_ERROR, "You cannot move someone to where they already are!");
 
		return true;
 
	}
 

	
 
	/* we are the server, so force the update */
 
	NetworkServerDoMove(ci->client_id, company_id);
 

	
 
@@ -855,28 +855,28 @@ DEF_CONSOLE_CMD(ConResetCompany)
 
	if (argc != 2) return false;
 

	
 
	CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
 

	
 
	/* Check valid range */
 
	if (!Company::IsValidID(index)) {
 
		IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
 
		IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
 
		return true;
 
	}
 

	
 
	if (!Company::IsHumanID(index)) {
 
		IConsoleError("Company is owned by an AI.");
 
		IConsolePrint(CC_ERROR, "Company is owned by an AI.");
 
		return true;
 
	}
 

	
 
	if (NetworkCompanyHasClients(index)) {
 
		IConsoleError("Cannot remove company: a client is connected to that company.");
 
		IConsolePrint(CC_ERROR, "Cannot remove company: a client is connected to that company.");
 
		return false;
 
	}
 
	const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
 
	if (ci->client_playas == index) {
 
		IConsoleError("Cannot remove company: the server is connected to that company.");
 
		IConsolePrint(CC_ERROR, "Cannot remove company: the server is connected to that company.");
 
		return true;
 
	}
 

	
 
	/* It is safe to remove this company */
 
	DoCommandP(0, CCA_DELETE | index << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
 
	IConsolePrint(CC_DEFAULT, "Company deleted.");
 
@@ -954,19 +954,19 @@ DEF_CONSOLE_CMD(ConExec)
 

	
 
	if (argc < 2) return false;
 

	
 
	FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
 

	
 
	if (script_file == nullptr) {
 
		if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
 
		if (argc == 2 || atoi(argv[2]) != 0) IConsolePrint(CC_ERROR, "Script file '{}' not found.", argv[1]);
 
		return true;
 
	}
 

	
 
	if (_script_current_depth == 11) {
 
		FioFCloseFile(script_file);
 
		IConsoleError("Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
 
		IConsolePrint(CC_ERROR, "Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
 
		return true;
 
	}
 

	
 
	_script_current_depth++;
 
	uint script_depth = _script_current_depth;
 

	
 
@@ -985,13 +985,13 @@ DEF_CONSOLE_CMD(ConExec)
 

	
 
		/* The 'return' command was executed. */
 
		if (_script_current_depth == script_depth - 1) break;
 
	}
 

	
 
	if (ferror(script_file)) {
 
		IConsoleError("Encountered error while trying to read from script file");
 
		IConsolePrint(CC_ERROR, "Encountered error while trying to read from script file '{}'.", argv[1]);
 
	}
 

	
 
	if (_script_current_depth == script_depth) _script_current_depth--;
 
	FioFCloseFile(script_file);
 
	return true;
 
}
 
@@ -1024,13 +1024,13 @@ DEF_CONSOLE_CMD(ConScript)
 

	
 
	if (!CloseConsoleLogIfActive()) {
 
		if (argc < 2) return false;
 

	
 
		IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
 
		_iconsole_output_file = fopen(argv[1], "ab");
 
		if (_iconsole_output_file == nullptr) IConsoleError("could not open file");
 
		if (_iconsole_output_file == nullptr) IConsolePrint(CC_ERROR, "Could not open file '{}'.", argv[1]);
 
	}
 

	
 
	return true;
 
}
 

	
 

	
 
@@ -1463,23 +1463,23 @@ DEF_CONSOLE_CMD(ConScreenShot)
 
			arg_index += 1;
 
		}
 
	}
 

	
 
	if (argc > arg_index && strcmp(argv[arg_index], "no_con") == 0) {
 
		if (type != SC_VIEWPORT) {
 
			IConsoleError("'no_con' can only be used in combination with 'viewport'");
 
			IConsolePrint(CC_ERROR, "'no_con' can only be used in combination with 'viewport'.");
 
			return true;
 
		}
 
		IConsoleClose();
 
		arg_index += 1;
 
	}
 

	
 
	if (argc > arg_index + 2 && strcmp(argv[arg_index], "size") == 0) {
 
		/* size <width> <height> */
 
		if (type != SC_DEFAULTZOOM && type != SC_ZOOMEDIN) {
 
			IConsoleError("'size' can only be used in combination with 'normal' or 'big'");
 
			IConsolePrint(CC_ERROR, "'size' can only be used in combination with 'normal' or 'big'.");
 
			return true;
 
		}
 
		GetArgumentInteger(&width, argv[arg_index + 1]);
 
		GetArgumentInteger(&height, argv[arg_index + 2]);
 
		arg_index += 3;
 
	}
 
@@ -1507,13 +1507,13 @@ DEF_CONSOLE_CMD(ConInfoCmd)
 
	}
 

	
 
	if (argc < 2) return false;
 

	
 
	const IConsoleCmd *cmd = IConsole::CmdGet(argv[1]);
 
	if (cmd == nullptr) {
 
		IConsoleError("the given command was not found");
 
		IConsolePrint(CC_ERROR, "The given command was not found.");
 
		return true;
 
	}
 

	
 
	IConsolePrint(CC_DEFAULT, "Command name: '{}'", cmd->name);
 

	
 
	if (cmd->hook != nullptr) IConsolePrint(CC_DEFAULT, "Command is hooked.");
 
@@ -1586,13 +1586,13 @@ DEF_CONSOLE_CMD(ConHelp)
 
				return true;
 
			}
 
			IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline.c_str());
 
			return true;
 
		}
 

	
 
		IConsoleError("command not found");
 
		IConsolePrint(CC_ERROR, "Command not found");
 
		return true;
 
	}
 

	
 
	IConsolePrint(TC_LIGHT_BLUE, " ---- OpenTTD Console Help ---- ");
 
	IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
 
	IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
 
@@ -1771,13 +1771,13 @@ DEF_CONSOLE_CMD(ConCompanyPassword)
 
		errormsg = "You have to specify the ID of a valid human controlled company.";
 
	} else {
 
		return false;
 
	}
 

	
 
	if (!Company::IsValidHumanID(company_id)) {
 
		IConsoleError(errormsg);
 
		IConsolePrint(CC_ERROR, errormsg);
 
		return false;
 
	}
 

	
 
	password = NetworkChangeCompanyPassword(company_id, password);
 

	
 
	if (password.empty()) {
 
@@ -1878,22 +1878,22 @@ DEF_CONSOLE_CMD(ConContent)
 
			/* The intention of this function was that you could download
 
			 * everything after a filter was applied; but this never really
 
			 * took off. Instead, a select few people used this functionality
 
			 * to download every available package on BaNaNaS. This is not in
 
			 * the spirit of this service. Additionally, these few people were
 
			 * good for 70% of the consumed bandwidth of BaNaNaS. */
 
			IConsoleError("'select all' is no longer supported since 1.11");
 
			IConsolePrint(CC_ERROR, "'select all' is no longer supported since 1.11.");
 
		} else {
 
			_network_content_client.Select((ContentID)atoi(argv[2]));
 
		}
 
		return true;
 
	}
 

	
 
	if (strcasecmp(argv[1], "unselect") == 0) {
 
		if (argc <= 2) {
 
			IConsoleError("You must enter the id.");
 
			IConsolePrint(CC_ERROR, "You must enter the id.");
 
			return false;
 
		}
 
		if (strcasecmp(argv[2], "all") == 0) {
 
			_network_content_client.UnselectAll();
 
		} else {
 
			_network_content_client.Unselect((ContentID)atoi(argv[2]));
 
@@ -2152,13 +2152,13 @@ DEF_CONSOLE_CMD(ConFramerateWindow)
 
	if (argc == 0) {
 
		IConsoleHelp("Open the frame rate window");
 
		return true;
 
	}
 

	
 
	if (_network_dedicated) {
 
		IConsoleError("Can not open frame rate window on a dedicated server");
 
		IConsolePrint(CC_ERROR, "Can not open frame rate window on a dedicated server");
 
		return false;
 
	}
 

	
 
	ShowFramerateWindow();
 
	return true;
 
}
src/error_gui.cpp
Show inline comments
 
@@ -396,16 +396,13 @@ void ShowErrorMessage(StringID summary_m
 
			b += seprintf(b, lastof(buf), " ");
 
			GetString(b, detailed_msg, lastof(buf));
 
		}
 

	
 
		if (textref_stack_size > 0) StopTextRefStackUsage();
 

	
 
		switch (wl) {
 
			case WL_WARNING: IConsolePrint(CC_WARNING, buf); break;
 
			default:         IConsoleError(buf); break;
 
		}
 
		IConsolePrint(wl == WL_WARNING ? CC_WARNING : CC_ERROR, buf);
 
	}
 

	
 
	bool no_timeout = wl == WL_CRITICAL;
 

	
 
	if (_game_mode == GM_BOOTSTRAP) return;
 
	if (_settings_client.gui.errmsg_duration == 0 && !no_timeout) return;
src/settings.cpp
Show inline comments
 
@@ -1947,15 +1947,15 @@ void IConsoleSetSetting(const char *name
 

	
 
		success = SetSettingValue(sd->AsIntSetting(), val, force_newgame);
 
	}
 

	
 
	if (!success) {
 
		if (_network_server) {
 
			IConsoleError("This command/variable is not available during network games.");
 
			IConsolePrint(CC_ERROR, "This command/variable is not available during network games.");
 
		} else {
 
			IConsoleError("This command/variable is only available to a network server.");
 
			IConsolePrint(CC_ERROR, "This command/variable is only available to a network server.");
 
		}
 
	}
 
}
 

	
 
void IConsoleSetSetting(const char *name, int value)
 
{
0 comments (0 inline, 0 general)