2005-09-24 04:48:20 +00:00
/*
Copyright ( C ) 1996 - 1997 Id Software , Inc .
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the included ( GNU . txt ) GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
2006-02-22 02:38:48 +00:00
# ifdef __GNUC__
# define LittleLong(x) ({ typeof(x) _x = (x); _x = (((unsigned char *)&_x)[0]|(((unsigned char *)&_x)[1]<<8)|(((unsigned char *)&_x)[2]<<16)|(((unsigned char *)&_x)[3]<<24)); _x; })
# define LittleShort(x) ({ typeof(x) _x = (x); _x = (((unsigned char *)&_x)[0]|(((unsigned char *)&_x)[1]<<8)); _x; })
# else
# define LittleLong(x) (x)
# define LittleShort(x) (x)
# endif
2005-09-24 04:48:20 +00:00
2006-10-07 22:29:31 +00:00
//this is for a future version
//#define COMMENTARY
2005-09-06 01:09:36 +00:00
//each server that we are connected to has it's own state.
//it should be easy enough to use one thread per server.
//mvd info is forwarded to other proxies instantly
//qwd stuff is buffered and delayed. :(
//this means that when a new proxy connects, we have to send initial state as well as a chunk of pending state, expect to need to send new data before the proxy even has all the init stuff. We may need to raise MAX_PROXY_BUFFER to be larger than on the server
2005-10-07 02:02:15 +00:00
//how does multiple servers work
//each proxy acts as a cluster of connections to servers
//when a viewer connects, they are given a list of active server connections
//if there's only one server connection, they are given that one automatically.
2005-09-06 01:09:36 +00:00
# ifdef _WIN32
2005-09-24 04:48:20 +00:00
# include <conio.h>
2006-09-17 01:27:32 +00:00
# include <winsock.h> //this includes windows.h and is the reason for much compiling slowness with windows builds.
# ifdef _MSC_VER
# pragma comment (lib, "wsock32.lib")
# endif
2005-09-06 01:09:36 +00:00
# define qerrno WSAGetLastError()
# define EWOULDBLOCK WSAEWOULDBLOCK
2006-04-11 22:15:09 +00:00
# define EINPROGRESS WSAEINPROGRESS
2006-09-17 01:27:32 +00:00
# define ECONNREFUSED WSAECONNREFUSED
2006-04-14 00:59:29 +00:00
# define ENOTCONN WSAENOTCONN
2005-09-06 01:09:36 +00:00
2006-09-17 01:27:32 +00:00
//we have special functions to properly terminate sprintf buffers in windows.
//we assume other systems are designed with even a minor thought to security.
# if !defined(__MINGW32_VERSION)
# define unlink _unlink //why do MS have to be so awkward?
int snprintf ( char * buffer , int buffersize , char * format , . . . ) ;
# if !defined(_VC80_UPGRADE)
int vsnprintf ( char * buffer , int buffersize , char * format , va_list argptr ) ;
# endif
# else
# define unlink remove //seems mingw misses something
# endif
2005-09-24 04:48:20 +00:00
# ifdef _MSC_VER
//okay, so warnings are here to help... they're ugly though.
# pragma warning(disable: 4761) //integral size mismatch in argument
# pragma warning(disable: 4244) //conversion from float to short
# pragma warning(disable: 4018) //signed/unsigned mismatch
2005-09-06 01:09:36 +00:00
# endif
# elif defined(__CYGWIN__)
2005-09-24 04:48:20 +00:00
# include <sys/time.h>
2005-09-06 01:09:36 +00:00
# include <sys/types.h>
# include <sys/socket.h>
# include <sys/errno.h>
# include <arpa/inet.h>
# include <stdarg.h>
# include <netdb.h>
# include <stdlib.h>
2005-09-24 04:48:20 +00:00
# include <sys/ioctl.h>
# include <unistd.h>
2005-09-06 01:09:36 +00:00
# define ioctlsocket ioctl
# define closesocket close
2006-02-22 00:48:22 +00:00
# elif defined(linux) || defined(ixemul)
2005-09-24 04:48:20 +00:00
# include <sys/time.h>
2005-09-06 16:44:31 +00:00
# include <sys/types.h>
# include <sys/socket.h>
2006-02-22 00:48:22 +00:00
# include <netinet/in.h>
2005-10-09 09:40:26 +00:00
# include <arpa/inet.h>
2005-09-06 16:44:31 +00:00
# include <netdb.h>
# include <stdarg.h>
# include <stdlib.h>
# include <string.h>
# include <errno.h>
# include <sys/ioctl.h>
# include <unistd.h>
# define ioctlsocket ioctl
# define closesocket close
2005-09-06 01:09:36 +00:00
# else
# error "Please insert required headers here"
//try the cygwin ones
# endif
2006-10-22 17:16:43 +00:00
# ifndef EAGAIN
# define EAGAIN EWOULDBLOCK
# endif
2005-09-24 04:48:20 +00:00
# ifndef pgetaddrinfo
# ifndef _WIN32
# define pgetaddrinfo getaddrinfo
# define pfreeaddrinfo freeaddrinfo
# endif
# endif
# ifndef SOCKET
# define SOCKET int
# endif
# ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
# endif
# ifndef qerrno
# define qerrno errno
# endif
2005-09-06 01:09:36 +00:00
# include <stdio.h>
2005-09-24 04:48:20 +00:00
# include <string.h>
2005-09-06 01:09:36 +00:00
2006-10-11 23:04:31 +00:00
# ifndef _WIN32
//stricmp is ansi, strcasecmp is unix.
# define stricmp strcasecmp
# define strnicmp strncasecmp
# endif
2006-10-07 22:29:31 +00:00
//linux and other systems have strlcat / strlcpy
//we support windows and can't use those
# define Q_strncatz(dest, src, sizeofdest) \
do { \
strncat ( dest , src , sizeofdest - strlen ( dest ) - 1 ) ; \
dest [ sizeofdest - 1 ] = 0 ; \
} while ( 0 )
# define Q_strncpyz(dest, src, sizeofdest) \
do { \
strncpy ( dest , src , sizeofdest - 1 ) ; \
dest [ sizeofdest - 1 ] = 0 ; \
} while ( 0 )
2005-09-06 01:09:36 +00:00
# define VERSION "0.01" //this will be added to the serverinfo
# define PROX_DEFAULTLISTENPORT 27501
# define PROX_DEFAULTSERVER "localhost:27500"
# define MAX_SERVERINFO_STRING 1024 //standard quake has 512 here.
# define MAX_USERINFO 192
# define MAX_CLIENTS 32
# define MAX_LIST 256
# define MAX_MODELS MAX_LIST
# define MAX_SOUNDS MAX_LIST
# define MAX_ENTITIES 512
# define MAX_STATICSOUNDS 64
2005-09-24 04:48:20 +00:00
# define MAX_STATICENTITIES 128
2005-09-06 01:09:36 +00:00
# define MAX_LIGHTSTYLES 64
2005-09-24 04:48:20 +00:00
# define DEFAULT_HOSTNAME "FTEQTV"
2005-09-06 01:09:36 +00:00
2006-09-17 01:27:32 +00:00
# define MAX_PROXY_INBUFFER 4096
2005-09-06 01:09:36 +00:00
# define MAX_PROXY_BUFFER (1<<14) //must be power-of-two
2006-09-19 01:48:12 +00:00
# define PREFERED_PROXY_BUFFER 4096 //the ammount of data we try to leave in our input buffer (must be large enough to contain any single mvd frame)
2005-09-06 01:09:36 +00:00
2005-09-24 04:48:20 +00:00
# define MAX_ENTITY_LEAFS 32
# define ENTS_PER_FRAME 64 //max number of entities per frame (OUCH!).
2005-09-06 01:09:36 +00:00
# define ENTITY_FRAMES 64 //number of frames to remember for deltaing
2005-09-24 04:48:20 +00:00
# define Z_EXT_SERVERTIME (1<<3) // STAT_TIME
# define Z_EXT_STRING "8"
2006-09-17 01:27:32 +00:00
# define MAX_STATS 32
# define STAT_HEALTH 0
# define STAT_FRAGS 1
# define STAT_WEAPON 2
# define STAT_AMMO 3
# define STAT_ARMOR 4
# define STAT_WEAPONFRAME 5
# define STAT_SHELLS 6
# define STAT_NAILS 7
# define STAT_ROCKETS 8
# define STAT_CELLS 9
# define STAT_ACTIVEWEAPON 10
# define STAT_TOTALSECRETS 11
# define STAT_TOTALMONSTERS 12
# define STAT_SECRETS 13 // bumped on client side by svc_foundsecret
# define STAT_MONSTERS 14 // bumped by svc_killedmonster
# define STAT_ITEMS 15
2005-09-24 04:48:20 +00:00
# define STAT_TIME 17 //A ZQ hack, sending time via a stat.
//this allows l33t engines to interpolate properly without spamming at a silly high fps.
2006-09-17 01:27:32 +00:00
# ifndef __cplusplus
2005-09-06 01:09:36 +00:00
typedef enum { false , true } qboolean ;
2006-09-17 01:27:32 +00:00
# else
typedef int qboolean ;
extern " C " {
# endif
2005-09-06 01:09:36 +00:00
typedef unsigned char netadr_t [ 64 ] ;
2006-10-07 22:29:31 +00:00
# define NQ_PACKETS_PER_SECOND 20
2006-09-17 01:27:32 +00:00
# define MAX_NQMSGLEN 8000
2005-09-06 01:09:36 +00:00
# define MAX_MSGLEN 1400
2006-09-17 01:27:32 +00:00
# define MAX_NQDATAGRAM 1024
2005-09-06 01:09:36 +00:00
# define MAX_BACKBUF_SIZE 1000 //this is smaller so we don't loose entities when lagging
2006-09-17 01:27:32 +00:00
//NQ transport layer defines
# define NETFLAG_LENGTH_MASK 0x0000ffff
# define NETFLAG_DATA 0x00010000
# define NETFLAG_ACK 0x00020000
# define NETFLAG_NAK 0x00040000
# define NETFLAG_EOM 0x00080000
# define NETFLAG_UNRELIABLE 0x00100000
# define NETFLAG_CTL 0x80000000
# define CCREQ_CONNECT 0x01
2006-09-19 01:48:12 +00:00
# define CCREQ_SERVER_INFO 0x02
2006-09-17 01:27:32 +00:00
# define CCREP_ACCEPT 0x81
# define CCREP_REJECT 0x82
2006-09-19 01:48:12 +00:00
# define CCREP_SERVER_INFO 0x83
2006-09-17 01:27:32 +00:00
# define NET_GAMENAME_NQ "QUAKE"
# define NET_PROTOCOL_VERSION 3
2006-10-07 22:29:31 +00:00
# ifdef COMMENTARY
2006-09-19 01:48:12 +00:00
typedef struct soundcapt_s {
int ( * update ) ( struct soundcapt_s * ghnd , int samplechunks , char * buffer ) ;
void ( * close ) ( struct soundcapt_s * ptr ) ;
} soundcapt_t ;
2007-03-03 18:46:43 +00:00
typedef struct soundplay_s {
int ( * update ) ( struct soundplay_s * ghnd , int samplechunks , char * buffer ) ;
void ( * close ) ( struct soundplay_s * ptr ) ;
} soundplay_t ;
2006-10-07 22:29:31 +00:00
# endif
2006-09-19 01:48:12 +00:00
2005-09-06 01:09:36 +00:00
typedef struct {
unsigned int readpos ;
unsigned int cursize ;
unsigned int maxsize ;
char * data ;
unsigned int startpos ;
qboolean overflowed ;
qboolean allowoverflow ;
} netmsg_t ;
typedef struct {
SOCKET sock ;
netadr_t remote_address ;
unsigned short qport ;
unsigned int last_received ;
unsigned int cleartime ;
int reliable_length ;
qboolean drop ;
2006-02-21 19:55:12 +00:00
qboolean isclient ;
2006-09-17 01:27:32 +00:00
qboolean isnqprotocol ;
2005-09-06 01:09:36 +00:00
netmsg_t message ;
2006-09-17 01:27:32 +00:00
char message_buf [ MAX_NQMSGLEN ] ; //reliable message being built
char reliable_buf [ MAX_NQMSGLEN ] ; //reliable message that we're making sure arrives.
2005-09-06 01:09:36 +00:00
float rate ;
unsigned int incoming_acknowledged ;
unsigned int last_reliable_sequence ;
unsigned int incoming_reliable_acknowledged ;
unsigned int incoming_reliable_sequence ;
unsigned int reliable_sequence ;
unsigned int incoming_sequence ;
unsigned int outgoing_sequence ;
2006-09-17 01:27:32 +00:00
unsigned int reliable_start ;
unsigned int outgoing_unreliable ;
unsigned int incoming_unreliable ;
unsigned int in_fragment_length ;
char in_fragment_buf [ MAX_NQMSGLEN ] ;
2005-09-06 01:09:36 +00:00
} netchan_t ;
typedef struct {
# define MAX_QPATH 64
char name [ MAX_QPATH ] ;
} filename_t ;
typedef struct {
unsigned char frame ;
unsigned char modelindex ;
unsigned char colormap ;
unsigned char skinnum ;
short origin [ 3 ] ;
2006-09-17 01:27:32 +00:00
char angles [ 3 ] ;
2005-09-06 01:09:36 +00:00
unsigned char effects ;
} entity_state_t ;
typedef struct {
unsigned char frame ;
unsigned char modelindex ;
unsigned char skinnum ;
short origin [ 3 ] ;
2006-04-11 22:15:09 +00:00
short velocity [ 3 ] ;
2006-09-17 01:27:32 +00:00
short angles [ 3 ] ;
2005-09-06 01:09:36 +00:00
unsigned char effects ;
unsigned char weaponframe ;
} player_state_t ;
typedef struct {
unsigned int stats [ MAX_STATS ] ;
char userinfo [ MAX_USERINFO ] ;
int ping ;
2005-09-24 21:33:03 +00:00
int packetloss ;
2005-09-06 01:09:36 +00:00
int frags ;
float entertime ;
2005-09-24 04:48:20 +00:00
int leafcount ;
unsigned short leafs [ MAX_ENTITY_LEAFS ] ;
2005-09-06 01:09:36 +00:00
qboolean active : 1 ;
qboolean gibbed : 1 ;
qboolean dead : 1 ;
player_state_t current ;
player_state_t old ;
} playerinfo_t ;
typedef struct {
entity_state_t ents [ ENTS_PER_FRAME ] ; //ouchie ouchie!
unsigned short entnum [ ENTS_PER_FRAME ] ;
int numents ;
} packet_entities_t ;
2006-04-11 22:15:09 +00:00
typedef struct {
unsigned char msec ;
unsigned short angles [ 3 ] ;
short forwardmove , sidemove , upmove ;
unsigned char buttons ;
unsigned char impulse ;
} usercmd_t ;
extern const usercmd_t nullcmd ;
2006-10-20 14:25:20 +00:00
typedef float vec3_t [ 3 ] ;
typedef struct {
float gravity ;
float maxspeed ;
float spectatormaxspeed ;
float accelerate ;
float airaccelerate ;
float waterfriction ;
float entgrav ;
float stopspeed ;
float wateraccelerate ;
float friction ;
} movevars_t ;
typedef struct {
//in / out
vec3_t origin ;
vec3_t velocity ;
//in
usercmd_t cmd ;
movevars_t movevars ;
//internal
vec3_t angles ;
float frametime ;
vec3_t forward , right , up ;
} pmove_t ;
2005-09-06 01:09:36 +00:00
# define MAX_BACK_BUFFERS 16
2005-10-07 02:02:15 +00:00
typedef struct sv_s sv_t ;
typedef struct cluster_s cluster_t ;
2005-09-06 01:09:36 +00:00
typedef struct viewer_s {
qboolean drop ;
2006-09-17 01:27:32 +00:00
unsigned int timeout ;
unsigned int nextpacket ; //for nq clients
2005-09-06 01:09:36 +00:00
netchan_t netchan ;
qboolean maysend ;
qboolean chokeme ;
qboolean thinksitsconnected ;
2006-10-07 22:29:31 +00:00
qboolean conmenussupported ;
2007-03-18 05:07:10 +00:00
qboolean isproxy ;
2005-09-06 01:09:36 +00:00
int delta_frame ;
2005-10-07 02:02:15 +00:00
int servercount ;
2005-09-06 01:09:36 +00:00
netmsg_t backbuf [ MAX_BACK_BUFFERS ] ; //note data is malloced!
int backbuffered ;
unsigned int currentstats [ MAX_STATS ] ;
2006-04-11 22:15:09 +00:00
int trackplayer ;
int thisplayer ;
2006-11-03 15:53:04 +00:00
int userid ;
2005-09-06 01:09:36 +00:00
packet_entities_t frame [ ENTITY_FRAMES ] ;
struct viewer_s * next ;
2006-11-03 15:53:04 +00:00
struct viewer_s * commentator ;
2005-09-06 01:09:36 +00:00
2005-09-24 04:48:20 +00:00
char name [ 32 ] ;
2006-10-20 14:25:20 +00:00
char userinfo [ 1024 ] ;
2006-04-11 22:15:09 +00:00
int lost ; //packets
usercmd_t ucmds [ 3 ] ;
2005-09-24 04:48:20 +00:00
int settime ; //the time that we last told the client.
2006-10-20 14:25:20 +00:00
vec3_t velocity ;
vec3_t origin ;
2005-10-07 02:02:15 +00:00
2006-02-20 01:33:13 +00:00
int isadmin ;
char expectcommand [ 16 ] ;
2005-10-07 02:02:15 +00:00
sv_t * server ;
2007-03-18 05:07:10 +00:00
int menuspamtime ;
2005-10-07 02:02:15 +00:00
int menunum ;
int menuop ;
int fwdval ; //for scrolling up/down the menu using +forward/+back :)
2005-09-06 01:09:36 +00:00
} viewer_t ;
2006-09-17 01:27:32 +00:00
//'other proxy', these are mvd stream clients.
2005-09-06 01:09:36 +00:00
typedef struct oproxy_s {
2006-09-17 01:27:32 +00:00
int authkey ;
unsigned int droptime ;
2005-09-06 01:09:36 +00:00
qboolean flushing ;
qboolean drop ;
2005-09-24 04:48:20 +00:00
2006-09-17 01:27:32 +00:00
sv_t * defaultstream ;
2007-03-16 04:05:01 +00:00
FILE * srcfile ; //buffer is padded with data from this file when its empty
FILE * file ; //recording a demo (written to)
2006-09-17 01:27:32 +00:00
SOCKET sock ; //playing to a proxy
unsigned char inbuffer [ MAX_PROXY_INBUFFER ] ;
unsigned int inbuffersize ; //amount of data available.
2005-09-24 04:48:20 +00:00
2005-09-06 01:09:36 +00:00
unsigned char buffer [ MAX_PROXY_BUFFER ] ;
unsigned int buffersize ; //use cyclic buffering.
unsigned int bufferpos ;
struct oproxy_s * next ;
} oproxy_t ;
typedef struct {
short origin [ 3 ] ;
unsigned char soundindex ;
unsigned char volume ;
unsigned char attenuation ;
} staticsound_t ;
2005-09-24 04:48:20 +00:00
typedef struct bsp_s bsp_t ;
typedef struct {
entity_state_t baseline ;
2006-12-26 21:26:10 +00:00
// entity_state_t current;
// entity_state_t old;
// unsigned int updatetime; //to stop lerping when it's an old entity (bodies, stationary grenades, ...)
2005-09-24 04:48:20 +00:00
int leafcount ;
unsigned short leafs [ MAX_ENTITY_LEAFS ] ;
} entity_t ;
2006-10-07 22:29:31 +00:00
# define MAX_ENTITY_FRAMES 64
typedef struct {
2006-12-26 21:26:10 +00:00
int oldframe ;
2006-10-07 22:29:31 +00:00
int numents ;
int maxents ;
2006-12-26 21:26:10 +00:00
entity_state_t * ents ; //dynamically allocated
unsigned short * entnums ; //dynamically allocated
2006-10-07 22:29:31 +00:00
} frame_t ;
2006-02-21 19:55:12 +00:00
typedef struct {
2006-04-11 22:15:09 +00:00
unsigned char number ;
char bits [ 6 ] ;
} nail_t ;
2006-02-21 19:55:12 +00:00
2007-01-06 09:46:32 +00:00
typedef struct {
float pos [ 3 ] ;
float angle [ 3 ] ;
} intermission_t ;
2007-01-09 05:24:03 +00:00
struct sv_s { //details about a server connection (also known as stream)
2006-09-17 01:27:32 +00:00
char connectpassword [ 64 ] ; //password given to server
2005-09-06 01:09:36 +00:00
netadr_t serveraddress ;
2006-02-21 19:55:12 +00:00
netchan_t netchan ;
2007-03-03 21:39:06 +00:00
qboolean serverquery ;
2005-09-06 01:09:36 +00:00
2007-03-18 05:07:10 +00:00
//proxy chaining
qboolean serverisproxy ;
qboolean proxyisselected ;
//
2005-09-06 01:09:36 +00:00
unsigned char buffer [ MAX_PROXY_BUFFER ] ; //this doesn't cycle.
int buffersize ; //it memmoves down
2006-09-19 01:48:12 +00:00
int forwardpoint ; //the point in the stream that we're forwarded up to.
2006-09-17 01:27:32 +00:00
qboolean parsingqtvheader ;
unsigned char upstreambuffer [ 2048 ] ;
int upstreambuffersize ;
2005-09-06 01:09:36 +00:00
unsigned int parsetime ;
char gamedir [ MAX_QPATH ] ;
char mapname [ 256 ] ;
2006-10-20 14:25:20 +00:00
movevars_t movevars ;
2005-09-06 01:09:36 +00:00
int cdtrack ;
2005-09-24 04:48:20 +00:00
entity_t entity [ MAX_ENTITIES ] ;
2006-10-07 22:29:31 +00:00
frame_t frame [ MAX_ENTITY_FRAMES ] ;
2006-12-26 21:26:10 +00:00
// int maxents;
2005-09-06 01:09:36 +00:00
staticsound_t staticsound [ MAX_STATICSOUNDS ] ;
int staticsound_count ;
2005-09-24 04:48:20 +00:00
entity_state_t spawnstatic [ MAX_STATICENTITIES ] ;
int spawnstatic_count ;
2005-09-06 01:09:36 +00:00
filename_t lightstyle [ MAX_LIGHTSTYLES ] ;
char serverinfo [ MAX_SERVERINFO_STRING ] ;
2005-10-07 02:02:15 +00:00
char hostname [ MAX_QPATH ] ;
2005-09-06 01:09:36 +00:00
playerinfo_t players [ MAX_CLIENTS ] ;
filename_t modellist [ MAX_MODELS ] ;
filename_t soundlist [ MAX_SOUNDS ] ;
int modelindex_spike ; // qw is wierd.
2006-02-21 19:55:12 +00:00
int modelindex_player ; // qw is wierd.
2006-04-11 22:15:09 +00:00
FILE * downloadfile ;
char downloadname [ 256 ] ;
char status [ 64 ] ;
nail_t nails [ 32 ] ;
int nailcount ;
2007-05-28 02:31:48 +00:00
qboolean silentstream ;
2006-02-21 19:55:12 +00:00
qboolean usequkeworldprotocols ;
int challenge ;
unsigned short qport ;
int isconnected ;
int clservercount ;
unsigned int nextsendpings ;
2006-04-11 22:15:09 +00:00
int trackplayer ;
2006-02-21 19:55:12 +00:00
int thisplayer ;
2006-02-21 23:25:54 +00:00
unsigned int timeout ;
qboolean ispaused ;
unsigned int packetratelimiter ;
2007-01-09 05:24:03 +00:00
2006-04-11 22:15:09 +00:00
viewer_t * controller ;
2007-01-09 05:24:03 +00:00
int controllersquencebias ;
2006-09-17 01:27:32 +00:00
qboolean proxyplayer ; //a player is actually playing on the proxy.
usercmd_t proxyplayerucmds [ 3 ] ;
int proxyplayerucmdnum ;
int proxyplayerbuttons ;
float proxyplayerangles [ 3 ] ;
float proxyplayerimpulse ;
2006-04-11 23:26:39 +00:00
qboolean maysend ;
2005-09-06 01:09:36 +00:00
2006-10-22 19:18:15 +00:00
FILE * sourcefile ;
2005-09-06 01:09:36 +00:00
unsigned int filelength ;
SOCKET sourcesock ;
2007-01-09 05:24:03 +00:00
// SOCKET tcpsocket; //tcp + mvd protocol
// int tcplistenportnum;
2005-09-06 01:09:36 +00:00
oproxy_t * proxies ;
qboolean parsingconnectiondata ; //so reject any new connects for now
2005-09-24 04:48:20 +00:00
unsigned int physicstime ; //the last time all the ents moved.
2006-02-21 23:25:54 +00:00
unsigned int simtime ;
2005-09-06 01:09:36 +00:00
unsigned int curtime ;
unsigned int oldpackettime ;
unsigned int nextpackettime ;
2006-02-21 19:55:12 +00:00
unsigned int nextconnectattempt ;
2006-04-11 22:15:09 +00:00
qboolean drop ;
2006-02-21 19:55:12 +00:00
qboolean disconnectwhennooneiswatching ;
unsigned int numviewers ;
2005-09-06 01:09:36 +00:00
2005-10-07 02:02:15 +00:00
cluster_t * cluster ;
sv_t * next ; //next proxy->server connection
2005-09-24 04:48:20 +00:00
bsp_t * bsp ;
int numinlines ;
2005-09-06 01:09:36 +00:00
2006-10-07 22:29:31 +00:00
# ifdef COMMENTARY
2006-09-19 01:48:12 +00:00
//audio stuff
soundcapt_t * comentrycapture ;
2006-10-07 22:29:31 +00:00
# endif
2006-09-19 01:48:12 +00:00
2005-09-06 01:09:36 +00:00
//options:
2005-10-07 02:02:15 +00:00
char server [ MAX_QPATH ] ;
2006-09-17 01:27:32 +00:00
int streamid ;
2005-10-09 09:40:26 +00:00
} ;
2005-10-07 02:02:15 +00:00
2007-03-03 18:46:43 +00:00
typedef struct {
char name [ 64 ] ;
int size ;
int time , smalltime ;
} availdemo_t ;
2005-10-09 09:40:26 +00:00
struct cluster_s {
2005-10-07 02:02:15 +00:00
SOCKET qwdsocket ; //udp + quakeworld protocols
2006-09-17 01:27:32 +00:00
SOCKET tcpsocket ; //tcp listening socket (for mvd and listings and stuff)
2005-10-07 02:02:15 +00:00
char commandinput [ 512 ] ;
int inputlength ;
unsigned int mastersendtime ;
unsigned int mastersequence ;
unsigned int curtime ;
viewer_t * viewers ;
int numviewers ;
sv_t * servers ;
int numservers ;
2006-09-17 01:27:32 +00:00
int nextstreamid ;
2006-11-03 15:53:04 +00:00
int nextuserid ;
2005-10-07 02:02:15 +00:00
2006-12-26 21:26:10 +00:00
sv_t * viewserver ;
2005-10-07 02:02:15 +00:00
//options
int qwlistenportnum ;
2006-09-17 01:27:32 +00:00
int tcplistenportnum ;
char adminpassword [ 256 ] ; //password required for rcon etc
char qtvpassword [ 256 ] ; //password required to connect a proxy
2005-09-24 04:48:20 +00:00
char hostname [ 256 ] ;
char master [ MAX_QPATH ] ;
2005-10-07 02:02:15 +00:00
qboolean chokeonnotupdated ;
qboolean lateforward ;
qboolean notalking ;
2005-09-24 04:48:20 +00:00
qboolean nobsp ;
2006-10-07 22:29:31 +00:00
qboolean allownqclients ; //nq clients require no challenge
qboolean nouserconnects ; //prohibit users from connecting to new streams.
2006-09-17 01:27:32 +00:00
2005-09-25 20:50:57 +00:00
int maxviewers ;
2006-09-17 01:27:32 +00:00
2006-10-07 22:29:31 +00:00
int buildnumber ;
2006-09-17 01:27:32 +00:00
int numproxies ;
2005-09-25 20:50:57 +00:00
int maxproxies ;
2005-09-06 01:09:36 +00:00
2005-10-09 09:40:26 +00:00
qboolean wanttoexit ;
2005-10-07 02:02:15 +00:00
2006-09-17 01:27:32 +00:00
oproxy_t * pendingproxies ;
2007-03-03 18:46:43 +00:00
char demodir [ 128 ] ;
availdemo_t availdemos [ 2048 ] ;
int availdemoscount ;
2005-10-09 09:40:26 +00:00
} ;
2005-09-06 01:09:36 +00:00
2007-01-09 05:24:03 +00:00
# define MENU_NONE 0
2007-03-18 05:07:10 +00:00
# define MENU_MAIN 1 //MENU_SERVERS
# define MENU_SERVERS 2
# define MENU_CLIENTS 3
# define MENU_ADMIN 4
# define MENU_ADMINSERVER 5
# define MENU_DEMOS 6
# define MENU_FORWARDING 7
# define MENU_DEFAULT MENU_MAIN
2005-09-06 01:09:36 +00:00
2007-03-18 05:07:10 +00:00
enum {
MENU_MAIN_STREAMS ,
MENU_MAIN_NEWSTREAM ,
MENU_MAIN_FIXME ,
MENU_MAIN_PREVPROX ,
2005-09-06 01:09:36 +00:00
2007-03-18 05:07:10 +00:00
MENU_MAIN_CLIENTLIST ,
MENU_MAIN_DEMOS ,
MENU_MAIN_ADMIN ,
MENU_MAIN_NEXTPROX ,
MENU_MAIN_ITEMCOUNT
} ;
2005-09-06 01:09:36 +00:00
unsigned char ReadByte ( netmsg_t * b ) ;
unsigned short ReadShort ( netmsg_t * b ) ;
unsigned int ReadLong ( netmsg_t * b ) ;
float ReadFloat ( netmsg_t * b ) ;
void ReadString ( netmsg_t * b , char * string , int maxlen ) ;
2006-09-17 02:35:23 +00:00
unsigned int SwapLong ( unsigned int val ) ;
unsigned int BigLong ( unsigned int val ) ;
2005-09-06 01:09:36 +00:00
# define clc_bad 0
# define clc_nop 1
2006-09-17 01:27:32 +00:00
# define clc_disconnect 2 //NQ only
2005-09-06 01:09:36 +00:00
# define clc_move 3 // [[usercmd_t]
# define clc_stringcmd 4 // [string] message
# define clc_delta 5 // [byte] sequence number, requests delta compression of message
# define clc_tmove 6 // teleport request, spectator only
# define clc_upload 7 // teleport request, spectator only
# define svc_bad 0
# define svc_nop 1
2005-09-24 04:48:20 +00:00
# define svc_disconnect 2
2005-09-06 01:09:36 +00:00
# define svc_updatestat 3 // [qbyte] [qbyte]
//#define svc_version 4 // [long] server version
2006-09-17 01:27:32 +00:00
# define svc_nqsetview 5 // [short] entity number
2005-09-06 01:09:36 +00:00
# define svc_sound 6 // <see code>
2006-09-17 01:27:32 +00:00
# define svc_nqtime 7 // [float] server time
2005-09-06 01:09:36 +00:00
# define svc_print 8 // [qbyte] id [string] null terminated string
# define svc_stufftext 9 // [string] stuffed into client's console buffer
// the string should be \n terminated
# define svc_setangle 10 // [angle3] set the view angle to this absolute value
# define svc_serverdata 11 // [long] protocol ...
# define svc_lightstyle 12 // [qbyte] [string]
2006-09-17 01:27:32 +00:00
# define svc_nqupdatename 13 // [qbyte] [string]
2005-09-06 01:09:36 +00:00
# define svc_updatefrags 14 // [qbyte] [short]
2006-09-17 01:27:32 +00:00
# define svc_nqclientdata 15 // <shortbits + data>
2005-09-06 01:09:36 +00:00
//#define svc_stopsound 16 // <see code>
2006-09-17 01:27:32 +00:00
# define svc_nqupdatecolors 17 // [qbyte] [qbyte] [qbyte]
2006-04-11 22:15:09 +00:00
# define svc_particle 18 // [vec3] <variable>
2005-09-06 01:09:36 +00:00
# define svc_damage 19
2005-09-25 20:50:57 +00:00
2005-09-24 04:48:20 +00:00
# define svc_spawnstatic 20
2005-09-06 01:09:36 +00:00
//#define svc_spawnstatic2 21
# define svc_spawnbaseline 22
2005-09-25 20:50:57 +00:00
2005-09-06 01:09:36 +00:00
# define svc_temp_entity 23 // variable
2006-02-21 23:25:54 +00:00
# define svc_setpause 24 // [qbyte] on / off
2006-09-17 01:27:32 +00:00
# define svc_nqsignonnum 25 // [qbyte] used for the signon sequence
2005-09-06 01:09:36 +00:00
# define svc_centerprint 26 // [string] to put in center of the screen
2007-05-28 02:31:48 +00:00
# define svc_killedmonster 27
# define svc_foundsecret 28
2005-09-06 01:09:36 +00:00
# define svc_spawnstaticsound 29 // [coord3] [qbyte] samp [qbyte] vol [qbyte] aten
2005-09-24 04:48:20 +00:00
# define svc_intermission 30 // [vec3_t] origin [vec3_t] angle
2005-09-06 01:09:36 +00:00
//#define svc_finale 31 // [string] text
# define svc_cdtrack 32 // [qbyte] track
//#define svc_sellscreen 33
//#define svc_cutscene 34 //hmm... nq only... added after qw tree splitt?
# define svc_smallkick 34 // set client punchangle to 2
# define svc_bigkick 35 // set client punchangle to 4
# define svc_updateping 36 // [qbyte] [short]
# define svc_updateentertime 37 // [qbyte] [float]
# define svc_updatestatlong 38 // [qbyte] [long]
# define svc_muzzleflash 39 // [short] entity
# define svc_updateuserinfo 40 // [qbyte] slot [long] uid
// [string] userinfo
# define svc_download 41 // [short] size [size bytes]
# define svc_playerinfo 42 // variable
2006-02-21 23:25:54 +00:00
# define svc_nails 43 // [qbyte] num [48 bits] xyzpy 12 12 12 4 8
2005-09-06 01:09:36 +00:00
# define svc_chokecount 44 // [qbyte] packets choked
# define svc_modellist 45 // [strings]
# define svc_soundlist 46 // [strings]
# define svc_packetentities 47 // [...]
# define svc_deltapacketentities 48 // [...]
2006-04-11 22:15:09 +00:00
# define svc_maxspeed 49 // maxspeed change, for prediction
2006-02-21 19:55:12 +00:00
# define svc_entgravity 50 // gravity change, for prediction
2005-10-07 02:02:15 +00:00
# define svc_setinfo 51 // setinfo on a client
2005-09-06 01:09:36 +00:00
# define svc_serverinfo 52 // serverinfo
# define svc_updatepl 53 // [qbyte] [qbyte]
2006-02-20 01:33:13 +00:00
# define svc_nails2 54 //qwe - [qbyte] num [52 bits] nxyzpy 8 12 12 12 4 8
2005-09-06 01:09:36 +00:00
2006-09-19 01:48:12 +00:00
# define dem_audio 0
2005-09-06 01:09:36 +00:00
# define dem_cmd 0
# define dem_read 1
# define dem_set 2
# define dem_multiple 3
2005-09-24 04:48:20 +00:00
# define dem_single 4
2005-09-06 01:09:36 +00:00
# define dem_stats 5
# define dem_all 6
# define dem_mask 7
2006-09-17 01:27:32 +00:00
# define PROTOCOL_VERSION_NQ 15
2005-09-06 01:09:36 +00:00
# define PROTOCOL_VERSION 28
//flags on entities
# define U_ORIGIN1 (1<<9)
# define U_ORIGIN2 (1<<10)
# define U_ORIGIN3 (1<<11)
# define U_ANGLE2 (1<<12)
# define U_FRAME (1<<13)
# define U_REMOVE (1<<14) // REMOVE this entity, don't add it
# define U_MOREBITS (1<<15)
// if MOREBITS is set, these additional flags are read in next
# define U_ANGLE1 (1<<0)
# define U_ANGLE3 (1<<1)
# define U_MODEL (1<<2)
# define U_COLORMAP (1<<3)
# define U_SKIN (1<<4)
# define U_EFFECTS (1<<5)
# define U_SOLID (1<<6) // the entity should be solid for prediction
//flags on players
# define PF_MSEC (1<<0)
# define PF_COMMAND (1<<1)
# define PF_VELOCITY1 (1<<2)
# define PF_VELOCITY2 (1<<3)
# define PF_VELOCITY3 (1<<4)
# define PF_MODEL (1<<5)
# define PF_SKINNUM (1<<6)
# define PF_EFFECTS (1<<7)
# define PF_WEAPONFRAME (1<<8) // only sent for view player
# define PF_DEAD (1<<9) // don't block movement any more
# define PF_GIB (1<<10) // offset the view height differently
2007-03-18 05:07:10 +00:00
//flags on players in mvds
# define DF_ORIGIN 1
# define DF_ANGLES (1<<3)
# define DF_EFFECTS (1<<6)
# define DF_SKINNUM (1<<7)
# define DF_DEAD (1<<8)
# define DF_GIB (1<<9)
# define DF_WEAPONFRAME (1<<10)
# define DF_MODEL (1<<11)
2005-09-06 01:09:36 +00:00
2006-09-17 01:27:32 +00:00
//flags for where a message can be sent, for easy broadcasting
# define Q1 (NQ|QW)
# define QW 1
# define NQ 2
2006-09-19 01:48:12 +00:00
# define CONNECTING 4
2005-09-06 01:09:36 +00:00
void InitNetMsg ( netmsg_t * b , char * buffer , int bufferlength ) ;
unsigned char ReadByte ( netmsg_t * b ) ;
unsigned short ReadShort ( netmsg_t * b ) ;
unsigned int ReadLong ( netmsg_t * b ) ;
float ReadFloat ( netmsg_t * b ) ;
void ReadString ( netmsg_t * b , char * string , int maxlen ) ;
void WriteByte ( netmsg_t * b , unsigned char c ) ;
void WriteShort ( netmsg_t * b , unsigned short l ) ;
void WriteLong ( netmsg_t * b , unsigned int l ) ;
void WriteFloat ( netmsg_t * b , float f ) ;
void WriteString2 ( netmsg_t * b , const char * str ) ;
void WriteString ( netmsg_t * b , const char * str ) ;
void WriteData ( netmsg_t * b , const char * data , int length ) ;
2006-09-17 01:27:32 +00:00
void Multicast ( sv_t * tv , char * buffer , int length , int to , unsigned int playermask , int suitablefor ) ;
void Broadcast ( cluster_t * cluster , char * buffer , int length , int suitablefor ) ;
2005-09-06 01:09:36 +00:00
void ParseMessage ( sv_t * tv , char * buffer , int length , int to , int mask ) ;
2006-11-03 15:53:04 +00:00
void BuildServerData ( sv_t * tv , netmsg_t * msg , int servercount , viewer_t * spectatorflag ) ;
2006-09-17 01:27:32 +00:00
void BuildNQServerData ( sv_t * tv , netmsg_t * msg , qboolean mvd , int servercount ) ;
2005-09-06 01:09:36 +00:00
SOCKET QW_InitUDPSocket ( int port ) ;
2005-10-07 02:02:15 +00:00
void QW_UpdateUDPStuff ( cluster_t * qtv ) ;
2005-09-24 04:48:20 +00:00
unsigned int Sys_Milliseconds ( void ) ;
void Prox_SendInitialEnts ( sv_t * qtv , oproxy_t * prox , netmsg_t * msg ) ;
qboolean QTV_Connect ( sv_t * qtv , char * serverurl ) ;
2006-02-20 01:33:13 +00:00
void QTV_Shutdown ( sv_t * qtv ) ;
2006-04-11 22:15:09 +00:00
qboolean NET_StringToAddr ( char * s , netadr_t * sadr , int defaultport ) ;
2005-09-24 04:48:20 +00:00
void SendBufferToViewer ( viewer_t * v , const char * buffer , int length , qboolean reliable ) ;
2006-02-20 01:33:13 +00:00
void QW_PrintfToViewer ( viewer_t * v , char * format , . . . ) ;
void QW_StuffcmdToViewer ( viewer_t * v , char * format , . . . ) ;
2005-09-24 04:48:20 +00:00
2006-10-20 14:25:20 +00:00
void PM_PlayerMove ( pmove_t * pmove ) ;
2006-02-21 19:55:12 +00:00
void Netchan_Setup ( SOCKET sock , netchan_t * chan , netadr_t adr , int qport , qboolean isclient ) ;
2005-10-07 02:02:15 +00:00
void Netchan_OutOfBandPrint ( cluster_t * cluster , SOCKET sock , netadr_t adr , char * format , . . . ) ;
2006-02-20 01:33:13 +00:00
int Netchan_IsLocal ( netadr_t adr ) ;
2005-10-07 02:02:15 +00:00
void NET_SendPacket ( cluster_t * cluster , SOCKET sock , int length , char * data , netadr_t adr ) ;
2005-09-24 04:48:20 +00:00
qboolean Net_CompareAddress ( netadr_t * s1 , netadr_t * s2 , int qp1 , int qp2 ) ;
qboolean Netchan_Process ( netchan_t * chan , netmsg_t * msg ) ;
2006-09-17 02:35:23 +00:00
qboolean NQNetchan_Process ( cluster_t * cluster , netchan_t * chan , netmsg_t * msg ) ;
2005-10-07 02:02:15 +00:00
void Netchan_Transmit ( cluster_t * cluster , netchan_t * chan , int length , const unsigned char * data ) ;
2006-10-22 20:31:57 +00:00
void Netchan_OutOfBand ( cluster_t * cluster , SOCKET sock , netadr_t adr , int length , unsigned char * data ) ;
qboolean Netchan_CanPacket ( netchan_t * chan ) ;
2005-10-07 02:02:15 +00:00
int SendList ( sv_t * qtv , int first , const filename_t * list , int svc , netmsg_t * msg ) ;
2006-04-11 22:15:09 +00:00
int Prespawn ( sv_t * qtv , int curmsgsize , netmsg_t * msg , int bufnum , int thisplayer ) ;
2005-09-24 04:48:20 +00:00
2005-10-07 02:02:15 +00:00
bsp_t * BSP_LoadModel ( cluster_t * cluster , char * gamedir , char * bspname ) ;
2005-09-24 04:48:20 +00:00
void BSP_Free ( bsp_t * bsp ) ;
int BSP_LeafNum ( bsp_t * bsp , float x , float y , float z ) ;
2006-02-21 23:25:54 +00:00
unsigned int BSP_Checksum ( bsp_t * bsp ) ;
2005-09-24 04:48:20 +00:00
int BSP_SphereLeafNums ( bsp_t * bsp , int maxleafs , unsigned short * list , float x , float y , float z , float radius ) ;
qboolean BSP_Visible ( bsp_t * bsp , int leafcount , unsigned short * list ) ;
void BSP_SetupForPosition ( bsp_t * bsp , float x , float y , float z ) ;
2007-01-06 09:46:32 +00:00
const intermission_t * BSP_IntermissionSpot ( bsp_t * bsp ) ;
void QW_SetViewersServer ( cluster_t * cluster , viewer_t * viewer , sv_t * sv ) ;
2006-06-10 22:15:24 +00:00
unsigned short QCRC_Block ( unsigned char * start , int count ) ;
2006-09-17 01:27:32 +00:00
unsigned short QCRC_Value ( unsigned short crcvalue ) ;
2006-06-10 22:15:24 +00:00
void WriteDeltaUsercmd ( netmsg_t * m , const usercmd_t * from , usercmd_t * move ) ;
void SendClientCommand ( sv_t * qtv , char * fmt , . . . ) ;
void QTV_Run ( sv_t * qtv ) ;
2006-09-17 02:35:23 +00:00
void QW_FreeViewer ( cluster_t * cluster , viewer_t * viewer ) ;
2006-10-07 22:37:40 +00:00
void QW_SetMenu ( viewer_t * v , int menunum ) ;
2005-09-24 04:48:20 +00:00
2005-10-07 02:02:15 +00:00
char * Rcon_Command ( cluster_t * cluster , sv_t * qtv , char * command , char * buffer , int sizeofbuffer , qboolean localcommand ) ;
2005-09-24 04:48:20 +00:00
char * COM_ParseToken ( char * data , char * out , int outsize , const char * punctuation ) ;
char * Info_ValueForKey ( char * s , const char * key , char * buffer , int buffersize ) ;
void Info_SetValueForStarKey ( char * s , const char * key , const char * value , int maxsize ) ;
2006-06-10 22:15:24 +00:00
void ReadDeltaUsercmd ( netmsg_t * m , const usercmd_t * from , usercmd_t * move ) ;
unsigned Com_BlockChecksum ( void * buffer , int length ) ;
2006-09-17 01:27:32 +00:00
void Com_BlockFullChecksum ( void * buffer , int len , unsigned char * outbuf ) ;
2007-03-16 04:05:01 +00:00
void Cluster_BuildAvailableDemoList ( cluster_t * cluster ) ;
2005-09-24 04:48:20 +00:00
2005-10-07 02:02:15 +00:00
void Sys_Printf ( cluster_t * cluster , char * fmt , . . . ) ;
2007-03-16 04:05:01 +00:00
void Net_ProxySend ( cluster_t * cluster , oproxy_t * prox , char * buffer , int length ) ;
2006-09-17 01:27:32 +00:00
oproxy_t * Net_FileProxy ( sv_t * qtv , char * filename ) ;
2007-03-03 21:39:06 +00:00
sv_t * QTV_NewServerConnection ( cluster_t * cluster , char * server , char * password , qboolean force , qboolean autoclose , qboolean noduplicates , qboolean query ) ;
2005-10-07 02:02:15 +00:00
SOCKET Net_MVDListen ( int port ) ;
qboolean Net_StopFileProxy ( sv_t * qtv ) ;
2006-09-17 01:27:32 +00:00
void SV_FindProxies ( SOCKET sock , cluster_t * cluster , sv_t * defaultqtv ) ;
qboolean SV_ReadPendingProxy ( cluster_t * cluster , oproxy_t * pend ) ;
void SV_ForwardStream ( sv_t * qtv , char * buffer , int length ) ;
unsigned char * FS_ReadFile ( char * gamedir , char * filename , unsigned int * size ) ;
void ChooseFavoriteTrack ( sv_t * tv ) ;
void DemoViewer_Update ( sv_t * svtest ) ;
2007-03-16 04:05:01 +00:00
//httpsv.c
void HTTPSV_GetMethod ( cluster_t * cluster , oproxy_t * pend ) ;
void HTTPSV_PostMethod ( cluster_t * cluster , oproxy_t * pend , char * postdata ) ;
2006-09-17 01:27:32 +00:00
# ifdef __cplusplus
}
# endif