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