/*
 * bottypes.h
 * (C) James Craig 1998, Email: jcraig@mad.scientist.com
 * (C) Christian Magnusson 1999, 2000, Email: d1mag@dtek.chalmers.se
 * This program is copyright, and covered by the Gnu Public License.
 * The Q bot.
 */
#include <time.h>
#include "settings.h"
#include "hash.h"

#ifndef BOTTYPES_H
#define BOTTYPES_H

struct ban {
  char ban[BANLEN+1];
  char nick[NICKLEN+1];  /* these are filled in automatically */
  char user[USERLEN+1];  /* these are filled in automatically */
  char host[HOSTLEN+1];  /* these are filled in automatically */
  int placedby;
  struct ban *next;
};

struct trusted {
  char *host;
  int nr_users;
  int placedby;
  time_t expire;
  char *reason;
};

struct gline {
  char gline[GLINELEN+1];
  char user[USERLEN+1];  /* these are filled in automatically */
  char host[HOSTLEN+1];  /* these are filled in automatically */
  time_t expire;
  time_t duration;
  int placedby;
  char *reason;
};

struct chantype {
  char *name;
  int id;
  int join_burst;
  int priority;
};

/*
struct nick_change {
  char old[NICKLEN+1];
  char new[NICKLEN+1];
  char yxx[YXXLEN+1];
  time_t tnow;
  time_t expire;
};
*/

/*
 * Channel description structure.
 */
struct chanopts {
  char channel[CHANNELLEN+1];
  char topic[TOPICLEN+1];
  char last_topic[TOPICLEN+1];
  char welcome[WELCOMELEN+1];
  int bot_joined;   /* not used anymore (+a) flag */
  int suspended;    /* channel is suspended from usage */
  int suspend_who;
  time_t suspend_time;
  char *suspend_reason;
  int type;     /* type of channel */
  int flags;    /* saved channel properties */
  int modes;    /* current modes from irc-servers */
  char chantype[CHANTYPELEN+1];
  char key[KEYLEN+1];
  char limit[LIMITLEN+1];     /* limit set from LIMIT command */
  char cur_limit[LIMITLEN+1]; /* current limit on channel */
  int limit_delay;   /* global at the moment */
  int limit_change;
  int limit_last_joined;
  time_t limit_next_check;
  int owner;
  int created_by; /* operator name who created the channel */
  /* stats about the channel */
  int nr_members;        /* just a counter used for stats, not initialized */
  int nr_owners, nr_masters, nr_opers, nr_voice;
  time_t first_joined;
  time_t last_joined;
  unsigned int nr_joined; /* total counter of joined users since registration*/
  unsigned int current_joined; /* counter with nr users on the channel right now */
#ifdef AUTH_HISTORY
  /*
    auth history saving x'th last userid's and nicks who authed for op on
    the channel.
  */
  char auth_history_nick[AUTH_HISTORY_LEN][NICKLEN+1];
  int auth_history_userid[AUTH_HISTORY_LEN];
  int auth_history_pos;
#endif

  struct ban *bans;
  ListElem *l_elem;      /* pointer to the list header */
  ListElem *h_elem;      /* pointer to the hash header */
};

/*
 * Structure defining a user's mode and presence on a channel.
 * Might need a little modification for the Q bot as opposed to the U bot.
 */

struct chanmod {
  char *channel; // [CHANNELLEN+1];
  int mode;
#ifdef DMALLOC
  int filler;
#endif
  struct chanmod *next;
};

struct chan_stat {
  char channel[CHANNELLEN+2];
  int count;
#ifdef DMALLOC
  int filler;
  int filler2;
#endif
    struct chan_stat *next;
};

struct chanpriv {
  char channel[CHANNELLEN+1];
  int chanlevel;
  struct chanpriv *next;
};

struct dbaseuser {
  char *nick; // [NICKLEN+1]; /* Nick at the time of registration */
  int userid;
  char password[PASSLEN+1]; /* Password (crypted?) */
  char *email;
  time_t last_email_request;
  int globalauth;
  time_t last_auth;
  char last_yxx[YXXLEN+1];
  char *last_hostname; // [HOSTLEN+1];
  char last_username[USERLEN+1];
  struct chanpriv *privs;
  ListElem *l_elem;         /* pointer to the list header */
  ListElem *h_elem_nick;    /* pointer to the hash header */
  ListElem *h_elem_lastyxx; /* pointer to the hash header */
  ListElem *h_elem_userid;
};

/*
 * Structure defining a currently active user - one who is actually connected
 * to the network, not merely one who *could* connect.
 */

struct activeuser {
  char nick[NICKLEN+1];
  char username[USERLEN+1];
  char hostname[HOSTLEN+1];
  char fullname[REALLEN+1];
  char yxx[YXXLEN+1];
  unsigned int mode;       /* user mode */
  int oper;                /* user is operator (+o in usermode) */
  int auth;                /* Auth level in database 0, 1, 900+ etc. */
  int userid;              /* authed as this userid */
  int userid_history[USERID_HISTORY_LEN]; /* list of userid's the user have used as */
  struct dbaseuser *dbuser;    /* if userid is set, this is set too */
  struct chanmod *chanmodes;
  ListElem *h_elem_yxx;   /* pointer to the hash headers */
  ListElem *h_elem_nick;
  ListElem *l_elem;       /* pointer to the list header */
};

#define NUMNICKMAXCHAR 'z'        /* See convert2n[] */
#define NUMNICKBASE 64            /* (2 << NUMNICKLOG) */
#define NUMNICKLOG 6
#define NUMNICKMASK 63            /* (NUMNICKBASE-1) */
#define MAX_MAXCLIENTS 262144       /* (NUMNICKBASE * NUMNICKBASE) */

/*
  servers_stat should be removed and info about nr. of oper/user
  and other stat should go into one struct!
*/
struct Server {
  char connected;
  char jupe;
  char name[SERVERLEN+1];
  char passwd[20];
  char parent_server[2];
  char yxx[2];
  int opers;
  int users;
  int opers_tot;
  int users_tot;
  char uptime_str[UPTIMELEN+1];
};

struct jupeinfo
{
  char jupe[100];
  char server[100];
  char reason[100];
  char yxx;
  int numeric;
};


extern char yxx[YXXLEN+1];
extern struct Server servers[MAX_SERVERS+1];
extern char convert2y[NUMNICKBASE];
#ifndef u_char
#define u_char unsigned char
#endif
extern u_char convert2n[NUMNICKMAXCHAR + 1];
extern int authid_history_trigger;
extern int donewithburst;
extern char *ourmsghost;

#endif
