private bool ClientAiDataUpdate(PacketObj data)
        {
            var packet       = data.Packet;
            var myGrid       = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;
            var aiSyncPacket = (AiDataPacket)packet;

            if (myGrid == null)
            {
                return(Error(data, Msg($"Grid: {packet.EntityId}")));
            }

            GridAi ai;

            if (GridTargetingAIs.TryGetValue(myGrid, out ai))
            {
                if (ai.MIds[(int)packet.PType] < packet.MId)
                {
                    ai.MIds[(int)packet.PType] = packet.MId;

                    ai.Data.Repo.Sync(aiSyncPacket.Data);
                }
                else
                {
                    Log.Line($"ClientAiDataUpdate: mid fail - senderId:{packet.SenderId} - mId:{ai.MIds[(int)packet.PType]} >= {packet.MId}");
                }

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}")));
            }

            return(true);
        }
        private bool ClientConstruct(PacketObj data)
        {
            var packet   = data.Packet;
            var myGrid   = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;
            var cgPacket = (ConstructPacket)packet;

            if (myGrid == null)
            {
                return(Error(data, Msg($"Grid: {packet.EntityId}")));
            }

            GridAi ai;

            if (GridToMasterAi.TryGetValue(myGrid, out ai))
            {
                if (ai.MIds[(int)packet.PType] < packet.MId)
                {
                    ai.MIds[(int)packet.PType] = packet.MId;

                    var rootConstruct = ai.Construct.RootAi.Construct;

                    rootConstruct.Data.Repo.Sync(rootConstruct, cgPacket.Data);
                    rootConstruct.UpdateLeafs();
                }
                else
                {
                    Log.Line($"ClientConstructGroups MID failure - mId:{packet.MId}");
                }

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}")));
            }

            return(true);
        }
Esempio n. 3
0
        private bool ServerActiveControlUpdate(PacketObj data)
        {
            var packet  = data.Packet;
            var dPacket = (BoolUpdatePacket)packet;
            var cube    = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeBlock;

            if (cube == null)
            {
                return(Error(data, Msg("Cube")));
            }

            GridAi ai;
            long   playerId = 0;

            if (GridToMasterAi.TryGetValue(cube.CubeGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId))
            {
                uint[] mIds;
                if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId)
                {
                    mIds[(int)packet.PType] = packet.MId;

                    ai.Construct.UpdateConstructsPlayers(cube, playerId, dPacket.Data);
                    data.Report.PacketValid = true;
                }
                else
                {
                    Log.Line($"ServerActiveControlUpdate: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}");
                }
            }
            else
            {
                Log.Line($"ServerActiveControlUpdate: ai:{ai != null} - targetingAi:{GridTargetingAIs.ContainsKey(cube.CubeGrid)} - masterAi:{GridToMasterAi.ContainsKey(cube.CubeGrid)} - IdToComp:{IdToCompMap.ContainsKey(cube.EntityId)} - {cube.BlockDefinition.Id.SubtypeName} - playerId:{playerId}({packet.SenderId}) - marked:{cube.MarkedForClose}({cube.CubeGrid.MarkedForClose}) - active:{dPacket.Data}");
            }

            return(true);
        }
Esempio n. 4
0
        private bool ServerFocusUpdate(PacketObj data)
        {
            var packet      = data.Packet;
            var focusPacket = (FocusPacket)packet;
            var myGrid      = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;

            if (myGrid == null)
            {
                return(Error(data, Msg("Grid")));
            }

            GridAi ai;

            uint[] mIds;
            if (GridToMasterAi.TryGetValue(myGrid, out ai) && PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId)
            {
                mIds[(int)packet.PType] = packet.MId;

                var targetGrid = MyEntities.GetEntityByIdOrDefault(focusPacket.TargetId) as MyCubeGrid;

                switch (packet.PType)
                {
                case PacketType.FocusUpdate:
                    if (targetGrid != null)
                    {
                        ai.Construct.Focus.ServerAddFocus(targetGrid, ai);
                    }
                    break;

                case PacketType.NextActiveUpdate:
                    ai.Construct.Focus.ServerNextActive(focusPacket.AddSecondary, ai);
                    break;

                case PacketType.ReleaseActiveUpdate:
                    ai.Construct.Focus.RequestReleaseActive(ai);
                    break;

                case PacketType.FocusLockUpdate:
                    ai.Construct.Focus.ServerCycleLock(ai);
                    break;
                }

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg($"GridAi not found or mid failure: ai:{ai != null}, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}")));
            }

            return(true);
        }
