Esempio n. 1
0
 internal void SendTrackReticleUpdate(WeaponComponent comp, bool track)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new BoolUpdatePacket
             {
                 MId      = ++mIds[(int)PacketType.ReticleUpdate],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReticleUpdate,
                 Data     = track
             });
         }
         else
         {
             Log.Line($"SendTrackReticleUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         comp.Data.Repo.Base.State.TrackingReticle = track;
         SendCompBaseData(comp);
     }
 }
        private bool ServerAmmoCycleRequest(PacketObj data)
        {
            var packet      = data.Packet;
            var cyclePacket = (AmmoCycleRequestPacket)packet;
            var ent         = MyEntities.GetEntityByIdOrDefault(packet.EntityId);
            var comp        = ent?.Components.Get <WeaponComponent>();

            if (comp?.Ai == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready)
            {
                return(Error(data, Msg("Comp", comp != null), Msg("Ai", comp?.Ai != null), Msg("Ai", comp?.Platform.State == MyWeaponPlatform.PlatformState.Ready)));
            }

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

                comp.Data.Repo.Base.State.PlayerId = cyclePacket.PlayerId;
                comp.Platform.Weapons[cyclePacket.WeaponId].ChangeAmmo(cyclePacket.NewAmmoId);
                data.Report.PacketValid = true;
            }
            else
            {
                Log.Line($"ServerAmmoCycleRequest: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}");
            }

            return(true);
        }
Esempio n. 3
0
 internal void SendActiveControlUpdate(GridAi ai, MyCubeBlock controlBlock, bool active)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new BoolUpdatePacket
             {
                 MId      = ++mIds[(int)PacketType.ActiveControlUpdate],
                 EntityId = controlBlock.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ActiveControlUpdate,
                 Data     = active
             });
         }
         else
         {
             Log.Line($"SendActiveControlUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         ai.Construct.UpdateConstructsPlayers(controlBlock, PlayerId, active);
     }
     else
     {
         Log.Line($"SendActiveControlUpdate should never be called on Dedicated");
     }
 }
Esempio n. 4
0
 internal void SendPlayerControlRequest(WeaponComponent comp, long playerId, CompStateValues.ControlMode mode)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new PlayerControlRequestPacket
             {
                 MId      = ++mIds[(int)PacketType.PlayerControlRequest],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.PlayerControlRequest,
                 PlayerId = playerId,
                 Mode     = mode,
             });
         }
         else
         {
             Log.Line($"SendPlayerControlRequest no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         SendCompBaseData(comp);
     }
     else
     {
         Log.Line($"SendPlayerControlRequest should never be called on Server");
     }
 }
Esempio n. 5
0
 internal void SendReleaseActiveUpdate(GridAi ai)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new FocusPacket
             {
                 MId      = ++mIds[(int)PacketType.ReleaseActiveUpdate],
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReleaseActiveUpdate
             });
         }
         else
         {
             Log.Line($"SendReleaseActiveUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new FocusPacket
             {
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReleaseActiveUpdate
             }
         });
     }
 }
Esempio n. 6
0
 internal void SendOverRidesClientComp(WeaponComponent comp, string settings, int value)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new OverRidesPacket
             {
                 MId      = ++mIds[(int)PacketType.OverRidesUpdate],
                 PType    = PacketType.OverRidesUpdate,
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 Setting  = settings,
                 Value    = value,
             });
         }
         else
         {
             Log.Line($"SendOverRidesClientComp no player MIds found");
         }
     }
     else
     {
         Log.Line($"SendOverRidesClientComp should only be called on clients");
     }
 }
Esempio n. 7
0
 internal void SendUpdateRequest(long entityId, PacketType ptype)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new Packet
             {
                 MId      = ++mIds[(int)ptype],
                 EntityId = entityId,
                 SenderId = MultiplayerId,
                 PType    = ptype
             });
         }
         else
         {
             Log.Line($"SendUpdateRequest no player MIds found");
         }
     }
     else
     {
         Log.Line($"SendUpdateRequest should only be called on clients");
     }
 }
Esempio n. 8
0
 internal void SendAmmoCycleRequest(Weapon w, int newAmmoId)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new AmmoCycleRequestPacket
             {
                 MId       = ++mIds[(int)PacketType.AmmoCycleRequest],
                 EntityId  = w.Comp.MyCube.EntityId,
                 SenderId  = MultiplayerId,
                 PType     = PacketType.AmmoCycleRequest,
                 WeaponId  = w.WeaponId,
                 NewAmmoId = newAmmoId,
                 PlayerId  = PlayerId,
             });
         }
         else
         {
             Log.Line($"SendAmmoCycleRequest no player MIds found");
         }
     }
     else
     {
         Log.Line($"SendAmmoCycleRequest should never be called on Non-Client");
     }
 }
