]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
patch from div0 that fixes rate limiting code to make use of sv_maxrate (as it was...
[xonotic/darkplaces.git] / sv_main.c
index 55fb0ef1497a4055af7855f1d5e4b69e68f2c2b2..1516b527188c3803518ebd65cbf04aebf18bf035 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -79,6 +79,13 @@ SV_Init
 */
 void SV_Init (void)
 {
+       // init the csqc progs cvars, since they are updated/used by the server code
+       // TODO: fix this since this is a quick hack to make some of [515]'s broken code run ;) [9/13/2006 Black]
+       extern cvar_t csqc_progname;    //[515]: csqc crc check and right csprogs name according to progs.dat
+       extern cvar_t csqc_progcrc;
+       Cvar_RegisterVariable (&csqc_progname);
+       Cvar_RegisterVariable (&csqc_progcrc);
+
        Cmd_AddCommand("sv_saveentfile", SV_SaveEntFile_f, "save map entities to .ent file (to allow external editing)");
        Cvar_RegisterVariable (&sv_maxvelocity);
        Cvar_RegisterVariable (&sv_gravity);
@@ -292,8 +299,6 @@ CLIENT SPAWNING
 ==============================================================================
 */
 
-static const char *SV_InitCmd; //[515]: svprogs able to send cmd to client on connect
-extern qboolean csqc_loaded;
 /*
 ================
 SV_SendServerinfo
@@ -341,15 +346,22 @@ void SV_SendServerinfo (client_t *client)
        dpsnprintf (message, sizeof (message), "\nServer: %s build %s (progs %i crc)", gamename, buildstring, prog->filecrc);
        MSG_WriteString (&client->netconnection->message,message);
 
-       // FIXME: LordHavoc: this does not work on dedicated servers, needs fixing.
-//[515]: init csprogs according to version of svprogs, check the crc, etc.
-       if(csqc_loaded && (cls.state == ca_dedicated || PRVM_NUM_FOR_EDICT(client->edict) != 1))
+       //[515]: init csprogs according to version of svprogs, check the crc, etc.
+       if (sv.csqc_progcrc >= 0)
        {
+               prvm_eval_t *val;
+               Con_DPrintf("sending csqc info to client (\"%s\" with crc %i)\n", sv.csqc_progname, sv.csqc_progcrc);
+               //[515]: init stufftext string (it is sent before svc_serverinfo)
+               val = PRVM_GETGLOBALFIELDVALUE(PRVM_ED_FindGlobalOffset("SV_InitCmd"));
                MSG_WriteByte (&client->netconnection->message, svc_stufftext);
-               if(SV_InitCmd)
-                       MSG_WriteString (&client->netconnection->message, va("csqc_progcrc %i;%s\n", csqc_progcrc.integer, SV_InitCmd));
-               else
-                       MSG_WriteString (&client->netconnection->message, va("csqc_progcrc %i\n", csqc_progcrc.integer));
+               MSG_WriteString (&client->netconnection->message, va("csqc_progname %s\n", sv.csqc_progname));
+               MSG_WriteByte (&client->netconnection->message, svc_stufftext);
+               MSG_WriteString (&client->netconnection->message, va("csqc_progcrc %i\n", sv.csqc_progcrc));
+               if (val)
+               {
+                       MSG_WriteByte (&client->netconnection->message, svc_stufftext);
+                       MSG_WriteString (&client->netconnection->message, va("%s\n", PRVM_GetString(val->string)));
+               }
        }
 
        MSG_WriteByte (&client->netconnection->message, svc_serverinfo);
@@ -383,6 +395,14 @@ void SV_SendServerinfo (client_t *client)
        MSG_WriteByte (&client->netconnection->message, svc_signonnum);
        MSG_WriteByte (&client->netconnection->message, 1);
 
+       {
+               client_t *save;
+               save = host_client;
+               host_client = client;
+               Curl_SendRequirements();
+               host_client = save;
+       }
+
        client->spawned = false;                // need prespawn, spawn, etc
 }
 
@@ -1221,7 +1241,7 @@ void SV_SendClientDatagram (client_t *client)
                // this rate limiting does not understand sys_ticrate 0
                // (but no one should be running that on a server!)
                rate = bound(NET_MINRATE, client->rate, maxrate);
-               rate = (int)(client->rate * sys_ticrate.value);
+               rate = (int)(rate * sys_ticrate.value);
                maxsize = bound(100, rate, 1400);
                maxsize2 = 1400;
        }
@@ -2174,6 +2194,8 @@ int eval_SendEntity;
 int eval_Version;
 int eval_customizeentityforclient;
 int eval_dphitcontentsmask;
+// DRESK - Support for Entity Contents Transition Event
+int eval_contentstransition;
 
 int gval_trace_dpstartcontents;
 int gval_trace_dphitcontents;
@@ -2185,8 +2207,6 @@ mfunction_t *EndFrameQC;
 //KrimZon - SERVER COMMANDS IN QUAKEC
 mfunction_t *SV_ParseClientCommandQC;
 
-ddef_t *PRVM_ED_FindGlobal(const char *name);
-
 void SV_VM_FindEdictFieldOffsets(void)
 {
        eval_gravity = PRVM_ED_FindFieldOffset("gravity");
@@ -2252,6 +2272,8 @@ void SV_VM_FindEdictFieldOffsets(void)
        eval_Version = PRVM_ED_FindFieldOffset("Version");
        eval_customizeentityforclient = PRVM_ED_FindFieldOffset("customizeentityforclient");
        eval_dphitcontentsmask = PRVM_ED_FindFieldOffset("dphitcontentsmask");
+       // DRESK - Support for Entity Contents Transition Event
+       eval_contentstransition = PRVM_ED_FindFieldOffset("contentstransition");
 
        // LordHavoc: allowing QuakeC to override the player movement code
        SV_PlayerPhysicsQC = PRVM_ED_FindFunction ("SV_PlayerPhysics");
@@ -2259,13 +2281,6 @@ void SV_VM_FindEdictFieldOffsets(void)
        EndFrameQC = PRVM_ED_FindFunction ("EndFrame");
        //KrimZon - SERVER COMMANDS IN QUAKEC
        SV_ParseClientCommandQC = PRVM_ED_FindFunction ("SV_ParseClientCommand");
-
-       //[515]: init stufftext string (it is sent before svc_serverinfo)
-       if(PRVM_ED_FindGlobal("SV_InitCmd") && PRVM_ED_FindGlobal("SV_InitCmd")->type & ev_string)
-               SV_InitCmd = PRVM_G_STRING(PRVM_ED_FindGlobal("SV_InitCmd")->ofs);
-       else
-               SV_InitCmd = NULL;
-
        gval_trace_dpstartcontents = PRVM_ED_FindGlobalOffset("trace_dpstartcontents");
        gval_trace_dphitcontents = PRVM_ED_FindGlobalOffset("trace_dphitcontents");
        gval_trace_dphitq3surfaceflags = PRVM_ED_FindGlobalOffset("trace_dphitq3surfaceflags");
@@ -2338,14 +2353,21 @@ prvm_required_field_t reqfields[] =
        {ev_string, "playerskin"},
        {ev_function, "SendEntity"},
        {ev_function, "customizeentityforclient"},
+       // DRESK - Support for Entity Contents Transition Event
+       {ev_function, "contentstransition"},
 };
 
 void SV_VM_Setup(void)
 {
+       extern cvar_t csqc_progname;    //[515]: csqc crc check and right csprogs name according to progs.dat
+       extern cvar_t csqc_progcrc;
+       unsigned char *csprogsdata;
+       fs_offset_t csprogsdatasize;
        PRVM_Begin;
        PRVM_InitProg( PRVM_SERVERPROG );
 
        // allocate the mempools
+       // TODO: move the magic numbers/constants into #defines [9/13/2006 Black]
        prog->progs_mempool = Mem_AllocPool("Server Progs", 0, NULL);
        prog->builtins = vm_sv_builtins;
        prog->numbuiltins = vm_sv_numbuiltins;
@@ -2376,6 +2398,18 @@ void SV_VM_Setup(void)
        EntityFrameCSQC_ClearVersions();//[515]: csqc
 
        PRVM_End;
+
+       // see if there is a csprogs.dat installed, and if so, set the csqc_progcrc accordingly, this will be sent to connecting clients to tell them to only load a matching csprogs.dat file
+       sv.csqc_progcrc = -1;
+       sv.csqc_progname[0] = 0;
+       csprogsdata = FS_LoadFile(csqc_progname.string, tempmempool, true, &csprogsdatasize);
+       if (csprogsdata)
+       {
+               strlcpy(sv.csqc_progname, csqc_progname.string, sizeof(sv.csqc_progname));
+               sv.csqc_progcrc = CRC_Block(csprogsdata, csprogsdatasize);
+               Mem_Free(csprogsdata);
+               Con_DPrintf("server detected csqc progs file \"%s\" with crc %i\n", sv.csqc_progname, sv.csqc_progcrc);
+       }
 }
 
 void SV_VM_Begin(void)