/* -TAG:LICENSE-
   
   This file is under the DigitalSpark Freeware Class License, see the
   file LICENSE for complete licensing information.
                                                         
                                                         -TAG:LICENSE- */
#include <Threading.h>
#include <Strings.h>
#include "tricky.h"

extern  size_t  Write( int slot, void *data, size_t size );
extern	void	IRCNotice( int Sock, char *type, char *message );

int	Command( char *command )
{
char	buff[1024];
char	outbuff[1024];
int	caught=0;
int	i=0,k=0;
char	*CommandWord;

CommandWord = PullToken(command,' ',1);

/* RAW/QUOTE command (useful for issuing a server QUIT, etc */
if (( strcmp("RAW",CommandWord) == 0 ) || ( strcmp("QUOTE",CommandWord) == 0 ))
   {
   while (( command[i] != 0 ) && ( k < 2 ))
      {
      if ( command[i] == ' ' )
         k++;
      i++;
      }
   k=0;
   while ( command[i] != 0 )
      {
      buff[k] = command[i];
      k++;
      i++;
      }
   buff[k] = command[i];
   Error(0,buff);
   sprintf(outbuff,"%s\r\n",buff);
   Write(ServerSock,outbuff,0);
   caught=1;
   }

/* Make the arbiter exit, this is TERM and not QUIT on purpose */
if ( strcmp("TERM",PullToken(command,' ',1)) == 0 )
   {
   cBusBroadcast("NOTICE %s :*** AUTH [TrickyIRC] TERM command caught\r\n",0);
   Error(0,"TERM command caught.");
   Write(ServerSock,"QUIT :Leaving\r\n",0);
   //sleep(1);
   exit(0);
   caught=1;
   }


if ( caught == 0 )
   cBusBroadcast("NOTICE %s :*** AUTH [TrickyIRC] Unknown command\r\n",0);

free(CommandWord);

/* Returning -1 causes it not to be sent on to the IRC Server */
return -1;
}
