]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - svvm_cmds.c
implemented an lhnetaddresstype_t enum instead of using #define's
[xonotic/darkplaces.git] / svvm_cmds.c
index 6f800eb3e8e4c8f8d4e1e8188f5706f33055eeee..d7fe26dc1905f8ee6cebbd83254b37a2c347b010 100644 (file)
@@ -1,6 +1,7 @@
 #include "quakedef.h"
 
 #include "prvm_cmds.h"
+#include "jpeg.h"
 
 //============================================================================
 // Server
@@ -62,6 +63,7 @@ char *vm_sv_extensions =
 "DP_QC_CVAR_STRING "
 "DP_QC_CVAR_TYPE "
 "DP_QC_EDICT_NUM "
+"DP_QC_ENTITYDATA "
 "DP_QC_ETOS "
 "DP_QC_FINDCHAIN "
 "DP_QC_FINDCHAINFLAGS "
@@ -92,6 +94,7 @@ char *vm_sv_extensions =
 "DP_QC_URI_ESCAPE "
 "DP_QC_VECTOANGLES_WITH_ROLL "
 "DP_QC_VECTORVECTORS "
+"DP_QC_WHICHPACK "
 "DP_QUAKE2_MODEL "
 "DP_QUAKE2_SPRITE "
 "DP_QUAKE3_MAP "
@@ -124,10 +127,13 @@ char *vm_sv_extensions =
 "DP_SV_PRECACHEANYTIME "
 "DP_SV_PRINT "
 "DP_SV_PUNCHVECTOR "
+"DP_SV_QCSTATUS "
 "DP_SV_ROTATINGBMODEL "
 "DP_SV_SETCOLOR "
 "DP_SV_SHUTDOWN "
 "DP_SV_SLOWMO "
+"DP_SV_SPAWNFUNC_PREFIX "
+"DP_SV_WRITEPICTURE "
 "DP_SV_WRITEUNTERMINATEDSTRING "
 "DP_TE_BLOOD "
 "DP_TE_BLOODSHOWER "
@@ -252,7 +258,7 @@ static vec3_t quakemins = {-16, -16, -16}, quakemaxs = {16, 16, 16};
 static void VM_SV_setmodel (void)
 {
        prvm_edict_t    *e;
-       model_t *mod;
+       dp_model_t      *mod;
        int             i;
 
        VM_SAFEPARMCOUNT(2, VM_setmodel);
@@ -1293,6 +1299,39 @@ static void VM_SV_WriteEntity (void)
        MSG_WriteShort (WriteDest(), PRVM_G_EDICTNUM(OFS_PARM1));
 }
 
+// writes a picture as at most size bytes of data
+// message:
+//   IMGNAME \0 SIZE(short) IMGDATA
+// if failed to read/compress:
+//   IMGNAME \0 \0 \0
+//#501 void(float dest, string name, float maxsize) WritePicture (DP_SV_WRITEPICTURE))
+static void VM_SV_WritePicture (void)
+{
+       const char *imgname;
+       void *buf;
+       size_t size;
+
+       VM_SAFEPARMCOUNT(3, VM_SV_WritePicture);
+
+       imgname = PRVM_G_STRING(OFS_PARM1);
+       size = PRVM_G_FLOAT(OFS_PARM2);
+       if(size > 65535)
+               size = 65535;
+
+       MSG_WriteString(WriteDest(), imgname);
+       if(Image_Compress(imgname, size, &buf, &size))
+       {
+               // actual picture
+               MSG_WriteShort(WriteDest(), size);
+               SZ_Write(WriteDest(), buf, size);
+       }
+       else
+       {
+               // placeholder
+               MSG_WriteShort(WriteDest(), 0);
+       }
+}
+
 //////////////////////////////////////////////////////////
 
 static void VM_SV_makestatic (void)
@@ -2104,7 +2143,7 @@ static void VM_SV_te_flamejet (void)
        SV_FlushBroadcastMessages();
 }
 
