#ifndef _SIRCD_H_
#define _SIRCD_H_

#include <sys/types.h>
#include <netinet/in.h>

#define MAX_CLIENTS FD_SETSIZE
#define MAX_MSG_TOKENS 10
#define MAX_MSG_LEN 512
#define MAX_USERNAME 32
#define MAX_HOSTNAME 512
#define MAX_SERVERNAME 512
#define MAX_REALNAME 512
#define MAX_CHANNAME 512
#define LISTENQ  1024  /* backlog for call to listen() */
#define INIT_CAPACITY 10

typedef struct sockaddr SA;

typedef struct { /*client struct */
    int sock;
    int descriptor_index;
    int set_nick;
    int set_user;
    struct sockaddr_in cliaddr;
    unsigned inbuf_size;
    int registered;
    char hostname[MAX_HOSTNAME];
    char servername[MAX_SERVERNAME];
    char user[MAX_USERNAME];
    char nick[MAX_USERNAME];
    char realname[MAX_REALNAME];
    char inbuf[MAX_MSG_LEN+1];
    char channel[MAX_CHANNAME];
} client;

typedef struct {	/* channel struct */
	int user_count;
	char name[MAX_CHANNAME];
	int users_capacity;
	client **users;
} channel;

typedef struct { /* pool of connected clients and available channels */
    int maxfd;
    fd_set read_set;
    fd_set ready_set;
    int nready;
    int maxi;
    char shostname[MAX_HOSTNAME];
    int clientfd[MAX_CLIENTS]; 	 /* array of client descriptors */
    client clients[MAX_CLIENTS]; /* array of client structs */
    channel *channels;			 /* pointer to array of available channels */
    int channels_capacity;
    int channel_count;
} pool;

void resize_channels(pool *p);
void resize_users(pool *p, int index);
void handle_line(char *line, client *curr_client, pool *p);

#endif /* _SIRCD_H_ */
