console_cmds.c
changeset 1026 02cc18821508
parent 1023 1ae7b7a78602
child 1046 f1d46abf7d35
equal deleted inserted replaced
1025:f10da46b66f0 1026:02cc18821508
   377 	}
   377 	}
   378 
   378 
   379 	return NULL;
   379 	return NULL;
   380 }
   380 }
   381 
   381 
       
   382 DEF_CONSOLE_CMD(ConRcon)
       
   383 {
       
   384 	if (argc < 3) {
       
   385 		IConsolePrint(_iconsole_color_default, "Usage: rcon <password> <command>");
       
   386 		return NULL;
       
   387 	}
       
   388 
       
   389 	SEND_COMMAND(PACKET_CLIENT_RCON)(argv[1], argv[2]);
       
   390 
       
   391 	return NULL;
       
   392 }
       
   393 
   382 DEF_CONSOLE_CMD(ConStatus)
   394 DEF_CONSOLE_CMD(ConStatus)
   383 {
   395 {
   384 	const char *status;
   396 	const char *status;
   385 	int lag;
   397 	int lag;
   386 	const NetworkClientState *cs;
   398 	const NetworkClientState *cs;
   423 {
   435 {
   424 	NetworkClientInfo *ci;
   436 	NetworkClientInfo *ci;
   425 
   437 
   426 	if (argc == 2) {
   438 	if (argc == 2) {
   427 		uint32 index = atoi(argv[1]);
   439 		uint32 index = atoi(argv[1]);
   428 		if (index == NETWORK_SERVER_INDEX && !_network_dedicated) {
   440 		if (index == NETWORK_SERVER_INDEX) {
   429 			IConsolePrint(_iconsole_color_default, "Silly boy, you can not kick yourself!");
   441 			IConsolePrint(_iconsole_color_default, "Silly boy, you can not kick yourself!");
   430 			return NULL;
   442 			return NULL;
   431 		}
   443 		}
   432 		if (index == 0) {
   444 		if (index == 0) {
   433 			IConsoleError("Invalid Client-ID");
   445 			IConsoleError("Invalid Client-ID");
   898 			return NULL;
   910 			return NULL;
   899 		}
   911 		}
   900 		if (argc == 3) {
   912 		if (argc == 3) {
   901 			// Change server password
   913 			// Change server password
   902 			if (strncmp(argv[2], "*", NETWORK_PASSWORD_LENGTH) == 0) {
   914 			if (strncmp(argv[2], "*", NETWORK_PASSWORD_LENGTH) == 0) {
   903 				_network_game_info.server_password[0] = '\0';
   915 				_network_server_password[0] = '\0';
   904 				_network_game_info.use_password = 0;
   916 				_network_game_info.use_password = 0;
   905 			} else {
   917 			} else {
   906 				ttd_strlcpy(_network_game_info.server_password, argv[2], sizeof(_network_game_info.server_password));
   918 				ttd_strlcpy(_network_server_password, argv[2], sizeof(_network_server_password));
   907 				_network_game_info.use_password = 1;
   919 				_network_game_info.use_password = 1;
   908 			}
   920 			}
   909 			IConsolePrintF(_iconsole_color_warning, "Game-password changed to '%s'", _network_game_info.server_password);
   921 			IConsolePrintF(_iconsole_color_warning, "Game-password changed to '%s'", _network_server_password);
       
   922 			ttd_strlcpy(_network_game_info.server_password, _network_server_password, sizeof(_network_game_info.server_password));
   910 		} else {
   923 		} else {
   911 			IConsolePrintF(_iconsole_color_default, "Current game-password is set to '%s'", _network_game_info.server_password);
   924 			IConsolePrintF(_iconsole_color_default, "Current game-password is set to '%s'", _network_game_info.server_password);
   912 			IConsolePrint(_iconsole_color_warning, "Usage: set server_pw \"<password>\".   Use * as <password> to set no password.");
   925 			IConsolePrint(_iconsole_color_warning, "Usage: set server_pw \"<password>\".   Use * as <password> to set no password.");
       
   926 		}
       
   927 		return NULL;
       
   928 	}
       
   929 
       
   930 	// setting the rcon password
       
   931 	if ((strcmp(argv[1], "rcon_pw") == 0) || (strcmp(argv[1], "rcon_password") == 0)) {
       
   932 		if (!_network_server) {
       
   933 			IConsolePrintF(_iconsole_color_error, "You are not the server");
       
   934 			return NULL;
       
   935 		}
       
   936 		if (argc == 3) {
       
   937 			// Change server password
       
   938 			if (strncmp(argv[2], "*", NETWORK_PASSWORD_LENGTH) == 0) {
       
   939 				_network_rcon_password[0] = '\0';
       
   940 			} else {
       
   941 				ttd_strlcpy(_network_rcon_password, argv[2], sizeof(_network_rcon_password));
       
   942 			}
       
   943 			IConsolePrintF(_iconsole_color_warning, "Rcon-password changed to '%s'", _network_rcon_password);
       
   944 			ttd_strlcpy(_network_game_info.rcon_password, _network_rcon_password, sizeof(_network_game_info.rcon_password));
       
   945 		} else {
       
   946 			IConsolePrintF(_iconsole_color_default, "Current rcon-password is set to '%s'", _network_game_info.rcon_password);
       
   947 			IConsolePrint(_iconsole_color_warning, "Usage: set rcon_pw \"<password>\".   Use * as <password> to disable rcon.");
   913 		}
   948 		}
   914 		return NULL;
   949 		return NULL;
   915 	}
   950 	}
   916 
   951 
   917 	// setting the company password
   952 	// setting the company password
  1121 	IConsolePrint(_iconsole_color_error, " - autoclean_companies on/off");
  1156 	IConsolePrint(_iconsole_color_error, " - autoclean_companies on/off");
  1122 	IConsolePrint(_iconsole_color_error, " - autoclean_protected <months>");
  1157 	IConsolePrint(_iconsole_color_error, " - autoclean_protected <months>");
  1123 	IConsolePrint(_iconsole_color_error, " - autoclean_unprotected <months>");
  1158 	IConsolePrint(_iconsole_color_error, " - autoclean_unprotected <months>");
  1124 	IConsolePrint(_iconsole_color_error, " - company_pw \"<password>\"");
  1159 	IConsolePrint(_iconsole_color_error, " - company_pw \"<password>\"");
  1125 	IConsolePrint(_iconsole_color_error, " - name \"<playername>\"");
  1160 	IConsolePrint(_iconsole_color_error, " - name \"<playername>\"");
       
  1161 	IConsolePrint(_iconsole_color_error, " - rcon_pw \"<password>\"");
  1126 	IConsolePrint(_iconsole_color_error, " - server_name \"<name>\"");
  1162 	IConsolePrint(_iconsole_color_error, " - server_name \"<name>\"");
  1127 	IConsolePrint(_iconsole_color_error, " - server_advertise on/off");
  1163 	IConsolePrint(_iconsole_color_error, " - server_advertise on/off");
  1128 	IConsolePrint(_iconsole_color_error, " - server_bind_ip <ip>");
  1164 	IConsolePrint(_iconsole_color_error, " - server_bind_ip <ip>");
  1129 	IConsolePrint(_iconsole_color_error, " - server_port <port>");
  1165 	IConsolePrint(_iconsole_color_error, " - server_port <port>");
  1130 	IConsolePrint(_iconsole_color_error, " - server_pw \"<password>\"");
  1166 	IConsolePrint(_iconsole_color_error, " - server_pw \"<password>\"");
  1227 	IConsoleCmdRegister("clients", ConNetworkClients);
  1263 	IConsoleCmdRegister("clients", ConNetworkClients);
  1228 	IConsoleCmdRegister("status",   ConStatus);
  1264 	IConsoleCmdRegister("status",   ConStatus);
  1229 	IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1265 	IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1230 	IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
  1266 	IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
  1231 
  1267 
       
  1268 	IConsoleCmdRegister("rcon",        ConRcon);
       
  1269 	IConsoleCmdHook("rcon", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
       
  1270 
  1232 	IConsoleCmdRegister("ban",   ConBan);
  1271 	IConsoleCmdRegister("ban",   ConBan);
  1233 	IConsoleCmdHook("ban", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1272 	IConsoleCmdHook("ban", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1234 	IConsoleCmdRegister("unban",   ConUnBan);
  1273 	IConsoleCmdRegister("unban",   ConUnBan);
  1235 	IConsoleCmdHook("unban", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1274 	IConsoleCmdHook("unban", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
  1236 	IConsoleCmdRegister("banlist",   ConBanList);
  1275 	IConsoleCmdRegister("banlist",   ConBanList);