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