static void OnUpdateShowerTarget(ref UpdateShowerTargetMsg msg, MyNetworkClient sender) { if (msg.HasTarget) MyMeteorShower.CurrentTarget = new BoundingSphere(msg.Center, msg.Radius); else MyMeteorShower.CurrentTarget = null; }
static void ChangeOreDetector(ref ChangeOreDetectorMsg msg, MyNetworkClient sender) { MyEntity entity; if (MyEntities.TryGetEntityById(msg.EntityId, out entity)) (entity as MyOreDetector).BroadcastUsingAntennas = msg.BroadcastUsingAntennas; }
static void ProxyExplosionSuccess(ref ProxyExplosionMsg msg, MyNetworkClient sender) { //Dont create explosion particles if message is bufferred, it is useless to create hundred explosion after scene load if (MySession.Ready) { // Create explosion MyExplosionInfo info = new MyExplosionInfo() { PlayerDamage = 0, //Damage = m_ammoProperties.Damage, Damage = 200, ExplosionType = msg.Type, ExplosionSphere = new BoundingSphere(msg.Center, msg.Radius), LifespanMiliseconds = MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadeLevel = 0, HitEntity = null, ParticleScale = msg.ParticleScale, OwnerEntity = null, Direction = Vector3.Forward, VoxelExplosionCenter = msg.VoxelCenter, ExplosionFlags = MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS, VoxelCutoutScale = 1.0f, PlaySound = true, ObjectsRemoveDelayInMiliseconds = 40 }; MyExplosions.AddExplosion(ref info, false); } }
static void OverrideGyroControlSuccess(ref OverrideGyroControlMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MyGyro; if (block != null) block.SetGyroOverride(msg.Override); }
static void ChangeGyroPowerSuccess(ref ChangeGyroPowerMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MyGyro; if (block != null) block.GyroPower = msg.GyroPower; }
static void OnCurrentAmmoCountChangedMsg(ref CurrentAmmoCountChangedMsg msg, MyNetworkClient sender) { Debug.Assert(!Sync.IsServer); var handler = AmmoCountChanged; if (handler != null) handler(msg.WeaponId, msg.AmmoCount); }
static void ChangeThrustOverrideSuccess(ref ChangeThrustOverrideMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MyThrust; if (block != null) block.SetThrustOverride(msg.ThrustOverride); }
static void StopManipulationCallback(ref StopManipulationMsg msg, MyNetworkClient sender) { MyManipulationTool manipulationTool; if (MyEntities.TryGetEntityById(msg.EntityId, out manipulationTool)) { manipulationTool.StopManipulation(); } }
static void ChangeGravityGeneratorRequest(ref ChangeGravityGeneratorMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); if (entity is MyGravityGeneratorSphere) { Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success); } }
static void OnRemoveEnvironmentItemMessage(ref RemoveEnvironmentItemMsg msg, MyNetworkClient sender) { MyEntity entity; if (MyEntities.TryGetEntityById(msg.EntityId, out entity)) { if (OnRemoveEnvironmentItem != null) OnRemoveEnvironmentItem(entity, msg.ItemInstanceId); } }
static void CapacitySyncSuccess(ref CapacitySyncMsg msg, MyNetworkClient sender) { MyCharacter owner; MyEntities.TryGetEntityById(msg.EntityId, out owner); if (owner != null) { MyBattery.Friend.OnSyncCapacitySuccess(owner.SuitBattery, msg.RemainingCapacity); } }
static void EndShootSuccess(ref EndShootMessage msg, MyNetworkClient sender) { MyUserControllableGun block = null; MyEntities.TryGetEntityById(msg.EntityId, out block); if (block != null) { block.EndShoot(); } }
static void ChangeUseConveyorSystemSucess(ref ChangeUseConveyorsMsg msg, MyNetworkClient sender) { MyEntity entity; if (MyEntities.TryGetEntityById(msg.GetEntityId(), out entity)) { if (entity as IMyInventoryOwner != null) (entity as IMyInventoryOwner).UseConveyorSystem = msg.Value; } }
static void StartManipulationCallback(ref StartManipulationMsg msg, MyNetworkClient sender) { MyManipulationTool manipulationTool; MyEntity otherEntity; if (MyEntities.TryGetEntityById(msg.EntityId, out manipulationTool) && MyEntities.TryGetEntityById(msg.OtherEntity, out otherEntity)) { manipulationTool.StartManipulation(msg.ToolState, otherEntity, msg.HitPosition, ref msg.OwnerWorldHeadMatrix, true); } }
static void ChangeDoorSuccess(ref ChangeDoorMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); MyDoor block = entity as MyDoor; if (block != null) { block.Open = msg.Open; } }
static void ChangeRadioBroadcasterRequest(ref ChangeRadioAntennaMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var broadcasterOwner = entity as IMyComponentOwner<MyDataBroadcaster>; if (broadcasterOwner != null) { Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success); } }
static void OnClearSlotRequest(ref PlayerToolbarClearSlotMsg msg, MyNetworkClient sender) { var playerId = new PlayerId(sender.SteamUserId, msg.PlayerSerialId); if (!MySession.Static.Toolbars.ContainsToolbar(playerId)) return; var toolbar = MySession.Static.Toolbars.TryGetPlayerToolbar(playerId); toolbar.SetItemAtIndex(msg.Index, null); }
static void ModMessageRecievedUnreliable(ref CustomModMsgUnreliable msg, MyNetworkClient sender) { List<Action<byte[]>> actionsList = null; if (m_registeredListeners.TryGetValue(msg.ModID, out actionsList) && actionsList != null) { foreach (var action in actionsList) { action(msg.Message); } } }
static void ChangeParamsSuccess(ref ChangeParamsMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MySpaceBall; if (block != null) { block.VirtualMass = msg.VirtualMass; block.Friction = msg.Friction; } }
private static void UseRequest(ref UseMsg msg, MyNetworkClient sender) { MyCharacter user; MyMedicalRoom medicalRoom; MyEntities.TryGetEntityById(msg.EntityId, out medicalRoom); MyEntities.TryGetEntityById(msg.UsedByEntityId, out user); if (user != null && medicalRoom != null) { Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success); } }
static void ChangeGravityGeneratorSuccess(ref ChangeGravityGeneratorMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MyGravityGeneratorSphere; if (block != null) { block.Radius = msg.Radius; block.GravityAcceleration = msg.GravityAcceleration; } }
static void DoDamage(ref DoDamageMsg msg, MyNetworkClient sender) { MyEntity ent; if(!MyEntities.TryGetEntityById(msg.DestroyableEntityId, out ent)) return; if (!(ent is IMyDestroyableObject)) { Debug.Fail("Damage can be done to destroyable only"); return; } (ent as IMyDestroyableObject).DoDamage(msg.Damage, msg.Type, false); }
static void StartManipulationCallback(ref StartManipulationMsg msg, MyNetworkClient sender) { MyManipulationTool manipulationTool; MyEntity otherEntity; if (MyEntities.TryGetEntityById(msg.EntityId, out manipulationTool) && MyEntities.TryGetEntityById(msg.OtherEntity, out otherEntity)) { manipulationTool.StartManipulation(msg.ToolState, otherEntity, msg.HitPosition, ref msg.OwnerWorldHeadMatrix, true); if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId); } } }
static void ChangeOreDetector(ref ChangeOreDetectorMsg msg, MyNetworkClient sender) { MyEntity entity; if (MyEntities.TryGetEntityById(msg.EntityId, out entity)) { (entity as MyOreDetector).BroadcastUsingAntennas = msg.BroadcastUsingAntennas; if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId); } } }
static void EndShootSuccess(ref EndShootMessage msg, MyNetworkClient sender) { MyUserControllableGun block = null; MyEntities.TryGetEntityById(msg.EntityId, out block); if (block != null) { block.EndShoot(); if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId, MyTransportMessageEnum.Success); } } }
protected override void ReadInternal(BitStream stream, MyNetworkClient sender, MyEntity controlledEntity) { Context = (MyContextKind)stream.ReadInt32(2); if (Context != MyContextKind.None) { long entityId = stream.ReadInt64(); ContextEntity = MyEntities.GetEntityByIdOrDefault(entityId); } else { ContextEntity = null; } }
static void ChangeGyroPowerSuccess(ref ChangeGyroPowerMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MyGyro; if (block != null) { block.GyroPower = msg.GyroPower; if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId, MyTransportMessageEnum.Success); } } }
private static void MissileCreatedSuccess(ref MissileShootMsg msg, MyNetworkClient sender) { MyEntity shootingEntity; MyEntities.TryGetEntityById(msg.LauncherEntityId, out shootingEntity); Debug.Assert(shootingEntity != null, "Could not find missile shooting entity"); if (shootingEntity == null) return; var shootingLauncher = shootingEntity as IMyMissileGunObject; Debug.Assert(shootingLauncher != null, "Shooting entity was not an IMyMissileGunObject"); if (shootingLauncher == null) return; shootingLauncher.ShootMissile(msg.InitialVelocity); }
static void ChangeParamsSuccess(ref ChangeParamsMsg msg, MyNetworkClient sender) { MyEntity entity; MyEntities.TryGetEntityById(msg.EntityId, out entity); var block = entity as MySpaceBall; if (block != null) { block.VirtualMass = msg.VirtualMass; block.Friction = msg.Friction; if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId, MyTransportMessageEnum.Success); } } }
static void ChangeUseConveyorSystemSucess(ref ChangeUseConveyorsMsg msg, MyNetworkClient sender) { MyEntity entity; if (MyEntities.TryGetEntityById(msg.GetEntityId(), out entity)) { if (entity as IMyInventoryOwner != null) { (entity as IMyInventoryOwner).UseConveyorSystem = msg.Value; if (Sync.IsServer) { Sync.Layer.SendMessageToAllButOne(ref msg, sender.SteamUserId, MyTransportMessageEnum.Success); } } } }
static void SyncCooldownResponse(ref SyncCooldownResponseMessage msg, MyNetworkClient sender) { int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; // msg.respawnTimes can be null, if the server sent empty list if (msg.RespawnTimes != null) { foreach (var respawnTime in msg.RespawnTimes) { var controllerId = new MyPlayer.PlayerId() { SteamId = MySteam.UserId, SerialId = respawnTime.ControllerId }; var key = new RespawnKey() { ControllerId = controllerId, RespawnShipId = respawnTime.ShipId }; m_globalRespawnTimesMs.Add(key, currentTime + respawnTime.RelativeRespawnTime, immediate: true); } } m_synced = true; }
public MyPlayer(MyNetworkClient client, PlayerId id) { m_client = client; Id = id; Controller = new MyEntityController(this); }
static void SyncCooldownRequest(ref SyncCooldownRequestMessage msg, MyNetworkClient sender) { SyncCooldownToPlayer(sender.SteamUserId); }