console_cmds.c
changeset 2859 ed471404f531
parent 2541 959903599cb9
child 2860 92f1a57844f9
equal deleted inserted replaced
2858:2385edfd358b 2859:ed471404f531
   363 {
   363 {
   364 	NetworkClientInfo *ci;
   364 	NetworkClientInfo *ci;
   365 	uint32 index;
   365 	uint32 index;
   366 
   366 
   367 	if (argc == 0) {
   367 	if (argc == 0) {
   368 		IConsoleHelp("Ban a player from a network game. Usage: 'ban <client-id>'");
   368 		IConsoleHelp("Ban a player from a network game. Usage: 'ban <ip | client-id>'");
   369 		IConsoleHelp("For client-id's, see the command 'clients'");
   369 		IConsoleHelp("For client-id's, see the command 'clients'");
   370 		return true;
   370 		return true;
   371 	}
   371 	}
   372 
   372 
   373 	if (argc != 2) return false;
   373 	if (argc != 2) return false;
   374 
   374 
   375 	index = atoi(argv[1]);
   375 	if (strchr(argv[1], '.') == NULL) {
       
   376 		index = atoi(argv[1]);
       
   377 		ci = NetworkFindClientFromIndex(index);
       
   378 	} else {
       
   379 		ci = NetworkFindClientFromIP(argv[1]);
       
   380 		index = (ci == NULL) ? 0 : ci->client_index;
       
   381 	}
   376 
   382 
   377 	if (index == NETWORK_SERVER_INDEX) {
   383 	if (index == NETWORK_SERVER_INDEX) {
   378 		IConsolePrint(_icolour_def, "Silly boy, you can not ban yourself!");
   384 		IConsolePrint(_icolour_def, "Silly boy, you can not ban yourself!");
   379 		return true;
   385 		return true;
   380 	}
   386 	}
       
   387 
   381 	if (index == 0) {
   388 	if (index == 0) {
   382 		IConsoleError("Invalid Client-ID");
   389 		IConsoleError("Invalid Client-ID");
   383 		return true;
   390 		return true;
   384 	}
   391 	}
   385 
       
   386 	ci = NetworkFindClientInfoFromIndex(index);
       
   387 
   392 
   388 	if (ci != NULL) {
   393 	if (ci != NULL) {
   389 		uint i;
   394 		uint i;
   390 		/* Add user to ban-list */
   395 		/* Add user to ban-list */
   391 		for (i = 0; i < lengthof(_network_ban_list); i++) {
   396 		for (i = 0; i < lengthof(_network_ban_list); i++) {
   405 DEF_CONSOLE_CMD(ConUnBan)
   410 DEF_CONSOLE_CMD(ConUnBan)
   406 {
   411 {
   407 	uint i, index;
   412 	uint i, index;
   408 
   413 
   409 	if (argc == 0) {
   414 	if (argc == 0) {
   410 		IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip | id>'");
   415 		IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip | client-id>'");
   411 		IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
   416 		IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
   412 		return true;
   417 		return true;
   413 	}
   418 	}
   414 
   419 
   415 	if (argc != 2) return false;
   420 	if (argc != 2) return false;
   526 {
   531 {
   527 	NetworkClientInfo *ci;
   532 	NetworkClientInfo *ci;
   528 	uint32 index;
   533 	uint32 index;
   529 
   534 
   530 	if (argc == 0) {
   535 	if (argc == 0) {
   531 		IConsoleHelp("Kick a player from a network game. Usage: 'kick <client-id>'");
   536 		IConsoleHelp("Kick a player from a network game. Usage: 'kick <ip | client-id>'");
   532 		IConsoleHelp("For client-id's, see the command 'clients'");
   537 		IConsoleHelp("For client-id's, see the command 'clients'");
   533 		return true;
   538 		return true;
   534 	}
   539 	}
   535 
   540 
   536 	if (argc != 2) return false;
   541 	if (argc != 2) return false;
   537 
   542 
   538 	index = atoi(argv[1]);
   543 	if (strchr(argv[1], '.') == NULL) {
       
   544 		index = atoi(argv[1]);
       
   545 		ci = NetworkFindClientFromIndex(index);
       
   546 	} else {
       
   547 		ci = NetworkFindClientFromIP(argv[1]);
       
   548 		index = (ci == NULL) ? 0 : ci->client_index;
       
   549 	}
       
   550 
   539 	if (index == NETWORK_SERVER_INDEX) {
   551 	if (index == NETWORK_SERVER_INDEX) {
   540 		IConsolePrint(_icolour_def, "Silly boy, you can not kick yourself!");
   552 		IConsolePrint(_icolour_def, "Silly boy, you can not kick yourself!");
   541 		return true;
   553 		return true;
   542 	}
   554 	}
       
   555 
   543 	if (index == 0) {
   556 	if (index == 0) {
   544 		IConsoleError("Invalid client-id");
   557 		IConsoleError("Invalid client-id");
   545 		return true;
   558 		return true;
   546 	}
   559 	}
   547 
       
   548 	ci = NetworkFindClientInfoFromIndex(index);
       
   549 
   560 
   550 	if (ci != NULL) {
   561 	if (ci != NULL) {
   551 		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   562 		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
   552 	} else
   563 	} else
   553 		IConsoleError("Client-id not found");
   564 		IConsoleError("Client-id not found");