OpenTTD Source: src/console_cmds.cpp Source File

OpenTTD Source 12.2

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