/***************************************************************************
 * plugin_sank_chatmode.sma
 * Author: Luke Sankey
 * Date: March 31, 2001
 * Last Updated: July 9, 2001
 *
 * This plugin allows the user to bind different keys to do special says
 * easily without having to bring down the console.
 ***************************************************************************/
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.e";
 
// Flag for whether or not to intercept next say
new WatchSay[MAX_PLAYERS] = {0,...};
// 0 means dont intercept next say
// 1 means intercept next as admin_chat
// 2 means intercept next as rcon say
// 3 means intercept next as admin_say
// 4 means intercept next as admin_csay
// 5 means intercept next as admin_rsay
// 6 means intercept next as admin_ssay
// 7 means intercept next as admin_tsay
 
 
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
 
 
public plugin_init() 
{
	plugin_registerinfo("Sank Chat-Mode Plugin", "Enables special chat key binding.", STRING_VERSION);
 
	plugin_registercmd("admin_chatmode", "admin_chatmode", ACCESS_SAY, "admin_chatmode: Takes the next chat message and makes it an admin_chat message.");
	plugin_registercmd("admin_rconmode", "admin_rconmode", ACCESS_RCON, "admin_rconmode: Takes the next chat message and makes it an rcon say message.");
	plugin_registercmd("admin_saymode",  "admin_saymode",  ACCESS_SAY, "admin_saymode:  Takes the next chat message and makes it an admin_say message.");
	plugin_registercmd("admin_csaymode", "admin_csaymode", ACCESS_SAY, "admin_csaymode: Takes the next chat message and makes it an admin_csay message.");
	plugin_registercmd("admin_rsaymode", "admin_rsaymode", ACCESS_SAY, "admin_rsaymode: Takes the next chat message and makes it an admin_rsay message.");
	plugin_registercmd("admin_rsaymode", "admin_ssaymode", ACCESS_SAY, "admin_ssaymode: Takes the next chat message and makes it an admin_ssay message.");
	plugin_registercmd("admin_tsaymode", "admin_tsaymode", ACCESS_SAY, "admin_tsaymode: Takes the next chat message and makes it an admin_tsay message.");
	plugin_registercmd("say", "HandleSay", ACCESS_ALL);
 
	return PLUGIN_CONTINUE;
}
 
public plugin_connect(HLUserName, HLIP, UserIndex) 
{
	if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS)
	{
		WatchSay[UserIndex] = 0;
	}
	return PLUGIN_CONTINUE;
}
 
public plugin_disconnect(HLUserName, UserIndex) 
{
	if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS)
	{
		WatchSay[UserIndex] = 0;
	}
	return PLUGIN_CONTINUE;
}
 
 
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
 
 
///////////////////////////////////////////////////////////////////////////////
// Use the admin_chat command without having to use the console.
//
// Usage: bind a key to "admin_chatmode"
///////////////////////////////////////////////////////////////////////////////
public admin_chatmode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 1;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
///////////////////////////////////////////////////////////////////////////////
// Do an rcon say command without having to use the console.
//
// Usage: bind a key to "admin_rconmode"
///////////////////////////////////////////////////////////////////////////////
public admin_rconmode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 2;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
///////////////////////////////////////////////////////////////////////////////
// Use the admin_say command without having to use the console.
//
// Usage: bind a key to "admin_saymode"
///////////////////////////////////////////////////////////////////////////////
public admin_saymode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 3;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
///////////////////////////////////////////////////////////////////////////////
// Use the admin_csay command without having to use the console.
//
// Usage: bind a key to "admin_csaymode"
///////////////////////////////////////////////////////////////////////////////
public admin_csaymode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 4;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
///////////////////////////////////////////////////////////////////////////////
// Use the admin_rsay command without having to use the console.
//
// Usage: bind a key to "admin_rsaymode"
///////////////////////////////////////////////////////////////////////////////
public admin_rsaymode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 5;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
///////////////////////////////////////////////////////////////////////////////
// Use the admin_ssay command without having to use the console.
//
// Usage: bind a key to "admin_ssaymode"
///////////////////////////////////////////////////////////////////////////////
public admin_ssaymode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 6;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
///////////////////////////////////////////////////////////////////////////////
// Use the admin_tsay command without having to use the console.
//
// Usage: bind a key to "admin_tsaymode"
///////////////////////////////////////////////////////////////////////////////
public admin_tsaymode(HLCommand, HLData, HLUserName, UserIndex) 
{
	new User[MAX_NAME_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	WatchSay[UserIndex] = 7;
	execclient(User, "messagemode");
 
	return PLUGIN_HANDLED;
}
 
 
//////////////////////////////////////////////////////////////////////////////
// Everything a person says goes through here, and we determine if they want
// us to treat their say as something special or just let them say as normal.
//
// Usage: say <something>
//////////////////////////////////////////////////////////////////////////////
public HandleSay(HLCommand, HLData, HLUserName, UserIndex) 
{
	new Command[MAX_COMMAND_LENGTH];
	new Speech[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	convert_string(HLCommand, Command, MAX_COMMAND_LENGTH);
	convert_string(HLData, Speech, MAX_DATA_LENGTH);
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	strstripquotes(Speech);
 
	switch(WatchSay[UserIndex])
	{
		case 1:
			plugin_exec("admin_chat", Speech);
		case 2:
		{
			snprintf(Text, MAX_TEXT_LENGTH, "say ^"%s^"", Speech);
			exec(Text);
		}
		case 3:
			plugin_exec("admin_say",  Speech);
		case 4:
			plugin_exec("admin_csay", Speech);
		case 5:
			plugin_exec("admin_rsay", Speech);
		case 6:
			plugin_exec("admin_ssay", Speech);
		case 7:
			plugin_exec("admin_tsay", Speech);
		default:
		{
			WatchSay[UserIndex] = 0;
			return PLUGIN_CONTINUE;
		}
	}
 
	WatchSay[UserIndex] = 0;
	return PLUGIN_HANDLED;
}