Esempio n. 9
0
        private bool ServerUpdateSetting(PacketObj data)
        {
            var packet = data.Packet;
            var ent    = MyEntities.GetEntityByIdOrDefault(packet.EntityId);
            var comp   = ent?.Components.Get <WeaponComponent>();

            if (comp?.Ai == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready)
            {
                return(Error(data, Msg($"CompId: {packet.EntityId}", comp != null), Msg("Ai", comp?.Ai != null), Msg("Ai", comp?.Platform.State == MyWeaponPlatform.PlatformState.Ready)));
            }

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

                switch (packet.PType)
                {
                case PacketType.RequestSetRof:
                {
                    WepUi.RequestSetRof(comp.MyCube as IMyTerminalBlock, ((FloatUpdatePacket)packet).Data);
                    break;
                }

                case PacketType.RequestSetRange:
                {
                    WepUi.RequestSetRange(comp.MyCube as IMyTerminalBlock, ((FloatUpdatePacket)packet).Data);
                    break;
                }

                case PacketType.RequestSetDps:
                {
                    WepUi.RequestSetDps(comp.MyCube as IMyTerminalBlock, ((FloatUpdatePacket)packet).Data);
                    break;
                }

                case PacketType.RequestSetGuidance:
                {
                    WepUi.RequestSetGuidance(comp.MyCube as IMyTerminalBlock, ((BoolUpdatePacket)packet).Data);
                    break;
                }

                case PacketType.RequestSetOverload:
                {
                    WepUi.RequestSetOverload(comp.MyCube as IMyTerminalBlock, ((BoolUpdatePacket)packet).Data);
                    break;
                }
                }

                data.Report.PacketValid = true;
            }
            else
            {
                Log.Line($"ServerUpdateSetting: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}");
            }


            return(true);
        }
Esempio n. 10
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. 11
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);
        }
Esempio n. 12
0
 internal void SendFakeTargetUpdate(GridAi ai, GridAi.FakeTarget fake)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new FakeTargetPacket
             {
                 MId      = ++mIds[(int)PacketType.FakeTargetUpdate],
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = ai.Session.MultiplayerId,
                 PType    = PacketType.FakeTargetUpdate,
                 Pos      = fake.Position,
                 TargetId = fake.EntityId,
             });
         }
         else
         {
             Log.Line($"SendFakeTargetUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new FakeTargetPacket
             {
                 MId      = ++ai.MIds[(int)PacketType.FakeTargetUpdate],
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = ai.Session.MultiplayerId,
                 PType    = PacketType.FakeTargetUpdate,
                 Pos      = fake.Position,
                 TargetId = fake.EntityId,
             }
         });
     }
     else
     {
         Log.Line($"SendFakeTargetUpdate should never be called on Dedicated");
     }
 }
Esempio n. 13
0
 internal void SendActionShootUpdate(WeaponComponent comp, ShootActions action)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             comp.Session.PacketsToServer.Add(new ShootStatePacket
             {
                 MId      = ++mIds[(int)PacketType.RequestShootUpdate],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = comp.Session.MultiplayerId,
                 PType    = PacketType.RequestShootUpdate,
                 Action   = action,
                 PlayerId = PlayerId,
             });
         }
         else
         {
             Log.Line($"SendActionShootUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = comp.MyCube,
             Packet = new ShootStatePacket
             {
                 MId      = ++comp.MIds[(int)PacketType.RequestShootUpdate],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = comp.Session.MultiplayerId,
                 PType    = PacketType.RequestShootUpdate,
                 Action   = action,
                 PlayerId = PlayerId,
             }
         });
     }
     else
     {
         Log.Line($"SendActionShootUpdate should never be called on Dedicated");
     }
 }
Esempio n. 14
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. 15
0
 internal void SendActiveTerminal(WeaponComponent comp)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new TerminalMonitorPacket
             {
                 SenderId = MultiplayerId,
                 PType    = PacketType.TerminalMonitor,
                 EntityId = comp.MyCube.EntityId,
                 State    = TerminalMonitorPacket.Change.Update,
                 MId      = ++mIds[(int)PacketType.TerminalMonitor],
             });
         }
         else
         {
             Log.Line($"SendActiveTerminal no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = comp.MyCube,
             Packet = new TerminalMonitorPacket
             {
                 SenderId = MultiplayerId,
                 PType    = PacketType.TerminalMonitor,
                 EntityId = comp.MyCube.EntityId,
                 State    = TerminalMonitorPacket.Change.Update,
                 MId      = ++comp.MIds[(int)PacketType.TerminalMonitor],
             }
         });
     }
     else
     {
         Log.Line($"SendActiveTerminal should never be called on Dedicated");
     }
 }
Esempio n. 16
0
 internal void SendMouseUpdate(GridAi ai, MyEntity entity)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new InputPacket
             {
                 MId      = ++mIds[(int)PacketType.ClientMouseEvent],
                 EntityId = entity.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ClientMouseEvent,
                 Data     = UiInput.ClientInputState
             });
         }
         else
         {
             Log.Line($"SendMouseUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = entity,
             Packet = new InputPacket
             {
                 MId      = ++ai.MIds[(int)PacketType.ClientMouseEvent],
                 EntityId = entity.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ClientMouseEvent,
                 Data     = UiInput.ClientInputState
             }
         });
     }
     else
     {
         Log.Line($"SendMouseUpdate should never be called on Dedicated");
     }
 }
Esempio n. 17
0
 internal void SendSetCompBoolRequest(WeaponComponent comp, bool newBool, PacketType type)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new BoolUpdatePacket
             {
                 MId      = ++mIds[(int)type],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 PType    = type,
                 Data     = newBool,
             });
         }
         else
         {
             Log.Line($"SendSetCompBoolRequest no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = comp.MyCube,
             Packet = new BoolUpdatePacket
             {
                 MId      = ++comp.MIds[(int)type],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 PType    = type,
                 Data     = newBool,
             }
         });
     }
     else
     {
         Log.Line($"SendSetCompBoolRequest should never be called on Non-HandlesInput");
     }
 }
Esempio n. 18
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);
        }