"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
typedef struct
{
byte ip[4];
unsigned short port;
unsigned short pad;
} netadr_t;
typedef struct server_s
{
netadr_t ip;
@ -75,128 +68,36 @@ typedef struct server_s
double timeout;
} 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
//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_Frame();
void SV_Shutdown();
void SV_Frame(void);
void SV_Shutdown(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
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);
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);
qboolean NET_GetPacket (void);
void SV_ConnectionlessPacket (void);
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_Remove(server_t *sv);
void SVL_Clear();
void SVL_Clear(void);
server_t* SVL_Find(netadr_t adr);
server_t* SVL_New();
server_t* SVL_New(netadr_t adr);
void Cmd_Filter_f();
server_t* SVL_New(netadr_t *adr);
void Cmd_Filter_f(void);
//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 WSADATA winsockdata;
extern netadr_t net_local_adr;
extern netadr_t master_adr[MAX_MASTERS]; // address of group servers
extern int num_masters;
extern short (*BigShort) (short l);
@ -206,8 +107,6 @@ extern int (*LittleLong) (int l);
extern float (*BigFloat) (float l);
extern float (*LittleFloat) (float l);
extern netadr_t net_from;
extern int msg_readcount;
extern qboolean msg_badread;

View file

@ -33,14 +33,14 @@ AUTOMAKE_OPTIONS= foreign
INCLUDES= -I$(top_srcdir)/include -I$(top_srcdir)/hw/include
SDL_LIBS = @SDL_LIBS@
bin_PROGRAMS= @QW_TARGETS@
bin_PROGRAMS= @HW_TARGETS@
EXTRA_PROGRAMS= hw-master
common_ldflags= -export-dynamic
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
# Kill the temp files, hopefully.

View file

