/* Reformats command to replace $user with username of whoever you're looking at, script by [WHO]Them */
 
/* $Id: plugin_seeuser.sma,v 1.5 2001/07/12 19:11:12 [WHO]Them Exp $ */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "1.1";
 
public admin_seeuser(HLCommand,HLData,HLUserName,UserIndex) {
        new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new i;
	new j;
        new targetwonid;
        new targetsession;
        new targetnumber;
        new targetteam;
        new targetdead;
        new numstring[MAX_DATA_LENGTH];
        new actualcommand[MAX_DATA_LENGTH];
        new newdata[MAX_DATA_LENGTH + 16];
	new targetname[MAX_NAME_LENGTH];
	new User[MAX_NAME_LENGTH];
	new newcommand[MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 16];
	new sAuthID[MAX_AUTHID_LENGTH];
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
        i = 0;
        //gettarget(User, targetname, MAX_NAME_LENGTH);
        targetnumber = pointto();
        numtostr(targetnumber, numstring);
        get_username(numstring,targetname,MAX_NAME_LENGTH);
        get_userindex(targetname,targetnumber);
        if(targetnumber < 1) {
                messageex(User, "ERROR *** Invalid Target *** ERROR", print_chat);
                return PLUGIN_HANDLED;
        }
        playerinfo(targetnumber, targetname, MAX_NAME_LENGTH, targetsession, targetwonid, targetteam, targetdead, sAuthID);
        i=0;
	for(j=0; i<=MAX_DATA_LENGTH;) {
		if(Data[i]=='$') {
			if((tolower(Data[i+1]) == 'u') && (tolower(Data[i+2]) == 's') && (tolower(Data[i+3]) == 'e') && (tolower(Data[i+4]) == 'r')) {
				strcat( newcommand, targetname, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 's') && (tolower(Data[i+2]) == 'l') && (tolower(Data[i+3]) == 'o') && (tolower(Data[i+4]) == 't')) {
				numtostr(targetnumber, numstring);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 't') && (tolower(Data[i+2]) == 'e') && (tolower(Data[i+3]) == 'a') && (tolower(Data[i+4]) == 'm')) {
				if(targetteam == 2) strcpy(numstring, "Counter-Terrorist", MAX_DATA_LENGTH);
                                else strcpy(numstring, "Terrorist", MAX_DATA_LENGTH);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 'd') && (tolower(Data[i+2]) == 'e') && (tolower(Data[i+3]) == 'a') && (tolower(Data[i+4]) == 'd')) {
				if(targetdead == 1) strcpy(numstring, "DEAD", MAX_DATA_LENGTH);
                                else strcpy(numstring, "ALIVE", MAX_DATA_LENGTH);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 'w') && (tolower(Data[i+2]) == 'o') && (tolower(Data[i+3]) == 'n') && (tolower(Data[i+4]) == 'i') && (tolower(Data[i+5]) == 'd')) {
				strcpy(numstring,sAuthID,MAX_AUTHID_LENGTH);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 6;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 's') && (tolower(Data[i+2]) == 'e') && (tolower(Data[i+3]) == 's') && (tolower(Data[i+4]) == 'i') && (tolower(Data[i+5]) == 'd')) {
                                numtostr(targetsession, numstring);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 6;
				j = strlen(newcommand);
			}
		}
		newcommand[j] = Data[i];
		i=i+1;
		j=j+1;
                newcommand[j] = '^0';
	}
        strbreak(newcommand, actualcommand, newdata, MAX_DATA_LENGTH + MAX_NAME_LENGTH + 16);
        message(User, newcommand);
        if((tolower(actualcommand[0]) == 'a') && (tolower(actualcommand[1]) == 'd') && (tolower(actualcommand[2]) == 'm') && (tolower(actualcommand[3]) == 'i') && (tolower(actualcommand[4]) == 'n')) {
        	plugin_exec(actualcommand, newdata);
        } else {
                execclient(User, newcommand);
        }
	return PLUGIN_HANDLED;
}
 
public admin_lockuser(HLCommand,HLData,HLUserName,UserIndex) {
        new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
        new targetwonid;
        new targetsession;
        new targetnumber;
        new targetteam;
        new targetdead;
        new numstring[MAX_DATA_LENGTH];
	new targetname[MAX_NAME_LENGTH];
	new User[MAX_NAME_LENGTH];
	new newcommand[MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 16];
	new sAuthID[MAX_AUTHID_LENGTH];
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
        //gettarget(User, targetname, MAX_NAME_LENGTH);
        targetnumber = pointto();
        numtostr(targetnumber, numstring);
        get_username(numstring,targetname,MAX_NAME_LENGTH);
        get_userindex(targetname,targetnumber);
        if(targetnumber < 1) {
                messageex(User, "ERROR *** Invalid Target *** ERROR", print_chat);
                return PLUGIN_HANDLED;
        }
        strcpy(newcommand, "setinfo lockeduser ", MAX_DATA_LENGTH);
        strcat(newcommand, numstring, MAX_DATA_LENGTH);
        playerinfo(targetnumber, targetname, MAX_NAME_LENGTH, targetsession, targetwonid, targetteam, targetdead, sAuthID);
        execclient(User, newcommand);
        strcpy(newcommand, "User: ", MAX_DATA_LENGTH);
        strcat(newcommand, targetname, MAX_DATA_LENGTH);
        strcat(newcommand, " selected", MAX_DATA_LENGTH);
        messageex(User, newcommand, print_chat);
	return PLUGIN_HANDLED;
}
 
