// plugin_ragman_acm 
// AdminConnectMessage
// Written by ||RAGMAN||
// Internet: http://ragman.pest-clan.de
// eMail: ragman@pest-clan.de
//
// vault.ini einträge
// ACM_Enabled 1
// ACM_AdminLevel 61891
 
#include <core>
#include <console>
#include <string>
#include <plugin>
#include <admin>
#include <adminlib>
 
#define ACCESS_SPEAK 64
new STRING_VERSION[MAX_DATA_LENGTH] = "1.0 by ||RAGMAN||";
 
new Message[MAX_TEXT_LENGTH];
new SpeakConnect[MAX_DATA_LENGTH];
new Speak[MAX_DATA_LENGTH];
new SessionID;
new Target[MAX_NAME_LENGTH];
new Team;
new WONID;
new Data[MAX_DATA_LENGTH];
 
new g_ACM_SpeakMessage[100];
new g_ACM_AdminConnectMessage[100];
 
new g_ACM_Enabled;
new g_ACM_AdminLevel;
 
stock LoadConfiguration() 
{
	new sVaultData[MAX_DATA_LENGTH];
	new VaultData[MAX_DATA_LENGTH];
 
	if(get_vaultdata("ACM_Enabled", sVaultData, MAX_DATA_LENGTH ) != 0)
	{
		g_ACM_Enabled = check_param(sVaultData);
	}
	else
	{
		g_ACM_Enabled = 1;
		snprintf(VaultData, MAX_DATA_LENGTH, "%d", g_ACM_Enabled);
		set_vaultdata("ACM_Enabled", VaultData);
	}
	if(get_vaultdata("ACM_AdminLevel", sVaultData, MAX_DATA_LENGTH ) != 0)
	{
		g_ACM_AdminLevel = strtonum(sVaultData);
	}
	else
	{
		g_ACM_AdminLevel = 65536;
		snprintf(VaultData, MAX_DATA_LENGTH, "%d", g_ACM_AdminLevel);
		set_vaultdata("ACM_AdminLevel", VaultData);
	}
 
 
	if(get_vaultdata("ACM_SpeakMessage",g_ACM_SpeakMessage ,100) == 0)
	{
		strcpy(g_ACM_SpeakMessage ,"message from administration",100);
		set_vaultdata("ACM_SpeakMessage",g_ACM_SpeakMessage );
	}
	if(get_vaultdata("ACM_AdminConnectMessage",g_ACM_AdminConnectMessage ,100) == 0)
	{
		strcpy(g_ACM_AdminConnectMessage ,"a user with access is authorized",100);
		set_vaultdata("ACM_AdminConnectMessage",g_ACM_AdminConnectMessage );
	}
 
	exec( "[RAGMAN ACM] Plugin loaded successfully" );
	selfmessage( "[RAGMAN ACM] Plugin loaded successfully" );
}
 
public admin_acm_csay(HLCommand, HLData, HLUserName, UserIndex) 
{
	new i;
	new maxplayers = maxplayercount();
 
	convert_string(HLData, Data, MAX_DATA_LENGTH);
	strcpy(Message,Data,MAX_TEXT_LENGTH);
 
	strsubst(g_ACM_SpeakMessage," ( ","(",MAX_DATA_LENGTH);
	strsubst(g_ACM_SpeakMessage," )",")",MAX_DATA_LENGTH);
	snprintf(Speak, MAX_DATA_LENGTH, "speak ^"%s^"", g_ACM_SpeakMessage);
 
	for(i=1; i<=maxplayers; i++)
	{
		strinit(Target);
		if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1)
		{
			execclient(Target,Speak);
		}
	}
	set_timer("say_centermessage",2,0);
}
 
public admin_acm_tsay(HLCommand, HLData, HLUserName, UserIndex) 
{
	new i;
	new maxplayers = maxplayercount();
 
	convert_string(HLData, Data, MAX_DATA_LENGTH);
	strcpy(Message,Data,MAX_TEXT_LENGTH);
 
	strsubst(g_ACM_SpeakMessage," ( ","(",MAX_DATA_LENGTH);
	strsubst(g_ACM_SpeakMessage," )",")",MAX_DATA_LENGTH);
	snprintf(Speak, MAX_DATA_LENGTH, "speak ^"%s^"", g_ACM_SpeakMessage);
 
	for(i=1; i<=maxplayers; i++)
	{
		strinit(Target);
		if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1)
		{
			execclient(Target,Speak);
		}
	}
	set_timer("say_typemessage",2,0);
}
 