@ -1,244 +1,219 @@
#include "defs.h"
static int cmd_argc;
static char *cmd_argv[MAX_ARGS];
static char *cmd_null_string = "";
static char *cmd_args = NULL;
static cmd_function_t *cmd_functions; // possible commands to execute
int Cmd_Argc (void)
static int cmd_argc;
static char *cmd_argv[MAX_ARGS];
static char *cmd_null_string = "";
static char *cmd_args = NULL;
static cmd_function_t *cmd_functions; // possible commands to execute
int
Cmd_Argc (void)
{
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_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
for (i=0 ; i<cmd_argc ; i++)
for (i = 0; i < cmd_argc; i++)
free (cmd_argv[i]);
cmd_argc = 0;
cmd_args = NULL;
while (1)
{
while (1) {
// skip whitespace up to a /n
while (*text && *text <= ' ' && *text != '\n')
{
while (*text && *text <= ' ' && *text != '\n') {
text++;
}
if (*text == '\n')
{ // a newline seperates commands in the buffer
if (*text == '\n') { // a newline seperates commands in the
// buffer
text++;
break;
}
if (!*text)
return;
if (cmd_argc == 1)
cmd_args = text;
cmd_args = text;
text = COM_Parse (text);
if (!text)
return;
if (cmd_argc < MAX_ARGS)
{
cmd_argv[cmd_argc] = (char *)malloc (strlen(com_token)+1);
if (cmd_argc < MAX_ARGS) {
cmd_argv[cmd_argc] = (char *) malloc (strlen (com_token) + 1);
strcpy (cmd_argv[cmd_argc], com_token);
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
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
if (!strcmp (cmd_name, cmd->name))
{
for (cmd = cmd_functions; cmd; cmd = cmd->next) {
if (!strcmp (cmd_name, cmd->name)) {
printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
return;
}
}
cmd = (cmd_function_t *)malloc(sizeof(cmd_function_t));
cmd = (cmd_function_t *) malloc (sizeof (cmd_function_t));
cmd->name = cmd_name;
cmd->function = function;
cmd->next = cmd_functions;
cmd_functions = cmd;
}
void Cmd_Init()
void
Cmd_Init ()
{
Cmd_AddCommand("quit",Cmd_Quit_f);
Cmd_AddCommand("list",Cmd_ServerList_f);
Cmd_AddCommand("filter",Cmd_Filter_f);
}
void Cmd_ExecuteString (char *text)
{
cmd_function_t *cmd;
Cmd_AddCommand ("quit", Cmd_Quit_f);
Cmd_AddCommand ("list", Cmd_ServerList_f);
Cmd_AddCommand ("filter", Cmd_Filter_f);
} void
Cmd_ExecuteString (char *text)
{
cmd_function_t *cmd;
Cmd_TokenizeString (text);
// execute the command line
if (!Cmd_Argc())
return; // no tokens
if (!Cmd_Argc ())
return; // no tokens
// check functions
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
if (!strcmp(cmd_argv[0],cmd->name))
{
for (cmd = cmd_functions; cmd; cmd = cmd->next) {
if (!strcmp (cmd_argv[0], cmd->name)) {
if (cmd->function)
cmd->function ();
return;
}
}
printf("Unknown command: %s\n",cmd_argv[0]);
printf ("Unknown command: %s\n", cmd_argv[0]);
}
void Cbuf_Init (void)
void
Cbuf_Init (void)
{
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;
l = strlen (text);
int l;
if (cmd_text.cursize + l >= cmd_text.maxsize)
{
l = strlen (text);
if (cmd_text.cursize + l >= cmd_text.maxsize) {
printf ("Cbuf_AddText: overflow\n");
return;
}
SZ_Write (&cmd_text, text, strlen (text));
}
void Cbuf_InsertText (char *text)
void
Cbuf_InsertText (char *text)
{
char *temp;
int templen;
char *temp;
int templen;
// copy off any commands still remaining in the exec buffer
templen = cmd_text.cursize;
if (templen)
{
temp = (char *)malloc (templen);
if (templen) {
temp = (char *) malloc (templen);
memcpy (temp, cmd_text.data, templen);
SZ_Clear (&cmd_text);
}
else
temp = NULL; // shut up compiler
temp = NULL; // shut up compiler
// add the entire text of the file
Cbuf_AddText (text);
SZ_Write (&cmd_text, "\n", 1);
// add the copied off data
if (templen)
{
if (templen) {
SZ_Write (&cmd_text, temp, templen);
free (temp);
}
}
void Cbuf_Execute (void)
void
Cbuf_Execute (void)
{
int i;
char *text;
char line[1024];
int quotes;
while (cmd_text.cursize)
{
// find a \n or ; line break
text = (char *)cmd_text.data;
int i;
char *text;
char line[1024];
int quotes;
while (cmd_text.cursize) {
// find a \n or ; line break
text = (char *) cmd_text.data;
quotes = 0;
for (i=0 ; i< cmd_text.cursize ; i++)
{
for (i = 0; i < cmd_text.cursize; i++) {
if (text[i] == '"')
quotes++;
if ( !(quotes&1) && text[i] == ';')
break; // don't break if inside a quoted string
if (!(quotes & 1) && text[i] == ';')
break; // don't break if inside a quoted
// string
if (text[i] == '\n')
break;
}
memcpy (line, text, i);
line[i] = 0;
// delete the text from the command buffer and move remaining commands down
// this is necessary because commands (exec, alias) can insert data at the
// beginning of the text buffer
if (i == cmd_text.cursize)
cmd_text.cursize = 0;
else
{
else {
i++;
cmd_text.cursize -= i;
memcpy (text, text+i, cmd_text.cursize);
memcpy (text, text + i, cmd_text.cursize);
}
// execute the command line
Cmd_ExecuteString (line);
}
}
qboolean Cmd_Exists (char *cmd_name)
qboolean
Cmd_Exists (char *cmd_name)
{
cmd_function_t *cmd;
cmd_function_t *cmd;
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
if (!strcmp (cmd_name,cmd->name))
for (cmd = cmd_functions; cmd; cmd = cmd->next) {
if (!strcmp (cmd_name, cmd->name))
return true;
}
return false;
}
//Commands
void Cmd_Quit_f()
void
Cmd_Quit_f ()
{
printf ("Shutting down.\n");
SV_Shutdown ();
Sys_Quit ();
} void
Sys_Quit();
}
void Cmd_ServerList_f()
Cmd_ServerList_f ()
{
server_t *sv;
server_t *sv;
for(sv = sv_list;sv;sv = sv->next)
printf("%s %i players\n",NET_AdrToString(sv->ip),sv->players);
for (sv = sv_list; sv; sv = sv->next)
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 <limits.h>
int sv_mode;
sizebuf_t cmd_text;
int sv_mode;
sizebuf_t cmd_text;
byte cmd_text_buf[8192];
char com_token[1024];
int com_argc;
char **com_argv;
static char *largv[MAX_NUM_ARGVS + 1];
static char *argvdummy = " ";
qboolean bigendien;
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 cmd_text_buf[8192];
char com_token[1024];
int com_argc;
char **com_argv;
static char *largv[MAX_NUM_ARGVS + 1];
static char *argvdummy = " ";
qboolean bigendien;
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;
b2 = (l>>8)&255;
return (b1<<8) + b2;
b1 = l & 255;
b2 = (l >> 8) & 255;
return (b1 << 8) + b2;
}
short ShortNoSwap (short l)
short
ShortNoSwap (short l)
{
return l;
}
int LongSwap (int l)
int
LongSwap (int l)
{
byte b1,b2,b3,b4;
byte b1, b2, b3, b4;
b1 = l&255;
b2 = (l>>8)&255;
b3 = (l>>16)&255;
b4 = (l>>24)&255;
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
b1 = l & 255;
b2 = (l >> 8) & 255;
b3 = (l >> 16) & 255;
b4 = (l >> 24) & 255;
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
}
int LongNoSwap (int l)
int
LongNoSwap (int l)
{
return l;
}
float FloatSwap (float f)
float
FloatSwap (float f)
{
union
{
float f;
byte b[4];
} dat1, dat2;
union {
float f;
byte b[4];
} dat1 , dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
@ -72,20 +66,23 @@ float FloatSwap (float f)
return dat2.f;
}
float FloatNoSwap (float f)
float
FloatNoSwap (float f)
{
return f;
}
////////////////////////////////
void COM_Init (void)
void
COM_Init (void)
{
byte swaptest[2] = {1,0};
byte swaptest[2] = {
1, 0
};
// set the byte swapping variables in a portable manner
if ( *(short *)swaptest == 1)
{
// set the byte swapping variables in a portable manner
if (*(short *) swaptest == 1) {
bigendien = false;
BigShort = ShortSwap;
LittleShort = ShortNoSwap;
@ -94,9 +91,9 @@ void COM_Init (void)
BigFloat = FloatSwap;
LittleFloat = FloatNoSwap;
}
else
{
bigendien = true;
else {
bigendien = true;
BigShort = ShortNoSwap;
LittleShort = ShortSwap;
BigLong = LongNoSwap;
@ -105,74 +102,62 @@ void COM_Init (void)
LittleFloat = FloatSwap;
}
}
void COM_InitArgv (int argc, char **argv)
void
COM_InitArgv (int argc, char **argv)
{
for (com_argc=0 ; (com_argc<MAX_NUM_ARGVS) && (com_argc < argc) ;
com_argc++)
{
for (com_argc = 0; (com_argc < MAX_NUM_ARGVS) && (com_argc < argc);
com_argc++) {
largv[com_argc] = argv[com_argc];
}
largv[com_argc] = argvdummy;
com_argv = largv;
}
int COM_CheckParm (char *parm)
int
COM_CheckParm (char *parm)
{
int i;
for (i=1 ; i<com_argc ; i++)
{
int i;
for (i = 1; i < com_argc; i++) {
if (!com_argv[i])
continue; // NEXTSTEP sometimes clears appkit vars.
if (!strcmp (parm,com_argv[i]))
continue; // NEXTSTEP sometimes clears appkit
// vars.
if (!strcmp (parm, com_argv[i]))
return i;
}
return 0;
}
char *COM_Parse (char *data)
char *
COM_Parse (char *data)
{
int c;
int len;
int c;
int len;
len = 0;
com_token[0] = 0;
if (!data)
return NULL;
// skip whitespace
skipwhite:
while ( (c = *data) <= ' ')
{
skipwhite:while ((c = *data) <= ' ') {
if (c == 0)
return NULL; // end of file;
return NULL; // end of file;
data++;
}
// skip // comments
if (c=='/' && data[1] == '/')
{
if (c == '/' && data[1] == '/') {
while (*data && *data != '\n')
data++;
goto skipwhite;
}
// handle quoted strings specially
if (c == '\"')
{
if (c == '\"') {
data++;
while (1)
{
while (1) {
c = *data++;
if (c=='\"' || !c)
{
if (c == '\"' || !c) {
com_token[len] = 0;
return data;
}
@ -180,72 +165,68 @@ skipwhite:
len++;
}
}
// parse a regular word
do
{
do {
com_token[len] = c;
data++;
len++;
c = *data;
} while (c>32);
} while (c > 32);
com_token[len] = 0;
return data;
}
void Sys_Error (char *error, ...)
void
Sys_Error (char *error, ...)
{
va_list argptr;
char text[1024];
va_list argptr;
char text[1024];
va_start (argptr,error);
vsprintf (text, error,argptr);
va_start (argptr, error);
vsprintf (text, error, argptr);
va_end (argptr);
// MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
printf ("ERROR: %s\n", text);
exit (1);
}
void Sys_Quit (void)
void
Sys_Quit (void)
{
exit (0);
}
void SV_WriteFilterList();
void SV_Shutdown (void)
void SV_WriteFilterList ();
void
SV_Shutdown (void)
{
NET_Shutdown ();
//write filter list
SV_WriteFilterList();
// write filter list
SV_WriteFilterList ();
}
char *Sys_ConsoleInput (void)
char *
Sys_ConsoleInput (void)
{
static char text[256];
static int len;
int c;
static char text[256];
static int len;
int c;
// read a line out
while (_kbhit())
{
c = _getch();
while (_kbhit ()) {
c = _getch ();
putch (c);
if (c == '\r')
{
if (c == '\r') {
text[len] = 0;
putch ('\n');
len = 0;
return text;
}
if (c == 8)
{
if (len)
{
if (c == 8) {
if (len) {
putch (' ');
putch (c);
len--;
@ -256,110 +237,93 @@ char *Sys_ConsoleInput (void)
text[len] = c;
len++;
text[len] = 0;
if (len == sizeof(text))
if (len == sizeof (text))
len = 0;
}
return NULL;
}
void SV_GetConsoleCommands (void)
void
SV_GetConsoleCommands (void)
{
char *cmd;
char *cmd;
while (1)
{
while (1) {
cmd = Sys_ConsoleInput ();
if (!cmd)
break;
Cbuf_AddText (cmd);
}
}
double Sys_DoubleTime (void)
double
Sys_DoubleTime (void)
{
static DWORD starttime;
static qboolean first = true;
DWORD now;
double t;
now = timeGetTime();
DWORD now;
double t;
now = timeGetTime ();
if (first) {
first = false;
starttime = now;
return 0.0;
}
if (now < starttime) // wrapped?
if (now < starttime) // wrapped?
return (now / 1000.0) + (LONG_MAX - starttime / 1000.0);
if (now - starttime == 0)
return 0.0;
return (now - starttime) / 1000.0;
}
#define SV_TIMEOUT 450
void SV_TimeOut()
void
SV_TimeOut ()
{
//Remove listed severs that havnt sent a heartbeat for some time
double time = Sys_DoubleTime();
server_t *sv;
server_t *next;
// Remove listed severs that havnt sent a heartbeat for some time
double time = Sys_DoubleTime ();
server_t *sv;
server_t *next;
if(sv_list==NULL)
if (sv_list == NULL)
return;
for(sv = sv_list;sv;)
{
if(sv->timeout + SV_TIMEOUT < time)
{
for (sv = sv_list; sv;) {
if (sv->timeout + SV_TIMEOUT < time) {
next = sv->next;
printf("%s timed out\n",NET_AdrToString(sv->ip));
SVL_Remove(sv);
free(sv);
printf ("%s timed out\n", NET_AdrToString (sv->ip));
SVL_Remove (sv);
free (sv);
sv = next;
}
else
sv = sv->next;
}
}
void SV_Frame()
void
SV_Frame ()
{
SV_GetConsoleCommands ();
Cbuf_Execute ();
SV_TimeOut();
SV_ReadPackets();
SV_TimeOut ();
SV_ReadPackets ();
}
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
COM_Init();
COM_Init ();
COM_InitArgv (argc, argv);
Cbuf_Init();
Cmd_Init ();
SV_InitNet();
printf ("Exe: "__TIME__" "__DATE__"\n");
printf("======== HW master initialized ========\n\n");
while(1)
{
SV_Frame();
Cbuf_Init ();
Cmd_Init ();
SV_InitNet ();
printf ("Exe: " __TIME__ " " __DATE__ "\n");
printf ("======== HW master initialized ========\n\n");
while (1) {
SV_Frame ();
}
return 0;
}

View file

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