--- quake2/qcommon/common.c 2018/04/24 17:58:33 1.1 +++ quake2/qcommon/common.c 2018/04/24 17:58:41 1.1.1.2 @@ -1,14 +1,22 @@ // common.c -- misc functions used in client and server #include "qcommon.h" #include + #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; + cvar_t *host_speeds; cvar_t *log_stats; cvar_t *developer; @@ -17,22 +25,30 @@ cvar_t *fixedtime; cvar_t *logfile_active; // 1 = buffer log, 2 = flush after each print cvar_t *showtrace; cvar_t *dedicated; + FILE *logfile; + int server_state; + // host_speeds times int time_before_game; int time_after_game; int time_before_ref; int time_after_ref; + /* ============================================================================ + 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) @@ -58,6 +74,7 @@ void Com_EndRedirect (void) /* ============= Com_Printf + Both client and server can use this, and it will output to the apropriate place. ============= @@ -66,9 +83,11 @@ void Com_Printf (char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; + va_start (argptr,fmt); vsprintf (msg,fmt,argptr); va_end (argptr); + if (rd_target) { if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) @@ -84,6 +103,7 @@ void Com_Printf (char *fmt, ...) // also echo to debugging console Sys_ConsoleOutput (msg); + // logfile if (logfile_active && logfile_active->value) { @@ -100,9 +120,12 @@ void Com_Printf (char *fmt, ...) fflush (logfile); // force it to save every time } } + + /* ================ Com_DPrintf + A Com_Printf that only shows up if the "developer" cvar is set ================ */ @@ -113,15 +136,19 @@ void Com_DPrintf (char *fmt, ...) if (!developer || !developer->value) return; // don't confuse non-developers with techie stuff... + va_start (argptr,fmt); vsprintf (msg,fmt,argptr); va_end (argptr); Com_Printf ("%s", msg); } + + /* ============= Com_Error + Both client and server can use this, and it will do the apropriate things. ============= @@ -131,9 +158,11 @@ 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); vsprintf (msg,fmt,argptr); va_end (argptr); @@ -157,16 +186,21 @@ void Com_Error (int code, char *fmt, ... SV_Shutdown (va("Server fatal crashed: %s\n", msg), false); CL_Shutdown (); } + if (logfile) { fclose (logfile); logfile = NULL; } + Sys_Error ("%s", msg); } + + /* ============= Com_Quit + Both client and server can use this, and it will do the apropriate things. ============= @@ -175,13 +209,17 @@ void Com_Quit (void) { SV_Shutdown ("Server quit\n", false); CL_Shutdown (); + if (logfile) { fclose (logfile); logfile = NULL; } + Sys_Quit (); } + + /* ================== Com_ServerState @@ -191,6 +229,7 @@ int Com_ServerState (void) { return server_state; } + /* ================== Com_SetServerState @@ -200,19 +239,26 @@ void Com_SetServerState (int state) { server_state = state; } + + /* ============================================================================== + MESSAGE IO FUNCTIONS + Handles byte ordering and avoids alignment errors ============================================================================== */ + vec3_t bytedirs[NUMVERTEXNORMALS] = { #include "../client/anorms.h" }; + // // writing functions // + void MSG_WriteChar (sizebuf_t *sb, int c) { byte *buf; @@ -221,9 +267,11 @@ void MSG_WriteChar (sizebuf_t *sb, int c if (c < -128 || c > 127) Com_Error (ERR_FATAL, "MSG_WriteChar: range error"); #endif + buf = SZ_GetSpace (sb, 1); buf[0] = c; } + void MSG_WriteByte (sizebuf_t *sb, int c) { byte *buf; @@ -232,9 +280,11 @@ void MSG_WriteByte (sizebuf_t *sb, int c if (c < 0 || c > 255) Com_Error (ERR_FATAL, "MSG_WriteByte: range error"); #endif + buf = SZ_GetSpace (sb, 1); buf[0] = c; } + void MSG_WriteShort (sizebuf_t *sb, int c) { byte *buf; @@ -243,10 +293,12 @@ void MSG_WriteShort (sizebuf_t *sb, int if (c < ((short)0x8000) || c > (short)0x7fff) Com_Error (ERR_FATAL, "MSG_WriteShort: range error"); #endif + buf = SZ_GetSpace (sb, 2); buf[0] = c&0xff; buf[1] = c>>8; } + void MSG_WriteLong (sizebuf_t *sb, int c) { byte *buf; @@ -257,6 +309,7 @@ void MSG_WriteLong (sizebuf_t *sb, int c buf[2] = (c>>16)&0xff; buf[3] = c>>24; } + void MSG_WriteFloat (sizebuf_t *sb, float f) { union @@ -271,6 +324,7 @@ void MSG_WriteFloat (sizebuf_t *sb, floa SZ_Write (sb, &dat.l, 4); } + void MSG_WriteString (sizebuf_t *sb, char *s) { if (!s) @@ -278,28 +332,34 @@ void MSG_WriteString (sizebuf_t *sb, cha else SZ_Write (sb, s, strlen(s)+1); } + void MSG_WriteCoord (sizebuf_t *sb, float f) { MSG_WriteShort (sb, (int)(f*8)); } + void MSG_WritePos (sizebuf_t *sb, vec3_t pos) { MSG_WriteShort (sb, (int)(pos[0]*8)); MSG_WriteShort (sb, (int)(pos[1]*8)); MSG_WriteShort (sb, (int)(pos[2]*8)); } + void MSG_WriteAngle (sizebuf_t *sb, float f) { MSG_WriteByte (sb, (int)(f*256/360) & 255); } + void MSG_WriteAngle16 (sizebuf_t *sb, float f) { MSG_WriteShort (sb, ANGLE2SHORT(f)); } + void MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd) { int bits; + // // send the movement message // @@ -320,7 +380,9 @@ void MSG_WriteDeltaUsercmd (sizebuf_t *b bits |= CM_BUTTONS; if (cmd->impulse != from->impulse) bits |= CM_IMPULSE; + MSG_WriteByte (buf, bits); + if (bits & CM_ANGLE1) MSG_WriteShort (buf, cmd->angles[0]); if (bits & CM_ANGLE2) @@ -334,13 +396,17 @@ void MSG_WriteDeltaUsercmd (sizebuf_t *b MSG_WriteShort (buf, cmd->sidemove); if (bits & CM_UP) MSG_WriteShort (buf, cmd->upmove); + if (bits & CM_BUTTONS) MSG_WriteByte (buf, cmd->buttons); if (bits & CM_IMPULSE) MSG_WriteByte (buf, cmd->impulse); + MSG_WriteByte (buf, cmd->msec); MSG_WriteByte (buf, cmd->lightlevel); } + + void MSG_WriteDir (sizebuf_t *sb, vec3_t dir) { int i, best; @@ -351,6 +417,7 @@ void MSG_WriteDir (sizebuf_t *sb, vec3_t MSG_WriteByte (sb, 0); return; } + bestd = 0; best = 0; for (i=0 ; i= NUMVERTEXNORMALS) Com_Error (ERR_DROP, "MSF_ReadDir: out of range"); VectorCopy (bytedirs[b], dir); } + + /* ================== MSG_WriteDeltaEntity + Writes part of a packetentities message. Can delta from either a baseline or a previous packet_entity ================== */ -void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force) +void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, qboolean newentity) { int bits; @@ -387,6 +460,7 @@ void MSG_WriteDeltaEntity (entity_state_ Com_Error (ERR_FATAL, "Unset entity number"); if (to->number >= MAX_EDICTS) Com_Error (ERR_FATAL, "Entity number >= MAX_EDICTS"); + // send an update bits = 0; @@ -399,6 +473,7 @@ void MSG_WriteDeltaEntity (entity_state_ bits |= U_ORIGIN2; if (to->origin[2] != from->origin[2]) bits |= U_ORIGIN3; + if ( to->angles[0] != from->angles[0] ) bits |= U_ANGLE1; if ( to->angles[1] != from->angles[1] ) @@ -423,6 +498,7 @@ void MSG_WriteDeltaEntity (entity_state_ else bits |= U_FRAME16; } + if ( to->effects != from->effects ) { if (to->effects < 256) @@ -458,18 +534,19 @@ void MSG_WriteDeltaEntity (entity_state_ bits |= U_MODEL3; if ( to->modelindex4 != from->modelindex4 ) bits |= U_MODEL4; + if ( to->sound != from->sound ) bits |= U_SOUND; - if (to->old_origin[0] != from->old_origin[0] - || to->old_origin[1] != from->old_origin[1] - || to->old_origin[2] != from->old_origin[2] ) - bits |= U_OLDORIGIN; // FIXME: only when newly seen!!! + if (newentity || (to->renderfx & RF_BEAM)) + bits |= U_OLDORIGIN; + // // write the message // if (!bits && !force) return; // nothing to send! + //---------- if (bits & 0xff000000) @@ -478,7 +555,9 @@ void MSG_WriteDeltaEntity (entity_state_ bits |= U_MOREBITS2 | U_MOREBITS1; else if (bits & 0x0000ff00) bits |= U_MOREBITS1; + MSG_WriteByte (msg, bits&255 ); + if (bits & 0xff000000) { MSG_WriteByte (msg, (bits>>8)&255 ); @@ -494,12 +573,14 @@ void MSG_WriteDeltaEntity (entity_state_ { MSG_WriteByte (msg, (bits>>8)&255 ); } + //---------- if (bits & U_NUMBER16) MSG_WriteShort (msg, to->number); else MSG_WriteByte (msg, to->number); + if (bits & U_MODEL) MSG_WriteByte (msg, to->modelindex); if (bits & U_MODEL2) @@ -508,10 +589,12 @@ void MSG_WriteDeltaEntity (entity_state_ MSG_WriteByte (msg, to->modelindex3); if (bits & U_MODEL4) MSG_WriteByte (msg, to->modelindex4); + if (bits & U_FRAME8) MSG_WriteByte (msg, to->frame); if (bits & U_FRAME16) MSG_WriteShort (msg, to->frame); + if ((bits & U_SKIN8) && (bits & U_SKIN16)) //used for laser colors MSG_WriteLong (msg, to->skinnum); else if (bits & U_SKIN8) @@ -519,36 +602,42 @@ void MSG_WriteDeltaEntity (entity_state_ else if (bits & U_SKIN16) MSG_WriteShort (msg, to->skinnum); + if ( (bits & (U_EFFECTS8|U_EFFECTS16)) == (U_EFFECTS8|U_EFFECTS16) ) MSG_WriteLong (msg, to->effects); else if (bits & U_EFFECTS8) MSG_WriteByte (msg, to->effects); else if (bits & U_EFFECTS16) MSG_WriteShort (msg, to->effects); + if ( (bits & (U_RENDERFX8|U_RENDERFX16)) == (U_RENDERFX8|U_RENDERFX16) ) MSG_WriteLong (msg, to->renderfx); else if (bits & U_RENDERFX8) MSG_WriteByte (msg, to->renderfx); else if (bits & U_RENDERFX16) MSG_WriteShort (msg, to->renderfx); + if (bits & U_ORIGIN1) MSG_WriteCoord (msg, to->origin[0]); if (bits & U_ORIGIN2) MSG_WriteCoord (msg, to->origin[1]); if (bits & U_ORIGIN3) MSG_WriteCoord (msg, to->origin[2]); + if (bits & U_ANGLE1) MSG_WriteAngle(msg, to->angles[0]); if (bits & U_ANGLE2) MSG_WriteAngle(msg, to->angles[1]); if (bits & U_ANGLE3) MSG_WriteAngle(msg, to->angles[2]); + if (bits & U_OLDORIGIN) { MSG_WriteCoord (msg, to->old_origin[0]); MSG_WriteCoord (msg, to->old_origin[1]); MSG_WriteCoord (msg, to->old_origin[2]); } + if (bits & U_SOUND) MSG_WriteByte (msg, to->sound); if (bits & U_EVENT) @@ -556,14 +645,19 @@ void MSG_WriteDeltaEntity (entity_state_ if (bits & U_SOLID) MSG_WriteShort (msg, to->solid); } + + //============================================================ + // // reading functions // + void MSG_BeginReading (sizebuf_t *msg) { msg->readcount = 0; } + // returns -1 if no more characters are available int MSG_ReadChar (sizebuf_t *msg_read) { @@ -577,6 +671,7 @@ int MSG_ReadChar (sizebuf_t *msg_read) return c; } + int MSG_ReadByte (sizebuf_t *msg_read) { int c; @@ -589,6 +684,7 @@ int MSG_ReadByte (sizebuf_t *msg_read) return c; } + int MSG_ReadShort (sizebuf_t *msg_read) { int c; @@ -603,6 +699,7 @@ int MSG_ReadShort (sizebuf_t *msg_read) return c; } + int MSG_ReadLong (sizebuf_t *msg_read) { int c; @@ -619,6 +716,7 @@ int MSG_ReadLong (sizebuf_t *msg_read) return c; } + float MSG_ReadFloat (sizebuf_t *msg_read) { union @@ -640,8 +738,10 @@ float MSG_ReadFloat (sizebuf_t *msg_read msg_read->readcount += 4; dat.l = LittleLong (dat.l); + return dat.f; } + char *MSG_ReadString (sizebuf_t *msg_read) { static char string[2048]; @@ -661,6 +761,7 @@ char *MSG_ReadString (sizebuf_t *msg_rea return string; } + char *MSG_ReadStringLine (sizebuf_t *msg_read) { static char string[2048]; @@ -680,28 +781,35 @@ char *MSG_ReadStringLine (sizebuf_t *msg return string; } + float MSG_ReadCoord (sizebuf_t *msg_read) { return MSG_ReadShort(msg_read) * (1.0/8); } + void MSG_ReadPos (sizebuf_t *msg_read, vec3_t pos) { pos[0] = MSG_ReadShort(msg_read) * (1.0/8); pos[1] = MSG_ReadShort(msg_read) * (1.0/8); pos[2] = MSG_ReadShort(msg_read) * (1.0/8); } + float MSG_ReadAngle (sizebuf_t *msg_read) { return MSG_ReadChar(msg_read) * (360.0/256); } + float MSG_ReadAngle16 (sizebuf_t *msg_read) { return SHORT2ANGLE(MSG_ReadShort(msg_read)); } + void MSG_ReadDeltaUsercmd (sizebuf_t *msg_read, usercmd_t *from, usercmd_t *move) { int bits; + memcpy (move, from, sizeof(*move)); + bits = MSG_ReadByte (msg_read); // read current angles @@ -723,31 +831,42 @@ void MSG_ReadDeltaUsercmd (sizebuf_t *ms // read buttons if (bits & CM_BUTTONS) move->buttons = MSG_ReadByte (msg_read); + if (bits & CM_IMPULSE) move->impulse = MSG_ReadByte (msg_read); + // read time to run command move->msec = MSG_ReadByte (msg_read); + // read the light level move->lightlevel = MSG_ReadByte (msg_read); } + + void MSG_ReadData (sizebuf_t *msg_read, void *data, int len) { int i; + for (i=0 ; idata = data; buf->maxsize = length; } + void SZ_Clear (sizebuf_t *buf) { buf->cursize = 0; buf->overflowed = false; } + void *SZ_GetSpace (sizebuf_t *buf, int length) { void *data; @@ -764,20 +883,24 @@ void *SZ_GetSpace (sizebuf_t *buf, int l SZ_Clear (buf); buf->overflowed = true; } + data = buf->data + buf->cursize; buf->cursize += length; return data; } + void SZ_Write (sizebuf_t *buf, void *data, int length) { memcpy (SZ_GetSpace(buf,length),data,length); } + void SZ_Print (sizebuf_t *buf, char *data) { int len; len = strlen(data)+1; + if (buf->cursize) { if (buf->data[buf->cursize-1]) @@ -788,10 +911,15 @@ void SZ_Print (sizebuf_t *buf, char *dat else memcpy ((byte *)SZ_GetSpace(buf, len),data,len); } + + //============================================================================ + + /* ================ COM_CheckParm + Returns the position (1 to argc-1) in the program's argument list where the given parameter apears, or 0 if not present ================ @@ -808,22 +936,27 @@ int COM_CheckParm (char *parm) return 0; } + int COM_Argc (void) { return com_argc; } + char *COM_Argv (int arg) { if (arg < 0 || arg >= com_argc || !com_argv[arg]) return ""; return com_argv[arg]; } + void COM_ClearArgv (int arg) { if (arg < 0 || arg >= com_argc || !com_argv[arg]) return; com_argv[arg] = ""; } + + /* ================ COM_InitArgv @@ -832,6 +965,7 @@ COM_InitArgv void COM_InitArgv (int argc, char **argv) { int i; + if (argc > MAX_NUM_ARGVS) Com_Error (ERR_FATAL, "argc > MAX_NUM_ARGVS"); com_argc = argc; @@ -843,9 +977,11 @@ void COM_InitArgv (int argc, char **argv com_argv[i] = argv[i]; } } + /* ================ COM_AddParm + Adds the given string at the end of the current argument list ================ */ @@ -855,6 +991,10 @@ void COM_AddParm (char *parm) Com_Error (ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS"); com_argv[com_argc++] = parm; } + + + + /// just for debugging int memsearch (byte *start, int count, int search) { @@ -865,6 +1005,8 @@ int memsearch (byte *start, int count, i return i; return -1; } + + char *CopyString (char *in) { char *out; @@ -873,12 +1015,16 @@ char *CopyString (char *in) strcpy (out, in); return out; } + + + void Info_Print (char *s) { char key[512]; char value[512]; char *o; int l; + if (*s == '\\') s++; while (*s) @@ -886,6 +1032,7 @@ void Info_Print (char *s) o = key; while (*s && *s != '\\') *o++ = *s++; + l = o - key; if (l < 20) { @@ -895,28 +1042,39 @@ void Info_Print (char *s) else *o = 0; Com_Printf ("%s", key); + if (!*s) { Com_Printf ("MISSING VALUE\n"); return; } + o = value; s++; while (*s && *s != '\\') *o++ = *s++; *o = 0; + if (*s) s++; Com_Printf ("%s\n", value); } } + + /* ============================================================================== + ZONE MEMORY ALLOCATION + just cleared malloc with counters now... + ============================================================================== */ + #define Z_MAGIC 0x1d1d + + typedef struct zhead_s { struct zhead_s *prev, *next; @@ -924,8 +1082,10 @@ typedef struct zhead_s short tag; // for group free int size; } zhead_t; + zhead_t z_chain; int z_count, z_bytes; + /* ======================== Z_Free @@ -934,15 +1094,21 @@ Z_Free void Z_Free (void *ptr) { zhead_t *z; + z = ((zhead_t *)ptr) - 1; + if (z->magic != Z_MAGIC) Com_Error (ERR_FATAL, "Z_Free: bad magic"); + z->prev->next = z->next; z->next->prev = z->prev; + z_count--; z_bytes -= z->size; free (z); } + + /* ======================== Z_Stats_f @@ -952,6 +1118,7 @@ void Z_Stats_f (void) { Com_Printf ("%i bytes in %i blocks\n", z_bytes, z_count); } + /* ======================== Z_FreeTags @@ -960,6 +1127,7 @@ Z_FreeTags void Z_FreeTags (int tag) { zhead_t *z, *next; + for (z=z_chain.next ; z != &z_chain ; z=next) { next = z->next; @@ -967,6 +1135,7 @@ void Z_FreeTags (int tag) Z_Free ((void *)(z+1)); } } + /* ======================== Z_TagMalloc @@ -986,12 +1155,15 @@ void *Z_TagMalloc (int size, int tag) z->magic = Z_MAGIC; z->tag = tag; z->size = size; + z->next = z_chain.next; z->prev = &z_chain; z_chain.next->prev = z; z_chain.next = z; + return (void *)(z+1); } + /* ======================== Z_Malloc @@ -1001,6 +1173,8 @@ void *Z_Malloc (int size) { return Z_TagMalloc (size, 0); } + + //============================================================================ @@ -1009,47 +1183,178 @@ void *Z_Malloc (int size) COM_BlockSequenceCheckByte For proxy protecting + +// THIS IS MASSIVELY BROKEN! CHALLENGE MAY BE NEGATIVE +// DON'T USE THIS FUNCTION!!!!! + ==================== */ -byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence) +byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, int challenge) { + Sys_Error("COM_BlockSequenceCheckByte called\n"); + +#if 0 int checksum; - byte buf[64]; - int n; + byte buf[68]; byte *p; + float temp; + byte c; + + temp = bytedirs[(sequence/3) % NUMVERTEXNORMALS][sequence % 3]; + temp = LittleFloat(temp); + p = ((byte *)&temp); - n = sequence % (NUMVERTEXNORMALS * sizeof(vec3_t)); - p = ((byte *)bytedirs)+n; if (length > 60) length = 60; memcpy (buf, base, length); - buf[length] = (sequence & 0xff) ^ *p++; - buf[length+1] = *p++; - buf[length+2] = ((sequence>>8) & 0xff) ^ *p++; - buf[length+3] = *p; - length += 4; - checksum = Com_BlockChecksum (buf, length); + buf[length] = (sequence & 0xff) ^ p[0]; + buf[length+1] = p[1]; + buf[length+2] = ((sequence>>8) & 0xff) ^ p[2]; + buf[length+3] = p[3]; + + temp = bytedirs[((sequence+challenge)/3) % NUMVERTEXNORMALS][(sequence+challenge) % 3]; + temp = LittleFloat(temp); + p = ((byte *)&temp); + + buf[length+4] = (sequence & 0xff) ^ p[3]; + buf[length+5] = (challenge & 0xff) ^ p[2]; + buf[length+6] = ((sequence>>8) & 0xff) ^ p[1]; + buf[length+7] = ((challenge >> 7) & 0xff) ^ p[0]; + + length += 8; + + checksum = LittleLong(Com_BlockChecksum (buf, length)); checksum &= 0xff; return checksum; +#endif + return 0; +} + +static byte chktbl[1024] = { +0x84, 0x47, 0x51, 0xc1, 0x93, 0x22, 0x21, 0x24, 0x2f, 0x66, 0x60, 0x4d, 0xb0, 0x7c, 0xda, +0x88, 0x54, 0x15, 0x2b, 0xc6, 0x6c, 0x89, 0xc5, 0x9d, 0x48, 0xee, 0xe6, 0x8a, 0xb5, 0xf4, +0xcb, 0xfb, 0xf1, 0x0c, 0x2e, 0xa0, 0xd7, 0xc9, 0x1f, 0xd6, 0x06, 0x9a, 0x09, 0x41, 0x54, +0x67, 0x46, 0xc7, 0x74, 0xe3, 0xc8, 0xb6, 0x5d, 0xa6, 0x36, 0xc4, 0xab, 0x2c, 0x7e, 0x85, +0xa8, 0xa4, 0xa6, 0x4d, 0x96, 0x19, 0x19, 0x9a, 0xcc, 0xd8, 0xac, 0x39, 0x5e, 0x3c, 0xf2, +0xf5, 0x5a, 0x72, 0xe5, 0xa9, 0xd1, 0xb3, 0x23, 0x82, 0x6f, 0x29, 0xcb, 0xd1, 0xcc, 0x71, +0xfb, 0xea, 0x92, 0xeb, 0x1c, 0xca, 0x4c, 0x70, 0xfe, 0x4d, 0xc9, 0x67, 0x43, 0x47, 0x94, +0xb9, 0x47, 0xbc, 0x3f, 0x01, 0xab, 0x7b, 0xa6, 0xe2, 0x76, 0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0xfb, 0xc5, 0xd9, 0x27, 0xec, 0xc6, +0x4e, 0x65, 0x27, 0x76, 0x87, 0xa6, 0xee, 0xee, 0xd7, 0x8b, 0xd1, 0xa0, 0x5c, 0xb0, 0x42, +0x13, 0x0e, 0x95, 0x4a, 0xf2, 0x06, 0xc6, 0x43, 0x33, 0xf4, 0xc7, 0xf8, 0xe7, 0x1f, 0xdd, +0xe4, 0x46, 0x4a, 0x70, 0x39, 0x6c, 0xd0, 0xed, 0xca, 0xbe, 0x60, 0x3b, 0xd1, 0x7b, 0x57, +0x48, 0xe5, 0x3a, 0x79, 0xc1, 0x69, 0x33, 0x53, 0x1b, 0x80, 0xb8, 0x91, 0x7d, 0xb4, 0xf6, +0x17, 0x1a, 0x1d, 0x5a, 0x32, 0xd6, 0xcc, 0x71, 0x29, 0x3f, 0x28, 0xbb, 0xf3, 0x5e, 0x71, +0xb8, 0x43, 0xaf, 0xf8, 0xb9, 0x64, 0xef, 0xc4, 0xa5, 0x6c, 0x08, 0x53, 0xc7, 0x00, 0x10, +0x39, 0x4f, 0xdd, 0xe4, 0xb6, 0x19, 0x27, 0xfb, 0xb8, 0xf5, 0x32, 0x73, 0xe5, 0xcb, 0x32 +}; + +/* +==================== +COM_BlockSequenceCRCByte + +For proxy protecting +==================== +*/ +byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence) +{ + unsigned short crc; + byte *p; + byte chkb[60 + 4]; + + if (sequence < 0) + Sys_Error("sequence < 0, this shouldn't happen\n"); + + p = chktbl + (sequence % (sizeof(chktbl) - 4)); + + if (length > 60) + length = 60; + memcpy (chkb, base, length); + + chkb[length] = p[0]; + chkb[length+1] = p[1]; + chkb[length+2] = p[2]; + chkb[length+3] = p[3]; + + length += 4; + + crc = CRC_Block(chkb, length); + + crc &= 0xff; + + return crc; } //======================================================== + float frand(void) { return (rand()&32767)* (1.0/32767); } + float crand(void) { return (rand()&32767)* (2.0/32767) - 1; } + void Key_Init (void); void SCR_EndLoadingPlaque (void); + /* ============= Com_Error_f + Just throw a fatal error to test error shutdown procedures ============= @@ -1068,33 +1373,45 @@ Qcommon_Init void Qcommon_Init (int argc, char **argv) { char *s; + if (setjmp (abortframe) ) Sys_Error ("Error during initialization"); + z_chain.next = z_chain.prev = &z_chain; + // prepare enough of the subsystems to handle // cvar and command buffer management COM_InitArgv (argc, argv); + Swap_Init (); Cbuf_Init (); + Cmd_Init (); Cvar_Init (); + Key_Init (); + // we need to add the early commands twice, because // a basedir or cddir needs to be set before execing // config files, but we want other parms to override // the settings of the config files Cbuf_AddEarlyCommands (false); Cbuf_Execute (); + FS_InitFilesystem (); + Cbuf_AddText ("exec default.cfg\n"); Cbuf_AddText ("exec config.cfg\n"); + Cbuf_AddEarlyCommands (true); Cbuf_Execute (); + // // init commands and vars // Cmd_AddCommand ("z_stats", Z_Stats_f); Cmd_AddCommand ("error", Com_Error_f); + host_speeds = Cvar_Get ("host_speeds", "0", 0); log_stats = Cvar_Get ("log_stats", "0", 0); developer = Cvar_Get ("developer", "0", 0); @@ -1102,16 +1419,27 @@ void Qcommon_Init (int argc, char **argv fixedtime = Cvar_Get ("fixedtime", "0", 0); logfile_active = Cvar_Get ("logfile", "0", 0); showtrace = Cvar_Get ("showtrace", "0", 0); +#ifdef DEDICATED_ONLY + dedicated = Cvar_Get ("dedicated", "1", CVAR_NOSET); +#else dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET); +#endif + s = va("%4.2f %s %s %s", VERSION, CPUSTRING, __DATE__, BUILDSTRING); Cvar_Get ("version", s, CVAR_SERVERINFO|CVAR_NOSET); + + if (dedicated->value) Cmd_AddCommand ("quit", Com_Quit); + Sys_Init (); + NET_Init (); Netchan_Init (); + SV_Init (); CL_Init (); + // add + commands from command line if (!Cbuf_AddLateCommands ()) { // if the user didn't give any commands, run default action @@ -1126,8 +1454,10 @@ void Qcommon_Init (int argc, char **argv // so drop the loading plaque SCR_EndLoadingPlaque (); } + Com_Printf ("====== Quake2 Initialized ======\n\n"); } + /* ================= Qcommon_Frame @@ -1137,6 +1467,7 @@ void Qcommon_Frame (int msec) { char *s; int time_before, time_between, time_after; + if (setjmp (abortframe) ) return; // an ERR_DROP was thrown @@ -1163,6 +1494,7 @@ void Qcommon_Frame (int msec) } } } + if (fixedtime->value) msec = fixedtime->value; else if (timescale->value) @@ -1176,11 +1508,13 @@ void Qcommon_Frame (int msec) { extern int c_traces, c_brush_traces; extern int c_pointcontents; + Com_Printf ("%4i traces %4i points\n", c_traces, c_pointcontents); c_traces = 0; c_brush_traces = 0; c_pointcontents = 0; } + do { s = Sys_ConsoleInput (); @@ -1188,17 +1522,25 @@ void Qcommon_Frame (int msec) Cbuf_AddText (va("%s\n",s)); } while (s); Cbuf_Execute (); + if (host_speeds->value) time_before = Sys_Milliseconds (); + SV_Frame (msec); + if (host_speeds->value) time_between = Sys_Milliseconds (); + CL_Frame (msec); + if (host_speeds->value) time_after = Sys_Milliseconds (); + + if (host_speeds->value) { int all, sv, gm, cl, rf; + all = time_after - time_before; sv = time_between - time_before; cl = time_after - time_between; @@ -1210,6 +1552,7 @@ void Qcommon_Frame (int msec) all, sv, gm, cl, rf); } } + /* ================= Qcommon_Shutdown