]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
server list: allow more AND and OR masks (except in DP_SMALLMEMORY profile)
[xonotic/darkplaces.git] / prvm_cmds.c
index 5acc3eb2fb2d0631296de2de4fb182e70bab17ad..359fc3866a1cd873c2748d1f562eaa0e142906a3 100644 (file)
@@ -13,6 +13,7 @@
 #include "cl_collision.h"
 #include "clvm_cmds.h"
 #include "ft2.h"
+#include "mdfour.h"
 
 extern cvar_t prvm_backtraceforwarnings;
 
@@ -280,6 +281,13 @@ static qboolean checkextension(const char *name)
                                return false;
 #endif
                        }
+
+                       // special sheck for d0_blind_id
+                       if (!strcasecmp("DP_CRYPTO", name))
+                               return Crypto_Available();
+                       if (!strcasecmp("DP_QC_DIGEST_SHA256", name))
+                               return Crypto_Available();
+
                        return true;
                }
        }
@@ -2923,7 +2931,8 @@ void VM_getsoundtime (void)
        }
        entnum = ((pnum == PRVM_CLIENTPROG) ? MAX_EDICTS : 0) + PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(OFS_PARM0));
        entchannel = (int)PRVM_G_FLOAT(OFS_PARM1);
-       if (entchannel <= 0 || entchannel > 8)
+       entchannel = CHAN_USER2ENGINE(entchannel);
+       if (!IS_CHAN(entchannel))
                VM_Warning("VM_getsoundtime: %s: bad channel %i\n", PRVM_NAME, entchannel);
        PRVM_G_FLOAT(OFS_RETURN) = (float)S_GetEntChannelPosition(entnum, entchannel);
 }
@@ -3354,22 +3363,23 @@ void VM_drawcharacter(void)
 =========
 VM_drawstring
 
