Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -39,6 +39,7 @@
#include "engine_base.h"
#include "game/game.hpp"
#include "table/strings.h"
#include <time.h>
#include "safeguards.h"
@@ -86,8 +87,6 @@ static ConsoleFileList _console_file_list; ///< File storage cache for the conso
* command hooks
****************/
#ifdef ENABLE_NETWORK
/**
* Check network availability and inform in console about failure of detection.
* @return Network availability.
@@ -159,10 +158,6 @@ DEF_CONSOLE_HOOK(ConHookNoNetwork)
return CHR_ALLOW;
}
#else
# define ConHookNoNetwork NULL
#endif /* ENABLE_NETWORK */
DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
{
if (_settings_client.gui.newgrf_developer_tools) {
@@ -170,11 +165,7 @@ DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
if (echo) IConsoleError("This command is only available in game and editor.");
return CHR_DISALLOW;
}
#ifdef ENABLE_NETWORK
return ConHookNoNetwork(echo);
#else
return CHR_ALLOW;
#endif
}
return CHR_HIDE;
}
@@ -258,7 +249,7 @@ DEF_CONSOLE_CMD(ConResetTile)
* Scroll to a tile on the map.
* param x tile number or tile x coordinate.
* param y optional y coordinate.
* @note When only one argument is given it is intepreted as the tile number.
* @note When only one argument is given it is interpreted as the tile number.
* When two arguments are given, they are interpreted as the tile's x
* and y coordinates.
* @return True when either console help was shown or a proper amount of parameters given.
@@ -359,7 +350,7 @@ DEF_CONSOLE_CMD(ConLoad)
const char *file = argv[1];
_console_file_list.ValidateFileList();
const FiosItem *item = _console_file_list.FindItem(file);
if (item != NULL) {
if (item != nullptr) {
if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
_switch_mode = SM_LOAD_GAME;
_file_to_saveload.SetMode(item->type);
@@ -388,7 +379,7 @@ DEF_CONSOLE_CMD(ConRemove)
const char *file = argv[1];
_console_file_list.ValidateFileList();
const FiosItem *item = _console_file_list.FindItem(file);
if (item != NULL) {
if (item != nullptr) {
if (!FiosDelete(item->name)) {
IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
}
@@ -430,7 +421,7 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
const char *file = argv[1];
_console_file_list.ValidateFileList(true);
const FiosItem *item = _console_file_list.FindItem(file);
if (item != NULL) {
if (item != nullptr) {
switch (item->type) {
case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
FiosBrowseTo(item);
@@ -458,7 +449,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
_console_file_list.ValidateFileList(true);
_console_file_list.InvalidateFileList();
FiosGetDescText(&path, NULL);
FiosGetDescText(&path, nullptr);
IConsolePrint(CC_DEFAULT, path);
return true;
}
@@ -479,13 +470,12 @@ DEF_CONSOLE_CMD(ConClearBuffer)
/**********************************
* Network Core Console Commands
**********************************/
#ifdef ENABLE_NETWORK
static bool ConKickOrBan(const char *argv, bool ban)
{
uint n;
if (strchr(argv, '.') == NULL && strchr(argv, ':') == NULL) { // banning with ID
if (strchr(argv, '.') == nullptr && strchr(argv, ':') == nullptr) { // banning with ID
ClientID client_id = (ClientID)atoi(argv);
/* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
@@ -498,7 +488,7 @@ static bool ConKickOrBan(const char *argv, bool ban)
}
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
if (ci == NULL) {
if (ci == nullptr) {
IConsoleError("Invalid client");
return true;
}
@@ -563,21 +553,20 @@ DEF_CONSOLE_CMD(ConUnBan)
/* Try by IP. */
uint index;
for (index = 0; index < _network_ban_list.Length(); index++) {
if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
for (index = 0; index < _network_ban_list.size(); index++) {
if (_network_ban_list[index] == argv[1]) break;
}
/* Try by index. */
if (index >= _network_ban_list.Length()) {
if (index >= _network_ban_list.size()) {
index = atoi(argv[1]) - 1U; // let it wrap
}
if (index < _network_ban_list.Length()) {
if (index < _network_ban_list.size()) {
char msg[64];
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index].c_str());
IConsolePrint(CC_DEFAULT, msg);
free(_network_ban_list[index]);
_network_ban_list.Erase(_network_ban_list.Get(index));
_network_ban_list.erase(_network_ban_list.begin() + index);
} else {
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
IConsolePrint(CC_DEFAULT, "For a list of banned IP's, see the command 'banlist'");
@@ -596,8 +585,8 @@ DEF_CONSOLE_CMD(ConBanList)
IConsolePrint(CC_DEFAULT, "Banlist: ");
uint i = 1;
for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++, i++) {
IConsolePrintF(CC_DEFAULT, " %d) %s", i, *iter);
for (const auto &entry : _network_ban_list) {
IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry.c_str());
}
return true;
@@ -700,7 +689,7 @@ DEF_CONSOLE_CMD(ConClientNickChange)
return true;
}
if (NetworkClientInfo::GetByClientID(client_id) == NULL) {
if (NetworkClientInfo::GetByClientID(client_id) == nullptr) {
IConsoleError("Invalid client");
return true;
}
@@ -771,7 +760,7 @@ DEF_CONSOLE_CMD(ConMoveClient)
CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
/* check the client exists */
if (ci == NULL) {
if (ci == nullptr) {
IConsoleError("Invalid client-id, check the command 'clients' for valid client-id's.");
return true;
}
@@ -870,8 +859,7 @@ DEF_CONSOLE_CMD(ConNetworkReconnect)
default:
/* From a user pov 0 is a new company, internally it's different and all
* companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
playas--;
if (playas < COMPANY_FIRST || playas >= MAX_COMPANIES) return false;
if (playas < COMPANY_FIRST + 1 || playas > MAX_COMPANIES + 1) return false;
break;
}
@@ -899,8 +887,8 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
if (argc < 2) return false;
if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
const char *port = NULL;
const char *company = NULL;
const char *port = nullptr;
const char *company = nullptr;
char *ip = argv[1];
/* Default settings: default port and new company */
uint16 rport = NETWORK_DEFAULT_PORT;
@@ -909,7 +897,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
ParseConnectionString(&company, &port, ip);
IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
if (company != NULL) {
if (company != nullptr) {
join_as = (CompanyID)atoi(company);
IConsolePrintF(CC_DEFAULT, " company-no: %d", join_as);
@@ -920,7 +908,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
join_as--;
}
}
if (port != NULL) {
if (port != nullptr) {
rport = atoi(port);
IConsolePrintF(CC_DEFAULT, " port: %s", port);
}
@@ -930,8 +918,6 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
return true;
}
#endif /* ENABLE_NETWORK */
/*********************************
* script file console commands
*********************************/
@@ -947,7 +933,7 @@ DEF_CONSOLE_CMD(ConExec)
FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
if (script_file == NULL) {
if (script_file == nullptr) {
if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
return true;
}
@@ -955,7 +941,7 @@ DEF_CONSOLE_CMD(ConExec)
_script_running = true;
char cmdline[ICON_CMDLN_SIZE];
while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != NULL) {
while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != nullptr) {
/* Remove newline characters from the executing script */
for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
if (*cmdptr == '\n' || *cmdptr == '\r') {
@@ -1006,7 +992,7 @@ DEF_CONSOLE_CMD(ConScript)
IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
_iconsole_output_file = fopen(argv[1], "ab");
if (_iconsole_output_file == NULL) IConsoleError("could not open file");
if (_iconsole_output_file == nullptr) IConsoleError("could not open file");
}
return true;
@@ -1045,7 +1031,7 @@ DEF_CONSOLE_CMD(ConNewGame)
return true;
}
StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], NULL, 10) : GENERATE_NEW_SEED);
StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], nullptr, 10) : GENERATE_NEW_SEED);
return true;
}
@@ -1297,7 +1283,7 @@ DEF_CONSOLE_CMD(ConRescanNewGRF)
return true;
}
ScanNewGRFFiles(NULL);
ScanNewGRFFiles(nullptr);
return true;
}
@@ -1317,13 +1303,27 @@ DEF_CONSOLE_CMD(ConGetSeed)
DEF_CONSOLE_CMD(ConGetDate)
{
if (argc == 0) {
IConsoleHelp("Returns the current date (day-month-year) of the game. Usage: 'getdate'");
IConsoleHelp("Returns the current date (year-month-day) of the game. Usage: 'getdate'");
return true;
}
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
IConsolePrintF(CC_DEFAULT, "Date: %04d-%02d-%02d", ymd.year, ymd.month + 1, ymd.day);
return true;
}
DEF_CONSOLE_CMD(ConGetSysDate)
{
if (argc == 0) {
IConsoleHelp("Returns the current date (year-month-day) of your system. Usage: 'getsysdate'");
return true;
}
time_t t;
time(&t);
auto timeinfo = localtime(&t);
IConsolePrintF(CC_DEFAULT, "System Date: %04d-%02d-%02d %02d:%02d:%02d", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
return true;
}
@@ -1340,7 +1340,7 @@ DEF_CONSOLE_CMD(ConAlias)
if (argc < 3) return false;
alias = IConsoleAliasGet(argv[1]);
if (alias == NULL) {
if (alias == nullptr) {
IConsoleAliasRegister(argv[1], argv[2]);
} else {
free(alias->cmdline);
@@ -1362,7 +1362,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
if (argc > 3) return false;
ScreenshotType type = SC_VIEWPORT;
const char *name = NULL;
const char *name = nullptr;
if (argc > 1) {
if (strcmp(argv[1], "big") == 0) {
@@ -1400,7 +1400,7 @@ DEF_CONSOLE_CMD(ConInfoCmd)
if (argc < 2) return false;
const IConsoleCmd *cmd = IConsoleCmdGet(argv[1]);
if (cmd == NULL) {
if (cmd == nullptr) {
IConsoleError("the given command was not found");
return true;
}
@@ -1408,7 +1408,7 @@ DEF_CONSOLE_CMD(ConInfoCmd)
IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
IConsolePrintF(CC_DEFAULT, "command proc: %p", cmd->proc);
if (cmd->hook != NULL) IConsoleWarning("command is hooked");
if (cmd->hook != nullptr) IConsoleWarning("command is hooked");
return true;
}
@@ -1466,16 +1466,16 @@ DEF_CONSOLE_CMD(ConHelp)
RemoveUnderscores(argv[1]);
cmd = IConsoleCmdGet(argv[1]);
if (cmd != NULL) {
cmd->proc(0, NULL);
if (cmd != nullptr) {
cmd->proc(0, nullptr);
return true;
}
alias = IConsoleAliasGet(argv[1]);
if (alias != NULL) {
if (alias != nullptr) {
cmd = IConsoleCmdGet(alias->cmdline);
if (cmd != NULL) {
cmd->proc(0, NULL);
if (cmd != nullptr) {
cmd->proc(0, nullptr);
return true;
}
IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
@@ -1505,9 +1505,9 @@ DEF_CONSOLE_CMD(ConListCommands)
return true;
}
for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) {
if (cmd->hook == NULL || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != nullptr; cmd = cmd->next) {
if (argv[1] == nullptr || strstr(cmd->name, argv[1]) != nullptr) {
if (cmd->hook == nullptr || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
}
}
@@ -1521,8 +1521,8 @@ DEF_CONSOLE_CMD(ConListAliases)
return true;
}
for (const IConsoleAlias *alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
if (argv[1] == NULL || strstr(alias->name, argv[1]) != NULL) {
for (const IConsoleAlias *alias = _iconsole_aliases; alias != nullptr; alias = alias->next) {
if (argv[1] == nullptr || strstr(alias->name, argv[1]) != nullptr) {
IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
}
}
@@ -1547,12 +1547,9 @@ DEF_CONSOLE_CMD(ConCompanies)
const char *password_state = "";
if (c->is_ai) {
password_state = "AI";
}
#ifdef ENABLE_NETWORK
else if (_network_server) {
} else if (_network_server) {
password_state = StrEmpty(_network_company_states[c->index].password) ? "unprotected" : "protected";
}
#endif
char colour[512];
GetString(colour, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(colour));
@@ -1569,8 +1566,6 @@ DEF_CONSOLE_CMD(ConCompanies)
return true;
}
#ifdef ENABLE_NETWORK
DEF_CONSOLE_CMD(ConSay)
{
if (argc == 0) {
@@ -1736,8 +1731,8 @@ static void OutputContentState(const ContentInfo *const ci)
DEF_CONSOLE_CMD(ConContent)
{
static ContentCallback *cb = NULL;
if (cb == NULL) {
static ContentCallback *cb = nullptr;
if (cb == nullptr) {
cb = new ConsoleContentCallback();
_network_content_client.AddCallback(cb);
}
@@ -1795,7 +1790,7 @@ DEF_CONSOLE_CMD(ConContent)
if (strcasecmp(argv[1], "state") == 0) {
IConsolePrintF(CC_WHITE, "id, type, state, name");
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
if (argc > 2 && strcasestr((*iter)->name, argv[2]) == NULL) continue;
if (argc > 2 && strcasestr((*iter)->name, argv[2]) == nullptr) continue;
OutputContentState(*iter);
}
return true;
@@ -1812,7 +1807,6 @@ DEF_CONSOLE_CMD(ConContent)
return false;
}
#endif /* defined(WITH_ZLIB) */
#endif /* ENABLE_NETWORK */
DEF_CONSOLE_CMD(ConSetting)
{
@@ -1861,7 +1855,7 @@ DEF_CONSOLE_CMD(ConListSettings)
if (argc > 2) return false;
IConsoleListSettings((argc == 2) ? argv[1] : NULL);
IConsoleListSettings((argc == 2) ? argv[1] : nullptr);
return true;
}
@@ -1946,6 +1940,7 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("restart", ConRestart);
IConsoleCmdRegister("getseed", ConGetSeed);
IConsoleCmdRegister("getdate", ConGetDate);
IConsoleCmdRegister("getsysdate", ConGetSysDate);
IConsoleCmdRegister("quit", ConExit);
IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
@@ -1992,7 +1987,7 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("players", "companies");
/* networking functions */
#ifdef ENABLE_NETWORK
/* Content downloading is only available with ZLIB */
#if defined(WITH_ZLIB)
IConsoleCmdRegister("content", ConContent);
@@ -2050,7 +2045,6 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("restart_game_year", "setting restart_game_year %+");
IConsoleAliasRegister("min_players", "setting min_active_clients %+");
IConsoleAliasRegister("reload_cfg", "setting reload_cfg %+");
#endif /* ENABLE_NETWORK */
/* debugging stuff */
#ifdef _DEBUG