/*
 * bottypes.h
 * (C) Peter Salanki 2002
 * This program is copyright, and covered by the Gnu Public License.
 * The Natasha bot.
 * sorcer@linux.se
 */

#include "settings.h"
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <signal.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>

struct slog {
   int cid;
   char action[10];
   char nick[NICKLEN];
   char username[USERLEN];
   char hostname[HOSTLEN];
   int uid;
   int time;
   char msg[512];
} log[LINESBEFORESAVE+1];

struct module {
  char name[20];
  void *fl;
  float version;
  char path[100];
  char compiledate[30];
  pthread_mutex_t mutex;

  struct module *last;
  struct module *next;
};

struct arm {
  int id;
  char nick[NICKLEN];
  int fd;
  int datasent;
  int datainbuff;
  int lastreset;
  int nextsend;
  int type;
  int channels;
  short status; // 0: Down 1: Up
  short activethread;
  short connect; // 0: No 1: Yes
  char server[50];
#ifdef OUTGOING_VHOST
  char vhost[150];
#endif

  fd_set r;
  pthread_t thread;
  pthread_mutex_t sendqmutex;

  struct parsevars *parsevars;

  struct sendqueue *lastsendqueue;
  struct sendqueue *firstsendqueue;
  
  struct arm *last;
  struct arm *next;
};

struct parsevars {
  char args[MAX_ARGS][512];
  int argcount;
  int isserver;
  char sender[512];
  char command[512];
};

struct sendqueue
{
  char data[511]; // We will not send more than 512 chars 
  struct sendqueue *last;
  struct sendqueue *next;
};

/*
 * Structure defining a currently active user - one who is actually connected
 * to the network.
 */

struct activeuser
{
  char nick[NICKLEN];
  char hand[NICKLEN];
  char *username;
  char *hostname;
  short auth;
  int userid;
  int lastseen;
  int check;
  short isinhome;
  short requestok;
  //  pthread_mutex_t mutex; No use ATM

  struct aculink *firstlink;
  struct aculink *lastlink;
  
  struct activeuser *next;
  struct activeuser *last;
};

/*
 * A structure that is used to link to the real data in the activeusersonchannels struct.
 * We use this so the searching by findachanuser() will be much more efficient.
 */

struct aculink
{
  struct activechanuser *link;
 
  struct aculink *last;
  struct aculink *next;
};

struct channel
  {
    int id;
    short isop;
    short ison;
    char topic[TOPICLEN];
    char name[CHANNELLEN];

    /* Settings */
    char modes[15];
    char key[20];
    short autoop;
    short autovoice;
    short bitch;
    short ftopic;
    char mvoice[15];
    char onjoin[500];
    short advertise;
    int floodrep;
    int floodtime;
    short peak;
    short greet;
    short tv;
    short vote;
    short infobot;
    short stats;
  
    struct vote *votestruct;

    struct arm *arm;

    struct banlist *firstbanlist;
    struct banlist *lastbanlist;

    struct channel *next;
    struct channel *last;
  };

struct chanuser
  {
    struct channel *channel;
    int uid;
    int level;
    char greet[100];

    struct chanuser *next;
    struct chanuser *last;
  };

struct activechanuser
  {
    struct channel *channel;
    struct activeuser *user;

    short op;
    short voice;
    
    short warned;
    int lastreset;
    short rows;

    //    pthread_mutex_t mutex; /* No use ATM */

    struct activechanuser *next;
    struct activechanuser *last;
  };

struct banlist
  {
    char host[BANLEN];
    char reason[512];
    int setby;
    int expire;

    struct banlist *next;
    struct banlist *last;
  };

struct vote
  {
    char question[256];
    int asker;
    int expiretime;
    
    int yes;
    int no;

    int lastvid;
    struct activeuser *voted[200];
    
  };

