"it compiles, but it's a dirty hack"

This commit is contained in:
Bill Currie 2003-02-10 21:06:03 +00:00
parent 2dc7cbaef0
commit 36c67684a4
6 changed files with 718 additions and 977 deletions

View file

@ -57,13 +57,6 @@
//Typedefs //Typedefs
typedef struct
{
byte ip[4];
unsigned short port;
unsigned short pad;
} netadr_t;
typedef struct server_s typedef struct server_s
{ {
netadr_t ip; netadr_t ip;
@ -75,128 +68,36 @@ typedef struct server_s
double timeout; double timeout;
} server_t; } server_t;
typedef struct sizebuf_s
{
qboolean allowoverflow; // if false, do a Sys_Error
qboolean overflowed; // set to true if the buffer size failed
byte *data;
int maxsize;
int cursize;
} sizebuf_t;
typedef void (*xcommand_t) (void);
typedef struct cmd_function_s
{
struct cmd_function_s *next;
char *name;
xcommand_t function;
} cmd_function_t;
//Function prototypes //Function prototypes
//net_test.cpp //net_test.cpp
void COM_Init (void);
int COM_CheckParm (char *parm);
char *COM_Parse (char *data);
void Sys_Error (char *error, ...);
void Sys_Quit (void);
void SZ_Clear (sizebuf_t *buf);
void *SZ_GetSpace (sizebuf_t *buf, int length);
void SZ_Write (sizebuf_t *buf, void *data, int length);
char *Sys_ConsoleInput (void);
void SV_GetConsoleCommands (void); void SV_GetConsoleCommands (void);
void SV_Frame(); void SV_Frame(void);
void SV_Shutdown(); void SV_Shutdown(void);
double Sys_DoubleTime (void); double Sys_DoubleTime (void);
//cmds.cpp
int Cmd_Argc (void);
char *Cmd_Argv (int arg);
void Cmd_TokenizeString (char *text);
void Cmd_AddCommand (char *cmd_name, xcommand_t function);
void Cmd_Init();
void Cmd_ExecuteString (char *text);
void Cbuf_Init (void);
void Cbuf_AddText (char *text);
void Cbuf_InsertText (char *text);
void Cbuf_Execute (void);
qboolean Cmd_Exists (char *cmd_name);
void Cmd_Quit_f();
void Cmd_ServerList_f();
//net.cpp //net.cpp
void MSG_WriteChar (sizebuf_t *sb, int c);
void MSG_WriteByte (sizebuf_t *sb, int c);
void MSG_WriteShort (sizebuf_t *sb, int c);
void MSG_WriteLong (sizebuf_t *sb, int c);
void MSG_WriteFloat (sizebuf_t *sb, float f);
void MSG_WriteString (sizebuf_t *sb, char *s);
void MSG_BeginReading (void);
int MSG_GetReadCount(void);
int MSG_ReadChar (void);
int MSG_ReadByte (void);
int MSG_ReadShort (void);
int MSG_ReadLong (void);
float MSG_ReadFloat (void);
char *MSG_ReadString (void);
char *MSG_ReadStringLine (void);
void NET_Init (int port);
void SV_InitNet (void); void SV_InitNet (void);
int UDP_OpenSocket (int port); int UDP_OpenSocket (int port);
void NET_Shutdown (void);
void NET_GetLocalAddress();
char *NET_AdrToString (netadr_t a);
qboolean NET_StringToAdr (char *s, netadr_t *a);
void NetadrToSockadr (netadr_t *a, struct sockaddr_in *s);
void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a);
void NET_SendPacket (int length, void *data, netadr_t to);
void SV_ReadPackets (void); void SV_ReadPackets (void);
qboolean NET_GetPacket (void);
void SV_ConnectionlessPacket (void); void SV_ConnectionlessPacket (void);
void NET_CopyAdr (netadr_t *a, netadr_t *b); void NET_CopyAdr (netadr_t *a, netadr_t *b);
qboolean NET_CompareAdr (netadr_t a, netadr_t b);
qboolean NET_CompareAdrNoPort (netadr_t a, netadr_t b);
void SVL_Add(server_t *sv); void SVL_Add(server_t *sv);
void SVL_Remove(server_t *sv); void SVL_Remove(server_t *sv);
void SVL_Clear(); void SVL_Clear(void);
server_t* SVL_Find(netadr_t adr); server_t* SVL_Find(netadr_t adr);
server_t* SVL_New(); server_t* SVL_New(netadr_t *adr);
server_t* SVL_New(netadr_t adr); void Cmd_Filter_f(void);
void Cmd_Filter_f();
//Globals //Globals
extern cmd_function_t *cmd_functions; // possible commands to execute
extern sizebuf_t cmd_text;
extern byte cmd_text_buf[8192];
extern int cmd_argc;
extern char *cmd_argv[MAX_ARGS];
extern char *cmd_null_string;
extern char *cmd_args;
extern char com_token[1024];
extern int com_argc;
extern char **com_argv;
extern char *largv[MAX_NUM_ARGVS + 1];
extern char *argvdummy;
extern sizebuf_t net_message;
extern int net_socket; extern int net_socket;
//extern WSADATA winsockdata; //extern WSADATA winsockdata;
extern netadr_t net_local_adr;
extern netadr_t master_adr[MAX_MASTERS]; // address of group servers
extern int num_masters; extern int num_masters;
extern short (*BigShort) (short l); extern short (*BigShort) (short l);
@ -206,8 +107,6 @@ extern int (*LittleLong) (int l);
extern float (*BigFloat) (float l); extern float (*BigFloat) (float l);
extern float (*LittleFloat) (float l); extern float (*LittleFloat) (float l);
extern netadr_t net_from;
extern int msg_readcount; extern int msg_readcount;
extern qboolean msg_badread; extern qboolean msg_badread;

