Kod: Tümünü seç
// Same IP Blackout:
// -----------------
// This plugin will give the admins  access to use a command that will scan all the
// present players and will compare their IPs. Then this command will return to that admin the na-
// mes of the players who have the same IP. 
// This way, the admin will know witch players are playing from the same place and are probably g-
// hosting. 
// Also this plugin allows the activation of a new fade to black function that turn the players w-
// ho has the same IP screen into black. This is an imitation of fade to black.
// It will only blackout their screen when they are dead or spectating.
// Commands:
// ---------
// + amx_scanip		- Scans for players with exact IPs
// Cvars:
// ------
// + amx_blackout <1|0>  - (default: 1) Enable the blackout function for players with similar IPs
// Installation:
// -------------
// + Copy SameIPBlackout.amxx to cstrike/addons/amxmodx/plugins
// + Go to cstrike/addons/amxmodx/configs/plugins.ini and add: SameIPBlackout.amxx
// Modules:
// --------
// amxmodx
// amxmisc
// Credits:
// --------
// + MPNumb (http://forums.alliedmods.net/member.php?u=25348) for helping me a lot in learning how to
// code, if it wasn't for him i would have never been able to make this plugin.
// + ConnorMcLeod (http://forums.alliedmods.net/member.php?u=18946) for helping me with ScreenFade
// and how to block other ScreenFade messages, also for his notepad++ plugin.
// + All who helped me through ScriptingHelp. (http://forums.alliedmods.net/forumdisplay.php?f=11)
// Change Log:
// -----------
// 1.0: + initial release
// 1.1: + removed dependency of ConnorMcLeod util
// 1.2: + added refresh when players join or disconnects
//		+ added refresh when plugin is unpaused
//		+ removed refresh when admin calls the command
// To do:
// ------
// + Remove the dependency of ConnorMcLeod include. Will be able to compile online. (DONE)
// + Add MultiLingual support
// + Add file where admins can add IPs to be blacked out
// Includes
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
// Forcing semicolon at end of each line
#pragma semicolon 1
// Define for the message screenfade
#define FFADE_STAYOUT		0x0004		// Ignores the duration of screenfade
// Plugin information
new PLUGIN[]	= "SameIPBlackout";
new VERSION[]	= "1.1";
new AUTHOR[]	= "n0br41ner";
// Global Variables
new g_cvarBlackout;			// Cvar for the blackoutondeath
new g_iMaxPlayers;			// Maximum number of players
new g_iPlayersIP[33][16];   // Stores the IP (16 digit) to the respective id (32 players); first value is a dummy value
new g_iDeadPlayer;			// The id of the dead player
new g_iMsgFade;				// Screenfade id or something :D
new bool:g_bFoundMatch;		// To tell if a match is found or no
new bool:g_bSameIPs[33];	// First value is a dummy value
public plugin_init() {
	// Plugin Registration
	register_plugin(PLUGIN, VERSION, AUTHOR);
	
	// Registering command for admins
	register_concmd("amx_scanip", "ScanIP", ADMIN_ADMIN, " - Scans players for similar IPs");
	
	// Registering blackout cvar and call blackoutondeath function if enabled
	g_cvarBlackout 	= register_cvar("amx_blackout", "1");
	if(get_pcvar_num(g_cvarBlackout) == 1) {
		register_event("DeathMsg", "BlackoutOnDeath", "a");
	}
	RegisterMessage("ScreenFade", "Message_ScreenFade");
	register_event("TextMsg", "spec_mode", "bd", "2&Spec_Mode");
	
	// Setting maxplayers and msgfade
	g_iMaxPlayers 	= clamp(get_maxplayers(), 1, 32); 
	g_iMsgFade = get_user_msgid("ScreenFade");
}
// Refreshing information when a player joins
public client_putinserver(id) {
	Refresh();
}
// Refreshing information when a player disconnects
public client_disconnect(id) {
	Refresh();
}
// Refreshing information when the plugin is unpaused
public plugin_unpause() {
	Refresh();
}
// Function to check access rights and call refresh, compare, and print
public ScanIP(id, level, cid) {
	// Checking if user has ADMIN_BAN flag
	if(!cmd_access(id, level, cid, 1)) {
		return PLUGIN_HANDLED;
	}
	
	// Comparing the ips and then print the result
	Compare();
	Print(id);
	
	return PLUGIN_HANDLED;
}
// Function to refresh information
public Refresh() {
	// Looping through players ids
	for(new i=1; i<=g_iMaxPlayers; i++) {
		// Checking if user is connected
		if(is_user_connected(i)) {
			// Getting the players IP and store it
			get_user_ip(i, g_iPlayersIP[i], charsmax(g_iPlayersIP[]), 1);
		}
	}
}
// Function to compare IPs
public Compare() {
	// Resetting found match to false
	g_bFoundMatch = false;
	
	// In these two nested for loops, i am checking each ip with all the others 
	// That is a total of maxplayers*maxplayers checks
	// In case of a match, set bool to true in g_bSameIPs so later on i know witch ids (of the players) have 
	// the same IP
	for(new i=1; i<=g_iMaxPlayers; i++) {
		if(is_user_connected(i)) {
			// Here i am resetting the state of sameips so results are accurate
			g_bSameIPs[i] = false;
			for(new j=1; j<=g_iMaxPlayers; j++) {
				if(is_user_connected(j)) {
					// Here i am stopping the comparision the same ip to itself
					// for example: equal(g_iPlayersIP[1] == g_iPlayersIP[1]) will be comparing the same ip
					// to itself and we will get bad results if this check was not there
					if(i!=j) {
						if(equal(g_iPlayersIP[i], g_iPlayersIP[j])) {
							g_bFoundMatch = true;
							g_bSameIPs[i] = true;
							g_bSameIPs[j] = true;
						}
					}
				}
			}
		}
	}
}
// Print function to display the names of the players with same ip
public Print(id) {
	// Check if a match was even found
	if(g_bFoundMatch) {
		// Print a small header
		client_print(id, print_console, "Players with identical IPs are:");
		
		// Looping through players 
		for(new i=1; i<=g_iMaxPlayers; i++) {
			// Check if player is among those with same ip
			if(g_bSameIPs[i]) {
				// Create array and store the players PlayerName in it
				new PlayerName[32];
				get_user_name(i, PlayerName, 31);
				
				// Print his PlayerName to the admin
				client_print(id, print_console, "%s", PlayerName);
			}
		}
	} else {
		client_print(id, print_console, "No identical IPs where found.");
	}
}
// Function to blackout players with the same ip
public BlackoutOnDeath() {
	// Variable the store the players id
	g_iDeadPlayer = read_data(2);
	
	// Check if player is among players with same ip and if he is dead and blackout his screen
	// 'g_bSameIPs[g_iDeadPlayer] &&' is commented for testing purposes
	if(g_bSameIPs[g_iDeadPlayer] && !is_user_alive(g_iDeadPlayer)) {
		client_cmd(g_iDeadPlayer, "spec_mode 4");
		message_begin(MSG_ONE, g_iMsgFade, _, g_iDeadPlayer);
		write_short(3);
		write_short(3);
		write_short(FFADE_STAYOUT);
		write_byte(0);
		write_byte(0);
		write_byte(0);
		write_byte(255);
		message_end();
		client_print(g_iDeadPlayer, print_chat, "Your IP was found matching to another player.");
		client_print(g_iDeadPlayer, print_chat, "Your screen has been blacked out.");
	}
}
// Function to block screenfade message
public Message_ScreenFade(iMsgIndex, iMsgDest, id) {
	// Stop the message if the player is one of the same ips and dead
	// 'g_bSameIPs[g_iDeadPlayer] &&' is commented for testing purposes
	if(g_bSameIPs[id] && !is_user_alive(id)) {
		return PLUGIN_HANDLED;
	}
	
	// If not continue
	return PLUGIN_CONTINUE;
}
// Something that ConnorMcLeod wrote and worked, however i don't understand it :D
RegisterMessage(const szMsgName[], const szCallBack[]) {
	return register_message(get_user_msgid(szMsgName), szCallBack);
}
// Change the spec mode to first person view
public spec_mode(id)
{
	// Checking if player is dead and among those with the same ips
    if (g_bSameIPs[id] && !is_user_alive(id)) {
		set_pev(id, pev_iuser1, 4);		
	}
	
    return PLUGIN_CONTINUE;
}
// End of plugin