/*
	Makes people without C-D (http://www.unitedadmins.com/) glow the color of
	their team. Requires StatsMe or LogD.
 
	This plugin is designed for Counter-Strike but may work with other mods StatsMe or LogD
	forwards the "RoundStart" event from.
 
	The default message can easily be overriden by putting CDGLOW_MSG1, CDGLOW_MSG2
	CDGLOW_MSG3 and CDGLOW_MSG4 with any value in addons/adminmod/config/vault.ini.
*/
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[] = "1.0";
new Msg1[MAX_TEXT_LENGTH];
new Msg2[MAX_TEXT_LENGTH];
new Msg3[MAX_TEXT_LENGTH];
new Msg4[MAX_TEXT_LENGTH];
 
public cdroundstart(HLCommand,HLData,HLUserName,UserIndex) {
	new maxplayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
	new i = 0;
	new SessionID;
	new Wonid;
	new Team;
	new Dead;
	new sAuthID[MAX_AUTHID_LENGTH];
 
 
	for(i=1; i<=maxplayers; i++) {
		if(playerinfo(i,Name,MAX_NAME_LENGTH,SessionID,Wonid,Team,Dead,sAuthID) == 1 && Dead == 0) {
			if(strmatch(sAuthID,"STEAM_",6)==1 && (Team == 1 || Team == 2)) {
				/*
					I know its possible to make a "real" check by requesting status with a command
					but it would require me to make arrays for the players and reset them when a player
					leave and so on.. I doubt its worth it compared to this.
				*/
				if(((strmatch(Name,"[No C-D]",8) == 1) || (strmatch(Name,"[Old C-D]",9) == 1)) && strmatch(Name,"Chicken #",9 == 0)) {
					if (Team == 1) {
						glow(Name,250,10,10);
					}
					else {
						glow(Name,10,10,250);
					}
					if (strlen(Msg1) > 0) {
						messageex(Name,Msg1,print_chat);
					}
					if (strlen(Msg2) > 0) {
						messageex(Name,Msg2,print_chat);
					}
					if (strlen(Msg3) > 0) {
						messageex(Name,Msg3,print_chat);
					}
					if (strlen(Msg4) > 0) {
						messageex(Name,Msg4,print_chat);
					}
				}
			}
		}
	}
	return PLUGIN_HANDLED;
}
 
UpdateMsg() {
	new sFile[MAX_DATA_LENGTH];
	getstrvar("admin_vault_file",sFile,MAX_DATA_LENGTH);
 
	if (fileexists(sFile) == 0) {
		log("vault not found");
		return PLUGIN_CONTINUE;
	}
	get_vaultdata("CDGLOW_MSG1",Msg1,MAX_TEXT_LENGTH);
	get_vaultdata("CDGLOW_MSG2",Msg2,MAX_TEXT_LENGTH);
	get_vaultdata("CDGLOW_MSG3",Msg3,MAX_TEXT_LENGTH);
	get_vaultdata("CDGLOW_MSG4",Msg4,MAX_TEXT_LENGTH);
 
 
	return PLUGIN_CONTINUE;
}
 
public plugin_init() {
	plugin_registerinfo("No-CD Glow Plugin","Makes players without or with an old version of Cheating-Death glow their team color.",STRING_VERSION);
	plugin_registercmd("admin_cdroundstart","cdroundstart",131072,"");
 
	if(cvar_exists("logd_version")) {
		exec("logd_reg 62 admin_command admin_cdroundstart");
	}
	else {
		exec("sm_reg SM_RoundStart ^"admin_command admin_cdroundstart^" bdc");
	}
 
	snprintf(Msg1,MAX_TEXT_LENGTH,"[CD CONTROL] You are now glowing because you have not been Cheating-Death authenticated!");
	snprintf(Msg2,MAX_TEXT_LENGTH,"[CD CONTROL] Get Cheating-Death free at http://www.unitedadmins.com/cdeath.php");
	snprintf(Msg3,MAX_TEXT_LENGTH,"");
	snprintf(Msg4,MAX_TEXT_LENGTH,"");
 
	UpdateMsg();
 
	return PLUGIN_CONTINUE;
}