Example #1
0
 internal void SendOverRidesClientComp(CoreComponent 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");
     }
 }
Example #2
0
        internal void SendFixedGunHitEvent(MyCubeBlock firingCube, MyEntity hitEnt, Vector3 origin, Vector3 velocity, Vector3 up, int muzzleId, int systemId, int ammoIndex, float maxTrajectory)
        {
            if (firingCube == null)
            {
                return;
            }

            var comp = firingCube.Components.Get <CoreComponent>();

            int weaponId;

            if (comp.Ai?.MyGrid != null && comp.Platform.State == CorePlatform.PlatformState.Ready && comp.Platform.Structure.HashToId.TryGetValue(systemId, out weaponId))
            {
                PacketsToServer.Add(new FixedWeaponHitPacket
                {
                    EntityId      = firingCube.EntityId,
                    SenderId      = MultiplayerId,
                    PType         = PacketType.FixedWeaponHitEvent,
                    HitEnt        = hitEnt.EntityId,
                    HitOffset     = hitEnt.PositionComp.WorldMatrixRef.Translation - origin,
                    Up            = up,
                    MuzzleId      = muzzleId,
                    WeaponId      = weaponId,
                    Velocity      = velocity,
                    AmmoIndex     = ammoIndex,
                    MaxTrajectory = maxTrajectory,
                });
            }
        }
Example #3
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");
     }
 }
Example #4
0
 internal void SendTrackReticleUpdate(CoreComponent 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);
     }
 }
Example #5
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");
     }
 }
Example #6
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
             {
                 MId      = ++ai.MIds[(int)PacketType.ReleaseActiveUpdate],
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReleaseActiveUpdate
             }
         });
     }
 }
Example #7
0
        internal void SendMouseUpdate(MyEntity entity)
        {
            if (!HandlesInput)
            {
                return;
            }

            if (IsClient)
            {
                PacketsToServer.Add(new InputPacket
                {
                    EntityId = entity.EntityId,
                    SenderId = MultiplayerId,
                    PType    = PacketType.ClientMouseEvent,
                    Data     = UiInput.ClientInputState
                });
            }
            else
            {
                PacketsToClient.Add(new PacketInfo
                {
                    Entity = entity,
                    Packet = new InputPacket
                    {
                        EntityId = entity.EntityId,
                        SenderId = MultiplayerId,
                        PType    = PacketType.ClientMouseEvent,
                        Data     = UiInput.ClientInputState
                    }
                });
            }
        }
Example #8
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");
     }
 }
Example #9
0
 internal void SendFakeTargetUpdate(GridAi ai, Vector3 hitPos)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new FakeTargetPacket
         {
             EntityId = ai.MyGrid.EntityId,
             SenderId = ai.Session.MultiplayerId,
             PType    = PacketType.FakeTargetUpdate,
             Data     = hitPos,
         });
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new FakeTargetPacket
             {
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = ai.Session.MultiplayerId,
                 PType    = PacketType.FakeTargetUpdate,
                 Data     = hitPos,
             }
         });
     }
 }
Example #10
0
        internal void SendCompSettingUpdate(WeaponComponent comp)
        {
            comp.SyncIds.MIds[(int)PacketType.CompSettingsUpdate]++;

            if (IsClient)// client, send settings to server
            {
                PacketsToServer.Add(new SettingPacket
                {
                    EntityId = comp.MyCube.EntityId,
                    PType    = PacketType.CompSettingsUpdate,
                    SenderId = MultiplayerId,
                    Data     = comp.Set.Value,
                    MId      = comp.SyncIds.MIds[(int)PacketType.CompSettingsUpdate]
                });
            }
            else if (HandlesInput)
            {
                PacketsToClient.Add(new PacketInfo
                {
                    Entity = comp.MyCube,
                    Packet = new SettingPacket
                    {
                        EntityId = comp.MyCube.EntityId,
                        SenderId = 0,
                        PType    = PacketType.CompSettingsUpdate,
                        Data     = comp.Set.Value,
                        MId      = comp.SyncIds.MIds[(int)PacketType.CompSettingsUpdate]
                    }
                });
            }
        }
