OpenTTD Source  1.10.0-RC1
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 "game/game.hpp"
40 #include "table/strings.h"
41 #include <time.h>
42 
43 #include "safeguards.h"
44 
45 /* scriptfile handling */
46 static bool _script_running;
47 
49 class ConsoleFileList : public FileList {
50 public:
52  {
53  this->file_list_valid = false;
54  }
55 
58  {
59  this->Clear();
60  this->file_list_valid = false;
61  }
62 
67  void ValidateFileList(bool force_reload = false)
68  {
69  if (force_reload || !this->file_list_valid) {
71  this->file_list_valid = true;
72  }
73  }
74 
76 };
77 
79 
80 /* console command defines */
81 #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
82 #define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo)
83 
84 
85 /****************
86  * command hooks
87  ****************/
88 
93 static inline bool NetworkAvailable(bool echo)
94 {
95  if (!_network_available) {
96  if (echo) IConsoleError("You cannot use this command because there is no network available.");
97  return false;
98  }
99  return true;
100 }
101 
106 DEF_CONSOLE_HOOK(ConHookServerOnly)
107 {
108  if (!NetworkAvailable(echo)) return CHR_DISALLOW;
109 
110  if (!_network_server) {
111  if (echo) IConsoleError("This command is only available to a network server.");
112  return CHR_DISALLOW;
113  }
114  return CHR_ALLOW;
115 }
116 
121 DEF_CONSOLE_HOOK(ConHookClientOnly)
122 {
123  if (!NetworkAvailable(echo)) return CHR_DISALLOW;
124 
125  if (_network_server) {
126  if (echo) IConsoleError("This command is not available to a network server.");
127  return CHR_DISALLOW;
128  }
129  return CHR_ALLOW;
130 }
131 
136 DEF_CONSOLE_HOOK(ConHookNeedNetwork)
137 {
138  if (!NetworkAvailable(echo)) return CHR_DISALLOW;
139 
141  if (echo) IConsoleError("Not connected. This command is only available in multiplayer.");
142  return CHR_DISALLOW;
143  }
144  return CHR_ALLOW;
145 }
146 
151 DEF_CONSOLE_HOOK(ConHookNoNetwork)
152 {
153  if (_networking) {
154  if (echo) IConsoleError("This command is forbidden in multiplayer.");
155  return CHR_DISALLOW;
156  }
157  return CHR_ALLOW;
158 }
159 
160 DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
161 {
163  if (_game_mode == GM_MENU) {
164  if (echo) IConsoleError("This command is only available in game and editor.");
165  return CHR_DISALLOW;
166  }
167  return ConHookNoNetwork(echo);
168  }
169  return CHR_HIDE;
170 }
171 
176 static void IConsoleHelp(const char *str)
177 {
178  IConsolePrintF(CC_WARNING, "- %s", str);
179 }
180 
185 DEF_CONSOLE_CMD(ConResetEngines)
186 {
187  if (argc == 0) {
188  IConsoleHelp("Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'");
189  return true;
190  }
191 
192  StartupEngines();
193  return true;
194 }
195 
201 DEF_CONSOLE_CMD(ConResetEnginePool)
202 {
203  if (argc == 0) {
204  IConsoleHelp("Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again.");
205  return true;
206  }
207 
208  if (_game_mode == GM_MENU) {
209  IConsoleError("This command is only available in game and editor.");
210  return true;
211  }
212 
214  IConsoleError("This can only be done when there are no vehicles in the game.");
215  return true;
216  }
217 
218  return true;
219 }
220 
221 #ifdef _DEBUG
222 
227 DEF_CONSOLE_CMD(ConResetTile)
228 {
229  if (argc == 0) {
230  IConsoleHelp("Reset a tile to bare land. Usage: 'resettile <tile>'");
231  IConsoleHelp("Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
232  return true;
233  }
234 
235  if (argc == 2) {
236  uint32 result;
237  if (GetArgumentInteger(&result, argv[1])) {
238  DoClearSquare((TileIndex)result);
239  return true;
240  }
241  }
242 
243  return false;
244 }
245 #endif /* _DEBUG */
246 
256 DEF_CONSOLE_CMD(ConScrollToTile)
257 {
258  switch (argc) {
259  case 0:
260  IConsoleHelp("Center the screen on a given tile.");
261  IConsoleHelp("Usage: 'scrollto <tile>' or 'scrollto <x> <y>'");
262  IConsoleHelp("Numbers can be either decimal (34161) or hexadecimal (0x4a5B).");
263  return true;
264 
265  case 2: {
266  uint32 result;
267  if (GetArgumentInteger(&result, argv[1])) {
268  if (result >= MapSize()) {
269  IConsolePrint(CC_ERROR, "Tile does not exist");
270  return true;
271  }
273  return true;
274  }
275  break;
276  }
277 
278  case 3: {
279  uint32 x, y;
280  if (GetArgumentInteger(&x, argv[1]) && GetArgumentInteger(&y, argv[2])) {
281  if (x >= MapSizeX() || y >= MapSizeY()) {
282  IConsolePrint(CC_ERROR, "Tile does not exist");
283  return true;
284  }
286  return true;
287  }
288  break;
289  }
290  }
291 
292  return false;
293 }
294 
301 {
302  if (argc == 0) {
303  IConsoleHelp("Save the current game. Usage: 'save <filename>'");
304  return true;
305  }
306 
307  if (argc == 2) {
308  char *filename = str_fmt("%s.sav", argv[1]);
309  IConsolePrint(CC_DEFAULT, "Saving map...");
310 
311  if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) {
312  IConsolePrint(CC_ERROR, "Saving map failed");
313  } else {
314  IConsolePrintF(CC_DEFAULT, "Map successfully saved to %s", filename);
315  }
316  free(filename);
317  return true;
318  }
319 
320  return false;
321 }
322 
327 DEF_CONSOLE_CMD(ConSaveConfig)
328 {
329  if (argc == 0) {
330  IConsoleHelp("Saves the configuration for new games to the configuration file, typically 'openttd.cfg'.");
331  IConsoleHelp("It does not save the configuration of the current game to the configuration file.");
332  return true;
333  }
334 
335  SaveToConfig();
336  IConsolePrint(CC_DEFAULT, "Saved config.");
337  return true;
338 }
339 
340 DEF_CONSOLE_CMD(ConLoad)
341 {
342  if (argc == 0) {
343  IConsoleHelp("Load a game by name or index. Usage: 'load <file | number>'");
344  return true;
345  }
346 
347  if (argc != 2) return false;
348 
349  const char *file = argv[1];
350  _console_file_list.ValidateFileList();
351  const FiosItem *item = _console_file_list.FindItem(file);
352  if (item != nullptr) {
353  if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
355  _file_to_saveload.SetMode(item->type);
357  _file_to_saveload.SetTitle(item->title);
358  } else {
359  IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
360  }
361  } else {
362  IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
363  }
364 
365  return true;
366 }
367 
368 
369 DEF_CONSOLE_CMD(ConRemove)
370 {
371  if (argc == 0) {
372  IConsoleHelp("Remove a savegame by name or index. Usage: 'rm <file | number>'");
373  return true;
374  }
375 
376  if (argc != 2) return false;
377 
378  const char *file = argv[1];
379  _console_file_list.ValidateFileList();
380  const FiosItem *item = _console_file_list.FindItem(file);
381  if (item != nullptr) {
382  if (!FiosDelete(item->name)) {
383  IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
384  }
385  } else {
386  IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
387  }
388 
389  _console_file_list.InvalidateFileList();
390  return true;
391 }
392 
393 
394 /* List all the files in the current dir via console */
395 DEF_CONSOLE_CMD(ConListFiles)
396 {
397  if (argc == 0) {
398  IConsoleHelp("List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'");
399  return true;
400  }
401 
402  _console_file_list.ValidateFileList(true);
403  for (uint i = 0; i < _console_file_list.Length(); i++) {
404  IConsolePrintF(CC_DEFAULT, "%d) %s", i, _console_file_list[i].title);
405  }
406 
407  return true;
408 }
409 
410 /* Change the dir via console */
411 DEF_CONSOLE_CMD(ConChangeDirectory)
412 {
413  if (argc == 0) {
414  IConsoleHelp("Change the dir via console. Usage: 'cd <directory | number>'");
415  return true;
416  }
417 
418  if (argc != 2) return false;
419 
420  const char *file = argv[1];
421  _console_file_list.ValidateFileList(true);
422  const FiosItem *item = _console_file_list.FindItem(file);
423  if (item != nullptr) {
424  switch (item->type) {
425  case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
426  FiosBrowseTo(item);
427  break;
428  default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
429  }
430  } else {
431  IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
432  }
433 
434  _console_file_list.InvalidateFileList();
435  return true;
436 }
437 
438 DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
439 {
440  const char *path;
441 
442  if (argc == 0) {
443  IConsoleHelp("Print out the current working directory. Usage: 'pwd'");
444  return true;
445  }
446 
447  /* XXX - Workaround for broken file handling */
448  _console_file_list.ValidateFileList(true);
449  _console_file_list.InvalidateFileList();
450 
451  FiosGetDescText(&path, nullptr);
452  IConsolePrint(CC_DEFAULT, path);
453  return true;
454 }
455 
456 DEF_CONSOLE_CMD(ConClearBuffer)
457 {
458  if (argc == 0) {
459  IConsoleHelp("Clear the console buffer. Usage: 'clear'");
460  return true;
461  }
462 
463  IConsoleClearBuffer();
465  return true;
466 }
467 
468 
469 /**********************************
470  * Network Core Console Commands
471  **********************************/
472 
473 static bool ConKickOrBan(const char *argv, bool ban, const char *reason)
474 {
475  uint n;
476 
477  if (strchr(argv, '.') == nullptr && strchr(argv, ':') == nullptr) { // banning with ID
478  ClientID client_id = (ClientID)atoi(argv);
479 
480  /* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
481  * kicking frees closes and subsequently free the connection related instances, which we
482  * would be reading from and writing to after returning. So we would read or write data
483  * from freed memory up till the segfault triggers. */
484  if (client_id == CLIENT_ID_SERVER || client_id == _redirect_console_to_client) {
485  IConsolePrintF(CC_ERROR, "ERROR: Silly boy, you can not %s yourself!", ban ? "ban" : "kick");
486  return true;
487  }
488 
490  if (ci == nullptr) {
491  IConsoleError("Invalid client");
492  return true;
493  }
494 
495  if (!ban) {
496  /* Kick only this client, not all clients with that IP */
497  NetworkServerKickClient(client_id, reason);
498  return true;
499  }
500 
501  /* When banning, kick+ban all clients with that IP */
502  n = NetworkServerKickOrBanIP(client_id, ban, reason);
503  } else {
504  n = NetworkServerKickOrBanIP(argv, ban, reason);
505  }
506 
507  if (n == 0) {
508  IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found");
509  } else {
510  IConsolePrintF(CC_DEFAULT, "%sed %u client(s)", ban ? "Bann" : "Kick", n);
511  }
512 
513  return true;
514 }
515 
516 DEF_CONSOLE_CMD(ConKick)
517 {
518  if (argc == 0) {
519  IConsoleHelp("Kick a client from a network game. Usage: 'kick <ip | client-id> [<kick-reason>]'");
520  IConsoleHelp("For client-id's, see the command 'clients'");
521  return true;
522  }
523 
524  if (argc != 2 && argc != 3) return false;
525 
526  /* No reason supplied for kicking */
527  if (argc == 2) return ConKickOrBan(argv[1], false, nullptr);
528 
529  /* Reason for kicking supplied */
530  size_t kick_message_length = strlen(argv[2]);
531  if (kick_message_length >= 255) {
532  IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered %d characters.", kick_message_length);
533  return false;
534  } else {
535  return ConKickOrBan(argv[1], false, argv[2]);
536  }
537 }
538 
539 DEF_CONSOLE_CMD(ConBan)
540 {
541  if (argc == 0) {
542  IConsoleHelp("Ban a client from a network game. Usage: 'ban <ip | client-id> [<ban-reason>]'");
543  IConsoleHelp("For client-id's, see the command 'clients'");
544  IConsoleHelp("If the client is no longer online, you can still ban his/her IP");
545  return true;
546  }
547 
548  if (argc != 2 && argc != 3) return false;
549 
550  /* No reason supplied for kicking */
551  if (argc == 2) return ConKickOrBan(argv[1], true, nullptr);
552 
553  /* Reason for kicking supplied */
554  size_t kick_message_length = strlen(argv[2]);
555  if (kick_message_length >= 255) {
556  IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered %d characters.", kick_message_length);
557  return false;
558  } else {
559  return ConKickOrBan(argv[1], true, argv[2]);
560  }
561 }
562 
563 DEF_CONSOLE_CMD(ConUnBan)
564 {
565  if (argc == 0) {
566  IConsoleHelp("Unban a client from a network game. Usage: 'unban <ip | banlist-index>'");
567  IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
568  return true;
569  }
570 
571  if (argc != 2) return false;
572 
573  /* Try by IP. */
574  uint index;
575  for (index = 0; index < _network_ban_list.size(); index++) {
576  if (_network_ban_list[index] == argv[1]) break;
577  }
578 
579  /* Try by index. */
580  if (index >= _network_ban_list.size()) {
581  index = atoi(argv[1]) - 1U; // let it wrap
582  }
583 
584  if (index < _network_ban_list.size()) {
585  char msg[64];
586  seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index].c_str());
588  _network_ban_list.erase(_network_ban_list.begin() + index);
589  } else {
590  IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
591  IConsolePrint(CC_DEFAULT, "For a list of banned IP's, see the command 'banlist'");
592  }
593 
594  return true;
595 }
596 
597 DEF_CONSOLE_CMD(ConBanList)
598 {
599  if (argc == 0) {
600  IConsoleHelp("List the IP's of banned clients: Usage 'banlist'");
601  return true;
602  }
603 
604  IConsolePrint(CC_DEFAULT, "Banlist: ");
605 
606  uint i = 1;
607  for (const auto &entry : _network_ban_list) {
608  IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry.c_str());
609  }
610 
611  return true;
612 }
613 
614 DEF_CONSOLE_CMD(ConPauseGame)
615 {
616  if (argc == 0) {
617  IConsoleHelp("Pause a network game. Usage: 'pause'");
618  return true;
619  }
620 
622  DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
623  if (!_networking) IConsolePrint(CC_DEFAULT, "Game paused.");
624  } else {
625  IConsolePrint(CC_DEFAULT, "Game is already paused.");
626  }
627 
628  return true;
629 }
630 
631 DEF_CONSOLE_CMD(ConUnpauseGame)
632 {
633  if (argc == 0) {
634  IConsoleHelp("Unpause a network game. Usage: 'unpause'");
635  return true;
636  }
637 
639  DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
640  if (!_networking) IConsolePrint(CC_DEFAULT, "Game unpaused.");
641  } else if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED) {
642  IConsolePrint(CC_DEFAULT, "Game is in error state and cannot be unpaused via console.");
643  } else if (_pause_mode != PM_UNPAUSED) {
644  IConsolePrint(CC_DEFAULT, "Game cannot be unpaused manually; disable pause_on_join/min_active_clients.");
645  } else {
646  IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
647  }
648 
649  return true;
650 }
651 
652 DEF_CONSOLE_CMD(ConRcon)
653 {
654  if (argc == 0) {
655  IConsoleHelp("Remote control the server from another client. Usage: 'rcon <password> <command>'");
656  IConsoleHelp("Remember to enclose the command in quotes, otherwise only the first parameter is sent");
657  return true;
658  }
659 
660  if (argc < 3) return false;
661 
662  if (_network_server) {
663  IConsoleCmdExec(argv[2]);
664  } else {
665  NetworkClientSendRcon(argv[1], argv[2]);
666  }
667  return true;
668 }
669 
670 DEF_CONSOLE_CMD(ConStatus)
671 {
672  if (argc == 0) {
673  IConsoleHelp("List the status of all clients connected to the server. Usage 'status'");
674  return true;
675  }
676 
678  return true;
679 }
680 
681 DEF_CONSOLE_CMD(ConServerInfo)
682 {
683  if (argc == 0) {
684  IConsoleHelp("List current and maximum client/company limits. Usage 'server_info'");
685  IConsoleHelp("You can change these values by modifying settings 'network.max_clients', 'network.max_companies' and 'network.max_spectators'");
686  return true;
687  }
688 
690  IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", (int)Company::GetNumItems(), _settings_client.network.max_companies);
691  IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), _settings_client.network.max_spectators);
692 
693  return true;
694 }
695 
696 DEF_CONSOLE_CMD(ConClientNickChange)
697 {
698  if (argc != 3) {
699  IConsoleHelp("Change the nickname of a connected client. Usage: 'client_name <client-id> <new-name>'");
700  IConsoleHelp("For client-id's, see the command 'clients'");
701  return true;
702  }
703 
704  ClientID client_id = (ClientID)atoi(argv[1]);
705 
706  if (client_id == CLIENT_ID_SERVER) {
707  IConsoleError("Please use the command 'name' to change your own name!");
708  return true;
709  }
710 
711  if (NetworkClientInfo::GetByClientID(client_id) == nullptr) {
712  IConsoleError("Invalid client");
713  return true;
714  }
715 
716  if (!NetworkServerChangeClientName(client_id, argv[2])) {
717  IConsoleError("Cannot give a client a duplicate name");
718  }
719 
720  return true;
721 }
722 
723 DEF_CONSOLE_CMD(ConJoinCompany)
724 {
725  if (argc < 2) {
726  IConsoleHelp("Request joining another company. Usage: join <company-id> [<password>]");
727  IConsoleHelp("For valid company-id see company list, use 255 for spectator");
728  return true;
729  }
730 
731  CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
732 
733  /* Check we have a valid company id! */
734  if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
735  IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
736  return true;
737  }
738 
739  if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
740  IConsoleError("You are already there!");
741  return true;
742  }
743 
744  if (company_id == COMPANY_SPECTATOR && NetworkMaxSpectatorsReached()) {
745  IConsoleError("Cannot join spectators, maximum number of spectators reached.");
746  return true;
747  }
748 
749  if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
750  IConsoleError("Cannot join AI company.");
751  return true;
752  }
753 
754  /* Check if the company requires a password */
755  if (NetworkCompanyIsPassworded(company_id) && argc < 3) {
756  IConsolePrintF(CC_ERROR, "Company %d requires a password to join.", company_id + 1);
757  return true;
758  }
759 
760  /* non-dedicated server may just do the move! */
761  if (_network_server) {
763  } else {
764  NetworkClientRequestMove(company_id, NetworkCompanyIsPassworded(company_id) ? argv[2] : "");
765  }
766 
767  return true;
768 }
769 
770 DEF_CONSOLE_CMD(ConMoveClient)
771 {
772  if (argc < 3) {
773  IConsoleHelp("Move a client to another company. Usage: move <client-id> <company-id>");
774  IConsoleHelp("For valid client-id see 'clients', for valid company-id see 'companies', use 255 for moving to spectators");
775  return true;
776  }
777 
778  const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)atoi(argv[1]));
779  CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
780 
781  /* check the client exists */
782  if (ci == nullptr) {
783  IConsoleError("Invalid client-id, check the command 'clients' for valid client-id's.");
784  return true;
785  }
786 
787  if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
788  IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
789  return true;
790  }
791 
792  if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
793  IConsoleError("You cannot move clients to AI companies.");
794  return true;
795  }
796 
798  IConsoleError("Silly boy, you cannot move the server!");
799  return true;
800  }
801 
802  if (ci->client_playas == company_id) {
803  IConsoleError("You cannot move someone to where he/she already is!");
804  return true;
805  }
806 
807  /* we are the server, so force the update */
808  NetworkServerDoMove(ci->client_id, company_id);
809 
810  return true;
811 }
812 
813 DEF_CONSOLE_CMD(ConResetCompany)
814 {
815  if (argc == 0) {
816  IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
817  IConsoleHelp("For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
818  return true;
819  }
820 
821  if (argc != 2) return false;
822 
823  CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
824 
825  /* Check valid range */
826  if (!Company::IsValidID(index)) {
827  IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
828  return true;
829  }
830 
831  if (!Company::IsHumanID(index)) {
832  IConsoleError("Company is owned by an AI.");
833  return true;
834  }
835 
836  if (NetworkCompanyHasClients(index)) {
837  IConsoleError("Cannot remove company: a client is connected to that company.");
838  return false;
839  }
841  if (ci->client_playas == index) {
842  IConsoleError("Cannot remove company: the server is connected to that company.");
843  return true;
844  }
845 
846  /* It is safe to remove this company */
847  DoCommandP(0, CCA_DELETE | index << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
848  IConsolePrint(CC_DEFAULT, "Company deleted.");
849 
850  return true;
851 }
852 
853 DEF_CONSOLE_CMD(ConNetworkClients)
854 {
855  if (argc == 0) {
856  IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
857  return true;
858  }
859 
861 
862  return true;
863 }
864 
865 DEF_CONSOLE_CMD(ConNetworkReconnect)
866 {
867  if (argc == 0) {
868  IConsoleHelp("Reconnect to server to which you were connected last time. Usage: 'reconnect [<company>]'");
869  IConsoleHelp("Company 255 is spectator (default, if not specified), 0 means creating new company.");
870  IConsoleHelp("All others are a certain company with Company 1 being #1");
871  return true;
872  }
873 
874  CompanyID playas = (argc >= 2) ? (CompanyID)atoi(argv[1]) : COMPANY_SPECTATOR;
875  switch (playas) {
876  case 0: playas = COMPANY_NEW_COMPANY; break;
877  case COMPANY_SPECTATOR: /* nothing to do */ break;
878  default:
879  /* From a user pov 0 is a new company, internally it's different and all
880  * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
881  if (playas < COMPANY_FIRST + 1 || playas > MAX_COMPANIES + 1) return false;
882  break;
883  }
884 
886  IConsolePrint(CC_DEFAULT, "No server for reconnecting.");
887  return true;
888  }
889 
890  /* Don't resolve the address first, just print it directly as it comes from the config file. */
892 
894  return true;
895 }
896 
897 DEF_CONSOLE_CMD(ConNetworkConnect)
898 {
899  if (argc == 0) {
900  IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
901  IConsoleHelp("IP can contain port and company: 'IP[:Port][#Company]', eg: 'server.ottd.org:443#2'");
902  IConsoleHelp("Company #255 is spectator all others are a certain company with Company 1 being #1");
903  return true;
904  }
905 
906  if (argc < 2) return false;
907  if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
908 
909  const char *port = nullptr;
910  const char *company = nullptr;
911  char *ip = argv[1];
912  /* Default settings: default port and new company */
913  uint16 rport = NETWORK_DEFAULT_PORT;
914  CompanyID join_as = COMPANY_NEW_COMPANY;
915 
916  ParseConnectionString(&company, &port, ip);
917 
918  IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
919  if (company != nullptr) {
920  join_as = (CompanyID)atoi(company);
921  IConsolePrintF(CC_DEFAULT, " company-no: %d", join_as);
922 
923  /* From a user pov 0 is a new company, internally it's different and all
924  * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
925  if (join_as != COMPANY_SPECTATOR) {
926  if (join_as > MAX_COMPANIES) return false;
927  join_as--;
928  }
929  }
930  if (port != nullptr) {
931  rport = atoi(port);
932  IConsolePrintF(CC_DEFAULT, " port: %s", port);
933  }
934 
935  NetworkClientConnectGame(NetworkAddress(ip, rport), join_as);
936 
937  return true;
938 }
939 
940 /*********************************
941  * script file console commands
942  *********************************/
943 
944 DEF_CONSOLE_CMD(ConExec)
945 {
946  if (argc == 0) {
947  IConsoleHelp("Execute a local script file. Usage: 'exec <script> <?>'");
948  return true;
949  }
950 
951  if (argc < 2) return false;
952 
953  FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
954 
955  if (script_file == nullptr) {
956  if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
957  return true;
958  }
959 
960  _script_running = true;
961 
962  char cmdline[ICON_CMDLN_SIZE];
963  while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != nullptr) {
964  /* Remove newline characters from the executing script */
965  for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
966  if (*cmdptr == '\n' || *cmdptr == '\r') {
967  *cmdptr = '\0';
968  break;
969  }
970  }
971  IConsoleCmdExec(cmdline);
972  }
973 
974  if (ferror(script_file)) {
975  IConsoleError("Encountered error while trying to read from script file");
976  }
977 
978  _script_running = false;
979  FioFCloseFile(script_file);
980  return true;
981 }
982 
983 DEF_CONSOLE_CMD(ConReturn)
984 {
985  if (argc == 0) {
986  IConsoleHelp("Stop executing a running script. Usage: 'return'");
987  return true;
988  }
989 
990  _script_running = false;
991  return true;
992 }
993 
994 /*****************************
995  * default console commands
996  ******************************/
997 extern bool CloseConsoleLogIfActive();
998 
999 DEF_CONSOLE_CMD(ConScript)
1000 {
1001  extern FILE *_iconsole_output_file;
1002 
1003  if (argc == 0) {
1004  IConsoleHelp("Start or stop logging console output to a file. Usage: 'script <filename>'");
1005  IConsoleHelp("If filename is omitted, a running log is stopped if it is active");
1006  return true;
1007  }
1008 
1009  if (!CloseConsoleLogIfActive()) {
1010  if (argc < 2) return false;
1011 
1012  IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
1013  _iconsole_output_file = fopen(argv[1], "ab");
1014  if (_iconsole_output_file == nullptr) IConsoleError("could not open file");
1015  }
1016 
1017  return true;
1018 }
1019 
1020 
1021 DEF_CONSOLE_CMD(ConEcho)
1022 {
1023  if (argc == 0) {
1024  IConsoleHelp("Print back the first argument to the console. Usage: 'echo <arg>'");
1025  return true;
1026  }
1027 
1028  if (argc < 2) return false;
1029  IConsolePrint(CC_DEFAULT, argv[1]);
1030  return true;
1031 }
1032 
1033 DEF_CONSOLE_CMD(ConEchoC)
1034 {
1035  if (argc == 0) {
1036  IConsoleHelp("Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
1037  return true;
1038  }
1039 
1040  if (argc < 3) return false;
1041  IConsolePrint((TextColour)Clamp(atoi(argv[1]), TC_BEGIN, TC_END - 1), argv[2]);
1042  return true;
1043 }
1044 
1045 DEF_CONSOLE_CMD(ConNewGame)
1046 {
1047  if (argc == 0) {
1048  IConsoleHelp("Start a new game. Usage: 'newgame [seed]'");
1049  IConsoleHelp("The server can force a new game using 'newgame'; any client joined will rejoin after the server is done generating the new game.");
1050  return true;
1051  }
1052 
1053  StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], nullptr, 10) : GENERATE_NEW_SEED);
1054  return true;
1055 }
1056 
1057 DEF_CONSOLE_CMD(ConRestart)
1058 {
1059  if (argc == 0) {
1060  IConsoleHelp("Restart game. Usage: 'restart'");
1061  IConsoleHelp("Restarts a game. It tries to reproduce the exact same map as the game started with.");
1062  IConsoleHelp("However:");
1063  IConsoleHelp(" * restarting games started in another version might create another map due to difference in map generation");
1064  IConsoleHelp(" * restarting games based on scenarios, loaded games or heightmaps will start a new game based on the settings stored in the scenario/savegame");
1065  return true;
1066  }
1067 
1068  /* Don't copy the _newgame pointers to the real pointers, so call SwitchToMode directly */
1072  return true;
1073 }
1074 
1080 static void PrintLineByLine(char *buf)
1081 {
1082  char *p = buf;
1083  /* Print output line by line */
1084  for (char *p2 = buf; *p2 != '\0'; p2++) {
1085  if (*p2 == '\n') {
1086  *p2 = '\0';
1087  IConsolePrintF(CC_DEFAULT, "%s", p);
1088  p = p2 + 1;
1089  }
1090  }
1091 }
1092 
1093 DEF_CONSOLE_CMD(ConListAILibs)
1094 {
1095  char buf[4096];
1096  AI::GetConsoleLibraryList(buf, lastof(buf));
1097 
1098  PrintLineByLine(buf);
1099 
1100  return true;
1101 }
1102 
1103 DEF_CONSOLE_CMD(ConListAI)
1104 {
1105  char buf[4096];
1106  AI::GetConsoleList(buf, lastof(buf));
1107 
1108  PrintLineByLine(buf);
1109 
1110  return true;
1111 }
1112 
1113 DEF_CONSOLE_CMD(ConListGameLibs)
1114 {
1115  char buf[4096];
1117 
1118  PrintLineByLine(buf);
1119 
1120  return true;
1121 }
1122 
1123 DEF_CONSOLE_CMD(ConListGame)
1124 {
1125  char buf[4096];
1126  Game::GetConsoleList(buf, lastof(buf));
1127 
1128  PrintLineByLine(buf);
1129 
1130  return true;
1131 }
1132 
1133 DEF_CONSOLE_CMD(ConStartAI)
1134 {
1135  if (argc == 0 || argc > 3) {
1136  IConsoleHelp("Start a new AI. Usage: 'start_ai [<AI>] [<settings>]'");
1137  IConsoleHelp("Start a new AI. If <AI> is given, it starts that specific AI (if found).");
1138  IConsoleHelp("If <settings> is given, it is parsed and the AI settings are set to that.");
1139  return true;
1140  }
1141 
1142  if (_game_mode != GM_NORMAL) {
1143  IConsoleWarning("AIs can only be managed in a game.");
1144  return true;
1145  }
1146 
1148  IConsoleWarning("Can't start a new AI (no more free slots).");
1149  return true;
1150  }
1151  if (_networking && !_network_server) {
1152  IConsoleWarning("Only the server can start a new AI.");
1153  return true;
1154  }
1156  IConsoleWarning("AIs are not allowed in multiplayer by configuration.");
1157  IConsoleWarning("Switch AI -> AI in multiplayer to True.");
1158  return true;
1159  }
1160  if (!AI::CanStartNew()) {
1161  IConsoleWarning("Can't start a new AI.");
1162  return true;
1163  }
1164 
1165  int n = 0;
1166  /* Find the next free slot */
1167  for (const Company *c : Company::Iterate()) {
1168  if (c->index != n) break;
1169  n++;
1170  }
1171 
1172  AIConfig *config = AIConfig::GetConfig((CompanyID)n);
1173  if (argc >= 2) {
1174  config->Change(argv[1], -1, true);
1175  if (!config->HasScript()) {
1176  IConsoleWarning("Failed to load the specified AI");
1177  return true;
1178  }
1179  if (argc == 3) {
1180  config->StringToSettings(argv[2]);
1181  }
1182  }
1183 
1184  /* Start a new AI company */
1186 
1187  return true;
1188 }
1189 
1190 DEF_CONSOLE_CMD(ConReloadAI)
1191 {
1192  if (argc != 2) {
1193  IConsoleHelp("Reload an AI. Usage: 'reload_ai <company-id>'");
1194  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.");
1195  return true;
1196  }
1197 
1198  if (_game_mode != GM_NORMAL) {
1199  IConsoleWarning("AIs can only be managed in a game.");
1200  return true;
1201  }
1202 
1203  if (_networking && !_network_server) {
1204  IConsoleWarning("Only the server can reload an AI.");
1205  return true;
1206  }
1207 
1208  CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
1209  if (!Company::IsValidID(company_id)) {
1210  IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
1211  return true;
1212  }
1213 
1214  if (Company::IsHumanID(company_id)) {
1215  IConsoleWarning("Company is not controlled by an AI.");
1216  return true;
1217  }
1218 
1219  /* First kill the company of the AI, then start a new one. This should start the current AI again */
1220  DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0,CMD_COMPANY_CTRL);
1221  DoCommandP(0, CCA_NEW_AI | company_id << 16, 0, CMD_COMPANY_CTRL);
1222  IConsolePrint(CC_DEFAULT, "AI reloaded.");
1223 
1224  return true;
1225 }
1226 
1227 DEF_CONSOLE_CMD(ConStopAI)
1228 {
1229  if (argc != 2) {
1230  IConsoleHelp("Stop an AI. Usage: 'stop_ai <company-id>'");
1231  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.");
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 stop 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) || company_id == _local_company) {
1252  IConsoleWarning("Company is not controlled by an AI.");
1253  return true;
1254  }
1255 
1256  /* Now kill the company of the AI. */
1257  DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
1258  IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
1259 
1260  return true;
1261 }
1262 
1263 DEF_CONSOLE_CMD(ConRescanAI)
1264 {
1265  if (argc == 0) {
1266  IConsoleHelp("Rescan the AI dir for scripts. Usage: 'rescan_ai'");
1267  return true;
1268  }
1269 
1270  if (_networking && !_network_server) {
1271  IConsoleWarning("Only the server can rescan the AI dir for scripts.");
1272  return true;
1273  }
1274 
1275  AI::Rescan();
1276 
1277  return true;
1278 }
1279 
1280 DEF_CONSOLE_CMD(ConRescanGame)
1281 {
1282  if (argc == 0) {
1283  IConsoleHelp("Rescan the Game Script dir for scripts. Usage: 'rescan_game'");
1284  return true;
1285  }
1286 
1287  if (_networking && !_network_server) {
1288  IConsoleWarning("Only the server can rescan the Game Script dir for scripts.");
1289  return true;
1290  }
1291 
1292  Game::Rescan();
1293 
1294  return true;
1295 }
1296 
1297 DEF_CONSOLE_CMD(ConRescanNewGRF)
1298 {
1299  if (argc == 0) {
1300  IConsoleHelp("Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'");
1301  return true;
1302  }
1303 
1304  ScanNewGRFFiles(nullptr);
1305 
1306  return true;
1307 }
1308 
1309 DEF_CONSOLE_CMD(ConGetSeed)
1310 {
1311  if (argc == 0) {
1312  IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
1313  IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
1314  return true;
1315  }
1316 
1318  return true;
1319 }
1320 
1321 DEF_CONSOLE_CMD(ConGetDate)
1322 {
1323  if (argc == 0) {
1324  IConsoleHelp("Returns the current date (year-month-day) of the game. Usage: 'getdate'");
1325  return true;
1326  }
1327 
1328  YearMonthDay ymd;
1329  ConvertDateToYMD(_date, &ymd);
1330  IConsolePrintF(CC_DEFAULT, "Date: %04d-%02d-%02d", ymd.year, ymd.month + 1, ymd.day);
1331  return true;
1332 }
1333 
1334 DEF_CONSOLE_CMD(ConGetSysDate)
1335 {
1336  if (argc == 0) {
1337  IConsoleHelp("Returns the current date (year-month-day) of your system. Usage: 'getsysdate'");
1338  return true;
1339  }
1340 
1341  time_t t;
1342  time(&t);
1343  auto timeinfo = localtime(&t);
1344  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);
1345  return true;
1346 }
1347 
1348 
1349 DEF_CONSOLE_CMD(ConAlias)
1350 {
1351  IConsoleAlias *alias;
1352 
1353  if (argc == 0) {
1354  IConsoleHelp("Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'");
1355  return true;
1356  }
1357 
1358  if (argc < 3) return false;
1359 
1360  alias = IConsoleAliasGet(argv[1]);
1361  if (alias == nullptr) {
1362  IConsoleAliasRegister(argv[1], argv[2]);
1363  } else {
1364  free(alias->cmdline);
1365  alias->cmdline = stredup(argv[2]);
1366  }
1367  return true;
1368 }
1369 
1370 DEF_CONSOLE_CMD(ConScreenShot)
1371 {
1372  if (argc == 0) {
1373  IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | giant | no_con | minimap] [file name]'");
1374  IConsoleHelp("'big' makes a zoomed-in screenshot of the visible area, 'giant' makes a screenshot of the "
1375  "whole map, 'no_con' hides the console to create the screenshot. 'big' or 'giant' "
1376  "screenshots are always drawn without console. "
1377  "'minimap' makes a top-viewed minimap screenshot of whole world which represents one tile by one pixel.");
1378  return true;
1379  }
1380 
1381  if (argc > 3) return false;
1382 
1383  ScreenshotType type = SC_VIEWPORT;
1384  const char *name = nullptr;
1385 
1386  if (argc > 1) {
1387  if (strcmp(argv[1], "big") == 0) {
1388  /* screenshot big [filename] */
1389  type = SC_ZOOMEDIN;
1390  if (argc > 2) name = argv[2];
1391  } else if (strcmp(argv[1], "giant") == 0) {
1392  /* screenshot giant [filename] */
1393  type = SC_WORLD;
1394  if (argc > 2) name = argv[2];
1395  } else if (strcmp(argv[1], "minimap") == 0) {
1396  /* screenshot minimap [filename] */
1397  type = SC_MINIMAP;
1398  if (argc > 2) name = argv[2];
1399  } else if (strcmp(argv[1], "no_con") == 0) {
1400  /* screenshot no_con [filename] */
1401  IConsoleClose();
1402  if (argc > 2) name = argv[2];
1403  } else if (argc == 2) {
1404  /* screenshot filename */
1405  name = argv[1];
1406  } else {
1407  /* screenshot argv[1] argv[2] - invalid */
1408  return false;
1409  }
1410  }
1411 
1412  MakeScreenshot(type, name);
1413  return true;
1414 }
1415 
1416 DEF_CONSOLE_CMD(ConInfoCmd)
1417 {
1418  if (argc == 0) {
1419  IConsoleHelp("Print out debugging information about a command. Usage: 'info_cmd <cmd>'");
1420  return true;
1421  }
1422 
1423  if (argc < 2) return false;
1424 
1425  const IConsoleCmd *cmd = IConsoleCmdGet(argv[1]);
1426  if (cmd == nullptr) {
1427  IConsoleError("the given command was not found");
1428  return true;
1429  }
1430 
1431  IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
1432  IConsolePrintF(CC_DEFAULT, "command proc: %p", cmd->proc);
1433 
1434  if (cmd->hook != nullptr) IConsoleWarning("command is hooked");
1435 
1436  return true;
1437 }
1438 
1439 DEF_CONSOLE_CMD(ConDebugLevel)
1440 {
1441  if (argc == 0) {
1442  IConsoleHelp("Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'");
1443  IConsoleHelp("Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
1444  return true;
1445  }
1446 
1447  if (argc > 2) return false;
1448 
1449  if (argc == 1) {
1450  IConsolePrintF(CC_DEFAULT, "Current debug-level: '%s'", GetDebugString());
1451  } else {
1452  SetDebugString(argv[1]);
1453  }
1454 
1455  return true;
1456 }
1457 
1458 DEF_CONSOLE_CMD(ConExit)
1459 {
1460  if (argc == 0) {
1461  IConsoleHelp("Exit the game. Usage: 'exit'");
1462  return true;
1463  }
1464 
1465  if (_game_mode == GM_NORMAL && _settings_client.gui.autosave_on_exit) DoExitSave();
1466 
1467  _exit_game = true;
1468  return true;
1469 }
1470 
1471 DEF_CONSOLE_CMD(ConPart)
1472 {
1473  if (argc == 0) {
1474  IConsoleHelp("Leave the currently joined/running game (only ingame). Usage: 'part'");
1475  return true;
1476  }
1477 
1478  if (_game_mode != GM_NORMAL) return false;
1479 
1481  return true;
1482 }
1483 
1484 DEF_CONSOLE_CMD(ConHelp)
1485 {
1486  if (argc == 2) {
1487  const IConsoleCmd *cmd;
1488  const IConsoleAlias *alias;
1489 
1490  RemoveUnderscores(argv[1]);
1491  cmd = IConsoleCmdGet(argv[1]);
1492  if (cmd != nullptr) {
1493  cmd->proc(0, nullptr);
1494  return true;
1495  }
1496 
1497  alias = IConsoleAliasGet(argv[1]);
1498  if (alias != nullptr) {
1499  cmd = IConsoleCmdGet(alias->cmdline);
1500  if (cmd != nullptr) {
1501  cmd->proc(0, nullptr);
1502  return true;
1503  }
1504  IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
1505  return true;
1506  }
1507 
1508  IConsoleError("command not found");
1509  return true;
1510  }
1511 
1512  IConsolePrint(CC_WARNING, " ---- OpenTTD Console Help ---- ");
1513  IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
1514  IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
1515  IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes");
1516  IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'");
1517  IConsolePrint(CC_DEFAULT, " - use 'help <command>' to get specific information");
1518  IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down | pageup | pagedown)");
1519  IConsolePrint(CC_DEFAULT, " - scroll console input history with the up or down arrows");
1521  return true;
1522 }
1523 
1524 DEF_CONSOLE_CMD(ConListCommands)
1525 {
1526  if (argc == 0) {
1527  IConsoleHelp("List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
1528  return true;
1529  }
1530 
1531  for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != nullptr; cmd = cmd->next) {
1532  if (argv[1] == nullptr || strstr(cmd->name, argv[1]) != nullptr) {
1533  if (cmd->hook == nullptr || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
1534  }
1535  }
1536 
1537  return true;
1538 }
1539 
1540 DEF_CONSOLE_CMD(ConListAliases)
1541 {
1542  if (argc == 0) {
1543  IConsoleHelp("List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
1544  return true;
1545  }
1546 
1547  for (const IConsoleAlias *alias = _iconsole_aliases; alias != nullptr; alias = alias->next) {
1548  if (argv[1] == nullptr || strstr(alias->name, argv[1]) != nullptr) {
1549  IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
1550  }
1551  }
1552 
1553  return true;
1554 }
1555 
1556 DEF_CONSOLE_CMD(ConCompanies)
1557 {
1558  if (argc == 0) {
1559  IConsoleHelp("List the details of all companies in the game. Usage 'companies'");
1560  return true;
1561  }
1562 
1563  for (const Company *c : Company::Iterate()) {
1564  /* Grab the company name */
1565  char company_name[512];
1566  SetDParam(0, c->index);
1567  GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
1568 
1569  const char *password_state = "";
1570  if (c->is_ai) {
1571  password_state = "AI";
1572  } else if (_network_server) {
1573  password_state = StrEmpty(_network_company_states[c->index].password) ? "unprotected" : "protected";
1574  }
1575 
1576  char colour[512];
1577  GetString(colour, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(colour));
1578  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",
1579  c->index + 1, colour, company_name,
1580  c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
1581  c->group_all[VEH_TRAIN].num_vehicle,
1582  c->group_all[VEH_ROAD].num_vehicle,
1583  c->group_all[VEH_AIRCRAFT].num_vehicle,
1584  c->group_all[VEH_SHIP].num_vehicle,
1585  password_state);
1586  }
1587 
1588  return true;
1589 }
1590 
1591 DEF_CONSOLE_CMD(ConSay)
1592 {
1593  if (argc == 0) {
1594  IConsoleHelp("Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
1595  return true;
1596  }
1597 
1598  if (argc != 2) return false;
1599 
1600  if (!_network_server) {
1601  NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
1602  } else {
1603  bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
1604  NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER, from_admin);
1605  }
1606 
1607  return true;
1608 }
1609 
1610 DEF_CONSOLE_CMD(ConSayCompany)
1611 {
1612  if (argc == 0) {
1613  IConsoleHelp("Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
1614  IConsoleHelp("CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
1615  return true;
1616  }
1617 
1618  if (argc != 3) return false;
1619 
1620  CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
1621  if (!Company::IsValidID(company_id)) {
1622  IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
1623  return true;
1624  }
1625 
1626  if (!_network_server) {
1627  NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2]);
1628  } else {
1629  bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
1630  NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2], CLIENT_ID_SERVER, from_admin);
1631  }
1632 
1633  return true;
1634 }
1635 
1636 DEF_CONSOLE_CMD(ConSayClient)
1637 {
1638  if (argc == 0) {
1639  IConsoleHelp("Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
1640  IConsoleHelp("For client-id's, see the command 'clients'");
1641  return true;
1642  }
1643 
1644  if (argc != 3) return false;
1645 
1646  if (!_network_server) {
1647  NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
1648  } else {
1649  bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID);
1650  NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], CLIENT_ID_SERVER, from_admin);
1651  }
1652 
1653  return true;
1654 }
1655 
1656 DEF_CONSOLE_CMD(ConCompanyPassword)
1657 {
1658  if (argc == 0) {
1659  const char *helpmsg;
1660 
1661  if (_network_dedicated) {
1662  helpmsg = "Change the password of a company. Usage: 'company_pw <company-no> \"<password>\"";
1663  } else if (_network_server) {
1664  helpmsg = "Change the password of your or any other company. Usage: 'company_pw [<company-no>] \"<password>\"'";
1665  } else {
1666  helpmsg = "Change the password of your company. Usage: 'company_pw \"<password>\"'";
1667  }
1668 
1669  IConsoleHelp(helpmsg);
1670  IConsoleHelp("Use \"*\" to disable the password.");
1671  return true;
1672  }
1673 
1674  CompanyID company_id;
1675  const char *password;
1676  const char *errormsg;
1677 
1678  if (argc == 2) {
1679  company_id = _local_company;
1680  password = argv[1];
1681  errormsg = "You have to own a company to make use of this command.";
1682  } else if (argc == 3 && _network_server) {
1683  company_id = (CompanyID)(atoi(argv[1]) - 1);
1684  password = argv[2];
1685  errormsg = "You have to specify the ID of a valid human controlled company.";
1686  } else {
1687  return false;
1688  }
1689 
1690  if (!Company::IsValidHumanID(company_id)) {
1691  IConsoleError(errormsg);
1692  return false;
1693  }
1694 
1695  password = NetworkChangeCompanyPassword(company_id, password);
1696 
1697  if (StrEmpty(password)) {
1698  IConsolePrintF(CC_WARNING, "Company password cleared");
1699  } else {
1700  IConsolePrintF(CC_WARNING, "Company password changed to: %s", password);
1701  }
1702 
1703  return true;
1704 }
1705 
1706 /* Content downloading only is available with ZLIB */
1707 #if defined(WITH_ZLIB)
1708 #include "network/network_content.h"
1709 
1711 static ContentType StringToContentType(const char *str)
1712 {
1713  static const char * const inv_lookup[] = { "", "base", "newgrf", "ai", "ailib", "scenario", "heightmap" };
1714  for (uint i = 1 /* there is no type 0 */; i < lengthof(inv_lookup); i++) {
1715  if (strcasecmp(str, inv_lookup[i]) == 0) return (ContentType)i;
1716  }
1717  return CONTENT_TYPE_END;
1718 }
1719 
1722  void OnConnect(bool success)
1723  {
1724  IConsolePrintF(CC_DEFAULT, "Content server connection %s", success ? "established" : "failed");
1725  }
1726 
1728  {
1729  IConsolePrintF(CC_DEFAULT, "Content server connection closed");
1730  }
1731 
1733  {
1734  IConsolePrintF(CC_DEFAULT, "Completed download of %d", cid);
1735  }
1736 };
1737 
1742 static void OutputContentState(const ContentInfo *const ci)
1743 {
1744  static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music", "Game script", "GS library" };
1745  assert_compile(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
1746  static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" };
1747  static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR };
1748 
1749  char buf[sizeof(ci->md5sum) * 2 + 1];
1750  md5sumToString(buf, lastof(buf), ci->md5sum);
1751  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);
1752 }
1753 
1754 DEF_CONSOLE_CMD(ConContent)
1755 {
1756  static ContentCallback *cb = nullptr;
1757  if (cb == nullptr) {
1758  cb = new ConsoleContentCallback();
1760  }
1761 
1762  if (argc <= 1) {
1763  IConsoleHelp("Query, select and download content. Usage: 'content update|upgrade|select [all|id]|unselect [all|id]|state [filter]|download'");
1764  IConsoleHelp(" update: get a new list of downloadable content; must be run first");
1765  IConsoleHelp(" upgrade: select all items that are upgrades");
1766  IConsoleHelp(" select: select a specific item given by its id or 'all' to select all. If no parameter is given, all selected content will be listed");
1767  IConsoleHelp(" unselect: unselect a specific item given by its id or 'all' to unselect all");
1768  IConsoleHelp(" state: show the download/select state of all downloadable content. Optionally give a filter string");
1769  IConsoleHelp(" download: download all content you've selected");
1770  return true;
1771  }
1772 
1773  if (strcasecmp(argv[1], "update") == 0) {
1775  return true;
1776  }
1777 
1778  if (strcasecmp(argv[1], "upgrade") == 0) {
1780  return true;
1781  }
1782 
1783  if (strcasecmp(argv[1], "select") == 0) {
1784  if (argc <= 2) {
1785  /* List selected content */
1786  IConsolePrintF(CC_WHITE, "id, type, state, name");
1788  if ((*iter)->state != ContentInfo::SELECTED && (*iter)->state != ContentInfo::AUTOSELECTED) continue;
1789  OutputContentState(*iter);
1790  }
1791  } else if (strcasecmp(argv[2], "all") == 0) {
1793  } else {
1794  _network_content_client.Select((ContentID)atoi(argv[2]));
1795  }
1796  return true;
1797  }
1798 
1799  if (strcasecmp(argv[1], "unselect") == 0) {
1800  if (argc <= 2) {
1801  IConsoleError("You must enter the id.");
1802  return false;
1803  }
1804  if (strcasecmp(argv[2], "all") == 0) {
1806  } else {
1807  _network_content_client.Unselect((ContentID)atoi(argv[2]));
1808  }
1809  return true;
1810  }
1811 
1812  if (strcasecmp(argv[1], "state") == 0) {
1813  IConsolePrintF(CC_WHITE, "id, type, state, name");
1815  if (argc > 2 && strcasestr((*iter)->name, argv[2]) == nullptr) continue;
1816  OutputContentState(*iter);
1817  }
1818  return true;
1819  }
1820 
1821  if (strcasecmp(argv[1], "download") == 0) {
1822  uint files;
1823  uint bytes;
1825  IConsolePrintF(CC_DEFAULT, "Downloading %d file(s) (%d bytes)", files, bytes);
1826  return true;
1827  }
1828 
1829  return false;
1830 }
1831 #endif /* defined(WITH_ZLIB) */
1832 
1833 DEF_CONSOLE_CMD(ConSetting)
1834 {
1835  if (argc == 0) {
1836  IConsoleHelp("Change setting for all clients. Usage: 'setting <name> [<value>]'");
1837  IConsoleHelp("Omitting <value> will print out the current value of the setting.");
1838  return true;
1839  }
1840 
1841  if (argc == 1 || argc > 3) return false;
1842 
1843  if (argc == 2) {
1844  IConsoleGetSetting(argv[1]);
1845  } else {
1846  IConsoleSetSetting(argv[1], argv[2]);
1847  }
1848 
1849  return true;
1850 }
1851 
1852 DEF_CONSOLE_CMD(ConSettingNewgame)
1853 {
1854  if (argc == 0) {
1855  IConsoleHelp("Change setting for the next game. Usage: 'setting_newgame <name> [<value>]'");
1856  IConsoleHelp("Omitting <value> will print out the current value of the setting.");
1857  return true;
1858  }
1859 
1860  if (argc == 1 || argc > 3) return false;
1861 
1862  if (argc == 2) {
1863  IConsoleGetSetting(argv[1], true);
1864  } else {
1865  IConsoleSetSetting(argv[1], argv[2], true);
1866  }
1867 
1868  return true;
1869 }
1870 
1871 DEF_CONSOLE_CMD(ConListSettings)
1872 {
1873  if (argc == 0) {
1874  IConsoleHelp("List settings. Usage: 'list_settings [<pre-filter>]'");
1875  return true;
1876  }
1877 
1878  if (argc > 2) return false;
1879 
1880  IConsoleListSettings((argc == 2) ? argv[1] : nullptr);
1881  return true;
1882 }
1883 
1884 DEF_CONSOLE_CMD(ConGamelogPrint)
1885 {
1887  return true;
1888 }
1889 
1890 DEF_CONSOLE_CMD(ConNewGRFReload)
1891 {
1892  if (argc == 0) {
1893  IConsoleHelp("Reloads all active NewGRFs from disk. Equivalent to reapplying NewGRFs via the settings, but without asking for confirmation. This might crash OpenTTD!");
1894  return true;
1895  }
1896 
1897  ReloadNewGRFData();
1898  return true;
1899 }
1900 
1901 DEF_CONSOLE_CMD(ConNewGRFProfile)
1902 {
1903  if (argc == 0) {
1904  IConsoleHelp("Collect performance data about NewGRF sprite requests and callbacks. Sub-commands can be abbreviated.");
1905  IConsoleHelp("Usage: newgrf_profile [list]");
1906  IConsoleHelp(" List all NewGRFs that can be profiled, and their status.");
1907  IConsoleHelp("Usage: newgrf_profile select <grf-num>...");
1908  IConsoleHelp(" Select one or more GRFs for profiling.");
1909  IConsoleHelp("Usage: newgrf_profile unselect <grf-num>...");
1910  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.");
1911  IConsoleHelp("Usage: newgrf_profile start [<num-days>]");
1912  IConsoleHelp(" Begin profiling all selected GRFs. If a number of days is provided, profiling stops after that many in-game days.");
1913  IConsoleHelp("Usage: newgrf_profile stop");
1914  IConsoleHelp(" End profiling and write the collected data to CSV files.");
1915  IConsoleHelp("Usage: newgrf_profile abort");
1916  IConsoleHelp(" End profiling and discard all collected data.");
1917  return true;
1918  }
1919 
1920  extern const std::vector<GRFFile *> &GetAllGRFFiles();
1921  const std::vector<GRFFile *> &files = GetAllGRFFiles();
1922 
1923  /* "list" sub-command */
1924  if (argc == 1 || strncasecmp(argv[1], "lis", 3) == 0) {
1925  IConsolePrint(CC_INFO, "Loaded GRF files:");
1926  int i = 1;
1927  for (GRFFile *grf : files) {
1928  auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; });
1929  bool selected = profiler != _newgrf_profilers.end();
1930  bool active = selected && profiler->active;
1931  TextColour tc = active ? TC_LIGHT_BLUE : selected ? TC_GREEN : CC_INFO;
1932  const char *statustext = active ? " (active)" : selected ? " (selected)" : "";
1933  IConsolePrintF(tc, "%d: [%08X] %s%s", i, BSWAP32(grf->grfid), grf->filename, statustext);
1934  i++;
1935  }
1936  return true;
1937  }
1938 
1939  /* "select" sub-command */
1940  if (strncasecmp(argv[1], "sel", 3) == 0 && argc >= 3) {
1941  for (size_t argnum = 2; argnum < argc; ++argnum) {
1942  int grfnum = atoi(argv[argnum]);
1943  if (grfnum < 1 || grfnum > (int)files.size()) { // safe cast, files.size() should not be larger than a few hundred in the most extreme cases
1944  IConsolePrintF(CC_WARNING, "GRF number %d out of range, not added.", grfnum);
1945  continue;
1946  }
1947  GRFFile *grf = files[grfnum - 1];
1948  if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; })) {
1949  IConsolePrintF(CC_WARNING, "GRF number %d [%08X] is already selected for profiling.", grfnum, BSWAP32(grf->grfid));
1950  continue;
1951  }
1952  _newgrf_profilers.emplace_back(grf);
1953  }
1954  return true;
1955  }
1956 
1957  /* "unselect" sub-command */
1958  if (strncasecmp(argv[1], "uns", 3) == 0 && argc >= 3) {
1959  for (size_t argnum = 2; argnum < argc; ++argnum) {
1960  if (strcasecmp(argv[argnum], "all") == 0) {
1961  _newgrf_profilers.clear();
1962  break;
1963  }
1964  int grfnum = atoi(argv[argnum]);
1965  if (grfnum < 1 || grfnum > (int)files.size()) {
1966  IConsolePrintF(CC_WARNING, "GRF number %d out of range, not removing.", grfnum);
1967  continue;
1968  }
1969  GRFFile *grf = files[grfnum - 1];
1970  auto pos = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; });
1971  if (pos != _newgrf_profilers.end()) _newgrf_profilers.erase(pos);
1972  }
1973  return true;
1974  }
1975 
1976  /* "start" sub-command */
1977  if (strncasecmp(argv[1], "sta", 3) == 0) {
1978  std::string grfids;
1979  size_t started = 0;
1980  for (NewGRFProfiler &pr : _newgrf_profilers) {
1981  if (!pr.active) {
1982  pr.Start();
1983  started++;
1984 
1985  if (!grfids.empty()) grfids += ", ";
1986  char grfidstr[12]{ 0 };
1987  seprintf(grfidstr, lastof(grfidstr), "[%08X]", BSWAP32(pr.grffile->grfid));
1988  grfids += grfidstr;
1989  }
1990  }
1991  if (started > 0) {
1992  IConsolePrintF(CC_DEBUG, "Started profiling for GRFID%s %s", (started > 1) ? "s" : "", grfids.c_str());
1993  if (argc >= 3) {
1994  int days = max(atoi(argv[2]), 1);
1995  _newgrf_profile_end_date = _date + days;
1996 
1997  char datestrbuf[32]{ 0 };
1998  SetDParam(0, _newgrf_profile_end_date);
1999  GetString(datestrbuf, STR_JUST_DATE_ISO, lastof(datestrbuf));
2000  IConsolePrintF(CC_DEBUG, "Profiling will automatically stop on game date %s", datestrbuf);
2001  } else {
2002  _newgrf_profile_end_date = MAX_DAY;
2003  }
2004  } else if (_newgrf_profilers.empty()) {
2005  IConsolePrintF(CC_WARNING, "No GRFs selected for profiling, did not start.");
2006  } else {
2007  IConsolePrintF(CC_WARNING, "Did not start profiling for any GRFs, all selected GRFs are already profiling.");
2008  }
2009  return true;
2010  }
2011 
2012  /* "stop" sub-command */
2013  if (strncasecmp(argv[1], "sto", 3) == 0) {
2014  NewGRFProfiler::FinishAll();
2015  return true;
2016  }
2017 
2018  /* "abort" sub-command */
2019  if (strncasecmp(argv[1], "abo", 3) == 0) {
2020  for (NewGRFProfiler &pr : _newgrf_profilers) {
2021  pr.Abort();
2022  }
2023  _newgrf_profile_end_date = MAX_DAY;
2024  return true;
2025  }
2026 
2027  return false;
2028 }
2029 
2030 #ifdef _DEBUG
2031 /******************
2032  * debug commands
2033  ******************/
2034 
2035 static void IConsoleDebugLibRegister()
2036 {
2037  IConsoleCmdRegister("resettile", ConResetTile);
2038  IConsoleAliasRegister("dbg_echo", "echo %A; echo %B");
2039  IConsoleAliasRegister("dbg_echo2", "echo %!");
2040 }
2041 #endif
2042 
2043 DEF_CONSOLE_CMD(ConFramerate)
2044 {
2045  extern void ConPrintFramerate(); // framerate_gui.cpp
2046 
2047  if (argc == 0) {
2048  IConsoleHelp("Show frame rate and game speed information");
2049  return true;
2050  }
2051 
2053  return true;
2054 }
2055 
2056 DEF_CONSOLE_CMD(ConFramerateWindow)
2057 {
2058  extern void ShowFramerateWindow();
2059 
2060  if (argc == 0) {
2061  IConsoleHelp("Open the frame rate window");
2062  return true;
2063  }
2064 
2065  if (_network_dedicated) {
2066  IConsoleError("Can not open frame rate window on a dedicated server");
2067  return false;
2068  }
2069 
2071  return true;
2072 }
2073 
2074 /*******************************
2075  * console command registration
2076  *******************************/
2077 
2078 void IConsoleStdLibRegister()
2079 {
2080  IConsoleCmdRegister("debug_level", ConDebugLevel);
2081  IConsoleCmdRegister("echo", ConEcho);
2082  IConsoleCmdRegister("echoc", ConEchoC);
2083  IConsoleCmdRegister("exec", ConExec);
2084  IConsoleCmdRegister("exit", ConExit);
2085  IConsoleCmdRegister("part", ConPart);
2086  IConsoleCmdRegister("help", ConHelp);
2087  IConsoleCmdRegister("info_cmd", ConInfoCmd);
2088  IConsoleCmdRegister("list_cmds", ConListCommands);
2089  IConsoleCmdRegister("list_aliases", ConListAliases);
2090  IConsoleCmdRegister("newgame", ConNewGame);
2091  IConsoleCmdRegister("restart", ConRestart);
2092  IConsoleCmdRegister("getseed", ConGetSeed);
2093  IConsoleCmdRegister("getdate", ConGetDate);
2094  IConsoleCmdRegister("getsysdate", ConGetSysDate);
2095  IConsoleCmdRegister("quit", ConExit);
2096  IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
2097  IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
2098  IConsoleCmdRegister("return", ConReturn);
2099  IConsoleCmdRegister("screenshot", ConScreenShot);
2100  IConsoleCmdRegister("script", ConScript);
2101  IConsoleCmdRegister("scrollto", ConScrollToTile);
2102  IConsoleCmdRegister("alias", ConAlias);
2103  IConsoleCmdRegister("load", ConLoad);
2104  IConsoleCmdRegister("rm", ConRemove);
2105  IConsoleCmdRegister("save", ConSave);
2106  IConsoleCmdRegister("saveconfig", ConSaveConfig);
2107  IConsoleCmdRegister("ls", ConListFiles);
2108  IConsoleCmdRegister("cd", ConChangeDirectory);
2109  IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
2110  IConsoleCmdRegister("clear", ConClearBuffer);
2111  IConsoleCmdRegister("setting", ConSetting);
2112  IConsoleCmdRegister("setting_newgame", ConSettingNewgame);
2113  IConsoleCmdRegister("list_settings",ConListSettings);
2114  IConsoleCmdRegister("gamelog", ConGamelogPrint);
2115  IConsoleCmdRegister("rescan_newgrf", ConRescanNewGRF);
2116 
2117  IConsoleAliasRegister("dir", "ls");
2118  IConsoleAliasRegister("del", "rm %+");
2119  IConsoleAliasRegister("newmap", "newgame");
2120  IConsoleAliasRegister("patch", "setting %+");
2121  IConsoleAliasRegister("set", "setting %+");
2122  IConsoleAliasRegister("set_newgame", "setting_newgame %+");
2123  IConsoleAliasRegister("list_patches", "list_settings %+");
2124  IConsoleAliasRegister("developer", "setting developer %+");
2125 
2126  IConsoleCmdRegister("list_ai_libs", ConListAILibs);
2127  IConsoleCmdRegister("list_ai", ConListAI);
2128  IConsoleCmdRegister("reload_ai", ConReloadAI);
2129  IConsoleCmdRegister("rescan_ai", ConRescanAI);
2130  IConsoleCmdRegister("start_ai", ConStartAI);
2131  IConsoleCmdRegister("stop_ai", ConStopAI);
2132 
2133  IConsoleCmdRegister("list_game", ConListGame);
2134  IConsoleCmdRegister("list_game_libs", ConListGameLibs);
2135  IConsoleCmdRegister("rescan_game", ConRescanGame);
2136 
2137  IConsoleCmdRegister("companies", ConCompanies);
2138  IConsoleAliasRegister("players", "companies");
2139 
2140  /* networking functions */
2141 
2142 /* Content downloading is only available with ZLIB */
2143 #if defined(WITH_ZLIB)
2144  IConsoleCmdRegister("content", ConContent);
2145 #endif /* defined(WITH_ZLIB) */
2146 
2147  /*** Networking commands ***/
2148  IConsoleCmdRegister("say", ConSay, ConHookNeedNetwork);
2149  IConsoleCmdRegister("say_company", ConSayCompany, ConHookNeedNetwork);
2150  IConsoleAliasRegister("say_player", "say_company %+");
2151  IConsoleCmdRegister("say_client", ConSayClient, ConHookNeedNetwork);
2152 
2153  IConsoleCmdRegister("connect", ConNetworkConnect, ConHookClientOnly);
2154  IConsoleCmdRegister("clients", ConNetworkClients, ConHookNeedNetwork);
2155  IConsoleCmdRegister("status", ConStatus, ConHookServerOnly);
2156  IConsoleCmdRegister("server_info", ConServerInfo, ConHookServerOnly);
2157  IConsoleAliasRegister("info", "server_info");
2158  IConsoleCmdRegister("reconnect", ConNetworkReconnect, ConHookClientOnly);
2159  IConsoleCmdRegister("rcon", ConRcon, ConHookNeedNetwork);
2160 
2161  IConsoleCmdRegister("join", ConJoinCompany, ConHookNeedNetwork);
2162  IConsoleAliasRegister("spectate", "join 255");
2163  IConsoleCmdRegister("move", ConMoveClient, ConHookServerOnly);
2164  IConsoleCmdRegister("reset_company", ConResetCompany, ConHookServerOnly);
2165  IConsoleAliasRegister("clean_company", "reset_company %A");
2166  IConsoleCmdRegister("client_name", ConClientNickChange, ConHookServerOnly);
2167  IConsoleCmdRegister("kick", ConKick, ConHookServerOnly);
2168  IConsoleCmdRegister("ban", ConBan, ConHookServerOnly);
2169  IConsoleCmdRegister("unban", ConUnBan, ConHookServerOnly);
2170  IConsoleCmdRegister("banlist", ConBanList, ConHookServerOnly);
2171 
2172  IConsoleCmdRegister("pause", ConPauseGame, ConHookServerOnly);
2173  IConsoleCmdRegister("unpause", ConUnpauseGame, ConHookServerOnly);
2174 
2175  IConsoleCmdRegister("company_pw", ConCompanyPassword, ConHookNeedNetwork);
2176  IConsoleAliasRegister("company_password", "company_pw %+");
2177 
2178  IConsoleAliasRegister("net_frame_freq", "setting frame_freq %+");
2179  IConsoleAliasRegister("net_sync_freq", "setting sync_freq %+");
2180  IConsoleAliasRegister("server_pw", "setting server_password %+");
2181  IConsoleAliasRegister("server_password", "setting server_password %+");
2182  IConsoleAliasRegister("rcon_pw", "setting rcon_password %+");
2183  IConsoleAliasRegister("rcon_password", "setting rcon_password %+");
2184  IConsoleAliasRegister("name", "setting client_name %+");
2185  IConsoleAliasRegister("server_name", "setting server_name %+");
2186  IConsoleAliasRegister("server_port", "setting server_port %+");
2187  IConsoleAliasRegister("server_advertise", "setting server_advertise %+");
2188  IConsoleAliasRegister("max_clients", "setting max_clients %+");
2189  IConsoleAliasRegister("max_companies", "setting max_companies %+");
2190  IConsoleAliasRegister("max_spectators", "setting max_spectators %+");
2191  IConsoleAliasRegister("max_join_time", "setting max_join_time %+");
2192  IConsoleAliasRegister("pause_on_join", "setting pause_on_join %+");
2193  IConsoleAliasRegister("autoclean_companies", "setting autoclean_companies %+");
2194  IConsoleAliasRegister("autoclean_protected", "setting autoclean_protected %+");
2195  IConsoleAliasRegister("autoclean_unprotected", "setting autoclean_unprotected %+");
2196  IConsoleAliasRegister("restart_game_year", "setting restart_game_year %+");
2197  IConsoleAliasRegister("min_players", "setting min_active_clients %+");
2198  IConsoleAliasRegister("reload_cfg", "setting reload_cfg %+");
2199 
2200  /* debugging stuff */
2201 #ifdef _DEBUG
2202  IConsoleDebugLibRegister();
2203 #endif
2204  IConsoleCmdRegister("fps", ConFramerate);
2205  IConsoleCmdRegister("fps_wnd", ConFramerateWindow);
2206 
2207  /* NewGRF development stuff */
2208  IConsoleCmdRegister("reload_newgrfs", ConNewGRFReload, ConHookNewGRFDeveloperTool);
2209  IConsoleCmdRegister("newgrf_profile", ConNewGRFProfile, ConHookNewGRFDeveloperTool);
2210 }
AISettings ai
what may the AI do?
World screenshot.
Definition: screenshot.h:23
Functions related to OTTD&#39;s strings.
Helper to mark the end of the types.
Definition: tcp_content.h:33
Owner
Enum for all companies/owners.
Definition: company_type.h:18
static void OutputContentState(const ContentInfo *const ci)
Outputs content state information to console.
Send message/notice to all clients (All)
Definition: network_type.h:79
const ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
used in multiplayer to create a new companies etc.
Definition: command_type.h:280
void IConsoleGetSetting(const char *name, bool force_newgame)
Output value of a specific setting to the console.
Definition: settings.cpp:2144
IConsoleCmd * next
next command in list
void IConsoleWarning(const char *string)
It is possible to print warnings to the console.
Definition: console.cpp:158
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:461
bool _networking
are we in networking mode?
Definition: network.cpp:52
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
char *CDECL str_fmt(const char *str,...)
Format, "printf", into a newly allocated string.
Definition: string.cpp:149
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
static void PrintLineByLine(char *buf)
Print a text buffer line by line to the console.
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
Profiling of NewGRF action 2 handling.
Container for all information known about a client.
Definition: network_base.h:23
IConsoleCmd * _iconsole_cmds
list of registered commands
Definition: console.cpp:27
uint32 unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content.h:73
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3218
uint16 last_port
port of the last joined server
void FioFCloseFile(FILE *f)
Close a file in a safe way.
Definition: fileio.cpp:332
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
void Clear()
Remove all items from the list.
Definition: fios.h:186
Train vehicle type.
Definition: vehicle_type.h:24
Switch to game intro menu.
Definition: openttd.h:30
void SetName(const char *name)
Set the name of the file.
Definition: saveload.cpp:2888
Functions related to dates.
Day day
Day (1..31)
Definition: date_type.h:106
std::vector< FiosItem > files
The list of files.
Definition: fios.h:200
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:407
Load game, Play Scenario.
Definition: openttd.h:29
static uint MapLogX()
Logarithm of the map size along the X side.
Definition: map_func.h:51
Functions related to debugging.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
Callbacks for notifying others about incoming data.
Ship vehicle type.
Definition: vehicle_type.h:26
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:318
Functions to be called to log possibly unsafe game events.
ClientID client_id
Client identifier (same as ClientState->client_id)
Definition: network_base.h:24
size_t Length() const
Get the number of files in the list.
Definition: fios.h:130
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:58
The company is manually removed.
Definition: company_type.h:56
The client wants a new company.
Definition: company_type.h:34
Screenshot of viewport.
Definition: screenshot.h:19
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:425
void IConsoleListSettings(const char *prefilter)
List all settings and their value to the console.
Definition: settings.cpp:2177
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
Definition: company_base.h:163
Client part of the network protocol.
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.
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:27
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
Definition: network.cpp:60
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
Notify the server of this client wanting to be moved to another company.
void OnDownloadComplete(ContentID cid)
We have finished downloading a file.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
void OnConnect(bool success)
Callback for when the connection has finished.
static const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
Definition: network_type.h:54
Functions for Standard In/Out file operations.
Send message/notice to only a certain client (Private)
Definition: network_type.h:81
The content has been selected as dependency.
Definition: tcp_content.h:59
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:2816
IConsoleCmdProc * proc
process executed when command is typed
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
char * name
name of command
static ContentType StringToContentType(const char *str)
Resolve a string to a content type.
static const TextColour CC_DEFAULT
Default colour of the console.
Definition: console_type.h:23
IConsoleAlias * _iconsole_aliases
list of registered aliases
Definition: console.cpp:28
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:213
Functions related to world/map generation.
Functions to make screenshots.
Base core network types and some helper functions to access them.
bool NetworkMaxSpectatorsReached()
Check if max_spectatos has been reached on the server (local check only).
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
ClientID
&#39;Unique&#39; identifier to be given to clients
Definition: network_type.h:39
static bool _script_running
Script is running (used to abort execution when #ConReturn is encountered).
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1750
uint8 map_x
X size of map.
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
ContentID
Unique identifier for the content.
Definition: tcp_content.h:49
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
Asynchronous callback.
File is being saved.
Definition: fileio_type.h:50
Deals with finding savegames.
Definition: fios.h:103
Hide the existence of the command.
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
Definition: genworld.h:24
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
Definition: fios.cpp:139
void OnDisconnect()
Callback for when the connection got disconnected.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:150
bool _network_available
is network mode available?
Definition: network.cpp:54
void Unselect(ContentID cid)
Unselect a specific content id.
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:55
Console; Window numbers:
Definition: window_type.h:631
const FiosItem * FindItem(const char *file)
Find file information of a file by its name from the file list.
Definition: fios.cpp:106
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for GameScanner::GetConsoleList.
Definition: game_core.cpp:228
Functions related to (drawing on) viewports.
uint8 map_y
Y size of map.
void UnselectAll()
Unselect everything that we&#39;ve not downloaded so far.
Save game or scenario file.
Definition: fileio_type.h:31
static const size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:85
old or new savegame
Definition: fileio_type.h:18
static ConsoleFileList _console_file_list
File storage cache for the console.
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
char password[NETWORK_PASSWORD_LENGTH]
The password for the company.
Definition: network_type.h:65
static bool IsConnected()
Check whether the client is actually connected (and in the game).
char name[32]
Name of the content.
Definition: tcp_content.h:69
NetworkSettings network
settings related to the network
void AddCallback(ContentCallback *cb)
Add a callback to this class.
Internally used functions for the console.
void SetTitle(const char *title)
Set the title of the file.
Definition: saveload.cpp:2897
Functions/types related to saving and loading games.
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:27
ConstContentIterator End() const
Get the end of the content inf iterator.
void GamelogPrintConsole()
Print the gamelog data to the console.
Definition: gamelog.cpp:345
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for GameScanner::GetConsoleLibraryList.
Definition: game_core.cpp:233
IConsoleAlias * next
next alias in list
A normal unpaused game.
Definition: openttd.h:56
The client is spectating.
Definition: company_type.h:35
void SelectUpgrade()
Select everything that&#39;s an update for something we&#39;ve got.
Functions related to engines.
uint8 max_spectators
maximum amount of spectators
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
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
IConsoleCmd * IConsoleCmdGet(const char *name)
Find the command pointed to by its string.
Definition: console.cpp:265
File list storage for the console, for caching the last &#39;ls&#39; command.
Allow command execution.
Create a new AI company.
Definition: company_type.h:66
Functions related to setting/changing the settings.
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:59
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
FILE * FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition: fileio.cpp:463
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
Definition of base types and functions in a cross-platform compatible way.
static const TextColour CC_DEBUG
Colour for debug output.
Definition: console_type.h:27
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:103
A number of safeguards to prevent using unsafe methods.
ContentID id
Unique (server side) ID for the content.
Definition: tcp_content.h:66
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
NetworkCompanyState * _network_company_states
Statistics about some companies.
Definition: network.cpp:58
void ShowFramerateWindow()
Open the general framerate window.
Base directory for all savegames.
Definition: fileio_type.h:110
Base directory for all subdirectories.
Definition: fileio_type.h:109
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
Definition: fios.cpp:74
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:45
void NetworkPrintClients()
Print all the clients to the console.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:136
Console functions used outside of the console code.
void RequestContentList(ContentType type)
Request the content list for the given type.
State state
Whether the content info is selected (for download)
Definition: tcp_content.h:79
void ConPrintFramerate()
Print performance statistics to game console.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:111
static void IConsoleHelp(const char *str)
Show help for the console.
byte clients_on
Current count of clients on server.
Definition: game.h:26
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?"
Year year
Year (0...)
Definition: date_type.h:104
void InvalidateFileList()
Declare the file storage cache as being invalid, also clears all stored files.
A game normally paused.
Definition: openttd.h:57
const char * GetDebugString()
Print out the current debug-level.
Definition: debug.cpp:226
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
Definition: fileio_type.h:90
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
SaveOrLoadResult SaveOrLoad(const char *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:2729
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:536
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
NetworkServerGameInfo _network_game_info
Information about our game.
Definition: network.cpp:57
File is being loaded.
Definition: fileio_type.h:49
Callback profiler for NewGRF development.
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:47
Delete a company.
Definition: company_type.h:67
Month month
Month (0..11)
Definition: date_type.h:105
byte md5sum[16]
The MD5 checksum.
Definition: tcp_content.h:74
static const TextColour CC_COMMAND
Colour for the console&#39;s commands.
Definition: console_type.h:28
IConsoleAlias * IConsoleAliasGet(const char *name)
Find the alias pointed to by its string.
Definition: console.cpp:303
uint8 max_companies
maximum amount of companies
char * RemoveUnderscores(char *name)
Remove underscores from a string; the string will be modified!
Definition: console.cpp:234
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
bool MakeScreenshot(ScreenshotType t, const char *name)
Make an actual screenshot.
Definition: screenshot.cpp:840
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
ContentType
The values in the enum are important; they are used as database &#39;keys&#39;.
Definition: tcp_content.h:21
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
Change the client name of the given client.
void NetworkServerKickClient(ClientID client_id, const char *reason)
Kick a single client.
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:253
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:693
void Select(ContentID cid)
Select a specific content id.
Functions related to companies.
An invalid company.
Definition: company_type.h:30
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
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.
static const uint16 NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
Definition: config.h:29
Base class for engines.
void SelectAll()
Select everything we can select.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason)
Ban, or kick, everyone joined from the given client&#39;s IP.
uint32 generation_seed
noise seed for world generation
GUISettings gui
settings related to the GUI
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:527
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:57
Declarations for savegames operations.
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:407
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
void IConsoleAliasRegister(const char *name, const char *cmd)
Register a an alias for an already existing command in the console.
Definition: console.cpp:280
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:359
List of file information.
Definition: fios.h:112
Minimap screenshot.
Definition: screenshot.h:25
ContentType type
Type of content.
Definition: tcp_content.h:65
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:150
uint8 max_clients
maximum amount of clients
Restart –> &#39;Random game&#39; with current settings.
Definition: openttd.h:27
void NetworkClientSendRcon(const char *password, const char *command)
Send a remote console command.
char * cmdline
command(s) that is/are being aliased
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:348
IConsoleHook * hook
any special trigger action that needs executing
void IConsoleError(const char *string)
It is possible to print error information to the console.
Definition: console.cpp:168
DEF_CONSOLE_CMD(ConResetEngines)
Reset status of all engines.
Helper to mark the begin of the types.
Definition: tcp_content.h:22
Maximum number of companies.
Definition: company_type.h:23
StringList _network_ban_list
The banned clients.
Definition: network.cpp:65
void ValidateFileList(bool force_reload=false)
(Re-)validate the file storage cache.
#define MAX_DAY
The number of days till the last day.
Definition: date_type.h:97
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
Functions related to OTTD&#39;s landscape.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2396
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
Base functions for all Games.
Functions related to commands.
Network functions used by other parts of OpenTTD.
bool _network_server
network-server is active
Definition: network.cpp:53
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:46
static char * GetConsoleLibraryList(char *p, const char *last)
Wrapper function for AIScanner::GetAIConsoleLibraryList.
Definition: ai_core.cpp:323
static const TextColour CC_ERROR
Colour for error lines.
Definition: console_type.h:24
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
Definition: network.cpp:781
bool ai_in_multiplayer
so we allow AIs in multiplayer
Aircraft vehicle type.
Definition: vehicle_type.h:27
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
The content has been manually selected.
Definition: tcp_content.h:58
char last_host[NETWORK_HOSTNAME_LENGTH]
IP address of the last joined server.
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:30
completed successfully
Definition: saveload.h:311
Base functions for all AIs.
Servers always have this ID.
Definition: network_type.h:41
GameCreationSettings game_creation
settings used during the creation of a game (map)
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:2859
void SetDebugString(const char *s)
Set debugging levels by parsing the text in s.
Definition: debug.cpp:172
bool file_list_valid
If set, the file list is valid.
AIConfig stores the configuration settings of every AI.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Window functions not directly related to making/drawing windows.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3158
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it&#39;s client-identifier.
Definition: network.cpp:119
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script...
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
Definition: network.cpp:162
Disallow command execution.
Date _date
Current date in days (day counter)
Definition: date.cpp:27
static bool NetworkAvailable(bool echo)
Check network availability and inform in console about failure of detection.
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:95
static const TextColour CC_WARNING
Colour for warning lines.
Definition: console_type.h:25
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:80
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
Container for all important information about a piece of content.
Definition: tcp_content.h:54
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
Definition: console.cpp:180
Road vehicle type.
Definition: vehicle_type.h:25
static const TextColour CC_WHITE
White console lines for various things such as the welcome.
Definition: console_type.h:29
A game paused because a (critical) error.
Definition: openttd.h:60
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook)
Register a new command to be used in the console.
Definition: console.cpp:249
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
static const TextColour CC_INFO
Colour for information lines.
Definition: console_type.h:26
DEF_CONSOLE_HOOK(ConHookServerOnly)
Check whether we are a server.
Server part of the admin network protocol.
void IConsoleClose()
Close the in-game console.
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
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
Base for the NewGRF implementation.
pause the game
Definition: command_type.h:255