OpenTTD Source: src/console_cmds.cpp Source File

OpenTTD Source 14.1

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