コード例 #1
0
            public override void Process()
            {
                Entity.CopyByMask(Changes);

                byte[] compressed;

                using (var ms = new MemoryStream())
                    using (var bw = new BinaryWriter(ms))
                    {
                        bw.Write(Entity.ID);
                        bw.Write(Changes.LastBitmask);
                        Entity.WriteByMask(Changes.LastBitmask, bw);

                        byte[] uncompressed = ms.ToArray();
                        compressed = ZlibHelper.CompressBuffer(uncompressed);
                    }

                foreach (var peer in Sender.Coob.GetClients(Sender))
                {
                    peer.Writer.Write(SCPacketIDs.EntityUpdate);
                    peer.Writer.Write(compressed.Length);
                    peer.Writer.Write(compressed);

                    if (!IsJoin)
                    {
                        continue;
                    }

                    byte[] peerCompressed;
                    using (var ms = new MemoryStream())
                        using (var bw = new BinaryWriter(ms))
                        {
                            bw.Write(peer.Entity.ID);
                            bw.Write(Changes.LastBitmask);
                            peer.Entity.WriteByMask(FullBitmask, bw);

                            byte[] uncompressed = ms.ToArray();
                            peerCompressed = ZlibHelper.CompressBuffer(uncompressed);
                        }

                    Sender.Writer.Write(SCPacketIDs.EntityUpdate);
                    Sender.Writer.Write(peerCompressed.Length);
                    Sender.Writer.Write(peerCompressed);
                }
            }
コード例 #2
0
        public void SendServerUpdate()
        {
            byte[] compressed;

            using (var ms = new MemoryStream())
                using (var bw = new BinaryWriter(ms))
                {
                    const uint Items1Length = 0;
                    bw.Write(Items1Length);

                    bw.Write(HitPackets.Count);
                    foreach (Packet.Hit hit in HitPackets)
                    {
                        hit.Write(bw);
                    }

                    const uint Items3Length = 0;
                    bw.Write(Items3Length);

                    const uint SoundActionsLength = 0;
                    bw.Write(SoundActionsLength);

                    bw.Write(ShootPackets.Count);
                    foreach (Packet.Shoot shoot in ShootPackets)
                    {
                        shoot.Write(bw);
                    }

                    const uint Items6Length = 0;
                    bw.Write(Items6Length);

                    const uint ChunkItemsLength = 0;
                    bw.Write(ChunkItemsLength);

                    const uint Items8Length = 0;
                    bw.Write(Items8Length);

                    const uint PickupsLength = 0;
                    bw.Write(PickupsLength);

                    const uint KillActions = 0;
                    bw.Write(KillActions);

                    const uint DamageActions = 0;
                    bw.Write(DamageActions);

                    const uint Items12Length = 0;
                    bw.Write(Items12Length);

                    const uint MissionsLength = 0;
                    bw.Write(MissionsLength);

                    byte[] uncompressed = ms.ToArray();
                    compressed = ZlibHelper.CompressBuffer(uncompressed);
                }

            // Send all the compressed data to every client
            foreach (Client client in Coob.GetClients().Where(client => client.Joined))
            {
                try
                {
                    client.Writer.Write(SCPacketIDs.ServerUpdate);
                    client.Writer.Write((uint)compressed.Length);
                    client.Writer.Write(compressed);
                }
                catch (IOException)
                {
                }
            }

            // Clear data
            HitPackets.Clear();
            ShootPackets.Clear();
        }