Exemple #1
0
        // no storge sync

        private bool ClientClientMouseEvent(PacketObj data)
        {
            var packet      = data.Packet;
            var mousePacket = (InputPacket)packet;

            if (mousePacket.Data == null)
            {
                return(Error(data, Msg("Data")));
            }
            var cube = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeBlock;

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

            GridAi ai;
            long   playerId;

            if (GridToMasterAi.TryGetValue(cube.CubeGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId))
            {
                PlayerMouseStates[playerId] = mousePacket.Data;

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg("No PlayerId Found")));
            }

            return(true);
        }
Exemple #2
0
        private bool ServerClientMouseEvent(PacketObj data)
        {
            var packet      = data.Packet;
            var inputPacket = (InputPacket)packet;
            var ent         = MyEntities.GetEntityByIdOrDefault(packet.EntityId);

            if (ent == null)
            {
                return(Error(data, Msg("Entity")));
            }
            if (inputPacket.Data == null)
            {
                return(Error(data, Msg("Data")));
            }

            long playerId;

            if (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;

                    if (PlayerMouseStates.ContainsKey(playerId))
                    {
                        PlayerMouseStates[playerId].Sync(inputPacket.Data);
                    }
                    else
                    {
                        PlayerMouseStates[playerId] = new InputStateData(inputPacket.Data);
                    }

                    PacketsToClient.Add(new PacketInfo {
                        Entity = ent, Packet = inputPacket
                    });

                    data.Report.PacketValid = true;
                }
                else
                {
                    Log.Line($"ServerClientMouseEvent: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}");
                }
            }
            else
            {
                return(Error(data, Msg("Player Not Found")));
            }

            return(true);
        }
        private bool ClientFakeTargetUpdate(PacketObj data)
        {
            var packet = data.Packet;

            data.ErrorPacket.NoReprocess = true;
            var targetPacket = (FakeTargetPacket)packet;
            var myGrid       = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;

            GridAi ai;

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

                    long playerId;
                    if (SteamToPlayer.TryGetValue(packet.SenderId, out playerId))
                    {
                        FakeTarget dummyTarget;
                        if (PlayerDummyTargets.TryGetValue(playerId, out dummyTarget))
                        {
                            dummyTarget.Update(targetPacket.Pos, ai, null, targetPacket.TargetId);
                        }
                        else
                        {
                            return(Error(data, Msg("Player dummy target not found")));
                        }
                    }
                    else
                    {
                        return(Error(data, Msg("SteamToPlayer missing Player")));
                    }
                }
                else
                {
                    Log.Line($"ClientFakeTargetUpdate: mid fail - senderId:{packet.SenderId} - mId:{ai.MIds[(int)packet.PType]} >= {packet.MId}");
                }

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg($"GridId: {packet.EntityId}", myGrid != null), Msg("Ai")));
            }

            return(true);
        }
Exemple #4
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);
        }
        private bool ClientFakeTargetUpdate(PacketObj data)
        {
            var packet = data.Packet;

            data.ErrorPacket.NoReprocess = true;
            var targetPacket = (FakeTargetPacket)packet;
            var myGrid       = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid;

            GridAi ai;

            if (myGrid != null && GridTargetingAIs.TryGetValue(myGrid, out ai))
            {
                long playerId;
                if (SteamToPlayer.TryGetValue(packet.SenderId, out playerId))
                {
                    FakeTargets dummyTargets;
                    if (PlayerDummyTargets.TryGetValue(playerId, out dummyTargets))
                    {
                        dummyTargets.ManualTarget.Sync(targetPacket, ai);
                        dummyTargets.PaintedTarget.Sync(targetPacket, ai);
                    }
                    else
                    {
                        return(Error(data, Msg("Player dummy target not found")));
                    }
                }
                else
                {
                    return(Error(data, Msg("SteamToPlayer missing Player")));
                }

                data.Report.PacketValid = true;
            }
            else
            {
                return(Error(data, Msg($"GridId: {packet.EntityId}", myGrid != null), Msg("Ai")));
            }

            return(true);
        }
Exemple #6
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);
        }