-float  drawstring(vector position, string text, vector scale, vector rgb, float alpha, float flag)
+float  drawstring(vector position, string text, vector scale, vector rgb, float alpha[, float flag])
 =========
 */
 void VM_drawstring(void)
 {
        float *pos,*scale,*rgb;
        const char  *string;
-       int flag;
+       int flag = 0;
        float sx, sy;
-       VM_SAFEPARMCOUNT(6,VM_drawstring);
+       VM_SAFEPARMCOUNTRANGE(5,6,VM_drawstring);
 
        string = PRVM_G_STRING(OFS_PARM1);
        pos = PRVM_G_VECTOR(OFS_PARM0);
        scale = PRVM_G_VECTOR(OFS_PARM2);
        rgb = PRVM_G_VECTOR(OFS_PARM3);
-       flag = (int)PRVM_G_FLOAT(OFS_PARM5);
+       if (prog->argc >= 6)
+               flag = (int)PRVM_G_FLOAT(OFS_PARM5);
 
        if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
        {
@@ -3697,9 +3707,9 @@ void VM_drawpic(void)
 {
        const char *picname;
        float *size, *pos, *rgb;
-       int flag;
+       int flag = 0;
 
-       VM_SAFEPARMCOUNT(6,VM_drawpic);
+       VM_SAFEPARMCOUNTRANGE(5,6,VM_drawpic);
 
        picname = PRVM_G_STRING(OFS_PARM1);
        VM_CheckEmptyString (picname);
@@ -3715,7 +3725,8 @@ void VM_drawpic(void)
        pos = PRVM_G_VECTOR(OFS_PARM0);
        size = PRVM_G_VECTOR(OFS_PARM2);
        rgb = PRVM_G_VECTOR(OFS_PARM3);
-       flag = (int) PRVM_G_FLOAT(OFS_PARM5);
+       if (prog->argc >= 6)
+               flag = (int) PRVM_G_FLOAT(OFS_PARM5);
 
        if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
        {
@@ -5631,12 +5642,61 @@ void VM_crc16(void)
 {
        float insensitive;
        static char s[VM_STRINGTEMP_LENGTH];
-       VM_SAFEPARMCOUNTRANGE(2, 8, VM_hash);
+       VM_SAFEPARMCOUNTRANGE(2, 8, VM_crc16);
        insensitive = PRVM_G_FLOAT(OFS_PARM0);
        VM_VarString(1, s, sizeof(s));
        PRVM_G_FLOAT(OFS_RETURN) = (unsigned short) ((insensitive ? CRC_Block_CaseInsensitive : CRC_Block) ((unsigned char *) s, strlen(s)));
 }
 
+// #639 float(string digest, string data, ...) digest_hex
+void VM_digest_hex(void)
+{
+       const char *digest;
+
+       static char out[32];
+       static char outhex[65];
+       int outlen;
+
+       static char s[VM_STRINGTEMP_LENGTH];
+       int len;
+
+       VM_SAFEPARMCOUNTRANGE(2, 8, VM_digest_hex);
+       digest = PRVM_G_STRING(OFS_PARM0);
+       if(!digest)
+               digest = "";
+       VM_VarString(1, s, sizeof(s));
+       len = strlen(s);
+
+       outlen = 0;
+
+       if(!strcmp(digest, "MD4"))
+       {
+               outlen = 16;
+               mdfour((unsigned char *) out, (unsigned char *) s, len);
+       }
+       else if(!strcmp(digest, "SHA256") && Crypto_Available())
+       {
+               outlen = 32;
+               sha256((unsigned char *) out, (unsigned char *) s, len);
+       }
+       // no warning needed on mismatch - we return string_null to QC
+
+       if(outlen)
+       {
+               int i;
+               static const char *hexmap = "0123456789abcdef";
+               for(i = 0; i < outlen; ++i)
+               {
+                       outhex[2*i]   = hexmap[(out[i] >> 4) & 15];
+                       outhex[2*i+1] = hexmap[(out[i] >> 0) & 15];
+               }
+               outhex[2*i] = 0;
+               PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(outhex);
+       }
+       else
+               PRVM_G_INT(OFS_RETURN) = 0;
+}
+
 void VM_wasfreed (void)
 {
        VM_SAFEPARMCOUNT(1, VM_wasfreed);
@@ -5821,7 +5881,7 @@ static void uri_to_string_callback(int status, size_t length_received, unsigned
                
        PRVM_SetProg(handle->prognr);
        PRVM_Begin;
-               if((prog->starttime == handle->starttime) && (prog->funcoffsets.URI_Get_Callback))
+               if((prog->starttime == handle->starttime) && (PRVM_allfunction(URI_Get_Callback)))
                {
                        if(length_received >= sizeof(handle->buffer))
                                length_received = sizeof(handle->buffer) - 1;
@@ -5830,7 +5890,7 @@ static void uri_to_string_callback(int status, size_t length_received, unsigned
                        PRVM_G_FLOAT(OFS_PARM0) = handle->id;
                        PRVM_G_FLOAT(OFS_PARM1) = status;
                        PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(handle->buffer);
-                       PRVM_ExecuteProgram(prog->funcoffsets.URI_Get_Callback, "QC function URI_Get_Callback is missing");
+                       PRVM_ExecuteProgram(PRVM_allfunction(URI_Get_Callback), "QC function URI_Get_Callback is missing");
                }
        PRVM_End;
        
@@ -5856,7 +5916,7 @@ void VM_uri_get (void)
        const char *query_string = NULL;
        size_t lq;
 
-       if(!prog->funcoffsets.URI_Get_Callback)
+       if(!PRVM_allfunction(URI_Get_Callback))
                PRVM_ERROR("uri_get called by %s without URI_Get_Callback defined", PRVM_NAME);
 
        VM_SAFEPARMCOUNTRANGE(2, 6, VM_uri_get);
@@ -5881,7 +5941,7 @@ void VM_uri_get (void)
        handle->prognr = PRVM_GetProgNr();
        handle->starttime = prog->starttime;
        handle->id = id;
-       if(postseparator)
+       if(postseparator && posttype && *posttype)
        {
                size_t l = strlen(postseparator);
                if(poststringbuffer >= 0)
@@ -6845,7 +6905,7 @@ void VM_getsurfaceclippedpoint(void)
        animatemodel(model, ed);
        applytransform_inverted(PRVM_G_VECTOR(OFS_PARM2), ed, p);
        clippointtosurface(ed, model, surface, p, out);
-       VectorAdd(out, ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
+       VectorAdd(out, PRVM_serveredictvector(ed, origin), PRVM_G_VECTOR(OFS_RETURN));
 }
 
 //PF_getsurfacenumtriangles, // #??? float(entity e, float s) getsurfacenumtriangles = #???;
@@ -6924,7 +6984,7 @@ void VM_physics_enable(void)
                return;
        }
        // entity should have MOVETYPE_PHYSICS already set, this can damage memory (making leaked allocation) so warn about this even if non-developer
-       if (ed->fields.server->movetype != MOVETYPE_PHYSICS)
+       if (PRVM_serveredictfloat(ed, movetype) != MOVETYPE_PHYSICS)
        {
                VM_Warning("VM_physics_enable: entity is not MOVETYPE_PHYSICS!\n");
                return;
@@ -6948,14 +7008,14 @@ void VM_physics_addforce(void)
                return;
        }
        // entity should have MOVETYPE_PHYSICS already set, this can damage memory (making leaked allocation) so warn about this even if non-developer
-       if (ed->fields.server->movetype != MOVETYPE_PHYSICS)
+       if (PRVM_serveredictfloat(ed, movetype) != MOVETYPE_PHYSICS)
        {
                VM_Warning("VM_physics_addforce: entity is not MOVETYPE_PHYSICS!\n");
                return;
        }
        f.type = ODEFUNC_RELFORCEATPOS;
        VectorCopy(PRVM_G_VECTOR(OFS_PARM1), f.v1);
-       VectorSubtract(ed->fields.server->origin, PRVM_G_VECTOR(OFS_PARM2), f.v2);
+       VectorSubtract(PRVM_serveredictvector(ed, origin), PRVM_G_VECTOR(OFS_PARM2), f.v2);
        VM_physics_ApplyCmd(ed, &f);
 }
 
@@ -6974,7 +7034,7 @@ void VM_physics_addtorque(void)
                return;
        }
        // entity should have MOVETYPE_PHYSICS already set, this can damage memory (making leaked allocation) so warn about this even if non-developer
-       if (ed->fields.server->movetype != MOVETYPE_PHYSICS)
+       if (PRVM_serveredictfloat(ed, movetype) != MOVETYPE_PHYSICS)
        {
                VM_Warning("VM_physics_addtorque: entity is not MOVETYPE_PHYSICS!\n");
                return;