X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=common.c;h=50fb662ee89b226eab570de4fbd6ecac148992d2;hb=3066e6fb3322a0fb39544a6753a89b47a7a66b0c;hp=570b6f43c4cda58ee5a6b8f94dd0335a80feff38;hpb=ac4cb312f454a6097b0f152c947cb8c9698d4bd1;p=xonotic%2Fdarkplaces.git diff --git a/common.c b/common.c index 570b6f43..50fb662e 100644 --- a/common.c +++ b/common.c @@ -27,17 +27,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -cvar_t registered = {0, "registered","0", "indicates if this is running registered quake (whether gfx/qpop.lmp was found)"}; +cvar_t registered = {0, "registered","0", "indicates if this is running registered quake (whether gfx/pop.lmp was found)"}; cvar_t cmdline = {0, "cmdline","0", "contains commandline the engine was launched with"}; -extern qboolean fs_modified; // set true if using non-id files - char com_token[MAX_INPUTLINE]; int com_argc; const char **com_argv; -char com_cmdline[MAX_INPUTLINE]; - gamemode_t gamemode; const char *gamename; const char *gamedirname1; @@ -303,15 +299,15 @@ void MSG_WriteFloat (sizebuf_t *sb, float f) void MSG_WriteString (sizebuf_t *sb, const char *s) { - if (!s) - SZ_Write (sb, (unsigned char *)"", 1); + if (!s || !*s) + MSG_WriteChar (sb, 0); else SZ_Write (sb, (unsigned char *)s, (int)strlen(s)+1); } void MSG_WriteUnterminatedString (sizebuf_t *sb, const char *s) { - if (s) + if (s && *s) SZ_Write (sb, (unsigned char *)s, (int)strlen(s)); } @@ -338,7 +334,7 @@ void MSG_WriteCoord32f (sizebuf_t *sb, float f) void MSG_WriteCoord (sizebuf_t *sb, float f, protocolversion_t protocol) { - if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE) + if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE || protocol == PROTOCOL_QUAKEWORLD) MSG_WriteCoord13i (sb, f); else if (protocol == PROTOCOL_DARKPLACES1) MSG_WriteCoord32f (sb, f); @@ -379,7 +375,7 @@ void MSG_WriteAngle32f (sizebuf_t *sb, float f) void MSG_WriteAngle (sizebuf_t *sb, float f, protocolversion_t protocol) { - if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE || protocol == PROTOCOL_DARKPLACES1 || protocol == PROTOCOL_DARKPLACES2 || protocol == PROTOCOL_DARKPLACES3 || protocol == PROTOCOL_DARKPLACES4) + if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE || protocol == PROTOCOL_DARKPLACES1 || protocol == PROTOCOL_DARKPLACES2 || protocol == PROTOCOL_DARKPLACES3 || protocol == PROTOCOL_DARKPLACES4 || protocol == PROTOCOL_QUAKEWORLD) MSG_WriteAngle8i (sb, f); else MSG_WriteAngle16i (sb, f); @@ -479,7 +475,7 @@ char *MSG_ReadString (void) { static char string[MAX_INPUTLINE]; int l,c; - for (l = 0;l < (int) sizeof(string) - 1 && (c = MSG_ReadChar()) != -1 && c != 0;l++) + for (l = 0;l < (int) sizeof(string) - 1 && (c = MSG_ReadByte()) != -1 && c != 0;l++) string[l] = c; string[l] = 0; return string; @@ -488,7 +484,7 @@ char *MSG_ReadString (void) int MSG_ReadBytes (int numbytes, unsigned char *out) { int l, c; - for (l = 0;l < numbytes && (c = MSG_ReadChar()) != -1;l++) + for (l = 0;l < numbytes && (c = MSG_ReadByte()) != -1;l++) out[l] = c; return l; } @@ -510,7 +506,7 @@ float MSG_ReadCoord32f (void) float MSG_ReadCoord (protocolversion_t protocol) { - if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE) + if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE || protocol == PROTOCOL_QUAKEWORLD) return MSG_ReadCoord13i(); else if (protocol == PROTOCOL_DARKPLACES1) return MSG_ReadCoord32f(); @@ -545,7 +541,7 @@ float MSG_ReadAngle32f (void) float MSG_ReadAngle (protocolversion_t protocol) { - if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE || protocol == PROTOCOL_DARKPLACES1 || protocol == PROTOCOL_DARKPLACES2 || protocol == PROTOCOL_DARKPLACES3 || protocol == PROTOCOL_DARKPLACES4) + if (protocol == PROTOCOL_QUAKE || protocol == PROTOCOL_QUAKEDP || protocol == PROTOCOL_NEHAHRAMOVIE || protocol == PROTOCOL_DARKPLACES1 || protocol == PROTOCOL_DARKPLACES2 || protocol == PROTOCOL_DARKPLACES3 || protocol == PROTOCOL_DARKPLACES4 || protocol == PROTOCOL_QUAKEWORLD) return MSG_ReadAngle8i (); else return MSG_ReadAngle16i (); @@ -633,7 +629,13 @@ void Com_HexDumpToConsole(const unsigned char *data, int size) { if (j < n) { - if (d[j] >= ' ' && d[j] <= 127) + // color change prefix character has to be treated specially + if (d[j] == STRING_COLOR_TAG) + { + *cur++ = STRING_COLOR_TAG; + *cur++ = STRING_COLOR_TAG; + } + else if (d[j] >= ' ') *cur++ = d[j]; else *cur++ = '.'; @@ -671,6 +673,7 @@ Parse a token out of a string int COM_ParseToken(const char **datapointer, int returnnewline) { int len; + int c; const char *data = *datapointer; len = 0; @@ -723,15 +726,34 @@ skipwhite: // quoted string for (data++;*data != '\"';data++) { - if (*data == '\\' && data[1] == '"' ) - data++; if (!*data || len >= (int)sizeof(com_token) - 1) { com_token[0] = 0; *datapointer = NULL; return false; } - com_token[len++] = *data; + c = *data; + if (*data == '\\') + { + if (data[1] == '"') + { + data++; + c = *data; + } + else if (data[1] == '\'') + { + data++; + c = *data; + } + else if (data[1] == 'n') + { + data++; + c = '\n'; + } + else if (data[1] == '\\') + data++; + } + com_token[len++] = c; } com_token[len] = 0; *datapointer = data+1; @@ -742,15 +764,34 @@ skipwhite: // quoted string for (data++;*data != '\'';data++) { - if (*data == '\\' && data[1] == '\'' ) - data++; if (!*data || len >= (int)sizeof(com_token) - 1) { com_token[0] = 0; *datapointer = NULL; return false; } - com_token[len++] = *data; + c = *data; + if (*data == '\\') + { + if (data[1] == '"') + { + data++; + c = *data; + } + else if (data[1] == '\'') + { + data++; + c = *data; + } + else if (data[1] == 'n') + { + data++; + c = '\n'; + } + else if (data[1] == '\\') + data++; + } + com_token[len++] = c; } com_token[len] = 0; *datapointer = data+1; @@ -783,7 +824,28 @@ skipwhite: *datapointer = NULL; return false; } - com_token[len++] = *data; + c = *data; + if (*data == '\\') + { + if (data[1] == '"') + { + data++; + c = *data; + } + else if (data[1] == '\'') + { + data++; + c = *data; + } + else if (data[1] == 'n') + { + data++; + c = '\n'; + } + else if (data[1] == '\\') + data++; + } + com_token[len++] = c; } com_token[len] = 0; *datapointer = data; @@ -891,69 +953,6 @@ int COM_CheckParm (const char *parm) return 0; } -/* -================ -COM_CheckRegistered - -Looks for the pop.txt file and verifies it. -Sets the "registered" cvar. -Immediately exits out if an alternate game was attempted to be started without -being registered. -================ -*/ -void COM_CheckRegistered (void) -{ - Cvar_Set ("cmdline", com_cmdline); - - if (gamemode == GAME_NORMAL && !FS_FileExists("gfx/pop.lmp")) - { - if (fs_modified) - Con_Print("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n"); - else - Con_Print("Playing shareware version.\n"); - return; - } - - Cvar_Set ("registered", "1"); - Con_Print("Playing registered version.\n"); -} - - -/* -================ -COM_InitArgv -================ -*/ -void COM_InitArgv (void) -{ - int i, j, n; - // reconstitute the command line for the cmdline externally visible cvar - n = 0; - for (j = 0;(j < MAX_NUM_ARGVS) && (j < com_argc);j++) - { - i = 0; - if (strstr(com_argv[j], " ")) - { - // arg contains whitespace, store quotes around it - com_cmdline[n++] = '\"'; - while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i]) - com_cmdline[n++] = com_argv[j][i++]; - com_cmdline[n++] = '\"'; - } - else - { - while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i]) - com_cmdline[n++] = com_argv[j][i++]; - } - if (n < ((int)sizeof(com_cmdline) - 1)) - com_cmdline[n++] = ' '; - else - break; - } - com_cmdline[n] = 0; -} - - //=========================================================================== // Game mods @@ -1002,9 +1001,6 @@ static const gamemode_info_t gamemode_info [] = // GAME_ZYMOTIC // COMMANDLINEOPTION: Game: -zymotic runs the singleplayer game Zymotic { "zymotic", "-zymotic", "Zymotic", "basezym", NULL, "zymotic", "zymotic" }, -// GAME_FNIGGIUM -// COMMANDLINEOPTION: Game: -fniggium runs the post apocalyptic melee RPG Fniggium -{ "fniggium", "-fniggium", "Fniggium", "data", NULL, "fniggium", "fniggium" }, // GAME_SETHERAL // COMMANDLINEOPTION: Game: -setheral runs the multiplayer game Setheral { "setheral", "-setheral", "Setheral", "data", NULL, "setheral", "setheral" }, @@ -1032,6 +1028,12 @@ static const gamemode_info_t gamemode_info [] = // GAME_DEFEATINDETAIL2 // COMMANDLINEOPTION: Game: -did2 runs the game Defeat In Detail 2 { "did2", "-did2", "Defeat In Detail 2", "data", NULL, "did2_", "did2" }, +// GAME_DARSANA +// COMMANDLINEOPTION: Game: -darsana runs the game Darsana +{ "darsana", "-darsana", "Darsana", "ddata", NULL, "darsana", "darsana" }, +// GAME_CONTAGIONTHEORY +// COMMANDLINEOPTION: Game: -contagiontheory runs the game Contagion Theory +{ "contagiontheory", "-contagiontheory", "Contagion Theory", "ctdata", NULL, "ct", "contagiontheory" }, }; void COM_InitGameType (void) @@ -1074,8 +1076,37 @@ COM_Init */ void COM_Init_Commands (void) { + int i, j, n; + char com_cmdline[MAX_INPUTLINE]; + Cvar_RegisterVariable (®istered); Cvar_RegisterVariable (&cmdline); + + // reconstitute the command line for the cmdline externally visible cvar + n = 0; + for (j = 0;(j < MAX_NUM_ARGVS) && (j < com_argc);j++) + { + i = 0; + if (strstr(com_argv[j], " ")) + { + // arg contains whitespace, store quotes around it + com_cmdline[n++] = '\"'; + while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i]) + com_cmdline[n++] = com_argv[j][i++]; + com_cmdline[n++] = '\"'; + } + else + { + while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i]) + com_cmdline[n++] = com_argv[j][i++]; + } + if (n < ((int)sizeof(com_cmdline) - 1)) + com_cmdline[n++] = ' '; + else + break; + } + com_cmdline[n] = 0; + Cvar_Set ("cmdline", com_cmdline); } /* @@ -1398,7 +1429,7 @@ void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, con for (pos2++;buffer[pos2] && buffer[pos2] != '\\';pos2++); for (pos2++;buffer[pos2] && buffer[pos2] != '\\';pos2++); } - if (bufferlength <= 1 + strlen(key) + 1 + strlen(value) + strlen(buffer + pos2)) + if (bufferlength <= pos + 1 + strlen(key) + 1 + strlen(value) + strlen(buffer + pos2)) { Con_Printf("InfoString_SetValue: no room for \"%s\" \"%s\" in infostring\n", key, value); return; @@ -1413,7 +1444,7 @@ void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, con else { // just remove the key from the text - strcpy(buffer + pos, buffer + pos2); + strlcpy(buffer + pos, buffer + pos2, bufferlength - pos); } }