/* Clan Tag Check Plugin Version 2
* I added a feature that makes it so you don't have to
* recompile this every time you add a WONID
* it comes with a file called WONID.CFG
* you just put all the WONID's in there
* Checks every person in the server to see if they are in
* Your clan if they are using the tag
* You have to modify this a little bit for your clan
* I commented most of the stuff
* Look at the comments for what you need to edit
* Please if you edit this give me SOME credit
* I mean other than the necessary changes
* Thanks to all -9mm- for this plugin idea
* Thanks to Greg for help testing it
* Thanks to Sarah for help testing it
* Thanks to Superplatypuss for the idea of external WONID's
* Copyright Chris (-9mm- Incubus) 2002
*/
 
/* Should be comaptible with AuthIDs now, untested, [WING] Black Knight */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
 
/* ALL MODIFICATIONS ARE MADE RIGHT HERE */
 
/* REQUIRED CHANGE */
new ClanTag1[MAX_DATA_LENGTH] = "-9mm-"; /* change to your clans tag */
 
/* OPTIONAL CHANGE */
#define AUTO_KICK 1; /* change to 0 if you don't want it to automatically check */
new SpeakGoodbye[MAX_DATA_LENGTH] = "speak ^"you are unauthorized personnel, goodbye ass hole^""; /* this is the string the HL voice guy speaks, change to whatever in between the ^" */
 
/* END OF MODIFICATIONS! */
 
 
new FILENAME[MAX_DATA_LENGTH] = "AUTHID.CFG";
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.1";
new DEBUG = 0;
 
/* THIS IS WHERE YOU PUT IN YOUR WONID'S */
InClan(sAuthID[])
{
	new i = 0;
	new temp[MAX_DATA_LENGTH];
	new NUM_MEMBERS = 0;
	for(i = 1; i <= 100; i++)
	{
		readfile(FILENAME, temp, i + 1, MAX_DATA_LENGTH);
		if(streq(temp, "") != 1)
			NUM_MEMBERS++;
		if(streq(temp, "") == 1)
			break;
	}
	for(i = 1; i <= NUM_MEMBERS; i++)
	{
		readfile(FILENAME,temp,i,MAX_DATA_LENGTH);
		if (streq(temp, ""))
		{
			return(0); /* there are no more WONID's and user isn't in clan*/
		}
		if(streq(sAuthID,temp))
		{
			return(1); /* return 1 if they are in clan */
		}
	}
	return(0); /* return 0 if they aren't in the clan */
}
 
findstr(str1[], str2[])
{
	new i = 0;
	new j = 0;
	new len1;
	new len2;
 
	len1 = strlen(str1);	// Length of source string
	len2 = strlen(str2);	// Length of string we're searching for
 
	// Step through str1
	for (j=0; j<len1; j++)
	{
		// If the current letter of str2 is the same as the current letter of str1
		while (str1[j+i] == str2[i])
		{
			i++;
			// If we are at the end of str2, then success!
			if (i == len2)
				return j+1;
			// If we get to the end of str1, but not end of str2, then fail.
			else if (len1 == j+i)
				return 0;
		}
 
		// Re-initialize i to zero for next time around
		i = 0;
	}
	// If we don't find anything, and we get to the end, then return 0
	return 0;
}
 
public AutoTagCheck() /* this is for the auto tag check feature */
{
	exec("admin_tagcheck"); /* execute the kick function */
	return PLUGIN_HANDLED;
}
 
public TagCheck(HLCommand,HLData,HLUserName,UserIndex) /* this is the actual testing and kicking function */
{
	new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new maxplayers = maxplayercount();
	new Target[MAX_NAME_LENGTH];
	new i = 0;
	new SessionID;
	new WONID;
	new Team;
	new Dead;
	new imp_message[MAX_DATA_LENGTH] = " is an imposter and was booted!";
	new temp[MAX_DATA_LENGTH] = "You aren't ";
	new temp2[MAX_DATA_LENGTH];
	new sAuthID1[MAX_AUTHID_LENGTH];
	new sAuthID2[MAX_AUTHID_LENGTH];
 
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
	for(i=1; i<=maxplayers; i++)
	{
		if(playerinfo(i, Target, MAX_NAME_LENGTH, SessionID, WONID, Team) == 1)
		{
			playerinfo(i, Target, MAX_NAME_LENGTH, SessionID, WONID, Team, Dead, sAuthID1);
			if (DEBUG == 1)
				selfmessage(Target);
			InClan(sAuthID2);
			if ((findstr(Target, ClanTag1) > 0) && (!streq(sAuthID1,sAuthID2)))
			{
				if((check_immunity(Target)==0) && (i != UserIndex))
				{
					execclient(Target, SpeakGoodbye); /* speaks the message, this is funny lol */
					strcat(temp, ClanTag1, MAX_DATA_LENGTH);
					temp2 = temp;
					strcat(temp2, ", change tag and then come back", MAX_DATA_LENGTH);
					message(Target, temp2); /* change this to your clan's tag */
					strcat(temp, imp_message, MAX_DATA_LENGTH);
					typesay(temp, 10, 255, 255, 255);
					kick(Target); /* kick em */
				}
			}
		}
	}
	return PLUGIN_HANDLED;
}
 
public plugin_init()
{
	plugin_registerinfo("Clan Tag Check","Makes it so if you don't have a clan wonid, you get booted for having clan tag", STRING_VERSION); /* register the info blah blah blah */
	plugin_registercmd("admin_tagcheck","TagCheck",ACCESS_IMMUNITY); /* register the command admin_tagcheck for manual use */
	plugin_registercmd("name", "TagCheck", ACCESS_ALL); /* checks as soon as a name is changed */
	plugin_registerhelp("admin_tagcheck",ACCESS_IMMUNITY,"admin_tagcheck: turns on or off clan tag checking"); /* just used for admin_help */
	#if AUTO_KICK == 1
		set_timer("AutoTagCheck", 30, 99999);
	#endif
	return PLUGIN_CONTINUE;
}