public plugin_connect(HLUserName, HLIP, UserIndex)
{
	if (!g_ACM_Enabled)
		return PLUGIN_CONTINUE;
 
	new sName[MAX_NAME_LENGTH];
	new i;
	new maxplayers = maxplayercount();
 
	convert_string(HLUserName, sName, MAX_NAME_LENGTH);
 	if (check_auth(g_ACM_AdminLevel))
	{
		strsubst(g_ACM_AdminConnectMessage," ( ","(",MAX_DATA_LENGTH);
		strsubst(g_ACM_AdminConnectMessage," )",")",MAX_DATA_LENGTH);
		snprintf(SpeakConnect, MAX_DATA_LENGTH, "speak ^"%s^"", g_ACM_AdminConnectMessage); 
		for(i=1; i<=maxplayers; i++)
		{
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1)
			{
				execclient(Target,SpeakConnect);
			}
		}
		set_timer("say_centermessage",2,0);
		snprintf( Message, MAX_TEXT_LENGTH, "%s have a admin access^nand joined this server.", sName );
	}
	return PLUGIN_HANDLED;
}
 
public say_typemessage()
{
	//red
	typesay( Message, 10, 250, 10, 10 );
}
 
public say_centermessage()
{
	//red
	centersay( Message, 10, 250, 10, 10 );
}
 
public admin_acm_help() 
{
	selfmessage( " " );
	selfmessage( " " );
	selfmessage( " " );
	selfmessage( "[RAGMAN ACM] ||RAGMAN||s AdminConnectMessage Plugin" );
	snprintf( Message, MAX_TEXT_LENGTH, "[RAGMAN ACM] PluginVersion v%s", STRING_VERSION );
	selfmessage( Message );
	selfmessage( "[RAGMAN ACM] ---------------------------------------------------" );
 
	if (!g_ACM_Enabled)
	{
		selfmessage( "[RAGMAN ACM] AdminConnectMessage is OFF" );
		selfmessage( "[RAGMAN ACM] write in the vault.ini: ACM_Enabled 1" );
	}
	else
	{
		selfmessage( "[RAGMAN ACM] AdminConnectMessage is ON" );
		snprintf( Message, MAX_TEXT_LENGTH, "[RAGMAN ACM] ACM_AdminLevel: %i", g_ACM_AdminLevel );
		selfmessage( Message );
	}
	selfmessage( "[RAGMAN ACM] admin_acm_tsay <msg>: Play the Sound ACM_SpeakMessage an gives the <msg> as type message" );
	selfmessage( "[RAGMAN ACM] admin_acm_csay <msg>: Play the Sound ACM_SpeakMessage an gives the <msg> as center message" );
	selfmessage( "[RAGMAN ACM] admin_acm_help: this page" );
	selfmessage( "[RAGMAN ACM] ---------------------------------------------------" );
	selfmessage( "[RAGMAN ACM] vault.ini settings" );
	selfmessage( "[RAGMAN ACM] ACM_Enabled - AdminConnectMessage is on|off (default is 1) " );
	selfmessage( "[RAGMAN ACM] ACM_AdminLevel - AdminLevel for see the ConnectMessage (default is 65536) " );
	selfmessage( "[RAGMAN ACM] ACM_SpeakMessage - the speak message for admin_acm_tsay and admin_acm_csay (default is ^"message from administration^") " );
	selfmessage( "[RAGMAN ACM] ACM_AdminConnectMessage - the speak message for AdminConnect (default is ^"a user with access is authorized^") " );
	selfmessage( "[RAGMAN ACM] ---------------------------------------------------" );
	selfmessage( "[RAGMAN ACM] the speak words for HL, can you read here:" );
	selfmessage( "[RAGMAN ACM] http://www.adminmod.org/manual/Admin_Mod_Reference/Half_Life_Sounds.htm" );
	selfmessage( "[RAGMAN ACM] ---------------------------------------------------" );
	selfmessage( "[RAGMAN ACM] written by ||RAGMAN||" );
	selfmessage( "[RAGMAN ACM] Internet: http://ragman.pest-clan.de" );
	selfmessage( "[RAGMAN ACM] eMail: ragman@pest-clan.de" );
	selfmessage( " " );
	selfmessage( " " );
	selfmessage( " " );
}
 
public plugin_init() {
	plugin_registerinfo("||RAGMAN||s AdminConnectMessage","Plays a sound and gives a message, if an admin connect the server.",STRING_VERSION);
 
	plugin_registercmd("admin_acm_tsay","admin_acm_tsay",ACCESS_SPEAK,"admin_acm_tsay <msg>: Speak message from administration and give a typemessage.");
	plugin_registercmd("admin_acm_csay","admin_acm_csay",ACCESS_SPEAK,"admin_acm_csay <msg>: Speak message from administration and give a centermessage.");
	plugin_registercmd("admin_acm_help","admin_acm_help",ACCESS_ALL,"admin_acm_help: Settings and Informationen from the RAGMAN ACM Plugin.");
 
	LoadConfiguration();
	return PLUGIN_CONTINUE;
}