-void clippointtosurface(model_t *model, msurface_t *surface, vec3_t p, vec3_t out)
+void clippointtosurface(dp_model_t *model, msurface_t *surface, vec3_t p, vec3_t out)
 {
        int i, j, k;
        float *v[3], facenormal[3], edgenormal[3], sidenormal[3], temp[3], offsetdist, dist, bestdist;
@@ -2140,7 +2179,7 @@ void clippointtosurface(model_t *model, msurface_t *surface, vec3_t p, vec3_t ou
        }
 }
 
-static model_t *getmodel(prvm_edict_t *ed)
+static dp_model_t *getmodel(prvm_edict_t *ed)
 {
        int modelindex;
        if (!ed || ed->priv.server->free)
@@ -2151,7 +2190,7 @@ static model_t *getmodel(prvm_edict_t *ed)
        return sv.models[modelindex];
 }
 
-static msurface_t *getsurface(model_t *model, int surfacenum)
+static msurface_t *getsurface(dp_model_t *model, int surfacenum)
 {
        if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
                return NULL;
@@ -2162,7 +2201,7 @@ static msurface_t *getsurface(model_t *model, int surfacenum)
 //PF_getsurfacenumpoints, // #434 float(entity e, float s) getsurfacenumpoints = #434;
 static void VM_SV_getsurfacenumpoints(void)
 {
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        VM_SAFEPARMCOUNT(2, VM_SV_getsurfacenumpoints);
        // return 0 if no such surface
@@ -2179,7 +2218,7 @@ static void VM_SV_getsurfacenumpoints(void)
 static void VM_SV_getsurfacepoint(void)
 {
        prvm_edict_t *ed;
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        int pointnum;
        VM_SAFEPARMCOUNT(3, VM_SV_getsurfacepoint);
@@ -2205,7 +2244,7 @@ static void VM_SV_getsurfacepoint(void)
 static void VM_SV_getsurfacepointattribute(void)
 {
        prvm_edict_t *ed;
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        int pointnum;
        int attributetype;
@@ -2270,7 +2309,7 @@ static void VM_SV_getsurfacepointattribute(void)
 //PF_getsurfacenormal,    // #436 vector(entity e, float s) getsurfacenormal = #436;
 static void VM_SV_getsurfacenormal(void)
 {
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        vec3_t normal;
        VM_SAFEPARMCOUNT(2, VM_SV_getsurfacenormal);
@@ -2288,7 +2327,7 @@ static void VM_SV_getsurfacenormal(void)
 //PF_getsurfacetexture,   // #437 string(entity e, float s) getsurfacetexture = #437;
 static void VM_SV_getsurfacetexture(void)
 {
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        VM_SAFEPARMCOUNT(2, VM_SV_getsurfacetexture);
        PRVM_G_INT(OFS_RETURN) = OFS_NULL;
@@ -2303,7 +2342,7 @@ static void VM_SV_getsurfacenearpoint(void)
        vec3_t clipped, p;
        vec_t dist, bestdist;
        prvm_edict_t *ed;
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        vec_t *point;
        VM_SAFEPARMCOUNT(2, VM_SV_getsurfacenearpoint);
@@ -2349,7 +2388,7 @@ static void VM_SV_getsurfacenearpoint(void)
 static void VM_SV_getsurfaceclippedpoint(void)
 {
        prvm_edict_t *ed;
-       model_t *model;
+       dp_model_t *model;
        msurface_t *surface;
        vec3_t p, out;
        VM_SAFEPARMCOUNT(3, VM_SV_te_getsurfaceclippedpoint);
@@ -2394,7 +2433,7 @@ static void VM_SV_setattachment (void)
        const char *tagname = PRVM_G_STRING(OFS_PARM2);
        prvm_eval_t *v;
        int modelindex;
-       model_t *model;
+       dp_model_t *model;
        VM_SAFEPARMCOUNT(3, VM_SV_setattachment);
 
        if (e == prog->edicts)
@@ -2438,7 +2477,7 @@ static void VM_SV_setattachment (void)
 int SV_GetTagIndex (prvm_edict_t *e, const char *tagname)
 {
        int i;
-       model_t *model;
+       dp_model_t *model;
 
        i = (int)e->fields.server->modelindex;
        if (i < 1 || i >= MAX_MODELS)
@@ -2463,7 +2502,7 @@ int SV_GetEntityLocalTagMatrix(prvm_edict_t *ent, int tagindex, matrix4x4_t *out
 {
        int modelindex;
        int frame;
-       model_t *model;
+       dp_model_t *model;
        if (tagindex >= 0
         && (modelindex = (int)ent->fields.server->modelindex) >= 1 && modelindex < MAX_MODELS
         && (model = sv.models[(int)ent->fields.server->modelindex])
@@ -2495,7 +2534,7 @@ int SV_GetTagMatrix (matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
        prvm_eval_t *val;
        int modelindex, attachloop;
        matrix4x4_t entitymatrix, tagmatrix, attachmatrix;
-       model_t *model;
+       dp_model_t *model;
 
        *out = identitymatrix; // warnings and errors return identical matrix
 
@@ -2727,7 +2766,7 @@ void VM_SV_serverkey(void)
 static void VM_SV_setmodelindex (void)
 {
        prvm_edict_t    *e;
-       model_t *mod;
+       dp_model_t      *mod;
        int             i;
        VM_SAFEPARMCOUNT(2, VM_SV_setmodelindex);
 
@@ -2809,6 +2848,9 @@ static void VM_SV_trailparticles (void)
 {
        VM_SAFEPARMCOUNT(4, VM_SV_trailparticles);
 
+       if ((int)PRVM_G_FLOAT(OFS_PARM0) < 0)
+               return;
+
        MSG_WriteByte(&sv.datagram, svc_trailparticles);
        MSG_WriteShort(&sv.datagram, PRVM_G_EDICTNUM(OFS_PARM0));
        MSG_WriteShort(&sv.datagram, (int)PRVM_G_FLOAT(OFS_PARM1));
@@ -2823,6 +2865,10 @@ static void VM_SV_pointparticles (void)
        int effectnum, count;
        vec3_t org, vel;
        VM_SAFEPARMCOUNTRANGE(4, 8, VM_SV_pointparticles);
+
+       if ((int)PRVM_G_FLOAT(OFS_PARM0) < 0)
+               return;
+
        effectnum = (int)PRVM_G_FLOAT(OFS_PARM0);
        VectorCopy(PRVM_G_VECTOR(OFS_PARM1), org);
        VectorCopy(PRVM_G_VECTOR(OFS_PARM2), vel);
@@ -3348,14 +3394,14 @@ NULL,                                                   // #492
 NULL,                                                  // #493
 VM_crc16,                                              // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
 VM_cvar_type,                                  // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
-NULL,                                                  // #496
-NULL,                                                  // #497
-NULL,                                                  // #498
-NULL,                                                  // #499
-NULL,                                                  // #500
-NULL,                                                  // #501
+VM_numentityfields,                            // #496 float() numentityfields = #496; (DP_QC_ENTITYDATA)
+VM_entityfieldname,                            // #497 string(float fieldnum) entityfieldname = #497; (DP_QC_ENTITYDATA)
+VM_entityfieldtype,                            // #498 float(float fieldnum) entityfieldtype = #498; (DP_QC_ENTITYDATA)
+VM_getentityfieldstring,               // #499 string(float fieldnum, entity ent) getentityfieldstring = #499; (DP_QC_ENTITYDATA)
+VM_putentityfieldstring,               // #500 float(float fieldnum, entity ent, string s) putentityfieldstring = #500; (DP_QC_ENTITYDATA)
+VM_SV_WritePicture,                            // #501
 NULL,                                                  // #502
-NULL,                                                  // #503
+VM_whichpack,                                  // #503 string(string) whichpack = #503;
 NULL,                                                  // #504
 NULL,                                                  // #505
 NULL,                                                  // #506