Example #11
0
        internal void SendFixedGunHitEvent(MyCubeBlock firingCube, MyEntity hitEnt, Vector3 hitPos, Vector3 hitDirection, Vector3 up, int muzzleId, int systemId)
        {
            if (firingCube == null)
            {
                return;
            }

            var comp = firingCube.Components.Get <WeaponComponent>();

            int weaponId;

            if (comp != null && comp.Platform.State == MyWeaponPlatform.PlatformState.Ready && comp.Platform.Structure.HashToId.TryGetValue(systemId, out weaponId))
            {
                PacketsToServer.Add(new FixedWeaponHitPacket
                {
                    EntityId     = firingCube.EntityId,
                    SenderId     = MultiplayerId,
                    PType        = PacketType.FixedWeaponHitEvent,
                    HitEnt       = hitEnt.EntityId,
                    HitDirection = hitDirection,
                    HitOffset    = hitEnt.PositionComp.WorldMatrixRef.Translation - hitPos,
                    Up           = up,
                    MuzzleId     = muzzleId,
                    WeaponId     = weaponId
                });
            }
        }
Example #12
0
 internal void SendControlingPlayer(WeaponComponent comp)
 {
     comp.SyncIds.MIds[(int)PacketType.PlayerControlUpdate]++;
     if (IsClient)
     {
         PacketsToServer.Add(new ControllingPlayerPacket
         {
             EntityId = comp.MyCube.EntityId,
             SenderId = MultiplayerId,
             MId      = comp.SyncIds.MIds[(int)PacketType.PlayerControlUpdate],
             PType    = PacketType.PlayerControlUpdate,
             Data     = comp.State.Value.CurrentPlayerControl,
         });
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = comp.MyCube,
             Packet = new ControllingPlayerPacket
             {
                 EntityId = comp.MyCube.EntityId,
                 SenderId = 0,
                 MId      = comp.SyncIds.MIds[(int)PacketType.PlayerControlUpdate],
                 PType    = PacketType.PlayerControlUpdate,
                 Data     = comp.State.Value.CurrentPlayerControl,
             }
         });
     }
 }
Example #13
0
 internal void SendCycleAmmoNetworkUpdate(Weapon weapon, int ammoId)
 {
     weapon.Comp.SyncIds.MIds[(int)PacketType.CycleAmmo]++;
     if (IsClient)
     {
         PacketsToServer.Add(new CycleAmmoPacket
         {
             EntityId = weapon.Comp.MyCube.EntityId,
             SenderId = MultiplayerId,
             PType    = PacketType.CycleAmmo,
             AmmoId   = ammoId,
             MId      = weapon.Comp.SyncIds.MIds[(int)PacketType.CycleAmmo],
             WeaponId = weapon.WeaponId
         });
     }
     else
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = weapon.Comp.MyCube,
             Packet = new CycleAmmoPacket
             {
                 EntityId = weapon.Comp.MyCube.EntityId,
                 SenderId = 0,
                 PType    = PacketType.CycleAmmo,
                 AmmoId   = ammoId,
                 MId      = weapon.Comp.SyncIds.MIds[(int)PacketType.CycleAmmo],
                 WeaponId = weapon.WeaponId
             }
         });
     }
 }
Example #14
0
 internal void SendOverRidesUpdate(GridAi ai, string groupName, GroupOverrides overRides)
 {
     if (MpActive)
     {
         ai.UiMId++;
         if (IsClient)
         {
             PacketsToServer.Add(new OverRidesPacket
             {
                 EntityId  = ai.MyGrid.EntityId,
                 SenderId  = MultiplayerId,
                 MId       = ai.UiMId,
                 GroupName = groupName,
                 PType     = PacketType.OverRidesUpdate,
                 Data      = overRides,
             });
         }
         else if (IsServer)
         {
             PacketsToClient.Add(new PacketInfo
             {
                 Entity = ai.MyGrid,
                 Packet = new OverRidesPacket
                 {
                     EntityId  = ai.MyGrid.EntityId,
                     SenderId  = 0,
                     MId       = ai.UiMId,
                     GroupName = groupName,
                     PType     = PacketType.OverRidesUpdate,
                     Data      = overRides,
                 }
             });
         }
     }
 }
Example #15
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");
     }
 }
Example #16
0
 internal void SendActiveControlUpdate(MyCubeBlock controlBlock, bool active)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new BoolUpdatePacket
         {
             EntityId = controlBlock.EntityId,
             SenderId = MultiplayerId,
             PType    = PacketType.ActiveControlUpdate,
             Data     = active
         });
     }
     else
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = controlBlock,
             Packet = new BoolUpdatePacket
             {
                 EntityId = controlBlock.EntityId,
                 SenderId = 0,
                 PType    = PacketType.ActiveControlUpdate,
                 Data     = active
             }
         });
     }
 }
