/* This plugin allows users to do IRC type actions by typing me first. */
/* Special thanks to Sank for really teaching me how to do this, and yensid for some ideas =) */
/* Thanks to Admin Mod team for making an EXCELLENT utility for us server admins. */
/* $Id: plugin_ircaction_cs.sma,v 1.0 2001/04/13 greider Exp $ */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
ProcessAction(User[],UserIndex,Data[])
{
	new i;
	new iTeam;
	new maxplayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
	new SessionID;
	new WONID;
	new UserDead;
	new ListenDead;
	new Text[MAX_TEXT_LENGTH];
 
	snprintf(Text, MAX_TEXT_LENGTH, "%s %s", User, Data);
 
	if (playerinfo(UserIndex, Name, MAX_NAME_LENGTH, SessionID, WONID, iTeam, UserDead))
	{
		for(i=1; i<=maxplayers; i++)
		{
			if(playerinfo(i, Name, MAX_NAME_LENGTH, SessionID, WONID, iTeam, ListenDead))
			{
				/* Find out if target's status is same as User, if so, print it. */
				if (UserDead == ListenDead)
				{
					messageex(Name, Text, print_chat);
				}
			}
		}
	}
}
 
public HandleSay(HLCommand, HLData, HLUserName, UserIndex) 
{
	new i;
	new Length;
	new User[MAX_NAME_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new strAction[MAX_DATA_LENGTH];
 
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_DATA_LENGTH);
	strstripquotes(Data);
	Length = strlen(Data);
	if (strmatch(Data,"me ",strlen("me "))==1)
	{
		/* we need to strip out 'me ' (3 characters */
		for(i=3;i<Length+1;i++)
			strAction[i-3] = Data[i];
		strAction[i-3] = NULL_CHAR;
		ProcessAction(User, UserIndex, strAction);
		return PLUGIN_HANDLED;
	}
	else if (strmatch(Data,"/me ",strlen("/me "))==1)
	{
		/* we need to strip out '/me ' (4 characters */
		for(i=4;i<Length+1;i++)
			strAction[i-4] = Data[i];
		strAction[i-3] = NULL_CHAR;
		ProcessAction(User, UserIndex, strAction);
		return PLUGIN_HANDLED;
	}
	return PLUGIN_CONTINUE;
}
 
public plugin_init()
{
	plugin_registerinfo("IRC Action Plugin","Converts say to IRC type actions by typing me or /me <action>.",STRING_VERSION);
	plugin_registercmd("say","HandleSay",ACCESS_ALL);
	plugin_registerhelp("say",ACCESS_ALL,"say me <action>: Converts say to IRC type actions.");
	plugin_registerhelp("say",ACCESS_ALL,"say /me <action>: Converts say to IRC type actions.");
 
	return PLUGIN_CONTINUE;
}