Esempio n. 5
0
        private bool ServerMarkedTargetUpdate(PacketObj data)
        {
            var packet       = data.Packet;
            var targetPacket = (FakeTargetPacket)packet;
            var myGrid       = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;

            if (myGrid == null)
            {
                return(Error(data, Msg($"GridId:{packet.EntityId} - entityExists:{MyEntities.EntityExists(packet.EntityId)}")));
            }


            GridAi ai;
            long   playerId;

            if (GridTargetingAIs.TryGetValue(myGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId))
            {
                GridAi.FakeTargets fakeTargets;
                uint[]             mIds;
                if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId && PlayerDummyTargets.TryGetValue(playerId, out fakeTargets))
                {
                    mIds[(int)packet.PType] = packet.MId;

                    fakeTargets.PaintedTarget.Sync(targetPacket, ai);
                    PacketsToClient.Add(new PacketInfo {
                        Entity = myGrid, Packet = targetPacket
                    });

                    data.Report.PacketValid = true;
                }
                else
                {
                    Log.Line($"ServerFakeTargetUpdate: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}");
                }
            }
            else
            {
                return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}")));
            }

            return(true);
        }
Esempio n. 6
0
        public bool IsWeaponAreaRestricted(MyStringHash subtype, MyOrientedBoundingBoxD cubeBoundingBox, MyCubeGrid myGrid, long ignoredEntity, GridAi gridAi, out MyOrientedBoundingBoxD restrictedBox, out BoundingSphereD restrictedSphere)
        {
            _tmpNearByBlocks.Clear();
            GridAi ai;

            if (gridAi == null)
            {
                if (!GridToMasterAi.ContainsKey(myGrid))
                {
                    restrictedSphere = new BoundingSphereD();
                    restrictedBox    = new MyOrientedBoundingBoxD();
                    return(false);
                }
                ai = GridToMasterAi[myGrid];
            }
            else
            {
                ai = gridAi;
            }

            CalculateRestrictedShapes(subtype, cubeBoundingBox, out restrictedBox, out restrictedSphere);
            var queryRadius = Math.Max(restrictedBox.HalfExtent.AbsMax(), restrictedSphere.Radius);

            if (queryRadius < 0.01)
            {
                return(false);
            }

            var restriction = WeaponAreaRestrictions[subtype];
            var checkBox    = restriction.RestrictionBoxInflation > 0;
            var checkSphere = restriction.RestrictionRadius > 0;
            var querySphere = new BoundingSphereD(cubeBoundingBox.Center, queryRadius);

            myGrid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks);

            foreach (var grid in ai.SubGrids)
            {
                if (grid == myGrid || !GridTargetingAIs.ContainsKey(grid))
                {
                    continue;
                }
                grid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks);
            }

            for (int l = 0; l < _tmpNearByBlocks.Count; l++)
            {
                var cube = _tmpNearByBlocks[l] as MyCubeBlock;
                if (cube == null || cube.EntityId == ignoredEntity || !WeaponCoreBlockDefs.ContainsKey(cube.BlockDefinition.Id.SubtypeId.String))
                {
                    continue;
                }

                if (!restriction.CheckForAnyWeapon && cube.BlockDefinition.Id.SubtypeId != subtype)
                {
                    continue;
                }

                if (checkBox)
                {
                    var cubeBox = new MyOrientedBoundingBoxD(cube.PositionComp.LocalAABB, cube.PositionComp.WorldMatrixRef);
                    if (restrictedBox.Contains(ref cubeBox) != ContainmentType.Disjoint)
                    {
                        return(true);
                    }
                }

                if (checkSphere && restrictedSphere.Contains(cube.PositionComp.WorldAABB) != ContainmentType.Disjoint)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 7
0
        private bool ClientConstructFoci(PacketObj data)
        {
            var packet     = data.Packet;
            var myGrid     = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;
            var fociPacket = (ConstructFociPacket)packet;

            if (myGrid == null)
            {
                return(Error(data, Msg($"Grid: {packet.EntityId}")));
            }

            GridAi ai;

            if (GridToMasterAi.TryGetValue(myGrid, out ai))
            {
                var rootConstruct = ai.Construct.RootAi.Construct;

                if (rootConstruct.Data.Repo.FocusData.Revision < fociPacket.Data.Revision)
                {
                    rootConstruct.Data.Repo.FocusData.Sync(ai, fociPacket.Data);
                }
                else
                {
                    Log.Line($"ClientConstructFoci Version failure - Version:{rootConstruct.Data.Repo.FocusData.Revision}({fociPacket.Data.Revision})");
                }

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}")));
            }

            return(true);
        }