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