|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
16 #include "network/core/network_game_info.h"
44 #include "table/strings.h"
45 #include "3rdparty/fmt/chrono.h"
92 #define DEF_CONSOLE_CMD(function) static bool function([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[])
93 #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
107 if (echo)
IConsolePrint(
CC_ERROR,
"You cannot use this command because there is no network available.");
187 if (_game_mode == GM_MENU) {
191 return ConHookNoNetwork(echo);
203 IConsolePrint(
CC_HELP,
"Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'.");
219 IConsolePrint(
CC_HELP,
"Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
223 if (_game_mode == GM_MENU) {
294 if (argv[1][0] ==
'-') {
332 IConsolePrint(
CC_HELP,
"'instant' will immediately move and redraw viewport without smooth scrolling.");
335 if (argc < 2)
return false;
337 uint32_t arg_index = 1;
338 bool instant =
false;
339 if (strcmp(argv[arg_index],
"instant") == 0) {
344 switch (argc - arg_index) {
388 std::string filename = argv[1];
410 IConsolePrint(
CC_HELP,
"Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
411 IConsolePrint(
CC_HELP,
"It does not save the configuration of the current game to the configuration file.");
427 if (argc != 2)
return false;
429 const char *file = argv[1];
432 if (item !=
nullptr) {
449 IConsolePrint(
CC_HELP,
"Load a scenario by name or index. Usage: 'load_scenario <file | number>'.");
453 if (argc != 2)
return false;
455 const char *file = argv[1];
458 if (item !=
nullptr) {
475 IConsolePrint(
CC_HELP,
"Load a heightmap by name or index. Usage: 'load_heightmap <file | number>'.");
479 if (argc != 2)
return false;
481 const char *file = argv[1];
484 if (item !=
nullptr) {
505 if (argc != 2)
return false;
507 const char *file = argv[1];
510 if (item !=
nullptr) {
511 if (unlink(item->name.c_str()) != 0) {
527 IConsolePrint(
CC_HELP,
"List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'.");
579 if (argc != 2)
return false;
581 const char *file = argv[1];
584 if (item !=
nullptr) {
585 switch (item->type) {
586 case FIOS_TYPE_DIR:
case FIOS_TYPE_DRIVE:
case FIOS_TYPE_PARENT:
621 IConsoleClearBuffer();
631 static bool ConKickOrBan(
const char *argv,
bool ban,
const std::string &reason)
635 if (strchr(argv,
'.') ==
nullptr && strchr(argv,
':') ==
nullptr) {
677 IConsolePrint(
CC_HELP,
"Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'.");
682 if (argc != 2 && argc != 3)
return false;
685 if (argc == 2)
return ConKickOrBan(argv[1],
false, {});
688 size_t kick_message_length = strlen(argv[2]);
689 if (kick_message_length >= 255) {
690 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
693 return ConKickOrBan(argv[1],
false, argv[2]);
700 IConsolePrint(
CC_HELP,
"Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'.");
706 if (argc != 2 && argc != 3)
return false;
709 if (argc == 2)
return ConKickOrBan(argv[1],
true, {});
712 size_t kick_message_length = strlen(argv[2]);
713 if (kick_message_length >= 255) {
714 IConsolePrint(
CC_ERROR,
"Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
717 return ConKickOrBan(argv[1],
true, argv[2]);
724 IConsolePrint(
CC_HELP,
"Unban a client from a network game. Usage: 'unban <ip | banlist-index>'.");
729 if (argc != 2)
return false;
739 index = atoi(argv[1]) - 1U;
778 if (_game_mode == GM_MENU) {
800 if (_game_mode == GM_MENU) {
822 IConsolePrint(
CC_HELP,
"Remote control the server from another client. Usage: 'rcon <password> <command>'.");
823 IConsolePrint(
CC_HELP,
"Remember to enclose the command in quotes, otherwise only the first parameter is sent.");
827 if (argc < 3)
return false;
840 IConsolePrint(
CC_HELP,
"List the status of all clients connected to the server. Usage 'status'.");
852 IConsolePrint(
CC_HELP,
"You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'.");
867 IConsolePrint(
CC_HELP,
"Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'.");
884 std::string client_name(argv[2]);
901 IConsolePrint(
CC_HELP,
"Request joining another company. Usage: 'join <company-id> [<password>]'.");
943 IConsolePrint(
CC_HELP,
"Move a client to another company. Usage: 'move <client-id> <company-id>'.");
944 IConsolePrint(
CC_HELP,
"For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators.");
986 IConsolePrint(
CC_HELP,
"Remove an idle company from the game. Usage: 'reset_company <company-id>'.");
987 IConsolePrint(
CC_HELP,
"For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
991 if (argc != 2)
return false;
1011 assert(ci !=
nullptr);
1027 IConsolePrint(
CC_HELP,
"Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'.");
1039 IConsolePrint(
CC_HELP,
"Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'.");
1040 IConsolePrint(
CC_HELP,
"Company 255 is spectator (default, if not specified), 0 means creating new company.");
1052 if (playas < COMPANY_FIRST + 1 || playas >
MAX_COMPANIES + 1)
return false;
1070 IConsolePrint(
CC_HELP,
"Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'.");
1071 IConsolePrint(
CC_HELP,
"IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'.");
1072 IConsolePrint(
CC_HELP,
"Company #255 is spectator all others are a certain company with Company 1 being #1.");
1076 if (argc < 2)
return false;
1092 if (argc < 2)
return false;
1096 if (script_file ==
nullptr) {
1097 if (argc == 2 || atoi(argv[2]) != 0)
IConsolePrint(
CC_ERROR,
"Script file '{}' not found.", argv[1]);
1103 IConsolePrint(
CC_ERROR,
"Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
1111 while (fgets(cmdline,
sizeof(cmdline), script_file) !=
nullptr) {
1113 for (
char *cmdptr = cmdline; *cmdptr !=
'\0'; cmdptr++) {
1114 if (*cmdptr ==
'\n' || *cmdptr ==
'\r') {
1127 if (ferror(script_file)) {
1150 extern bool CloseConsoleLogIfActive();
1151 extern const std::vector<GRFFile *> &GetAllGRFFiles();
1157 extern FILE *_iconsole_output_file;
1160 IConsolePrint(
CC_HELP,
"Start or stop logging console output to a file. Usage: 'script <filename>'.");
1165 if (!CloseConsoleLogIfActive()) {
1166 if (argc < 2)
return false;
1168 _iconsole_output_file = fopen(argv[1],
"ab");
1169 if (_iconsole_output_file ==
nullptr) {
1187 if (argc < 2)
return false;
1195 IConsolePrint(
CC_HELP,
"Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'.");
1199 if (argc < 3)
return false;
1208 IConsolePrint(
CC_HELP,
"The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game.");
1218 if (argc == 0 || argc > 2) {
1220 IConsolePrint(
CC_HELP,
"Restarts a game, using either the current or newgame (default) settings.");
1221 IConsolePrint(
CC_HELP,
" * if you started from a new game, and your current/newgame settings haven't changed, the game will be identical to when you started it.");
1222 IConsolePrint(
CC_HELP,
" * if you started from a savegame / scenario / heightmap, the game might be different, because the current/newgame settings might differ.");
1226 if (argc == 1 || std::string_view(argv[1]) ==
"newgame") {
1263 std::istringstream in(full_string);
1265 while (std::getline(in, line)) {
1270 template <
typename F,
typename ... Args>
1271 bool PrintList(F list_function, Args... args)
1273 std::string output_str;
1274 auto inserter = std::back_inserter(output_str);
1275 list_function(inserter, args...);
1323 if (argc == 0 || argc > 3) {
1325 IConsolePrint(
CC_HELP,
"Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1326 IConsolePrint(
CC_HELP,
"If <settings> is given, it is parsed and the AI settings are set to that.");
1330 if (_game_mode != GM_NORMAL) {
1356 if (c->index != n)
break;
1362 config->
Change(argv[1], -1,
false);
1368 const char *e = strrchr(argv[1],
'.');
1370 size_t name_length = e - argv[1];
1373 int version = atoi(e);
1374 config->
Change(std::string(argv[1], name_length), version,
true);
1397 IConsolePrint(
CC_HELP,
"Reload the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1401 if (_game_mode != GM_NORMAL) {
1435 IConsolePrint(
CC_HELP,
"Stop the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
1439 if (_game_mode != GM_NORMAL) {
1510 IConsolePrint(
CC_ERROR,
"NewGRF scanning is already running. Please wait until completed to run again.");
1520 IConsolePrint(
CC_HELP,
"The seed can be used to reproduce the exact same map as the game started with.");
1531 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
1543 IConsolePrint(
CC_HELP,
"Returns the current date (year-month-day) of your system. Usage: 'getsysdate'.");
1557 IConsolePrint(
CC_HELP,
"Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'.");
1561 if (argc < 3)
return false;
1564 if (alias ==
nullptr) {
1575 IConsolePrint(
CC_HELP,
"Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | heightmap | minimap] [no_con] [size <width> <height>] [<filename>]'.");
1576 IConsolePrint(
CC_HELP,
" 'viewport' (default) makes a screenshot of the current viewport (including menus, windows).");
1580 IConsolePrint(
CC_HELP,
" 'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap.");
1581 IConsolePrint(
CC_HELP,
" 'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel.");
1582 IConsolePrint(
CC_HELP,
" 'no_con' hides the console to create the screenshot (only useful in combination with 'viewport').");
1583 IConsolePrint(
CC_HELP,
" 'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big').");
1584 IConsolePrint(
CC_HELP,
" A filename ending in # will prevent overwriting existing files and will number files counting upwards.");
1588 if (argc > 7)
return false;
1592 uint32_t height = 0;
1594 uint32_t arg_index = 1;
1596 if (argc > arg_index) {
1597 if (strcmp(argv[arg_index],
"viewport") == 0) {
1600 }
else if (strcmp(argv[arg_index],
"normal") == 0) {
1603 }
else if (strcmp(argv[arg_index],
"big") == 0) {
1606 }
else if (strcmp(argv[arg_index],
"giant") == 0) {
1609 }
else if (strcmp(argv[arg_index],
"heightmap") == 0) {
1612 }
else if (strcmp(argv[arg_index],
"minimap") == 0) {
1618 if (argc > arg_index && strcmp(argv[arg_index],
"no_con") == 0) {
1627 if (argc > arg_index + 2 && strcmp(argv[arg_index],
"size") == 0) {
1638 if (argc > arg_index) {
1640 name = argv[arg_index];
1644 if (argc > arg_index) {
1656 IConsolePrint(
CC_HELP,
"Print out debugging information about a command. Usage: 'info_cmd <cmd>'.");
1660 if (argc < 2)
return false;
1663 if (cmd ==
nullptr) {
1678 IConsolePrint(
CC_HELP,
"Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'.");
1679 IConsolePrint(
CC_HELP,
"Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'\"s.");
1683 if (argc > 2)
return false;
1710 IConsolePrint(
CC_HELP,
"Leave the currently joined/running game (only ingame). Usage: 'part'.");
1714 if (_game_mode != GM_NORMAL)
return false;
1727 if (cmd !=
nullptr) {
1728 cmd->
proc(0,
nullptr);
1733 if (alias !=
nullptr) {
1735 if (cmd !=
nullptr) {
1736 cmd->
proc(0,
nullptr);
1747 IConsolePrint(TC_LIGHT_BLUE,
" ---- OpenTTD Console Help ---- ");
1766 for (
auto &it : IConsole::Commands()) {
1768 if (argv[1] ==
nullptr || cmd->
name.find(argv[1]) != std::string::npos) {
1783 for (
auto &it : IConsole::Aliases()) {
1785 if (argv[1] ==
nullptr || alias->
name.find(argv[1]) != std::string::npos) {
1803 std::string company_name =
GetString(STR_COMPANY_NAME);
1805 const char *password_state =
"";
1807 password_state =
"AI";
1813 IConsolePrint(
CC_INFO,
"#:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {}",
1814 c->index + 1, colour, company_name,
1815 c->inaugurated_year, (int64_t)c->money, (int64_t)c->current_loan, (int64_t)
CalculateCompanyValue(c),
1817 c->group_all[
VEH_ROAD].num_vehicle,
1819 c->group_all[
VEH_SHIP].num_vehicle,
1829 IConsolePrint(
CC_HELP,
"Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'.");
1833 if (argc != 2)
return false;
1848 IConsolePrint(
CC_HELP,
"Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'.");
1849 IConsolePrint(
CC_HELP,
"CompanyNo is the company that plays as company <companyno>, 1 through max_companies.");
1853 if (argc != 3)
return false;
1874 IConsolePrint(
CC_HELP,
"Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'.");
1879 if (argc != 3)
return false;
1895 IConsolePrint(
CC_HELP,
"Change the password of a company. Usage: 'company_pw <company-no> \"<password>\".");
1897 IConsolePrint(
CC_HELP,
"Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'.");
1899 IConsolePrint(
CC_HELP,
"Change the password of your company. Usage: 'company_pw \"<password>\"'.");
1907 std::string password;
1908 const char *errormsg;
1913 errormsg =
"You have to own a company to make use of this command.";
1915 company_id = (
CompanyID)(atoi(argv[1]) - 1);
1917 errormsg =
"You have to specify the ID of a valid human controlled company.";
1929 if (password.empty()) {
1939 #if defined(WITH_ZLIB)
1945 static const char *
const inv_lookup[] = {
"",
"base",
"newgrf",
"ai",
"ailib",
"scenario",
"heightmap" };
1946 for (uint i = 1 ; i <
lengthof(inv_lookup); i++) {
1954 void OnConnect(
bool success)
override
1964 void OnDownloadComplete(
ContentID cid)
override
1976 static const char *
const types[] = {
"Base graphics",
"NewGRF",
"AI",
"AI library",
"Scenario",
"Heightmap",
"Base sound",
"Base music",
"Game script",
"GS library" };
1978 static const char *
const states[] = {
"Not selected",
"Selected",
"Dep Selected",
"Installed",
"Unknown" };
1981 IConsolePrint(state_to_colour[ci->
state],
"{}, {}, {}, {}, {:08X}, {}", ci->
id, types[ci->
type - 1], states[ci->
state], ci->
name, ci->
unique_id,
FormatArrayAsHex(ci->
md5sum));
1987 if (cb ==
nullptr) {
1993 IConsolePrint(
CC_HELP,
"Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'.");
1996 IConsolePrint(
CC_HELP,
" select: select a specific item given by its id. If no parameter is given, all selected content will be listed.");
1997 IConsolePrint(
CC_HELP,
" unselect: unselect a specific item given by its id or 'all' to unselect all.");
1998 IConsolePrint(
CC_HELP,
" state: show the download/select state of all downloadable content. Optionally give a filter string.");
2051 if (argc > 2 && strcasestr((*iter)->name.c_str(), argv[2]) ==
nullptr)
continue;
2078 IConsolePrint(
CC_HELP,
" Set <name> to \"\" for the sprite font (size and aa have no effect on sprite font).");
2083 for (argfs =
FS_BEGIN; argfs < FS_END; argfs++) {
2088 if (argc > 1 && argfs == FS_END)
return false;
2092 std::string font = setting->
font;
2093 uint size = setting->
size;
2094 bool aa = setting->
aa;
2100 if (argc > arg_index)
return false;
2105 font = argv[arg_index++];
2109 if (argc > arg_index) {
2118 if (argc > arg_index) {
2122 if (argc > arg_index)
return false;
2125 SetFont(argfs, font, size, aa);
2150 if (argc == 1 || argc > 3)
return false;
2155 IConsoleSetSetting(argv[1], argv[2]);
2164 IConsolePrint(
CC_HELP,
"Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'.");
2169 if (argc == 1 || argc > 3)
return false;
2174 IConsoleSetSetting(argv[1], argv[2],
true);
2187 if (argc > 2)
return false;
2196 IConsolePrint(
CC_HELP,
"Print logged fundamental changes to the game since the start. Usage: 'gamelog'.");
2207 IConsolePrint(
CC_HELP,
"Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD!");
2217 struct SubdirNameMap {
2222 static const SubdirNameMap subdir_name_map[] = {
2240 IConsolePrint(
CC_HELP,
"List all search paths or default directories for various categories.");
2242 std::string cats = subdir_name_map[0].name;
2244 for (
const SubdirNameMap &sdn : subdir_name_map) {
2245 if (!first) cats = cats +
", " + sdn.name;
2252 std::set<std::string> seen_dirs;
2253 for (
const SubdirNameMap &sdn : subdir_name_map) {
2258 std::string path = FioGetDirectory(sp, sdn.subdir);
2260 if (seen_dirs.find(path) != seen_dirs.end())
continue;
2261 seen_dirs.insert(path);
2266 if (!sdn.default_only || exists) {
2268 if (sdn.default_only)
break;
2284 IConsolePrint(
CC_HELP,
"Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
2290 IConsolePrint(
CC_HELP,
" Unselect one or more GRFs from profiling. Use the keyword \"all\" instead of a GRF number to unselect all. Removing an active profiler aborts data collection.");
2292 IConsolePrint(
CC_HELP,
" Begin profiling all selected GRFs. If a number of ticks is provided, profiling stops after that many game ticks. There are 74 ticks in a calendar day.");
2300 const std::vector<GRFFile *> &files = GetAllGRFFiles();
2307 auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2308 bool selected = profiler != _newgrf_profilers.end();
2309 bool active = selected && profiler->active;
2311 const char *statustext = active ?
" (active)" : selected ?
" (selected)" :
"";
2320 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2321 int grfnum = atoi(argv[argnum]);
2322 if (grfnum < 1 || grfnum > (
int)files.size()) {
2326 GRFFile *grf = files[grfnum - 1];
2327 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2331 _newgrf_profilers.emplace_back(grf);
2338 for (
size_t argnum = 2; argnum < argc; ++argnum) {
2340 _newgrf_profilers.clear();
2343 int grfnum = atoi(argv[argnum]);
2344 if (grfnum < 1 || grfnum > (
int)files.size()) {
2348 GRFFile *grf = files[grfnum - 1];
2349 auto pos = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
NewGRFProfiler &pr) { return pr.grffile == grf; });
2350 if (pos != _newgrf_profilers.end()) _newgrf_profilers.erase(pos);
2364 if (!grfids.empty()) grfids +=
", ";
2365 fmt::format_to(std::back_inserter(grfids),
"[{:08X}]",
BSWAP32(pr.
grffile->grfid));
2372 uint64_t ticks = std::max(atoi(argv[2]), 1);
2376 }
else if (_newgrf_profilers.empty()) {
2379 IConsolePrint(
CC_ERROR,
"Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2386 NewGRFProfiler::FinishAll();
2407 static void IConsoleDebugLibRegister()
2442 static void ConDumpRoadTypes()
2451 std::map<uint32_t, const GRFFile *> grfs;
2454 if (rti->
label == 0)
continue;
2457 if (grf !=
nullptr) {
2459 grfs.emplace(grfid, grf);
2463 RoadTypeIsTram(rt) ?
"Tram" :
"Road",
2474 for (
const auto &grf : grfs) {
2479 static void ConDumpRailTypes()
2489 std::map<uint32_t, const GRFFile *> grfs;
2492 if (rti->
label == 0)
continue;
2495 if (grf !=
nullptr) {
2497 grfs.emplace(grfid, grf);
2512 for (
const auto &grf : grfs) {
2517 static void ConDumpCargoTypes()
2532 std::map<uint32_t, const GRFFile *> grfs;
2534 if (!spec->IsValid())
continue;
2536 const GRFFile *grf = spec->grffile;
2537 if (grf !=
nullptr) {
2539 grfs.emplace(grfid, grf);
2541 IConsolePrint(
CC_DEFAULT,
" {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}",
2544 spec->label >> 24, spec->label >> 16, spec->label >> 8, spec->label,
2545 spec->callback_mask,
2547 (spec->classes &
CC_MAIL) != 0 ?
'm' :
'-',
2548 (spec->classes &
CC_EXPRESS) != 0 ?
'x' :
'-',
2550 (spec->classes &
CC_BULK) != 0 ?
'b' :
'-',
2552 (spec->classes &
CC_LIQUID) != 0 ?
'l' :
'-',
2555 (spec->classes &
CC_COVERED) != 0 ?
'c' :
'-',
2556 (spec->classes &
CC_SPECIAL) != 0 ?
'S' :
'-',
2558 GetStringPtr(spec->name)
2561 for (
const auto &grf : grfs) {
2587 ConDumpCargoTypes();
2598 void IConsoleStdLibRegister()
2673 #if defined(WITH_ZLIB)
2730 IConsoleDebugLibRegister();
@ VEH_AIRCRAFT
Aircraft vehicle type.
RoadTypeFlags flags
Bit mask of road type flags.
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
bool show_dirs
Whether to show directories in the file list.
bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
Callbacks for notifying others about incoming data.
static const TextColour CC_INFO
Colour for information lines.
@ ROTSG_GROUND
Required: Main group of ground images.
@ CC_HAZARDOUS
Hazardous cargo (Nuclear Fuel, Explosives, etc.)
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
@ ROADTYPE_END
Used for iterations.
std::string name
Name of the content.
@ CC_COVERED
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
IConsoleCmdProc * proc
process executed when command is typed
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
@ FT_SCENARIO
old or new scenario
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
@ SAVE_DIR
Base directory for all savegames.
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
ContentType type
Type of content.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
ConstContentIterator End() const
Get the end of the content inf iterator.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
ScreenshotType
Type of requested screenshot.
void ConPrintFramerate()
Print performance statistics to game console.
Settings for a single font.
@ SM_LOAD_GAME
Load game, Play Scenario.
static void OutputContentState(const ContentInfo *const ci)
Outputs content state information to console.
@ ZOOM_OUT
Zoom out (get helicopter view).
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
@ RTF_NO_SPRITE_COMBINE
Bit number for using non-combined junctions.
static debug_inline uint LogX()
Logarithm of the map size along the X side.
CompanyID client_playas
As which company is this client playing (CompanyID)
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
Gamelog _gamelog
Gamelog instance.
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
Notify the server of this client wanting to be moved to another company.
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
@ SC_HEIGHTMAP
Heightmap of the world.
@ CC_EXPRESS
Express cargo (Goods, Food, Candy, but also possible for passengers)
ViewportData * viewport
Pointer to viewport data, if present.
bool _network_server
network-server is active
@ GAME_LIBRARY_DIR
Subdirectory for all GS libraries.
const GRFFile * grffile
Which GRF is being profiled.
void SaveToConfig()
Save the values to the configuration file.
static void AbortTimer()
Abort the timeout timer, so the timer callback is never called.
@ SCREENSHOT_DIR
Subdirectory for all screenshots.
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
static ConsoleFileList _console_file_list_savegame
File storage cache for savegames.
Searchpath
Types of searchpaths OpenTTD might use.
bool aa
Whether to do anti aliasing or not.
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
This struct contains all the info that is needed to draw and construct tracks.
@ DFT_GAME_FILE
Save game or scenario file.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
bool GetArgumentInteger(uint32_t *value, const char *arg)
Change a string into its number representation.
static bool CanStartNew()
Is it possible to start a new AI company?
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
ClientSettings _settings_client
The current settings for this game.
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
@ ZOOM_LVL_MAX
Maximum zoom level.
Specification of a cargo type.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
@ CC_LIQUID
Liquids (Oil, Water, Rubber)
@ CONTENT_TYPE_END
Helper to mark the end of the types.
@ VEH_ROAD
Road vehicle type.
@ CC_PASSENGERS
Passengers.
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
void StartupEngines()
Start/initialise all our engines.
Owner
Enum for all companies/owners.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
std::string FiosGetCurrentPath()
Get the current path/working directory.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
MD5Hash md5sum
The MD5 checksum.
ZoomLevel zoom_max
maximum zoom out level
List of file information.
void InvalidateFileList()
Declare the file storage cache as being invalid, also clears all stored files.
const typedef ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
std::string cmdline
command(s) that is/are being aliased
static const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
ContentType
The values in the enum are important; they are used as database 'keys'.
uint size
The (requested) size of the font.
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
static const TextColour CC_DEFAULT
Default colour of the console.
IConsoleHook * hook
any special trigger action that needs executing
GameCreationSettings game_creation
settings used during the creation of a game (map)
const FiosItem * FindItem(const std::string_view file)
Find file information of a file by its name from the file list.
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
std::string name
name of command
@ PM_UNPAUSED
A normal unpaused game.
@ ROTF_CATENARY
Bit number for adding catenary.
void RequestContentList(ContentType type)
Request the content list for the given type.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
StringID name
Name of this rail type.
@ ZOOM_LVL_MIN
Minimum zoom level.
AbstractFileType
The different abstract types of files that the system knows about.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
@ ZOOM_IN
Zoom in (get more detailed view).
@ RTF_DISALLOW_90DEG
Bit number for never allowed 90 degree turns, regardless of setting.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
@ BASE_DIR
Base directory for all subdirectories.
std::string GetDebugString()
Print out the current debug-level.
Data structure for viewport, display of a part of the world.
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
@ COMPANY_NEW_COMPANY
The client wants a new company.
@ SLO_LOAD
File is being loaded.
static uint _script_current_depth
Depth of scripts running (used to abort execution when #ConReturn is encountered).
RailType
Enumeration for all possible railtypes.
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
@ CC_SPECIAL
Special bit used for livery refit tricks instead of normal cargoes.
std::string last_joined
Last joined server.
bool HasParent()
Check whether the font cache has a parent.
@ SLO_SAVE
File is being saved.
static void StartTimer(uint64_t ticks)
Start the timeout timer that will finish all profiling sessions.
static const TextColour CC_HELP
Colour for help lines.
@ AI_DIR
Subdirectory for all AI files.
@ RTF_CATENARY
Bit number for drawing a catenary.
@ CCA_NEW_AI
Create a new AI company.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
static ConsoleFileList _console_file_list_scenario
File storage cache for scenarios.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
void UnselectAll()
Unselect everything that we've not downloaded so far.
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for GameScanner::GetConsoleLibraryList.
@ CC_PIECE_GOODS
Piece goods (Livestock, Wood, Steel, Paper)
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for GameScanner::GetConsoleList.
std::string font
The name of the font, or path to the font.
Container for all important information about a piece of content.
bool FileExists(const std::string &filename)
Test whether the given filename exists.
@ RTF_ALLOW_90DEG
Bit number for always allowed 90 degree turns, regardless of setting.
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
@ CC_BULK
Bulk cargo (Coal, Grain etc., Ores, Fruit)
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Deals with finding savegames.
PauseMode _pause_mode
The current pause mode.
void Unselect(ContentID cid)
Unselect a specific content id.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ CHR_ALLOW
Allow command execution.
RailTypeLabel label
Unique 32 bit rail type identifier.
void ShowFramerateWindow()
Open the general framerate window.
void NetworkPrintClients()
Print all the clients to the console.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
AbstractFileType abstract_filetype
The abstract file type to list.
std::string password
The password for the company.
@ GAME_DIR
Subdirectory for all game scripts.
@ SCENARIO_DIR
Base directory for all scenarios.
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
@ FT_INVALID
Invalid or unknown file type.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
NetworkCompanyState * _network_company_states
Statistics about some companies.
@ SELECTED
The content has been manually selected.
static const TextColour CC_DEBUG
Colour for debug output.
bool _networking
are we in networking mode?
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
@ RTF_HIDDEN
Bit number for hiding from selection.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
@ RTSG_GROUND
Main group of ground images.
void ValidateFileList(bool force_reload=false)
(Re-)validate the file storage cache.
StringID name
Name of this rail type.
bool active
Is this profiler collecting data.
bool _network_dedicated
are we a dedicated server?
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
@ FT_SAVEGAME
old or new savegame
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
static const TextColour CC_COMMAND
Colour for the console's commands.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
bool file_list_valid
If set, the file list is valid.
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
ClientID client_id
Client identifier (same as ClientState->client_id)
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
File list storage for the console, for caching the last 'ls' command.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
ClientID _network_own_client_id
Our client identifier.
std::string name
name of the alias
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
ZoomLevel zoom_min
minimum zoom out level
static debug_inline uint SizeX()
Get the size of the map along the X.
static ConsoleFileList _console_file_list_heightmap
File storage cache for heightmaps.
AISettings ai
what may the AI do?
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
SwitchMode _switch_mode
The next mainloop command.
void PrintConsole()
Print the gamelog data to the console.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Callback profiler for NewGRF development.
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
virtual std::string GetFontName()=0
Get the name of this font.
@ SC_WORLD
World screenshot.
Font cache for basic fonts.
uint32_t generation_seed
noise seed for world generation
ClientID
'Unique' identifier to be given to clients
@ CC_ARMOURED
Armoured cargo (Valuables, Gold, Diamonds)
static size_t GetNumItems()
Returns number of valid items in the pool.
uint8_t map_y
Y size of map.
RoadTypeLabel label
Unique 32 bit road type identifier.
uint8_t map_x
X size of map.
void Set(const FiosItem &item)
Set the title of the file.
static debug_inline uint Size()
Get the size of the map.
@ AUTOSELECTED
The content has been selected as dependency.
@ CRR_NONE
Dummy reason for actions that don't need one.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
@ COMPANY_SPECTATOR
The client is spectating.
@ RAILTYPE_END
Used for iterations.
@ CC_REFRIGERATED
Refrigerated cargo (Food, Fruit)
Window * GetMainWindow()
Get the main window, i.e.
DEF_CONSOLE_CMD(ConResetEngines)
Reset status of all engines.
@ WC_CONSOLE
Console; Window numbers:
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
ContentID
Unique identifier for the content.
static void AliasRegister(const std::string &name, const std::string &cmd)
Register a an alias for an already existing command in the console.
@ PM_PAUSED_NORMAL
A game normally paused.
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
uint8_t max_clients
maximum amount of clients
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
uint8_t max_companies
maximum amount of companies
@ RTF_NO_LEVEL_CROSSING
Bit number for disallowing level crossings.
bool StrEqualsIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
virtual int GetFontSize() const
Get the nominal font size of the font.
static ContentType StringToContentType(const char *str)
Resolve a string to a content type.
RoadType
The different roadtypes we support.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ FT_HEIGHTMAP
heightmap file
void Select(ContentID cid)
Select a specific content id.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
@ INVALID_CLIENT_ID
Client is not part of anything.
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
static const TextColour CC_ERROR
Colour for error lines.
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
@ SM_MENU
Switch to game intro menu.
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
@ ROTF_HIDDEN
Bit number for hidden from construction.
void AddCallback(ContentCallback *cb)
Add a callback to this class.
static bool NetworkAvailable(bool echo)
Check network availability and inform in console about failure of detection.
@ CHR_DISALLOW
Disallow command execution.
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
State state
Whether the content info is selected (for download)
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password, const std::string &join_company_password)
Join a client to the server at with the given connection string.
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
#define lengthof(x)
Return the length of an fixed size array.
StringList _network_ban_list
The banned clients.
ZoomLevel zoom
The zoom level of the viewport.
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
@ SOCIAL_INTEGRATION_DIR
Subdirectory for all social integration plugins.
static uint LogY()
Logarithm of the map size along the y side.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
NetworkSettings network
settings related to the network
void IConsoleClose()
Close the in-game console.
@ SC_VIEWPORT
Screenshot of viewport.
@ CHR_HIDE
Hide the existence of the command.
@ FS_MONO
Index of the monospaced font in the font tables.
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
@ INVALID_COMPANY
An invalid company.
DEF_CONSOLE_HOOK(ConHookServerOnly)
Check whether we are a server.
RailTypeFlags flags
Bit mask of rail type flags.
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
void OnDisconnect() override
Callback for when the connection got disconnected.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat message.
static Date date
Current date in days (day counter).
FontSize
Available font sizes.
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Data structure for an opened window.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
bool MakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
Schedule making a screenshot.
@ SC_MINIMAP
Minimap screenshot.
byte clients_on
Current count of clients on server.
bool _network_available
is network mode available?
void SelectUpgrade()
Select everything that's an update for something we've got.
static const TextColour CC_WARNING
Colour for warning lines.
ContentID id
Unique (server side) ID for the content.
@ CCA_DELETE
Delete a company.
static void Rescan()
Rescans all searchpaths for available AIs.
@ VEH_SHIP
Ship vehicle type.
@ PM_PAUSED_ERROR
A game paused because a (critical) error.
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
@ SL_OK
completed successfully
@ ROADTYPE_BEGIN
Used for iterations.
@ CLIENT_ID_SERVER
Servers always have this ID.
Container for all information known about a client.
@ CRR_MANUAL
The company is manually removed.
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
uint32_t unique_id
Unique ID; either GRF ID or shortname.
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
bool ai_in_multiplayer
so we allow AIs in multiplayer
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
static uint SizeY()
Get the size of the map along the Y.
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
void FioFCloseFile(FILE *f)
Close a file in a safe way.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
static void PrintLineByLine(const std::string &full_string)
Print a text buffer line by line to the console.
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
@ RAILTYPE_BEGIN
Used for iterations.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.