src/console_cmds.cpp
changeset 9337 ab6e0234bacc
parent 9336 6baad5b3033d
child 9354 845e07db4549
equal deleted inserted replaced
9336:6baad5b3033d 9337:ab6e0234bacc
   105 
   105 
   106 #endif /* ENABLE_NETWORK */
   106 #endif /* ENABLE_NETWORK */
   107 
   107 
   108 static void IConsoleHelp(const char *str)
   108 static void IConsoleHelp(const char *str)
   109 {
   109 {
   110 	IConsolePrintF(_icolour_warn, "- %s", str);
   110 	IConsolePrintF(CC_WARNING, "- %s", str);
   111 }
   111 }
   112 
   112 
   113 DEF_CONSOLE_CMD(ConResetEngines)
   113 DEF_CONSOLE_CMD(ConResetEngines)
   114 {
   114 {
   115 	if (argc == 0) {
   115 	if (argc == 0) {
   163 
   163 
   164 	if (argc == 2) {
   164 	if (argc == 2) {
   165 		uint32 result;
   165 		uint32 result;
   166 		if (GetArgumentInteger(&result, argv[1])) {
   166 		if (GetArgumentInteger(&result, argv[1])) {
   167 			if (result >= MapSize()) {
   167 			if (result >= MapSize()) {
   168 				IConsolePrint(_icolour_err, "Tile does not exist");
   168 				IConsolePrint(CC_ERROR, "Tile does not exist");
   169 				return true;
   169 				return true;
   170 			}
   170 			}
   171 			ScrollMainWindowToTile((TileIndex)result);
   171 			ScrollMainWindowToTile((TileIndex)result);
   172 			return true;
   172 			return true;
   173 		}
   173 		}
   187 		return true;
   187 		return true;
   188 	}
   188 	}
   189 
   189 
   190 	if (argc == 2) {
   190 	if (argc == 2) {
   191 		char *filename = str_fmt("%s.sav", argv[1]);
   191 		char *filename = str_fmt("%s.sav", argv[1]);
   192 		IConsolePrint(_icolour_def, "Saving map...");
   192 		IConsolePrint(CC_DEFAULT, "Saving map...");
   193 
   193 
   194 		if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) {
   194 		if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) {
   195 			IConsolePrint(_icolour_err, "Saving map failed");
   195 			IConsolePrint(CC_ERROR, "Saving map failed");
   196 		} else {
   196 		} else {
   197 			IConsolePrintF(_icolour_def, "Map sucessfully saved to %s", filename);
   197 			IConsolePrintF(CC_DEFAULT, "Map sucessfully saved to %s", filename);
   198 		}
   198 		}
   199 		free(filename);
   199 		free(filename);
   200 		return true;
   200 		return true;
   201 	}
   201 	}
   202 
   202 
   210 		IConsoleHelp("Saves the current config, typically to 'openttd.cfg'.");
   210 		IConsoleHelp("Saves the current config, typically to 'openttd.cfg'.");
   211 		return true;
   211 		return true;
   212 	}
   212 	}
   213 
   213 
   214 	SaveToConfig();
   214 	SaveToConfig();
   215 	IConsolePrint(_icolour_def, "Saved config.");
   215 	IConsolePrint(CC_DEFAULT, "Saved config.");
   216 	return true;
   216 	return true;
   217 }
   217 }
   218 
   218 
   219 static const FiosItem* GetFiosItem(const char* file)
   219 static const FiosItem* GetFiosItem(const char* file)
   220 {
   220 {
   260 				SetFiosType(item->type);
   260 				SetFiosType(item->type);
   261 
   261 
   262 				ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
   262 				ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
   263 				ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
   263 				ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
   264 			} break;
   264 			} break;
   265 			default: IConsolePrintF(_icolour_err, "%s: Not a savegame.", file);
   265 			default: IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
   266 		}
   266 		}
   267 	} else {
   267 	} else {
   268 		IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
   268 		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
   269 	}
   269 	}
   270 
   270 
   271 	FiosFreeSavegameList();
   271 	FiosFreeSavegameList();
   272 	return true;
   272 	return true;
   273 }
   273 }
   287 
   287 
   288 	file = argv[1];
   288 	file = argv[1];
   289 	item = GetFiosItem(file);
   289 	item = GetFiosItem(file);
   290 	if (item != NULL) {
   290 	if (item != NULL) {
   291 		if (!FiosDelete(item->name))
   291 		if (!FiosDelete(item->name))
   292 			IConsolePrintF(_icolour_err, "%s: Failed to delete file", file);
   292 			IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
   293 	} else {
   293 	} else {
   294 		IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
   294 		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
   295 	}
   295 	}
   296 
   296 
   297 	FiosFreeSavegameList();
   297 	FiosFreeSavegameList();
   298 	return true;
   298 	return true;
   299 }
   299 }
   311 
   311 
   312 	BuildFileList();
   312 	BuildFileList();
   313 
   313 
   314 	for (i = 0; i < _fios_num; i++) {
   314 	for (i = 0; i < _fios_num; i++) {
   315 		const FiosItem *item = &_fios_list[i];
   315 		const FiosItem *item = &_fios_list[i];
   316 		IConsolePrintF(_icolour_def, "%d) %s", i, item->title);
   316 		IConsolePrintF(CC_DEFAULT, "%d) %s", i, item->title);
   317 	}
   317 	}
   318 
   318 
   319 	FiosFreeSavegameList();
   319 	FiosFreeSavegameList();
   320 	return true;
   320 	return true;
   321 }
   321 }
   338 	if (item != NULL) {
   338 	if (item != NULL) {
   339 		switch (item->type) {
   339 		switch (item->type) {
   340 			case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
   340 			case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
   341 				FiosBrowseTo(item);
   341 				FiosBrowseTo(item);
   342 				break;
   342 				break;
   343 			default: IConsolePrintF(_icolour_err, "%s: Not a directory.", file);
   343 			default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
   344 		}
   344 		}
   345 	} else {
   345 	} else {
   346 		IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
   346 		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
   347 	}
   347 	}
   348 
   348 
   349 	FiosFreeSavegameList();
   349 	FiosFreeSavegameList();
   350 	return true;
   350 	return true;
   351 }
   351 }
   362 	// XXX - Workaround for broken file handling
   362 	// XXX - Workaround for broken file handling
   363 	FiosGetSavegameList(SLD_LOAD_GAME);
   363 	FiosGetSavegameList(SLD_LOAD_GAME);
   364 	FiosFreeSavegameList();
   364 	FiosFreeSavegameList();
   365 
   365 
   366 	FiosGetDescText(&path, NULL);
   366 	FiosGetDescText(&path, NULL);
   367 	IConsolePrint(_icolour_def, path);
   367 	IConsolePrint(CC_DEFAULT, path);
   368 	return true;
   368 	return true;
   369 }
   369 }
   370 
   370 
   371 DEF_CONSOLE_CMD(ConClearBuffer)
   371 DEF_CONSOLE_CMD(ConClearBuffer)
   372 {
   372 {
   425 	}
   425 	}
   426 
   426 
   427 	if (ci != NULL) {
   427 	if (ci != NULL) {
   428 		banip = inet_ntoa(*(struct in_addr *)&ci->client_ip);
   428 		banip = inet_ntoa(*(struct in_addr *)&ci->client_ip);
   429 		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   429 		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   430 		IConsolePrint(_icolour_def, "Client banned");
   430 		IConsolePrint(CC_DEFAULT, "Client banned");
   431 	} else {
   431 	} else {
   432 		IConsolePrint(_icolour_def, "Client not online, banned IP");
   432 		IConsolePrint(CC_DEFAULT, "Client not online, banned IP");
   433 	}
   433 	}
   434 
   434 
   435 	/* Add user to ban-list */
   435 	/* Add user to ban-list */
   436 	for (index = 0; index < lengthof(_network_ban_list); index++) {
   436 	for (index = 0; index < lengthof(_network_ban_list); index++) {
   437 		if (_network_ban_list[index] == NULL) {
   437 		if (_network_ban_list[index] == NULL) {
   462 		if (_network_ban_list[i] == NULL) continue;
   462 		if (_network_ban_list[i] == NULL) continue;
   463 
   463 
   464 		if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) {
   464 		if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) {
   465 			free(_network_ban_list[i]);
   465 			free(_network_ban_list[i]);
   466 			_network_ban_list[i] = NULL;
   466 			_network_ban_list[i] = NULL;
   467 			IConsolePrint(_icolour_def, "IP unbanned.");
   467 			IConsolePrint(CC_DEFAULT, "IP unbanned.");
   468 			return true;
   468 			return true;
   469 		}
   469 		}
   470 	}
   470 	}
   471 
   471 
   472 	IConsolePrint(_icolour_def, "IP not in ban-list.");
   472 	IConsolePrint(CC_DEFAULT, "IP not in ban-list.");
   473 	return true;
   473 	return true;
   474 }
   474 }
   475 
   475 
   476 DEF_CONSOLE_CMD(ConBanList)
   476 DEF_CONSOLE_CMD(ConBanList)
   477 {
   477 {
   480 	if (argc == 0) {
   480 	if (argc == 0) {
   481 		IConsoleHelp("List the IP's of banned clients: Usage 'banlist'");
   481 		IConsoleHelp("List the IP's of banned clients: Usage 'banlist'");
   482 		return true;
   482 		return true;
   483 	}
   483 	}
   484 
   484 
   485 	IConsolePrint(_icolour_def, "Banlist: ");
   485 	IConsolePrint(CC_DEFAULT, "Banlist: ");
   486 
   486 
   487 	for (i = 0; i < lengthof(_network_ban_list); i++) {
   487 	for (i = 0; i < lengthof(_network_ban_list); i++) {
   488 		if (_network_ban_list[i] != NULL)
   488 		if (_network_ban_list[i] != NULL)
   489 			IConsolePrintF(_icolour_def, "  %d) %s", i + 1, _network_ban_list[i]);
   489 			IConsolePrintF(CC_DEFAULT, "  %d) %s", i + 1, _network_ban_list[i]);
   490 	}
   490 	}
   491 
   491 
   492 	return true;
   492 	return true;
   493 }
   493 }
   494 
   494 
   499 		return true;
   499 		return true;
   500 	}
   500 	}
   501 
   501 
   502 	if (_pause_game == 0) {
   502 	if (_pause_game == 0) {
   503 		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
   503 		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
   504 		IConsolePrint(_icolour_def, "Game paused.");
   504 		IConsolePrint(CC_DEFAULT, "Game paused.");
   505 	} else {
   505 	} else {
   506 		IConsolePrint(_icolour_def, "Game is already paused.");
   506 		IConsolePrint(CC_DEFAULT, "Game is already paused.");
   507 	}
   507 	}
   508 
   508 
   509 	return true;
   509 	return true;
   510 }
   510 }
   511 
   511 
   516 		return true;
   516 		return true;
   517 	}
   517 	}
   518 
   518 
   519 	if (_pause_game != 0) {
   519 	if (_pause_game != 0) {
   520 		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
   520 		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
   521 		IConsolePrint(_icolour_def, "Game unpaused.");
   521 		IConsolePrint(CC_DEFAULT, "Game unpaused.");
   522 	} else {
   522 	} else {
   523 		IConsolePrint(_icolour_def, "Game is already unpaused.");
   523 		IConsolePrint(CC_DEFAULT, "Game is already unpaused.");
   524 	}
   524 	}
   525 
   525 
   526 	return true;
   526 	return true;
   527 }
   527 }
   528 
   528 
   568 		int lag = NetworkCalculateLag(cs);
   568 		int lag = NetworkCalculateLag(cs);
   569 		const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
   569 		const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
   570 		const char* status;
   570 		const char* status;
   571 
   571 
   572 		status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
   572 		status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
   573 		IConsolePrintF(8, "Client #%1d  name: '%s'  status: '%s'  frame-lag: %3d  company: %1d  IP: %s  unique-id: '%s'",
   573 		IConsolePrintF(CC_INFO, "Client #%1d  name: '%s'  status: '%s'  frame-lag: %3d  company: %1d  IP: %s  unique-id: '%s'",
   574 			cs->index, ci->client_name, status, lag,
   574 			cs->index, ci->client_name, status, lag,
   575 			ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
   575 			ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
   576 			GetPlayerIP(ci), ci->unique_id);
   576 			GetPlayerIP(ci), ci->unique_id);
   577 	}
   577 	}
   578 
   578 
   588 		IConsoleHelp("You can change these values by setting the variables 'max_clients', 'max_companies' and 'max_spectators'");
   588 		IConsoleHelp("You can change these values by setting the variables 'max_clients', 'max_companies' and 'max_spectators'");
   589 		return true;
   589 		return true;
   590 	}
   590 	}
   591 
   591 
   592 	gi = &_network_game_info;
   592 	gi = &_network_game_info;
   593 	IConsolePrintF(_icolour_def, "Current/maximum clients:    %2d/%2d", gi->clients_on, gi->clients_max);
   593 	IConsolePrintF(CC_DEFAULT, "Current/maximum clients:    %2d/%2d", gi->clients_on, gi->clients_max);
   594 	IConsolePrintF(_icolour_def, "Current/maximum companies:  %2d/%2d", ActivePlayerCount(), gi->companies_max);
   594 	IConsolePrintF(CC_DEFAULT, "Current/maximum companies:  %2d/%2d", ActivePlayerCount(), gi->companies_max);
   595 	IConsolePrintF(_icolour_def, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), gi->spectators_max);
   595 	IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), gi->spectators_max);
   596 
   596 
   597 	return true;
   597 	return true;
   598 }
   598 }
   599 
   599 
   600 DEF_CONSOLE_HOOK(ConHookValidateMaxClientsCount)
   600 DEF_CONSOLE_HOOK(ConHookValidateMaxClientsCount)
   691 
   691 
   692 	index = (PlayerID)(atoi(argv[1]) - 1);
   692 	index = (PlayerID)(atoi(argv[1]) - 1);
   693 
   693 
   694 	/* Check valid range */
   694 	/* Check valid range */
   695 	if (!IsValidPlayer(index)) {
   695 	if (!IsValidPlayer(index)) {
   696 		IConsolePrintF(_icolour_err, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
   696 		IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
   697 		return true;
   697 		return true;
   698 	}
   698 	}
   699 
   699 
   700 	/* Check if company does exist */
   700 	/* Check if company does exist */
   701 	p = GetPlayer(index);
   701 	p = GetPlayer(index);
   723 		return true;
   723 		return true;
   724 	}
   724 	}
   725 
   725 
   726 	/* It is safe to remove this company */
   726 	/* It is safe to remove this company */
   727 	DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
   727 	DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
   728 	IConsolePrint(_icolour_def, "Company deleted.");
   728 	IConsolePrint(CC_DEFAULT, "Company deleted.");
   729 
   729 
   730 	return true;
   730 	return true;
   731 }
   731 }
   732 
   732 
   733 DEF_CONSOLE_CMD(ConNetworkClients)
   733 DEF_CONSOLE_CMD(ConNetworkClients)
   738 		IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
   738 		IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
   739 		return true;
   739 		return true;
   740 	}
   740 	}
   741 
   741 
   742 	FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
   742 	FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
   743 		IConsolePrintF(8, "Client #%1d  name: '%s'  company: %1d  IP: %s",
   743 		IConsolePrintF(CC_INFO, "Client #%1d  name: '%s'  company: %1d  IP: %s",
   744 		               ci->client_index, ci->client_name,
   744 		               ci->client_index, ci->client_name,
   745 		               ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
   745 		               ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
   746 		               GetPlayerIP(ci));
   746 		               GetPlayerIP(ci));
   747 	}
   747 	}
   748 
   748 
   771 	rport = NETWORK_DEFAULT_PORT;
   771 	rport = NETWORK_DEFAULT_PORT;
   772 	_network_playas = PLAYER_NEW_COMPANY;
   772 	_network_playas = PLAYER_NEW_COMPANY;
   773 
   773 
   774 	ParseConnectionString(&player, &port, ip);
   774 	ParseConnectionString(&player, &port, ip);
   775 
   775 
   776 	IConsolePrintF(_icolour_def, "Connecting to %s...", ip);
   776 	IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
   777 	if (player != NULL) {
   777 	if (player != NULL) {
   778 		_network_playas = (PlayerID)atoi(player);
   778 		_network_playas = (PlayerID)atoi(player);
   779 		IConsolePrintF(_icolour_def, "    player-no: %d", _network_playas);
   779 		IConsolePrintF(CC_DEFAULT, "    player-no: %d", _network_playas);
   780 
   780 
   781 		/* From a user pov 0 is a new player, internally it's different and all
   781 		/* From a user pov 0 is a new player, internally it's different and all
   782 		 * players are offset by one to ease up on users (eg players 1-8 not 0-7) */
   782 		 * players are offset by one to ease up on users (eg players 1-8 not 0-7) */
   783 		if (_network_playas != PLAYER_SPECTATOR) {
   783 		if (_network_playas != PLAYER_SPECTATOR) {
   784 			_network_playas--;
   784 			_network_playas--;
   785 			if (!IsValidPlayer(_network_playas)) return false;
   785 			if (!IsValidPlayer(_network_playas)) return false;
   786 		}
   786 		}
   787 	}
   787 	}
   788 	if (port != NULL) {
   788 	if (port != NULL) {
   789 		rport = atoi(port);
   789 		rport = atoi(port);
   790 		IConsolePrintF(_icolour_def, "    port: %s", port);
   790 		IConsolePrintF(CC_DEFAULT, "    port: %s", port);
   791 	}
   791 	}
   792 
   792 
   793 	NetworkClientConnectGame(ip, rport);
   793 	NetworkClientConnectGame(ip, rport);
   794 
   794 
   795 	return true;
   795 	return true;
   868 	}
   868 	}
   869 
   869 
   870 	if (!CloseConsoleLogIfActive()) {
   870 	if (!CloseConsoleLogIfActive()) {
   871 		if (argc < 2) return false;
   871 		if (argc < 2) return false;
   872 
   872 
   873 		IConsolePrintF(_icolour_def, "file output started to: %s", argv[1]);
   873 		IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
   874 		_iconsole_output_file = fopen(argv[1], "ab");
   874 		_iconsole_output_file = fopen(argv[1], "ab");
   875 		if (_iconsole_output_file == NULL) IConsoleError("could not open file");
   875 		if (_iconsole_output_file == NULL) IConsoleError("could not open file");
   876 	}
   876 	}
   877 
   877 
   878 	return true;
   878 	return true;
   885 		IConsoleHelp("Print back the first argument to the console. Usage: 'echo <arg>'");
   885 		IConsoleHelp("Print back the first argument to the console. Usage: 'echo <arg>'");
   886 		return true;
   886 		return true;
   887 	}
   887 	}
   888 
   888 
   889 	if (argc < 2) return false;
   889 	if (argc < 2) return false;
   890 	IConsolePrint(_icolour_def, argv[1]);
   890 	IConsolePrint(CC_DEFAULT, argv[1]);
   891 	return true;
   891 	return true;
   892 }
   892 }
   893 
   893 
   894 DEF_CONSOLE_CMD(ConEchoC)
   894 DEF_CONSOLE_CMD(ConEchoC)
   895 {
   895 {
   897 		IConsoleHelp("Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
   897 		IConsoleHelp("Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
   898 		return true;
   898 		return true;
   899 	}
   899 	}
   900 
   900 
   901 	if (argc < 3) return false;
   901 	if (argc < 3) return false;
   902 	IConsolePrint(atoi(argv[1]), argv[2]);
   902 	IConsolePrint((ConsoleColour)atoi(argv[1]), argv[2]);
   903 	return true;
   903 	return true;
   904 }
   904 }
   905 
   905 
   906 DEF_CONSOLE_CMD(ConNewGame)
   906 DEF_CONSOLE_CMD(ConNewGame)
   907 {
   907 {
   938 		IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
   938 		IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
   939 		IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
   939 		IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
   940 		return true;
   940 		return true;
   941 	}
   941 	}
   942 
   942 
   943 	IConsolePrintF(_icolour_def, "Generation Seed: %u", _patches.generation_seed);
   943 	IConsolePrintF(CC_DEFAULT, "Generation Seed: %u", _patches.generation_seed);
   944 	return true;
   944 	return true;
   945 }
   945 }
   946 
   946 
   947 DEF_CONSOLE_CMD(ConGetDate)
   947 DEF_CONSOLE_CMD(ConGetDate)
   948 {
   948 {
   951 		return true;
   951 		return true;
   952 	}
   952 	}
   953 
   953 
   954 	YearMonthDay ymd;
   954 	YearMonthDay ymd;
   955 	ConvertDateToYMD(_date, &ymd);
   955 	ConvertDateToYMD(_date, &ymd);
   956 	IConsolePrintF(_icolour_def, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
   956 	IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
   957 	return true;
   957 	return true;
   958 }
   958 }
   959 
   959 
   960 
   960 
   961 DEF_CONSOLE_CMD(ConAlias)
   961 DEF_CONSOLE_CMD(ConAlias)
  1017 	if (var == NULL) {
  1017 	if (var == NULL) {
  1018 		IConsoleError("the given variable was not found");
  1018 		IConsoleError("the given variable was not found");
  1019 		return true;
  1019 		return true;
  1020 	}
  1020 	}
  1021 
  1021 
  1022 	IConsolePrintF(_icolour_def, "variable name: %s", var->name);
  1022 	IConsolePrintF(CC_DEFAULT, "variable name: %s", var->name);
  1023 	IConsolePrintF(_icolour_def, "variable type: %s", _icon_vartypes[var->type]);
  1023 	IConsolePrintF(CC_DEFAULT, "variable type: %s", _icon_vartypes[var->type]);
  1024 	IConsolePrintF(_icolour_def, "variable addr: 0x%X", var->addr);
  1024 	IConsolePrintF(CC_DEFAULT, "variable addr: 0x%X", var->addr);
  1025 
  1025 
  1026 	if (var->hook.access) IConsoleWarning("variable is access hooked");
  1026 	if (var->hook.access) IConsoleWarning("variable is access hooked");
  1027 	if (var->hook.pre) IConsoleWarning("variable is pre hooked");
  1027 	if (var->hook.pre) IConsoleWarning("variable is pre hooked");
  1028 	if (var->hook.post) IConsoleWarning("variable is post hooked");
  1028 	if (var->hook.post) IConsoleWarning("variable is post hooked");
  1029 	return true;
  1029 	return true;
  1045 	if (cmd == NULL) {
  1045 	if (cmd == NULL) {
  1046 		IConsoleError("the given command was not found");
  1046 		IConsoleError("the given command was not found");
  1047 		return true;
  1047 		return true;
  1048 	}
  1048 	}
  1049 
  1049 
  1050 	IConsolePrintF(_icolour_def, "command name: %s", cmd->name);
  1050 	IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
  1051 	IConsolePrintF(_icolour_def, "command proc: 0x%X", cmd->proc);
  1051 	IConsolePrintF(CC_DEFAULT, "command proc: 0x%X", cmd->proc);
  1052 
  1052 
  1053 	if (cmd->hook.access) IConsoleWarning("command is access hooked");
  1053 	if (cmd->hook.access) IConsoleWarning("command is access hooked");
  1054 	if (cmd->hook.pre) IConsoleWarning("command is pre hooked");
  1054 	if (cmd->hook.pre) IConsoleWarning("command is pre hooked");
  1055 	if (cmd->hook.post) IConsoleWarning("command is post hooked");
  1055 	if (cmd->hook.post) IConsoleWarning("command is post hooked");
  1056 
  1056 
  1066 	}
  1066 	}
  1067 
  1067 
  1068 	if (argc > 2) return false;
  1068 	if (argc > 2) return false;
  1069 
  1069 
  1070 	if (argc == 1) {
  1070 	if (argc == 1) {
  1071 		IConsolePrintF(_icolour_def, "Current debug-level: '%s'", GetDebugString());
  1071 		IConsolePrintF(CC_DEFAULT, "Current debug-level: '%s'", GetDebugString());
  1072 	} else {
  1072 	} else {
  1073 		SetDebugString(argv[1]);
  1073 		SetDebugString(argv[1]);
  1074 	}
  1074 	}
  1075 
  1075 
  1076 	return true;
  1076 	return true;
  1120 			cmd = IConsoleCmdGet(alias->cmdline);
  1120 			cmd = IConsoleCmdGet(alias->cmdline);
  1121 			if (cmd != NULL) {
  1121 			if (cmd != NULL) {
  1122 				cmd->proc(0, NULL);
  1122 				cmd->proc(0, NULL);
  1123 				return true;
  1123 				return true;
  1124 			}
  1124 			}
  1125 			IConsolePrintF(_icolour_err, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
  1125 			IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
  1126 			return true;
  1126 			return true;
  1127 		}
  1127 		}
  1128 
  1128 
  1129 		var = IConsoleVarGet(argv[1]);
  1129 		var = IConsoleVarGet(argv[1]);
  1130 		if (var != NULL && var->help != NULL) {
  1130 		if (var != NULL && var->help != NULL) {
  1134 
  1134 
  1135 		IConsoleError("command or variable not found");
  1135 		IConsoleError("command or variable not found");
  1136 		return true;
  1136 		return true;
  1137 	}
  1137 	}
  1138 
  1138 
  1139 	IConsolePrint(13, " ---- OpenTTD Console Help ---- ");
  1139 	IConsolePrint(CC_WARNING, " ---- OpenTTD Console Help ---- ");
  1140 	IConsolePrint( 1, " - variables: [command to list all variables: list_vars]");
  1140 	IConsolePrint(CC_DEFAULT, " - variables: [command to list all variables: list_vars]");
  1141 	IConsolePrint( 1, " set value with '<var> = <value>', use '++/--' to in-or decrement");
  1141 	IConsolePrint(CC_DEFAULT, " set value with '<var> = <value>', use '++/--' to in-or decrement");
  1142 	IConsolePrint( 1, " or omit '=' and just '<var> <value>'. get value with typing '<var>'");
  1142 	IConsolePrint(CC_DEFAULT, " or omit '=' and just '<var> <value>'. get value with typing '<var>'");
  1143 	IConsolePrint( 1, " - commands: [command to list all commands: list_cmds]");
  1143 	IConsolePrint(CC_DEFAULT, " - commands: [command to list all commands: list_cmds]");
  1144 	IConsolePrint( 1, " call commands with '<command> <arg2> <arg3>...'");
  1144 	IConsolePrint(CC_DEFAULT, " call commands with '<command> <arg2> <arg3>...'");
  1145 	IConsolePrint( 1, " - to assign strings, or use them as arguments, enclose it within quotes");
  1145 	IConsolePrint(CC_DEFAULT, " - to assign strings, or use them as arguments, enclose it within quotes");
  1146 	IConsolePrint( 1, " like this: '<command> \"string argument with spaces\"'");
  1146 	IConsolePrint(CC_DEFAULT, " like this: '<command> \"string argument with spaces\"'");
  1147 	IConsolePrint( 1, " - use 'help <command> | <variable>' to get specific information");
  1147 	IConsolePrint(CC_DEFAULT, " - use 'help <command> | <variable>' to get specific information");
  1148 	IConsolePrint( 1, " - scroll console output with shift + (up | down) | (pageup | pagedown))");
  1148 	IConsolePrint(CC_DEFAULT, " - scroll console output with shift + (up | down) | (pageup | pagedown))");
  1149 	IConsolePrint( 1, " - scroll console input history with the up | down arrows");
  1149 	IConsolePrint(CC_DEFAULT, " - scroll console input history with the up | down arrows");
  1150 	IConsolePrint( 1, "");
  1150 	IConsolePrint(CC_DEFAULT, "");
  1151 	return true;
  1151 	return true;
  1152 }
  1152 }
  1153 
  1153 
  1154 DEF_CONSOLE_CMD(ConListCommands)
  1154 DEF_CONSOLE_CMD(ConListCommands)
  1155 {
  1155 {
  1163 
  1163 
  1164 	if (argv[1] != NULL) l = strlen(argv[1]);
  1164 	if (argv[1] != NULL) l = strlen(argv[1]);
  1165 
  1165 
  1166 	for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
  1166 	for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
  1167 		if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) {
  1167 		if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) {
  1168 				IConsolePrintF(_icolour_def, "%s", cmd->name);
  1168 				IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
  1169 		}
  1169 		}
  1170 	}
  1170 	}
  1171 
  1171 
  1172 	return true;
  1172 	return true;
  1173 }
  1173 }
  1184 
  1184 
  1185 	if (argv[1] != NULL) l = strlen(argv[1]);
  1185 	if (argv[1] != NULL) l = strlen(argv[1]);
  1186 
  1186 
  1187 	for (var = _iconsole_vars; var != NULL; var = var->next) {
  1187 	for (var = _iconsole_vars; var != NULL; var = var->next) {
  1188 		if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
  1188 		if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
  1189 			IConsolePrintF(_icolour_def, "%s", var->name);
  1189 			IConsolePrintF(CC_DEFAULT, "%s", var->name);
  1190 	}
  1190 	}
  1191 
  1191 
  1192 	return true;
  1192 	return true;
  1193 }
  1193 }
  1194 
  1194 
  1204 
  1204 
  1205 	if (argv[1] != NULL) l = strlen(argv[1]);
  1205 	if (argv[1] != NULL) l = strlen(argv[1]);
  1206 
  1206 
  1207 	for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
  1207 	for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
  1208 		if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0)
  1208 		if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0)
  1209 			IConsolePrintF(_icolour_def, "%s => %s", alias->name, alias->cmdline);
  1209 			IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
  1210 	}
  1210 	}
  1211 
  1211 
  1212 	return true;
  1212 	return true;
  1213 }
  1213 }
  1214 
  1214 
  1248 		if (!p->is_active) continue;
  1248 		if (!p->is_active) continue;
  1249 
  1249 
  1250 		const NetworkPlayerInfo *npi = &_network_player_info[p->index];
  1250 		const NetworkPlayerInfo *npi = &_network_player_info[p->index];
  1251 
  1251 
  1252 		GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index], lastof(buffer));
  1252 		GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index], lastof(buffer));
  1253 		IConsolePrintF(8, "#:%d(%s) Company Name: '%s'  Year Founded: %d  Money: %" OTTD_PRINTF64 "d  Loan: %" OTTD_PRINTF64 "d  Value: %" OTTD_PRINTF64 "d  (T:%d, R:%d, P:%d, S:%d) %sprotected",
  1253 		IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s'  Year Founded: %d  Money: %" OTTD_PRINTF64 "d  Loan: %" OTTD_PRINTF64 "d  Value: %" OTTD_PRINTF64 "d  (T:%d, R:%d, P:%d, S:%d) %sprotected",
  1254 			p->index + 1, buffer, npi->company_name, p->inaugurated_year, (int64)p->player_money, (int64)p->current_loan, (int64)CalculateCompanyValue(p),
  1254 			p->index + 1, buffer, npi->company_name, p->inaugurated_year, (int64)p->player_money, (int64)p->current_loan, (int64)CalculateCompanyValue(p),
  1255 			/* trains      */ npi->num_vehicle[0],
  1255 			/* trains      */ npi->num_vehicle[0],
  1256 			/* lorry + bus */ npi->num_vehicle[1] + npi->num_vehicle[2],
  1256 			/* lorry + bus */ npi->num_vehicle[1] + npi->num_vehicle[2],
  1257 			/* planes      */ npi->num_vehicle[3],
  1257 			/* planes      */ npi->num_vehicle[3],
  1258 			/* ships       */ npi->num_vehicle[4],
  1258 			/* ships       */ npi->num_vehicle[4],
  1271 	}
  1271 	}
  1272 
  1272 
  1273 	if (argc != 3) return false;
  1273 	if (argc != 3) return false;
  1274 
  1274 
  1275 	if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) {
  1275 	if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) {
  1276 		IConsolePrintF(_icolour_def, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
  1276 		IConsolePrintF(CC_DEFAULT, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
  1277 		return true;
  1277 		return true;
  1278 	}
  1278 	}
  1279 
  1279 
  1280 	if (!_network_server) {
  1280 	if (!_network_server) {
  1281 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, atoi(argv[1]), argv[2]);
  1281 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, atoi(argv[1]), argv[2]);
  1333 /* Also use from within player_gui to change the password graphically */
  1333 /* Also use from within player_gui to change the password graphically */
  1334 bool NetworkChangeCompanyPassword(byte argc, char *argv[])
  1334 bool NetworkChangeCompanyPassword(byte argc, char *argv[])
  1335 {
  1335 {
  1336 	if (argc == 0) {
  1336 	if (argc == 0) {
  1337 		if (!IsValidPlayer(_local_player)) return true; // dedicated server
  1337 		if (!IsValidPlayer(_local_player)) return true; // dedicated server
  1338 		IConsolePrintF(_icolour_warn, "Current value for 'company_pw': %s", _network_player_info[_local_player].password);
  1338 		IConsolePrintF(CC_WARNING, "Current value for 'company_pw': %s", _network_player_info[_local_player].password);
  1339 		return true;
  1339 		return true;
  1340 	}
  1340 	}
  1341 
  1341 
  1342 	if (!IsValidPlayer(_local_player)) {
  1342 	if (!IsValidPlayer(_local_player)) {
  1343 		IConsoleError("You have to own a company to make use of this command.");
  1343 		IConsoleError("You have to own a company to make use of this command.");
  1354 		SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
  1354 		SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
  1355 	} else {
  1355 	} else {
  1356 		HashCurrentCompanyPassword();
  1356 		HashCurrentCompanyPassword();
  1357 	}
  1357 	}
  1358 
  1358 
  1359 	IConsolePrintF(_icolour_warn, "'company_pw' changed to:  %s", _network_player_info[_local_player].password);
  1359 	IConsolePrintF(CC_WARNING, "'company_pw' changed to:  %s", _network_player_info[_local_player].password);
  1360 
  1360 
  1361 	return true;
  1361 	return true;
  1362 }
  1362 }
  1363 
  1363 
  1364 DEF_CONSOLE_HOOK(ConProcPlayerName)
  1364 DEF_CONSOLE_HOOK(ConProcPlayerName)
  1371 	if (strcmp(ci->client_name, _network_player_name) != 0) {
  1371 	if (strcmp(ci->client_name, _network_player_name) != 0) {
  1372 		if (!_network_server) {
  1372 		if (!_network_server) {
  1373 			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name);
  1373 			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name);
  1374 		} else {
  1374 		} else {
  1375 			if (NetworkFindName(_network_player_name)) {
  1375 			if (NetworkFindName(_network_player_name)) {
  1376 				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", _network_player_name);
  1376 				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _network_player_name);
  1377 				ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
  1377 				ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
  1378 				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
  1378 				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
  1379 			}
  1379 			}
  1380 		}
  1380 		}
  1381 	}
  1381 	}
  1398 }
  1398 }
  1399 
  1399 
  1400 DEF_CONSOLE_CMD(ConProcServerIP)
  1400 DEF_CONSOLE_CMD(ConProcServerIP)
  1401 {
  1401 {
  1402 	if (argc == 0) {
  1402 	if (argc == 0) {
  1403 		IConsolePrintF(_icolour_warn, "Current value for 'server_ip': %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
  1403 		IConsolePrintF(CC_WARNING, "Current value for 'server_ip': %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
  1404 		return true;
  1404 		return true;
  1405 	}
  1405 	}
  1406 
  1406 
  1407 	if (argc != 1) return false;
  1407 	if (argc != 1) return false;
  1408 
  1408 
  1409 	_network_server_bind_ip = (strcmp(argv[0], "all") == 0) ? inet_addr("0.0.0.0") : inet_addr(argv[0]);
  1409 	_network_server_bind_ip = (strcmp(argv[0], "all") == 0) ? inet_addr("0.0.0.0") : inet_addr(argv[0]);
  1410 	snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
  1410 	snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
  1411 	IConsolePrintF(_icolour_warn, "'server_ip' changed to:  %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
  1411 	IConsolePrintF(CC_WARNING, "'server_ip' changed to:  %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
  1412 	return true;
  1412 	return true;
  1413 }
  1413 }
  1414 #endif /* ENABLE_NETWORK */
  1414 #endif /* ENABLE_NETWORK */
  1415 
  1415 
  1416 DEF_CONSOLE_CMD(ConPatch)
  1416 DEF_CONSOLE_CMD(ConPatch)