コード例 #1
0
        internal void SendCompBaseData(WeaponComponent comp)
        {
            if (IsServer)
            {
                const PacketType type = PacketType.CompBase;
                comp.Data.Repo.Base.UpdateCompBasePacketInfo(comp, true);

                PacketInfo     oldInfo;
                CompBasePacket iPacket;
                if (PrunedPacketsToClient.TryGetValue(comp.Data.Repo.Base, out oldInfo))
                {
                    iPacket          = (CompBasePacket)oldInfo.Packet;
                    iPacket.EntityId = comp.MyCube.EntityId;
                    iPacket.Data     = comp.Data.Repo.Base;
                }
                else
                {
                    iPacket          = PacketCompBasePool.Get();
                    iPacket.MId      = ++comp.MIds[(int)type];
                    iPacket.EntityId = comp.MyCube.EntityId;
                    iPacket.SenderId = MultiplayerId;
                    iPacket.PType    = type;
                    iPacket.Data     = comp.Data.Repo.Base;
                }

                PrunedPacketsToClient[comp.Data.Repo.Base] = new PacketInfo {
                    Entity = comp.MyCube,
                    Packet = iPacket,
                };
            }
            else
            {
                Log.Line($"SendCompData should never be called on Client");
            }
        }
コード例 #2
0
        private void ServerPacketsForClientsClean()
        {
            PacketsToClient.Clear();
            foreach (var pInfo in PrunedPacketsToClient.Values)
            {
                switch (pInfo.Packet.PType)
                {
                case PacketType.AiData:
                {
                    var iPacket = (AiDataPacket)pInfo.Packet;
                    PacketAiPool.Return(iPacket);
                    break;
                }

                case PacketType.CompBase:
                {
                    var iPacket = (CompBasePacket)pInfo.Packet;
                    PacketCompBasePool.Return(iPacket);
                    break;
                }

                case PacketType.CompState:
                {
                    var iPacket = (CompStatePacket)pInfo.Packet;
                    PacketStatePool.Return(iPacket);
                    break;
                }

                case PacketType.TargetChange:
                {
                    var iPacket = (TargetPacket)pInfo.Packet;
                    PacketTargetPool.Return(iPacket);
                    break;
                }

                case PacketType.WeaponReload:
                {
                    var iPacket = (WeaponReloadPacket)pInfo.Packet;
                    PacketReloadPool.Return(iPacket);
                    break;
                }

                case PacketType.Construct:
                {
                    var iPacket = (ConstructPacket)pInfo.Packet;
                    PacketConstructPool.Return(iPacket);
                    break;
                }

                case PacketType.ConstructFoci:
                {
                    var iPacket = (ConstructFociPacket)pInfo.Packet;
                    PacketConstructFociPool.Return(iPacket);
                    break;
                }

                case PacketType.WeaponAmmo:
                {
                    var iPacket = (WeaponAmmoPacket)pInfo.Packet;
                    PacketAmmoPool.Return(iPacket);
                    break;
                }
                }
            }
            PrunedPacketsToClient.Clear();
        }