Example #17
0
 internal void SendReleaseActiveUpdate(GridAi ai)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new FocusPacket
         {
             EntityId = ai.MyGrid.EntityId,
             SenderId = MultiplayerId,
             PType    = PacketType.ReleaseActiveUpdate
         });
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new FocusPacket
             {
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReleaseActiveUpdate
             }
         });
     }
 }
Example #18
0
 internal void SendNextActiveUpdate(GridAi ai, bool addSecondary)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new FocusPacket
         {
             EntityId     = ai.MyGrid.EntityId,
             SenderId     = MultiplayerId,
             PType        = PacketType.NextActiveUpdate,
             AddSecondary = addSecondary
         });
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new FocusPacket
             {
                 EntityId     = ai.MyGrid.EntityId,
                 SenderId     = MultiplayerId,
                 PType        = PacketType.NextActiveUpdate,
                 AddSecondary = addSecondary
             }
         });
     }
 }
Example #19
0
 internal void SendReassignTargetUpdate(GridAi ai, long targetId, int focusId)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new FocusPacket
         {
             EntityId = ai.MyGrid.EntityId,
             SenderId = MultiplayerId,
             PType    = PacketType.ReassignTargetUpdate,
             TargetId = targetId,
             FocusId  = focusId
         });
     }
     else if (HandlesInput)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new FocusPacket
             {
                 EntityId = ai.MyGrid.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReassignTargetUpdate,
                 TargetId = targetId,
                 FocusId  = focusId
             }
         });
     }
 }
Example #20
0
 internal void SendTrackReticleUpdate(WeaponComponent comp)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new BoolUpdatePacket
         {
             EntityId = comp.MyCube.EntityId,
             SenderId = MultiplayerId,
             PType    = PacketType.ReticleUpdate,
             Data     = comp.TrackReticle
         });
     }
     else if (IsServer)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = comp.MyCube,
             Packet = new BoolUpdatePacket
             {
                 EntityId = comp.MyCube.EntityId,
                 PType    = PacketType.ReticleUpdate,
                 Data     = comp.TrackReticle
             }
         });
     }
 }
Example #21
0
 internal void SendOverRidesUpdate(WeaponComponent comp, GroupOverrides overRides)
 {
     if (MpActive)
     {
         comp.SyncIds.MIds[(int)PacketType.OverRidesUpdate]++;
         if (IsClient)
         {
             PacketsToServer.Add(new OverRidesPacket
             {
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 MId      = comp.SyncIds.MIds[(int)PacketType.OverRidesUpdate],
                 PType    = PacketType.OverRidesUpdate,
                 Data     = comp.Set.Value.Overrides,
             });
         }
         else
         {
             PacketsToClient.Add(new PacketInfo
             {
                 Entity = comp.MyCube,
                 Packet = new OverRidesPacket
                 {
                     EntityId = comp.MyCube.EntityId,
                     SenderId = 0,
                     MId      = comp.SyncIds.MIds[(int)PacketType.OverRidesUpdate],
                     PType    = PacketType.OverRidesUpdate,
                     Data     = comp.Set.Value.Overrides,
                 }
             });
         }
     }
 }
Example #22
0
 internal void SendUpdateRequest(long entityId, PacketType ptype)
 {
     PacketsToServer.Add(new Packet
     {
         EntityId = entityId,
         SenderId = MultiplayerId,
         PType    = ptype
     });
 }
 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");
     }
 }
 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");
     }
 }
 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");
     }
 }
 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");
     }
 }
Example #27
0
 internal void SendGroupUpdate(GridAi ai)
 {
     if (IsClient)
     {
         PacketsToServer.Add(new Packet
         {
             EntityId = ai.MyGrid.EntityId,
             SenderId = MultiplayerId,
             PType    = PacketType.RescanGroupRequest,
         });
     }
     else if (IsServer)
     {
         PacketsToClient.Add(new PacketInfo
         {
             Entity = ai.MyGrid,
             Packet = new Packet
             {
                 EntityId = ai.MyGrid.EntityId,
                 PType    = PacketType.RescanGroupRequest,
             }
         });
     }
 }