Пример #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
        internal void SendConstruct(GridAi ai)
        {
            if (IsServer)
            {
                PrunedPacketsToClient.Remove(ai.Construct.Data.Repo.FocusData);
                ++ai.Construct.Data.Repo.FocusData.Revision;

                PacketInfo      oldInfo;
                ConstructPacket iPacket;
                if (PrunedPacketsToClient.TryGetValue(ai.Construct.Data.Repo, out oldInfo))
                {
                    iPacket          = (ConstructPacket)oldInfo.Packet;
                    iPacket.EntityId = ai.MyGrid.EntityId;
                    iPacket.Data     = ai.Construct.Data.Repo;
                }
                else
                {
                    iPacket          = PacketConstructPool.Get();
                    iPacket.MId      = ++ai.MIds[(int)PacketType.Construct];
                    iPacket.EntityId = ai.MyGrid.EntityId;
                    iPacket.SenderId = MultiplayerId;
                    iPacket.PType    = PacketType.Construct;
                    iPacket.Data     = ai.Construct.Data.Repo;
                }

                PrunedPacketsToClient[ai.Construct.Data.Repo] = new PacketInfo {
                    Entity = ai.MyGrid,
                    Packet = iPacket,
                };
            }
            else
            {
                Log.Line($"SendConstruct should never be called on Client");
            }
        }
Пример #3
0
        internal void SendAiData(GridAi ai)
        {
            if (IsServer)
            {
                PacketInfo   oldInfo;
                AiDataPacket iPacket;
                if (PrunedPacketsToClient.TryGetValue(ai.Data.Repo, out oldInfo))
                {
                    iPacket          = (AiDataPacket)oldInfo.Packet;
                    iPacket.EntityId = ai.MyGrid.EntityId;
                    iPacket.Data     = ai.Data.Repo;
                }
                else
                {
                    iPacket          = PacketAiPool.Get();
                    iPacket.MId      = ++ai.MIds[(int)PacketType.AiData];
                    iPacket.EntityId = ai.MyGrid.EntityId;
                    iPacket.SenderId = MultiplayerId;
                    iPacket.PType    = PacketType.AiData;
                    iPacket.Data     = ai.Data.Repo;
                }

                ++ai.Data.Repo.Revision;

                PrunedPacketsToClient[ai.Data.Repo] = new PacketInfo {
                    Entity = ai.MyGrid,
                    Packet = iPacket,
                };
            }
            else
            {
                Log.Line($"SendAiData should never be called on Client");
            }
        }
Пример #4
0
        internal void SendTargetChange(WeaponComponent comp, int weaponId)
        {
            if (IsServer)
            {
                if (!comp.Session.PrunedPacketsToClient.ContainsKey(comp.Data.Repo.Base))
                {
                    const PacketType type = PacketType.TargetChange;
                    comp.Data.Repo.Base.UpdateCompBasePacketInfo(comp);

                    var          w = comp.Platform.Weapons[weaponId];
                    PacketInfo   oldInfo;
                    TargetPacket iPacket;
                    if (PrunedPacketsToClient.TryGetValue(w.TargetData, out oldInfo))
                    {
                        iPacket          = (TargetPacket)oldInfo.Packet;
                        iPacket.EntityId = comp.MyCube.EntityId;
                        iPacket.Target   = w.TargetData;
                    }
                    else
                    {
                        iPacket          = PacketTargetPool.Get();
                        iPacket.MId      = ++w.MIds[(int)type];
                        iPacket.EntityId = comp.MyCube.EntityId;
                        iPacket.SenderId = MultiplayerId;
                        iPacket.PType    = type;
                        iPacket.Target   = w.TargetData;
                    }


                    PrunedPacketsToClient[w.TargetData] = new PacketInfo {
                        Entity = comp.MyCube,
                        Packet = iPacket,
                    };
                }
                else
                {
                    SendCompBaseData(comp);
                }
            }
            else
            {
                Log.Line($"SendTargetChange should never be called on Client");
            }
        }
Пример #5
0
        internal void SendWeaponReload(Weapon w)
        {
            if (IsServer)
            {
                if (!PrunedPacketsToClient.ContainsKey(w.Comp.Data.Repo.Base))
                {
                    const PacketType type = PacketType.WeaponReload;
                    w.Comp.Data.Repo.Base.UpdateCompBasePacketInfo(w.Comp);

                    PacketInfo         oldInfo;
                    WeaponReloadPacket iPacket;
                    if (PrunedPacketsToClient.TryGetValue(w.Reload, out oldInfo))
                    {
                        iPacket          = (WeaponReloadPacket)oldInfo.Packet;
                        iPacket.EntityId = w.Comp.MyCube.EntityId;
                        iPacket.Data     = w.Reload;
                    }
                    else
                    {
                        iPacket          = PacketReloadPool.Get();
                        iPacket.MId      = ++w.MIds[(int)type];
                        iPacket.EntityId = w.Comp.MyCube.EntityId;
                        iPacket.SenderId = MultiplayerId;
                        iPacket.PType    = type;
                        iPacket.Data     = w.Reload;
                        iPacket.WeaponId = w.WeaponId;
                    }

                    PrunedPacketsToClient[w.Reload] = new PacketInfo {
                        Entity = w.Comp.MyCube,
                        Packet = iPacket,
                    };
                }
                else
                {
                    SendCompBaseData(w.Comp);
                }
            }
            else
            {
                Log.Line($"SendWeaponReload should never be called on Client");
            }
        }
