]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
Reject clc_stringcmd with \r and \n in them; when developer is set, hex dump these...
[xonotic/darkplaces.git] / prvm_cmds.c
index e990d4bf295e2a166befd8a6203588296ef846a6..936b4d83bf8df3fd89006e844b50eebf7bb3ad43 100644 (file)
@@ -724,10 +724,6 @@ void VM_remove (void)
        }
        else
                PRVM_ED_Free (ed);
-//     if (ed == prog->edicts)
-//             PRVM_ERROR ("remove: tried to remove world");
-//     if (PRVM_NUM_FOR_EDICT(ed) <= sv.maxclients)
-//             Host_Error("remove: tried to remove a client");
 }
 
 /*
@@ -1754,53 +1750,12 @@ void VM_strdecolorize(void)
 {
        char szNewString[VM_STRINGTEMP_LENGTH];
        const char *szString;
-       size_t nCnt;
-       int nPos;
-       int nFillPos;
-       int bFinished;
-               nPos = 0;
-               nFillPos = 0;
-               nCnt = 0;
-               bFinished = 0;
 
        // Prepare Strings
        VM_SAFEPARMCOUNT(1,VM_strdecolorize);
        szString = PRVM_G_STRING(OFS_PARM0);
 
-       while(!bFinished)
-       { // Traverse through String
-               if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
-               { // String End Found
-                       szNewString[nFillPos++] = szString[nPos];
-                       bFinished = 1;
-               }
-               else
-               if( szString[nPos] == STRING_COLOR_TAG)
-               { // Color Code Located
-                       if( szString[nPos + 1] == STRING_COLOR_TAG)
-                       { // Valid Characters to Include
-                               szNewString[nFillPos++] = szString[nPos];
-                               nPos = nPos + 1;
-                               szNewString[nFillPos++] = szString[nPos];
-                       }
-                       else
-                       if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
-                       { // Color Code Found; Increment Position
-                               nPos = nPos + 1;
-                       }
-                       else
-                       { // Unknown Color Code; Include
-                               szNewString[nFillPos++] = szString[nPos];
-                               nPos = nPos + 1;
-                       }
-               }
-               else
-                       // Include Character
-                       szNewString[nFillPos++] = szString[nPos];
-
-                       // Increment Position
-                       nPos = nPos + 1;
-       }
+       COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), TRUE);
 
        PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(szNewString);
 }
@@ -1818,56 +1773,62 @@ float   strlennocol(string s)
 void VM_strlennocol(void)
 {
        const char *szString;
-       size_t nCnt;
-       int nPos;
-       int bFinished;
-               nPos = 0;
-               nCnt = 0;
-               bFinished = 0;
+       int nCnt;
 
        VM_SAFEPARMCOUNT(1,VM_strlennocol);
 
        szString = PRVM_G_STRING(OFS_PARM0);
 
-       while(!bFinished)
-       { // Count Characters
-               // SV_BroadcastPrintf("Position '%d'; Character '%c'; Length '%d'\n", nPos, szString[nPos], nCnt);
-
-               if( szString[nPos] == '\n' || szString[nPos] == '\r' || szString[nPos] <= 0)
-               { // String End Found
-                       // SV_BroadcastPrintf("Found End of String at '%d'\n", nPos);
-                       bFinished = 1;
-               }
-               else
-               if( szString[nPos] == STRING_COLOR_TAG)
-               { // Color Code Located
-                       if( szString[nPos + 1] == STRING_COLOR_TAG)
-                       { // Increment Length; Skip Color Code
-                               nCnt = nCnt + 1;
-                               nPos = nPos + 1;
-                       }
-                       else
-                       if( szString[nPos + 1] >= '0' && szString[nPos + 1] <= '9' )
-                       { // Color Code Found; Increment Position
-                               // SV_BroadcastPrintf("Found Color Codes at '%d'\n", nPos);
-                               nPos = nPos + 1;
-                       }
-                       else
-                       { // Unknown Color Code; Increment Length!
-                               nPos = nPos + 1;
-                               nCnt = nCnt + 1;
-                       }
-               }
-               else
-                       // Increment String Length
-                       nCnt = nCnt + 1;
+       nCnt = COM_StringLengthNoColors(szString, 0, NULL);
 
-               // Increment Position
-               nPos = nPos + 1;
-       }
        PRVM_G_FLOAT(OFS_RETURN) = nCnt;
 }
 
+// DRESK - String to Uppercase and Lowercase
+/*
+=========
+VM_strtolower
+
+string strtolower(string s)
+=========
+*/
+// string (string s) strtolower = #480; // returns passed in string in lowercase form
+void VM_strtolower(void)
+{
+       char szNewString[VM_STRINGTEMP_LENGTH];
+       const char *szString;
+
+       // Prepare Strings
+       VM_SAFEPARMCOUNT(1,VM_strtolower);
+       szString = PRVM_G_STRING(OFS_PARM0);
+
+       COM_ToLowerString(szString, szNewString, sizeof(szNewString) );
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(szNewString);
+}
+
+/*
+=========
+VM_strtoupper
+
+string strtoupper(string s)
+=========
+*/
+// string (string s) strtoupper = #481; // returns passed in string in uppercase form
+void VM_strtoupper(void)
+{
+       char szNewString[VM_STRINGTEMP_LENGTH];
+       const char *szString;
+
+       // Prepare Strings
+       VM_SAFEPARMCOUNT(1,VM_strtoupper);
+       szString = PRVM_G_STRING(OFS_PARM0);
+
+       COM_ToUpperString(szString, szNewString, sizeof(szNewString) );
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(szNewString);
+}
+
 /*
 =========
 VM_strcat
@@ -2019,7 +1980,7 @@ void VM_tokenize (void)
        p = PRVM_G_STRING(OFS_PARM0);
 
        num_tokens = 0;
-       while(COM_ParseToken(&p, false))
+       while(COM_ParseToken_VM_Tokenize(&p, false))
        {
                if (num_tokens >= (int)(sizeof(tokens)/sizeof(tokens[0])))
                        break;
@@ -2050,6 +2011,7 @@ void VM_tokenizebyseparator (void)
        int separatorlen[7];
        const char *separators[7];
        const char *p;
+       const char *token;
        char tokentext[MAX_INPUTLINE];
 
        VM_SAFEPARMCOUNTRANGE(2, 8,VM_tokenizebyseparator);
@@ -2060,16 +2022,20 @@ void VM_tokenizebyseparator (void)
        for (j = 1;j < prog->argc;j++)
        {
                // skip any blank separator strings
-               if (!PRVM_G_STRING(OFS_PARM0 + j)[0])
+               const char *s = PRVM_G_STRING(OFS_PARM0+j*3);
+               if (!s[0])
                        continue;
-               separators[numseparators] = PRVM_G_STRING(OFS_PARM0 + j);
-               separatorlen[numseparators] = strlen(separators[numseparators]);
+               separators[numseparators] = s;
+               separatorlen[numseparators] = strlen(s);
                numseparators++;
        }
 
        num_tokens = 0;
-       for (num_tokens = 0;num_tokens < (int)(sizeof(tokens)/sizeof(tokens[0]));num_tokens++)
+       j = 0;
+
+       while (num_tokens < (int)(sizeof(tokens)/sizeof(tokens[0])))
        {
+               token = tokentext + j;
                while (*p)
                {
                        for (k = 0;k < numseparators;k++)
@@ -2082,12 +2048,14 @@ void VM_tokenizebyseparator (void)
                        }
                        if (k < numseparators)
                                break;
-                       if (j < (int)sizeof(tokentext[MAX_INPUTLINE]-1))
+                       if (j < (int)sizeof(tokentext)-1)
                                tokentext[j++] = *p;
                        p++;
                }
-               tokentext[j] = 0;
-               tokens[num_tokens] = PRVM_SetTempString(tokentext);
+               if (j >= (int)sizeof(tokentext))
+                       break;
+               tokentext[j++] = 0;
+               tokens[num_tokens++] = PRVM_SetTempString(token);
                if (!*p)
                        break;
        }
@@ -2238,15 +2206,15 @@ void VM_parseentitydata(void)
 
        VM_SAFEPARMCOUNT(2, VM_parseentitydata);
 
-    // get edict and test it
+       // get edict and test it
        ent = PRVM_G_EDICT(OFS_PARM0);
        if (ent->priv.required->free)
                PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent));
 
        data = PRVM_G_STRING(OFS_PARM1);
 
-    // parse the opening brace
-       if (!COM_ParseTokenConsole(&data) || com_token[0] != '{' )
+       // parse the opening brace
+       if (!COM_ParseToken_Simple(&data, false) || com_token[0] != '{' )
                PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s", PRVM_NAME, data );
 
        PRVM_ED_ParseEdict (data, ent);
@@ -2693,7 +2661,7 @@ void VM_drawfill(void)
        if(pos[2] || size[2])
                Con_Printf("VM_drawfill: z value%s from %s discarded\n",(pos[2] && size[2]) ? "s" : " ",((pos[2] && size[2]) ? "pos and size" : (pos[2] ? "pos" : "size")));
 
-       DrawQ_Pic(pos[0], pos[1], NULL, size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM3), flag);
+       DrawQ_Fill(pos[0], pos[1], size[0], size[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM3), flag);
        PRVM_G_FLOAT(OFS_RETURN) = 1;
 }