/* aoe 2005 gpl2 */

#define LISTENPORT 7670
#define LISTENADDR "0.0.0.0"
#define SERVERPORT 7670
#define IRCPORT 6667
/* #define SERVER "213.155.73.107" */
#define SERVER "78.111.72.163"
#define LOGFILE "/dev/stderr"
#define LOGSTREAM stderr

#define JAVA_VERSION_DEFAULT "unknown"

/* s till reconnect */
#define CONNECTRETRY 10

/* some IRC stuff */
#define MAX_IRC_COMMAND_LENGTH 510

typedef struct protoent protoent_t;

/* one day, make lists of clients, ircclients and possibly servers ... */
typedef struct fdlist {
	int fd;
	struct fdlist * next;
} fdlist_t;

typedef struct bswdata {
	int inport;
	int outport;
	int ircport;
	char *servername;
	char *logfile;
	FILE *log;
	int clientfd;
	int clientlistenfd;
	int serverfd;
	fdlist_t * ircfdlist;
	int irclistenfd;
	int debug;
	int daemon;
	int sv[2];
	char *username;
	char *password;
	char *menu;
	char *listenaddr;
	char *java_ver;
	char *lang;
	char *room_location;
	char *room_board;
	int logged_in;
}
bswdata_t;

/* parsing packets */
typedef struct parsed_packet {
	char type;
	short length;
	char *content;
	struct parsed_packet *next;
}
parsed_packet_t;
	
/* one day, make lists of clients, ircclients and possibly servers ... */
typedef struct chlist {
	char name[32];
	/* topic, users ... */
	struct chlist * next;
} chlist_t;

/* data types */
enum bsw_datatypes {
	BSWTYPE_LONG =		0x01, /* long int (4b)? */
	BSWTYPE_BYTE =		0x02, /* char (1b)? */
	BSWTYPE_STRING =	0x03, /* short length, data */
	BSWTYPE_LIST =		0x04, /* short length, short count, listdata */
	BSWTYPE_BLOB1 =		0x05, /* short length, data zb HeckmeckBoard */
	BSWTYPE_SUBLIST =	0x06, /* short length, short count, listdata */
	BSWTYPE_BLOB2 =		0x07, /* short length, data zb EinfachGenialBoard 2, HM */
	BSWTYPE_BLOB3 =		0x08 /* short length, data zb EinfachGenialBoard 1 */
};

/* message types */
enum bsw_msgtypes {
	BSWMSG_QUIT =			0, 
	BSWMSG_MESSAGE = 	0x0001,
	BSWMSG_NOTICE,
	BSWMSG_SOUND =		0x0013, 
	BSWMSG_LOGIN, 						/* auch vom server vor tatsaechlicher menueliste */
	BSWMSG_PING = 		0x0017, /* immer wieder */
	BSWMSG_PONG,
	BSWMSG_LOCATION = 0x001c,
	BSWMSG_GETLOCATION = 0x0021,
	BSWMSG_CHANNEL = 0x002d,
	BSWMSG_SOLO =			0x0037,
	BSWMSG_BOARDTYPE = 0x005e,
	BSWMSG_BOARDSTART = 0x02bc,
	BSWMSG_TERRAINSTART =	0x1388,
	BSWMSG_TERRAINVIEWSTART,
	BSWMSG_TERRAINVIEWDATA=0x1390,
	BSWMSG_TERRAINVIEWMETADATA,
	BSWMSG_MENU =			0x2710,
	BSWMSG_SHOWTOOL,
	BSWMSG_USERLIST,
	BSWMSG_GAMEPLAYERS =0x2713,
	BSWMSG_WORLDLISTTOOL =0x2714,
	BSWMSG_CHANNELRESPONSE=0x271f,
	BSWMSG_CHANNELREQUEST=0x2720,
	BSWMSG_SPV_CITY=0x2758,
	BSWMSG_MENUITEMLIST =0x27e2,
	BSWMSG_SHOWTOOL2=0x4e20,
	BSWMSG_SHOWBOARD =0x4e21
};

short int initpackettypes[] = {
	BSWMSG_LOGIN,
	BSWMSG_MENU,
	BSWMSG_MENUITEMLIST,
	BSWMSG_CHANNEL,
	BSWMSG_SPV_CITY,
	BSWMSG_TERRAINSTART,
	BSWMSG_TERRAINVIEWSTART,
	BSWMSG_TERRAINVIEWDATA,
	BSWMSG_TERRAINVIEWMETADATA,
	BSWMSG_LOCATION,
	BSWMSG_WORLDLISTTOOL,
	BSWMSG_BOARDTYPE,
	BSWMSG_GAMEPLAYERS,
	BSWMSG_BOARDSTART,
	BSWMSG_SHOWBOARD,
	BSWMSG_USERLIST
};


/* debug level */
enum bsw_debuglevels {
	BSWDEBUG_NONE = 0,
	BSWDEBUG_ERROR,
	BSWDEBUG_INFO,
	BSWDEBUG_VERBOSE,
	BSWDEBUG_COUNT /* placeholder */
};

#ifndef USLEEPTIME
#define USLEEPTIME 100000
#endif
#ifndef myusleep
#define myusleep(usa) { \
	struct timeval tv;   \
	long int us; \
	us=usa; \
	tv.tv_sec=us/1000000;    \
	tv.tv_usec=us%1000000;   \
	select(0,NULL,NULL,NULL,&tv); \
}
#endif

