#ifndef _H_CNETSERVER
#define _H_CNETSERVER

class CNetServer;

#include "mbot.h"
#include "CText.h"
#include "CChannel.h"
#include "CListVars.h"
#include "CListUsers.h"
#include "CNet.h"
#include "CNetDCC.h"
#include "CServices.h"
#include "CScript.h"

class CNetServer : public CNet {
public:
  CNetServer (CBot *);
  ~CNetServer (void);

  void irc_pong (const char *);
  void irc_quit (const char *);
  void irc_privmsg (const char *, const char *, ...);
  void irc_notice (const char *, const char *, ...);
  void irc_nick (const char *);
  void irc_user (const char *, const char *);
  void irc_whois (const char *);
  void irc_ison (const char *);
  void irc_watch (const char *, bool);
  void irc_who (const char *);
  void irc_oper (const char *, const char *);
  void irc_kill (const char *, const char *);
  void irc_away (const char *);

  void write_botlog (const char *, ...);
  void irc_connect (void);
  void irc_restart (void);
  void work (void);

  int channel_add(const char *, const char *);
  int channel_del(const char *);
  int channel_index (const char *);

  void irc_parse (void);

  // circular list of hosts
  struct host_type {
    CString host;
    int port;
    host_type *next;
    host_type (c_char h, int p) : host (h, HOST_SIZE) {
      port = p; next = this;
    }
    host_type (c_char h, int p, host_type *n) : host (h, HOST_SIZE) {
      port = p; next = n;
    }
  } *hosts,				// hosts list
    *host_current;			// current host, points to one of them

  host_type *host_add (host_type *, const char *, int);

  CString virtualhost;
  CString nick;
  CString nick_orig;
  CString user;
  CString name;
  CString away;
  CString quit;

  time_t last_try; 	// last try to connect to the server

  int change_time;	// time (in seconds) to be added to local time
  time_t time_now;	// current local time, with change_time applied

  CListUsers *users;				// registered users

  CChannel *channels[CHANNEL_MAX];		// channels
  int channel_num;				// channels number

  CNetDCC *dccs[DCC_MAX];			// dccs
  int dcc_num,					// dccs number
      dcc_port;					// port for dccs, 0 to any free
  CString dcc_file,				// file with !get definitions
          dcc_motdfile;				// file with dcc chat's motd
  CText *dcc_motd;				// opened motd or NULL

  CListVars vars;				// server variables
  CServices services;				// nick/chan/oper/memoserv etc
  CScript script;				// events and replies handler
  
  char cmd[CMD_SIZE][MSG_SIZE+1];		// parsed message
  int cmd_i;					// components
  char buf[CMD_SIZE*(MSG_SIZE+1)];
  time_t uptime;				// when the server connected

  CList works;

private:

};

#endif
