console_cmds.c
changeset 1739 4c8fb3905cbd
parent 1602 79f98b4b83fc
child 1740 f7af92074430
equal deleted inserted replaced
1738:dfa8f078450a 1739:4c8fb3905cbd
     1 /* -------------------- dont cross this line --------------------- */
       
     2 #include "stdafx.h"
     1 #include "stdafx.h"
     3 #include "ttd.h"
     2 #include "ttd.h"
     4 #include "console.h"
     3 #include "console.h"
     5 #include "debug.h"
     4 #include "debug.h"
     6 #include "engine.h"
     5 #include "engine.h"
    13 #include "network_udp.h"
    12 #include "network_udp.h"
    14 #include "command.h"
    13 #include "command.h"
    15 #include "settings.h"
    14 #include "settings.h"
    16 #include "hal.h" /* for file list */
    15 #include "hal.h" /* for file list */
    17 
    16 
    18 
       
    19 // ** scriptfile handling ** //
    17 // ** scriptfile handling ** //
    20 static FILE * _script_file;
    18 static FILE *_script_file;
    21 static bool _script_running;
    19 static bool _script_running;
    22 
    20 
    23 // ** console command / variable defines ** //
    21 // ** console command / variable defines ** //
    24 
    22 #define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
    25 #define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, char* argv[], byte argt[])
    23 #define DEF_CONSOLE_HOOK(function) static bool function(void)
    26 #define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd)
    24 
    27 #define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar)
       
    28 
       
    29 
       
    30 // ** supporting functions ** //
       
    31 
       
    32 static uint32 GetArgumentInteger(const char* arg)
       
    33 {
       
    34 	uint32 result;
       
    35 	sscanf(arg, "%u", &result);
       
    36 
       
    37 	if (result == 0 && arg[0] == '0' && arg[1] == 'x')
       
    38 		sscanf(arg, "%x", &result);
       
    39 
       
    40 	return result;
       
    41 }
       
    42 
    25 
    43 /* **************************** */
    26 /* **************************** */
    44 /* variable and command hooks   */
    27 /* variable and command hooks   */
    45 /* **************************** */
    28 /* **************************** */
    46 
    29 
    47 #ifdef ENABLE_NETWORK
    30 #ifdef ENABLE_NETWORK
    48 
    31 
    49 DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetwork)
    32 static inline bool NetworkAvailable(void)
       
    33 {
       
    34 	if (!_network_available) {
       
    35 		IConsoleError("You cannot use this command because there is no network available.");
       
    36 		return false;
       
    37 	}
       
    38 	return true;
       
    39 }
       
    40 
       
    41 DEF_CONSOLE_HOOK(ConHookServerOnly)
       
    42 {
       
    43 	if (!NetworkAvailable()) return false;
       
    44 
       
    45 	if (!_network_server) {
       
    46 		IConsoleError("This variable is only available to a network server.");
       
    47 		return false;
       
    48 	}
       
    49 	return true;
       
    50 }
       
    51 
       
    52 DEF_CONSOLE_HOOK(ConHookClientOnly)
       
    53 {
       
    54 	if (!NetworkAvailable()) return false;
       
    55 
       
    56 	if (_network_server) {
       
    57 		IConsoleError("This command is not available to a network server.");
       
    58 		return false;
       
    59 	}
       
    60 	return true;
       
    61 }
       
    62 
       
    63 DEF_CONSOLE_HOOK(ConHookNeedNetwork)
       
    64 {
       
    65 	if (!NetworkAvailable()) return false;
       
    66 
       
    67 	if (!_networking) {
       
    68 		IConsoleError("Not connected. This command is only available in multiplayer.");
       
    69 		return false;
       
    70 	}
       
    71 	return true;
       
    72 }
       
    73 
       
    74 DEF_CONSOLE_HOOK(ConHookNoNetwork)
    50 {
    75 {
    51 	if (_networking) {
    76 	if (_networking) {
    52 		IConsoleError("This command is forbidden in multiplayer.");
    77 		IConsoleError("This command is forbidden in multiplayer.");
    53 		return false;
    78 		return false;
    54 	}
    79 	}
    55 	return true;
    80 	return true;
    56 }
    81 }
    57 
    82 
    58 DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
       
    59 {
       
    60 	if (!_network_available) {
       
    61 		IConsoleError("You can not use this command because there is no network available.");
       
    62 		return false;
       
    63 	}
       
    64 	if (!_network_server) {
       
    65 		IConsoleError("This variable only makes sense for a network server.");
       
    66 		return false;
       
    67 	}
       
    68 	return true;
       
    69 }
       
    70 
       
    71 DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetClient)
       
    72 {
       
    73 	if (!_network_available) {
       
    74 		IConsoleError("You can not use this command because there is no network available.");
       
    75 		return false;
       
    76 	}
       
    77 	if (!_network_server) {
       
    78 		IConsoleError("This command is only available for a network server.");
       
    79 		return false;
       
    80 	}
       
    81 	return true;
       
    82 }
       
    83 
       
    84 DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetServer)
       
    85 {
       
    86 	if (!_network_available) {
       
    87 		IConsoleError("You can not use this command because there is no network available.");
       
    88 		return false;
       
    89 	}
       
    90 	if (_network_server) {
       
    91 		IConsoleError("You can not use this command because you are a network-server.");
       
    92 		return false;
       
    93 	}
       
    94 	return true;
       
    95 }
       
    96 
       
    97 DEF_CONSOLE_CMD_HOOK(ConCmdHookNeedNetwork)
       
    98 {
       
    99 	if (!_network_available) {
       
   100 		IConsoleError("You can not use this command because there is no network available.");
       
   101 		return false;
       
   102 	}
       
   103 	if (!_networking) {
       
   104 		IConsoleError("Not connected. Multiplayer only command.");
       
   105 		return false;
       
   106 	}
       
   107 	return true;
       
   108 }
       
   109 
       
   110 #endif /* ENABLE_NETWORK */
    83 #endif /* ENABLE_NETWORK */
   111 
    84 
   112 /* **************************** */
    85 static void IConsoleHelp(const char *str)
   113 /* reset commands               */
    86 {
   114 /* **************************** */
    87 	IConsolePrintF(_iconsole_color_warning, "- %s", str);
       
    88 }
   115 
    89 
   116 DEF_CONSOLE_CMD(ConResetEngines)
    90 DEF_CONSOLE_CMD(ConResetEngines)
   117 {
    91 {
       
    92 	if (argc == 0) {
       
    93 		IConsoleHelp("Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'");
       
    94 		return true;
       
    95 	}
       
    96 
   118 	StartupEngines();
    97 	StartupEngines();
   119 	return 0;
    98 	return true;
   120 }
    99 }
   121 
   100 
   122 #ifdef _DEBUG
   101 #ifdef _DEBUG
   123 DEF_CONSOLE_CMD(ConResetTile)
   102 DEF_CONSOLE_CMD(ConResetTile)
   124 {
   103 {
       
   104 	if (argc == 0) {
       
   105 		IConsoleHelp("Reset a tile to bare land. Usage: 'resettile <tile>'");
       
   106 		IConsoleHelp("Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
       
   107 		return true;
       
   108 	}
       
   109 
   125 	if (argc == 2) {
   110 	if (argc == 2) {
   126 		TileIndex tile = (TileIndex)GetArgumentInteger(argv[1]);
   111 		uint32 result;
   127 		DoClearSquare(tile);
   112 		if (GetArgumentInteger(&result, argv[1])) {
   128 	}
   113 			DoClearSquare((TileIndex)result);
   129 
   114 			return true;
   130 	return 0;
   115 		}
   131 }
   116 	}
   132 #endif
   117 
       
   118 	return false;
       
   119 }
   133 
   120 
   134 DEF_CONSOLE_CMD(ConScrollToTile)
   121 DEF_CONSOLE_CMD(ConScrollToTile)
   135 {
   122 {
       
   123 	if (argc == 0) {
       
   124 		IConsoleHelp("Center the screen on a given tile. Usage: 'scrollto <tile>'");
       
   125 		IConsoleHelp("Tile can be either decimal (34161) or hexadecimal (0x4a5B)");
       
   126 		return true;
       
   127 	}
       
   128 
   136 	if (argc == 2) {
   129 	if (argc == 2) {
   137 		TileIndex tile = (TileIndex)GetArgumentInteger(argv[1]);
   130 		uint32 result;
   138 		ScrollMainWindowToTile(tile);
   131 		if (GetArgumentInteger(&result, argv[1])) {
   139 	}
   132 			ScrollMainWindowToTile((TileIndex)result);
   140 
   133 			return true;
   141 	return 0;
   134 		}
   142 }
   135 	}
       
   136 
       
   137 	return false;
       
   138 }
       
   139 #endif /* _DEBUG */
   143 
   140 
   144 extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
   141 extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
   145 extern void BuildFileList(void);
   142 extern void BuildFileList(void);
   146 extern void SetFiosType(const byte fiostype);
   143 extern void SetFiosType(const byte fiostype);
   147 
   144 
   148 /* Save the map to current dir */
       
   149 static void SaveMap(const char *filename)
       
   150 {
       
   151 	char buf[200];
       
   152 
       
   153 	snprintf(buf, lengthof(buf), "%s%s%s.sav", _path.save_dir, PATHSEP, filename);
       
   154 	IConsolePrint(_iconsole_color_default, "Saving map...");
       
   155 
       
   156 	if (SaveOrLoad(buf, SL_SAVE) != SL_OK) {
       
   157 		IConsolePrint(_iconsole_color_error, "SaveMap failed");
       
   158 	} else
       
   159 		IConsolePrintF(_iconsole_color_default, "Map sucessfully saved to %s", buf);
       
   160 }
       
   161 
       
   162 /* Save the map to a file */
   145 /* Save the map to a file */
   163 DEF_CONSOLE_CMD(ConSave)
   146 DEF_CONSOLE_CMD(ConSave)
   164 {
   147 {
   165 	/* We need 1 argument */
   148 	if (argc == 0) {
       
   149 		IConsoleHelp("Save the current game. Usage: 'save <filename>'");
       
   150 		return true;
       
   151 	}
       
   152 
   166 	if (argc == 2) {
   153 	if (argc == 2) {
   167 		/* Save the map */
   154 		char buf[200];
   168 		SaveMap(argv[1]);
   155 
   169 		return NULL;
   156 		snprintf(buf, lengthof(buf), "%s%s%s.sav", _path.save_dir, PATHSEP, argv[1]);
   170 	}
   157 		IConsolePrint(_iconsole_color_default, "Saving map...");
   171 
   158 
   172 	/* Give usage */
   159 		if (SaveOrLoad(buf, SL_SAVE) != SL_OK) {
   173 	IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: save <filename>");
   160 			IConsolePrint(_iconsole_color_error, "SaveMap failed");
   174 	return NULL;
   161 		} else
   175 }
   162 			IConsolePrintF(_iconsole_color_default, "Map sucessfully saved to %s", buf);
   176 
   163 		return true;
       
   164 	}
       
   165 
       
   166 	return false;
       
   167 }
   177 
   168 
   178 static const FiosItem* GetFiosItem(const char* file)
   169 static const FiosItem* GetFiosItem(const char* file)
   179 {
   170 {
   180 	int i;
   171 	int i;
   181 
   172 
   196 }
   187 }
   197 
   188 
   198 
   189 
   199 DEF_CONSOLE_CMD(ConLoad)
   190 DEF_CONSOLE_CMD(ConLoad)
   200 {
   191 {
   201 	const FiosItem* item;
   192 	const FiosItem *item;
   202 	const char* file;
   193 	const char *file;
   203 
   194 
   204 	if (argc != 2) {
   195 	if (argc == 0) {
   205 		IConsolePrint(_iconsole_color_default, "Usage: load <file | number>");
   196 		IConsoleHelp("Load a game by name or index. Usage: 'load <file | number>'");
   206 		return NULL;
   197 		return true;
   207 	}
   198 	}
       
   199 
       
   200 	if (argc != 2) return false;
   208 
   201 
   209 	file = argv[1];
   202 	file = argv[1];
   210 	item = GetFiosItem(file);
   203 	item = GetFiosItem(file);
   211 	if (item != NULL) {
   204 	if (item != NULL) {
   212 		switch (item->type) {
   205 		switch (item->type) {
   213 			case FIOS_TYPE_FILE:
   206 			case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE:
   214 			case FIOS_TYPE_OLDFILE:
       
   215 				_switch_mode = SM_LOAD;
   207 				_switch_mode = SM_LOAD;
   216 				SetFiosType(item->type);
   208 				SetFiosType(item->type);
   217 				strcpy(_file_to_saveload.name, FiosBrowseTo(item));
   209 				strcpy(_file_to_saveload.name, FiosBrowseTo(item));
   218 				break;
   210 				break;
   219 
   211 			default: IConsolePrintF(_iconsole_color_error, "%s: Not a savegame.", file);
   220 			default:
       
   221 				IConsolePrintF(_iconsole_color_error, "%s: Not a map.", file);
       
   222 				break;
       
   223 		}
   212 		}
   224 	} else {
   213 	} else
   225 		IConsolePrintF(_iconsole_color_error, "%s: No such file or directory.",
   214 		IConsolePrintF(_iconsole_color_error, "%s: No such file or directory.", file);
   226 			file);
       
   227 	}
       
   228 
   215 
   229 	FiosFreeSavegameList();
   216 	FiosFreeSavegameList();
   230 	return NULL;
   217 	return true;
   231 }
   218 }
   232 
       
   233 
   219 
   234 /* List all the files in the current dir via console */
   220 /* List all the files in the current dir via console */
   235 DEF_CONSOLE_CMD(ConListFiles)
   221 DEF_CONSOLE_CMD(ConListFiles)
   236 {
   222 {
   237 	int i;
   223 	int i;
   238 
   224 
       
   225 	if (argc == 0) {
       
   226 		IConsoleHelp("List all the files in the current dir via console. Usage: 'ls | dir'");
       
   227 		return true;
       
   228 	}
       
   229 
   239 	BuildFileList();
   230 	BuildFileList();
   240 
   231 
   241 	for (i = 0; i < _fios_num; i++) {
   232 	for (i = 0; i < _fios_num; i++) {
   242 		const FiosItem* item = &_fios_list[i];
   233 		const FiosItem *item = &_fios_list[i];
   243 
   234 		IConsolePrintF(_iconsole_color_default, "%d) %s", i, (item->title[0] != '\0') ? item->title : item->name);
   244 		IConsolePrintF(_iconsole_color_default, "%d) %s",
       
   245 			i, item->title[0] != '\0' ? item->title : item->name);
       
   246 	}
   235 	}
   247 
   236 
   248 	FiosFreeSavegameList();
   237 	FiosFreeSavegameList();
   249 	return NULL;
   238 	return true;
   250 }
   239 }
   251 
       
   252 
   240 
   253 /* Change the dir via console */
   241 /* Change the dir via console */
   254 DEF_CONSOLE_CMD(ConChangeDirectory)
   242 DEF_CONSOLE_CMD(ConChangeDirectory)
   255 {
   243 {
   256 	const FiosItem* item;
   244 	const FiosItem *item;
   257 	const char* file;
   245 	const char *file;
   258 
   246 
   259 	if (argc != 2) {
   247 	if (argc == 0) {
   260 		IConsolePrint(_iconsole_color_default, "Usage: cd <directory | number>");
   248 		IConsoleHelp("Change the dir via console. Usage: 'cd <directory | number>'");
   261 		return NULL;
   249 		return true;
   262 	}
   250 	}
       
   251 
       
   252 	if (argc != 2) return false;
   263 
   253 
   264 	file = argv[1];
   254 	file = argv[1];
   265 	item = GetFiosItem(file);
   255 	item = GetFiosItem(file);
   266 	if (item != NULL) {
   256 	if (item != NULL) {
   267 		switch (item->type) {
   257 		switch (item->type) {
   268 			case FIOS_TYPE_DIR:
   258 			case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
   269 			case FIOS_TYPE_DRIVE:
       
   270 			case FIOS_TYPE_PARENT:
       
   271 				FiosBrowseTo(item);
   259 				FiosBrowseTo(item);
   272 				break;
   260 				break;
   273 
   261 			default: IConsolePrintF(_iconsole_color_error, "%s: Not a directory.", file);
   274 			default:
       
   275 				IConsolePrintF(_iconsole_color_error, "%s: Not a directory.", file);
       
   276 				break;
       
   277 		}
   262 		}
   278 	} else {
   263 	} else
   279 		IConsolePrintF(_iconsole_color_error, "%s: No such file or directory.",
   264 		IConsolePrintF(_iconsole_color_error, "%s: No such file or directory.", file);
   280 			file);
       
   281 	}
       
   282 
   265 
   283 	FiosFreeSavegameList();
   266 	FiosFreeSavegameList();
   284 	return NULL;
   267 	return true;
   285 }
   268 }
   286 
   269 
   287 
   270 
   288 DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
   271 DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
   289 {
   272 {
   290 	const char* path;
   273 	const char *path;
   291 
   274 
   292 	// XXX Workaround for broken file handling
   275 	if (argc == 0) {
       
   276 		IConsoleHelp("Print out the current working directory. Usage: 'pwd'");
       
   277 		return true;
       
   278 	}
       
   279 
       
   280 	// XXX - Workaround for broken file handling
   293 	FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
   281 	FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
   294 	FiosFreeSavegameList();
   282 	FiosFreeSavegameList();
   295 
   283 
   296 	FiosGetDescText(&path, NULL);
   284 	FiosGetDescText(&path, NULL);
   297 	IConsolePrint(_iconsole_color_default, path);
   285 	IConsolePrint(_iconsole_color_default, path);
   298 	return NULL;
   286 	return true;
   299 }
   287 }
   300 
   288 
   301 
   289 
   302 // ********************************* //
   290 // ********************************* //
   303 // * Network Core Console Commands * //
   291 // * Network Core Console Commands * //
   305 #ifdef ENABLE_NETWORK
   293 #ifdef ENABLE_NETWORK
   306 
   294 
   307 DEF_CONSOLE_CMD(ConBan)
   295 DEF_CONSOLE_CMD(ConBan)
   308 {
   296 {
   309 	NetworkClientInfo *ci;
   297 	NetworkClientInfo *ci;
   310 
   298 	uint32 index;
   311 	if (argc == 2) {
   299 
   312 		uint32 index = atoi(argv[1]);
   300 	if (argc == 0) {
   313 		if (index == NETWORK_SERVER_INDEX) {
   301 		IConsoleHelp("Ban a player from a network game. Usage: 'ban <client-id>'");
   314 			IConsolePrint(_iconsole_color_default, "Silly boy, you can not ban yourself!");
   302 		IConsoleHelp("For client-id's, see the command 'clients'");
   315 			return NULL;
   303 		return true;
   316 		}
   304 	}
   317 		if (index == 0) {
   305 
   318 			IConsoleError("Invalid Client-ID");
   306 	if (argc != 2) return false;
   319 			return NULL;
   307 
   320 		}
   308 	index = atoi(argv[1]);
   321 
   309 
   322 		ci = NetworkFindClientInfoFromIndex(index);
   310 	if (index == NETWORK_SERVER_INDEX) {
   323 
   311 		IConsolePrint(_iconsole_color_default, "Silly boy, you can not ban yourself!");
   324 		if (ci != NULL) {
   312 		return true;
   325 			uint i;
   313 	}
   326 			/* Add user to ban-list */
   314 	if (index == 0) {
   327 			for (i = 0; i < lengthof(_network_ban_list); i++) {
   315 		IConsoleError("Invalid Client-ID");
   328 				if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0') {
   316 		return true;
   329 					_network_ban_list[i] = strdup(inet_ntoa(*(struct in_addr *)&ci->client_ip));
   317 	}
   330 					break;
   318 
   331 				}
   319 	ci = NetworkFindClientInfoFromIndex(index);
   332 			}
   320 
   333 
   321 	if (ci != NULL) {
   334 			SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
       
   335 			return NULL;
       
   336 		} else {
       
   337 			IConsoleError("Client-ID not found");
       
   338 			return NULL;
       
   339 		}
       
   340 	}
       
   341 
       
   342 	IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: ban <client-id>. For client-ids, see 'clients'.");
       
   343 
       
   344 	return NULL;
       
   345 }
       
   346 
       
   347 DEF_CONSOLE_CMD(ConUnBan)
       
   348 {
       
   349 	if (argc == 2) {
       
   350 		uint i;
   322 		uint i;
       
   323 		/* Add user to ban-list */
   351 		for (i = 0; i < lengthof(_network_ban_list); i++) {
   324 		for (i = 0; i < lengthof(_network_ban_list); i++) {
   352 			if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0')
   325 			if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0') {
   353 				continue;
   326 				_network_ban_list[i] = strdup(inet_ntoa(*(struct in_addr *)&ci->client_ip));
   354 
   327 				break;
   355 			if (strncmp(_network_ban_list[i], argv[1], strlen(_network_ban_list[i])) == 0) {
       
   356 				_network_ban_list[i][0] = '\0';
       
   357 				IConsolePrint(_iconsole_color_default, "IP unbanned.");
       
   358 				return NULL;
       
   359 			}
   328 			}
   360 		}
   329 		}
   361 
   330 
   362 		IConsolePrint(_iconsole_color_default, "IP not in ban-list.");
   331 		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   363 
   332 	} else
   364 		return NULL;
   333 		IConsoleError("Client-ID not found");
   365 	}
   334 
   366 
   335 	return true;
   367 	IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: unban <ip>.");
   336 }
   368 
   337 
   369 	return NULL;
   338 DEF_CONSOLE_CMD(ConUnBan)
   370 }
       
   371 
       
   372 DEF_CONSOLE_CMD(ConBanList)
       
   373 {
   339 {
   374 	uint i;
   340 	uint i;
   375 
   341 
   376 	IConsolePrint(_iconsole_color_default, "Banlist: ");
   342 	if (argc == 0) {
       
   343 		IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip>'");
       
   344 		return true;
       
   345 	}
       
   346 
       
   347 	if (argc != 2) return false;
   377 
   348 
   378 	for (i = 0; i < lengthof(_network_ban_list); i++) {
   349 	for (i = 0; i < lengthof(_network_ban_list); i++) {
   379 		if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0')
   350 		if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0')
   380 			continue;
   351 			continue;
   381 
   352 
       
   353 		if (strncmp(_network_ban_list[i], argv[1], strlen(_network_ban_list[i])) == 0) {
       
   354 			_network_ban_list[i][0] = '\0';
       
   355 			IConsolePrint(_iconsole_color_default, "IP unbanned.");
       
   356 			return true;
       
   357 		}
       
   358 	}
       
   359 
       
   360 	IConsolePrint(_iconsole_color_default, "IP not in ban-list.");
       
   361 	return true;
       
   362 }
       
   363 
       
   364 DEF_CONSOLE_CMD(ConBanList)
       
   365 {
       
   366 	uint i;
       
   367 
       
   368 	if (argc == 0) {
       
   369 		IConsoleHelp("List the IP's of banned clients: Usage 'banlist'");
       
   370 		return true;
       
   371 	}
       
   372 
       
   373 	IConsolePrint(_iconsole_color_default, "Banlist: ");
       
   374 
       
   375 	for (i = 0; i < lengthof(_network_ban_list); i++) {
       
   376 		if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0')
       
   377 			continue;
       
   378 
   382 		IConsolePrintF(_iconsole_color_default, "  %d) %s", i + 1, _network_ban_list[i]);
   379 		IConsolePrintF(_iconsole_color_default, "  %d) %s", i + 1, _network_ban_list[i]);
   383 	}
   380 	}
   384 
   381 
   385 	return NULL;
   382 	return true;
   386 }
   383 }
   387 
   384 
   388 DEF_CONSOLE_CMD(ConPauseGame)
   385 DEF_CONSOLE_CMD(ConPauseGame)
   389 {
   386 {
       
   387 	if (argc == 0) {
       
   388 		IConsoleHelp("Pause a network game. Usage: 'pause'");
       
   389 		return true;
       
   390 	}
       
   391 
   390 	if (_pause == 0) {
   392 	if (_pause == 0) {
   391 		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
   393 		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
   392 		IConsolePrint(_iconsole_color_default, "Game paused.");
   394 		IConsolePrint(_iconsole_color_default, "Game paused.");
   393 	} else
   395 	} else
   394 		IConsolePrint(_iconsole_color_default, "Game is already paused.");
   396 		IConsolePrint(_iconsole_color_default, "Game is already paused.");
   395 
   397 
   396 	return NULL;
   398 	return true;
   397 }
   399 }
   398 
   400 
   399 DEF_CONSOLE_CMD(ConUnPauseGame)
   401 DEF_CONSOLE_CMD(ConUnPauseGame)
   400 {
   402 {
       
   403 	if (argc == 0) {
       
   404 		IConsoleHelp("Unpause a network game. Usage: 'unpause'");
       
   405 		return true;
       
   406 	}
       
   407 
   401 	if (_pause != 0) {
   408 	if (_pause != 0) {
   402 		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
   409 		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
   403 		IConsolePrint(_iconsole_color_default, "Game unpaused.");
   410 		IConsolePrint(_iconsole_color_default, "Game unpaused.");
   404 	} else
   411 	} else
   405 		IConsolePrint(_iconsole_color_default, "Game is already unpaused.");
   412 		IConsolePrint(_iconsole_color_default, "Game is already unpaused.");
   406 
   413 
   407 	return NULL;
   414 	return true;
   408 }
   415 }
   409 
   416 
   410 DEF_CONSOLE_CMD(ConRcon)
   417 DEF_CONSOLE_CMD(ConRcon)
   411 {
   418 {
   412 	if (argc < 3) {
   419 	if (argc == 0) {
   413 		IConsolePrint(_iconsole_color_default, "Usage: rcon <password> <command>");
   420 		IConsoleHelp("Remote control the server from another client. Usage: 'rcon <password> <command>'");
   414 		return NULL;
   421 		IConsoleHelp("Remember to enclose the command in quotes, otherwise only the first parameter is sent");
   415 	}
   422 		return true;
       
   423 	}
       
   424 
       
   425 	if (argc < 3) return false;
   416 
   426 
   417 	SEND_COMMAND(PACKET_CLIENT_RCON)(argv[1], argv[2]);
   427 	SEND_COMMAND(PACKET_CLIENT_RCON)(argv[1], argv[2]);
   418 
   428 	return true;
   419 	return NULL;
       
   420 }
   429 }
   421 
   430 
   422 DEF_CONSOLE_CMD(ConStatus)
   431 DEF_CONSOLE_CMD(ConStatus)
   423 {
   432 {
       
   433 	static const char *stat_str[] = {"inactive", "authorized", "waiting", "loading map", "map done", "ready", "active"};
   424 	const char *status;
   434 	const char *status;
   425 	int lag;
       
   426 	const NetworkClientState *cs;
   435 	const NetworkClientState *cs;
   427 	const NetworkClientInfo *ci;
   436 
       
   437 	if (argc == 0) {
       
   438 		IConsoleHelp("List the status of all clients connected to the server: Usage 'status'");
       
   439 		return true;
       
   440 	}
       
   441 
   428 	FOR_ALL_CLIENTS(cs) {
   442 	FOR_ALL_CLIENTS(cs) {
   429 		lag = NetworkCalculateLag(cs);
   443 		int lag = NetworkCalculateLag(cs);
   430 		ci = DEREF_CLIENT_INFO(cs);
   444 		const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
   431 
   445 
   432 		switch (cs->status) {
   446 		status = (cs->status <= STATUS_ACTIVE) ? stat_str[cs->status] : "unknown";
   433 			case STATUS_INACTIVE:
       
   434 				status = "inactive";
       
   435 				break;
       
   436 			case STATUS_AUTH:
       
   437 				status = "authorized";
       
   438 				break;
       
   439 			case STATUS_MAP_WAIT:
       
   440 				status = "waiting";
       
   441 				break;
       
   442 			case STATUS_MAP:
       
   443 				status = "loading map";
       
   444 				break;
       
   445 			case STATUS_DONE_MAP:
       
   446 				status = "done map";
       
   447 				break;
       
   448 			case STATUS_PRE_ACTIVE:
       
   449 				status = "ready";
       
   450 				break;
       
   451 			case STATUS_ACTIVE:
       
   452 				status = "active";
       
   453 				break;
       
   454 			default:
       
   455 				status = "unknown";
       
   456 				break;
       
   457 		}
       
   458 		IConsolePrintF(8, "Client #%d/%s  status: %s  frame-lag: %d  play-as: %d  unique-id: %s",
   447 		IConsolePrintF(8, "Client #%d/%s  status: %s  frame-lag: %d  play-as: %d  unique-id: %s",
   459 			cs->index, ci->client_name, status, lag, ci->client_playas, ci->unique_id);
   448 			cs->index, ci->client_name, status, lag, ci->client_playas, ci->unique_id);
   460 	}
   449 	}
   461 
   450 
   462 	return NULL;
   451 	return true;
   463 }
   452 }
   464 
   453 
   465 DEF_CONSOLE_CMD(ConKick)
   454 DEF_CONSOLE_CMD(ConKick)
   466 {
   455 {
   467 	NetworkClientInfo *ci;
   456 	NetworkClientInfo *ci;
   468 
   457 	uint32 index;
   469 	if (argc == 2) {
   458 
   470 		uint32 index = atoi(argv[1]);
   459 	if (argc == 0) {
   471 		if (index == NETWORK_SERVER_INDEX) {
   460 		IConsoleHelp("Kick a player from a network game. Usage: 'kick <client-id>'");
   472 			IConsolePrint(_iconsole_color_default, "Silly boy, you can not kick yourself!");
   461 		IConsoleHelp("For client-id's, see the command 'clients'");
   473 			return NULL;
   462 		return true;
   474 		}
   463 	}
   475 		if (index == 0) {
   464 
   476 			IConsoleError("Invalid Client-ID");
   465 	if (argc != 2) return false;
   477 			return NULL;
   466 
   478 		}
   467 	index = atoi(argv[1]);
   479 
   468 	if (index == NETWORK_SERVER_INDEX) {
   480 		ci = NetworkFindClientInfoFromIndex(index);
   469 		IConsolePrint(_iconsole_color_default, "Silly boy, you can not kick yourself!");
   481 
   470 		return true;
   482 		if (ci != NULL) {
   471 	}
   483 			SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   472 	if (index == 0) {
   484 			return NULL;
   473 		IConsoleError("Invalid Client-ID");
   485 		} else {
   474 		return true;
   486 			IConsoleError("Client-ID not found");
   475 	}
   487 			return NULL;
   476 
   488 		}
   477 	ci = NetworkFindClientInfoFromIndex(index);
   489 	}
   478 
   490 
   479 	if (ci != NULL) {
   491 	IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: kick <client-id>. For client-ids, see 'clients'.");
   480 		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   492 
   481 	} else
   493 	return NULL;
   482 		IConsoleError("Client-ID not found");
       
   483 
       
   484 	return true;
   494 }
   485 }
   495 
   486 
   496 DEF_CONSOLE_CMD(ConResetCompany)
   487 DEF_CONSOLE_CMD(ConResetCompany)
   497 {
   488 {
   498 	Player *p;
   489 	Player *p;
   499 	NetworkClientState *cs;
   490 	NetworkClientState *cs;
   500 	NetworkClientInfo *ci;
   491 	NetworkClientInfo *ci;
   501 
   492 	byte index;
   502 	if (argc == 2) {
   493 
   503 		byte index = atoi(argv[1]);
   494 	if (argc == 0) {
   504 
   495 		IConsoleHelp("Remove an (idle) company from the game. Usage: 'reset_company <company-id>'");
   505 		/* Check valid range */
   496 		return true;
   506 		if (index < 1 || index > MAX_PLAYERS) {
   497 	}
   507 			IConsolePrintF(_iconsole_color_error, "Company does not exist. Company-ID must be between 1 and %d.", MAX_PLAYERS);
   498 
   508 			return NULL;
   499 	if (argc != 2) return false;
   509 		}
   500 
   510 
   501 	index = atoi(argv[1]);
   511 		/* Check if company does exist */
   502 
   512 		index--;
   503 	/* Check valid range */
   513 		p = DEREF_PLAYER(index);
   504 	if (index < 1 || index > MAX_PLAYERS) {
   514 		if (!p->is_active) {
   505 		IConsolePrintF(_iconsole_color_error, "Company does not exist. Company-ID must be between 1 and %d.", MAX_PLAYERS);
   515 			IConsolePrintF(_iconsole_color_error, "Company does not exist.");
   506 		return true;
   516 			return NULL;
   507 	}
   517 		}
   508 
   518 
   509 	/* Check if company does exist */
   519 		if (p->is_ai) {
   510 	index--;
   520 			IConsolePrintF(_iconsole_color_error, "Company is owned by an AI.");
   511 	p = DEREF_PLAYER(index);
   521 			return NULL;
   512 	if (!p->is_active) {
   522 		}
   513 		IConsolePrintF(_iconsole_color_error, "Company does not exist.");
   523 
   514 		return true;
   524 		/* Check if the company has active players */
   515 	}
   525 		FOR_ALL_CLIENTS(cs) {
   516 
   526 			ci = DEREF_CLIENT_INFO(cs);
   517 	if (p->is_ai) {
   527 			if (ci->client_playas-1 == index) {
   518 		IConsolePrintF(_iconsole_color_error, "Company is owned by an AI.");
   528 				IConsolePrintF(_iconsole_color_error, "Cannot remove company: a client is connected to that company.");
   519 		return true;
   529 				return NULL;
   520 	}
   530 			}
   521 
   531 		}
   522 	/* Check if the company has active players */
   532 		ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
   523 	FOR_ALL_CLIENTS(cs) {
       
   524 		ci = DEREF_CLIENT_INFO(cs);
   533 		if (ci->client_playas-1 == index) {
   525 		if (ci->client_playas-1 == index) {
   534 			IConsolePrintF(_iconsole_color_error, "Cannot remove company: a client is connected to that company.");
   526 			IConsolePrintF(_iconsole_color_error, "Cannot remove company: a client is connected to that company.");
   535 			return NULL;
   527 			return true;
   536 		}
   528 		}
   537 
   529 	}
   538 		/* It is safe to remove this company */
   530 	ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
   539 		DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
   531 	if (ci->client_playas - 1 == index) {
   540 		IConsolePrint(_iconsole_color_default, "Company deleted.");
   532 		IConsolePrintF(_iconsole_color_error, "Cannot remove company; a client is connected to that company.");
   541 		return NULL;
   533 		return true;
   542 	}
   534 	}
   543 
   535 
   544 	IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: reset_company <company-id>.");
   536 	/* It is safe to remove this company */
   545 
   537 	DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
   546 	return NULL;
   538 	IConsolePrint(_iconsole_color_default, "Company deleted.");
       
   539 
       
   540 	return true;
   547 }
   541 }
   548 
   542 
   549 DEF_CONSOLE_CMD(ConNetworkClients)
   543 DEF_CONSOLE_CMD(ConNetworkClients)
   550 {
   544 {
   551 	NetworkClientInfo *ci;
   545 	NetworkClientInfo *ci;
       
   546 
       
   547 	if (argc == 0) {
       
   548 		IConsoleHelp("Get a list of connected clients including their ID, name, and company-id. Usage: 'clients'");
       
   549 		return true;
       
   550 	}
       
   551 
   552 	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
   552 	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
   553 		if (ci->client_index != NETWORK_EMPTY_INDEX) {
   553 		if (ci->client_index != NETWORK_EMPTY_INDEX) {
   554 			IConsolePrintF(8,"Client #%d   name: %s  play-as: %d", ci->client_index, ci->client_name, ci->client_playas);
   554 			IConsolePrintF(8,"Client #%d   name: %s  play-as: %d", ci->client_index, ci->client_name, ci->client_playas);
   555 		}
   555 		}
   556 	}
   556 	}
   557 
   557 
   558 	return NULL;
   558 	return true;
   559 }
   559 }
   560 
   560 
   561 DEF_CONSOLE_CMD(ConNetworkConnect)
   561 DEF_CONSOLE_CMD(ConNetworkConnect)
   562 {
   562 {
   563 	char* ip;
   563 	char *ip;
   564 	const char *port = NULL;
   564 	const char *port = NULL;
   565 	const char *player = NULL;
   565 	const char *player = NULL;
   566 	uint16 rport;
   566 	uint16 rport;
   567 
   567 
   568 	if (argc<2) return NULL;
   568 	if (argc == 0) {
   569 
   569 		IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
   570 	if (_networking) {
   570 		IConsoleHelp("IP can contain port and player: 'IP#Player:Port', eg: 'server.ottd.org#2:443'");
   571 		// We are in network-mode, first close it!
   571 		return true;
       
   572 	}
       
   573 
       
   574 	if (argc < 2) return false;
       
   575 
       
   576 	if (_networking) // We are in network-mode, first close it!
   572 		NetworkDisconnect();
   577 		NetworkDisconnect();
   573 	}
       
   574 
   578 
   575 	ip = argv[1];
   579 	ip = argv[1];
   576 	rport = NETWORK_DEFAULT_PORT;
   580 	rport = NETWORK_DEFAULT_PORT;
   577 
   581 
   578 	ParseConnectionString(&player, &port, ip);
   582 	ParseConnectionString(&player, &port, ip);
   587 		IConsolePrintF(_iconsole_color_default, "    port: %s", port);
   591 		IConsolePrintF(_iconsole_color_default, "    port: %s", port);
   588 	}
   592 	}
   589 
   593 
   590 	NetworkClientConnectGame(ip, rport);
   594 	NetworkClientConnectGame(ip, rport);
   591 
   595 
   592 	return NULL;
   596 	return true;
   593 }
   597 }
   594 
   598 
   595 #endif /* ENABLE_NETWORK */
   599 #endif /* ENABLE_NETWORK */
   596 
   600 
   597 /* ******************************** */
   601 /* ******************************** */
   598 /*   script file console commands   */
   602 /*   script file console commands   */
   599 /* ******************************** */
   603 /* ******************************** */
   600 
   604 
   601 DEF_CONSOLE_CMD(ConExec)
   605 DEF_CONSOLE_CMD(ConExec)
   602 {
   606 {
   603 	char cmd[1024];
   607 	char cmdline[ICON_CMDLN_SIZE];
   604 
   608 
   605 	if (argc < 2) return NULL;
   609 	if (argc == 0) {
       
   610 		IConsoleHelp("Execute a local script file. Usage: 'exec <script> <?>'");
       
   611 		return true;
       
   612 	}
       
   613 
       
   614 	if (argc < 2) return false;
   606 
   615 
   607 	_script_file = fopen(argv[1], "r");
   616 	_script_file = fopen(argv[1], "r");
   608 
   617 
   609 	if (_script_file == NULL) {
   618 	if (_script_file == NULL) {
   610 		if (argc <= 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
   619 		if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
   611 		return NULL;
   620 		return true;
   612 	}
   621 	}
   613 
   622 
   614 	_script_running = true;
   623 	_script_running = true;
   615 
   624 
   616 	while (_script_running && fgets(cmd, sizeof(cmd), _script_file) != NULL) {
   625 	while (_script_running && fgets(cmdline, sizeof(cmdline), _script_file) != NULL)
   617 		IConsoleCmdExec(cmd);
   626 		IConsoleCmdExec(cmdline);
   618 	}
   627 
   619 
   628 	if (ferror(_script_file))
   620 	if (ferror(_script_file)) {
       
   621 		IConsoleError("Encountered errror while trying to read from script file");
   629 		IConsoleError("Encountered errror while trying to read from script file");
   622 	}
       
   623 
   630 
   624 	_script_running = false;
   631 	_script_running = false;
   625 	fclose(_script_file);
   632 	fclose(_script_file);
   626 	return NULL;
   633 	return true;
   627 }
   634 }
   628 
   635 
   629 DEF_CONSOLE_CMD(ConReturn)
   636 DEF_CONSOLE_CMD(ConReturn)
   630 {
   637 {
       
   638 	if (argc == 0) {
       
   639 		IConsoleHelp("Stop executing a running script. Usage: 'return'");
       
   640 		return true;
       
   641 	}
       
   642 
   631 	_script_running = false;
   643 	_script_running = false;
   632 	return NULL;
   644 	return true;
   633 }
   645 }
   634 
   646 
   635 /* **************************** */
   647 /* **************************** */
   636 /*   default console commands   */
   648 /*   default console commands   */
   637 /* **************************** */
   649 /* **************************** */
   638 extern bool CloseConsoleLogIfActive(void);
   650 extern bool CloseConsoleLogIfActive(void);
   639 
   651 
   640 DEF_CONSOLE_CMD(ConScript)
   652 DEF_CONSOLE_CMD(ConScript)
   641 {
   653 {
   642 	extern FILE* _iconsole_output_file;
   654 	extern FILE* _iconsole_output_file;
       
   655 
       
   656 	if (argc == 0) {
       
   657 		IConsoleHelp("Start or stop logging console output to a file. Usage: 'script <filename>'");
       
   658 		IConsoleHelp("If filename is omitted, a running log is stopped if it is active");
       
   659 		return true;
       
   660 	}
       
   661 
   643 	if (!CloseConsoleLogIfActive()) {
   662 	if (!CloseConsoleLogIfActive()) {
   644 		if (argc < 2) return NULL;
   663 		if (argc < 2) return false;
       
   664 
   645 		IConsolePrintF(_iconsole_color_default, "file output started to: %s",	argv[1]);
   665 		IConsolePrintF(_iconsole_color_default, "file output started to: %s",	argv[1]);
   646 		_iconsole_output_file = fopen(argv[1], "ab");
   666 		_iconsole_output_file = fopen(argv[1], "ab");
   647 		if (_iconsole_output_file == NULL) IConsoleError("could not open file");
   667 		if (_iconsole_output_file == NULL) IConsoleError("could not open file");
   648 	}
   668 	}
   649 
   669 
   650 	return NULL;
   670 	return true;
   651 }
   671 }
   652 
   672 
   653 
   673 
   654 DEF_CONSOLE_CMD(ConEcho)
   674 DEF_CONSOLE_CMD(ConEcho)
   655 {
   675 {
   656 	if (argc < 2) return NULL;
   676 	if (argc == 0) {
       
   677 		IConsoleHelp("Print back the first argument to the console. Usage: 'echo <arg>'");
       
   678 		return true;
       
   679 	}
       
   680 
       
   681 	if (argc < 2) return false;
   657 	IConsolePrint(_iconsole_color_default, argv[1]);
   682 	IConsolePrint(_iconsole_color_default, argv[1]);
   658 	return NULL;
   683 	return true;
   659 }
   684 }
   660 
   685 
   661 DEF_CONSOLE_CMD(ConEchoC)
   686 DEF_CONSOLE_CMD(ConEchoC)
   662 {
   687 {
   663 	if (argc < 3) return NULL;
   688 	if (argc == 0) {
       
   689 		IConsoleHelp("Print back the first argument to the console in a given colour. Usage: 'echoc <colour> <arg2>'");
       
   690 		return true;
       
   691 	}
       
   692 
       
   693 	if (argc < 3) return false;
   664 	IConsolePrint(atoi(argv[1]), argv[2]);
   694 	IConsolePrint(atoi(argv[1]), argv[2]);
   665 	return NULL;
   695 	return true;
   666 }
   696 }
   667 
   697 
   668 extern void SwitchMode(int new_mode);
   698 extern void SwitchMode(int new_mode);
   669 
   699 
   670 DEF_CONSOLE_CMD(ConNewGame)
   700 DEF_CONSOLE_CMD(ConNewGame)
   671 {
   701 {
       
   702 	if (argc == 0) {
       
   703 		IConsoleHelp("Start a new game. Usage: 'newgame'");
       
   704 		return true;
       
   705 	}
       
   706 
   672 	_docommand_recursive = 0;
   707 	_docommand_recursive = 0;
   673 
   708 
   674 	_random_seeds[0][0] = Random();
   709 	_random_seeds[0][0] = Random();
   675 	_random_seeds[0][1] = InteractiveRandom();
   710 	_random_seeds[0][1] = InteractiveRandom();
   676 
   711 
   677 	SwitchMode(SM_NEWGAME);
   712 	SwitchMode(SM_NEWGAME);
   678 	return NULL;
   713 	return true;
   679 }
       
   680 
       
   681 DEF_CONSOLE_CMD(ConPrintF)
       
   682 {
       
   683 	if (argc < 3) return NULL;
       
   684 	IConsolePrintF(_iconsole_color_default, argv[1] , argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15], argv[16], argv[17], argv[18], argv[19]); /* XXX ugh... */
       
   685 	return NULL;
       
   686 }
       
   687 
       
   688 DEF_CONSOLE_CMD(ConPrintFC)
       
   689 {
       
   690 	if (argc < 3) return NULL;
       
   691 	IConsolePrintF(atoi(argv[1]), argv[2] , argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14], argv[15], argv[16], argv[17], argv[18], argv[19]); /* XXX ugh... */
       
   692 	return NULL;
       
   693 }
   714 }
   694 
   715 
   695 DEF_CONSOLE_CMD(ConAlias)
   716 DEF_CONSOLE_CMD(ConAlias)
   696 {
   717 {
   697 	_iconsole_alias* alias;
   718 	IConsoleAlias *alias;
   698 
   719 
   699 	if (argc < 3) return NULL;
   720 	if (argc == 0) {
       
   721 		IConsoleHelp("Add a new alias, or redefine the behaviour of an existing alias . Usage: 'alias <name> <command>'");
       
   722 		return true;
       
   723 	}
       
   724 
       
   725 	if (argc < 3) return false;
   700 
   726 
   701 	alias = IConsoleAliasGet(argv[1]);
   727 	alias = IConsoleAliasGet(argv[1]);
   702 	if (alias == NULL) {
   728 	if (alias == NULL) {
   703 		IConsoleAliasRegister(argv[1],argv[2]);
   729 		IConsoleAliasRegister(argv[1], argv[2]);
   704 	} else {
   730 	} else {
   705 		free(alias->cmdline);
   731 		free(alias->cmdline);
   706 		alias->cmdline = strdup(argv[2]);
   732 		alias->cmdline = strdup(argv[2]);
   707 	}
   733 	}
   708 	return NULL;
   734 	return true;
   709 }
   735 }
   710 
   736 
   711 DEF_CONSOLE_CMD(ConScreenShot)
   737 DEF_CONSOLE_CMD(ConScreenShot)
   712 {
   738 {
       
   739 	if (argc == 0) {
       
   740 		IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big|no_con]'");
       
   741 		IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create the screenshot");
       
   742 		return true;
       
   743 	}
       
   744 
   713 	if (argc < 2) {
   745 	if (argc < 2) {
   714 		_make_screenshot = 1;
   746 		_make_screenshot = 1;
   715 	} else {
   747 	} else {
   716 		if (strcmp(argv[1], "big") == 0)
   748 		if (strcmp(argv[1], "big") == 0)
   717 			_make_screenshot=2;
   749 			_make_screenshot = 2;
       
   750 
   718 		if (strcmp(argv[1], "no_con") == 0) {
   751 		if (strcmp(argv[1], "no_con") == 0) {
   719 			IConsoleClose();
   752 			IConsoleClose();
   720 			_make_screenshot = 1;
   753 			_make_screenshot = 1;
   721 		}
   754 		}
   722 	}
   755 	}
   723 	return NULL;
   756 	return true;
   724 }
   757 }
   725 
   758 
   726 DEF_CONSOLE_CMD(ConInfoVar)
   759 DEF_CONSOLE_CMD(ConInfoVar)
   727 {
   760 {
   728 	if (argc < 2) return NULL;
   761 	static const char *_icon_vartypes[] = {"boolean", "byte", "uint16", "uint32", "int16", "int32", "string"};
   729 	if (argt[1] != ICONSOLE_VAR_REFERENCE) {
   762 	const IConsoleVar *var;
   730 		IConsoleError("first argument has to be a variable reference");
   763 
   731 	} else {
   764 	if (argc == 0) {
   732 		_iconsole_var* item;
   765 		IConsoleHelp("Print out debugging information about a variable. Usage: 'info_var <var>'");
   733 		item = (_iconsole_var*)argv[1];
   766 		return true;
   734 		IConsolePrintF(_iconsole_color_default, "var_name: %s", item->name);
   767 	}
   735 		IConsolePrintF(_iconsole_color_default, "var_type: %i", item->type);
   768 
   736 		IConsolePrintF(_iconsole_color_default, "var_addr: %i", item->data.addr);
   769 	if (argc < 2) return false;
   737 		if (item->_malloc)
   770 
   738 			IConsolePrintF(_iconsole_color_default, "var_malloc: internal");
   771 	var = IConsoleVarGet(argv[1]);
   739 		else
   772 	if (var == NULL) {
   740 			IConsolePrintF(_iconsole_color_default, "var_malloc: external");
   773 		IConsoleError("the given variable was not found");
   741 		if (item->hook_access) IConsoleWarning("var_access hooked");
   774 		return true;
   742 		if (item->hook_before_change) IConsoleWarning("var_before_change hooked");
   775 	}
   743 		if (item->hook_after_change) IConsoleWarning("var_after_change hooked");
   776 
   744 	}
   777 	IConsolePrintF(_iconsole_color_default, "variable name: %s", var->name);
   745 	return NULL;
   778 	IConsolePrintF(_iconsole_color_default, "variable type: %s", _icon_vartypes[var->type]);
       
   779 	IConsolePrintF(_iconsole_color_default, "variable addr: 0x%X", var->addr);
       
   780 
       
   781 	if (var->hook.access) IConsoleWarning("variable is access hooked");
       
   782 	if (var->hook.pre) IConsoleWarning("variable is pre hooked");
       
   783 	if (var->hook.post) IConsoleWarning("variable is post hooked");
       
   784 	return true;
   746 }
   785 }
   747 
   786 
   748 
   787 
   749 DEF_CONSOLE_CMD(ConInfoCmd)
   788 DEF_CONSOLE_CMD(ConInfoCmd)
   750 {
   789 {
   751 	if (argc < 2) return NULL;
   790 	const IConsoleCmd *cmd;
   752 	if (argt[1] != ICONSOLE_VAR_UNKNOWN) {
   791 
   753 		IConsoleError("first argument has to be a command name");
   792 	if (argc == 0) {
   754 	} else {
   793 		IConsoleHelp("Print out debugging information about a command. Usage: 'info_cmd <cmd>'");
   755 		_iconsole_cmd* item;
   794 		return true;
   756 		item = IConsoleCmdGet(argv[1]);
   795 	}
   757 		if (item == NULL) {
   796 
   758 			IConsoleError("the given command was not found");
   797 	if (argc < 2) return false;
   759 			return NULL;
   798 
       
   799 	cmd = IConsoleCmdGet(argv[1]);
       
   800 	if (cmd == NULL) {
       
   801 		IConsoleError("the given command was not found");
       
   802 		return true;
       
   803 	}
       
   804 
       
   805 	IConsolePrintF(_iconsole_color_default, "command name: %s", cmd->name);
       
   806 	IConsolePrintF(_iconsole_color_default, "command proc: 0x%X", cmd->proc);
       
   807 
       
   808 	if (cmd->hook.access) IConsoleWarning("command is access hooked");
       
   809 	if (cmd->hook.pre) IConsoleWarning("command is pre hooked");
       
   810 	if (cmd->hook.post) IConsoleWarning("command is post hooked");
       
   811 
       
   812 	return true;
       
   813 }
       
   814 
       
   815 DEF_CONSOLE_CMD(ConDebugLevel)
       
   816 {
       
   817 	if (argc == 0) {
       
   818 		IConsoleHelp("Set the default debugging level for the game. Usage: 'debug_level <level>'");
       
   819 		IConsoleHelp("Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
       
   820 		return true;
       
   821 	}
       
   822 
       
   823 	if (argc < 2) return false;
       
   824 	SetDebugString(argv[1]);
       
   825 	return true;
       
   826 }
       
   827 
       
   828 DEF_CONSOLE_CMD(ConExit)
       
   829 {
       
   830 	if (argc == 0) {
       
   831 		IConsoleHelp("Exit the game. Usage: 'exit'");
       
   832 		return true;
       
   833 	}
       
   834 
       
   835 	_exit_game = true;
       
   836 	return true;
       
   837 }
       
   838 
       
   839 DEF_CONSOLE_CMD(ConHelp)
       
   840 {
       
   841 	if (argc == 2) {
       
   842 		IConsoleCmd *cmd;
       
   843 		IConsoleVar *var;
       
   844 
       
   845 		cmd = IConsoleCmdGet(argv[1]);
       
   846 	 	if (cmd != NULL) {
       
   847 	 		cmd->proc(0, NULL);
       
   848 	 		return true;
       
   849 	 	}
       
   850 
       
   851 	 	var = IConsoleVarGet(argv[1]);
       
   852    	if (var != NULL && var->help != NULL) {
       
   853    		IConsolePrintF(_iconsole_color_warning, "%s.", var->help);
       
   854    		return true;
       
   855    	}
       
   856 
       
   857    	IConsoleError("command or variable not found");
       
   858    	return true;
       
   859   }
       
   860 
       
   861 	IConsolePrint(13, " -- OpenTTD Console Help -- ");
       
   862 	IConsolePrint( 1, " variables: [command to list all variables: list_vars]");
       
   863 	IConsolePrint( 1, " set value with '<var> = <value>', use '++/--' to in-or decrement");
       
   864 	IConsolePrint( 1, " or omit '=' and just '<var> <value>'. get value with typing '<var>'");
       
   865 	IConsolePrint( 1, "");
       
   866 	IConsolePrint( 1, " commands: [command to list all commands: list_cmds]");
       
   867 	IConsolePrint( 1, " call commands with '<command> <arg2> <arg3>...'");
       
   868 	IConsolePrint( 1, "");
       
   869 	IConsolePrint( 1, " to assign strings, or use them as arguments, enclose it within quotes");
       
   870 	IConsolePrint( 1, " like this: '<command> \"string argument with spaces\"'");
       
   871 	IConsolePrint( 1, " use 'help <command>|<variable>' to get specific information");
       
   872 	IConsolePrint( 1, "");
       
   873 	return true;
       
   874 }
       
   875 
       
   876 DEF_CONSOLE_CMD(ConListCommands)
       
   877 {
       
   878 	const IConsoleCmd *cmd;
       
   879 	size_t l = 0;
       
   880 
       
   881 	if (argc == 0) {
       
   882 		IConsoleHelp("List all registered commands. Usage: 'list_cmds [<pre-filter>]'");
       
   883 		return true;
       
   884 	}
       
   885 
       
   886 	if (argv[1] != NULL) l = strlen(argv[1]);
       
   887 
       
   888 	for (cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
       
   889 		if (argv[1] == NULL || strncmp(cmd->name, argv[1], l) == 0) {
       
   890 				IConsolePrintF(_iconsole_color_default, "%s", cmd->name);
   760 		}
   891 		}
   761 		IConsolePrintF(_iconsole_color_default, "cmd_name: %s", item->name);
   892 	}
   762 		IConsolePrintF(_iconsole_color_default, "cmd_addr: %i", item->addr);
   893 
   763 		if (item->hook_access) IConsoleWarning("cmd_access hooked");
   894 	return true;
   764 		if (item->hook_before_exec) IConsoleWarning("cmd_before_exec hooked");
   895 }
   765 		if (item->hook_after_exec) IConsoleWarning("cmd_after_exec hooked");
   896 
   766 	}
   897 DEF_CONSOLE_CMD(ConListVariables)
   767 	return NULL;
   898 {
   768 }
   899 	const IConsoleVar *var;
   769 
       
   770 DEF_CONSOLE_CMD(ConDebugLevel)
       
   771 {
       
   772 	if (argc < 2) return NULL;
       
   773 	SetDebugString(argv[1]);
       
   774 	return NULL;
       
   775 }
       
   776 
       
   777 DEF_CONSOLE_CMD(ConExit)
       
   778 {
       
   779 	_exit_game = true;
       
   780 	return NULL;
       
   781 }
       
   782 
       
   783 DEF_CONSOLE_CMD(ConHelp)
       
   784 {
       
   785 	IConsolePrint(13, " -- console help -- ");
       
   786 	IConsolePrint( 1, " variables: [command to list them: list_vars]");
       
   787 	IConsolePrint( 1, " temp_string = \"my little \"");
       
   788 	IConsolePrint( 1, "");
       
   789 	IConsolePrint( 1, " commands: [command to list them: list_cmds]");
       
   790 	IConsolePrint( 1, " [command] [\"string argument with spaces\"] [argument 2] ...");
       
   791 	IConsolePrint( 1, " printf \"%s world\" temp_string");
       
   792 	IConsolePrint( 1, "");
       
   793 	IConsolePrint( 1, " command/variable returning a value into an variable:");
       
   794 	IConsolePrint( 1, " temp_uint16 << random");
       
   795 	IConsolePrint( 1, " temp_uint16 << temp_uint16_2");
       
   796 	IConsolePrint( 1, "");
       
   797 	return NULL;
       
   798 }
       
   799 
       
   800 DEF_CONSOLE_CMD(ConRandom)
       
   801 {
       
   802 	_iconsole_var* result;
       
   803 	result = IConsoleVarAlloc(ICONSOLE_VAR_UINT16);
       
   804 	IConsoleVarSetValue(result, rand());
       
   805 	return result;
       
   806 }
       
   807 
       
   808 DEF_CONSOLE_CMD(ConListCommands)
       
   809 {
       
   810 	const _iconsole_cmd* item;
       
   811 	size_t l = 0;
   900 	size_t l = 0;
   812 
   901 
       
   902 	if (argc == 0) {
       
   903 		IConsoleHelp("List all registered variables. Usage: 'list_vars [<pre-filter>]'");
       
   904 		return true;
       
   905 	}
       
   906 
   813 	if (argv[1] != NULL) l = strlen(argv[1]);
   907 	if (argv[1] != NULL) l = strlen(argv[1]);
   814 
   908 
   815 	for (item = _iconsole_cmds; item != NULL; item = item->_next)
   909 	for (var = _iconsole_vars; var != NULL; var = var->next) {
   816 		if (argv[1] == NULL || strncmp(item->name, argv[1], l) == 0)
   910 		if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
   817 			IConsolePrintF(_iconsole_color_default, "%s", item->name);
   911 			IConsolePrintF(_iconsole_color_default, "%s", var->name);
   818 
   912 	}
   819 	return NULL;
   913 
   820 }
   914 	return true;
   821 
   915 }
   822 DEF_CONSOLE_CMD(ConListVariables)
   916 
   823 {
   917 DEF_CONSOLE_CMD(ConListAliases)
   824 	const _iconsole_var* item;
   918 {
       
   919 	const IConsoleAlias *alias;
   825 	size_t l = 0;
   920 	size_t l = 0;
   826 
   921 
       
   922 	if (argc == 0) {
       
   923 		IConsoleHelp("List all registered aliases. Usage: 'list_aliases [<pre-filter>]'");
       
   924 		return true;
       
   925 	}
       
   926 
   827 	if (argv[1] != NULL) l = strlen(argv[1]);
   927 	if (argv[1] != NULL) l = strlen(argv[1]);
   828 
   928 
   829 	for (item = _iconsole_vars; item != NULL; item = item->_next)
   929 	for (alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
   830 		if (argv[1] == NULL || strncmp(item->name, argv[1], l) == 0)
   930 		if (argv[1] == NULL || strncmp(alias->name, argv[1], l) == 0)
   831 			IConsolePrintF(_iconsole_color_default, "%s", item->name);
   931 			IConsolePrintF(_iconsole_color_default, "%s => %s", alias->name, alias->cmdline);
   832 
   932 	}
   833 	return NULL;
   933 
   834 }
   934 	return true;
   835 
   935 }
   836 DEF_CONSOLE_CMD(ConListAliases)
   936 
   837 {
   937 #ifdef ENABLE_NETWORK
   838 	const _iconsole_alias* item;
   938 
       
   939 DEF_CONSOLE_CMD(ConSay)
       
   940 {
       
   941 	if (argc == 0) {
       
   942 		IConsoleHelp("Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
       
   943 		return true;
       
   944 	}
       
   945 
       
   946 	if (argc != 2) return false;
       
   947 
       
   948 	if (!_network_server) {
       
   949 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
       
   950 	} else
       
   951 		NetworkServer_HandleChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], NETWORK_SERVER_INDEX);
       
   952 
       
   953 	return true;
       
   954 }
       
   955 
       
   956 DEF_CONSOLE_CMD(ConSayPlayer)
       
   957 {
       
   958 	if (argc == 0) {
       
   959 		IConsoleHelp("Chat to a certain player in a multiplayer game. Usage: 'say_player <player-no> \"<msg>\"'");
       
   960 		IConsoleHelp("PlayerNo is the player that plays as company <playerno>, 1 through max_players");
       
   961 		return true;
       
   962 	}
       
   963 
       
   964 	if (argc != 3) return false;
       
   965 
       
   966 	if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) {
       
   967 		IConsolePrintF(_iconsole_color_default, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
       
   968 		return true;
       
   969 	}
       
   970 
       
   971 	if (!_network_server) {
       
   972 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_PLAYER, DESTTYPE_PLAYER, atoi(argv[1]), argv[2]);
       
   973 	} else
       
   974 		NetworkServer_HandleChat(NETWORK_ACTION_CHAT_PLAYER, DESTTYPE_PLAYER, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
       
   975 
       
   976 	return true;
       
   977 }
       
   978 
       
   979 DEF_CONSOLE_CMD(ConSayClient)
       
   980 {
       
   981 	if (argc == 0) {
       
   982 		IConsoleHelp("Chat to a certain player in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
       
   983   	IConsoleHelp("For client-id's, see the command 'clients'");
       
   984 		return true;
       
   985 	}
       
   986 
       
   987 	if (argc != 3) return false;
       
   988 
       
   989 	if (!_network_server) {
       
   990 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
       
   991 	} else
       
   992 		NetworkServer_HandleChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
       
   993 
       
   994 	return true;
       
   995 }
       
   996 
       
   997 DEF_CONSOLE_HOOK(ConHookServerPW)
       
   998 {
       
   999 	if (strncmp(_network_server_password, "*", NETWORK_PASSWORD_LENGTH) == 0) {
       
  1000 		_network_server_password[0] = '\0';
       
  1001 		_network_game_info.use_password = 0;
       
  1002 	} else
       
  1003 		_network_game_info.use_password = 1;
       
  1004 
       
  1005 	return true;
       
  1006 }
       
  1007 
       
  1008 DEF_CONSOLE_HOOK(ConHookRconPW)
       
  1009 {
       
  1010 	if (strncmp(_network_rcon_password, "*", NETWORK_PASSWORD_LENGTH) == 0)
       
  1011 		_network_rcon_password[0] = '\0';
       
  1012 
       
  1013 	ttd_strlcpy(_network_game_info.rcon_password, _network_rcon_password, sizeof(_network_game_info.rcon_password));
       
  1014 
       
  1015 	return true;
       
  1016 }
       
  1017 
       
  1018 /* Also use from within player_gui to change the password graphically */
       
  1019 bool NetworkChangeCompanyPassword(byte argc, char *argv[])
       
  1020 {
       
  1021 	if (argc == 0) {
       
  1022 		IConsolePrintF(_iconsole_color_warning, "Current value of 'company_pw': %s", _network_player_info[_local_player].password);
       
  1023 		return true;
       
  1024 	}
       
  1025 
       
  1026 	if (_local_player >= MAX_PLAYERS) {
       
  1027 		IConsoleError("You have to own a company to make use of this command.");
       
  1028 		return false;
       
  1029 	}
       
  1030 
       
  1031 	if (argc != 1) return false;
       
  1032 
       
  1033 	if (strncmp(argv[0], "*", sizeof(_network_player_info[_local_player].password)) == 0)
       
  1034 		argv[0][0] = '\0';
       
  1035 
       
  1036 	ttd_strlcpy(_network_player_info[_local_player].password, argv[0], sizeof(_network_player_info[_local_player].password));
       
  1037 
       
  1038 	if (!_network_server)
       
  1039 		SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
       
  1040 
       
  1041 	return true;
       
  1042 }
       
  1043 
       
  1044 DEF_CONSOLE_HOOK(ConProcPlayerName)
       
  1045 {
       
  1046 	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
       
  1047 
       
  1048 	if (ci == NULL) return false;
       
  1049 
       
  1050 	// Don't change the name if it is the same as the old name
       
  1051 	if (strcmp(ci->client_name, _network_player_name) != 0) {
       
  1052 		if (!_network_server) {
       
  1053 			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name);
       
  1054 		} else {
       
  1055 			if (NetworkFindName(_network_player_name)) {
       
  1056 				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, _network_player_name);
       
  1057 				ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
       
  1058 				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
       
  1059 			}
       
  1060 		}
       
  1061 	}
       
  1062 
       
  1063 	return true;
       
  1064 }
       
  1065 
       
  1066 DEF_CONSOLE_HOOK(ConHookServerName)
       
  1067 {
       
  1068 	ttd_strlcpy(_network_game_info.server_name, _network_server_name, sizeof(_network_game_info.server_name));
       
  1069 	return true;
       
  1070 }
       
  1071 
       
  1072 DEF_CONSOLE_HOOK(ConHookServerAdvertise)
       
  1073 {
       
  1074 	if (!_network_advertise)
       
  1075 		NetworkUDPRemoveAdvertise();
       
  1076 
       
  1077 	return true;
       
  1078 }
       
  1079 
       
  1080 DEF_CONSOLE_CMD(ConProcServerIP)
       
  1081 {
       
  1082 	if (argc == 0) {
       
  1083 		IConsolePrintF(_iconsole_color_warning, "Current value of 'server_ip': %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
       
  1084 		return true;
       
  1085 	}
       
  1086 
       
  1087 	if (argc != 1) return false;
       
  1088 
       
  1089 	_network_server_bind_ip = inet_addr(argv[0]);
       
  1090 	snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
       
  1091 	return true;
       
  1092 }
       
  1093 
       
  1094 DEF_CONSOLE_CMD(ConPatch)
       
  1095 {
       
  1096 	if (argc == 0) {
       
  1097 		IConsoleHelp("Change patch variables for all players. Usage: 'patch <name> [<value>]'");
       
  1098 		IConsoleHelp("Omitting <value> will print out the current value of the patch-setting.");
       
  1099 		return true;
       
  1100 	}
       
  1101 
       
  1102 	if (argc == 1 || argc > 3) return false;
       
  1103 
       
  1104 	if (argc == 2) {
       
  1105 		IConsoleGetPatchSetting(argv[1]);
       
  1106 	} else
       
  1107 		IConsoleSetPatchSetting(argv[1], argv[2]);
       
  1108 
       
  1109 	return true;
       
  1110 }
       
  1111 #endif /* ENABLE_NETWORK */
       
  1112 
       
  1113 DEF_CONSOLE_CMD(ConListDumpVariables)
       
  1114 {
       
  1115 	const IConsoleVar *var;
   839 	size_t l = 0;
  1116 	size_t l = 0;
   840 
  1117 
       
  1118 	if (argc == 0) {
       
  1119 		IConsoleHelp("List all variables with their value. Usage: 'dump_vars [<pre-filter>]'");
       
  1120 		return true;
       
  1121 	}
       
  1122 
   841 	if (argv[1] != NULL) l = strlen(argv[1]);
  1123 	if (argv[1] != NULL) l = strlen(argv[1]);
   842 
  1124 
   843 	for (item = _iconsole_aliases; item != NULL; item = item->_next)
  1125 	for (var = _iconsole_vars; var != NULL; var = var->next) {
   844 		if (argv[1] == NULL || strncmp(item->name, argv[1], l) == 0)
  1126 		if (argv[1] == NULL || strncmp(var->name, argv[1], l) == 0)
   845 			IConsolePrintF(_iconsole_color_default, "%s => %s", item->name, item->cmdline);
  1127 			IConsoleVarPrintGetValue(var);
   846 
  1128 	}
   847 	return NULL;
  1129 
   848 }
  1130 	return true;
   849 
       
   850 DEF_CONSOLE_CMD(ConListDumpVariables)
       
   851 {
       
   852 	const _iconsole_var* item;
       
   853 	size_t l = 0;
       
   854 
       
   855 	if (argv[1] != NULL) l = strlen(argv[1]);
       
   856 
       
   857 	for (item = _iconsole_vars; item != NULL; item = item->_next)
       
   858 		if (argv[1] == NULL || strncmp(item->name, argv[1], l) == 0)
       
   859 			IConsoleVarDump(item, NULL);
       
   860 
       
   861 	return NULL;
       
   862 }
       
   863 
       
   864 #ifdef ENABLE_NETWORK
       
   865 
       
   866 DEF_CONSOLE_CMD(ConSay)
       
   867 {
       
   868 	if (argc == 2) {
       
   869 		if (!_network_server)
       
   870 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
       
   871 		else
       
   872 			NetworkServer_HandleChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], NETWORK_SERVER_INDEX);
       
   873 	} else
       
   874 		IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: say \"<msg>\"");
       
   875 	return NULL;
       
   876 }
       
   877 
       
   878 DEF_CONSOLE_CMD(ConSayPlayer)
       
   879 {
       
   880 	if (argc == 3) {
       
   881 		if (atoi(argv[1]) < 1 || atoi(argv[1]) > MAX_PLAYERS) {
       
   882 			IConsolePrintF(_iconsole_color_default, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
       
   883 			return NULL;
       
   884 		}
       
   885 
       
   886 		if (!_network_server)
       
   887 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_PLAYER, DESTTYPE_PLAYER, atoi(argv[1]), argv[2]);
       
   888 		else
       
   889 			NetworkServer_HandleChat(NETWORK_ACTION_CHAT_PLAYER, DESTTYPE_PLAYER, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
       
   890 	} else
       
   891 		IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: say_player <playerno> \"<msg>\"");
       
   892 	return NULL;
       
   893 }
       
   894 
       
   895 DEF_CONSOLE_CMD(ConSayClient)
       
   896 {
       
   897 	if (argc == 3) {
       
   898 		if (!_network_server)
       
   899 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
       
   900 		else
       
   901 			NetworkServer_HandleChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
       
   902 	} else
       
   903 		IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: say_client <clientno> \"<msg>\"");
       
   904 	return NULL;
       
   905 }
       
   906 
       
   907 #endif /* ENABLE_NETWORK */
       
   908 
       
   909 /* **************************** */
       
   910 /*   the "set" command          */
       
   911 /* **************************** */
       
   912 
       
   913 extern void ConsoleSetPatchSetting(char *name, char *value);
       
   914 extern void ConsoleGetPatchSetting(char *name);
       
   915 
       
   916 DEF_CONSOLE_CMD(ConSet) {
       
   917 	if (argc < 2) {
       
   918 		IConsolePrint(_iconsole_color_warning, "Unknonw usage. Usage: set [setting] [value].");
       
   919 		return NULL;
       
   920 	}
       
   921 
       
   922 #ifdef ENABLE_NETWORK
       
   923 
       
   924 	// setting the server password
       
   925 	if ((strcmp(argv[1],"server_pw") == 0) || (strcmp(argv[1],"server_password") == 0)) {
       
   926 		if (!_network_server) {
       
   927 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
   928 			return NULL;
       
   929 		}
       
   930 		if (argc == 3) {
       
   931 			// Change server password
       
   932 			if (strncmp(argv[2], "*", NETWORK_PASSWORD_LENGTH) == 0) {
       
   933 				_network_server_password[0] = '\0';
       
   934 				_network_game_info.use_password = 0;
       
   935 			} else {
       
   936 				ttd_strlcpy(_network_server_password, argv[2], sizeof(_network_server_password));
       
   937 				_network_game_info.use_password = 1;
       
   938 			}
       
   939 			IConsolePrintF(_iconsole_color_warning, "Game-password changed to '%s'", _network_server_password);
       
   940 			ttd_strlcpy(_network_game_info.server_password, _network_server_password, sizeof(_network_game_info.server_password));
       
   941 		} else {
       
   942 			IConsolePrintF(_iconsole_color_default, "Current game-password is set to '%s'", _network_game_info.server_password);
       
   943 			IConsolePrint(_iconsole_color_warning, "Usage: set server_pw \"<password>\".   Use * as <password> to set no password.");
       
   944 		}
       
   945 		return NULL;
       
   946 	}
       
   947 
       
   948 	// setting the rcon password
       
   949 	if ((strcmp(argv[1], "rcon_pw") == 0) || (strcmp(argv[1], "rcon_password") == 0)) {
       
   950 		if (!_network_server) {
       
   951 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
   952 			return NULL;
       
   953 		}
       
   954 		if (argc == 3) {
       
   955 			// Change server password
       
   956 			if (strncmp(argv[2], "*", NETWORK_PASSWORD_LENGTH) == 0) {
       
   957 				_network_rcon_password[0] = '\0';
       
   958 			} else {
       
   959 				ttd_strlcpy(_network_rcon_password, argv[2], sizeof(_network_rcon_password));
       
   960 			}
       
   961 			IConsolePrintF(_iconsole_color_warning, "Rcon-password changed to '%s'", _network_rcon_password);
       
   962 			ttd_strlcpy(_network_game_info.rcon_password, _network_rcon_password, sizeof(_network_game_info.rcon_password));
       
   963 		} else {
       
   964 			IConsolePrintF(_iconsole_color_default, "Current rcon-password is set to '%s'", _network_game_info.rcon_password);
       
   965 			IConsolePrint(_iconsole_color_warning, "Usage: set rcon_pw \"<password>\".   Use * as <password> to disable rcon.");
       
   966 		}
       
   967 		return NULL;
       
   968 	}
       
   969 
       
   970 	// setting the company password
       
   971 	if ((strcmp(argv[1],"company_pw") == 0) || (strcmp(argv[1],"company_password") == 0)) {
       
   972 		if (!_networking) {
       
   973 			IConsolePrintF(_iconsole_color_error,"No network game running");
       
   974 			return NULL;
       
   975 		}
       
   976 		if (_local_player >= MAX_PLAYERS) {
       
   977 			IConsolePrintF(_iconsole_color_default, "You have to own a company to make use of this command.");
       
   978 			return NULL;
       
   979 		}
       
   980 		if (argc == 3) {
       
   981 			NetworkChangeCompanyPassword(argv[2]);
       
   982 		} else {
       
   983 			IConsolePrint(_iconsole_color_default, "'set company_pw' sets a password for your company, so no-one without the correct password can join.");
       
   984 			IConsolePrint(_iconsole_color_warning, "Usage: set company_pw \"<password>\".   Use * as <password> to set no password.");
       
   985 		}
       
   986 		return NULL;
       
   987 	}
       
   988 
       
   989 	// setting the player name
       
   990 	if (strcmp(argv[1],"name") == 0) {
       
   991 		NetworkClientInfo *ci;
       
   992 
       
   993 		if (!_networking) {
       
   994 			IConsolePrintF(_iconsole_color_error,"No network game running");
       
   995 			return NULL;
       
   996 		}
       
   997 
       
   998 		ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
       
   999 
       
  1000 		if (argc == 3 && ci != NULL) {
       
  1001 			// Don't change the name if it is the same as the old name
       
  1002 			if (strcmp(ci->client_name, argv[2]) != 0) {
       
  1003 				if (!_network_server) {
       
  1004 					SEND_COMMAND(PACKET_CLIENT_SET_NAME)(argv[2]);
       
  1005 				} else {
       
  1006 					if (NetworkFindName(argv[2])) {
       
  1007 						NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, argv[2]);
       
  1008 						ttd_strlcpy(ci->client_name, argv[2], sizeof(ci->client_name));
       
  1009 						NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
       
  1010 					}
       
  1011 				}
       
  1012 				/* Also keep track of the new name on the client itself */
       
  1013 				ttd_strlcpy(_network_player_name, argv[2], sizeof(_network_player_name));
       
  1014 			}
       
  1015 		} else {
       
  1016 			IConsolePrint(_iconsole_color_default, "With 'set name' you can change your network-player name.");
       
  1017 			IConsolePrint(_iconsole_color_warning, "Usage: set name \"<name>\".");
       
  1018 		}
       
  1019 		return NULL;
       
  1020 	}
       
  1021 
       
  1022 	// setting the server name
       
  1023 	if (strcmp(argv[1],"server_name") == 0) {
       
  1024 		if (!_network_server) {
       
  1025 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1026 			return NULL;
       
  1027 		}
       
  1028 		if (argc == 3) {
       
  1029 			ttd_strlcpy(_network_server_name, argv[2], sizeof(_network_server_name));
       
  1030 			IConsolePrintF(_iconsole_color_warning, "Server-name changed to '%s'", _network_server_name);
       
  1031 			ttd_strlcpy(_network_game_info.server_name, _network_server_name, sizeof(_network_game_info.server_name));
       
  1032 		} else {
       
  1033 			IConsolePrintF(_iconsole_color_default, "Current server-name is '%s'", _network_server_name);
       
  1034 			IConsolePrint(_iconsole_color_warning, "Usage: set server_name \"<GameName>\".");
       
  1035 		}
       
  1036 		return NULL;
       
  1037 	}
       
  1038 
       
  1039 	// setting the server port
       
  1040 	if (strcmp(argv[1],"server_port") == 0) {
       
  1041 		if (argc == 3 && atoi(argv[2]) != 0) {
       
  1042 			_network_server_port = atoi(argv[2]);
       
  1043 			IConsolePrintF(_iconsole_color_warning, "Server-port changed to '%d'", _network_server_port);
       
  1044 			IConsolePrintF(_iconsole_color_warning, "Changes will take effect the next time you start a server.");
       
  1045 		} else {
       
  1046 			IConsolePrintF(_iconsole_color_default, "Current server-port is '%d'", _network_server_port);
       
  1047 			IConsolePrint(_iconsole_color_warning, "Usage: set server_port <port>.");
       
  1048 		}
       
  1049 		return NULL;
       
  1050 	}
       
  1051 
       
  1052 	// setting the server ip
       
  1053 	if (strcmp(argv[1],"server_bind_ip") == 0 || strcmp(argv[1],"server_ip_bind") == 0 ||
       
  1054 			strcmp(argv[1],"server_ip") == 0 || strcmp(argv[1],"server_bind") == 0) {
       
  1055 		if (argc == 3) {
       
  1056 			_network_server_bind_ip = inet_addr(argv[2]);
       
  1057 			snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
       
  1058 			IConsolePrintF(_iconsole_color_warning, "Server-bind-ip changed to '%s'", _network_server_bind_ip_host);
       
  1059 			IConsolePrintF(_iconsole_color_warning, "Changes will take effect the next time you start a server.");
       
  1060 		} else {
       
  1061 			IConsolePrintF(_iconsole_color_default, "Current server-bind-ip is '%s'", _network_server_bind_ip_host);
       
  1062 			IConsolePrint(_iconsole_color_warning, "Usage: set server_bind_ip <ip>.");
       
  1063 		}
       
  1064 		return NULL;
       
  1065 	}
       
  1066 
       
  1067 	// setting max-join-time
       
  1068 	if (strcmp(argv[1],"max_join_time") == 0) {
       
  1069 		if (argc == 3 && atoi(argv[2]) != 0) {
       
  1070 			_network_max_join_time = atoi(argv[2]);
       
  1071 			IConsolePrintF(_iconsole_color_warning, "Max-join-time changed to '%d'", _network_max_join_time);
       
  1072 			IConsolePrintF(_iconsole_color_warning, "Changes will take effect immediatly.");
       
  1073 		} else {
       
  1074 			IConsolePrintF(_iconsole_color_default, "Current max-join-time is '%d'", _network_max_join_time);
       
  1075 			IConsolePrint(_iconsole_color_warning, "Usage: set max_join_time <ticks> (default = 500).");
       
  1076 		}
       
  1077 		return NULL;
       
  1078 	}
       
  1079 
       
  1080 
       
  1081 	// setting the server advertising on/off
       
  1082 	if (strcmp(argv[1],"server_advertise") == 0) {
       
  1083 		if (!_network_server) {
       
  1084 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1085 			return NULL;
       
  1086 		}
       
  1087 		if (argc == 3) {
       
  1088 			if (strcmp(argv[2], "on") == 0 || atoi(argv[2]) == 1)
       
  1089 				_network_advertise = true;
       
  1090 			else {
       
  1091 				NetworkUDPRemoveAdvertise();
       
  1092 				_network_advertise = false;
       
  1093 			}
       
  1094 			IConsolePrintF(_iconsole_color_warning, "Server-advertise changed to '%s'", (_network_advertise)?"on":"off");
       
  1095 		} else {
       
  1096 			IConsolePrintF(_iconsole_color_default, "Current server-advertise is '%s'", (_network_advertise)?"on":"off");
       
  1097 			IConsolePrint(_iconsole_color_warning, "Usage: set server_advertise on/off.");
       
  1098 		}
       
  1099 		return NULL;
       
  1100 	}
       
  1101 
       
  1102 	// setting the server 'pause on client join' on/off
       
  1103 	if (strcmp(argv[1],"pause_on_join") == 0) {
       
  1104 		if (!_network_server) {
       
  1105 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1106 			return NULL;
       
  1107 		}
       
  1108 		if (argc == 3) {
       
  1109 			if (strcmp(argv[2], "on") == 0 || atoi(argv[2]) == 1)
       
  1110 				_network_pause_on_join = true;
       
  1111 			else
       
  1112 				_network_pause_on_join = false;
       
  1113 			IConsolePrintF(_iconsole_color_warning, "Pause-on-join changed to '%s'", (_network_pause_on_join)?"on":"off");
       
  1114 		} else {
       
  1115 			IConsolePrintF(_iconsole_color_default, "Current pause-on-join is '%s'", (_network_pause_on_join)?"on":"off");
       
  1116 			IConsolePrint(_iconsole_color_warning, "Usage: set pause_on_join on/off.");
       
  1117 		}
       
  1118 		return NULL;
       
  1119 	}
       
  1120 
       
  1121 	// setting the server autoclean on/off
       
  1122 	if (strcmp(argv[1],"autoclean_companies") == 0) {
       
  1123 		if (!_network_server) {
       
  1124 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1125 			return NULL;
       
  1126 		}
       
  1127 		if (argc == 3) {
       
  1128 			if (strcmp(argv[2], "on") == 0 || atoi(argv[2]) == 1)
       
  1129 				_network_autoclean_companies = true;
       
  1130 			else
       
  1131 				_network_autoclean_companies = false;
       
  1132 			IConsolePrintF(_iconsole_color_warning, "Autoclean-companies changed to '%s'", (_network_autoclean_companies)?"on":"off");
       
  1133 		} else {
       
  1134 			IConsolePrintF(_iconsole_color_default, "Current autoclean-companies is '%s'", (_network_autoclean_companies)?"on":"off");
       
  1135 			IConsolePrint(_iconsole_color_warning, "Usage: set autoclean_companies on/off.");
       
  1136 		}
       
  1137 		return NULL;
       
  1138 	}
       
  1139 
       
  1140 	// setting the server autoclean protected
       
  1141 	if (strcmp(argv[1],"autoclean_protected") == 0) {
       
  1142 		if (!_network_server) {
       
  1143 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1144 			return NULL;
       
  1145 		}
       
  1146 		if (argc == 3) {
       
  1147 			_network_autoclean_protected = atoi(argv[2]);
       
  1148 			IConsolePrintF(_iconsole_color_warning, "Autoclean-protected changed to '%d'", _network_autoclean_protected);
       
  1149 		} else {
       
  1150 			IConsolePrintF(_iconsole_color_default, "Current autoclean-protected is '%d'", _network_autoclean_protected);
       
  1151 			IConsolePrint(_iconsole_color_warning, "Usage: set autoclean_protected <months>.");
       
  1152 		}
       
  1153 		return NULL;
       
  1154 	}
       
  1155 
       
  1156 	// setting the server autoclean protected
       
  1157 	if (strcmp(argv[1],"autoclean_unprotected") == 0) {
       
  1158 		if (!_network_server) {
       
  1159 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1160 			return NULL;
       
  1161 		}
       
  1162 		if (argc == 3) {
       
  1163 			_network_autoclean_unprotected = atoi(argv[2]);
       
  1164 			IConsolePrintF(_iconsole_color_warning, "Autoclean-unprotected changed to '%d'", _network_autoclean_unprotected);
       
  1165 		} else {
       
  1166 			IConsolePrintF(_iconsole_color_default, "Current autoclean-unprotected is '%d'", _network_autoclean_unprotected);
       
  1167 			IConsolePrint(_iconsole_color_warning, "Usage: set autoclean_unprotected <months>.");
       
  1168 		}
       
  1169 		return NULL;
       
  1170 	}
       
  1171 
       
  1172 	// setting the server auto restart date
       
  1173 	if (strcmp(argv[1],"restart_game_date") == 0) {
       
  1174 		if (!_network_server) {
       
  1175 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1176 			return NULL;
       
  1177 		}
       
  1178 		if (argc == 3) {
       
  1179 			_network_restart_game_date = atoi(argv[2]);
       
  1180 			IConsolePrintF(_iconsole_color_warning, "Restart Game Date changed to '%d'", _network_restart_game_date);
       
  1181 		} else {
       
  1182 			IConsolePrintF(_iconsole_color_default, "Current Restart Game Date is '%d'", _network_restart_game_date);
       
  1183 			IConsolePrint(_iconsole_color_warning, "Usage: set restart_game_date <year>. '0' means disabled.");
       
  1184 			IConsolePrint(_iconsole_color_warning, " Auto-restart the server when 1 jan of this year is reached (e.g.: 2030).");
       
  1185 		}
       
  1186 		return NULL;
       
  1187 	}
       
  1188 
       
  1189 #endif /* ENABLE_NETWORK */
       
  1190 
       
  1191 	// Patch-options
       
  1192 	if (strcmp(argv[1],"patch") == 0) {
       
  1193 		if (_networking && !_network_server) {
       
  1194 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
  1195 			return NULL;
       
  1196 		}
       
  1197 		if (argc == 3)
       
  1198 			ConsoleGetPatchSetting(argv[2]);
       
  1199 		else if (argc == 4)
       
  1200 			ConsoleSetPatchSetting(argv[2], argv[3]);
       
  1201 		else
       
  1202 			IConsolePrint(_iconsole_color_warning, "Usage: set patch <patch_name> [<value>].");
       
  1203 		return NULL;
       
  1204 	}
       
  1205 
       
  1206 
       
  1207 	IConsolePrint(_iconsole_color_error, "Unknown setting");
       
  1208 	IConsolePrint(_iconsole_color_error, "Known settings are:");
       
  1209 #ifdef ENABLE_NETWORK
       
  1210 	IConsolePrint(_iconsole_color_error, " - autoclean_companies on/off");
       
  1211 	IConsolePrint(_iconsole_color_error, " - autoclean_protected <months>");
       
  1212 	IConsolePrint(_iconsole_color_error, " - autoclean_unprotected <months>");
       
  1213 	IConsolePrint(_iconsole_color_error, " - company_pw \"<password>\"");
       
  1214 	IConsolePrint(_iconsole_color_error, " - max_join_time <frames>");
       
  1215 	IConsolePrint(_iconsole_color_error, " - name \"<playername>\"");
       
  1216 	IConsolePrint(_iconsole_color_error, " - pause_on_join on/off");
       
  1217 	IConsolePrint(_iconsole_color_error, " - rcon_pw \"<password>\"");
       
  1218 	IConsolePrint(_iconsole_color_error, " - server_name \"<name>\"");
       
  1219 	IConsolePrint(_iconsole_color_error, " - server_advertise on/off");
       
  1220 	IConsolePrint(_iconsole_color_error, " - server_bind_ip <ip>");
       
  1221 	IConsolePrint(_iconsole_color_error, " - server_port <port>");
       
  1222 	IConsolePrint(_iconsole_color_error, " - server_pw \"<password>\"");
       
  1223 	IConsolePrint(_iconsole_color_error, " - restart_game_date \"<year>\"");
       
  1224 #endif /* ENABLE_NETWORK */
       
  1225 	IConsolePrint(_iconsole_color_error, " - patch <patch_name> [<value>]");
       
  1226 
       
  1227 	return NULL;
       
  1228 }
  1131 }
  1229 
  1132 
  1230 
  1133 
  1231 #ifdef _DEBUG
  1134 #ifdef _DEBUG
  1232 /* ****************************************** */
  1135 /* ****************************************** */
  1236 static void IConsoleDebugLibRegister(void)
  1139 static void IConsoleDebugLibRegister(void)
  1237 {
  1140 {
  1238 	// debugging variables and functions
  1141 	// debugging variables and functions
  1239 	extern bool _stdlib_con_developer; /* XXX extern in .c */
  1142 	extern bool _stdlib_con_developer; /* XXX extern in .c */
  1240 
  1143 
  1241 	IConsoleVarRegister("con_developer", &_stdlib_con_developer, ICONSOLE_VAR_BOOLEAN);
  1144 	IConsoleVarRegister("con_developer",    &_stdlib_con_developer, ICONSOLE_VAR_BOOLEAN, "Enable/disable console debugging information (internal)");
  1242 	IConsoleVarMemRegister("temp_string2", ICONSOLE_VAR_STRING);
  1145 	IConsoleCmdRegister("resettile",        ConResetTile);
  1243 	IConsoleVarMemRegister("temp_uint16_2", ICONSOLE_VAR_UINT16);
  1146 	IConsoleAliasRegister("dbg_echo",       "echo %A; echo %B");
  1244 	IConsoleCmdRegister("resettile", ConResetTile);
  1147 	IConsoleAliasRegister("dbg_echo2",      "echo %!");
  1245 	IConsoleAliasRegister("dbg_echo","echo %A; echo %B");
       
  1246 	IConsoleAliasRegister("dbg_echo2","echo %+");
       
  1247 }
  1148 }
  1248 #endif
  1149 #endif
  1249 
  1150 
  1250 /* ****************************************** */
  1151 /* ****************************************** */
  1251 /*  console command and variable registration */
  1152 /*  console command and variable registration */
  1266 	IConsoleCmdRegister("help",         ConHelp);
  1167 	IConsoleCmdRegister("help",         ConHelp);
  1267 	IConsoleCmdRegister("info_cmd",     ConInfoCmd);
  1168 	IConsoleCmdRegister("info_cmd",     ConInfoCmd);
  1268 	IConsoleCmdRegister("info_var",     ConInfoVar);
  1169 	IConsoleCmdRegister("info_var",     ConInfoVar);
  1269 	IConsoleCmdRegister("list_cmds",    ConListCommands);
  1170 	IConsoleCmdRegister("list_cmds",    ConListCommands);
  1270 	IConsoleCmdRegister("list_vars",    ConListVariables);
  1171 	IConsoleCmdRegister("list_vars",    ConListVariables);
  1271 	IConsoleCmdRegister("list_aliases",    ConListAliases);
  1172 	IConsoleCmdRegister("list_aliases", ConListAliases);
  1272 	IConsoleCmdRegister("newgame",         ConNewGame);
  1173 	IConsoleCmdRegister("newgame",      ConNewGame);
  1273 	IConsoleCmdRegister("printf",       ConPrintF);
       
  1274 	IConsoleCmdRegister("printfc",      ConPrintFC);
       
  1275 	IConsoleCmdRegister("quit",         ConExit);
  1174 	IConsoleCmdRegister("quit",         ConExit);
  1276 	IConsoleCmdRegister("random",       ConRandom);
       
  1277 	IConsoleCmdRegister("resetengines", ConResetEngines);
  1175 	IConsoleCmdRegister("resetengines", ConResetEngines);
  1278 	IConsoleCmdRegister("return",     ConReturn);
  1176 	IConsoleCmdRegister("return",       ConReturn);
  1279 	IConsoleCmdRegister("screenshot", ConScreenShot);
  1177 	IConsoleCmdRegister("screenshot",   ConScreenShot);
  1280 	IConsoleCmdRegister("script",     ConScript);
  1178 	IConsoleCmdRegister("script",       ConScript);
  1281 	IConsoleCmdRegister("scrollto",   ConScrollToTile);
  1179 	IConsoleCmdRegister("scrollto",     ConScrollToTile);
  1282 	IConsoleCmdRegister("set",			ConSet);
  1180 	IConsoleCmdRegister("alias",	      ConAlias);
  1283 	IConsoleCmdRegister("alias",		ConAlias);
  1181 	IConsoleCmdRegister("load",			    ConLoad);
  1284 	IConsoleCmdRegister("load",			ConLoad);
  1182 	IConsoleCmdRegister("save",			    ConSave);
  1285 	IConsoleCmdRegister("save",			ConSave);
  1183 	IConsoleCmdRegister("ls",           ConListFiles);
  1286 	IConsoleCmdRegister("ls", ConListFiles);
  1184 	IConsoleCmdRegister("cd",           ConChangeDirectory);
  1287 	IConsoleCmdRegister("cd", ConChangeDirectory);
  1185 	IConsoleCmdRegister("pwd",          ConPrintWorkingDirectory);
  1288 	IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
  1186 
  1289 	IConsoleAliasRegister("dir", "ls");
  1187 	IConsoleAliasRegister("dir",      "ls");
       
  1188 	IConsoleAliasRegister("newmap",   "newgame");
       
  1189 	IConsoleAliasRegister("new_map",  "newgame");
  1290 	IConsoleAliasRegister("new_game", "newgame");
  1190 	IConsoleAliasRegister("new_game", "newgame");
  1291 	IConsoleAliasRegister("newmap", "newgame");
  1191 
  1292 	IConsoleAliasRegister("new_map", "newgame");
  1192 
  1293 
  1193 	IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE, "Redirect debugging output from the console/command line to the ingame console (value 2). Default value: 1");
  1294 	IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE);
  1194 
  1295 
  1195 	/* networking variables and functions */
  1296 	// temporary data containers for alias scripting
       
  1297 	IConsoleVarMemRegister("temp_string", ICONSOLE_VAR_STRING);
       
  1298 	IConsoleVarMemRegister("temp_bool", ICONSOLE_VAR_BOOLEAN);
       
  1299 	IConsoleVarMemRegister("temp_int16", ICONSOLE_VAR_INT16);
       
  1300 	IConsoleVarMemRegister("temp_int32", ICONSOLE_VAR_INT32);
       
  1301 	IConsoleVarMemRegister("temp_pointer", ICONSOLE_VAR_POINTER);
       
  1302 	IConsoleVarMemRegister("temp_uint16", ICONSOLE_VAR_UINT16);
       
  1303 	IConsoleVarMemRegister("temp_uint32", ICONSOLE_VAR_UINT32);
       
  1304 
       
  1305 
       
  1306 	// networking variables and functions
       
  1307 #ifdef ENABLE_NETWORK
  1196 #ifdef ENABLE_NETWORK
  1308 	IConsoleCmdRegister("say",        ConSay);
  1197 	/*** Networking commands ***/
  1309 	IConsoleCmdHook("say", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
  1198 	IConsoleCmdRegister("say",             ConSay);
  1310 	IConsoleCmdRegister("say_player", ConSayPlayer);
  1199 	IConsoleCmdHookAdd("say",              ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
  1311 	IConsoleCmdHook("say_player", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
  1200 	IConsoleCmdRegister("say_player",      ConSayPlayer);
  1312 	IConsoleCmdRegister("say_client", ConSayClient);
  1201 	IConsoleCmdHookAdd("say_player",       ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
  1313 	IConsoleCmdHook("say_client", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
  1202 	IConsoleCmdRegister("say_client",      ConSayClient);
  1314 	IConsoleCmdRegister("kick",         ConKick);
  1203 	IConsoleCmdHookAdd("say_client",       ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
  1315 	IConsoleCmdHook("kick", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1204 	IConsoleCmdRegister("kick",            ConKick);
  1316 	IConsoleCmdRegister("reset_company",         ConResetCompany);
  1205 	IConsoleCmdHookAdd("kick",             ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1317 	IConsoleCmdHook("reset_company", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1206 	IConsoleCmdRegister("reset_company",   ConResetCompany);
  1318 	IConsoleCmdRegister("connect", ConNetworkConnect);
  1207 	IConsoleCmdHookAdd("reset_company",    ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1319 	IConsoleCmdHook("connect", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetServer);
  1208 	IConsoleAliasRegister("clean_company", "reset_company %A");
  1320 	IConsoleCmdRegister("clients", ConNetworkClients);
  1209 	IConsoleCmdRegister("connect",         ConNetworkConnect);
  1321 	IConsoleCmdRegister("status",   ConStatus);
  1210 	IConsoleCmdHookAdd("connect",          ICONSOLE_HOOK_ACCESS, ConHookClientOnly);
  1322 	IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1211 	IConsoleCmdRegister("clients",         ConNetworkClients);
  1323 	IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
  1212 	IConsoleCmdRegister("status",          ConStatus);
  1324 
  1213 	IConsoleCmdHookAdd("status",           ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1325 	IConsoleCmdRegister("rcon",        ConRcon);
  1214 	IConsoleCmdHookAdd("resetengines",     ICONSOLE_HOOK_ACCESS, ConHookNoNetwork);
  1326 	IConsoleCmdHook("rcon", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
  1215 
  1327 
  1216 	IConsoleCmdRegister("rcon",            ConRcon);
  1328 	IConsoleCmdRegister("ban",   ConBan);
  1217 	IConsoleCmdHookAdd("rcon",             ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
  1329 	IConsoleCmdHook("ban", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1218 
  1330 	IConsoleCmdRegister("unban",   ConUnBan);
  1219 	IConsoleCmdRegister("ban",             ConBan);
  1331 	IConsoleCmdHook("unban", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1220 	IConsoleCmdHookAdd("ban",              ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1332 	IConsoleCmdRegister("banlist",   ConBanList);
  1221 	IConsoleCmdRegister("unban",           ConUnBan);
  1333 	IConsoleCmdHook("banlist", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1222 	IConsoleCmdHookAdd("unban",            ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1334 	IConsoleCmdRegister("pause",   ConPauseGame);
  1223 	IConsoleCmdRegister("banlist",         ConBanList);
  1335 	IConsoleCmdHook("pause", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1224 	IConsoleCmdHookAdd("banlist",          ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1336 	IConsoleCmdRegister("unpause",   ConUnPauseGame);
  1225 	IConsoleCmdRegister("pause",           ConPauseGame);
  1337 	IConsoleCmdHook("unpause", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1226 	IConsoleCmdHookAdd("pause",            ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1338 
  1227 	IConsoleCmdRegister("unpause",         ConUnPauseGame);
  1339 	IConsoleAliasRegister("clean_company",		"reset_company %A");
  1228 	IConsoleCmdHookAdd("unpause",          ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1340 
  1229 
  1341 	IConsoleVarRegister("net_frame_freq", &_network_frame_freq, ICONSOLE_VAR_UINT8);
  1230 	IConsoleCmdRegister("patch",           ConPatch);
  1342 	IConsoleVarHook("net_frame_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
  1231 	IConsoleCmdHookAdd("patch",            ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
  1343 	IConsoleVarRegister("net_sync_freq", &_network_sync_freq, ICONSOLE_VAR_UINT16);
  1232 
  1344 	IConsoleVarHook("net_sync_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
  1233 	/*** Networking variables ***/
       
  1234 	IConsoleVarRegister("net_frame_freq",        &_network_frame_freq, ICONSOLE_VAR_BYTE, "The amount of frames before a command will be (visibly) executed. Default value: 1");
       
  1235 	IConsoleVarHookAdd("net_frame_freq",         ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1236 	IConsoleVarRegister("net_sync_freq",         &_network_sync_freq,  ICONSOLE_VAR_UINT16, "The amount of frames to check if the game is still in sync. Default value: 100");
       
  1237 	IConsoleVarHookAdd("net_sync_freq",          ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1238 
       
  1239 	IConsoleVarStringRegister("server_pw",       &_network_server_password, sizeof(_network_server_password), "Set the server password to protect your server. Use '*' to clear the password");
       
  1240 	IConsoleVarHookAdd("server_pw",              ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1241 	IConsoleVarHookAdd("server_pw",              ICONSOLE_HOOK_POST_ACTION, ConHookServerPW);
       
  1242 	IConsoleAliasRegister("server_password",     "server_pw %+");
       
  1243 
       
  1244 	IConsoleVarStringRegister("rcon_pw",         &_network_rcon_password, sizeof(_network_rcon_password), "Set the rcon-password to change server behaviour. Use '*' to disable rcon");
       
  1245 	IConsoleVarHookAdd("rcon_pw",                ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1246 	IConsoleVarHookAdd("rcon_pw",                ICONSOLE_HOOK_POST_ACTION, ConHookRconPW);
       
  1247 	IConsoleAliasRegister("rcon_password",       "rcon_pw %+");
       
  1248 
       
  1249 	IConsoleVarStringRegister("company_pw",      NULL, 0, "Set a password for your company, so no one without the correct password can join. Use '*' to clear the password");
       
  1250 	IConsoleVarHookAdd("company_pw",             ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
       
  1251 	IConsoleVarProcAdd("company_pw",             NetworkChangeCompanyPassword);
       
  1252 	IConsoleAliasRegister("company_password",    "company_pw %+");
       
  1253 
       
  1254 	IConsoleVarStringRegister("name",            &_network_player_name, sizeof(_network_player_name), "Set your name for multiplayer");
       
  1255 	IConsoleVarHookAdd("name",                   ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
       
  1256 	IConsoleVarHookAdd("name",                   ICONSOLE_HOOK_POST_ACTION, ConProcPlayerName);
       
  1257 
       
  1258 	IConsoleVarStringRegister("server_name",     &_network_server_name, sizeof(_network_server_name), "Set the name of the server for multiplayer");
       
  1259 	IConsoleVarHookAdd("server_name",            ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1260 	IConsoleVarHookAdd("server_name",            ICONSOLE_HOOK_POST_ACTION, ConHookServerName);
       
  1261 
       
  1262 	IConsoleVarRegister("server_port",           &_network_server_port, ICONSOLE_VAR_UINT32, "Set the server port. Changes take effect the next time you start a server");
       
  1263 
       
  1264 	IConsoleVarRegister("server_ip",             &_network_server_bind_ip, ICONSOLE_VAR_UINT32, "Set the IP the server binds to. Changes take effect the next time you start a server");
       
  1265 	IConsoleVarProcAdd("server_ip",              ConProcServerIP);
       
  1266 	IConsoleAliasRegister("server_bind_ip",      "server_ip %+");
       
  1267 	IConsoleAliasRegister("server_ip_bind",      "server_ip %+");
       
  1268 	IConsoleAliasRegister("server_bind",         "server_ip %+");
       
  1269 
       
  1270 	IConsoleVarRegister("max_join_time",         &_network_max_join_time, ICONSOLE_VAR_UINT16, "Set the maximum amount of time (ticks) a client is allowed to join. Default value: 500");
       
  1271 
       
  1272 	IConsoleVarRegister("server_advertise",      &_network_advertise, ICONSOLE_VAR_BOOLEAN, "Set if the server will advertise to the master server and show up there");
       
  1273 	IConsoleVarHookAdd("server_advertise",       ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1274 	IConsoleVarHookAdd("server_advertise",       ICONSOLE_HOOK_POST_ACTION, ConHookServerAdvertise);
       
  1275 
       
  1276 	IConsoleVarRegister("pause_on_join",         &_network_pause_on_join, ICONSOLE_VAR_BOOLEAN, "Set if the server should pause gameplay while a client is joining. This might help slow users");
       
  1277 	IConsoleVarHookAdd("pause_on_join",          ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1278 
       
  1279 	IConsoleVarRegister("autoclean_companies",   &_network_autoclean_companies, ICONSOLE_VAR_BOOLEAN, "Automatically shut down inactive companies to free them up for other players. Customize with 'autoclean_(un)protected'");
       
  1280 	IConsoleVarHookAdd("autoclean_companies",    ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1281 
       
  1282 	IConsoleVarRegister("autoclean_protected",   &_network_autoclean_protected, ICONSOLE_VAR_BYTE, "Automatically remove the password from an inactive company after the given amount of months");
       
  1283 	IConsoleVarHookAdd("autoclean_protected",    ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1284 
       
  1285 	IConsoleVarRegister("autoclean_unprotected", &_network_autoclean_protected, ICONSOLE_VAR_BYTE, "Automatically shut down inactive companies after the given amount of months");
       
  1286 	IConsoleVarHookAdd("autoclean_unprotected",  ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1287 
       
  1288 	IConsoleVarRegister("restart_game_date",     &_network_restart_game_date, ICONSOLE_VAR_BYTE, "Auto-restart the server when Jan 1st of the set year is reached. Use '0' to disable this");
       
  1289 	IConsoleVarHookAdd("restart_game_date",      ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
       
  1290 
  1345 #endif /* ENABLE_NETWORK */
  1291 #endif /* ENABLE_NETWORK */
  1346 
  1292 
  1347 	// debugging stuff
  1293 	// debugging stuff
  1348 #ifdef _DEBUG
  1294 #ifdef _DEBUG
  1349 	IConsoleDebugLibRegister();
  1295 	IConsoleDebugLibRegister();
  1350 #endif
  1296 #endif
  1351 
  1297 }
  1352 }
       
  1353 /* -------------------- don't cross this line --------------------- */