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