Move stuff from common/common/ to common/

This commit is contained in:
Yamagi Burmeister 2012-06-07 13:54:08 +02:00
parent 56aff1dc89
commit e0faf784a6
3 changed files with 168 additions and 103 deletions

View file

@ -462,6 +462,8 @@ CLIENT_OBJS_ := \
src/client/sound/snd_mix.o \ src/client/sound/snd_mix.o \
src/client/sound/snd_vorbis.o \ src/client/sound/snd_vorbis.o \
src/client/sound/snd_wav.o \ src/client/sound/snd_wav.o \
src/common/argproc.o \
src/common/clientserver.o \
src/common/crc.o \ src/common/crc.o \
src/common/cmdparser.o \ src/common/cmdparser.o \
src/common/cvar.o \ src/common/cvar.o \
@ -473,8 +475,6 @@ CLIENT_OBJS_ := \
src/common/pmove.o \ src/common/pmove.o \
src/common/szone.o \ src/common/szone.o \
src/common/zone.o \ src/common/zone.o \
src/common/common/com_arg.o \
src/common/common/com_clientserver.o \
src/common/message/msg_io.o \ src/common/message/msg_io.o \
src/common/message/msg_read.o \ src/common/message/msg_read.o \
src/common/model/cm_areaportals.o \ src/common/model/cm_areaportals.o \
@ -523,6 +523,8 @@ endif
# Used by the server # Used by the server
SERVER_OBJS_ := \ SERVER_OBJS_ := \
src/common/argproc.o \
src/common/clientserver.o \
src/common/crc.o \ src/common/crc.o \
src/common/cmdparser.o \ src/common/cmdparser.o \
src/common/cvar.o \ src/common/cvar.o \
@ -534,8 +536,6 @@ SERVER_OBJS_ := \
src/common/pmove.o \ src/common/pmove.o \
src/common/szone.o \ src/common/szone.o \
src/common/zone.o \ src/common/zone.o \
src/common/common/com_arg.o \
src/common/common/com_clientserver.o \
src/common/message/msg_io.o \ src/common/message/msg_io.o \
src/common/message/msg_read.o \ src/common/message/msg_read.o \
src/common/model/cm_areaportals.o \ src/common/model/cm_areaportals.o \

View file