View file

@ -33,14 +33,14 @@ AUTOMAKE_OPTIONS= foreign
INCLUDES= -I$(top_srcdir)/include -I$(top_srcdir)/hw/include INCLUDES= -I$(top_srcdir)/include -I$(top_srcdir)/hw/include
SDL_LIBS = @SDL_LIBS@ SDL_LIBS = @SDL_LIBS@
bin_PROGRAMS= @QW_TARGETS@ bin_PROGRAMS= @HW_TARGETS@
EXTRA_PROGRAMS= hw-master EXTRA_PROGRAMS= hw-master
common_ldflags= -export-dynamic common_ldflags= -export-dynamic
hw_master_SOURCES= master.c hw_master_SOURCES= master.c
hw_master_LDADD= $(top_builddir)/libs/util/libQFutil.la $(NET_LIBS) hw_master_LDADD= $(top_builddir)/qw/source/net_packetlog.o $(top_builddir)/qw/source/libnet.a $(SERVER_PLUGIN_STATIC_LIBS) $(top_builddir)/libs/console/libQFconsole.la $(top_builddir)/libs/util/libQFutil.la $(NET_LIBS)
hw_master_LDFLAGS= $(common_ldflags) -static hw_master_LDFLAGS= $(common_ldflags) -static
# Kill the temp files, hopefully. # Kill the temp files, hopefully.

View file

