/************************************************************************
 *   IRC - Internet Relay Chat, include/msg.h
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Computing Center
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 1, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: msg.h,v 1.6 2001/02/10 19:00:43 jpinto Exp $
 */
#ifndef INCLUDED_msg_h
#define INCLUDED_msg_h
#ifndef INCLUDED_config_h
#include "config.h"
#endif

struct Client;

/* 
 * Message table structure 
 */
struct  Message
{
  char  *cmd;
  int   (* func)();
  unsigned int  count;                  /* number of times command used */
  int   parameters;
  char  flags;
  /* bit 0 set means that this command is allowed to be used
   * only on the average of once per 2 seconds -SRB */

  /* I could have defined other bit maps to above instead of the next two
     flags that I added. so sue me. -Dianora */

  char    allow_unregistered_use;       /* flag if this command can be
                                           used if unregistered */

  char    reset_idle;                   /* flag if this command causes
                                           idle time to be reset */
  unsigned long bytes;
};

struct MessageTree
{
  char*               final;
  struct Message*     msg;
  struct MessageTree* pointers[26];
}; 

typedef struct MessageTree MESSAGE_TREE;


#define MSG_PRIVATE  "PRIVMSG"  /* PRIV */
#define MSG_WHO      "WHO"      /* WHO  -> WHOC */
#define MSG_WHOIS    "WHOIS"    /* WHOI */
#define MSG_WHOWAS   "WHOWAS"   /* WHOW */
#define MSG_USER     "USER"     /* USER */
#define MSG_NICK     "NICK"     /* NICK */
#define MSG_SERVER   "SERVER"   /* SERV */
#define MSG_LIST     "LIST"     /* LIST */
#define MSG_TOPIC    "TOPIC"    /* TOPI */
#define MSG_INVITE   "INVITE"   /* INVI */
#define MSG_VERSION  "VERSION"  /* VERS */
#define MSG_QUIT     "QUIT"     /* QUIT */
#define MSG_SQUIT    "SQUIT"    /* SQUI */
#define MSG_KILL     "KILL"     /* KILL */
#define MSG_INFO     "INFO"     /* INFO */
#define MSG_LINKS    "LINKS"    /* LINK */
#define MSG_STATS    "STATS"    /* STAT */
#define MSG_USERS    "USERS"    /* USER -> USRS */
#define MSG_HELPSYS  "HELPSYS"  /* HELP */
#define MSG_AJUDA    "AJUDA"    /* HELP */
#define MSG_ERROR    "ERROR"    /* ERRO */
#define MSG_AWAY     "AWAY"     /* AWAY */
#define MSG_CONNECT  "CONNECT"  /* CONN */
#define MSG_PING     "PING"     /* PING */
#define MSG_PONG     "PONG"     /* PONG */
#define MSG_OPER     "OPER"     /* OPER */
#define MSG_PASS     "PASS"     /* PASS */
#define MSG_WALLOPS  "WALLOPS"  /* WALL */
#define MSG_POST     "POST"     /* POST */
#define MSG_GLOBOPS	 "GLOBOPS"	/* -> WALLOPS */
#define MSG_TIME     "TIME"     /* TIME */
#define MSG_NAMES    "NAMES"    /* NAME */
#define MSG_ADMIN    "ADMIN"    /* ADMI */
#define MSG_TRACE    "TRACE"    /* TRAC */
#define MSG_LTRACE   "LTRACE"   /* LTRA */
#define MSG_NOTICE   "NOTICE"   /* NOTI */
#define MSG_JOIN     "JOIN"     /* JOIN */
#define MSG_PART     "PART"     /* PART */
#define MSG_LUSERS   "LUSERS"   /* LUSE */
#define MSG_MOTD     "MOTD"     /* MOTD */
#define MSG_MODE     "MODE"     /* MODE */
#define MSG_KICK     "KICK"     /* KICK */
#define MSG_USERHOST "USERHOST" /* USER -> USRH */
#define MSG_ISON     "ISON"     /* ISON */
#define MSG_REHASH   "REHASH"   /* REHA */
#define MSG_RESTART  "RESTART"  /* REST */
#define MSG_CLOSE    "CLOSE"    /* CLOS */
#define MSG_SVINFO   "SVINFO"   /* SVINFO */
#define MSG_SJOIN    "SJOIN"    /* SJOIN */
#define MSG_CAPAB    "CAPAB"    /* CAPAB */
#define MSG_HASH     "HASH"     /* HASH */
#define MSG_DNS      "DNS"      /* DNS  -> DNSS */
#define MSG_KLINE    "KLINE"    /* KLINE */
#define MSG_UNDLINE  "UNDLINE"  /* UNDLINE */
#define MSG_UNDLINE  "UNDLINE"  /* UNDLINE */
#define MSG_UNKLINE  "UNKLINE"  /* UNKLINE */
#define MSG_DLINE    "DLINE"    /* DLINE */
#define MSG_HTM      "HTM"      /* HTM */
#define MSG_SET      "SET"      /* SET */
#define MSG_DCONF	 "DCONF"		/* DCONF */
#define MSG_SANOTICE	"SANOTICE"	/* SANOTICE */
#define MSG_SRNOTICE	"SRNOTICE"	/* SRNOTICE */
#define MSG_NEWMASK     "NEWMASK"       /* NEWMASK */

