OpenTTD Source: src/console_cmds.cpp Source File

OpenTTD Source 14.0-beta1

console_cmds.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "console_internal.h"
12 #include "debug.h"
13 #include "engine_func.h"
14 #include "landscape.h"
15 #include "saveload/saveload.h"
16 #include "network/core/network_game_info.h"
17 #include "network/network.h"
18 #include "network/network_func.h"
19 #include "network/network_base.h"
20 #include "network/network_admin.h"
21 #include "network/network_client.h"
22 #include "command_func.h"
23 #include "settings_func.h"
24 #include "fios.h"
25 #include "fileio_func.h"
26 #include "fontcache.h"
27 #include "screenshot.h"
28 #include "genworld.h"
29 #include "strings_func.h"
30 #include "viewport_func.h"
31 #include "window_func.h"
32 #include "timer/timer_game_calendar.h"
33 #include "company_func.h"
34 #include "gamelog.h"
35 #include "ai/ai.hpp"
36 #include "ai/ai_config.hpp"
37 #include "newgrf.h"
38 #include "newgrf_profiling.h"
39 #include "console_func.h"
40 #include "engine_base.h"
41 #include "road.h"
42 #include "rail.h"
43 #include "game/game.hpp"
44 #include "table/strings.h"
45 #include "3rdparty/fmt/chrono.h"
46 #include "company_cmd.h"
47 #include "misc_cmd.h"
48
49 #include <sstream>
50
51 #include "safeguards.h"
52
53 /* scriptfile handling */
54 static uint _script_current_depth;
55
57 class ConsoleFileList : public FileList {
58 public:
59 ConsoleFileList(AbstractFileType abstract_filetype, bool show_dirs) : FileList(), abstract_filetype(abstract_filetype), show_dirs(show_dirs)
60 {
61 }
62
64 void InvalidateFileList()
65 {
66 this->clear();
67 this->file_list_valid = false;
68 }
69
74 void ValidateFileList(bool force_reload = false)
75 {
76 if (force_reload || !this->file_list_valid) {
77 this->BuildFileList(this->abstract_filetype, SLO_LOAD, this->show_dirs);
78 this->file_list_valid = true;
79 }
80 }
81
82 AbstractFileType abstract_filetype;
83 bool show_dirs;
84 bool file_list_valid = false;
85 };
86
87 static ConsoleFileList _console_file_list_savegame{FT_SAVEGAME, true};
88 static ConsoleFileList _console_file_list_scenario{FT_SCENARIO, false};
89 static ConsoleFileList _console_file_list_heightmap{FT_HEIGHTMAP, false};
90
91 /* console command defines */
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)
94
95
96 /****************
97 * command hooks
98 ****************/
99
104 static inline bool NetworkAvailable(bool echo)
105 {
106 if (!_network_available) {
107 if (echo) IConsolePrint(CC_ERROR, "You cannot use this command because there is no network available.");
108 return false;
109 }
110 return true;
111 }
112
117 DEF_CONSOLE_HOOK(ConHookServerOnly)
118 {
119 if (!NetworkAvailable(echo)) return CHR_DISALLOW;
120
121 if (!_network_server) {
122 if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server.");
123 return CHR_DISALLOW;
124 }
125 return CHR_ALLOW;
126 }
127
132 DEF_CONSOLE_HOOK(ConHookClientOnly)
133 {
134 if (!NetworkAvailable(echo)) return CHR_DISALLOW;
135
136 if (_network_server) {
137 if (echo) IConsolePrint(CC_ERROR, "This command is not available to a network server.");
138 return CHR_DISALLOW;
139 }
140 return CHR_ALLOW;
141 }
142
147 DEF_CONSOLE_HOOK(ConHookNeedNetwork)
148 {
149 if (!NetworkAvailable(echo)) return CHR_DISALLOW;
150
151 if (!_networking || (!_network_server && !MyClient::IsConnected())) {
152 if (echo) IConsolePrint(CC_ERROR, "Not connected. This command is only available in multiplayer.");
153 return CHR_DISALLOW;
154 }
155 return CHR_ALLOW;
156 }
157
162 DEF_CONSOLE_HOOK(ConHookNoNetwork)
163 {
164 if (_networking) {
165 if (echo) IConsolePrint(CC_ERROR, "This command is forbidden in multiplayer.");
166 return CHR_DISALLOW;
167 }
168 return CHR_ALLOW;
169 }
170
175 DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork)
176 {
177 if (_networking && !_network_server) {
178 if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server.");
179 return CHR_DISALLOW;
180 }
181 return CHR_ALLOW;
182 }
183
184 DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
185 {
186 if (_settings_client.gui.newgrf_developer_tools) {
187 if (_game_mode == GM_MENU) {
188 if (echo) IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
189 return CHR_DISALLOW;
190 }
191 return ConHookNoNetwork(echo);
192 }
193 return CHR_HIDE;
194 }
195
200 DEF_CONSOLE_CMD(ConResetEngines)
201 {
202 if (argc == 0) {
203 IConsolePrint(CC_HELP, "Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'.");
204 return true;
205 }
206
207 StartupEngines();
208 return true;
209 }
210
216 DEF_CONSOLE_CMD(ConResetEnginePool)
217 {
218 if (argc == 0) {
219 IConsolePrint(CC_HELP, "Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
220 return true;
221 }
222
223 if (_game_mode == GM_MENU) {
224 IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
225 return true;
226 }
227
228 if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) {
229 IConsolePrint(CC_ERROR, "This can only be done when there are no vehicles in the game.");
230 return true;
231 }
232
233 return true;
234 }
235
236 #ifdef _DEBUG
237
242 DEF_CONSOLE_CMD(ConResetTile)
243 {
244 if (argc == 0) {
245 IConsolePrint(CC_HELP, "Reset a tile to bare land. Usage: 'resettile <tile>'.");
246 IConsolePrint(CC_HELP, "Tile can be either decimal (34161) or hexadecimal (0x4a5B).");
247 return true;
248 }
249
250 if (argc == 2) {
251 uint32_t result;
252 if (GetArgumentInteger(&result, argv[1])) {
253 DoClearSquare((TileIndex)result);
254 return true;
255 }
256 }
257
258 return false;
259 }
260 #endif /* _DEBUG */
261
267 DEF_CONSOLE_CMD(ConZoomToLevel)
268 {
269 switch (argc) {
270 case 0:
271 IConsolePrint(CC_HELP, "Set the current zoom level of the main viewport.");
272 IConsolePrint(CC_HELP, "Usage: 'zoomto <level>'.");
273
274 if (ZOOM_LVL_MIN < _settings_client.gui.zoom_min) {
275 IConsolePrint(CC_HELP, "The lowest zoom-in level allowed by current client settings is {}.", std::max(ZOOM_LVL_MIN, _settings_client.gui.zoom_min));
276 } else {
277 IConsolePrint(CC_HELP, "The lowest supported zoom-in level is {}.", std::max(ZOOM_LVL_MIN, _settings_client.gui.zoom_min));
278 }
279
280 if (_settings_client.gui.zoom_max < ZOOM_LVL_MAX) {
281 IConsolePrint(CC_HELP, "The highest zoom-out level allowed by current client settings is {}.", std::min(_settings_client.gui.zoom_max, ZOOM_LVL_MAX));
282 } else {
283 IConsolePrint(CC_HELP, "The highest supported zoom-out level is {}.", std::min(_settings_client.gui.zoom_max, ZOOM_LVL_MAX));
284 }
285 return true;
286
287 case 2: {
288 uint32_t level;
289 if (GetArgumentInteger(&level, argv[1])) {
290 /* In case ZOOM_LVL_MIN is more than 0, the next if statement needs to be amended.
291 * A simple check for less than ZOOM_LVL_MIN does not work here because we are
292 * reading an unsigned integer from the console, so just check for a '-' char. */
293 static_assert(ZOOM_LVL_MIN == 0);
294 if (argv[1][0] == '-') {
295 IConsolePrint(CC_ERROR, "Zoom-in levels below {} are not supported.", ZOOM_LVL_MIN);
296 } else if (level < _settings_client.gui.zoom_min) {
297 IConsolePrint(CC_ERROR, "Current client settings do not allow zooming in below level {}.", _settings_client.gui.zoom_min);
298 } else if (level > ZOOM_LVL_MAX) {
299 IConsolePrint(CC_ERROR, "Zoom-in levels above {} are not supported.", ZOOM_LVL_MAX);
300 } else if (level > _settings_client.gui.zoom_max) {
301 IConsolePrint(CC_ERROR, "Current client settings do not allow zooming out beyond level {}.", _settings_client.gui.zoom_max);
302 } else {
303 Window *w = GetMainWindow();
304 Viewport *vp = w->viewport;
305 while (vp->zoom > level) DoZoomInOutWindow(ZOOM_IN, w);
306 while (vp->zoom < level) DoZoomInOutWindow(ZOOM_OUT, w);
307 }
308 return true;
309 }
310 break;
311 }
312 }
313
314 return false;
315 }
316
326 DEF_CONSOLE_CMD(ConScrollToTile)
327 {
328 if (argc == 0) {
329 IConsolePrint(CC_HELP, "Center the screen on a given tile.");
330 IConsolePrint(CC_HELP, "Usage: 'scrollto [instant] <tile>' or 'scrollto [instant] <x> <y>'.");
331 IConsolePrint(CC_HELP, "Numbers can be either decimal (34161) or hexadecimal (0x4a5B).");
332 IConsolePrint(CC_HELP, "'instant' will immediately move and redraw viewport without smooth scrolling.");
333 return true;
334 }
335 if (argc < 2) return false;
336
337 uint32_t arg_index = 1;
338 bool instant = false;
339 if (strcmp(argv[arg_index], "instant") == 0) {
340 ++arg_index;
341 instant = true;
342 }
343
344 switch (argc - arg_index) {
345 case 1: {
346 uint32_t result;
347 if (GetArgumentInteger(&result, argv[arg_index])) {
348 if (result >= Map::Size()) {
349 IConsolePrint(CC_ERROR, "Tile does not exist.");
350 return true;
351 }
352 ScrollMainWindowToTile((TileIndex)result, instant);
353 return true;
354 }
355 break;
356 }
357
358 case 2: {
359 uint32_t x, y;
360 if (GetArgumentInteger(&x, argv[arg_index]) && GetArgumentInteger(&y, argv[arg_index + 1])) {
361 if (x >= Map::SizeX() || y >= Map::SizeY()) {
362 IConsolePrint(CC_ERROR, "Tile does not exist.");
363 return true;
364 }
365 ScrollMainWindowToTile(TileXY(x, y), instant);
366 return true;
367 }
368 break;
369 }
370 }
371
372 return false;
373 }
374
380 DEF_CONSOLE_CMD(ConSave)
381 {
382 if (argc == 0) {
383 IConsolePrint(CC_HELP, "Save the current game. Usage: 'save <filename>'.");
384 return true;
385 }
386
387 if (argc == 2) {
388 std::string filename = argv[1];
389 filename += ".sav";
390 IConsolePrint(CC_DEFAULT, "Saving map...");
391
392 if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) {
393 IConsolePrint(CC_ERROR, "Saving map failed.");
394 } else {
395 IConsolePrint(CC_INFO, "Map successfully saved to '{}'.", filename);
396 }
397 return true;
398 }
399
400 return false;
401 }
402
407 DEF_CONSOLE_CMD(ConSaveConfig)
408 {
409 if (argc == 0) {
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.");
412 return true;
413 }
414
415 SaveToConfig();
416 IConsolePrint(CC_DEFAULT, "Saved config.");
417 return true;
418 }
419
420 DEF_CONSOLE_CMD(ConLoad)
421 {
422 if (argc == 0) {
423 IConsolePrint(CC_HELP, "Load a game by name or index. Usage: 'load <file | number>'.");
424 return true;
425 }
426
427 if (argc != 2) return false;
428
429 const char *file = argv[1];
430 _console_file_list_savegame.ValidateFileList();
431 const FiosItem *item = _console_file_list_savegame.FindItem(file);
432 if (item != nullptr) {
433 if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
434 _switch_mode = SM_LOAD_GAME;
435 _file_to_saveload.Set(*item);
436 } else {
437 IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
438 }
439 } else {
440 IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
441 }
442
443 return true;
444 }
445
446 DEF_CONSOLE_CMD(ConLoadScenario)
447 {
448 if (argc == 0) {
449 IConsolePrint(CC_HELP, "Load a scenario by name or index. Usage: 'load_scenario <file | number>'.");
450 return true;
451 }
452
453 if (argc != 2) return false;
454
455 const char *file = argv[1];
456 _console_file_list_scenario.ValidateFileList();
457 const FiosItem *item = _console_file_list_scenario.FindItem(file);
458 if (item != nullptr) {
459 if (GetAbstractFileType(item->type) == FT_SCENARIO) {
460 _switch_mode = SM_LOAD_GAME;
461 _file_to_saveload.Set(*item);
462 } else {
463 IConsolePrint(CC_ERROR, "'{}' is not a scenario.", file);
464 }
465 } else {
466 IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
467 }
468
469 return true;
470 }
471
472 DEF_CONSOLE_CMD(ConLoadHeightmap)
473 {
474 if (argc == 0) {
475 IConsolePrint(CC_HELP, "Load a heightmap by name or index. Usage: 'load_heightmap <file | number>'.");
476 return true;
477 }
478
479 if (argc != 2) return false;
480
481 const char *file = argv[1];
482 _console_file_list_heightmap.ValidateFileList();
483 const FiosItem *item = _console_file_list_heightmap.FindItem(file);
484 if (item != nullptr) {
485 if (GetAbstractFileType(item->type) == FT_HEIGHTMAP) {
486 _switch_mode = SM_START_HEIGHTMAP;
487 _file_to_saveload.Set(*item);
488 } else {
489 IConsolePrint(CC_ERROR, "'{}' is not a heightmap.", file);
490 }
491 } else {
492 IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
493 }
494
495 return true;
496 }
497
498 DEF_CONSOLE_CMD(ConRemove)
499 {
500 if (argc == 0) {
501 IConsolePrint(CC_HELP, "Remove a savegame by name or index. Usage: 'rm <file | number>'.");
502 return true;
503 }
504
505 if (argc != 2) return false;
506
507 const char *file = argv[1];
508 _console_file_list_savegame.ValidateFileList();
509 const FiosItem *item = _console_file_list_savegame.FindItem(file);
510 if (item != nullptr) {
511 if (unlink(item->name.c_str()) != 0) {
512 IConsolePrint(CC_ERROR, "Failed to delete '{}'.", item->name);
513 }
514 } else {
515 IConsolePrint(CC_ERROR, "'{}' could not be found.", file);
516 }
517
518 _console_file_list_savegame.InvalidateFileList();
519 return true;
520 }
521
522
523 /* List all the files in the current dir via console */
524 DEF_CONSOLE_CMD(ConListFiles)
525 {
526 if (argc == 0) {
527 IConsolePrint(CC_HELP, "List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'.");
528 return true;
529 }
530
531 _console_file_list_savegame.ValidateFileList(true);
532 for (uint i = 0; i < _console_file_list_savegame.size(); i++) {
533 IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_savegame[i].title);
534 }
535
536 return true;
537 }
538
539 /* List all the scenarios */
540 DEF_CONSOLE_CMD(ConListScenarios)
541 {
542 if (argc == 0) {
543 IConsolePrint(CC_HELP, "List all loadable scenarios. Usage: 'list_scenarios'.");
544 return true;
545 }
546
547 _console_file_list_scenario.ValidateFileList(true);
548 for (uint i = 0; i < _console_file_list_scenario.size(); i++) {
549 IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_scenario[i].title);
550 }
551
552 return true;
553 }
554
555 /* List all the heightmaps */
556 DEF_CONSOLE_CMD(ConListHeightmaps)
557 {
558 if (argc == 0) {
559 IConsolePrint(CC_HELP, "List all loadable heightmaps. Usage: 'list_heightmaps'.");
560 return true;
561 }
562
563 _console_file_list_heightmap.ValidateFileList(true);
564 for (uint i = 0; i < _console_file_list_heightmap.size(); i++) {
565 IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_heightmap[i].title);
566 }
567
568 return true;
569 }
570
571 /* Change the dir via console */
572 DEF_CONSOLE_CMD(ConChangeDirectory)
573 {
574 if (argc == 0) {
575 IConsolePrint(CC_HELP, "Change the dir via console. Usage: 'cd <directory | number>'.");
576 return true;
577 }
578
579 if (argc != 2) return false;
580
581 const char *file = argv[1];
582 _console_file_list_savegame.ValidateFileList(true);
583 const FiosItem *item = _console_file_list_savegame.FindItem(file);
584 if (item != nullptr) {
585 switch (item->type) {
586 case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
587 FiosBrowseTo(item);
588 break;
589 default: IConsolePrint(CC_ERROR, "{}: Not a directory.", file);
590 }
591 } else {
592 IConsolePrint(CC_ERROR, "{}: No such file or directory.", file);
593 }
594
595 _console_file_list_savegame.InvalidateFileList();
596 return true;
597 }
598
599 DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
600 {
601 if (argc == 0) {
602 IConsolePrint(CC_HELP, "Print out the current working directory. Usage: 'pwd'.");
603 return true;
604 }
605
606 /* XXX - Workaround for broken file handling */
607 _console_file_list_savegame.ValidateFileList(true);
608 _console_file_list_savegame.InvalidateFileList();
609
610 IConsolePrint(CC_DEFAULT, FiosGetCurrentPath());
611 return true;
612 }
613
614 DEF_CONSOLE_CMD(ConClearBuffer)
615 {
616 if (argc == 0) {
617 IConsolePrint(CC_HELP, "Clear the console buffer. Usage: 'clear'.");
618 return true;
619 }
620
621 IConsoleClearBuffer();
622 SetWindowDirty(WC_CONSOLE, 0);
623 return true;
624 }
625
626
627 /**********************************
628 * Network Core Console Commands
629 **********************************/
630
631 static bool ConKickOrBan(const char *argv, bool ban, const std::string &reason)
632 {
633 uint n;
634
635 if (strchr(argv, '.') == nullptr && strchr(argv, ':') == nullptr) { // banning with ID
636 ClientID client_id = (ClientID)atoi(argv);
637
638 /* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
639 * kicking frees closes and subsequently free the connection related instances, which we
640 * would be reading from and writing to after returning. So we would read or write data
641 * from freed memory up till the segfault triggers. */
642 if (client_id == CLIENT_ID_SERVER || client_id == _redirect_console_to_client) {
643 IConsolePrint(CC_ERROR, "You can not {} yourself!", ban ? "ban" : "kick");
644 return true;
645 }
646
647 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
648 if (ci == nullptr) {
649 IConsolePrint(CC_ERROR, "Invalid client ID.");
650 return true;
651 }
652
653 if (!ban) {
654 /* Kick only this client, not all clients with that IP */
655 NetworkServerKickClient(client_id, reason);
656 return true;
657 }
658
659 /* When banning, kick+ban all clients with that IP */
660 n = NetworkServerKickOrBanIP(client_id, ban, reason);
661 } else {
662 n = NetworkServerKickOrBanIP(argv, ban, reason);
663 }
664
665 if (n == 0) {
666 IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist." : "Client not found.");
667 } else {
668 IConsolePrint(CC_DEFAULT, "{}ed {} client(s).", ban ? "Bann" : "Kick", n);
669 }
670
671 return true;
672 }
673
674 DEF_CONSOLE_CMD(ConKick)
675 {
676 if (argc == 0) {
677 IConsolePrint(CC_HELP, "Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'.");
678 IConsolePrint(CC_HELP, "For client-id's, see the command 'clients'.");
679 return true;
680 }
681
682 if (argc != 2 && argc != 3) return false;
683
684 /* No reason supplied for kicking */
685 if (argc == 2) return ConKickOrBan(argv[1], false, {});
686
687 /* Reason for kicking supplied */
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);
691 return false;
692 } else {
693 return ConKickOrBan(argv[1], false, argv[2]);
694 }
695 }
696
697 DEF_CONSOLE_CMD(ConBan)
698 {
699 if (argc == 0) {
700 IConsolePrint(CC_HELP, "Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'.");
701 IConsolePrint(CC_HELP, "For client-id's, see the command 'clients'.");
702 IConsolePrint(CC_HELP, "If the client is no longer online, you can still ban their IP.");
703 return true;
704 }
705
706 if (argc != 2 && argc != 3) return false;
707
708 /* No reason supplied for kicking */
709 if (argc == 2) return ConKickOrBan(argv[1], true, {});
710
711 /* Reason for kicking supplied */
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);
715 return false;
716 } else {
717 return ConKickOrBan(argv[1], true, argv[2]);
718 }
719 }
720
721 DEF_CONSOLE_CMD(ConUnBan)
722 {
723 if (argc == 0) {
724 IConsolePrint(CC_HELP, "Unban a client from a network game. Usage: 'unban <ip | banlist-index>'.");
725 IConsolePrint(CC_HELP, "For a list of banned IP's, see the command 'banlist'.");
726 return true;
727 }
728
729 if (argc != 2) return false;
730
731 /* Try by IP. */
732 uint index;
733 for (index = 0; index < _network_ban_list.size(); index++) {
734 if (_network_ban_list[index] == argv[1]) break;
735 }
736
737 /* Try by index. */
738 if (index >= _network_ban_list.size()) {
739 index = atoi(argv[1]) - 1U; // let it wrap
740 }
741
742 if (index < _network_ban_list.size()) {
743 IConsolePrint(CC_DEFAULT, "Unbanned {}.", _network_ban_list[index]);
744 _network_ban_list.erase(_network_ban_list.begin() + index);
745 } else {
746 IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
747 IConsolePrint(CC_DEFAULT, "For a list of banned IP's, see the command 'banlist'.");
748 }
749
750 return true;
751 }
752
753 DEF_CONSOLE_CMD(ConBanList)
754 {
755 if (argc == 0) {
756 IConsolePrint(CC_HELP, "List the IP's of banned clients: Usage 'banlist'.");
757 return true;
758 }
759
760 IConsolePrint(CC_DEFAULT, "Banlist:");
761
762 uint i = 1;
763 for (const auto &entry : _network_ban_list) {
764 IConsolePrint(CC_DEFAULT, " {}) {}", i, entry);
765 i++;
766 }
767
768 return true;
769 }
770
771 DEF_CONSOLE_CMD(ConPauseGame)
772 {
773 if (argc == 0) {
774 IConsolePrint(CC_HELP, "Pause a network game. Usage: 'pause'.");
775 return true;
776 }
777
778 if (_game_mode == GM_MENU) {
779 IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
780 return true;
781 }
782
783 if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
784 Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
785 if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused.");
786 } else {
787 IConsolePrint(CC_DEFAULT, "Game is already paused.");
788 }
789
790 return true;
791 }
792
793 DEF_CONSOLE_CMD(ConUnpauseGame)
794 {
795 if (argc == 0) {
796 IConsolePrint(CC_HELP, "Unpause a network game. Usage: 'unpause'.");
797 return true;
798 }
799
800 if (_game_mode == GM_MENU) {
801 IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
802 return true;
803 }
804
805 if ((_pause_mode & PM_PAUSED_NORMAL) != PM_UNPAUSED) {
806 Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, false);
807 if (!_networking) IConsolePrint(CC_DEFAULT, "Game unpaused.");
808 } else if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED) {
809 IConsolePrint(CC_DEFAULT, "Game is in error state and cannot be unpaused via console.");
810 } else if (_pause_mode != PM_UNPAUSED) {
811 IConsolePrint(CC_DEFAULT, "Game cannot be unpaused manually; disable pause_on_join/min_active_clients.");
812 } else {
813 IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
814 }
815
816 return true;
817 }
818
819 DEF_CONSOLE_CMD(ConRcon)
820 {
821 if (argc == 0) {
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.");
824 return true;
825 }
826
827 if (argc < 3) return false;
828
829 if (_network_server) {
830 IConsoleCmdExec(argv[2]);
831 } else {
832 NetworkClientSendRcon(argv[1], argv[2]);
833 }
834 return true;
835 }
836
837 DEF_CONSOLE_CMD(ConStatus)
838 {
839 if (argc == 0) {
840 IConsolePrint(CC_HELP, "List the status of all clients connected to the server. Usage 'status'.");
841 return true;
842 }
843
844 NetworkServerShowStatusToConsole();
845 return true;
846 }
847
848 DEF_CONSOLE_CMD(ConServerInfo)
849 {
850 if (argc == 0) {
851 IConsolePrint(CC_HELP, "List current and maximum client/company limits. Usage 'server_info'.");
852 IConsolePrint(CC_HELP, "You can change these values by modifying settings 'network.max_clients' and 'network.max_companies'.");
853 return true;
854 }
855
856 IConsolePrint(CC_DEFAULT, "Invite code: {}", _network_server_invite_code);
857 IConsolePrint(CC_DEFAULT, "Current/maximum clients: {:3d}/{:3d}", _network_game_info.clients_on, _settings_client.network.max_clients);
858 IConsolePrint(CC_DEFAULT, "Current/maximum companies: {:3d}/{:3d}", Company::GetNumItems(), _settings_client.network.max_companies);
859 IConsolePrint(CC_DEFAULT, "Current spectators: {:3d}", NetworkSpectatorCount());
860
861 return true;
862 }
863
864 DEF_CONSOLE_CMD(ConClientNickChange)
865 {
866 if (argc != 3) {
867 IConsolePrint(CC_HELP, "Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'.");
868 IConsolePrint(CC_HELP, "For client-id's, see the command 'clients'.");
869 return true;
870 }
871
872 ClientID client_id = (ClientID)atoi(argv[1]);
873
874 if (client_id == CLIENT_ID_SERVER) {
875 IConsolePrint(CC_ERROR, "Please use the command 'name' to change your own name!");
876 return true;
877 }
878
879 if (NetworkClientInfo::GetByClientID(client_id) == nullptr) {
880 IConsolePrint(CC_ERROR, "Invalid client ID.");
881 return true;
882 }
883
884 std::string client_name(argv[2]);
885 StrTrimInPlace(client_name);
886 if (!NetworkIsValidClientName(client_name)) {
887 IConsolePrint(CC_ERROR, "Cannot give a client an empty name.");
888 return true;
889 }
890
891 if (!NetworkServerChangeClientName(client_id, client_name)) {
892 IConsolePrint(CC_ERROR, "Cannot give a client a duplicate name.");
893 }
894
895 return true;
896 }
897
898 DEF_CONSOLE_CMD(ConJoinCompany)
899 {
900 if (argc < 2) {
901 IConsolePrint(CC_HELP, "Request joining another company. Usage: 'join <company-id> [<password>]'.");
902 IConsolePrint(CC_HELP, "For valid company-id see company list, use 255 for spectator.");
903 return true;
904 }
905
906 CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
907
908 /* Check we have a valid company id! */
909 if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
910 IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
911 return true;
912 }
913
914 if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
915 IConsolePrint(CC_ERROR, "You are already there!");
916 return true;
917 }
918
919 if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
920 IConsolePrint(CC_ERROR, "Cannot join AI company.");
921 return true;
922 }
923
924 /* Check if the company requires a password */
925 if (NetworkCompanyIsPassworded(company_id) && argc < 3) {
926 IConsolePrint(CC_ERROR, "Company {} requires a password to join.", company_id + 1);
927 return true;
928 }
929
930 /* non-dedicated server may just do the move! */
931 if (_network_server) {
932 NetworkServerDoMove(CLIENT_ID_SERVER, company_id);
933 } else {
934 NetworkClientRequestMove(company_id, NetworkCompanyIsPassworded(company_id) ? argv[2] : "");
935 }
936
937 return true;
938 }
939
940 DEF_CONSOLE_CMD(ConMoveClient)
941 {
942 if (argc < 3) {
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.");
945 return true;
946 }
947
948 const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)atoi(argv[1]));
949 CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
950
951 /* check the client exists */
952 if (ci == nullptr) {
953 IConsolePrint(CC_ERROR, "Invalid client-id, check the command 'clients' for valid client-id's.");
954 return true;
955 }
956
957 if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
958 IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
959 return true;
960 }
961
962 if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
963 IConsolePrint(CC_ERROR, "You cannot move clients to AI companies.");
964 return true;
965 }
966
967 if (ci->client_id == CLIENT_ID_SERVER && _network_dedicated) {
968 IConsolePrint(CC_ERROR, "You cannot move the server!");
969 return true;
970 }
971
972 if (ci->client_playas == company_id) {
973 IConsolePrint(CC_ERROR, "You cannot move someone to where they already are!");
974 return true;
975 }
976
977 /* we are the server, so force the update */
978 NetworkServerDoMove(ci->client_id, company_id);
979
980 return true;
981 }
982
983 DEF_CONSOLE_CMD(ConResetCompany)
984 {
985 if (argc == 0) {
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.");
988 return true;
989 }
990
991 if (argc != 2) return false;
992
993 CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
994
995 /* Check valid range */
996 if (!Company::IsValidID(index)) {
997 IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
998 return true;
999 }
1000
1001 if (!Company::IsHumanID(index)) {
1002 IConsolePrint(CC_ERROR, "Company is owned by an AI.");
1003 return true;
1004 }
1005
1006 if (NetworkCompanyHasClients(index)) {
1007 IConsolePrint(CC_ERROR, "Cannot remove company: a client is connected to that company.");
1008 return false;
1009 }
1010 const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
1011 assert(ci != nullptr);
1012 if (ci->client_playas == index) {
1013 IConsolePrint(CC_ERROR, "Cannot remove company: the server is connected to that company.");
1014 return true;
1015 }
1016
1017 /* It is safe to remove this company */
1018 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, index, CRR_MANUAL, INVALID_CLIENT_ID);
1019 IConsolePrint(CC_DEFAULT, "Company deleted.");
1020
1021 return true;
1022 }
1023
1024 DEF_CONSOLE_CMD(ConNetworkClients)
1025 {
1026 if (argc == 0) {
1027 IConsolePrint(CC_HELP, "Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'.");
1028 return true;
1029 }
1030
1031 NetworkPrintClients();
1032
1033 return true;
1034 }
1035
1036 DEF_CONSOLE_CMD(ConNetworkReconnect)
1037 {
1038 if (argc == 0) {
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.");
1041 IConsolePrint(CC_HELP, "All others are a certain company with Company 1 being #1.");
1042 return true;
1043 }
1044
1045 CompanyID playas = (argc >= 2) ? (CompanyID)atoi(argv[1]) : COMPANY_SPECTATOR;
1046 switch (playas) {
1047 case 0: playas = COMPANY_NEW_COMPANY; break;
1048 case COMPANY_SPECTATOR: /* nothing to do */ break;
1049 default:
1050 /* From a user pov 0 is a new company, internally it's different and all
1051 * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
1052 if (playas < COMPANY_FIRST + 1 || playas > MAX_COMPANIES + 1) return false;
1053 break;
1054 }
1055
1056 if (_settings_client.network.last_joined.empty()) {
1057 IConsolePrint(CC_DEFAULT, "No server for reconnecting.");
1058 return true;
1059 }
1060
1061 /* Don't resolve the address first, just print it directly as it comes from the config file. */
1062 IConsolePrint(CC_DEFAULT, "Reconnecting to {} ...", _settings_client.network.last_joined);
1063
1064 return NetworkClientConnectGame(_settings_client.network.last_joined, playas);
1065 }
1066
1067 DEF_CONSOLE_CMD(ConNetworkConnect)
1068 {
1069 if (argc == 0) {
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.");
1073 return true;
1074 }
1075
1076 if (argc < 2) return false;
1077
1078 return NetworkClientConnectGame(argv[1], COMPANY_NEW_COMPANY);
1079 }
1080
1081 /*********************************
1082 * script file console commands
1083 *********************************/
1084
1085 DEF_CONSOLE_CMD(ConExec)
1086 {
1087 if (argc == 0) {
1088 IConsolePrint(CC_HELP, "Execute a local script file. Usage: 'exec <script> <?>'.");
1089 return true;
1090 }
1091
1092 if (argc < 2) return false;
1093
1094 FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
1095
1096 if (script_file == nullptr) {
1097 if (argc == 2 || atoi(argv[2]) != 0) IConsolePrint(CC_ERROR, "Script file '{}' not found.", argv[1]);
1098 return true;
1099 }
1100
1101 if (_script_current_depth == 11) {
1102 FioFCloseFile(script_file);
1103 IConsolePrint(CC_ERROR, "Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
1104 return true;
1105 }
1106
1107 _script_current_depth++;
1108 uint script_depth = _script_current_depth;
1109
1110 char cmdline[ICON_CMDLN_SIZE];
1111 while (fgets(cmdline, sizeof(cmdline), script_file) != nullptr) {
1112 /* Remove newline characters from the executing script */
1113 for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
1114 if (*cmdptr == '\n' || *cmdptr == '\r') {
1115 *cmdptr = '\0';
1116 break;
1117 }
1118 }
1119 IConsoleCmdExec(cmdline);
1120 /* Ensure that we are still on the same depth or that we returned via 'return'. */
1121 assert(_script_current_depth == script_depth || _script_current_depth == script_depth - 1);
1122
1123 /* The 'return' command was executed. */
1124 if (_script_current_depth == script_depth - 1) break;
1125 }
1126
1127 if (ferror(script_file)) {
1128 IConsolePrint(CC_ERROR, "Encountered error while trying to read from script file '{}'.", argv[1]);
1129 }
1130
1131 if (_script_current_depth == script_depth) _script_current_depth--;
1132 FioFCloseFile(script_file);
1133 return true;
1134 }
1135
1136 DEF_CONSOLE_CMD(ConReturn)
1137 {
1138 if (argc == 0) {
1139 IConsolePrint(CC_HELP, "Stop executing a running script. Usage: 'return'.");
1140 return true;
1141 }
1142
1143 _script_current_depth--;
1144 return true;
1145 }
1146
1147 /*****************************
1148 * default console commands
1149 ******************************/
1150 extern bool CloseConsoleLogIfActive();
1151 extern const std::vector<GRFFile *> &GetAllGRFFiles();
1152 extern void ConPrintFramerate(); // framerate_gui.cpp
1153 extern void ShowFramerateWindow();
1154
1155 DEF_CONSOLE_CMD(ConScript)
1156 {
1157 extern FILE *_iconsole_output_file;
1158
1159 if (argc == 0) {
1160 IConsolePrint(CC_HELP, "Start or stop logging console output to a file. Usage: 'script <filename>'.");
1161 IConsolePrint(CC_HELP, "If filename is omitted, a running log is stopped if it is active.");
1162 return true;
1163 }
1164
1165 if (!CloseConsoleLogIfActive()) {
1166 if (argc < 2) return false;
1167
1168 _iconsole_output_file = fopen(argv[1], "ab");
1169 if (_iconsole_output_file == nullptr) {
1170 IConsolePrint(CC_ERROR, "Could not open console log file '{}'.", argv[1]);
1171 } else {
1172 IConsolePrint(CC_INFO, "Console log output started to '{}'.", argv[1]);
1173 }
1174 }
1175
1176 return true;
1177 }
1178
1179
1180 DEF_CONSOLE_CMD(ConEcho)
1181 {
1182 if (argc == 0) {
1183 IConsolePrint(CC_HELP, "Print back the first argument to the console. Usage: 'echo <arg>'.");
1184 return true;
1185 }
1186
1187 if (argc < 2) return false;
1188 IConsolePrint(CC_DEFAULT, argv[1]);
1189 return true;
1190 }
1191
1192 DEF_CONSOLE_CMD(ConEchoC)
1193 {
1194 if (argc == 0) {
1195 IConsolePrint(CC_HELP, "Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'.");
1196 return true;
1197 }
1198
1199 if (argc < 3) return false;
1200 IConsolePrint((TextColour)Clamp(atoi(argv[1]), TC_BEGIN, TC_END - 1), argv[2]);
1201 return true;
1202 }
1203
1204 DEF_CONSOLE_CMD(ConNewGame)
1205 {
1206 if (argc == 0) {
1207 IConsolePrint(CC_HELP, "Start a new game. Usage: 'newgame [seed]'.");
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.");
1209 return true;
1210 }
1211
1212 StartNewGameWithoutGUI((argc == 2) ? std::strtoul(argv[1], nullptr, 10) : GENERATE_NEW_SEED);
1213 return true;
1214 }
1215
1216 DEF_CONSOLE_CMD(ConRestart)
1217 {
1218 if (argc == 0 || argc > 2) {
1219 IConsolePrint(CC_HELP, "Restart game. Usage: 'restart [current|newgame]'.");
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.");
1223 return true;
1224 }
1225
1226 if (argc == 1 || std::string_view(argv[1]) == "newgame") {
1227 StartNewGameWithoutGUI(_settings_game.game_creation.generation_seed);
1228 } else {
1229 _settings_game.game_creation.map_x = Map::LogX();
1230 _settings_game.game_creation.map_y = Map::LogY();
1231 _switch_mode = SM_RESTARTGAME;
1232 }
1233
1234 return true;
1235 }
1236
1237 DEF_CONSOLE_CMD(ConReload)
1238 {
1239 if (argc == 0) {
1240 IConsolePrint(CC_HELP, "Reload game. Usage: 'reload'.");
1241 IConsolePrint(CC_HELP, "Reloads a game if loaded via savegame / scenario / heightmap.");
1242 return true;
1243 }
1244
1245 if (_file_to_saveload.abstract_ftype == FT_NONE || _file_to_saveload.abstract_ftype == FT_INVALID) {
1246 IConsolePrint(CC_ERROR, "No game loaded to reload.");
1247 return true;
1248 }
1249
1250 /* Use a switch-mode to prevent copying over newgame settings to active settings. */
1251 _settings_game.game_creation.map_x = Map::LogX();
1252 _settings_game.game_creation.map_y = Map::LogY();
1253 _switch_mode = SM_RELOADGAME;
1254 return true;
1255 }
1256
1261 static void PrintLineByLine(const std::string &full_string)
1262 {
1263 std::istringstream in(full_string);
1264 std::string line;
1265 while (std::getline(in, line)) {
1266 IConsolePrint(CC_DEFAULT, line);
1267 }
1268 }
1269
1270 template <typename F, typename ... Args>
1271 bool PrintList(F list_function, Args... args)
1272 {
1273 std::string output_str;
1274 auto inserter = std::back_inserter(output_str);
1275 list_function(inserter, args...);
1276 PrintLineByLine(output_str);
1277
1278 return true;
1279 }
1280
1281 DEF_CONSOLE_CMD(ConListAILibs)
1282 {
1283 if (argc == 0) {
1284 IConsolePrint(CC_HELP, "List installed AI libraries. Usage: 'list_ai_libs'.");
1285 return true;
1286 }
1287
1288 return PrintList(AI::GetConsoleLibraryList);
1289 }
1290
1291 DEF_CONSOLE_CMD(ConListAI)
1292 {
1293 if (argc == 0) {
1294 IConsolePrint(CC_HELP, "List installed AIs. Usage: 'list_ai'.");
1295 return true;
1296 }
1297
1298 return PrintList(AI::GetConsoleList, false);
1299 }
1300
1301 DEF_CONSOLE_CMD(ConListGameLibs)
1302 {
1303 if (argc == 0) {
1304 IConsolePrint(CC_HELP, "List installed Game Script libraries. Usage: 'list_game_libs'.");
1305 return true;
1306 }
1307
1308 return PrintList(Game::GetConsoleLibraryList);
1309 }
1310
1311 DEF_CONSOLE_CMD(ConListGame)
1312 {
1313 if (argc == 0) {
1314 IConsolePrint(CC_HELP, "List installed Game Scripts. Usage: 'list_game'.");
1315 return true;
1316 }
1317
1318 return PrintList(Game::GetConsoleList, false);
1319 }
1320
1321 DEF_CONSOLE_CMD(ConStartAI)
1322 {
1323 if (argc == 0 || argc > 3) {
1324 IConsolePrint(CC_HELP, "Start a new AI. Usage: 'start_ai [<AI>] [<settings>]'.");
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.");
1327 return true;
1328 }
1329
1330 if (_game_mode != GM_NORMAL) {
1331 IConsolePrint(CC_ERROR, "AIs can only be managed in a game.");
1332 return true;
1333 }
1334
1335 if (Company::GetNumItems() == CompanyPool::MAX_SIZE) {
1336 IConsolePrint(CC_ERROR, "Can't start a new AI (no more free slots).");
1337 return true;
1338 }
1339 if (_networking && !_network_server) {
1340 IConsolePrint(CC_ERROR, "Only the server can start a new AI.");
1341 return true;
1342 }
1343 if (_networking && !_settings_game.ai.ai_in_multiplayer) {
1344 IConsolePrint(CC_ERROR, "AIs are not allowed in multiplayer by configuration.");
1345 IConsolePrint(CC_ERROR, "Switch AI -> AI in multiplayer to True.");
1346 return true;
1347 }
1348 if (!AI::CanStartNew()) {
1349 IConsolePrint(CC_ERROR, "Can't start a new AI.");
1350 return true;
1351 }
1352
1353 int n = 0;
1354 /* Find the next free slot */
1355 for (const Company *c : Company::Iterate()) {
1356 if (c->index != n) break;
1357 n++;
1358 }
1359
1360 AIConfig *config = AIConfig::GetConfig((CompanyID)n);
1361 if (argc >= 2) {
1362 config->Change(argv[1], -1, false);
1363
1364 /* If the name is not found, and there is a dot in the name,
1365 * try again with the assumption everything right of the dot is
1366 * the version the user wants to load. */
1367 if (!config->HasScript()) {
1368 const char *e = strrchr(argv[1], '.');
1369 if (e != nullptr) {
1370 size_t name_length = e - argv[1];
1371 e++;
1372
1373 int version = atoi(e);
1374 config->Change(std::string(argv[1], name_length), version, true);
1375 }
1376 }
1377
1378 if (!config->HasScript()) {
1379 IConsolePrint(CC_ERROR, "Failed to load the specified AI.");
1380 return true;
1381 }
1382 if (argc == 3) {
1383 config->StringToSettings(argv[2]);
1384 }
1385 }
1386
1387 /* Start a new AI company */
1388 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID);
1389
1390 return true;
1391 }
1392
1393 DEF_CONSOLE_CMD(ConReloadAI)
1394 {
1395 if (argc != 2) {
1396 IConsolePrint(CC_HELP, "Reload an AI. Usage: 'reload_ai <company-id>'.");
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.");
1398 return true;
1399 }
1400
1401 if (_game_mode != GM_NORMAL) {
1402 IConsolePrint(CC_ERROR, "AIs can only be managed in a game.");
1403 return true;
1404 }
1405
1406 if (_networking && !_network_server) {
1407 IConsolePrint(CC_ERROR, "Only the server can reload an AI.");
1408 return true;
1409 }
1410
1411 CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
1412 if (!Company::IsValidID(company_id)) {
1413 IConsolePrint(CC_ERROR, "Unknown company. Company range is between 1 and {}.", MAX_COMPANIES);
1414 return true;
1415 }
1416
1417 /* In singleplayer mode the player can be in an AI company, after cheating or loading network save with an AI in first slot. */
1418 if (Company::IsHumanID(company_id) || company_id == _local_company) {
1419 IConsolePrint(CC_ERROR, "Company is not controlled by an AI.");
1420 return true;
1421 }
1422
1423 /* First kill the company of the AI, then start a new one. This should start the current AI again */
1424 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, company_id, CRR_MANUAL, INVALID_CLIENT_ID);
1425 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, company_id, CRR_NONE, INVALID_CLIENT_ID);
1426 IConsolePrint(CC_DEFAULT, "AI reloaded.");
1427
1428 return true;
1429 }
1430
1431 DEF_CONSOLE_CMD(ConStopAI)
1432 {
1433 if (argc != 2) {
1434 IConsolePrint(CC_HELP, "Stop an AI. Usage: 'stop_ai <company-id>'.");
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.");
1436 return true;
1437 }
1438
1439 if (_game_mode != GM_NORMAL) {
1440 IConsolePrint(CC_ERROR, "AIs can only be managed in a game.");
1441 return true;
1442 }
1443
1444 if (_networking && !_network_server) {
1445 IConsolePrint(CC_ERROR, "Only the server can stop an AI.");
1446 return true;
1447 }
1448
1449 CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
1450 if (!Company::IsValidID(company_id)) {
1451 IConsolePrint(CC_ERROR, "Unknown company. Company range is between 1 and {}.", MAX_COMPANIES);
1452 return true;
1453 }
1454
1455 /* In singleplayer mode the player can be in an AI company, after cheating or loading network save with an AI in first slot. */
1456 if (Company::IsHumanID(company_id) || company_id == _local_company) {
1457 IConsolePrint(CC_ERROR, "Company is not controlled by an AI.");
1458 return true;
1459 }
1460
1461 /* Now kill the company of the AI. */
1462 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, company_id, CRR_MANUAL, INVALID_CLIENT_ID);
1463 IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
1464
1465 return true;
1466 }
1467
1468 DEF_CONSOLE_CMD(ConRescanAI)
1469 {
1470 if (argc == 0) {
1471 IConsolePrint(CC_HELP, "Rescan the AI dir for scripts. Usage: 'rescan_ai'.");
1472 return true;
1473 }
1474
1475 if (_networking && !_network_server) {
1476 IConsolePrint(CC_ERROR, "Only the server can rescan the AI dir for scripts.");
1477 return true;
1478 }
1479
1480 AI::Rescan();
1481
1482 return true;
1483 }
1484
1485 DEF_CONSOLE_CMD(ConRescanGame)
1486 {
1487 if (argc == 0) {
1488 IConsolePrint(CC_HELP, "Rescan the Game Script dir for scripts. Usage: 'rescan_game'.");
1489 return true;
1490 }
1491
1492 if (_networking && !_network_server) {
1493 IConsolePrint(CC_ERROR, "Only the server can rescan the Game Script dir for scripts.");
1494 return true;
1495 }
1496
1497 Game::Rescan();
1498
1499 return true;
1500 }
1501
1502 DEF_CONSOLE_CMD(ConRescanNewGRF)
1503 {
1504 if (argc == 0) {
1505 IConsolePrint(CC_HELP, "Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'.");
1506 return true;
1507 }
1508
1509 if (!RequestNewGRFScan()) {
1510 IConsolePrint(CC_ERROR, "NewGRF scanning is already running. Please wait until completed to run again.");
1511 }
1512
1513 return true;
1514 }
1515
1516 DEF_CONSOLE_CMD(ConGetSeed)
1517 {
1518 if (argc == 0) {
1519 IConsolePrint(CC_HELP, "Returns the seed used to create this game. Usage: 'getseed'.");
1520 IConsolePrint(CC_HELP, "The seed can be used to reproduce the exact same map as the game started with.");
1521 return true;
1522 }
1523
1524 IConsolePrint(CC_DEFAULT, "Generation Seed: {}", _settings_game.game_creation.generation_seed);
1525 return true;
1526 }
1527
1528 DEF_CONSOLE_CMD(ConGetDate)
1529 {
1530 if (argc == 0) {
1531 IConsolePrint(CC_HELP, "Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
1532 return true;
1533 }
1534
1535 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
1536 IConsolePrint(CC_DEFAULT, "Date: {:04d}-{:02d}-{:02d}", ymd.year, ymd.month + 1, ymd.day);
1537 return true;
1538 }
1539
1540 DEF_CONSOLE_CMD(ConGetSysDate)
1541 {
1542 if (argc == 0) {
1543 IConsolePrint(CC_HELP, "Returns the current date (year-month-day) of your system. Usage: 'getsysdate'.");
1544 return true;
1545 }
1546
1547 IConsolePrint(CC_DEFAULT, "System Date: {:%Y-%m-%d %H:%M:%S}", fmt::localtime(time(nullptr)));
1548 return true;
1549 }
1550
1551
1552 DEF_CONSOLE_CMD(ConAlias)
1553 {
1554 IConsoleAlias *alias;
1555
1556 if (argc == 0) {
1557 IConsolePrint(CC_HELP, "Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'.");
1558 return true;
1559 }
1560
1561 if (argc < 3) return false;
1562
1563 alias = IConsole::AliasGet(argv[1]);
1564 if (alias == nullptr) {
1565 IConsole::AliasRegister(argv[1], argv[2]);
1566 } else {
1567 alias->cmdline = argv[2];
1568 }
1569 return true;
1570 }
1571
1572 DEF_CONSOLE_CMD(ConScreenShot)
1573 {
1574 if (argc == 0) {
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).");
1577 IConsolePrint(CC_HELP, " 'normal' makes a screenshot of the visible area.");
1578 IConsolePrint(CC_HELP, " 'big' makes a zoomed-in screenshot of the visible area.");
1579 IConsolePrint(CC_HELP, " 'giant' makes a screenshot of the whole map.");
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.");
1585 return true;
1586 }
1587
1588 if (argc > 7) return false;
1589
1590 ScreenshotType type = SC_VIEWPORT;
1591 uint32_t width = 0;
1592 uint32_t height = 0;
1593 std::string name{};
1594 uint32_t arg_index = 1;
1595
1596 if (argc > arg_index) {
1597 if (strcmp(argv[arg_index], "viewport") == 0) {
1598 type = SC_VIEWPORT;
1599 arg_index += 1;
1600 } else if (strcmp(argv[arg_index], "normal") == 0) {
1601 type = SC_DEFAULTZOOM;
1602 arg_index += 1;
1603 } else if (strcmp(argv[arg_index], "big") == 0) {
1604 type = SC_ZOOMEDIN;
1605 arg_index += 1;
1606 } else if (strcmp(argv[arg_index], "giant") == 0) {
1607 type = SC_WORLD;
1608 arg_index += 1;
1609 } else if (strcmp(argv[arg_index], "heightmap") == 0) {
1610 type = SC_HEIGHTMAP;
1611 arg_index += 1;
1612 } else if (strcmp(argv[arg_index], "minimap") == 0) {
1613 type = SC_MINIMAP;
1614 arg_index += 1;
1615 }
1616 }
1617
1618 if (argc > arg_index && strcmp(argv[arg_index], "no_con") == 0) {
1619 if (type != SC_VIEWPORT) {
1620 IConsolePrint(CC_ERROR, "'no_con' can only be used in combination with 'viewport'.");
1621 return true;
1622 }
1623 IConsoleClose();
1624 arg_index += 1;
1625 }
1626
1627 if (argc > arg_index + 2 && strcmp(argv[arg_index], "size") == 0) {
1628 /* size <width> <height> */
1629 if (type != SC_DEFAULTZOOM && type != SC_ZOOMEDIN) {
1630 IConsolePrint(CC_ERROR, "'size' can only be used in combination with 'normal' or 'big'.");
1631 return true;
1632 }
1633 GetArgumentInteger(&width, argv[arg_index + 1]);
1634 GetArgumentInteger(&height, argv[arg_index + 2]);
1635 arg_index += 3;
1636 }
1637
1638 if (argc > arg_index) {
1639 /* Last parameter that was not one of the keywords must be the filename. */
1640 name = argv[arg_index];
1641 arg_index += 1;
1642 }
1643
1644 if (argc > arg_index) {
1645 /* We have parameters we did not process; means we misunderstood any of the above. */
1646 return false;
1647 }
1648
1649 MakeScreenshot(type, name, width, height);
1650 return true;
1651 }
1652
1653 DEF_CONSOLE_CMD(ConInfoCmd)
1654 {
1655 if (argc == 0) {
1656 IConsolePrint(CC_HELP, "Print out debugging information about a command. Usage: 'info_cmd <cmd>'.");
1657 return true;
1658 }
1659
1660 if (argc < 2) return false;
1661
1662 const IConsoleCmd *cmd = IConsole::CmdGet(argv[1]);
1663 if (cmd == nullptr) {
1664 IConsolePrint(CC_ERROR, "The given command was not found.");
1665 return true;
1666 }
1667
1668 IConsolePrint(CC_DEFAULT, "Command name: '{}'", cmd->name);
1669
1670 if (cmd->hook != nullptr) IConsolePrint(CC_DEFAULT, "Command is hooked.");
1671
1672 return true;
1673 }
1674
1675 DEF_CONSOLE_CMD(ConDebugLevel)
1676 {
1677 if (argc == 0) {
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.");
1680 return true;
1681 }
1682
1683 if (argc > 2) return false;
1684
1685 if (argc == 1) {
1686 IConsolePrint(CC_DEFAULT, "Current debug-level: '{}'", GetDebugString());
1687 } else {
1688 SetDebugString(argv[1], [](const std::string &err) { IConsolePrint(CC_ERROR, err); });
1689 }
1690
1691 return true;
1692 }
1693
1694 DEF_CONSOLE_CMD(ConExit)
1695 {
1696 if (argc == 0) {
1697 IConsolePrint(CC_HELP, "Exit the game. Usage: 'exit'.");
1698 return true;
1699 }
1700
1701 if (_game_mode == GM_NORMAL && _settings_client.gui.autosave_on_exit) DoExitSave();
1702
1703 _exit_game = true;
1704 return true;
1705 }
1706
1707 DEF_CONSOLE_CMD(ConPart)
1708 {
1709 if (argc == 0) {
1710 IConsolePrint(CC_HELP, "Leave the currently joined/running game (only ingame). Usage: 'part'.");
1711 return true;
1712 }
1713
1714 if (_game_mode != GM_NORMAL) return false;
1715
1716 _switch_mode = SM_MENU;
1717 return true;
1718 }
1719
1720 DEF_CONSOLE_CMD(ConHelp)
1721 {
1722 if (argc == 2) {
1723 const IConsoleCmd *cmd;
1724 const IConsoleAlias *alias;
1725
1726 cmd = IConsole::CmdGet(argv[1]);
1727 if (cmd != nullptr) {
1728 cmd->proc(0, nullptr);
1729 return true;
1730 }
1731
1732 alias = IConsole::AliasGet(argv[1]);
1733 if (alias != nullptr) {
1734 cmd = IConsole::CmdGet(alias->cmdline);
1735 if (cmd != nullptr) {
1736 cmd->proc(0, nullptr);
1737 return true;
1738 }
1739 IConsolePrint(CC_ERROR, "Alias is of special type, please see its execution-line: '{}'.", alias->cmdline);
1740 return true;
1741 }
1742
1743 IConsolePrint(CC_ERROR, "Command not found.");
1744 return true;
1745 }
1746
1747 IConsolePrint(TC_LIGHT_BLUE, " ---- OpenTTD Console Help ---- ");
1748 IConsolePrint(CC_DEFAULT, " - commands: the command to list all commands is 'list_cmds'.");
1749 IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
1750 IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes.");
1751 IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'.");
1752 IConsolePrint(CC_DEFAULT, " - use 'help <command>' to get specific information.");
1753 IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down | pageup | pagedown).");
1754 IConsolePrint(CC_DEFAULT, " - scroll console input history with the up or down arrows.");
1755 IConsolePrint(CC_DEFAULT, "");
1756 return true;
1757 }
1758
1759 DEF_CONSOLE_CMD(ConListCommands)
1760 {
1761 if (argc == 0) {
1762 IConsolePrint(CC_HELP, "List all registered commands. Usage: 'list_cmds [<pre-filter>]'.");
1763 return true;
1764 }
1765
1766 for (auto &it : IConsole::Commands()) {
1767 const IConsoleCmd *cmd = &it.second;
1768 if (argv[1] == nullptr || cmd->name.find(argv[1]) != std::string::npos) {
1769 if (cmd->hook == nullptr || cmd->hook(false) != CHR_HIDE) IConsolePrint(CC_DEFAULT, cmd->name);
1770 }
1771 }
1772
1773 return true;
1774 }
1775
1776 DEF_CONSOLE_CMD(ConListAliases)
1777 {
1778 if (argc == 0) {
1779 IConsolePrint(CC_HELP, "List all registered aliases. Usage: 'list_aliases [<pre-filter>]'.");
1780 return true;
1781 }
1782
1783 for (auto &it : IConsole::Aliases()) {
1784 const IConsoleAlias *alias = &it.second;
1785 if (argv[1] == nullptr || alias->name.find(argv[1]) != std::string::npos) {
1786 IConsolePrint(CC_DEFAULT, "{} => {}", alias->name, alias->cmdline);
1787 }
1788 }
1789
1790 return true;
1791 }
1792
1793 DEF_CONSOLE_CMD(ConCompanies)
1794 {
1795 if (argc == 0) {
1796 IConsolePrint(CC_HELP, "List the details of all companies in the game. Usage 'companies'.");
1797 return true;
1798 }
1799
1800 for (const Company *c : Company::Iterate()) {
1801 /* Grab the company name */
1802 SetDParam(0, c->index);
1803 std::string company_name = GetString(STR_COMPANY_NAME);
1804
1805 const char *password_state = "";
1806 if (c->is_ai) {
1807 password_state = "AI";
1808 } else if (_network_server) {
1809 password_state = _network_company_states[c->index].password.empty() ? "unprotected" : "protected";
1810 }
1811
1812 std::string colour = GetString(STR_COLOUR_DARK_BLUE + _company_colours[c->index]);
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),
1816 c->group_all[VEH_TRAIN].num_vehicle,
1817 c->group_all[VEH_ROAD].num_vehicle,
1818 c->group_all[VEH_AIRCRAFT].num_vehicle,
1819 c->group_all[VEH_SHIP].num_vehicle,
1820 password_state);
1821 }
1822
1823 return true;
1824 }
1825
1826 DEF_CONSOLE_CMD(ConSay)
1827 {
1828 if (argc == 0) {
1829 IConsolePrint(CC_HELP, "Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'.");
1830 return true;
1831 }
1832
1833 if (argc != 2) return false;
1834
1835 if (!_network_server) {
1836 NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
1837 } else {
1838 bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
1839 NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER, from_admin);
1840 }
1841
1842 return true;
1843 }
1844
1845 DEF_CONSOLE_CMD(ConSayCompany)
1846 {
1847 if (argc == 0) {
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.");
1850 return true;
1851 }
1852
1853 if (argc != 3) return false;
1854
1855 CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
1856 if (!Company::IsValidID(company_id)) {
1857 IConsolePrint(CC_DEFAULT, "Unknown company. Company range is between 1 and {}.", MAX_COMPANIES);
1858 return true;
1859 }
1860
1861 if (!_network_server) {
1862 NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2]);
1863 } else {
1864 bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
1865 NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2], CLIENT_ID_SERVER, from_admin);
1866 }
1867
1868 return true;
1869 }
1870
1871 DEF_CONSOLE_CMD(ConSayClient)
1872 {
1873 if (argc == 0) {
1874 IConsolePrint(CC_HELP, "Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'.");
1875 IConsolePrint(CC_HELP, "For client-id's, see the command 'clients'.");
1876 return true;
1877 }
1878
1879 if (argc != 3) return false;
1880
1881 if (!_network_server) {
1882 NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
1883 } else {
1884 bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
1885 NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], CLIENT_ID_SERVER, from_admin);
1886 }
1887
1888 return true;
1889 }
1890
1891 DEF_CONSOLE_CMD(ConCompanyPassword)
1892 {
1893 if (argc == 0) {
1894 if (_network_dedicated) {
1895 IConsolePrint(CC_HELP, "Change the password of a company. Usage: 'company_pw <company-no> \"<password>\".");
1896 } else if (_network_server) {
1897 IConsolePrint(CC_HELP, "Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'.");
1898 } else {
1899 IConsolePrint(CC_HELP, "Change the password of your company. Usage: 'company_pw \"<password>\"'.");
1900 }
1901
1902 IConsolePrint(CC_HELP, "Use \"*\" to disable the password.");
1903 return true;
1904 }
1905
1906 CompanyID company_id;
1907 std::string password;
1908 const char *errormsg;
1909
1910 if (argc == 2) {
1911 company_id = _local_company;
1912 password = argv[1];
1913 errormsg = "You have to own a company to make use of this command.";
1914 } else if (argc == 3 && _network_server) {
1915 company_id = (CompanyID)(atoi(argv[1]) - 1);
1916 password = argv[2];
1917 errormsg = "You have to specify the ID of a valid human controlled company.";
1918 } else {
1919 return false;
1920 }
1921
1922 if (!Company::IsValidHumanID(company_id)) {
1923 IConsolePrint(CC_ERROR, errormsg);
1924 return false;
1925 }
1926
1927 password = NetworkChangeCompanyPassword(company_id, password);
1928
1929 if (password.empty()) {
1930 IConsolePrint(CC_INFO, "Company password cleared.");
1931 } else {
1932 IConsolePrint(CC_INFO, "Company password changed to '{}'.", password);
1933 }
1934
1935 return true;
1936 }
1937
1938 /* Content downloading only is available with ZLIB */
1939 #if defined(WITH_ZLIB)
1940 #include "network/network_content.h"
1941
1943 static ContentType StringToContentType(const char *str)
1944 {
1945 static const char * const inv_lookup[] = { "", "base", "newgrf", "ai", "ailib", "scenario", "heightmap" };
1946 for (uint i = 1 /* there is no type 0 */; i < lengthof(inv_lookup); i++) {
1947 if (StrEqualsIgnoreCase(str, inv_lookup[i])) return (ContentType)i;
1948 }
1949 return CONTENT_TYPE_END;
1950 }
1951
1953 struct ConsoleContentCallback : public ContentCallback {
1954 void OnConnect(bool success) override
1955 {
1956 IConsolePrint(CC_DEFAULT, "Content server connection {}.", success ? "established" : "failed");
1957 }
1958
1959 void OnDisconnect() override
1960 {
1961 IConsolePrint(CC_DEFAULT, "Content server connection closed.");
1962 }
1963
1964 void OnDownloadComplete(ContentID cid) override
1965 {
1966 IConsolePrint(CC_DEFAULT, "Completed download of {}.", cid);
1967 }
1968 };
1969
1974 static void OutputContentState(const ContentInfo *const ci)
1975 {
1976 static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music", "Game script", "GS library" };
1977 static_assert(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
1978 static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" };
1979 static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR };
1980
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));
1982 }
1983
1984 DEF_CONSOLE_CMD(ConContent)
1985 {
1986 static ContentCallback *cb = nullptr;
1987 if (cb == nullptr) {
1988 cb = new ConsoleContentCallback();
1989 _network_content_client.AddCallback(cb);
1990 }
1991
1992 if (argc <= 1) {
1993 IConsolePrint(CC_HELP, "Query, select and download content. Usage: 'content update|upgrade|select [id]|unselect [all|id]|state [filter]|download'.");
1994 IConsolePrint(CC_HELP, " update: get a new list of downloadable content; must be run first.");
1995 IConsolePrint(CC_HELP, " upgrade: select all items that are upgrades.");
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.");
1999 IConsolePrint(CC_HELP, " download: download all content you've selected.");
2000 return true;
2001 }
2002
2003 if (StrEqualsIgnoreCase(argv[1], "update")) {
2004 _network_content_client.RequestContentList((argc > 2) ? StringToContentType(argv[2]) : CONTENT_TYPE_END);
2005 return true;
2006 }
2007
2008 if (StrEqualsIgnoreCase(argv[1], "upgrade")) {
2009 _network_content_client.SelectUpgrade();
2010 return true;
2011 }
2012
2013 if (StrEqualsIgnoreCase(argv[1], "select")) {
2014 if (argc <= 2) {
2015 /* List selected content */
2016 IConsolePrint(CC_WHITE, "id, type, state, name");
2017 for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
2018 if ((*iter)->state != ContentInfo::SELECTED && (*iter)->state != ContentInfo::AUTOSELECTED) continue;
2019 OutputContentState(*iter);
2020 }
2021 } else if (StrEqualsIgnoreCase(argv[2], "all")) {
2022 /* The intention of this function was that you could download
2023 * everything after a filter was applied; but this never really
2024 * took off. Instead, a select few people used this functionality
2025 * to download every available package on BaNaNaS. This is not in
2026 * the spirit of this service. Additionally, these few people were
2027 * good for 70% of the consumed bandwidth of BaNaNaS. */
2028 IConsolePrint(CC_ERROR, "'select all' is no longer supported since 1.11.");
2029 } else {
2030 _network_content_client.Select((ContentID)atoi(argv[2]));
2031 }
2032 return true;
2033 }
2034
2035 if (StrEqualsIgnoreCase(argv[1], "unselect")) {
2036 if (argc <= 2) {
2037 IConsolePrint(CC_ERROR, "You must enter the id.");
2038 return false;
2039 }
2040 if (StrEqualsIgnoreCase(argv[2], "all")) {
2041 _network_content_client.UnselectAll();
2042 } else {
2043 _network_content_client.Unselect((ContentID)atoi(argv[2]));
2044 }
2045 return true;
2046 }
2047
2048 if (StrEqualsIgnoreCase(argv[1], "state")) {
2049 IConsolePrint(CC_WHITE, "id, type, state, name");
2050 for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
2051 if (argc > 2 && strcasestr((*iter)->name.c_str(), argv[2]) == nullptr) continue;
2052 OutputContentState(*iter);
2053 }
2054 return true;
2055 }
2056
2057 if (StrEqualsIgnoreCase(argv[1], "download")) {
2058 uint files;
2059 uint bytes;
2060 _network_content_client.DownloadSelectedContent(files, bytes);
2061 IConsolePrint(CC_DEFAULT, "Downloading {} file(s) ({} bytes).", files, bytes);
2062 return true;
2063 }
2064
2065 return false;
2066 }
2067 #endif /* defined(WITH_ZLIB) */
2068
2069 DEF_CONSOLE_CMD(ConFont)
2070 {
2071 if (argc == 0) {
2072 IConsolePrint(CC_HELP, "Manage the fonts configuration.");
2073 IConsolePrint(CC_HELP, "Usage 'font'.");
2074 IConsolePrint(CC_HELP, " Print out the fonts configuration.");
2075 IConsolePrint(CC_HELP, "Usage 'font [medium|small|large|mono] [<name>] [<size>] [aa|noaa]'.");
2076 IConsolePrint(CC_HELP, " Change the configuration for a font.");
2077 IConsolePrint(CC_HELP, " Omitting an argument will keep the current value.");
2078 IConsolePrint(CC_HELP, " Set <name> to \"\" for the sprite font (size and aa have no effect on sprite font).");
2079 return true;
2080 }
2081
2082 FontSize argfs;
2083 for (argfs = FS_BEGIN; argfs < FS_END; argfs++) {
2084 if (argc > 1 && StrEqualsIgnoreCase(argv[1], FontSizeToName(argfs))) break;
2085 }
2086
2087 /* First argument must be a FontSize. */
2088 if (argc > 1 && argfs == FS_END) return false;
2089
2090 if (argc > 2) {
2091 FontCacheSubSetting *setting = GetFontCacheSubSetting(argfs);
2092 std::string font = setting->font;
2093 uint size = setting->size;
2094 bool aa = setting->aa;
2095
2096 byte arg_index = 2;
2097 /* We may encounter "aa" or "noaa" but it must be the last argument. */
2098 if (StrEqualsIgnoreCase(argv[arg_index], "aa") || StrEqualsIgnoreCase(argv[arg_index], "noaa")) {
2099 aa = !StrStartsWithIgnoreCase(argv[arg_index++], "no");
2100 if (argc > arg_index) return false;
2101 } else {
2102 /* For <name> we want a string. */
2103 uint v;
2104 if (!GetArgumentInteger(&v, argv[arg_index])) {
2105 font = argv[arg_index++];
2106 }
2107 }
2108
2109 if (argc > arg_index) {
2110 /* For <size> we want a number. */
2111 uint v;
2112 if (GetArgumentInteger(&v, argv[arg_index])) {
2113 size = v;
2114 arg_index++;
2115 }
2116 }
2117
2118 if (argc > arg_index) {
2119 /* Last argument must be "aa" or "noaa". */
2120 if (!StrEqualsIgnoreCase(argv[arg_index], "aa") && !StrEqualsIgnoreCase(argv[arg_index], "noaa")) return false;
2121 aa = !StrStartsWithIgnoreCase(argv[arg_index++], "no");
2122 if (argc > arg_index) return false;
2123 }
2124
2125 SetFont(argfs, font, size, aa);
2126 }
2127
2128 for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
2129 FontCache *fc = FontCache::Get(fs);
2130 FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
2131 /* Make sure all non sprite fonts are loaded. */
2132 if (!setting->font.empty() && !fc->HasParent()) {
2133 InitFontCache(fs == FS_MONO);
2134 fc = FontCache::Get(fs);
2135 }
2136 IConsolePrint(CC_DEFAULT, "{}: \"{}\" {} {} [\"{}\" {} {}]", FontSizeToName(fs), fc->GetFontName(), fc->GetFontSize(), GetFontAAState(fs) ? "aa" : "noaa", setting->font, setting->size, setting->aa ? "aa" : "noaa");
2137 }
2138
2139 return true;
2140 }
2141
2142 DEF_CONSOLE_CMD(ConSetting)
2143 {
2144 if (argc == 0) {
2145 IConsolePrint(CC_HELP, "Change setting for all clients. Usage: 'setting <name> [<value>]'.");
2146 IConsolePrint(CC_HELP, "Omitting <value> will print out the current value of the setting.");
2147 return true;
2148 }
2149
2150 if (argc == 1 || argc > 3) return false;
2151
2152 if (argc == 2) {
2153 IConsoleGetSetting(argv[1]);
2154 } else {
2155 IConsoleSetSetting(argv[1], argv[2]);
2156 }
2157
2158 return true;
2159 }
2160
2161 DEF_CONSOLE_CMD(ConSettingNewgame)
2162 {
2163 if (argc == 0) {
2164 IConsolePrint(CC_HELP, "Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'.");
2165 IConsolePrint(CC_HELP, "Omitting <value> will print out the current value of the setting.");
2166 return true;
2167 }
2168
2169 if (argc == 1 || argc > 3) return false;
2170
2171 if (argc == 2) {
2172 IConsoleGetSetting(argv[1], true);
2173 } else {
2174 IConsoleSetSetting(argv[1], argv[2], true);
2175 }
2176
2177 return true;
2178 }
2179
2180 DEF_CONSOLE_CMD(ConListSettings)
2181 {
2182 if (argc == 0) {
2183 IConsolePrint(CC_HELP, "List settings. Usage: 'list_settings [<pre-filter>]'.");
2184 return true;
2185 }
2186
2187 if (argc > 2) return false;
2188
2189 IConsoleListSettings((argc == 2) ? argv[1] : nullptr);
2190 return true;
2191 }
2192
2193 DEF_CONSOLE_CMD(ConGamelogPrint)
2194 {
2195 if (argc == 0) {
2196 IConsolePrint(CC_HELP, "Print logged fundamental changes to the game since the start. Usage: 'gamelog'.");
2197 return true;
2198 }
2199
2200 _gamelog.PrintConsole();
2201 return true;
2202 }
2203
2204 DEF_CONSOLE_CMD(ConNewGRFReload)
2205 {
2206 if (argc == 0) {
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!");
2208 return true;
2209 }
2210
2211 ReloadNewGRFData();
2212 return true;
2213 }
2214
2215 DEF_CONSOLE_CMD(ConListDirs)
2216 {
2217 struct SubdirNameMap {
2218 Subdirectory subdir;
2219 const char *name;
2220 bool default_only;
2221 };
2222 static const SubdirNameMap subdir_name_map[] = {
2223 /* Game data directories */
2224 { BASESET_DIR, "baseset", false },
2225 { NEWGRF_DIR, "newgrf", false },
2226 { AI_DIR, "ai", false },
2227 { AI_LIBRARY_DIR, "ailib", false },
2228 { GAME_DIR, "gs", false },
2229 { GAME_LIBRARY_DIR, "gslib", false },
2230 { SCENARIO_DIR, "scenario", false },
2231 { HEIGHTMAP_DIR, "heightmap", false },
2232 /* Default save locations for user data */
2233 { SAVE_DIR, "save", true },
2234 { AUTOSAVE_DIR, "autosave", true },
2235 { SCREENSHOT_DIR, "screenshot", true },
2236 { SOCIAL_INTEGRATION_DIR, "social_integration", true },
2237 };
2238
2239 if (argc != 2) {
2240 IConsolePrint(CC_HELP, "List all search paths or default directories for various categories.");
2241 IConsolePrint(CC_HELP, "Usage: list_dirs <category>");
2242 std::string cats = subdir_name_map[0].name;
2243 bool first = true;
2244 for (const SubdirNameMap &sdn : subdir_name_map) {
2245 if (!first) cats = cats + ", " + sdn.name;
2246 first = false;
2247 }
2248 IConsolePrint(CC_HELP, "Valid categories: {}", cats);
2249 return true;
2250 }
2251
2252 std::set<std::string> seen_dirs;
2253 for (const SubdirNameMap &sdn : subdir_name_map) {
2254 if (!StrEqualsIgnoreCase(argv[1], sdn.name)) continue;
2255 bool found = false;
2256 for (Searchpath sp : _valid_searchpaths) {
2257 /* Get the directory */
2258 std::string path = FioGetDirectory(sp, sdn.subdir);
2259 /* Check it hasn't already been listed */
2260 if (seen_dirs.find(path) != seen_dirs.end()) continue;
2261 seen_dirs.insert(path);
2262 /* Check if exists and mark found */
2263 bool exists = FileExists(path);
2264 found |= exists;
2265 /* Print */
2266 if (!sdn.default_only || exists) {
2267 IConsolePrint(exists ? CC_DEFAULT : CC_INFO, "{} {}", path, exists ? "[ok]" : "[not found]");
2268 if (sdn.default_only) break;
2269 }
2270 }
2271 if (!found) {
2272 IConsolePrint(CC_ERROR, "No directories exist for category {}", argv[1]);
2273 }
2274 return true;
2275 }
2276
2277 IConsolePrint(CC_ERROR, "Invalid category name: {}", argv[1]);
2278 return false;
2279 }
2280
2281 DEF_CONSOLE_CMD(ConNewGRFProfile)
2282 {
2283 if (argc == 0) {
2284 IConsolePrint(CC_HELP, "Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
2285 IConsolePrint(CC_HELP, "Usage: 'newgrf_profile [list]':");
2286 IConsolePrint(CC_HELP, " List all NewGRFs that can be profiled, and their status.");
2287 IConsolePrint(CC_HELP, "Usage: 'newgrf_profile select <grf-num>...':");
2288 IConsolePrint(CC_HELP, " Select one or more GRFs for profiling.");
2289 IConsolePrint(CC_HELP, "Usage: 'newgrf_profile unselect <grf-num>...':");
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.");
2291 IConsolePrint(CC_HELP, "Usage: 'newgrf_profile start [<num-ticks>]':");
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.");
2293 IConsolePrint(CC_HELP, "Usage: 'newgrf_profile stop':");
2294 IConsolePrint(CC_HELP, " End profiling and write the collected data to CSV files.");
2295 IConsolePrint(CC_HELP, "Usage: 'newgrf_profile abort':");
2296 IConsolePrint(CC_HELP, " End profiling and discard all collected data.");
2297 return true;
2298 }
2299
2300 const std::vector<GRFFile *> &files = GetAllGRFFiles();
2301
2302 /* "list" sub-command */
2303 if (argc == 1 || StrStartsWithIgnoreCase(argv[1], "lis")) {
2304 IConsolePrint(CC_INFO, "Loaded GRF files:");
2305 int i = 1;
2306 for (GRFFile *grf : files) {
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;
2310 TextColour tc = active ? TC_LIGHT_BLUE : selected ? TC_GREEN : CC_INFO;
2311 const char *statustext = active ? " (active)" : selected ? " (selected)" : "";
2312 IConsolePrint(tc, "{}: [{:08X}] {}{}", i, BSWAP32(grf->grfid), grf->filename, statustext);
2313 i++;
2314 }
2315 return true;
2316 }
2317
2318 /* "select" sub-command */
2319 if (StrStartsWithIgnoreCase(argv[1], "sel") && argc >= 3) {
2320 for (size_t argnum = 2; argnum < argc; ++argnum) {
2321 int grfnum = atoi(argv[argnum]);
2322 if (grfnum < 1 || grfnum > (int)files.size()) { // safe cast, files.size() should not be larger than a few hundred in the most extreme cases
2323 IConsolePrint(CC_WARNING, "GRF number {} out of range, not added.", grfnum);
2324 continue;
2325 }
2326 GRFFile *grf = files[grfnum - 1];
2327 if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; })) {
2328 IConsolePrint(CC_WARNING, "GRF number {} [{:08X}] is already selected for profiling.", grfnum, BSWAP32(grf->grfid));
2329 continue;
2330 }
2331 _newgrf_profilers.emplace_back(grf);
2332 }
2333 return true;
2334 }
2335
2336 /* "unselect" sub-command */
2337 if (StrStartsWithIgnoreCase(argv[1], "uns") && argc >= 3) {
2338 for (size_t argnum = 2; argnum < argc; ++argnum) {
2339 if (StrEqualsIgnoreCase(argv[argnum], "all")) {
2340 _newgrf_profilers.clear();
2341 break;
2342 }
2343 int grfnum = atoi(argv[argnum]);
2344 if (grfnum < 1 || grfnum > (int)files.size()) {
2345 IConsolePrint(CC_WARNING, "GRF number {} out of range, not removing.", grfnum);
2346 continue;
2347 }
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);
2351 }
2352 return true;
2353 }
2354
2355 /* "start" sub-command */
2356 if (StrStartsWithIgnoreCase(argv[1], "sta")) {
2357 std::string grfids;
2358 size_t started = 0;
2359 for (NewGRFProfiler &pr : _newgrf_profilers) {
2360 if (!pr.active) {
2361 pr.Start();
2362 started++;
2363
2364 if (!grfids.empty()) grfids += ", ";
2365 fmt::format_to(std::back_inserter(grfids), "[{:08X}]", BSWAP32(pr.grffile->grfid));
2366 }
2367 }
2368 if (started > 0) {
2369 IConsolePrint(CC_DEBUG, "Started profiling for GRFID{} {}.", (started > 1) ? "s" : "", grfids);
2370
2371 if (argc >= 3) {
2372 uint64_t ticks = std::max(atoi(argv[2]), 1);
2373 NewGRFProfiler::StartTimer(ticks);
2374 IConsolePrint(CC_DEBUG, "Profiling will automatically stop after {} ticks.", ticks);
2375 }
2376 } else if (_newgrf_profilers.empty()) {
2377 IConsolePrint(CC_ERROR, "No GRFs selected for profiling, did not start.");
2378 } else {
2379 IConsolePrint(CC_ERROR, "Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2380 }
2381 return true;
2382 }
2383
2384 /* "stop" sub-command */
2385 if (StrStartsWithIgnoreCase(argv[1], "sto")) {
2386 NewGRFProfiler::FinishAll();
2387 return true;
2388 }
2389
2390 /* "abort" sub-command */
2391 if (StrStartsWithIgnoreCase(argv[1], "abo")) {
2392 for (NewGRFProfiler &pr : _newgrf_profilers) {
2393 pr.Abort();
2394 }
2395 NewGRFProfiler::AbortTimer();
2396 return true;
2397 }
2398
2399 return false;
2400 }
2401
2402 #ifdef _DEBUG
2403 /******************
2404 * debug commands
2405 ******************/
2406
2407 static void IConsoleDebugLibRegister()
2408 {
2409 IConsole::CmdRegister("resettile", ConResetTile);
2410 IConsole::AliasRegister("dbg_echo", "echo %A; echo %B");
2411 IConsole::AliasRegister("dbg_echo2", "echo %!");
2412 }
2413 #endif
2414
2415 DEF_CONSOLE_CMD(ConFramerate)
2416 {
2417 if (argc == 0) {
2418 IConsolePrint(CC_HELP, "Show frame rate and game speed information.");
2419 return true;
2420 }
2421
2422 ConPrintFramerate();
2423 return true;
2424 }
2425
2426 DEF_CONSOLE_CMD(ConFramerateWindow)
2427 {
2428 if (argc == 0) {
2429 IConsolePrint(CC_HELP, "Open the frame rate window.");
2430 return true;
2431 }
2432
2433 if (_network_dedicated) {
2434 IConsolePrint(CC_ERROR, "Can not open frame rate window on a dedicated server.");
2435 return false;
2436 }
2437
2438 ShowFramerateWindow();
2439 return true;
2440 }
2441
2442 static void ConDumpRoadTypes()
2443 {
2444 IConsolePrint(CC_DEFAULT, " Flags:");
2445 IConsolePrint(CC_DEFAULT, " c = catenary");
2446 IConsolePrint(CC_DEFAULT, " l = no level crossings");
2447 IConsolePrint(CC_DEFAULT, " X = no houses");
2448 IConsolePrint(CC_DEFAULT, " h = hidden");
2449 IConsolePrint(CC_DEFAULT, " T = buildable by towns");
2450
2451 std::map<uint32_t, const GRFFile *> grfs;
2452 for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
2453 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
2454 if (rti->label == 0) continue;
2455 uint32_t grfid = 0;
2456 const GRFFile *grf = rti->grffile[ROTSG_GROUND];
2457 if (grf != nullptr) {
2458 grfid = grf->grfid;
2459 grfs.emplace(grfid, grf);
2460 }
2461 IConsolePrint(CC_DEFAULT, " {:02d} {} {:c}{:c}{:c}{:c}, Flags: {}{}{}{}{}, GRF: {:08X}, {}",
2462 (uint)rt,
2463 RoadTypeIsTram(rt) ? "Tram" : "Road",
2464 rti->label >> 24, rti->label >> 16, rti->label >> 8, rti->label,
2465 HasBit(rti->flags, ROTF_CATENARY) ? 'c' : '-',
2466 HasBit(rti->flags, ROTF_NO_LEVEL_CROSSING) ? 'l' : '-',
2467 HasBit(rti->flags, ROTF_NO_HOUSES) ? 'X' : '-',
2468 HasBit(rti->flags, ROTF_HIDDEN) ? 'h' : '-',
2469 HasBit(rti->flags, ROTF_TOWN_BUILD) ? 'T' : '-',
2470 BSWAP32(grfid),
2471 GetStringPtr(rti->strings.name)
2472 );
2473 }
2474 for (const auto &grf : grfs) {
2475 IConsolePrint(CC_DEFAULT, " GRF: {:08X} = {}", BSWAP32(grf.first), grf.second->filename);
2476 }
2477 }
2478
2479 static void ConDumpRailTypes()
2480 {
2481 IConsolePrint(CC_DEFAULT, " Flags:");
2482 IConsolePrint(CC_DEFAULT, " c = catenary");
2483 IConsolePrint(CC_DEFAULT, " l = no level crossings");
2484 IConsolePrint(CC_DEFAULT, " h = hidden");
2485 IConsolePrint(CC_DEFAULT, " s = no sprite combine");
2486 IConsolePrint(CC_DEFAULT, " a = always allow 90 degree turns");
2487 IConsolePrint(CC_DEFAULT, " d = always disallow 90 degree turns");
2488
2489 std::map<uint32_t, const GRFFile *> grfs;
2490 for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
2491 const RailTypeInfo *rti = GetRailTypeInfo(rt);
2492 if (rti->label == 0) continue;
2493 uint32_t grfid = 0;
2494 const GRFFile *grf = rti->grffile[RTSG_GROUND];
2495 if (grf != nullptr) {
2496 grfid = grf->grfid;
2497 grfs.emplace(grfid, grf);
2498 }
2499 IConsolePrint(CC_DEFAULT, " {:02d} {:c}{:c}{:c}{:c}, Flags: {}{}{}{}{}{}, GRF: {:08X}, {}",
2500 (uint)rt,
2501 rti->label >> 24, rti->label >> 16, rti->label >> 8, rti->label,
2502 HasBit(rti->flags, RTF_CATENARY) ? 'c' : '-',
2503 HasBit(rti->flags, RTF_NO_LEVEL_CROSSING) ? 'l' : '-',
2504 HasBit(rti->flags, RTF_HIDDEN) ? 'h' : '-',
2505 HasBit(rti->flags, RTF_NO_SPRITE_COMBINE) ? 's' : '-',
2506 HasBit(rti->flags, RTF_ALLOW_90DEG) ? 'a' : '-',
2507 HasBit(rti->flags, RTF_DISALLOW_90DEG) ? 'd' : '-',
2508 BSWAP32(grfid),
2509 GetStringPtr(rti->strings.name)
2510 );
2511 }
2512 for (const auto &grf : grfs) {
2513 IConsolePrint(CC_DEFAULT, " GRF: {:08X} = {}", BSWAP32(grf.first), grf.second->filename);
2514 }
2515 }
2516
2517 static void ConDumpCargoTypes()
2518 {
2519 IConsolePrint(CC_DEFAULT, " Cargo classes:");
2520 IConsolePrint(CC_DEFAULT, " p = passenger");
2521 IConsolePrint(CC_DEFAULT, " m = mail");
2522 IConsolePrint(CC_DEFAULT, " x = express");
2523 IConsolePrint(CC_DEFAULT, " a = armoured");
2524 IConsolePrint(CC_DEFAULT, " b = bulk");
2525 IConsolePrint(CC_DEFAULT, " g = piece goods");
2526 IConsolePrint(CC_DEFAULT, " l = liquid");
2527 IConsolePrint(CC_DEFAULT, " r = refrigerated");
2528 IConsolePrint(CC_DEFAULT, " h = hazardous");
2529 IConsolePrint(CC_DEFAULT, " c = covered/sheltered");
2530 IConsolePrint(CC_DEFAULT, " S = special");
2531
2532 std::map<uint32_t, const GRFFile *> grfs;
2533 for (const CargoSpec *spec : CargoSpec::Iterate()) {
2534 if (!spec->IsValid()) continue;
2535 uint32_t grfid = 0;
2536 const GRFFile *grf = spec->grffile;
2537 if (grf != nullptr) {
2538 grfid = grf->grfid;
2539 grfs.emplace(grfid, grf);
2540 }
2541 IConsolePrint(CC_DEFAULT, " {:02d} Bit: {:2d}, Label: {:c}{:c}{:c}{:c}, Callback mask: 0x{:02X}, Cargo class: {}{}{}{}{}{}{}{}{}{}{}, GRF: {:08X}, {}",
2542 spec->Index(),
2543 spec->bitnum,
2544 spec->label >> 24, spec->label >> 16, spec->label >> 8, spec->label,
2545 spec->callback_mask,
2546 (spec->classes & CC_PASSENGERS) != 0 ? 'p' : '-',
2547 (spec->classes & CC_MAIL) != 0 ? 'm' : '-',
2548 (spec->classes & CC_EXPRESS) != 0 ? 'x' : '-',
2549 (spec->classes & CC_ARMOURED) != 0 ? 'a' : '-',
2550 (spec->classes & CC_BULK) != 0 ? 'b' : '-',
2551 (spec->classes & CC_PIECE_GOODS) != 0 ? 'g' : '-',
2552 (spec->classes & CC_LIQUID) != 0 ? 'l' : '-',
2553 (spec->classes & CC_REFRIGERATED) != 0 ? 'r' : '-',
2554 (spec->classes & CC_HAZARDOUS) != 0 ? 'h' : '-',
2555 (spec->classes & CC_COVERED) != 0 ? 'c' : '-',
2556 (spec->classes & CC_SPECIAL) != 0 ? 'S' : '-',
2557 BSWAP32(grfid),
2558 GetStringPtr(spec->name)
2559 );
2560 }
2561 for (const auto &grf : grfs) {
2562 IConsolePrint(CC_DEFAULT, " GRF: {:08X} = {}", BSWAP32(grf.first), grf.second->filename);
2563 }
2564 }
2565
2566
2567 DEF_CONSOLE_CMD(ConDumpInfo)
2568 {
2569 if (argc != 2) {
2570 IConsolePrint(CC_HELP, "Dump debugging information.");
2571 IConsolePrint(CC_HELP, "Usage: 'dump_info roadtypes|railtypes|cargotypes'.");
2572 IConsolePrint(CC_HELP, " Show information about road/tram types, rail types or cargo types.");
2573 return true;
2574 }
2575
2576 if (StrEqualsIgnoreCase(argv[1], "roadtypes")) {
2577 ConDumpRoadTypes();
2578 return true;
2579 }
2580
2581 if (StrEqualsIgnoreCase(argv[1], "railtypes")) {
2582 ConDumpRailTypes();
2583 return true;
2584 }
2585
2586 if (StrEqualsIgnoreCase(argv[1], "cargotypes")) {
2587 ConDumpCargoTypes();
2588 return true;
2589 }
2590
2591 return false;
2592 }
2593
2594 /*******************************
2595 * console command registration
2596 *******************************/
2597
2598 void IConsoleStdLibRegister()
2599 {
2600 IConsole::CmdRegister("debug_level", ConDebugLevel);
2601 IConsole::CmdRegister("echo", ConEcho);
2602 IConsole::CmdRegister("echoc", ConEchoC);
2603 IConsole::CmdRegister("exec", ConExec);
2604 IConsole::CmdRegister("exit", ConExit);
2605 IConsole::CmdRegister("part", ConPart);
2606 IConsole::CmdRegister("help", ConHelp);
2607 IConsole::CmdRegister("info_cmd", ConInfoCmd);
2608 IConsole::CmdRegister("list_cmds", ConListCommands);
2609 IConsole::CmdRegister("list_aliases", ConListAliases);
2610 IConsole::CmdRegister("newgame", ConNewGame);
2611 IConsole::CmdRegister("restart", ConRestart);
2612 IConsole::CmdRegister("reload", ConReload);
2613 IConsole::CmdRegister("getseed", ConGetSeed);
2614 IConsole::CmdRegister("getdate", ConGetDate);
2615 IConsole::CmdRegister("getsysdate", ConGetSysDate);
2616 IConsole::CmdRegister("quit", ConExit);
2617 IConsole::CmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
2618 IConsole::CmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
2619 IConsole::CmdRegister("return", ConReturn);
2620 IConsole::CmdRegister("screenshot", ConScreenShot);
2621 IConsole::CmdRegister("script", ConScript);
2622 IConsole::CmdRegister("zoomto", ConZoomToLevel);
2623 IConsole::CmdRegister("scrollto", ConScrollToTile);
2624 IConsole::CmdRegister("alias", ConAlias);
2625 IConsole::CmdRegister("load", ConLoad);
2626 IConsole::CmdRegister("load_save", ConLoad);
2627 IConsole::CmdRegister("load_scenario", ConLoadScenario);
2628 IConsole::CmdRegister("load_heightmap", ConLoadHeightmap);
2629 IConsole::CmdRegister("rm", ConRemove);
2630 IConsole::CmdRegister("save", ConSave);
2631 IConsole::CmdRegister("saveconfig", ConSaveConfig);
2632 IConsole::CmdRegister("ls", ConListFiles);
2633 IConsole::CmdRegister("list_saves", ConListFiles);
2634 IConsole::CmdRegister("list_scenarios", ConListScenarios);
2635 IConsole::CmdRegister("list_heightmaps", ConListHeightmaps);
2636 IConsole::CmdRegister("cd", ConChangeDirectory);
2637 IConsole::CmdRegister("pwd", ConPrintWorkingDirectory);
2638 IConsole::CmdRegister("clear", ConClearBuffer);
2639 IConsole::CmdRegister("font", ConFont);
2640 IConsole::CmdRegister("setting", ConSetting);
2641 IConsole::CmdRegister("setting_newgame", ConSettingNewgame);
2642 IConsole::CmdRegister("list_settings", ConListSettings);
2643 IConsole::CmdRegister("gamelog", ConGamelogPrint);
2644 IConsole::CmdRegister("rescan_newgrf", ConRescanNewGRF);
2645 IConsole::CmdRegister("list_dirs", ConListDirs);
2646
2647 IConsole::AliasRegister("dir", "ls");
2648 IConsole::AliasRegister("del", "rm %+");
2649 IConsole::AliasRegister("newmap", "newgame");
2650 IConsole::AliasRegister("patch", "setting %+");
2651 IConsole::AliasRegister("set", "setting %+");
2652 IConsole::AliasRegister("set_newgame", "setting_newgame %+");
2653 IConsole::AliasRegister("list_patches", "list_settings %+");
2654 IConsole::AliasRegister("developer", "setting developer %+");
2655
2656 IConsole::CmdRegister("list_ai_libs", ConListAILibs);
2657 IConsole::CmdRegister("list_ai", ConListAI);
2658 IConsole::CmdRegister("reload_ai", ConReloadAI);
2659 IConsole::CmdRegister("rescan_ai", ConRescanAI);
2660 IConsole::CmdRegister("start_ai", ConStartAI);
2661 IConsole::CmdRegister("stop_ai", ConStopAI);
2662
2663 IConsole::CmdRegister("list_game", ConListGame);
2664 IConsole::CmdRegister("list_game_libs", ConListGameLibs);
2665 IConsole::CmdRegister("rescan_game", ConRescanGame);
2666
2667 IConsole::CmdRegister("companies", ConCompanies);
2668 IConsole::AliasRegister("players", "companies");
2669
2670 /* networking functions */
2671
2672 /* Content downloading is only available with ZLIB */
2673 #if defined(WITH_ZLIB)
2674 IConsole::CmdRegister("content", ConContent);
2675 #endif /* defined(WITH_ZLIB) */
2676
2677 /*** Networking commands ***/
2678 IConsole::CmdRegister("say", ConSay, ConHookNeedNetwork);
2679 IConsole::CmdRegister("say_company", ConSayCompany, ConHookNeedNetwork);
2680 IConsole::AliasRegister("say_player", "say_company %+");
2681 IConsole::CmdRegister("say_client", ConSayClient, ConHookNeedNetwork);
2682
2683 IConsole::CmdRegister("connect", ConNetworkConnect, ConHookClientOnly);
2684 IConsole::CmdRegister("clients", ConNetworkClients, ConHookNeedNetwork);
2685 IConsole::CmdRegister("status", ConStatus, ConHookServerOnly);
2686 IConsole::CmdRegister("server_info", ConServerInfo, ConHookServerOnly);
2687 IConsole::AliasRegister("info", "server_info");
2688 IConsole::CmdRegister("reconnect", ConNetworkReconnect, ConHookClientOnly);
2689 IConsole::CmdRegister("rcon", ConRcon, ConHookNeedNetwork);
2690
2691 IConsole::CmdRegister("join", ConJoinCompany, ConHookNeedNetwork);
2692 IConsole::AliasRegister("spectate", "join 255");
2693 IConsole::CmdRegister("move", ConMoveClient, ConHookServerOnly);
2694 IConsole::CmdRegister("reset_company", ConResetCompany, ConHookServerOnly);
2695 IConsole::AliasRegister("clean_company", "reset_company %A");
2696 IConsole::CmdRegister("client_name", ConClientNickChange, ConHookServerOnly);
2697 IConsole::CmdRegister("kick", ConKick, ConHookServerOnly);
2698 IConsole::CmdRegister("ban", ConBan, ConHookServerOnly);
2699 IConsole::CmdRegister("unban", ConUnBan, ConHookServerOnly);
2700 IConsole::CmdRegister("banlist", ConBanList, ConHookServerOnly);
2701
2702 IConsole::CmdRegister("pause", ConPauseGame, ConHookServerOrNoNetwork);
2703 IConsole::CmdRegister("unpause", ConUnpauseGame, ConHookServerOrNoNetwork);
2704
2705 IConsole::CmdRegister("company_pw", ConCompanyPassword, ConHookNeedNetwork);
2706 IConsole::AliasRegister("company_password", "company_pw %+");
2707
2708 IConsole::AliasRegister("net_frame_freq", "setting frame_freq %+");
2709 IConsole::AliasRegister("net_sync_freq", "setting sync_freq %+");
2710 IConsole::AliasRegister("server_pw", "setting server_password %+");
2711 IConsole::AliasRegister("server_password", "setting server_password %+");
2712 IConsole::AliasRegister("rcon_pw", "setting rcon_password %+");
2713 IConsole::AliasRegister("rcon_password", "setting rcon_password %+");
2714 IConsole::AliasRegister("name", "setting client_name %+");
2715 IConsole::AliasRegister("server_name", "setting server_name %+");
2716 IConsole::AliasRegister("server_port", "setting server_port %+");
2717 IConsole::AliasRegister("max_clients", "setting max_clients %+");
2718 IConsole::AliasRegister("max_companies", "setting max_companies %+");
2719 IConsole::AliasRegister("max_join_time", "setting max_join_time %+");
2720 IConsole::AliasRegister("pause_on_join", "setting pause_on_join %+");
2721 IConsole::AliasRegister("autoclean_companies", "setting autoclean_companies %+");
2722 IConsole::AliasRegister("autoclean_protected", "setting autoclean_protected %+");
2723 IConsole::AliasRegister("autoclean_unprotected", "setting autoclean_unprotected %+");
2724 IConsole::AliasRegister("restart_game_year", "setting restart_game_year %+");
2725 IConsole::AliasRegister("min_players", "setting min_active_clients %+");
2726 IConsole::AliasRegister("reload_cfg", "setting reload_cfg %+");
2727
2728 /* debugging stuff */
2729 #ifdef _DEBUG
2730 IConsoleDebugLibRegister();
2731 #endif
2732 IConsole::CmdRegister("fps", ConFramerate);
2733 IConsole::CmdRegister("fps_wnd", ConFramerateWindow);
2734
2735 /* NewGRF development stuff */
2736 IConsole::CmdRegister("reload_newgrfs", ConNewGRFReload, ConHookNewGRFDeveloperTool);
2737 IConsole::CmdRegister("newgrf_profile", ConNewGRFProfile, ConHookNewGRFDeveloperTool);
2738
2739 IConsole::CmdRegister("dump_info", ConDumpInfo);
2740 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
game.hpp
RoadTypeInfo::flags
RoadTypeFlags flags
Bit mask of road type flags.
Definition: road.h:127
NetworkClientSendRcon
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
Definition: network_client.cpp:1273
network_content.h
ConsoleFileList::show_dirs
bool show_dirs
Whether to show directories in the file list.
Definition: console_cmds.cpp:83
StrStartsWithIgnoreCase
bool StrStartsWithIgnoreCase(std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix, ignoring case.
Definition: string.cpp:300
ContentCallback
Callbacks for notifying others about incoming data.
Definition: network_content.h:29
RoadTypeInfo
Definition: road.h:78
CC_INFO
static const TextColour CC_INFO
Colour for information lines.
Definition: console_type.h:27
ROTSG_GROUND
@ ROTSG_GROUND
Required: Main group of ground images.
Definition: road.h:62
CC_HAZARDOUS
@ CC_HAZARDOUS
Hazardous cargo (Nuclear Fuel, Explosives, etc.)
Definition: cargotype.h:61
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
Definition: string.cpp:88
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:29
ContentInfo::name
std::string name
Name of the content.
Definition: tcp_content_type.h:67
CC_COVERED
@ CC_COVERED
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
Definition: cargotype.h:62
IConsoleCmd::proc
IConsoleCmdProc * proc
process executed when command is typed
Definition: console_internal.h:39
AIConfig
Definition: ai_config.hpp:16
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:547
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition: fileio_type.h:19
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
SAVE_DIR
@ SAVE_DIR
Base directory for all savegames.
Definition: fileio_type.h:110
NetworkServerShowStatusToConsole
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
Definition: network_server.cpp:1996
ContentInfo::type
ContentType type
Type of content.
Definition: tcp_content_type.h:63
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
ClientNetworkContentSocketHandler::End
ConstContentIterator End() const
Get the end of the content inf iterator.
Definition: network_content.h:141
ReloadNewGRFData
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3334
SM_START_HEIGHTMAP
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition: openttd.h:38
GUISettings::newgrf_developer_tools
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Definition: settings_type.h:216
ScreenshotType
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
ConPrintFramerate
void ConPrintFramerate()
Print performance statistics to game console.
Definition: framerate_gui.cpp:1043
FontCacheSubSetting
Settings for a single font.
Definition: fontcache.h:207
SM_LOAD_GAME
@ SM_LOAD_GAME
Load game, Play Scenario.
Definition: openttd.h:32
OutputContentState
static void OutputContentState(const ContentInfo *const ci)
Outputs content state information to console.
Definition: console_cmds.cpp:1974
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition: viewport_type.h:74
command_func.h
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3159
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
RTF_NO_SPRITE_COMBINE
@ RTF_NO_SPRITE_COMBINE
Bit number for using non-combined junctions.
Definition: rail.h:29
Map::LogX
static debug_inline uint LogX()
Logarithm of the map size along the X side.
Definition: map_func.h:251
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:27
timer_game_calendar.h
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:209
GUISettings::autosave_on_exit
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
Definition: settings_type.h:163
_gamelog
Gamelog _gamelog
Gamelog instance.
Definition: gamelog.cpp:31
BASESET_DIR
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:116
SaveOrLoad
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.
Definition: saveload.cpp:3050
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
Notify the server of this client wanting to be moved to another company.
Definition: network_client.cpp:1284
ICON_CMDLN_SIZE
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
Definition: console_internal.h:15
SC_HEIGHTMAP
@ SC_HEIGHTMAP
Heightmap of the world.
Definition: screenshot.h:24
CC_EXPRESS
@ CC_EXPRESS
Express cargo (Goods, Food, Candy, but also possible for passengers)
Definition: cargotype.h:55
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
GAME_LIBRARY_DIR
@ GAME_LIBRARY_DIR
Subdirectory for all GS libraries.
Definition: fileio_type.h:122
NewGRFProfiler::grffile
const GRFFile * grffile
Which GRF is being profiled.
Definition: newgrf_profiling.h:52
SaveToConfig
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1453
NewGRFProfiler::AbortTimer
static void AbortTimer()
Abort the timeout timer, so the timer callback is never called.
Definition: newgrf_profiling.cpp:176
SCREENSHOT_DIR
@ SCREENSHOT_DIR
Subdirectory for all screenshots.
Definition: fileio_type.h:123
ROTF_NO_LEVEL_CROSSING
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
Definition: road.h:39
NetworkCompanyHasClients
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
Definition: network_server.cpp:2175
_console_file_list_savegame
static ConsoleFileList _console_file_list_savegame
File storage cache for savegames.
Definition: console_cmds.cpp:87
Searchpath
Searchpath
Types of searchpaths OpenTTD might use.
Definition: fileio_type.h:132
misc_cmd.h
FontCacheSubSetting::aa
bool aa
Whether to do anti aliasing or not.
Definition: fontcache.h:210
IConsole::AliasGet
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
Definition: console.cpp:195
NetworkServerDoMove
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
Definition: network_server.cpp:2067
RailTypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:127
DFT_GAME_FILE
@ DFT_GAME_FILE
Save game or scenario file.
Definition: fileio_type.h:31
HEIGHTMAP_DIR
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
Definition: fileio_type.h:113
GetArgumentInteger
bool GetArgumentInteger(uint32_t *value, const char *arg)
Change a string into its number representation.
Definition: console.cpp:129
AI::CanStartNew
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:30
RequestNewGRFScan
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition: openttd.cpp:1546
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:93
saveload.h
fileio_func.h
CargoSpec::Iterate
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
Definition: cargotype.h:190
AUTOSAVE_DIR
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
Definition: fileio_type.h:111
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
SC_ZOOMEDIN
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
ZOOM_LVL_MAX
@ ZOOM_LVL_MAX
Maximum zoom level.
Definition: zoom_type.h:44
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:71
Company::IsValidHumanID
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:150
SetDebugString
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
Definition: debug.cpp:145
CC_LIQUID
@ CC_LIQUID
Liquids (Oil, Water, Rubber)
Definition: cargotype.h:59
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
CONTENT_TYPE_END
@ CONTENT_TYPE_END
Helper to mark the end of the types.
Definition: tcp_content_type.h:30
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:53
NetworkServerSendChat
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.
Definition: network_server.cpp:1271
RailTypeInfo::strings
struct RailTypeInfo::@26 strings
Strings associated with the rail type.
_redirect_console_to_client
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
Definition: network.cpp:66
gamelog.h
fios.h
StartupEngines
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:761
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
CalculateCompanyValue
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:149
FiosGetCurrentPath
std::string FiosGetCurrentPath()
Get the current path/working directory.
Definition: fios.cpp:133
StartNewGameWithoutGUI
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
Definition: genworld_gui.cpp:1069
ContentInfo::md5sum
MD5Hash md5sum
The MD5 checksum.
Definition: tcp_content_type.h:72
GUISettings::zoom_max
ZoomLevel zoom_max
maximum zoom out level
Definition: settings_type.h:158
FileList
List of file information.
Definition: fios.h:88
ConsoleFileList::InvalidateFileList
void InvalidateFileList()
Declare the file storage cache as being invalid, also clears all stored files.
Definition: console_cmds.cpp:64
ConstContentIterator
const typedef ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
Definition: network_content.h:26
IConsoleAlias::cmdline
std::string cmdline
command(s) that is/are being aliased
Definition: console_internal.h:59
INVALID_ADMIN_ID
static const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
Definition: network_type.h:64
genworld.h
ContentType
ContentType
The values in the enum are important; they are used as database 'keys'.
Definition: tcp_content_type.h:18
FontCacheSubSetting::size
uint size
The (requested) size of the font.
Definition: fontcache.h:209
_redirect_console_to_admin
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
Definition: network_admin.cpp:32
CC_DEFAULT
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
IConsoleCmd::hook
IConsoleHook * hook
any special trigger action that needs executing
Definition: console_internal.h:40
network_base.h
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
ai.hpp
FileList::FindItem
const FiosItem * FindItem(const std::string_view file)
Find file information of a file by its name from the file list.
Definition: fios.cpp:102
NetworkChangeCompanyPassword
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
Definition: network.cpp:157
IConsoleCmd::name
std::string name
name of command
Definition: console_internal.h:38
screenshot.h
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:63
ROTF_CATENARY
@ ROTF_CATENARY
Bit number for adding catenary.
Definition: road.h:38
ClientNetworkContentSocketHandler::RequestContentList
void RequestContentList(ContentType type)
Request the content list for the given type.
Definition: network_content.cpp:189
Pool::MAX_SIZE
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:84
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:114
company_cmd.h
RailTypeInfo::name
StringID name
Name of this rail type.
Definition: rail.h:176
ZOOM_LVL_MIN
@ ZOOM_LVL_MIN
Minimum zoom level.
Definition: zoom_type.h:43
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
FileToSaveLoad::abstract_ftype
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:393
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:51
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition: viewport_type.h:73
RTF_DISALLOW_90DEG
@ RTF_DISALLOW_90DEG
Bit number for never allowed 90 degree turns, regardless of setting.
Definition: rail.h:31
AI::GetConsoleLibraryList
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:298
BASE_DIR
@ BASE_DIR
Base directory for all subdirectories.
Definition: fileio_type.h:109
GetDebugString
std::string GetDebugString()
Print out the current debug-level.
Definition: debug.cpp:210
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
IConsole::CmdRegister
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
Definition: console.cpp:162
COMPANY_NEW_COMPANY
@ COMPANY_NEW_COMPANY
The client wants a new company.
Definition: company_type.h:34
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition: fileio_type.h:49
_script_current_depth
static uint _script_current_depth
Depth of scripts running (used to abort execution when #ConReturn is encountered).
Definition: console_cmds.cpp:54
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:345
CC_SPECIAL
@ CC_SPECIAL
Special bit used for livery refit tricks instead of normal cargoes.
Definition: cargotype.h:63
NetworkSettings::last_joined
std::string last_joined
Last joined server.
Definition: settings_type.h:332
FontCache::HasParent
bool HasParent()
Check whether the font cache has a parent.
Definition: fontcache.h:155
SLO_SAVE
@ SLO_SAVE
File is being saved.
Definition: fileio_type.h:50
settings_func.h
NewGRFProfiler::StartTimer
static void StartTimer(uint64_t ticks)
Start the timeout timer that will finish all profiling sessions.
Definition: newgrf_profiling.cpp:168
CC_HELP
static const TextColour CC_HELP
Colour for help lines.
Definition: console_type.h:26
AI_DIR
@ AI_DIR
Subdirectory for all AI files.
Definition: fileio_type.h:119
RTF_CATENARY
@ RTF_CATENARY
Bit number for drawing a catenary.
Definition: rail.h:26
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition: company_type.h:69
ClientNetworkGameSocketHandler::IsConnected
static bool IsConnected()
Check whether the client is actually connected (and in the game).
Definition: network_client.cpp:559
_console_file_list_scenario
static ConsoleFileList _console_file_list_scenario
File storage cache for scenarios.
Definition: console_cmds.cpp:88
FioFOpenFile
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.
Definition: fileio.cpp:263
console_internal.h
StrTrimInPlace
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
Definition: string.cpp:288
ClientNetworkContentSocketHandler::UnselectAll
void UnselectAll()
Unselect everything that we've not downloaded so far.
Definition: network_content.cpp:912
IConsoleCmdExec
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:293
Game::GetConsoleLibraryList
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator)
Wrapper function for GameScanner::GetConsoleLibraryList.
Definition: game_core.cpp:228
CC_PIECE_GOODS
@ CC_PIECE_GOODS
Piece goods (Livestock, Wood, Steel, Paper)
Definition: cargotype.h:58
Game::GetConsoleList
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for GameScanner::GetConsoleList.
Definition: game_core.cpp:223
FontCacheSubSetting::font
std::string font
The name of the font, or path to the font.
Definition: fontcache.h:208
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:52
FileExists
bool FileExists(const std::string &filename)
Test whether the given filename exists.
Definition: fileio.cpp:140
RTF_ALLOW_90DEG
@ RTF_ALLOW_90DEG
Bit number for always allowed 90 degree turns, regardless of setting.
Definition: rail.h:30
InitFontCache
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
Definition: fontcache.cpp:197
CC_BULK
@ CC_BULK
Bulk cargo (Coal, Grain etc., Ores, Fruit)
Definition: cargotype.h:57
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:19
IConsoleCmd
Definition: console_internal.h:35
FiosItem
Deals with finding savegames.
Definition: fios.h:79
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
ClientNetworkContentSocketHandler::Unselect
void Unselect(ContentID cid)
Unselect a specific content id.
Definition: network_content.cpp:880
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
CHR_ALLOW
@ CHR_ALLOW
Allow command execution.
Definition: console_internal.h:20
RailTypeInfo::label
RailTypeLabel label
Unique 32 bit rail type identifier.
Definition: rail.h:236
ShowFramerateWindow
void ShowFramerateWindow()
Open the general framerate window.
Definition: framerate_gui.cpp:1030
NetworkPrintClients
void NetworkPrintClients()
Print all the clients to the console.
Definition: network_server.cpp:2200
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition: timer_game_calendar.cpp:42
safeguards.h
ConsoleFileList::abstract_filetype
AbstractFileType abstract_filetype
The abstract file type to list.
Definition: console_cmds.cpp:82
NetworkCompanyState::password
std::string password
The password for the company.
Definition: network_type.h:75
GAME_DIR
@ GAME_DIR
Subdirectory for all game scripts.
Definition: fileio_type.h:121
SCENARIO_DIR
@ SCENARIO_DIR
Base directory for all scenarios.
Definition: fileio_type.h:112
NetworkServerChangeClientName
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
Definition: network_server.cpp:1696
FT_INVALID
@ FT_INVALID
Invalid or unknown file type.
Definition: fileio_type.h:22
ScriptConfig::StringToSettings
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
Definition: script_config.cpp:157
_network_company_states
NetworkCompanyState * _network_company_states
Statistics about some companies.
Definition: network.cpp:64
ContentInfo::SELECTED
@ SELECTED
The content has been manually selected.
Definition: tcp_content_type.h:56
CC_DEBUG
static const TextColour CC_DEBUG
Colour for debug output.
Definition: console_type.h:28
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
GetFontCacheSubSetting
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
Definition: fontcache.h:232
rail.h
RTF_HIDDEN
@ RTF_HIDDEN
Bit number for hiding from selection.
Definition: rail.h:28
NetworkServerKickOrBanIP
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
Definition: network_server.cpp:2126
road.h
network_client.h
RTSG_GROUND
@ RTSG_GROUND
Main group of ground images.
Definition: rail.h:52
ConsoleFileList::ValidateFileList
void ValidateFileList(bool force_reload=false)
(Re-)validate the file storage cache.
Definition: console_cmds.cpp:74
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition: road.h:103
NewGRFProfiler::active
bool active
Is this profiler collecting data.
Definition: newgrf_profiling.h:53
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:62
stdafx.h
ClientNetworkContentSocketHandler::DownloadSelectedContent
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
Definition: network_content.cpp:309
Company::IsHumanID
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
Definition: company_base.h:163
FT_SAVEGAME
@ FT_SAVEGAME
old or new savegame
Definition: fileio_type.h:18
RailTypeInfo::grffile
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
Definition: rail.h:276
landscape.h
CC_COMMAND
static const TextColour CC_COMMAND
Colour for the console's commands.
Definition: console_type.h:29
NEWGRF_DIR
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
ConsoleFileList::file_list_valid
bool file_list_valid
If set, the file list is valid.
Definition: console_cmds.cpp:84
viewport_func.h
NetworkCompanyIsPassworded
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:209
NetworkClientInfo::client_id
ClientID client_id
Client identifier (same as ClientState->client_id)
Definition: network_base.h:25
ScriptConfig::Change
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.
Definition: script_config.cpp:21
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:93
ConsoleFileList
File list storage for the console, for caching the last 'ls' command.
Definition: console_cmds.cpp:57
GENERATE_NEW_SEED
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
Definition: genworld.h:24
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:65
IConsoleAlias::name
std::string name
name of the alias
Definition: console_internal.h:58
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:157
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition: map_func.h:270
_console_file_list_heightmap
static ConsoleFileList _console_file_list_heightmap
File storage cache for heightmaps.
Definition: console_cmds.cpp:89
GameSettings::ai
AISettings ai
what may the AI do?
Definition: settings_type.h:621
_network_content_client
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
Definition: network_content.cpp:35
RoadTypeInfo::grffile
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition: road.h:187
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:48
Gamelog::PrintConsole
void PrintConsole()
Print the gamelog data to the console.
Definition: gamelog.cpp:310
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
strings_func.h
NewGRFProfiler
Callback profiler for NewGRF development.
Definition: newgrf_profiling.h:23
IConsoleListSettings
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Definition: settings.cpp:1927
FontCache::GetFontName
virtual std::string GetFontName()=0
Get the name of this font.
SC_WORLD
@ SC_WORLD
World screenshot.
Definition: screenshot.h:23
FT_NONE
@ FT_NONE
nothing to do
Definition: fileio_type.h:17
FontCache
Font cache for basic fonts.
Definition: fontcache.h:21
GameCreationSettings::generation_seed
uint32_t generation_seed
noise seed for world generation
Definition: settings_type.h:340
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:49
CC_ARMOURED
@ CC_ARMOURED
Armoured cargo (Valuables, Gold, Diamonds)
Definition: cargotype.h:56
Pool::PoolItem<&_company_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:365
GameCreationSettings::map_y
uint8_t map_y
Y size of map.
Definition: settings_type.h:344
RoadTypeInfo::label
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition: road.h:147
GameCreationSettings::map_x
uint8_t map_x
X size of map.
Definition: settings_type.h:343
FileToSaveLoad::Set
void Set(const FiosItem &item)
Set the title of the file.
Definition: saveload.cpp:3239
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
ContentInfo::AUTOSELECTED
@ AUTOSELECTED
The content has been selected as dependency.
Definition: tcp_content_type.h:57
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition: company_type.h:63
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
RAILTYPE_END
@ RAILTYPE_END
Used for iterations.
Definition: rail_type.h:33
CC_REFRIGERATED
@ CC_REFRIGERATED
Refrigerated cargo (Food, Fruit)
Definition: cargotype.h:60
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition: window.cpp:1128
DEF_CONSOLE_CMD
DEF_CONSOLE_CMD(ConResetEngines)
Reset status of all engines.
Definition: console_cmds.cpp:200
WC_CONSOLE
@ WC_CONSOLE
Console; Window numbers:
Definition: window_type.h:644
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:60
ContentID
ContentID
Unique identifier for the content.
Definition: tcp_content_type.h:47
IConsole::AliasRegister
static void AliasRegister(const std::string &name, const std::string &cmd)
Register a an alias for an already existing command in the console.
Definition: console.cpp:184
PM_PAUSED_NORMAL
@ PM_PAUSED_NORMAL
A game normally paused.
Definition: openttd.h:64
IConsoleAlias
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
Definition: console_internal.h:55
newgrf.h
NetworkSettings::max_clients
uint8_t max_clients
maximum amount of clients
Definition: settings_type.h:327
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
NetworkSettings::max_companies
uint8_t max_companies
maximum amount of companies
Definition: settings_type.h:326
RTF_NO_LEVEL_CROSSING
@ RTF_NO_LEVEL_CROSSING
Bit number for disallowing level crossings.
Definition: rail.h:27
StrEqualsIgnoreCase
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.
Definition: string.cpp:366
CONTENT_TYPE_BEGIN
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
Definition: tcp_content_type.h:19
FontCache::GetFontSize
virtual int GetFontSize() const
Get the nominal font size of the font.
Definition: fontcache.h:73
StringToContentType
static ContentType StringToContentType(const char *str)
Resolve a string to a content type.
Definition: console_cmds.cpp:1943
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:94
FT_HEIGHTMAP
@ FT_HEIGHTMAP
heightmap file
Definition: fileio_type.h:20
ClientNetworkContentSocketHandler::Select
void Select(ContentID cid)
Select a specific content id.
Definition: network_content.cpp:867
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
SC_DEFAULTZOOM
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:50
RoadTypeInfo::strings
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
company_func.h
CC_ERROR
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:24
SM_RELOADGAME
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
Definition: openttd.h:30
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:33
ROTF_TOWN_BUILD
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
Definition: road.h:42
FiosBrowseTo
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:143
DESTTYPE_BROADCAST
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
Definition: network_type.h:92
ROTF_HIDDEN
@ ROTF_HIDDEN
Bit number for hidden from construction.
Definition: road.h:41
ClientNetworkContentSocketHandler::AddCallback
void AddCallback(ContentCallback *cb)
Add a callback to this class.
Definition: network_content.h:146
NetworkAvailable
static bool NetworkAvailable(bool echo)
Check network availability and inform in console about failure of detection.
Definition: console_cmds.cpp:104
CHR_DISALLOW
@ CHR_DISALLOW
Disallow command execution.
Definition: console_internal.h:21
IConsoleGetSetting
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
Definition: settings.cpp:1892
network.h
ContentInfo::state
State state
Whether the content info is selected (for download)
Definition: tcp_content_type.h:75
CommandHelper
Definition: command_func.h:93
NetworkClientConnectGame
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.
Definition: network.cpp:772
window_func.h
AI_LIBRARY_DIR
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
Definition: fileio_type.h:120
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
_network_ban_list
StringList _network_ban_list
The banned clients.
Definition: network.cpp:70
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
ROTF_NO_HOUSES
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
Definition: road.h:40
SOCIAL_INTEGRATION_DIR
@ SOCIAL_INTEGRATION_DIR
Subdirectory for all social integration plugins.
Definition: fileio_type.h:124
Map::LogY
static uint LogY()
Logarithm of the map size along the y side.
Definition: map_func.h:261
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:637
IConsoleClose
void IConsoleClose()
Close the in-game console.
Definition: console_gui.cpp:393
SC_VIEWPORT
@ SC_VIEWPORT
Screenshot of viewport.
Definition: screenshot.h:19
CHR_HIDE
@ CHR_HIDE
Hide the existence of the command.
Definition: console_internal.h:22
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:206
GetAbstractFileType
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
Definition: fileio_type.h:90
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
engine_base.h
DEF_CONSOLE_HOOK
DEF_CONSOLE_HOOK(ConHookServerOnly)
Check whether we are a server.
Definition: console_cmds.cpp:117
RailTypeInfo::flags
RailTypeFlags flags
Bit mask of rail type flags.
Definition: rail.h:211
fontcache.h
ConsoleContentCallback
Asynchronous callback.
Definition: console_cmds.cpp:1953
NetworkServerKickClient
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
Definition: network_server.cpp:2114
ConsoleContentCallback::OnDisconnect
void OnDisconnect() override
Callback for when the connection got disconnected.
Definition: console_cmds.cpp:1959
NetworkClientSendChat
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data)
Send a chat message.
Definition: network_client.cpp:1391
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
AI::GetConsoleList
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:293
Window
Data structure for an opened window.
Definition: window_gui.h:267
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
network_admin.h
console_func.h
MakeScreenshot
bool MakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
Schedule making a screenshot.
Definition: screenshot.cpp:979
SC_MINIMAP
@ SC_MINIMAP
Minimap screenshot.
Definition: screenshot.h:25
NetworkServerGameInfo::clients_on
byte clients_on
Current count of clients on server.
Definition: network_game_info.h:107
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:61
ClientNetworkContentSocketHandler::SelectUpgrade
void SelectUpgrade()
Select everything that's an update for something we've got.
Definition: network_content.cpp:901
CC_WARNING
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
ContentInfo::id
ContentID id
Unique (server side) ID for the content.
Definition: tcp_content_type.h:64
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:70
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:323
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
newgrf_profiling.h
PM_PAUSED_ERROR
@ PM_PAUSED_ERROR
A game paused because a (critical) error.
Definition: openttd.h:67
Company
Definition: company_base.h:116
CC_MAIL
@ CC_MAIL
Mail.
Definition: cargotype.h:54
_network_server_invite_code
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
Definition: network_coordinator.cpp:32
CC_WHITE
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition: console_type.h:30
SL_OK
@ SL_OK
completed successfully
Definition: saveload.h:384
ROADTYPE_BEGIN
@ ROADTYPE_BEGIN
Used for iterations.
Definition: road_type.h:26
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:51
network_func.h
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
CRR_MANUAL
@ CRR_MANUAL
The company is manually removed.
Definition: company_type.h:57
FileList::BuildFileList
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
Definition: fios.cpp:70
ScriptConfig::HasScript
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
Definition: script_config.cpp:137
ContentInfo::unique_id
uint32_t unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content_type.h:71
NetworkIsValidClientName
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
Definition: network_client.cpp:1315
AISettings::ai_in_multiplayer
bool ai_in_multiplayer
so we allow AIs in multiplayer
Definition: settings_type.h:399
IConsole::CmdGet
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
Definition: console.cpp:172
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition: map_func.h:279
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
FioFCloseFile
void FioFCloseFile(FILE *f)
Close a file in a safe way.
Definition: fileio.cpp:148
debug.h
FontCache::Get
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
Definition: fontcache.h:144
ClientNetworkContentSocketHandler::Begin
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
Definition: network_content.h:137
ai_config.hpp
engine_func.h
PrintLineByLine
static void PrintLineByLine(const std::string &full_string)
Print a text buffer line by line to the console.
Definition: console_cmds.cpp:1261
SM_RESTARTGAME
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
Definition: openttd.h:29
RAILTYPE_BEGIN
@ RAILTYPE_BEGIN
Used for iterations.
Definition: rail_type.h:28
IConsolePrint
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.
Definition: console.cpp:91
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103