Esempio n. 1
0
        /**
         * Save everything in the world out without deltas. Used for recording
         * footage for merged or assembled demos.
         */
        public static void SV_RecordDemoMessage()
        {
            if (SV_INIT.svs.demofile == null)
            {
                return;
            }

            //memset (nostate, 0, sizeof(nostate));
            entity_state_t nostate = new(null);
            sizebuf_t      buf     = new();

            SZ.Init(buf, SV_ENTS.buf_data, SV_ENTS.buf_data.Length);

            // write a frame message that doesn't contain a player_state_t
            MSG.WriteByte(buf, Defines.svc_frame);
            MSG.WriteLong(buf, SV_INIT.sv.framenum);

            MSG.WriteByte(buf, Defines.svc_packetentities);

            var e   = 1;
            var ent = GameBase.g_edicts[e];

            while (e < GameBase.num_edicts)
            {
                // ignore ents without visible models unless they have an effect
                if (ent.inuse &&
                    ent.s.number != 0 &&
                    (ent.s.modelindex != 0 || ent.s.effects != 0 || ent.s.sound != 0 || ent.s.@event != 0) &&
                    0 == (ent.svflags & Defines.SVF_NOCLIENT))
                {
                    MSG.WriteDeltaEntity(nostate, ent.s, buf, false, true);
                }

                e++;
                ent = GameBase.g_edicts[e];
            }

            MSG.WriteShort(buf, 0);             // end of packetentities

            // now add the accumulated multicast information
            SZ.Write(buf, SV_INIT.svs.demo_multicast.data, SV_INIT.svs.demo_multicast.cursize);
            SZ.Clear(SV_INIT.svs.demo_multicast);

            // now write the entire message to the file, prefixed by the length
            var len = EndianHandler.swapInt(buf.cursize);

            try
            {
                //fwrite (len, 4, 1, svs.demofile);
                SV_INIT.svs.demofile.Write(len);

                //fwrite (buf.data, buf.cursize, 1, svs.demofile);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (Exception)
            {
                Com.Printf("Error writing demo file:" + e);
            }
        }
Esempio n. 2
0
        public static void SV_RecordDemoMessage( )
        {
            if (SV_INIT.svs.demofile == null)
            {
                return;
            }
            entity_state_t nostate = new entity_state_t(null);
            sizebuf_t      buf     = new sizebuf_t();

            SZ.Init(buf, buf_data, buf_data.Length);
            MSG.WriteByte(buf, Defines.svc_frame);
            MSG.WriteLong(buf, SV_INIT.sv.framenum);
            MSG.WriteByte(buf, Defines.svc_packetentities);
            var     e   = 1;
            edict_t ent = GameBase.g_edicts[e];

            while (e < GameBase.num_edicts)
            {
                if (ent.inuse && ent.s.number != 0 && (ent.s.modelindex != 0 || ent.s.effects != 0 || ent.s.sound != 0 || ent.s.event_renamed != 0) && 0 == (ent.svflags & Defines.SVF_NOCLIENT))
                {
                    MSG.WriteDeltaEntity(nostate, ent.s, buf, false, true);
                }
                e++;
                ent = GameBase.g_edicts[e];
            }

            MSG.WriteShort(buf, 0);
            SZ.Write(buf, SV_INIT.svs.demo_multicast.data, SV_INIT.svs.demo_multicast.cursize);
            SZ.Clear(SV_INIT.svs.demo_multicast);
            var len = EndianHandler.SwapInt(buf.cursize);

            try
            {
                SV_INIT.svs.demofile.Write(len);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (Exception e1)
            {
                Com.Printf("Error writing demo file:" + e);
            }
        }
Esempio n. 3
0
        public static void SV_ServerRecord_f( )
        {
            String name;

            Byte[]    buf_data = new Byte[32768];
            sizebuf_t buf      = new sizebuf_t();
            Int32     len;
            Int32     i;

            if (Cmd.Argc() != 2)
            {
                Com.Printf("serverrecord <demoname>\\n");
                return;
            }

            if (SV_INIT.svs.demofile != null)
            {
                Com.Printf("Already recording.\\n");
                return;
            }

            if (SV_INIT.sv.state != Defines.ss_game)
            {
                Com.Printf("You must be in a level to record.\\n");
                return;
            }

            name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2";
            Com.Printf("recording to " + name + ".\\n");
            FS.CreatePath(name);
            try
            {
                SV_INIT.svs.demofile = new QuakeFile(name, FileAccess.ReadWrite);
            }
            catch (Exception e)
            {
                Com.Printf("ERROR: couldn't open.\\n");
                return;
            }

            SZ.Init(SV_INIT.svs.demo_multicast, SV_INIT.svs.demo_multicast_buf, SV_INIT.svs.demo_multicast_buf.Length);
            SZ.Init(buf, buf_data, buf_data.Length);
            MSG.WriteByte(buf, Defines.svc_serverdata);
            MSG.WriteLong(buf, Defines.PROTOCOL_VERSION);
            MSG.WriteLong(buf, SV_INIT.svs.spawncount);
            MSG.WriteByte(buf, 2);
            MSG.WriteString(buf, Cvar.VariableString("gamedir"));
            MSG.WriteShort(buf, -1);
            MSG.WriteString(buf, SV_INIT.sv.configstrings[Defines.CS_NAME]);
            for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++)
            {
                if (SV_INIT.sv.configstrings[i].Length == 0)
                {
                    MSG.WriteByte(buf, Defines.svc_configstring);
                    MSG.WriteShort(buf, i);
                    MSG.WriteString(buf, SV_INIT.sv.configstrings[i]);
                }
            }

            Com.DPrintf("signon message length: " + buf.cursize + "\\n");
            len = EndianHandler.SwapInt(buf.cursize);
            try
            {
                SV_INIT.svs.demofile.Write(len);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (IOException e1)
            {
                e1.PrintStackTrace();
            }
        }
Esempio n. 4
0
        public static void SV_SendClientMessages( )
        {
            Int32    i;
            client_t c;
            Int32    msglen;
            Int32    r;

            msglen = 0;
            if (SV_INIT.sv.state == Defines.ss_demo && SV_INIT.sv.demofile != null)
            {
                if (SV_MAIN.sv_paused.value != 0)
                {
                    msglen = 0;
                }
                else
                {
                    try
                    {
                        msglen = EndianHandler.SwapInt(SV_INIT.sv.demofile.ReadInt32());
                    }
                    catch (Exception e)
                    {
                        SV_DemoCompleted();
                        return;
                    }

                    if (msglen == -1)
                    {
                        SV_DemoCompleted();
                        return;
                    }

                    if (msglen > Defines.MAX_MSGLEN)
                    {
                        Com.Error(Defines.ERR_DROP, "SV_SendClientMessages: msglen > MAX_MSGLEN");
                    }
                    r = 0;
                    try
                    {
                        r = SV_INIT.sv.demofile.Read(msgbuf, 0, msglen);
                    }
                    catch (Exception e1)
                    {
                        Com.Printf("IOError: reading demo file, " + e1);
                    }

                    if (r != msglen)
                    {
                        SV_DemoCompleted();
                        return;
                    }
                }
            }

            for (i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                c = SV_INIT.svs.clients[i];
                if (c.state == 0)
                {
                    continue;
                }
                if (c.netchan.message.overflowed)
                {
                    SZ.Clear(c.netchan.message);
                    SZ.Clear(c.datagram);
                    SV_BroadcastPrintf(Defines.PRINT_HIGH, c.name + " overflowed\\n");
                    SV_MAIN.SV_DropClient(c);
                }

                if (SV_INIT.sv.state == Defines.ss_cinematic || SV_INIT.sv.state == Defines.ss_demo || SV_INIT.sv.state == Defines.ss_pic)
                {
                    Netchan.Transmit(c.netchan, msglen, msgbuf);
                }
                else if (c.state == Defines.cs_spawned)
                {
                    if (SV_RateDrop(c))
                    {
                        continue;
                    }
                    SV_SendClientDatagram(c);
                }
                else
                {
                    if (c.netchan.message.cursize != 0 || Globals.curtime - c.netchan.last_sent > 1000)
                    {
                        Netchan.Transmit(c.netchan, 0, NULLBYTE);
                    }
                }
            }
        }