Пример #6
0
        internal void SendConstructFoci(GridAi ai)
        {
            if (IsServer)
            {
                ++ai.Construct.Data.Repo.FocusData.Revision;

                if (!PrunedPacketsToClient.ContainsKey(ai.Construct.Data.Repo))
                {
                    PacketInfo          oldInfo;
                    ConstructFociPacket iPacket;
                    if (PrunedPacketsToClient.TryGetValue(ai.Construct.Data.Repo.FocusData, out oldInfo))
                    {
                        iPacket          = (ConstructFociPacket)oldInfo.Packet;
                        iPacket.EntityId = ai.MyGrid.EntityId;
                        iPacket.Data     = ai.Construct.Data.Repo.FocusData;
                    }
                    else
                    {
                        iPacket          = PacketConstructFociPool.Get();
                        iPacket.MId      = ++ai.MIds[(int)PacketType.ConstructFoci];
                        iPacket.EntityId = ai.MyGrid.EntityId;
                        iPacket.SenderId = MultiplayerId;
                        iPacket.PType    = PacketType.ConstructFoci;
                        iPacket.Data     = ai.Construct.Data.Repo.FocusData;
                    }

                    PrunedPacketsToClient[ai.Construct.Data.Repo.FocusData] = new PacketInfo {
                        Entity = ai.MyGrid,
                        Packet = iPacket,
                    };
                }
                else
                {
                    SendConstruct(ai);
                }
            }
            else
            {
                Log.Line($"SendConstructGroups should never be called on Client");
            }
        }
Пример #7
0
        internal void SendCompState(WeaponComponent comp)
        {
            if (IsServer)
            {
                if (!comp.Session.PrunedPacketsToClient.ContainsKey(comp.Data.Repo.Base))
                {
                    const PacketType type = PacketType.CompState;
                    comp.Data.Repo.Base.UpdateCompBasePacketInfo(comp);

                    PacketInfo      oldInfo;
                    CompStatePacket iPacket;
                    if (PrunedPacketsToClient.TryGetValue(comp.Data.Repo.Base.State, out oldInfo))
                    {
                        iPacket          = (CompStatePacket)oldInfo.Packet;
                        iPacket.EntityId = comp.MyCube.EntityId;
                        iPacket.Data     = comp.Data.Repo.Base.State;
                    }
                    else
                    {
                        iPacket          = PacketStatePool.Get();
                        iPacket.EntityId = comp.MyCube.EntityId;
                        iPacket.SenderId = MultiplayerId;
                        iPacket.PType    = type;
                        iPacket.Data     = comp.Data.Repo.Base.State;
                    }

                    PrunedPacketsToClient[comp.Data.Repo.Base.State] = new PacketInfo {
                        Entity = comp.MyCube,
                        Packet = iPacket,
                    };
                }
                else
                {
                    SendCompBaseData(comp);
                }
            }
            else
            {
                Log.Line($"SendCompState should never be called on Client");
            }
        }
Пример #8
0
        internal void SendWeaponAmmoData(Weapon w)
        {
            if (IsServer)
            {
                const PacketType type = PacketType.WeaponAmmo;
                ++w.Ammo.Revision;

                PacketInfo       oldInfo;
                WeaponAmmoPacket iPacket;
                if (PrunedPacketsToClient.TryGetValue(w.Ammo, out oldInfo))
                {
                    iPacket          = (WeaponAmmoPacket)oldInfo.Packet;
                    iPacket.EntityId = w.Comp.MyCube.EntityId;
                    iPacket.Data     = w.Ammo;
                }
                else
                {
                    iPacket          = PacketAmmoPool.Get();
                    iPacket.MId      = ++w.MIds[(int)type];
                    iPacket.EntityId = w.Comp.MyCube.EntityId;
                    iPacket.SenderId = MultiplayerId;
                    iPacket.PType    = type;
                    iPacket.Data     = w.Ammo;
                    iPacket.WeaponId = w.WeaponId;
                }


                PrunedPacketsToClient[w.Ammo] = new PacketInfo {
                    Entity = w.Comp.MyCube,
                    Packet = iPacket,
                };
            }
            else
            {
                Log.Line($"SendWeaponAmmoData should never be called on Client");
            }
        }
Пример #9
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();
        }