#ifndef INC_HLCLIENTPROTOCOL
#define INC_HLCLIENTPROTOCOL

#define	MASTER_VERSION	200
#include <stdio.h>
#include <string.h>
#include <winsock.h>
#include <time.h>
#include <errno.h>

typedef unsigned char byte;

// master protocols, shared with client and server

/*

The protocol packets are all pure, readable ascii.  The first byte is
the command code.  Followed by a \n, then any other parameters, each
followed by a \n.

key/value info sets are represented by a \n terminated string.

The string is seperated into tokens by backslash characters.
There will allways be an even number of tokens.
An empty token is acceptable.

Individual tokens may not contain \n or backslash characters.

The string:

\name\johnc\!password\test

would break into:
user = johnc
!password = test

*/

#define MAX_SVCHANNELS 10

#define LAUNCHERONLY
#include "U:\\Quiver\\Src\\Engine\\Protocol.h"

#define	MAX_INFO_STRING	512

#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif

typedef struct sockaddr_in	netadr_t;

#define MIN_SV_TIMEOUT_INTERVAL 5 // Once every 5 seconds is fast enough

#define SV_CHAT 0
#define SV_SERVER_MASTER 1
#define SV_CLIENT_MASTER 2

typedef struct sv_s
{
	struct	sv_s	*next;

	netadr_t	address;

/*  contents of last heartbeat */
	double     tLastRequest;  // Time we send a request.
	int			time;				/*  local time at message arrival */
	BOOL        bNoTimeout;  // True for persistent server IPs

	int      nType; // SV_CHAT, SV_SERVER_MASTER or SV_CLIENT_MASTER
} sv_t;

#define TIMEOUT_SECONDS (60 * 30) // 30 minutes
#define MIN_TIMEOUT_INTERVAL (15) // Only check once every 15 secs
#define GUID_HASH_ENTRIES 317

typedef struct 
{
	unsigned char id[16];
} hlUUID;

typedef struct guid_s
{
	struct guid_s *next;

	BOOL bValidated;

	netadr_t address;

	unsigned int bitseed[4]; // Randomized checksum seed value.

	unsigned char md5[16]; // Client's launcher.exe hash value (for versioning)

	hlUUID unique;           // The user's unique ID.  Generated by the UuidCreate() API

	char guid[GUID_LEN];  // 13 digit unique id

	CID_t *CID;   // The certificate/ token sent back to this client.  The token is the client's ip address
			     // This token is also used for client hearbeats.

	double lastUpdate; // Time of last update.
	int nFailures;     // # of failures since last valid message
} guid_t;

/*  master */
extern	FILE	*logfile;

/*  mas_unix */
extern	byte	packet_data[65536];
extern	int		packet_length;
extern	struct sockaddr_in	packet_from;

extern	int	msg_readcount;

#endif

