All pastes #375872 Raw Edit

Someone

public text v1 · immutable
#375872 ·published 2007-02-28 18:03 UTC
rendered paste body
#include <amxmodx>
#include <amxmisc>


#define MAX_DESCRIPTION_LEN 64
new g_IPDescFile[64] = ""

public plugin_init()
{
	register_plugin("Show IP", "1.0", "ahtoh")
	register_dictionary("show_ip.txt")
	register_concmd("amx_showip", "cmdShowIP", 0,"Show players Ip's")

	get_configsdir(g_IPDescFile, 63)
	format(g_IPDescFile, 63, "%s/ipdesc.ini", g_IPDescFile)
}

public cmdShowIP(id)
{

	new players[32], inum, userip[16], name[32], description[MAX_DESCRIPTION_LEN + 1]
	new lDescription[16], lPl_on_server[64]
	
	format(lDescription, 15, "%L", id, "DESCRIPTION")
	format(lPl_on_server, 63, "%L", id, "PLAYERS_ON_SERVER")
	
	get_players(players, inum)
	console_print(id, "^n%s:^n #  %-25.24s %-20s %s", lPl_on_server, "nick", "IP", lDescription)
	
	for (new a = 0; a < inum; ++a)
	{
		get_user_ip(players[a],userip,15,1)
		get_user_name(players[a], name, 31)
		get_ip_description(userip, description)
		console_print(id, "%2d  %-25.24s %-20s %s", players[a], name, userip, description)
	}
	
	console_print(id, "%L", id, "TOTAL_NUM", inum)
	
	return PLUGIN_HANDLED
}

public get_ip_description(const ip[16], description[MAX_DESCRIPTION_LEN + 1])
{
	new ipsubnet[16]
	new part1[4], part2[4], part3[4], part4[4]
	
	copy(ipsubnet, 15, ip)
	replace_all(ipsubnet, 15, ".", " ")
	parse(ipsubnet, part1, 3, part2, 3, part3, 3, part4, 3)
	
	
	// first try to find IP
	if (find_ipdesc(ip, description) != -1)
		return 0

	// try xxx.xxx.xxx format
	format(ipsubnet, 15, "%s.%s.%s", part1, part2, part3)
	if (find_ipdesc(ipsubnet, description) != -1)
		return 0

	// try xxx.xxx format
	format(ipsubnet, 15, "%s.%s", part1, part2)
	if (find_ipdesc(ipsubnet, description) != -1)
		return 0
	
	return -1
}

public find_ipdesc(const ip[16], description[MAX_DESCRIPTION_LEN + 1])
{
	// Make sure that the ipdesc.ini file exists.
	if (!file_exists(g_IPDescFile))
		return -1
	
	new line = 0, textline[256], len
	new lineIP[16], lineDescription[MAX_DESCRIPTION_LEN + 1]
	
	// <ip> <description>
	while ((line = read_file(g_IPDescFile, line, textline, 255, len)))
	{
		if (len == 0 || equal(textline, ";", 1))
			continue // comment line

		parse(textline, lineIP, 15, lineDescription, MAX_DESCRIPTION_LEN)
		
		if (equal(lineIP, ip))
		{
			copy(description, MAX_DESCRIPTION_LEN, lineDescription)
			return 0
		}
	}
	
	return -1
}


public client_connect(id)
{
	new userip[16]
	new name[32]
	new description[MAX_DESCRIPTION_LEN + 1]

	get_user_ip(id,userip,15,1) 
	get_user_name(id,name,31)
	get_ip_description(userip, description)

	client_print(0, print_chat, "%L", LANG_PLAYER, "PLAYER_CONNECT", name, userip, description)
	
	return PLUGIN_CONTINUE
}  

public client_disconnect(id)
{
	new userip[16]
	new name[32]
	new description[MAX_DESCRIPTION_LEN + 1]

	get_user_ip(id,userip,15,1) 
	get_user_name(id,name,31)
	get_ip_description(userip, description)

	client_print(0, print_chat, "%L", LANG_PLAYER, "PLAYER_DISCONNECT", name, userip, description)
	
	return PLUGIN_CONTINUE
} 

/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/