#ifndef __I_NET_H__
#define __I_NET_H__

#define	MAX_UDP_PACKET	8192
#define MASTERPORT 15100
#define LAUNCHERPORT 12999

typedef unsigned char byte;

#define CHALLENGE 5560020  // challenge
#define SERVER_CHALLENGE 5560020  // doomsv challenge
#define LAUNCHER_CHALLENGE 777123  // csdl challenge

extern int   localport;
extern byte	 net_message_buffer[MAX_UDP_PACKET];
extern int   msg_badread;

typedef struct
{
   byte    ip[4];
   unsigned short  port;
   unsigned short  pad;
} netadr_t;

extern  netadr_t  net_from;  // address of who sent the packet


typedef struct buf_s
{
   byte    *data;
   int      maxsize;
   int      cursize;
   bool     overflowed;  // set to true if the buffer size failed
} buf_t;

extern buf_t net_message;

void CloseNetwork (void);
void InitNetCommon(void);
void I_SetPort(netadr_t &addr, int port);
void I_DoSelect (void);

char *NET_AdrToString (netadr_t a);
bool NET_StringToAdr (char *s, netadr_t *a);
bool NET_CompareAdr (netadr_t a, netadr_t b);
int  NET_GetPacket (void);
void NET_SendPacket (int length, byte *data, netadr_t to);

void SZ_Clear (buf_t *buf);
void SZ_Write (buf_t *b, void *data, int length);

void MSG_WriteByte (buf_t *b, int c);
void MSG_WriteShort (buf_t *b, int c);
void MSG_WriteLong (buf_t *b, int c);
void MSG_WriteString (buf_t *b, char *s);

int MSG_ReadByte (void);
int MSG_ReadShort (void);
int MSG_ReadLong (void);
char *MSG_ReadString (void);


#endif