#define MSG_GLINE    	"GLINE"    	/* GLINE */
#define MSG_UNGLINE    "UNGLINE"    /* UNGLINE */

#define MSG_SGLINE    	"SGLINE"    /* SGLINE */
#define MSG_UNSGLINE    "UNSGLINE"	/* UNGLINE */

#define MSG_SVLINE    	"SVLINE"    /* SVLINE */
#define MSG_UNSVLINE    "UNSVLINE"	/* UNSVLINE */

#define MSG_ZLINE    	"ZLINE"    	/* ZLINE */
#define MSG_UNZLINE    	"UNZLINE"  	/* UNZLINE */

#define MSG_STLINE              "STLINE"    /* STLINE */
#define MSG_UNSTLINE    "UNSTLINE"    /* UNSTLINE */
#define MSG_SETVIRTUAL "SETVIRTUAL"
#define MSG_SPAMADD     "SPAMADD"
#define MSG_SPAMDEL     "SPAMDEL"
#define MSG_VHOSTADD    "VHOSTADD"
#define MSG_VHOSTDEL    "VHOSTDEL"

#define MSG_SQLINE 		"SQLINE"    /* SQLINE */
#define MSG_UNSQLINE   	"UNSQLINE" 	/* UNSQLINE */

#define MSG_LOCOPS   	"LOCOPS"   	/* LOCOPS */
#ifdef LWALLOPS
#define MSG_LWALLOPS 	"LWALLOPS" 	/* Same as LOCOPS */
#endif /* LWALLOPS */
#ifdef USE_KNOCK
#define MSG_KNOCK       "KNOCK"     /* KNOCK */
#endif
#define MSG_MAP       	"MAP"       /* MAP */
#define MSG_NEWS       	"NEWS"      /* NEWS */
#define MSG_ZOMBIE		"ZOMBIE"    /* ZOMBIE */
#define MSG_UNZOMBIE    "UNZOMBIE"  /* UNZOMBIE */
#define MSG_DCCDENY		"DCCDENY"
#define MSG_DCCALLOW	"DCCALLOW"
#define MSG_SVSINFO		"SVSINFO"	/* SVSINFO */
#define MSG_CMSG	    "CMSG"		/* CMSG */
#define MSG_CPRIVMSG	    "CPRIVMSG"		/* CPRIVMSG */
#define MSG_CNOTICE	    "CNOTICE"   /* CNOT */


/* Services only messages */
#define MSG_SVSJOIN		"SVSJOIN"
#define MSG_SVSPART		"SVSPART"
#define MSG_SVSMODE 	"SVSMODE"
#define MSG_SVSNICK		"SVSNICK"


/* Services aliases */
#define MSG_NICKSERV	"NICKSERV"
#define MSG_HOSTSERV	"HOSTSERV"
#define MSG_CHANSERV	"CHANSERV"
#define MSG_MEMOSERV	"MEMOSERV"
#define MSG_NEWSSERV	"NEWSSERV"
#define MSG_OPERSERV	"OPERSERV"
#define MSG_STATSERV	"STATSERV"
#define MSG_HELPSERV    "HELPSERV"
#define MSG_IDENTIFY	"IDENTIFY"
#define MSG_BOTSERV     "BOTSERV"
#define MSG_HOSTSERV	"HOSTSERV"
#define MSG_GAMESERV    "GAMESERV"

#define MSG_SILENCE	    "SILENCE"
#define	MSG_WATCH	    "WATCH"
#define MSG_IRCOPS	    "IRCOPS"
#define MSG_STAFF               "STAFF"
#define MSG_SVSADMIN	"SVSADMIN"
#define MSG_REDIRECT    "REDIRECT"
#define MSG_LNOTICE	"LNOTICE"
#define MSG_GETSIGNON   "GETSIGNON"
#define MAXPARA    15

#define MSG_OS		"OS"

