]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
-Changed the dpv buffer to 1 MB.
[xonotic/darkplaces.git] / host_cmd.c
index df867c23914faf60540154e74ba8d560c1fce805..21ad53e6ee25648a4d5f916509a867dd269e7c75 100644 (file)
@@ -65,8 +65,8 @@ void Host_Status_f (void)
        for (players = 0, j = 0;j < svs.maxclients;j++)
                if (svs.clients[j].active)
                        players++;
-       print ("host:    %s\n", Cvar_VariableString ("hostname"));
-       print ("version: %s build %s\n", gamename, buildstring);
+       print ("host:     %s\n", Cvar_VariableString ("hostname"));
+       print ("version:  %s build %s\n", gamename, buildstring);
        switch(sv.protocol)
        {
                case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
@@ -75,11 +75,12 @@ void Host_Status_f (void)
                case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
                case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
                case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
+               case PROTOCOL_DARKPLACES6: protocolname = "PROTOCOL_DARKPLACES6";break;
                default: protocolname = "PROTOCOL_UNKNOWN";break;
        }
        print ("protocol: %i (%s)\n", sv.protocol, protocolname);
-       print ("map:     %s\n", sv.name);
-       print ("players: %i active (%i max)\n\n", players, svs.maxclients);
+       print ("map:      %s\n", sv.name);
+       print ("players:  %i active (%i max)\n\n", players, svs.maxclients);
        for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
        {
                if (!client->active)
@@ -275,7 +276,6 @@ void Host_Map_f (void)
        if (cmd_source != src_command)
                return;
 
-       SCR_BeginLoadingPlaque ();
        cls.demonum = -1;               // stop demo loop in case this fails
 
        CL_Disconnect ();
@@ -303,7 +303,7 @@ Goes to a new map, taking all clients along
 void Host_Changelevel_f (void)
 {
        char level[MAX_QPATH];
-       
+
        if (Cmd_Argc() != 2)
        {
                Con_Print("changelevel <levelname> : continue game on a new level\n");
@@ -322,7 +322,6 @@ void Host_Changelevel_f (void)
        key_consoleactive = 0;
 
        SV_SaveSpawnparms ();
-       SCR_BeginLoadingPlaque();
        allowcheats = sv_cheats.integer != 0;
        strcpy(level, Cmd_Argv(1));
        SV_SpawnServer(level);
@@ -340,7 +339,7 @@ Restarts the current server for a dead player
 void Host_Restart_f (void)
 {
        char mapname[MAX_QPATH];
-       
+
        if (Cmd_Argc() != 1)
        {
                Con_Print("restart : restart current level\n");
@@ -358,7 +357,6 @@ void Host_Restart_f (void)
        key_dest = key_game;
        key_consoleactive = 0;
 
-       SCR_BeginLoadingPlaque();
        allowcheats = sv_cheats.integer != 0;
        strcpy(mapname, sv.name);
        SV_SpawnServer(mapname);
@@ -386,7 +384,6 @@ void Host_Reconnect_f (void)
                //Con_Print("reconnect: no signon, ignoring reconnect\n");
                return;
        }
-       SCR_BeginLoadingPlaque();
        cls.signon = 0;         // need new connection messages
 }
 
@@ -503,7 +500,7 @@ void Host_Savegame_f (void)
        FS_DefaultExtension (name, ".sav", sizeof (name));
 
        Con_Printf("Saving game to %s...\n", name);
-       f = FS_Open (name, "w", false);
+       f = FS_Open (name, "wb", false, false);
        if (!f)
        {
                Con_Print("ERROR: couldn't open.\n");
@@ -519,8 +516,7 @@ void Host_Savegame_f (void)
        FS_Printf(f, "%s\n", sv.name);
        FS_Printf(f, "%f\n",sv.time);
 
-// write the light styles
-
+       // write the light styles
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
                if (sv.lightstyles[i])
@@ -529,20 +525,14 @@ void Host_Savegame_f (void)
                        FS_Print(f,"m\n");
        }
 
-
        ED_WriteGlobals (f);
        for (i=0 ; i<sv.num_edicts ; i++)
-       {
                ED_Write (f, EDICT_NUM(i));
-               FS_Flush (f);
-       }
        FS_Close (f);
        Con_Print("done.\n");
 }
 
 
-extern mempool_t *edictstring_mempool;
-
 /*
 ===============
 Host_Loadgame_f
@@ -550,15 +540,14 @@ Host_Loadgame_f
 */
 void Host_Loadgame_f (void)
 {
-       qfile_t *f;
        char filename[MAX_QPATH];
        char mapname[MAX_QPATH];
-       float time, tfloat;
-       char buf[32768];
+       float time;
        const char *start;
-       char *str;
-       int i, r;
+       const char *t;
+       char *text;
        edict_t *ent;
+       int i;
        int entnum;
        int version;
        float spawn_parms[NUM_SPAWN_PARMS];
@@ -579,45 +568,53 @@ void Host_Loadgame_f (void)
 
        cls.demonum = -1;               // stop demo loop in case this fails
 
-       f = FS_Open (filename, "r", false);
-       if (!f)
+       t = text = FS_LoadFile (filename, tempmempool, false);
+       if (!text)
        {
                Con_Print("ERROR: couldn't open.\n");
                return;
        }
 
-       str = FS_Getline (f);
-       sscanf (str, "%i\n", &version);
+       // version
+       COM_ParseToken(&t, false);
+       version = atoi(com_token);
        if (version != SAVEGAME_VERSION)
        {
-               FS_Close (f);
+               Mem_Free(text);
                Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
                return;
        }
 
-       SCR_BeginLoadingPlaque ();
+       // description
+       // this is a little hard to parse, as : is a separator in COM_ParseToken,
+       // so use the console parser instead
+       COM_ParseTokenConsole(&t);
 
-       str = FS_Getline (f);
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
        {
-               str = FS_Getline (f);
-               sscanf (str, "%f\n", &spawn_parms[i]);
+               COM_ParseToken(&t, false);
+               spawn_parms[i] = atof(com_token);
        }
+       // skill
+       COM_ParseToken(&t, false);
 // this silliness is so we can load 1.06 save files, which have float skill values
-       str = FS_Getline (f);
-       sscanf (str, "%f\n", &tfloat);
-       current_skill = (int)(tfloat + 0.1);
+       current_skill = (int)(atof(com_token) + 0.5);
        Cvar_SetValue ("skill", (float)current_skill);
 
-       strcpy (mapname, FS_Getline (f));
+       // mapname
+       COM_ParseToken(&t, false);
+       strcpy (mapname, com_token);
 
-       str = FS_Getline (f);
-       sscanf (str, "%f\n",&time);
+       // time
+       COM_ParseToken(&t, false);
+       time = atof(com_token);
 
        allowcheats = sv_cheats.integer != 0;
+
        SV_SpawnServer (mapname);
        if (!sv.active)
        {
+               Mem_Free(text);
                Con_Print("Couldn't load map\n");
                return;
        }
@@ -628,9 +625,10 @@ void Host_Loadgame_f (void)
 
        for (i = 0;i < MAX_LIGHTSTYLES;i++)
        {
-               str = FS_Getline (f);
-               sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
-               strcpy (sv.lightstyles[i], str);
+               // light style
+               COM_ParseToken(&t, false);
+               sv.lightstyles[i] = PR_Alloc(strlen(com_token)+1);
+               strcpy(sv.lightstyles[i], com_token);
        }
 
 // load the edicts out of the savegame file
@@ -638,31 +636,20 @@ void Host_Loadgame_f (void)
        entnum = -1;
        for (;;)
        {
-               for (i = 0;i < (int)sizeof(buf) - 1;i++)
-               {
-                       r = FS_Getc (f);
-                       if (r == EOF || !r)
+               start = t;
+               while (COM_ParseToken(&t, false))
+                       if (!strcmp(com_token, "}"))
                                break;
-                       buf[i] = r;
-                       if (r == '}')
-                       {
-                               i++;
-                               break;
-                       }
-               }
-               if (r == EOF)
-                       break;
-               if (i == sizeof(buf)-1)
-                       Host_Error ("Loadgame buffer overflow");
-               buf[i] = 0;
-               start = buf;
                if (!COM_ParseToken(&start, false))
                {
                        // end of file
                        break;
                }
                if (strcmp(com_token,"{"))
+               {
+                       Mem_Free(text);
                        Host_Error ("First token isn't a brace");
+               }
 
                if (entnum == -1)
                {
@@ -673,7 +660,10 @@ void Host_Loadgame_f (void)
                {
                        // parse an edict
                        if (entnum >= MAX_EDICTS)
+                       {
+                               Mem_Free(text);
                                Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
+                       }
                        while (entnum >= sv.max_edicts)
                                SV_IncreaseEdicts();
                        ent = EDICT_NUM(entnum);
@@ -692,8 +682,6 @@ void Host_Loadgame_f (void)
        sv.num_edicts = entnum;
        sv.time = time;
 
-       FS_Close (f);
-
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
                svs.clients[0].spawn_parms[i] = spawn_parms[i];
 
@@ -744,7 +732,7 @@ void Host_Name_f (void)
                SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
                return;
        }
-       
+
        host_client->nametime = sv.time + 5;
 
        // point the string back at updateclient->name to keep it safe
@@ -762,6 +750,128 @@ void Host_Name_f (void)
        }
 }
 
+/*
+======================
+Host_Playermodel_f
+======================
+*/
+cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", ""};
+// the old cl_playermodel in cl_main has been renamed to __cl_playermodel
+void Host_Playermodel_f (void)
+{
+       int i, j;
+       char newPath[sizeof(host_client->playermodel)];
+
+       if (Cmd_Argc () == 1)
+       {
+               Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
+               return;
+       }
+
+       if (Cmd_Argc () == 2)
+               strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
+       else
+               strlcpy (newPath, Cmd_Args(), sizeof (newPath));
+
+       for (i = 0, j = 0;newPath[i];i++)
+               if (newPath[i] != '\r' && newPath[i] != '\n')
+                       newPath[j++] = newPath[i];
+       newPath[j] = 0;
+
+       if (cmd_source == src_command)
+       {
+               Cvar_Set ("_cl_playermodel", newPath);
+               if (cls.state == ca_connected)
+                       Cmd_ForwardToServer ();
+               return;
+       }
+
+       /*
+       if (sv.time < host_client->nametime)
+       {
+               SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
+               return;
+       }
+
+       host_client->nametime = sv.time + 5;
+       */
+
+       // point the string back at updateclient->name to keep it safe
+       strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
+       if( eval_playermodel )
+               GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PR_SetString(host_client->playermodel);
+       if (strcmp(host_client->old_model, host_client->playermodel))
+       {
+               if (host_client->spawned)
+                       SV_BroadcastPrintf("%s changed model to %s\n", host_client->old_model, host_client->playermodel);
+               strcpy(host_client->old_model, host_client->playermodel);
+               /*// send notification to all clients
+               MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
+               MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
+               MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
+       }
+}
+
+/*
+======================
+Host_Playerskin_f
+======================
+*/
+cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", ""};
+void Host_Playerskin_f (void)
+{
+       int i, j;
+       char newPath[sizeof(host_client->playerskin)];
+
+       if (Cmd_Argc () == 1)
+       {
+               Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
+               return;
+       }
+
+       if (Cmd_Argc () == 2)
+               strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
+       else
+               strlcpy (newPath, Cmd_Args(), sizeof (newPath));
+
+       for (i = 0, j = 0;newPath[i];i++)
+               if (newPath[i] != '\r' && newPath[i] != '\n')
+                       newPath[j++] = newPath[i];
+       newPath[j] = 0;
+
+       if (cmd_source == src_command)
+       {
+               Cvar_Set ("_cl_playerskin", newPath);
+               if (cls.state == ca_connected)
+                       Cmd_ForwardToServer ();
+               return;
+       }
+
+       /*
+       if (sv.time < host_client->nametime)
+       {
+               SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
+               return;
+       }
+
+       host_client->nametime = sv.time + 5;
+       */
+
+       // point the string back at updateclient->name to keep it safe
+       strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
+       if( eval_playerskin )
+               GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PR_SetString(host_client->playerskin);
+       if (strcmp(host_client->old_skin, host_client->playerskin))
+       {
+               if (host_client->spawned)
+                       SV_BroadcastPrintf("%s changed skin to %s\n", host_client->old_skin, host_client->playerskin);
+               strcpy(host_client->old_skin, host_client->playerskin);
+               /*// send notification to all clients
+               MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
+               MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
+               MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
+       }
+}
 
 void Host_Version_f (void)
 {
@@ -807,9 +917,9 @@ void Host_Say(qboolean teamonly)
                p1++;
        }
        if (!fromServer)
-               snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
+               dpsnprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
        else
-               snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
+               dpsnprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
        p2 = text + strlen(text);
        while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
        {
@@ -827,7 +937,7 @@ void Host_Say(qboolean teamonly)
                        SV_ClientPrint(text);
        host_client = save;
 
-       Sys_Print(&text[1]);
+       //Con_Print(&text[1]);
 }
 
 
@@ -1132,6 +1242,7 @@ void Host_Spawn_f (void)
        client_t *client;
        func_t RestoreGame;
        mfunction_t *f;
+       int stats[MAX_CL_STATS];
 
        if (cmd_source == src_command)
        {
@@ -1186,7 +1297,7 @@ void Host_Spawn_f (void)
                PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
 
                if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
-                       Sys_Printf("%s entered the game\n", host_client->name);
+                       Con_Printf("%s entered the game\n", host_client->name);
 
                PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
        }
@@ -1246,7 +1357,7 @@ void Host_Spawn_f (void)
        MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[1], sv.protocol);
        MSG_WriteAngle (&host_client->message, 0, sv.protocol);
 
-       SV_WriteClientdataToMessage (host_client->edict, &host_client->message);
+       SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->message, stats);
 
        MSG_WriteByte (&host_client->message, svc_signonnum);
        MSG_WriteByte (&host_client->message, 3);
@@ -1659,7 +1770,7 @@ void Host_Startdemos_f (void)
                Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
                c = MAX_DEMOS;
        }
-       Con_DPrintf("%i demo(s) in loop\n", c);
+       Con_Printf("%i demo(s) in loop\n", c);
 
        for (i=1 ; i<c+1 ; i++)
                strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
@@ -1733,7 +1844,7 @@ static void MaxPlayers_f(void)
        if (svs.clients)
                Mem_Free(svs.clients);
        svs.maxclients = n;
-       svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
+       svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
        if (n == 1)
                Cvar_Set ("deathmatch", "0");
        else
@@ -1803,6 +1914,13 @@ void Host_InitCommands (void)
                Cvar_RegisterVariable (&cl_pmodel);
                Cmd_AddCommand ("pmodel", Host_PModel_f);
        }
+
+       // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
+       Cvar_RegisterVariable (&cl_playermodel);
+       Cmd_AddCommand ("playermodel", Host_Playermodel_f);
+       Cvar_RegisterVariable (&cl_playerskin);
+       Cmd_AddCommand ("playerskin", Host_Playerskin_f);
+
        Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
        Cmd_AddCommand ("spawn", Host_Spawn_f);
        Cmd_AddCommand ("begin", Host_Begin_f);