SPlit the client/server-stuff into an own file

This commit is contained in:
Yamagi Burmeister 2010-08-31 08:40:45 +00:00
parent a54576c9ce
commit 2ec78c2df7
3 changed files with 256 additions and 214 deletions

View File

@ -203,6 +203,7 @@ COMMON_OBJS = \
build/common/cmd_execution.o \
build/common/cmd_parser.o \
build/common/cmd_script.o \
build/common/com_clientserver.o \
build/common/common.o \
build/common/crc.o \
build/common/cvar.o \
@ -281,6 +282,7 @@ DEDICATED_SERVER_COMMON_OBJS = \
build/dedicated_server_common/cmd_execution.o \
build/dedicated_server_common/cmd_parser.o \
build/dedicated_server_common/cmd_script.o \
build/dedicated_server_common/com_clientserver.o \
build/dedicated_server_common/common.o \
build/dedicated_server_common/crc.o \
build/dedicated_server_common/cvar.o \
@ -517,6 +519,9 @@ build/common/cmd_parser.o : src/common/cmd_parser.c
build/common/cmd_script.o : src/common/cmd_script.c
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
build/common/com_clientserver.o : src/common/com_clientserver.c
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
build/common/common.o : src/common/common.c
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
@ -666,9 +671,12 @@ build/dedicated_server_common/cmd_parser.o : src/common/cmd_parser.c
build/dedicated_server_common/cmd_script.o : src/common/cmd_script.c
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
build/dedicated_server_common/common.o : src/common/common.c
build/dedicated_server_common/com_clientserver.o : src/common/com_clientserver.c
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
build/dedicated_server_common/common.o : src/common/common.c
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
build/dedicated_server_common/crc.o : src/common/crc.c
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<

View File

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

View File

@ -21,13 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "qcommon.h"
#include <setjmp.h>
#define MAXPRINTMSG 4096
#define MAX_NUM_ARGVS 50
int com_argc;
char *com_argv[MAX_NUM_ARGVS+1];
int realtime;
jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */
FILE *log_stats_file;
@ -37,15 +35,13 @@ cvar_t *developer;
cvar_t *modder;
cvar_t *timescale;
cvar_t *fixedtime;
cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */
#ifndef DEDICATED_ONLY
cvar_t *showtrace;
#endif
cvar_t *dedicated;
FILE *logfile;
int server_state;
extern cvar_t *logfile_active;
extern jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */
/* host_speeds times */
int time_before_game;
@ -61,213 +57,6 @@ CLIENT / SERVER interactions
============================================================================
*/
static int rd_target;
static char *rd_buffer;
static int rd_buffersize;
static void (*rd_flush)(int target, char *buffer);
void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush))
{
if (!target || !buffer || !buffersize || !flush)
return;
rd_target = target;
rd_buffer = buffer;
rd_buffersize = buffersize;
rd_flush = flush;
*rd_buffer = 0;
}
void Com_EndRedirect (void)
{
rd_flush(rd_target, rd_buffer);
rd_target = 0;
rd_buffer = NULL;
rd_buffersize = 0;
rd_flush = NULL;
}
/*
* Both client and server can use this, and it will output
* to the apropriate place.
*/
void Com_Printf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
if (rd_target)
{
if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
{
rd_flush(rd_target, rd_buffer);
*rd_buffer = 0;
}
strcat (rd_buffer, msg);
return;
}
#ifndef DEDICATED_ONLY
Con_Print (msg);
#endif
/* also echo to debugging console */
Sys_ConsoleOutput (msg);
/* logfile */
if (logfile_active && logfile_active->value)
{
char name[MAX_QPATH];
if (!logfile)
{
Com_sprintf (name, sizeof(name), "%s/qconsole.log", FS_Gamedir ());
if (logfile_active->value > 2)
logfile = fopen (name, "a");
else
logfile = fopen (name, "w");
}
if (logfile)
fprintf (logfile, "%s", msg);
if (logfile_active->value > 1)
fflush (logfile); /* force it to save every time */
}
}
/*
* A Com_Printf that only shows up if the "developer" cvar is set
*/
void Com_DPrintf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
if (!developer || !developer->value)
return; /* don't confuse non-developers with techie stuff... */
va_start (argptr,fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
Com_Printf ("%s", msg);
}
/*
* A Com_Printf that only shows up when either the "modder" or "developer"
* cvars is set
*/
void Com_MDPrintf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
if((!modder || !modder->value) && (!developer || !developer->value))
return;
va_start (argptr,fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
Com_Printf("%s", msg);
}
/*
* Both client and server can use this, and it will
* do the apropriate things.
*/
void Com_Error (int code, char *fmt, ...)
{
va_list argptr;
static char msg[MAXPRINTMSG];
static qboolean recursive;
if (recursive)
Sys_Error ("recursive error after: %s", msg);
recursive = true;
va_start (argptr,fmt);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
if (code == ERR_DISCONNECT)
{
#ifndef DEDICATED_ONLY
CL_Drop ();
#endif
recursive = false;
longjmp (abortframe, -1);
}
else if (code == ERR_DROP)
{
Com_Printf ("********************\nERROR: %s\n********************\n", msg);
SV_Shutdown (va("Server crashed: %s\n", msg), false);
#ifndef DEDICATED_ONLY
CL_Drop ();
#endif
recursive = false;
longjmp (abortframe, -1);
}
else
{
SV_Shutdown (va("Server fatal crashed: %s\n", msg), false);
#ifndef DEDICATED_ONLY
CL_Shutdown ();
#endif
}
if (logfile)
{
fclose (logfile);
logfile = NULL;
}
Sys_Error ("%s", msg);
recursive = false;
}
/*
* Both client and server can use this, and it will
* do the apropriate things.
*/
void Com_Quit (void)
{
SV_Shutdown ("Server quit\n", false);
#ifndef DEDICATED_ONLY
CL_Shutdown ();
#endif
if (logfile)
{
fclose (logfile);
logfile = NULL;
}
Sys_Quit ();
}
int Com_ServerState (void)
{
return server_state;
}
void Com_SetServerState (int state)
{
server_state = state;
}
/*