#ifdef MSGTAB
#ifndef INCLUDED_m_commands_h
#include "m_commands.h"       /* m_xxx */
#endif
struct Message msgtab[] = {
#ifdef IDLE_FROM_MSG   /* reset idle time only if privmsg used */
#ifdef IDLE_CHECK       /* reset idle time only if valid target for privmsg
                           and target is not source */

  /*                                        |-- allow use even when unreg.
                                            v   yes/no                  */
  { MSG_PRIVATE, m_private,  0, MAXPARA, 1, 0, 0, 0L },
#else
  { MSG_PRIVATE, m_private,  0, MAXPARA, 1, 0, 1, 0L },
#endif

  /*                                           ^
                                               |__ reset idle time when 1 */
#else   /* IDLE_FROM_MSG */
#ifdef  IDLE_CHECK      /* reset idle time on anything but privmsg */
  { MSG_PRIVATE, m_private,  0, MAXPARA, 1, 0, 1, 0L },
#else
  { MSG_PRIVATE, m_private,  0, MAXPARA, 1, 0, 0, 0L },
  /*                                           ^
                                               |__ reset idle time when 0 */
#endif  /* IDLE_CHECK */
#endif  /* IDLE_FROM_MSG */

  { MSG_NOTICE,  m_notice,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_PING,    m_ping,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SJOIN,   m_sjoin,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_MODE,    m_mode,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_LUSERS,  m_lusers,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_NICK,    m_nick,     0, MAXPARA, 1, 1, 0, 0L },
  { MSG_PART,    m_part,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_PONG,    m_pong,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_QUIT,    m_quit,     0, MAXPARA, 1, 1, 0, 0L },
  { MSG_JOIN,    m_join,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SVSMODE, m_svsmode,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_WHOIS,   m_whois,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_AWAY,    m_away,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_WHO,     m_who,      0, MAXPARA, 1, 0, 0, 0L },
  { MSG_TOPIC,   m_topic,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_USER,    m_user,     0, MAXPARA, 1, 1, 0, 0L },
  { MSG_KICK,    m_kick,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_USERHOST,m_userhost, 0, 1,       1, 0, 0, 0L },
  { MSG_CMSG,    m_cmsg,     0, MAXPARA, 1, 0, 1, 0L },
  { MSG_NICKSERV,m_nickserv, 0,       1, 1, 0, 0, 0L },
  { MSG_WATCH,   m_watch,    0,       1, 1, 0, 0, 0L },
  { MSG_CHANSERV,m_chanserv, 0,       1, 1, 0, 0, 0L },
  { MSG_ISON,    m_ison,     0, 1,       1, 0, 0, 0L },
  { MSG_SVSNICK, m_svsnick,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_KILL,    m_kill,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_PASS,    m_pass,     0, MAXPARA, 1, 1, 0, 0L },
  { MSG_ZLINE,   m_zline,    0,       4, 1, 0, 0, 0L },
  { MSG_CNOTICE, m_cnotice,  0, MAXPARA, 1, 0, 0, 0L },  
  { MSG_MEMOSERV,m_memoserv, 0,       1, 1, 0, 0, 0L },
  { MSG_SVSJOIN, m_svsjoin,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_IDENTIFY,m_identify, 0,       1, 1, 0, 0, 0L },
  { MSG_STLINE,  m_stline,   0,       4, 1, 0, 0, 0L },
  { MSG_GLINE,   m_gline,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_NAMES,   m_names,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_LIST,    m_list,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SQLINE,  m_sqline,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_TIME,    m_time,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_INVITE,  m_invite,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_WHOWAS,  m_whowas,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_IRCOPS,  m_ircops,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SVLINE,  m_svline,   0,       3, 1, 0, 0, 0L },
  { MSG_SANOTICE,m_sanotice, 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SRNOTICE,m_srnotice, 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_NEWMASK, m_newmask,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_LINKS,   m_links,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_OPERSERV,m_operserv, 0,       1, 1, 0, 0, 0L },
  { MSG_VERSION, m_version,  0, MAXPARA, 1, 0, 0, 0L },

#ifdef USE_KNOCK
  { MSG_KNOCK,   m_knock,    0, MAXPARA, 1, 0, 0, 0L },
#endif
#ifdef POST_REGISTER
  { MSG_POST,   m_post,      0, MAXPARA, 1, 1, 0, 0L },
#endif /* POST_REGISTER */  
  { MSG_GLOBOPS, m_globops,  0,       1, 1, 0, 0, 0L },
  { MSG_LOCOPS,  m_locops,   0,       1, 1, 0, 0, 0L },
#ifdef LWALLOPS
  { MSG_LWALLOPS,m_locops,   0,       1, 1, 0, 0, 0L },
#endif /* LWALLOPS */
  { MSG_ERROR,   m_error,    0, MAXPARA, 1, 1, 0, 0L },
  { MSG_SERVER,  m_server,   0, MAXPARA, 1, 1, 0, 0L },
  { MSG_SQUIT,   m_squit,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_TRACE,   m_trace,    0, MAXPARA, 1, 0, 0, 0L },
#ifdef LTRACE
  { MSG_LTRACE,  m_ltrace,   0, MAXPARA, 1, 0, 0, 0L },
#endif /* LTRACE */
  { MSG_OPER,    m_oper,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_CONNECT, m_connect,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_STATS,   m_stats,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_ADMIN,   m_admin,    0, MAXPARA, 1, 1, 0, 0L },
  { MSG_USERS,   m_users,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_AJUDA,   m_helpsys,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_HELPSYS, m_helpsys,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_INFO,    m_info,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_MOTD,    m_motd,     0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SVINFO,  m_svinfo,   0, MAXPARA, 1, 1, 0, 0L },
  { MSG_CAPAB,   m_capab,    0, MAXPARA, 1, 1, 0, 0L },
  { MSG_CLOSE,   m_close,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_KLINE,   m_kline,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_UNKLINE, m_unkline,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_DLINE,   m_dline,    0, MAXPARA, 1, 0, 0, 0L },
  { MSG_UNGLINE, m_ungline,  0, MAXPARA, 1, 0, 0, 0L }, 
  { MSG_SGLINE,  m_sgline,   0,       3, 1, 0, 0, 0L },
  { MSG_UNSGLINE,m_unsgline, 0,       2, 1, 0, 0, 0L },   
  { MSG_UNSVLINE,m_unsvline, 0,       3, 1, 0, 0, 0L },     
  { MSG_UNSTLINE,m_unstline, 0,       2, 1, 0, 0, 0L },
  { MSG_UNZLINE, m_unzline,  0, MAXPARA, 1, 0, 0, 0L },    
  { MSG_UNSQLINE,m_unsqline, 0, MAXPARA, 1, 0, 0, 0L },    
  { MSG_SILENCE, m_silence,	 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SPAMADD, m_spamadd,  0, MAXPARA, 1, 0, 0, 0L },    
  { MSG_SPAMDEL, m_spamdel,  0, MAXPARA, 1, 0, 0, 0L },    
  { MSG_VHOSTADD, m_vhostadd,  0, MAXPARA, 1, 0, 0, 0L },    
  { MSG_VHOSTDEL, m_vhostdel,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_REHASH,  m_rehash,   0, MAXPARA, 1, 0, 0, 0L },
  { MSG_RESTART, m_restart,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_HTM,     m_htm,      0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SET,     m_set,      0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SVSINFO, m_svsinfo,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SVSPART, m_svspart,  0, MAXPARA, 1, 0, 0, 0L },
  { MSG_NEWSSERV,m_newsserv, 0,       1, 1, 0, 0, 0L },
  { MSG_STATSERV,m_statserv, 0,       1, 1, 0, 0, 0L },
  { MSG_HELPSERV,m_helpserv, 0,       1, 1, 0, 0, 0L },
  { MSG_BOTSERV, m_botserv, 0,        1, 1, 0, 0, 0L },
  { MSG_HOSTSERV,m_hostserv, 0,       1, 1, 0, 0, 0L },
  { MSG_GAMESERV,m_gameserv, 0,        1, 1, 0, 0, 0L },
  { MSG_DCONF,   m_dconf,    0,       4, 1, 0, 0, 0L },
  { MSG_MAP,     m_map, 	 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_STAFF,   m_staff,       0, MAXPARA, 1, 0, 0, 0L },
  { MSG_NEWS,  	 m_news, 	 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_ZOMBIE,	 m_zombie,	 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_UNZOMBIE,m_unzombie, 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_DCCDENY, m_dccdeny,	 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_DCCALLOW,m_dccallow, 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_SVSADMIN,m_svsadmin, 0, MAXPARA, 1, 0, 0, 0L },  
  { MSG_CPRIVMSG,m_cmsg,     0, MAXPARA, 1, 0, 1, 0L },
  { MSG_REDIRECT,m_redirect, 0, MAXPARA, 1, 0, 0, 0L },
  { MSG_LNOTICE, m_lnotice,  0, 1, 1, 0, 0, 0L },
  { MSG_GETSIGNON, m_getsignon,0, 1, 1, 0, 0, 0L },
  { (char *) 0, (int (*)()) 0 , 0, 0,    0, 0, 0, 0L }
};

struct MessageTree* msg_tree_root;

#else
extern struct Message       msgtab[];
extern struct MessageTree*  msg_tree_root;
#endif

#endif /* INCLUDED_msg_h */

