Exemple #1
0
        public static void SV_WriteFrameToClient(client_t client, sizebuf_t msg)
        {
            client_frame_t frame, oldframe;
            Int32          lastframe;

            frame = client.frames[SV_INIT.sv.framenum & Defines.UPDATE_MASK];
            if (client.lastframe <= 0)
            {
                oldframe  = null;
                lastframe = -1;
            }
            else if (SV_INIT.sv.framenum - client.lastframe >= (Defines.UPDATE_BACKUP - 3))
            {
                oldframe  = null;
                lastframe = -1;
            }
            else
            {
                oldframe  = client.frames[client.lastframe & Defines.UPDATE_MASK];
                lastframe = client.lastframe;
            }

            MSG.WriteByte(msg, Defines.svc_frame);
            MSG.WriteLong(msg, SV_INIT.sv.framenum);
            MSG.WriteLong(msg, lastframe);
            MSG.WriteByte(msg, client.surpressCount);
            client.surpressCount = 0;
            MSG.WriteByte(msg, frame.areabytes);
            SZ.Write(msg, frame.areabits, frame.areabytes);
            SV_WritePlayerstateToClient(oldframe, frame, msg);
            SV_EmitPacketEntities(oldframe, frame, msg);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        /**
         * Writes a frame to a client system.
         */
        public static void SV_WriteFrameToClient(client_t client, sizebuf_t msg)
        {
            //ptr
            client_frame_t frame, oldframe;
            int            lastframe;

            //Com.Printf ("%i . %i\n", new
            // Vargs().add(client.lastframe).add(sv.framenum));
            // this is the frame we are creating
            frame = client.frames[SV_INIT.sv.framenum & Defines.UPDATE_MASK];

            if (client.lastframe <= 0)
            {
                // client is asking for a retransmit
                oldframe  = null;
                lastframe = -1;
            }
            else if (SV_INIT.sv.framenum - client.lastframe >= Defines.UPDATE_BACKUP - 3)
            {
                // client hasn't gotten a good message through in a long time
                // Com_Printf ("%s: Delta request from out-of-date packet.\n",
                // client.name);
                oldframe  = null;
                lastframe = -1;
            }
            else
            {
                // we have a valid message to delta from
                oldframe  = client.frames[client.lastframe & Defines.UPDATE_MASK];
                lastframe = client.lastframe;
            }

            MSG.WriteByte(msg, Defines.svc_frame);
            MSG.WriteLong(msg, SV_INIT.sv.framenum);
            MSG.WriteLong(msg, lastframe);             // what we are delta'ing from
            MSG.WriteByte(msg, client.surpressCount);  // rate dropped packets
            client.surpressCount = 0;

            // send over the areabits
            MSG.WriteByte(msg, frame.areabytes);
            SZ.Write(msg, frame.areabits, frame.areabytes);

            // delta encode the playerstate
            SV_ENTS.SV_WritePlayerstateToClient(oldframe, frame, msg);

            // delta encode the entities
            SV_ENTS.SV_EmitPacketEntities(oldframe, frame, msg);
        }
Exemple #4
0
        public static void SV_New_f( )
        {
            String  gamedir;
            Int32   playernum;
            edict_t ent;

            Com.DPrintf("New() from " + SV_MAIN.sv_client.name + "\\n");
            if (SV_MAIN.sv_client.state != Defines.cs_connected)
            {
                Com.Printf("New not valid -- already spawned\\n");
                return;
            }

            if (SV_INIT.sv.state == Defines.ss_demo)
            {
                SV_BeginDemoserver();
                return;
            }

            gamedir = Cvar.VariableString("gamedir");
            MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_serverdata);
            MSG.WriteInt(SV_MAIN.sv_client.netchan.message, Defines.PROTOCOL_VERSION);
            MSG.WriteLong(SV_MAIN.sv_client.netchan.message, SV_INIT.svs.spawncount);
            MSG.WriteByte(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.attractloop ? 1 : 0);
            MSG.WriteString(SV_MAIN.sv_client.netchan.message, gamedir);
            if (SV_INIT.sv.state == Defines.ss_cinematic || SV_INIT.sv.state == Defines.ss_pic)
            {
                playernum = -1;
            }
            else
            {
                playernum = SV_MAIN.sv_client.serverindex;
            }
            MSG.WriteShort(SV_MAIN.sv_client.netchan.message, playernum);
            MSG.WriteString(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.configstrings[Defines.CS_NAME]);
            if (SV_INIT.sv.state == Defines.ss_game)
            {
                ent                       = GameBase.g_edicts[playernum + 1];
                ent.s.number              = playernum + 1;
                SV_MAIN.sv_client.edict   = ent;
                SV_MAIN.sv_client.lastcmd = new usercmd_t();
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd configstrings " + SV_INIT.svs.spawncount + " 0\\n");
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
0
        public static void SendCmd()
        {
            int       i;
            usercmd_t cmd, oldcmd;
            int       checksumIndex;

            i   = Globals.cls.netchan.outgoing_sequence & (Defines.CMD_BACKUP - 1);
            cmd = Globals.cl.cmds[i];
            Globals.cl.cmd_time[i] = (int)Globals.cls.realtime;
            CreateCmd(cmd);
            Globals.cl.cmd.Set(cmd);
            if (Globals.cls.state == Defines.ca_disconnected || Globals.cls.state == Defines.ca_connecting)
            {
                return;
            }
            if (Globals.cls.state == Defines.ca_connected)
            {
                if (Globals.cls.netchan.message.cursize != 0 || Globals.curtime - Globals.cls.netchan.last_sent > 1000)
                {
                    Netchan.Transmit(Globals.cls.netchan, 0, new byte[0]);
                }
                return;
            }

            if (Globals.userinfo_modified)
            {
                CL.FixUpGender();
                Globals.userinfo_modified = false;
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_userinfo);
                MSG.WriteString(Globals.cls.netchan.message, Cvar.Userinfo());
            }

            SZ.Init(buf, data, data.Length);
            if (cmd.buttons != 0 && Globals.cl.cinematictime > 0 && !Globals.cl.attractloop && Globals.cls.realtime - Globals.cl.cinematictime > 1000)
            {
                SCR.FinishCinematic();
            }

            MSG.WriteByte(buf, Defines.clc_move);
            checksumIndex = buf.cursize;
            MSG.WriteByte(buf, 0);
            if (cl_nodelta.value != 0F || !Globals.cl.frame.valid || Globals.cls.demowaiting)
            {
                MSG.WriteLong(buf, -1);
            }
            else
            {
                MSG.WriteLong(buf, Globals.cl.frame.serverframe);
            }
            i   = (Globals.cls.netchan.outgoing_sequence - 2) & (Defines.CMD_BACKUP - 1);
            cmd = Globals.cl.cmds[i];
            nullcmd.Clear();
            MSG.WriteDeltaUsercmd(buf, nullcmd, cmd);
            oldcmd = cmd;
            i      = (Globals.cls.netchan.outgoing_sequence - 1) & (Defines.CMD_BACKUP - 1);
            cmd    = Globals.cl.cmds[i];
            MSG.WriteDeltaUsercmd(buf, oldcmd, cmd);
            oldcmd = cmd;
            i      = (Globals.cls.netchan.outgoing_sequence) & (Defines.CMD_BACKUP - 1);
            cmd    = Globals.cl.cmds[i];
            MSG.WriteDeltaUsercmd(buf, oldcmd, cmd);
            buf.data[checksumIndex] = Com.BlockSequenceCRCByte(buf.data, checksumIndex + 1, buf.cursize - checksumIndex - 1, Globals.cls.netchan.outgoing_sequence);
            Netchan.Transmit(Globals.cls.netchan, buf.cursize, buf.data);
        }
Exemple #8
0
 public static void PF_WriteLong(int c)
 {
     MSG.WriteLong(SV_INIT.sv.multicast, c);
 }
Exemple #9
0
        static void SV_WritePlayerstateToClient(client_frame_t from, client_frame_t to, sizebuf_t msg)
        {
            player_state_t ps, ops;
            player_state_t dummy;

            ps = to.ps;
            if (from == null)
            {
                dummy = new player_state_t();
                ops   = dummy;
            }
            else
            {
                ops = from.ps;
            }

            var pflags = 0;

            if (ps.pmove.pm_type != ops.pmove.pm_type)
            {
                pflags |= Defines.PS_M_TYPE;
            }
            if (ps.pmove.origin[0] != ops.pmove.origin[0] || ps.pmove.origin[1] != ops.pmove.origin[1] || ps.pmove.origin[2] != ops.pmove.origin[2])
            {
                pflags |= Defines.PS_M_ORIGIN;
            }
            if (ps.pmove.velocity[0] != ops.pmove.velocity[0] || ps.pmove.velocity[1] != ops.pmove.velocity[1] || ps.pmove.velocity[2] != ops.pmove.velocity[2])
            {
                pflags |= Defines.PS_M_VELOCITY;
            }
            if (ps.pmove.pm_time != ops.pmove.pm_time)
            {
                pflags |= Defines.PS_M_TIME;
            }
            if (ps.pmove.pm_flags != ops.pmove.pm_flags)
            {
                pflags |= Defines.PS_M_FLAGS;
            }
            if (ps.pmove.gravity != ops.pmove.gravity)
            {
                pflags |= Defines.PS_M_GRAVITY;
            }
            if (ps.pmove.delta_angles[0] != ops.pmove.delta_angles[0] || ps.pmove.delta_angles[1] != ops.pmove.delta_angles[1] || ps.pmove.delta_angles[2] != ops.pmove.delta_angles[2])
            {
                pflags |= Defines.PS_M_DELTA_ANGLES;
            }
            if (ps.viewoffset[0] != ops.viewoffset[0] || ps.viewoffset[1] != ops.viewoffset[1] || ps.viewoffset[2] != ops.viewoffset[2])
            {
                pflags |= Defines.PS_VIEWOFFSET;
            }
            if (ps.viewangles[0] != ops.viewangles[0] || ps.viewangles[1] != ops.viewangles[1] || ps.viewangles[2] != ops.viewangles[2])
            {
                pflags |= Defines.PS_VIEWANGLES;
            }
            if (ps.kick_angles[0] != ops.kick_angles[0] || ps.kick_angles[1] != ops.kick_angles[1] || ps.kick_angles[2] != ops.kick_angles[2])
            {
                pflags |= Defines.PS_KICKANGLES;
            }
            if (ps.blend[0] != ops.blend[0] || ps.blend[1] != ops.blend[1] || ps.blend[2] != ops.blend[2] || ps.blend[3] != ops.blend[3])
            {
                pflags |= Defines.PS_BLEND;
            }
            if (ps.fov != ops.fov)
            {
                pflags |= Defines.PS_FOV;
            }
            if (ps.rdflags != ops.rdflags)
            {
                pflags |= Defines.PS_RDFLAGS;
            }
            if (ps.gunframe != ops.gunframe)
            {
                pflags |= Defines.PS_WEAPONFRAME;
            }
            pflags |= Defines.PS_WEAPONINDEX;
            MSG.WriteByte(msg, Defines.svc_playerinfo);
            MSG.WriteShort(msg, pflags);
            if ((pflags & Defines.PS_M_TYPE) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_type);
            }
            if ((pflags & Defines.PS_M_ORIGIN) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.origin[0]);
                MSG.WriteShort(msg, ps.pmove.origin[1]);
                MSG.WriteShort(msg, ps.pmove.origin[2]);
            }

            if ((pflags & Defines.PS_M_VELOCITY) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.velocity[0]);
                MSG.WriteShort(msg, ps.pmove.velocity[1]);
                MSG.WriteShort(msg, ps.pmove.velocity[2]);
            }

            if ((pflags & Defines.PS_M_TIME) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_time);
            }
            if ((pflags & Defines.PS_M_FLAGS) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_flags);
            }
            if ((pflags & Defines.PS_M_GRAVITY) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.gravity);
            }
            if ((pflags & Defines.PS_M_DELTA_ANGLES) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.delta_angles[0]);
                MSG.WriteShort(msg, ps.pmove.delta_angles[1]);
                MSG.WriteShort(msg, ps.pmove.delta_angles[2]);
            }

            if ((pflags & Defines.PS_VIEWOFFSET) != 0)
            {
                MSG.WriteChar(msg, ps.viewoffset[0] * 4);
                MSG.WriteChar(msg, ps.viewoffset[1] * 4);
                MSG.WriteChar(msg, ps.viewoffset[2] * 4);
            }

            if ((pflags & Defines.PS_VIEWANGLES) != 0)
            {
                MSG.WriteAngle16(msg, ps.viewangles[0]);
                MSG.WriteAngle16(msg, ps.viewangles[1]);
                MSG.WriteAngle16(msg, ps.viewangles[2]);
            }

            if ((pflags & Defines.PS_KICKANGLES) != 0)
            {
                MSG.WriteChar(msg, ps.kick_angles[0] * 4);
                MSG.WriteChar(msg, ps.kick_angles[1] * 4);
                MSG.WriteChar(msg, ps.kick_angles[2] * 4);
            }

            if ((pflags & Defines.PS_WEAPONINDEX) != 0)
            {
                MSG.WriteByte(msg, ps.gunindex);
            }

            if ((pflags & Defines.PS_WEAPONFRAME) != 0)
            {
                MSG.WriteByte(msg, ps.gunframe);
                MSG.WriteChar(msg, ps.gunoffset[0] * 4);
                MSG.WriteChar(msg, ps.gunoffset[1] * 4);
                MSG.WriteChar(msg, ps.gunoffset[2] * 4);
                MSG.WriteChar(msg, ps.gunangles[0] * 4);
                MSG.WriteChar(msg, ps.gunangles[1] * 4);
                MSG.WriteChar(msg, ps.gunangles[2] * 4);
            }

            if ((pflags & Defines.PS_BLEND) != 0)
            {
                MSG.WriteByte(msg, ps.blend[0] * 255);
                MSG.WriteByte(msg, ps.blend[1] * 255);
                MSG.WriteByte(msg, ps.blend[2] * 255);
                MSG.WriteByte(msg, ps.blend[3] * 255);
            }

            if ((pflags & Defines.PS_FOV) != 0)
            {
                MSG.WriteByte(msg, ps.fov);
            }
            if ((pflags & Defines.PS_RDFLAGS) != 0)
            {
                MSG.WriteByte(msg, ps.rdflags);
            }
            var statbits = 0;

            for (var i = 0; i < Defines.MAX_STATS; i++)
            {
                if (ps.stats[i] != ops.stats[i])
                {
                    statbits |= 1 << i;
                }
            }
            MSG.WriteLong(msg, statbits);
            for (var i = 0; i < Defines.MAX_STATS; i++)
            {
                if ((statbits & (1 << i)) != 0)
                {
                    MSG.WriteShort(msg, ps.stats[i]);
                }
            }
        }