@ -1,244 +1,219 @@
#include "defs.h" #include "defs.h"
static int cmd_argc;
static int cmd_argc; static char *cmd_argv[MAX_ARGS];
static char *cmd_argv[MAX_ARGS]; static char *cmd_null_string = "";
static char *cmd_null_string = ""; static char *cmd_args = NULL;
static char *cmd_args = NULL; static cmd_function_t *cmd_functions; // possible commands to execute
int
static cmd_function_t *cmd_functions; // possible commands to execute Cmd_Argc (void)
int Cmd_Argc (void)
{ {
return cmd_argc; return cmd_argc;
} }
char *Cmd_Argv (int arg) char *
Cmd_Argv (int arg)
{ {
if ( arg >= cmd_argc ) if (arg >= cmd_argc)
return cmd_null_string; return cmd_null_string;
return cmd_argv[arg]; return cmd_argv[arg];
} }
void Cmd_TokenizeString (char *text) void
Cmd_TokenizeString (char *text)
{ {
int i; int i;
// clear the args from the last string // clear the args from the last string
for (i=0 ; i<cmd_argc ; i++) for (i = 0; i < cmd_argc; i++)
free (cmd_argv[i]); free (cmd_argv[i]);
cmd_argc = 0; cmd_argc = 0;
cmd_args = NULL; cmd_args = NULL;
while (1) {
while (1)
{
// skip whitespace up to a /n // skip whitespace up to a /n
while (*text && *text <= ' ' && *text != '\n') while (*text && *text <= ' ' && *text != '\n') {
{
text++; text++;
} }
if (*text == '\n') { // a newline seperates commands in the
if (*text == '\n') // buffer
{ // a newline seperates commands in the buffer
text++; text++;
break; break;
} }
if (!*text) if (!*text)
return; return;
if (cmd_argc == 1) if (cmd_argc == 1)
cmd_args = text; cmd_args = text;
text = COM_Parse (text); text = COM_Parse (text);
if (!text) if (!text)
return; return;
if (cmd_argc < MAX_ARGS) {
if (cmd_argc < MAX_ARGS) cmd_argv[cmd_argc] = (char *) malloc (strlen (com_token) + 1);
{
cmd_argv[cmd_argc] = (char *)malloc (strlen(com_token)+1);
strcpy (cmd_argv[cmd_argc], com_token); strcpy (cmd_argv[cmd_argc], com_token);
cmd_argc++; cmd_argc++;
} }
} }} void
Cmd_AddCommand (char *cmd_name, xcommand_t function)
}
void Cmd_AddCommand (char *cmd_name, xcommand_t function)
{ {
cmd_function_t *cmd; cmd_function_t *cmd;
// fail if the command already exists // fail if the command already exists
for (cmd=cmd_functions ; cmd ; cmd=cmd->next) for (cmd = cmd_functions; cmd; cmd = cmd->next) {
{ if (!strcmp (cmd_name, cmd->name)) {
if (!strcmp (cmd_name, cmd->name))
{
printf ("Cmd_AddCommand: %s already defined\n", cmd_name); printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
return; return;
} }
} }
cmd = (cmd_function_t *) malloc (sizeof (cmd_function_t));
cmd = (cmd_function_t *)malloc(sizeof(cmd_function_t));
cmd->name = cmd_name; cmd->name = cmd_name;
cmd->function = function; cmd->function = function;
cmd->next = cmd_functions; cmd->next = cmd_functions;
cmd_functions = cmd; cmd_functions = cmd;
} }
void Cmd_Init() void
Cmd_Init ()
{ {
Cmd_AddCommand("quit",Cmd_Quit_f); Cmd_AddCommand ("quit", Cmd_Quit_f);
Cmd_AddCommand("list",Cmd_ServerList_f); Cmd_AddCommand ("list", Cmd_ServerList_f);
Cmd_AddCommand("filter",Cmd_Filter_f); Cmd_AddCommand ("filter", Cmd_Filter_f);
} } void
Cmd_ExecuteString (char *text)
void Cmd_ExecuteString (char *text) {
{ cmd_function_t *cmd;
cmd_function_t *cmd;
Cmd_TokenizeString (text); Cmd_TokenizeString (text);
// execute the command line // execute the command line
if (!Cmd_Argc()) if (!Cmd_Argc ())
return; // no tokens return; // no tokens
// check functions // check functions
for (cmd=cmd_functions ; cmd ; cmd=cmd->next) for (cmd = cmd_functions; cmd; cmd = cmd->next) {
{ if (!strcmp (cmd_argv[0], cmd->name)) {
if (!strcmp(cmd_argv[0],cmd->name))
{
if (cmd->function) if (cmd->function)
cmd->function (); cmd->function ();
return; return;
} }
} }
printf ("Unknown command: %s\n", cmd_argv[0]);
printf("Unknown command: %s\n",cmd_argv[0]);
} }
void
void Cbuf_Init (void) Cbuf_Init (void)
{ {
cmd_text.data = cmd_text_buf; cmd_text.data = cmd_text_buf;
cmd_text.maxsize = sizeof(cmd_text_buf); cmd_text.maxsize = sizeof (cmd_text_buf);
} }
void Cbuf_AddText (char *text) void
Cbuf_AddText (char *text)
{ {
int l; int l;
l = strlen (text);
if (cmd_text.cursize + l >= cmd_text.maxsize) l = strlen (text);
{ if (cmd_text.cursize + l >= cmd_text.maxsize) {
printf ("Cbuf_AddText: overflow\n"); printf ("Cbuf_AddText: overflow\n");
return; return;
} }
SZ_Write (&cmd_text, text, strlen (text)); SZ_Write (&cmd_text, text, strlen (text));
} }
void Cbuf_InsertText (char *text) void
Cbuf_InsertText (char *text)
{ {
char *temp; char *temp;
int templen; int templen;
// copy off any commands still remaining in the exec buffer // copy off any commands still remaining in the exec buffer
templen = cmd_text.cursize; templen = cmd_text.cursize;
if (templen) if (templen) {
{ temp = (char *) malloc (templen);
temp = (char *)malloc (templen);
memcpy (temp, cmd_text.data, templen); memcpy (temp, cmd_text.data, templen);
SZ_Clear (&cmd_text); SZ_Clear (&cmd_text);
} }
else else
temp = NULL; // shut up compiler temp = NULL; // shut up compiler
// add the entire text of the file // add the entire text of the file
Cbuf_AddText (text); Cbuf_AddText (text);
SZ_Write (&cmd_text, "\n", 1); SZ_Write (&cmd_text, "\n", 1);
// add the copied off data // add the copied off data
if (templen) if (templen) {
{
SZ_Write (&cmd_text, temp, templen); SZ_Write (&cmd_text, temp, templen);
free (temp); free (temp);
} }
} }
void
void Cbuf_Execute (void) Cbuf_Execute (void)
{ {
int i; int i;
char *text; char *text;
char line[1024]; char line[1024];
int quotes; int quotes;
while (cmd_text.cursize)
{
// find a \n or ; line break
text = (char *)cmd_text.data;
while (cmd_text.cursize) {
// find a \n or ; line break
text = (char *) cmd_text.data;
quotes = 0; quotes = 0;
for (i=0 ; i< cmd_text.cursize ; i++) for (i = 0; i < cmd_text.cursize; i++) {
{
if (text[i] == '"') if (text[i] == '"')
quotes++; quotes++;
if ( !(quotes&1) && text[i] == ';') if (!(quotes & 1) && text[i] == ';')
break; // don't break if inside a quoted string break; // don't break if inside a quoted
// string
if (text[i] == '\n') if (text[i] == '\n')
break; break;
} }
memcpy (line, text, i); memcpy (line, text, i);
line[i] = 0; line[i] = 0;
// delete the text from the command buffer and move remaining commands down // delete the text from the command buffer and move remaining commands down
// this is necessary because commands (exec, alias) can insert data at the // this is necessary because commands (exec, alias) can insert data at the
// beginning of the text buffer // beginning of the text buffer
if (i == cmd_text.cursize) if (i == cmd_text.cursize)
cmd_text.cursize = 0; cmd_text.cursize = 0;
else
{ else {
i++; i++;
cmd_text.cursize -= i; cmd_text.cursize -= i;
memcpy (text, text+i, cmd_text.cursize); memcpy (text, text + i, cmd_text.cursize);
} }
// execute the command line // execute the command line
Cmd_ExecuteString (line); Cmd_ExecuteString (line);
} }
} }
qboolean
qboolean Cmd_Exists (char *cmd_name) Cmd_Exists (char *cmd_name)
{ {
cmd_function_t *cmd; cmd_function_t *cmd;
for (cmd=cmd_functions ; cmd ; cmd=cmd->next) for (cmd = cmd_functions; cmd; cmd = cmd->next) {
{ if (!strcmp (cmd_name, cmd->name))
if (!strcmp (cmd_name,cmd->name))
return true; return true;
} }
return false; return false;
} }
//Commands //Commands
void
void Cmd_Quit_f() Cmd_Quit_f ()
{ {
printf ("Shutting down.\n"); printf ("Shutting down.\n");
SV_Shutdown (); SV_Shutdown ();
Sys_Quit ();
} void
Sys_Quit(); Cmd_ServerList_f ()
}
void Cmd_ServerList_f()
{ {
server_t *sv; server_t *sv;
for(sv = sv_list;sv;sv = sv->next) for (sv = sv_list; sv; sv = sv->next)
printf("%s %i players\n",NET_AdrToString(sv->ip),sv->players); printf ("%s %i players\n", NET_AdrToString (sv->ip), sv->players);
} }

