X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=common.c;h=c4461231503c32f80eb3ee79e5444b04a56618e5;hp=cd6c392c2686733c192c889ecbbef1343f4fdbd3;hb=ef35a088cb3ab1900acdbd5285465cd845368e79;hpb=1ae145acaf81ed231a047916ec42c786368bc560 diff --git a/common.c b/common.c index cd6c392c..c4461231 100644 --- a/common.c +++ b/common.c @@ -163,7 +163,7 @@ Handles byte ordering and avoids alignment errors void MSG_WriteChar (sizebuf_t *sb, int c) { qbyte *buf; - + buf = SZ_GetSpace (sb, 1); buf[0] = c; } @@ -171,7 +171,7 @@ void MSG_WriteChar (sizebuf_t *sb, int c) void MSG_WriteByte (sizebuf_t *sb, int c) { qbyte *buf; - + buf = SZ_GetSpace (sb, 1); buf[0] = c; } @@ -257,61 +257,81 @@ void MSG_BeginReading (void) msg_badread = false; } -int MSG_ReadShort (void) +int MSG_ReadLittleShort (void) { - int c; - if (msg_readcount+2 > net_message.cursize) { msg_badread = true; return -1; } - - c = (short)(net_message.data[msg_readcount] - + (net_message.data[msg_readcount+1]<<8)); - msg_readcount += 2; - - return c; + return (short)(net_message.data[msg_readcount-2] | (net_message.data[msg_readcount-1]<<8)); } -int MSG_ReadLong (void) +int MSG_ReadBigShort (void) { - int c; + if (msg_readcount+2 > net_message.cursize) + { + msg_badread = true; + return -1; + } + msg_readcount += 2; + return (short)((net_message.data[msg_readcount-2]<<8) + net_message.data[msg_readcount-1]); +} +int MSG_ReadLittleLong (void) +{ if (msg_readcount+4 > net_message.cursize) { msg_badread = true; return -1; } - - c = net_message.data[msg_readcount] - + (net_message.data[msg_readcount+1]<<8) - + (net_message.data[msg_readcount+2]<<16) - + (net_message.data[msg_readcount+3]<<24); - msg_readcount += 4; + return net_message.data[msg_readcount-4] | (net_message.data[msg_readcount-3]<<8) | (net_message.data[msg_readcount-2]<<16) | (net_message.data[msg_readcount-1]<<24); +} - return c; +int MSG_ReadBigLong (void) +{ + if (msg_readcount+4 > net_message.cursize) + { + msg_badread = true; + return -1; + } + msg_readcount += 4; + return (net_message.data[msg_readcount-4]<<24) + (net_message.data[msg_readcount-3]<<16) + (net_message.data[msg_readcount-2]<<8) + net_message.data[msg_readcount-1]; } -float MSG_ReadFloat (void) +float MSG_ReadLittleFloat (void) { union { - qbyte b[4]; float f; int l; } dat; - - dat.b[0] = net_message.data[msg_readcount]; - dat.b[1] = net_message.data[msg_readcount+1]; - dat.b[2] = net_message.data[msg_readcount+2]; - dat.b[3] = net_message.data[msg_readcount+3]; + if (msg_readcount+4 > net_message.cursize) + { + msg_badread = true; + return -1; + } msg_readcount += 4; + dat.l = net_message.data[msg_readcount-4] | (net_message.data[msg_readcount-3]<<8) | (net_message.data[msg_readcount-2]<<16) | (net_message.data[msg_readcount-1]<<24); + return dat.f; +} - dat.l = LittleLong (dat.l); - +float MSG_ReadBigFloat (void) +{ + union + { + float f; + int l; + } dat; + if (msg_readcount+4 > net_message.cursize) + { + msg_badread = true; + return -1; + } + msg_readcount += 4; + dat.l = (net_message.data[msg_readcount-4]<<24) | (net_message.data[msg_readcount-3]<<16) | (net_message.data[msg_readcount-2]<<8) | net_message.data[msg_readcount-1]; return dat.f; } @@ -319,37 +339,35 @@ char *MSG_ReadString (void) { static char string[2048]; int l,c; - - l = 0; - do - { - c = MSG_ReadChar (); - if (c == -1 || c == 0) - break; + for (l = 0;l < (int) sizeof(string) - 1 && (c = MSG_ReadChar()) != -1 && c != 0;l++) string[l] = c; - l++; - } while (l < (int)sizeof(string)-1); - string[l] = 0; - return string; } +int MSG_ReadBytes (int numbytes, unsigned char *out) +{ + int l, c; + for (l = 0;l < numbytes && (c = MSG_ReadChar()) != -1;l++) + out[l] = c; + return l; +} + // used by server (always latest dpprotocol) float MSG_ReadDPCoord (void) { - return (signed short) MSG_ReadShort(); + return (signed short) MSG_ReadLittleShort(); } // used by client float MSG_ReadCoord (void) { if (dpprotocol == DPPROTOCOL_VERSION2 || dpprotocol == DPPROTOCOL_VERSION3) - return (signed short) MSG_ReadShort(); + return (signed short) MSG_ReadLittleShort(); else if (dpprotocol == DPPROTOCOL_VERSION1) - return MSG_ReadFloat(); + return MSG_ReadLittleFloat(); else - return MSG_ReadShort() * (1.0f/8.0f); + return MSG_ReadLittleShort() * (1.0f/8.0f); } @@ -488,7 +506,7 @@ COM_ParseToken Parse a token out of a string ============== */ -int COM_ParseToken (const char **datapointer) +int COM_ParseToken(const char **datapointer, int returnnewline) { int c; int len; @@ -505,7 +523,7 @@ int COM_ParseToken (const char **datapointer) // skip whitespace skipwhite: - while ((c = *data) <= ' ') + while ((c = *data) <= ' ' && (c != '\n' || !returnnewline)) { if (c == 0) { @@ -516,15 +534,25 @@ skipwhite: data++; } -// skip // comments - if (c=='/' && data[1] == '/') + // check if it's a comment + if (c == '/') { - while (*data && *data != '\n') - data++; - goto skipwhite; + // skip // comments + if (data[1] == '/') + { + while (*data && *data != '\n') + data++; + goto skipwhite; + } + // skip /* comments + if (data[1] == '*') + { + while (*data && *data != '*' && data[1] != '/') + data++; + goto skipwhite; + } } - // handle quoted strings specially if (c == '\"') { @@ -532,7 +560,7 @@ skipwhite: while (1) { c = *data++; - if (c=='\"' || !c) + if (c == '\"' || !c) { com_token[len] = 0; *datapointer = data; @@ -544,7 +572,7 @@ skipwhite: } // parse single characters - if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':') + if (c == '{' || c == '}' || c == ')' || c == '(' || c == ']' || c == '[' || c == '\'' || c == ':' || c == ',' || c == ';' || c == '\n') { com_token[len] = c; len++; @@ -560,7 +588,7 @@ skipwhite: data++; len++; c = *data; - if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':') + if (c == '{' || c == '}' || c == ')' || c == '(' || c == ']' || c == '[' || c == '\'' || c == ':' || c == ',' || c == ';') break; } while (c>32); @@ -652,21 +680,27 @@ void COM_InitGameType (void) if (strstr(name, "transfusion")) gamemode = GAME_TRANSFUSION; - else if (strstr(name, "nexiuz")) - gamemode = GAME_NEXIUZ; + else if (strstr(name, "nexuiz")) + gamemode = GAME_NEXUIZ; else if (strstr(name, "nehahra")) gamemode = GAME_NEHAHRA; else if (strstr(name, "hipnotic")) gamemode = GAME_HIPNOTIC; else if (strstr(name, "rogue")) gamemode = GAME_ROGUE; + else if (strstr(name, "gvb2")) + gamemode = GAME_GOODVSBAD2; + else if (strstr(name, "teu")) + gamemode = GAME_TEU; + else if (strstr(name, "battlemech")) + gamemode = GAME_BATTLEMECH; else gamemode = GAME_NORMAL; if (COM_CheckParm ("-transfusion")) gamemode = GAME_TRANSFUSION; - else if (COM_CheckParm ("-nexiuz")) - gamemode = GAME_NEXIUZ; + else if (COM_CheckParm ("-nexuiz")) + gamemode = GAME_NEXUIZ; else if (COM_CheckParm ("-nehahra")) gamemode = GAME_NEHAHRA; else if (COM_CheckParm ("-hipnotic")) @@ -675,6 +709,12 @@ void COM_InitGameType (void) gamemode = GAME_ROGUE; else if (COM_CheckParm ("-quake")) gamemode = GAME_NORMAL; + else if (COM_CheckParm ("-goodvsbad2")) + gamemode = GAME_GOODVSBAD2; + else if (COM_CheckParm ("-teu")) + gamemode = GAME_TEU; + else if (COM_CheckParm ("-battlemech")) + gamemode = GAME_BATTLEMECH; switch(gamemode) { @@ -694,14 +734,26 @@ void COM_InitGameType (void) gamename = "DarkPlaces-Nehahra"; gamedirname = "nehahra"; break; - case GAME_NEXIUZ: - gamename = "Nexiuz"; + case GAME_NEXUIZ: + gamename = "Nexuiz"; gamedirname = "data"; break; case GAME_TRANSFUSION: gamename = "Transfusion"; gamedirname = "transfusion"; break; + case GAME_GOODVSBAD2: + gamename = "GoodVs.Bad2"; + gamedirname = "rts"; + break; + case GAME_TEU: + gamename = "TheEvilUnleashed"; + gamedirname = "teu"; + break; + case GAME_BATTLEMECH: + gamename = "Battlemech"; + gamedirname = "battlemech"; + break; default: Sys_Error("COM_InitGameType: unknown gamemode %i\n", gamemode); break; @@ -749,6 +801,7 @@ void COM_Init (void) Mathlib_Init(); FS_Init (); + Con_InitLogging(); COM_CheckRegistered (); COM_InitGameType(); @@ -813,3 +866,66 @@ int COM_StringBeginsWith(const char *s, const char *match) return false; return true; } + +// written by Elric, thanks Elric! +char *SearchInfostring(const char *infostring, const char *key) +{ + static char value [256]; + char crt_key [256]; + size_t value_ind, key_ind; + char c; + + if (*infostring++ != '\\') + return NULL; + + value_ind = 0; + for (;;) + { + key_ind = 0; + + // Get the key name + for (;;) + { + c = *infostring++; + + if (c == '\0') + return NULL; + if (c == '\\') + { + crt_key[key_ind] = '\0'; + break; + } + + crt_key[key_ind++] = c; + } + + // If it's the key we are looking for, save it in "value" + if (!strcmp(crt_key, key)) + { + for (;;) + { + c = *infostring++; + + if (c == '\0' || c == '\\') + { + value[value_ind] = '\0'; + return value; + } + + value[value_ind++] = c; + } + } + + // Else, skip the value + for (;;) + { + c = *infostring++; + + if (c == '\0') + return NULL; + if (c == '\\') + break; + } + } +} +