@ -24,134 +24,167 @@
* ======================================================================= * =======================================================================
*/ */
#include "../header/common.h" #include "header/common.h"
#define MAX_NUM_ARGVS 50 #define MAX_NUM_ARGVS 50
int com_argc; int com_argc;
char *com_argv[MAX_NUM_ARGVS+1]; char *com_argv[MAX_NUM_ARGVS + 1];
/* /*
* Returns the position (1 to argc-1) in the program's argument list * Returns the position (1 to argc-1) in the program's argument list
* where the given parameter apears, or 0 if not present * where the given parameter apears, or 0 if not present
*/ */
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 (!strcmp (parm,com_argv[i])) if (!strcmp(parm, com_argv[i]))
{
return i; return i;
}
} }
return 0; return 0;
} }
int COM_Argc (void) int
COM_Argc(void)
{ {
return com_argc; return com_argc;
} }
char *COM_Argv (int arg) char *
COM_Argv(int arg)
{ {
if (arg < 0 || arg >= com_argc || !com_argv[arg]) if ((arg < 0) || (arg >= com_argc) || !com_argv[arg])
{
return ""; return "";
}
return com_argv[arg]; return com_argv[arg];
} }
void COM_ClearArgv (int arg) void
COM_ClearArgv(int arg)
{ {
if (arg < 0 || arg >= com_argc || !com_argv[arg]) if ((arg < 0) || (arg >= com_argc) || !com_argv[arg])
{
return; return;
}
com_argv[arg] = ""; com_argv[arg] = "";
} }
void COM_InitArgv (int argc, char **argv) void
COM_InitArgv(int argc, char **argv)
{ {
int i; int i;
if (argc > MAX_NUM_ARGVS) if (argc > MAX_NUM_ARGVS)
Com_Error (ERR_FATAL, "argc > MAX_NUM_ARGVS"); {
Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS");
}
com_argc = argc; com_argc = argc;
for (i=0 ; i<argc ; i++) for (i = 0; i < argc; i++)
{ {
if (!argv[i] || strlen(argv[i]) >= MAX_TOKEN_CHARS ) if (!argv[i] || (strlen(argv[i]) >= MAX_TOKEN_CHARS))
{
com_argv[i] = ""; com_argv[i] = "";
}
else else
{
com_argv[i] = argv[i]; com_argv[i] = argv[i];
}
} }
} }
/* /*
* Adds the given string at the end of the current argument list * Adds the given string at the end of the current argument list
*/ */
void COM_AddParm (char *parm) void
COM_AddParm(char *parm)
{ {
if (com_argc == MAX_NUM_ARGVS) if (com_argc == MAX_NUM_ARGVS)
Com_Error (ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS"); {
Com_Error(ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS");
}
com_argv[com_argc++] = parm; com_argv[com_argc++] = parm;
} }
int memsearch (byte *start, int count, int search) int
memsearch(byte *start, int count, int search)
{ {
int i; int i;
for (i=0 ; i<count ; i++) for (i = 0; i < count; i++)
{
if (start[i] == search) if (start[i] == search)
{
return i; return i;
}
}
return -1; return -1;
} }
char *CopyString (char *in) char *
CopyString(char *in)
{ {
char *out; char *out;
out = Z_Malloc ((int)strlen(in)+1); out = Z_Malloc((int)strlen(in) + 1);
strcpy (out, in); strcpy(out, in);
return out; return out;
} }
void Info_Print (char *s) void
Info_Print(char *s)
{ {
char key[512]; char key[512];
char value[512]; char value[512];
char *o; char *o;
int l; int l;
if (*s == '\\') if (*s == '\\')
{
s++; s++;
}
while (*s) while (*s)
{ {
o = key; o = key;
while (*s && *s != '\\') while (*s && *s != '\\')
{
*o++ = *s++; *o++ = *s++;
}
l = o - key; l = o - key;
if (l < 20) if (l < 20)
{ {
memset (o, ' ', 20-l); memset(o, ' ', 20 - l);
key[20] = 0; key[20] = 0;
} }
else else
{
*o = 0; *o = 0;
}
Com_Printf ("%s", key); Com_Printf("%s", key);
if (!*s) if (!*s)
{ {
Com_Printf ("MISSING VALUE\n"); Com_Printf("MISSING VALUE\n");
return; return;
} }
@ -159,13 +192,18 @@ void Info_Print (char *s)
s++; s++;
while (*s && *s != '\\') while (*s && *s != '\\')
{
*o++ = *s++; *o++ = *s++;
}
*o = 0; *o = 0;
if (*s) if (*s)
{
s++; s++;
}
Com_Printf ("%s\n", value); Com_Printf("%s\n", value);
} }
} }

View file

@ -24,26 +24,29 @@
* ======================================================================= * =======================================================================
*/ */
#include "../header/common.h" #include "header/common.h"
#include <stdlib.h> #include <stdlib.h>
#include <setjmp.h> #include <setjmp.h>
#define MAXPRINTMSG 4096 #define MAXPRINTMSG 4096
FILE *logfile; FILE *logfile;
cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */ cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */
jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */ jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */
int server_state; int server_state;
static int rd_target; static int rd_target;
static char *rd_buffer; static char *rd_buffer;
static int rd_buffersize; static int rd_buffersize;
static void (*rd_flush)(int target, char *buffer); static void (*rd_flush)(int target, char *buffer);
void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush)) void
Com_BeginRedirect(int target, char *buffer, int buffersize, void (*flush))
{ {
if (!target || !buffer || !buffersize || !flush) if (!target || !buffer || !buffersize || !flush)
{
return; return;
}
rd_target = target; rd_target = target;
rd_buffer = buffer; rd_buffer = buffer;
@ -53,7 +56,8 @@ void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush))
*rd_buffer = 0; *rd_buffer = 0;
} }
void Com_EndRedirect (void) void
Com_EndRedirect(void)
{ {
rd_flush(rd_target, rd_buffer); rd_flush(rd_target, rd_buffer);
@ -67,91 +71,106 @@ void Com_EndRedirect (void)
* Both client and server can use this, and it will output * Both client and server can use this, and it will output
* to the apropriate place. * to the apropriate place.
*/ */
void Com_Printf (char *fmt, ...) void
Com_Printf(char *fmt, ...)
{ {
va_list argptr; va_list argptr;
char msg[MAXPRINTMSG]; char msg[MAXPRINTMSG];
va_start (argptr,fmt); va_start(argptr, fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr); vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
va_end (argptr); va_end(argptr);
if (rd_target) if (rd_target)
{ {
if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
{ {
rd_flush(rd_target, rd_buffer); rd_flush(rd_target, rd_buffer);
*rd_buffer = 0; *rd_buffer = 0;
} }
strcat (rd_buffer, msg); strcat(rd_buffer, msg);
return; return;
} }
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
Con_Print (msg); Con_Print(msg);
#endif #endif
/* also echo to debugging console */ /* also echo to debugging console */
Sys_ConsoleOutput (msg); Sys_ConsoleOutput(msg);
/* logfile */ /* logfile */
if (logfile_active && logfile_active->value) if (logfile_active && logfile_active->value)
{ {
char name[MAX_QPATH]; char name[MAX_QPATH];
if (!logfile) if (!logfile)
{ {
Com_sprintf (name, sizeof(name), "%s/qconsole.log", FS_Gamedir ()); Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());
if (logfile_active->value > 2) if (logfile_active->value > 2)
logfile = fopen (name, "a"); {
logfile = fopen(name, "a");
}
else else
logfile = fopen (name, "w"); {
logfile = fopen(name, "w");
}
} }
if (logfile) if (logfile)
fprintf (logfile, "%s", msg); {
fprintf(logfile, "%s", msg);
}
if (logfile_active->value > 1) if (logfile_active->value > 1)
fflush (logfile); /* force it to save every time */ {
fflush(logfile); /* force it to save every time */
}
} }
} }
/* /*
* A Com_Printf that only shows up if the "developer" cvar is set * A Com_Printf that only shows up if the "developer" cvar is set
*/ */
void Com_DPrintf (char *fmt, ...) void
Com_DPrintf(char *fmt, ...)
{ {
va_list argptr; va_list argptr;
char msg[MAXPRINTMSG]; char msg[MAXPRINTMSG];
if (!developer || !developer->value) if (!developer || !developer->value)
return; /* don't confuse non-developers with techie stuff... */ {
return; /* don't confuse non-developers with techie stuff... */
}
va_start (argptr,fmt); va_start(argptr, fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr); vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
va_end (argptr); va_end(argptr);
Com_Printf ("%s", msg); Com_Printf("%s", msg);
} }
/* /*
* A Com_Printf that only shows up when either the "modder" or "developer" * A Com_Printf that only shows up when either the "modder" or "developer"
* cvars is set * cvars is set
*/ */
void Com_MDPrintf (char *fmt, ...) void
Com_MDPrintf(char *fmt, ...)
{ {
va_list argptr; va_list argptr;
char msg[MAXPRINTMSG]; char msg[MAXPRINTMSG];
if((!modder || !modder->value) && (!developer || !developer->value)) if ((!modder || !modder->value) && (!developer || !developer->value))
{
return; return;
}
va_start (argptr,fmt); va_start(argptr, fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr); vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
va_end (argptr); va_end(argptr);
Com_Printf("%s", msg); Com_Printf("%s", msg);
} }
@ -160,56 +179,60 @@ void Com_MDPrintf (char *fmt, ...)
* Both client and server can use this, and it will * Both client and server can use this, and it will
* do the apropriate things. * do the apropriate things.
*/ */
void Com_Error (int code, char *fmt, ...) void
Com_Error(int code, char *fmt, ...)
{ {
va_list argptr; va_list argptr;
static char msg[MAXPRINTMSG]; static char msg[MAXPRINTMSG];
static qboolean recursive; static qboolean recursive;
if (recursive) if (recursive)
Sys_Error ("recursive error after: %s", msg); {
Sys_Error("recursive error after: %s", msg);
}
recursive = true; recursive = true;
va_start (argptr,fmt); va_start(argptr, fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr); vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
va_end (argptr); va_end(argptr);
if (code == ERR_DISCONNECT) if (code == ERR_DISCONNECT)
{ {
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
CL_Drop (); CL_Drop();
#endif #endif
recursive = false; recursive = false;
longjmp (abortframe, -1); longjmp(abortframe, -1);
} }
else if (code == ERR_DROP) else if (code == ERR_DROP)
{ {
Com_Printf ("********************\nERROR: %s\n********************\n", msg); Com_Printf("********************\nERROR: %s\n********************\n",
SV_Shutdown (va("Server crashed: %s\n", msg), false); msg);
SV_Shutdown(va("Server crashed: %s\n", msg), false);
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
CL_Drop (); CL_Drop();
#endif #endif
recursive = false; recursive = false;
longjmp (abortframe, -1); longjmp(abortframe, -1);
} }
else else
{ {
SV_Shutdown (va("Server fatal crashed: %s\n", msg), false); SV_Shutdown(va("Server fatal crashed: %s\n", msg), false);
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
CL_Shutdown (); CL_Shutdown();
#endif #endif
} }
if (logfile) if (logfile)
{ {
fclose (logfile); fclose(logfile);
logfile = NULL; logfile = NULL;
} }
Sys_Error ("%s", msg); Sys_Error("%s", msg);
recursive = false; recursive = false;
} }
@ -217,19 +240,23 @@ void Com_Error (int code, char *fmt, ...)
* Both client and server can use this, and it will * Both client and server can use this, and it will
* do the apropriate things. * do the apropriate things.
*/ */
void Com_Quit (void) void
Com_Quit(void)
{ {
Com_Printf("\n----------- shutting down ----------\n"); Com_Printf("\n----------- shutting down ----------\n");
SV_Shutdown ("Server quit\n", false); SV_Shutdown("Server quit\n", false);
Sys_Quit (); Sys_Quit();
} }
int Com_ServerState (void) int
Com_ServerState(void)
{ {
return server_state; return server_state;
} }
void Com_SetServerState (int state) void
Com_SetServerState(int state)
{ {
server_state = state; server_state = state;
} }