public admin_lockeduser(HLCommand,HLData,HLUserName,UserIndex) {
        new Command[MAX_COMMAND_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new i;
	new j;
        new targetwonid;
        new targetsession;
        new targetnumber;
        new targetteam;
        new targetdead;
        new numstring[MAX_DATA_LENGTH];
        new actualcommand[MAX_DATA_LENGTH];
        new newdata[MAX_DATA_LENGTH + 16];
	new targetname[MAX_NAME_LENGTH];
	new User[MAX_NAME_LENGTH];
	new newcommand[MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 16];
	new sAuthID[MAX_AUTHID_LENGTH];
	convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_NAME_LENGTH);
        i = 0;
        get_userinfo(User,"lockeduser",numstring,MAX_DATA_LENGTH);
 
        //gettarget(User, targetname, MAX_NAME_LENGTH);
        //targetnumber = pointto();
        //numtostr(targetnumber, numstring);
        get_username(numstring,targetname,MAX_NAME_LENGTH);
        get_userindex(targetname,targetnumber);
        if(targetnumber < 1) {
                messageex(User, "ERROR *** Invalid Target *** ERROR", print_chat);
                return PLUGIN_HANDLED;
        }
        playerinfo(targetnumber, targetname, MAX_NAME_LENGTH, targetsession, targetwonid, targetteam, targetdead, sAuthID);
        i=0;
	for(j=0; i<=MAX_DATA_LENGTH;) {
		if(Data[i]=='$') {
			if((tolower(Data[i+1]) == 'u') && (tolower(Data[i+2]) == 's') && (tolower(Data[i+3]) == 'e') && (tolower(Data[i+4]) == 'r')) {
				strcat( newcommand, targetname, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 's') && (tolower(Data[i+2]) == 'l') && (tolower(Data[i+3]) == 'o') && (tolower(Data[i+4]) == 't')) {
				numtostr(targetnumber, numstring);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 't') && (tolower(Data[i+2]) == 'e') && (tolower(Data[i+3]) == 'a') && (tolower(Data[i+4]) == 'm')) {
				if(targetteam == 2) strcpy(numstring, "Counter-Terrorist", MAX_DATA_LENGTH);
                                else strcpy(numstring, "Terrorist", MAX_DATA_LENGTH);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 'd') && (tolower(Data[i+2]) == 'e') && (tolower(Data[i+3]) == 'a') && (tolower(Data[i+4]) == 'd')) {
				if(targetdead == 1) strcpy(numstring, "DEAD", MAX_DATA_LENGTH);
                                else strcpy(numstring, "ALIVE", MAX_DATA_LENGTH);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 5;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 'w') && (tolower(Data[i+2]) == 'o') && (tolower(Data[i+3]) == 'n') && (tolower(Data[i+4]) == 'i') && (tolower(Data[i+5]) == 'd')) {
				strcpy(numstring,	sAuthID, MAX_AUTHID_LENGTH);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 6;
				j = strlen(newcommand);
			}
                        else if((tolower(Data[i+1]) == 's') && (tolower(Data[i+2]) == 'e') && (tolower(Data[i+3]) == 's') && (tolower(Data[i+4]) == 'i') && (tolower(Data[i+5]) == 'd')) {
                                numtostr(targetsession, numstring);
				strcat( newcommand, numstring, (MAX_DATA_LENGTH + MAX_COMMAND_LENGTH + 2));
				i = i + 6;
				j = strlen(newcommand);
			}
		}
		newcommand[j] = Data[i];
		i=i+1;
		j=j+1;
                newcommand[j] = '^0';
	}
        strbreak(newcommand, actualcommand, newdata, MAX_DATA_LENGTH + MAX_NAME_LENGTH + 16);
        message(User, newcommand);
        if((tolower(actualcommand[0]) == 'a') && (tolower(actualcommand[1]) == 'd') && (tolower(actualcommand[2]) == 'm') && (tolower(actualcommand[3]) == 'i') && (tolower(actualcommand[4]) == 'n')) {
        	plugin_exec(actualcommand, newdata);
        } else {
                execclient(User, newcommand);
        }
	return PLUGIN_HANDLED;
}
 
public plugin_init() {
	plugin_registerinfo("[WHO]Them's seeuser plugin","Reformats a commands to include variable data",STRING_VERSION);
	plugin_registercmd("admin_seeuser","admin_seeuser",ACCESS_ALL,"admin_seeuser <command>: replaces $user,$slot,$wonid,$sesid,$team, and $dead with info of who you're pointing at");
        plugin_registercmd("admin_lockeduser","admin_lockeduser",ACCESS_ALL,"admin_lockeduser <command>: replaces $user,$slot,$wonid,$sesid,$team, and $dead with info of who you're pointing at");
        plugin_registercmd("admin_lockuser","admin_lockuser",ACCESS_ALL,"admin_lockuser <command>: locks admin_lockeduser onto whoever you're looking at");
	return PLUGIN_CONTINUE;
}