File diff suppressed because it is too large Load diff

View file

@ -1,69 +1,63 @@
#include "defs.h" #include "defs.h"
#include <limits.h> #include <limits.h>
int sv_mode;
sizebuf_t cmd_text;
byte cmd_text_buf[8192];
int sv_mode; char com_token[1024];
int com_argc;
sizebuf_t cmd_text; char **com_argv;
byte cmd_text_buf[8192]; static char *largv[MAX_NUM_ARGVS + 1];
static char *argvdummy = " ";
char com_token[1024]; qboolean bigendien;
int com_argc; short (*BigShort) (short l);
char **com_argv; short (*LittleShort) (short l);
int (*BigLong) (int l);
static char *largv[MAX_NUM_ARGVS + 1]; int (*LittleLong) (int l);
static char *argvdummy = " "; float (*BigFloat) (float l);
float (*LittleFloat) (float l);
qboolean bigendien; short
ShortSwap (short l)
short (*BigShort) (short l);
short (*LittleShort) (short l);
int (*BigLong) (int l);
int (*LittleLong) (int l);
float (*BigFloat) (float l);
float (*LittleFloat) (float l);
short ShortSwap (short l)
{ {
byte b1,b2; byte b1, b2;
b1 = l&255; b1 = l & 255;
b2 = (l>>8)&255; b2 = (l >> 8) & 255;
return (b1 << 8) + b2;
return (b1<<8) + b2;
} }
short ShortNoSwap (short l) short
ShortNoSwap (short l)
{ {
return l; return l;
} }
int LongSwap (int l) int
LongSwap (int l)
{ {
byte b1,b2,b3,b4; byte b1, b2, b3, b4;
b1 = l&255; b1 = l & 255;
b2 = (l>>8)&255; b2 = (l >> 8) & 255;
b3 = (l>>16)&255; b3 = (l >> 16) & 255;
b4 = (l>>24)&255; b4 = (l >> 24) & 255;
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
} }
int LongNoSwap (int l) int
LongNoSwap (int l)
{ {
return l; return l;
} }
float FloatSwap (float f) float
FloatSwap (float f)
{ {
union union {
{ float f;
float f; byte b[4];
byte b[4]; } dat1 , dat2;
} dat1, dat2;
dat1.f = f; dat1.f = f;
dat2.b[0] = dat1.b[3]; dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2]; dat2.b[1] = dat1.b[2];
@ -72,20 +66,23 @@ float FloatSwap (float f)
return dat2.f; return dat2.f;
} }
float FloatNoSwap (float f) float
FloatNoSwap (float f)
{ {
return f; return f;
} }
//////////////////////////////// ////////////////////////////////
void
void COM_Init (void) COM_Init (void)
{ {
byte swaptest[2] = {1,0}; byte swaptest[2] = {
1, 0
};
// set the byte swapping variables in a portable manner // set the byte swapping variables in a portable manner
if ( *(short *)swaptest == 1) if (*(short *) swaptest == 1) {
{
bigendien = false; bigendien = false;
BigShort = ShortSwap; BigShort = ShortSwap;
LittleShort = ShortNoSwap; LittleShort = ShortNoSwap;
@ -94,9 +91,9 @@ void COM_Init (void)
BigFloat = FloatSwap; BigFloat = FloatSwap;
LittleFloat = FloatNoSwap; LittleFloat = FloatNoSwap;
} }
else
{ else {
bigendien = true; bigendien = true;
BigShort = ShortNoSwap; BigShort = ShortNoSwap;
LittleShort = ShortSwap; LittleShort = ShortSwap;
BigLong = LongNoSwap; BigLong = LongNoSwap;
@ -105,74 +102,62 @@ void COM_Init (void)
LittleFloat = FloatSwap; LittleFloat = FloatSwap;
} }
} }
void
void COM_InitArgv (int argc, char **argv) COM_InitArgv (int argc, char **argv)
{ {
for (com_argc = 0; (com_argc < MAX_NUM_ARGVS) && (com_argc < argc);
for (com_argc=0 ; (com_argc<MAX_NUM_ARGVS) && (com_argc < argc) ; com_argc++) {
com_argc++)
{
largv[com_argc] = argv[com_argc]; largv[com_argc] = argv[com_argc];
} }
largv[com_argc] = argvdummy; largv[com_argc] = argvdummy;
com_argv = largv; com_argv = largv;
} }
int COM_CheckParm (char *parm) int
COM_CheckParm (char *parm)
{ {
int i; int i;
for (i=1 ; i<com_argc ; i++) for (i = 1; i < com_argc; i++) {
{
if (!com_argv[i]) if (!com_argv[i])
continue; // NEXTSTEP sometimes clears appkit vars. continue; // NEXTSTEP sometimes clears appkit
if (!strcmp (parm,com_argv[i])) // vars.
if (!strcmp (parm, com_argv[i]))
return i; return i;
} }
return 0; return 0;
} }
char *COM_Parse (char *data) char *
COM_Parse (char *data)
{ {
int c; int c;
int len; int len;
len = 0; len = 0;
com_token[0] = 0; com_token[0] = 0;
if (!data) if (!data)
return NULL; return NULL;
// skip whitespace // skip whitespace
skipwhite: skipwhite:while ((c = *data) <= ' ') {
while ( (c = *data) <= ' ')
{
if (c == 0) if (c == 0)
return NULL; // end of file; return NULL; // end of file;
data++; data++;
} }
// skip // comments // skip // comments
if (c=='/' && data[1] == '/') if (c == '/' && data[1] == '/') {
{
while (*data && *data != '\n') while (*data && *data != '\n')
data++; data++;
goto skipwhite; goto skipwhite;
} }
// handle quoted strings specially // handle quoted strings specially
if (c == '\"') if (c == '\"') {
{
data++; data++;
while (1) while (1) {
{
c = *data++; c = *data++;
if (c=='\"' || !c) if (c == '\"' || !c) {
{
com_token[len] = 0; com_token[len] = 0;
return data; return data;
} }
@ -180,72 +165,68 @@ skipwhite:
len++; len++;
} }
} }
// parse a regular word // parse a regular word
do do {
{
com_token[len] = c; com_token[len] = c;
data++; data++;
len++; len++;
c = *data; c = *data;
} while (c>32); } while (c > 32);
com_token[len] = 0; com_token[len] = 0;
return data; return data;
} }
void Sys_Error (char *error, ...) void
Sys_Error (char *error, ...)
{ {
va_list argptr; va_list argptr;
char text[1024]; char text[1024];
va_start (argptr,error); va_start (argptr, error);
vsprintf (text, error,argptr); vsprintf (text, error, argptr);
va_end (argptr); va_end (argptr);
// MessageBox(NULL, text, "Error", 0 /* MB_OK */ ); // MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
printf ("ERROR: %s\n", text); printf ("ERROR: %s\n", text);
exit (1); exit (1);
} }
void Sys_Quit (void) void
Sys_Quit (void)
{ {
exit (0); exit (0);
} }
void SV_WriteFilterList(); void SV_WriteFilterList ();
void
void SV_Shutdown (void) SV_Shutdown (void)
{ {
NET_Shutdown (); NET_Shutdown ();
//write filter list // write filter list
SV_WriteFilterList(); SV_WriteFilterList ();
} }
char *Sys_ConsoleInput (void) char *
Sys_ConsoleInput (void)
{ {
static char text[256]; static char text[256];
static int len; static int len;
int c; int c;
// read a line out // read a line out
while (_kbhit()) while (_kbhit ()) {
{ c = _getch ();
c = _getch();
putch (c); putch (c);
if (c == '\r') if (c == '\r') {
{
text[len] = 0; text[len] = 0;
putch ('\n'); putch ('\n');
len = 0; len = 0;
return text; return text;
} }
if (c == 8) if (c == 8) {
{ if (len) {
if (len)
{
putch (' '); putch (' ');
putch (c); putch (c);
len--; len--;
@ -256,110 +237,93 @@ char *Sys_ConsoleInput (void)
text[len] = c; text[len] = c;
len++; len++;
text[len] = 0; text[len] = 0;
if (len == sizeof(text)) if (len == sizeof (text))
len = 0; len = 0;
} }
return NULL; return NULL;
} }
void SV_GetConsoleCommands (void) void
SV_GetConsoleCommands (void)
{ {
char *cmd; char *cmd;
while (1) while (1) {
{
cmd = Sys_ConsoleInput (); cmd = Sys_ConsoleInput ();
if (!cmd) if (!cmd)
break; break;
Cbuf_AddText (cmd); Cbuf_AddText (cmd);
} }
} }
double
double Sys_DoubleTime (void) Sys_DoubleTime (void)
{ {
static DWORD starttime; static DWORD starttime;
static qboolean first = true; static qboolean first = true;
DWORD now;
double t;
now = timeGetTime(); DWORD now;
double t;
now = timeGetTime ();
if (first) { if (first) {
first = false; first = false;
starttime = now; starttime = now;
return 0.0; return 0.0;
} }
if (now < starttime) // wrapped?
if (now < starttime) // wrapped?
return (now / 1000.0) + (LONG_MAX - starttime / 1000.0); return (now / 1000.0) + (LONG_MAX - starttime / 1000.0);
if (now - starttime == 0) if (now - starttime == 0)
return 0.0; return 0.0;
return (now - starttime) / 1000.0; return (now - starttime) / 1000.0;
} }
#define SV_TIMEOUT 450 #define SV_TIMEOUT 450
void
void SV_TimeOut() SV_TimeOut ()
{ {
//Remove listed severs that havnt sent a heartbeat for some time
double time = Sys_DoubleTime();
server_t *sv; // Remove listed severs that havnt sent a heartbeat for some time
server_t *next; double time = Sys_DoubleTime ();
server_t *sv;
server_t *next;
if(sv_list==NULL) if (sv_list == NULL)
return; return;
for (sv = sv_list; sv;) {
for(sv = sv_list;sv;) if (sv->timeout + SV_TIMEOUT < time) {
{
if(sv->timeout + SV_TIMEOUT < time)
{
next = sv->next; next = sv->next;
printf("%s timed out\n",NET_AdrToString(sv->ip)); printf ("%s timed out\n", NET_AdrToString (sv->ip));
SVL_Remove(sv); SVL_Remove (sv);
free(sv); free (sv);
sv = next; sv = next;
} }
else else
sv = sv->next; sv = sv->next;
} }
} }
void
void SV_Frame() SV_Frame ()
{ {
SV_GetConsoleCommands (); SV_GetConsoleCommands ();
Cbuf_Execute (); Cbuf_Execute ();
SV_TimeOut ();
SV_TimeOut(); SV_ReadPackets ();
SV_ReadPackets();
} }
int main (int argc, char **argv) int
main (int argc, char **argv)
{ {
COM_Init(); COM_Init ();
COM_InitArgv (argc, argv); COM_InitArgv (argc, argv);
Cbuf_Init ();
Cbuf_Init(); Cmd_Init ();
Cmd_Init (); SV_InitNet ();
printf ("Exe: " __TIME__ " " __DATE__ "\n");
SV_InitNet(); printf ("======== HW master initialized ========\n\n");
while (1) {
printf ("Exe: "__TIME__" "__DATE__"\n"); SV_Frame ();
printf("======== HW master initialized ========\n\n");
while(1)
{
SV_Frame();
} }
return 0; return 0;
} }

View file

@ -1,111 +1,103 @@
#include "defs.h" #include "defs.h"
#include "QF/cvar.h" #include "QF/cvar.h"
cvar_t *cvar_vars;
cvar_t *cvar_vars; char *cvar_null_string = "";
char *cvar_null_string = ""; qboolean
Cvar_Command (void)
qboolean Cvar_Command (void)
{ {
cvar_t *v; cvar_t *v;
// check variables // check variables
v = Cvar_FindVar (Cmd_Argv(0)); v = Cvar_FindVar (Cmd_Argv (0));
if (!v) if (!v)
return false; return false;
// perform a variable print or set // perform a variable print or set
if (Cmd_Argc() == 1) if (Cmd_Argc () == 1) {
{
printf ("\"%s\" is \"%s\"\n", v->name, v->string); printf ("\"%s\" is \"%s\"\n", v->name, v->string);
return true; return true;
} }
Cvar_Set (v->name, Cmd_Argv (1));
Cvar_Set (v->name, Cmd_Argv(1));
return true; return true;
} }
cvar_t *Cvar_FindVar (char *var_name) cvar_t *
Cvar_FindVar (char *var_name)
{ {
cvar_t *var; cvar_t *var;
for (var=cvar_vars ; var ; var=var->next) for (var = cvar_vars; var; var = var->next)
if (!strcmp (var_name, var->name)) if (!strcmp (var_name, var->name))
return var; return var;
return NULL; return NULL;
} }
void Cvar_RegisterVariable (cvar_t *variable) void
Cvar_RegisterVariable (cvar_t *variable)
{ {
char value[512]; char value[512];
// first check to see if it has allready been defined // first check to see if it has allready been defined
if (Cvar_FindVar (variable->name)) if (Cvar_FindVar (variable->name)) {
{ printf ("Can't register variable %s, allready defined\n",
printf ("Can't register variable %s, allready defined\n", variable->name); variable->name);
return; return;
} }
// check for overlap with a command // check for overlap with a command
if (Cmd_Exists (variable->name)) if (Cmd_Exists (variable->name)) {
{
printf ("Cvar_RegisterVariable: %s is a command\n", variable->name); printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
return; return;
} }
// link the variable in // link the variable in
variable->next = cvar_vars; variable->next = cvar_vars;
cvar_vars = variable; cvar_vars = variable;
// copy the value off, because future sets will Z_Free it // copy the value off, because future sets will Z_Free it
strcpy (value, variable->string); strcpy (value, variable->string);
variable->string = (char *)malloc (1); variable->string = (char *) malloc (1);
// set it through the function to be consistant // set it through the function to be consistant
Cvar_Set (variable->name, value); Cvar_Set (variable->name, value);
} } void
Cvar_Set (char *var_name, char *value)
void Cvar_Set (char *var_name, char *value)
{ {
cvar_t *var; cvar_t *var;
var = Cvar_FindVar (var_name); var = Cvar_FindVar (var_name);
if (!var) if (!var) { // there is an error in C code if this
{ // there is an error in C code if this happens // happens
printf ("Cvar_Set: variable %s not found\n", var_name); printf ("Cvar_Set: variable %s not found\n", var_name);
return; return;
} }
free (var->string); // free the old value string
var->string = (char *) malloc (strlen (value) + 1);
free (var->string); // free the old value string
var->string = (char *)malloc (strlen(value)+1);
strcpy (var->string, value); strcpy (var->string, value);
var->value = atof (var->string); var->value = atof (var->string);
} } void
Cvar_SetValue (char *var_name, float value)
void Cvar_SetValue (char *var_name, float value)
{ {
char val[32]; char val[32];
sprintf (val, "%f",value); sprintf (val, "%f", value);
Cvar_Set (var_name, val); Cvar_Set (var_name, val);
} } char *
Cvar_VariableString (char *var_name)
char *Cvar_VariableString (char *var_name)
{ {
cvar_t *var; cvar_t *var;
var = Cvar_FindVar (var_name); var = Cvar_FindVar (var_name);
if (!var) if (!var)
return cvar_null_string; return cvar_null_string;
return var->string; return var->string;
} }
float Cvar_VariableValue (char *var_name) float
Cvar_VariableValue (char *var_name)
{ {
cvar_t *var; cvar_t *var;
var = Cvar_FindVar (var_name); var = Cvar_FindVar (var_name);
if (!var) if (!var)
return 0; return 0;