static void EntityClosedSuccess(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender) { if (!sync.Entity.MarkedForClose) { sync.Entity.Close(); } }
static void RequestUpdateCallback(MySyncEntity sync, ref RequestPositionUpdateMsg msg, MyNetworkClient sender) { if (false && Sync.IsServer || sync.IsResponsibleForUpdate) { sync.UpdatePosition(); } }
static void EntityClosedRequest(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender) { // Test right to closing entity (e.g. is creative mode?) if (!sync.Entity.MarkedForClose) { sync.Entity.Close(); // close only on server, server uses replication to propagate it to clients } }
static void UseRequestCallback(MySyncEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender) { var usableEntity = sync.Entity as IMyUsableEntity; MyEntity controlledEntity; bool entityExists = MyEntities.TryGetEntityById <MyEntity>(msg.UsedByEntityId, out controlledEntity); IMyControllableEntity controllableEntity = controlledEntity as IMyControllableEntity; Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity"); Debug.Assert(entityExists && usableEntity != null); if (entityExists && usableEntity != null && (msg.UseResult = usableEntity.CanUse(msg.UseAction, controllableEntity)) == UseActionResult.OK) { MySession.Static.SyncLayer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); UseSuccessCallback(sync as MySyncControllableEntity, ref msg, Sync.Clients.LocalClient); } else { MySession.Static.SyncLayer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure); } }
static void OnControlChangedSuccess(MySyncEntity entity, ref ControlChangedMsg msg, MyNetworkClient sender) { PlayerId id = new PlayerId(msg.ClientSteamId, msg.PlayerSerialId); MyTrace.Send(TraceWindow.Multiplayer, "OnControlChanged to entity: " + msg.EntityId, id.ToString()); Sync.Players.SetControlledEntityInternal(id, entity.Entity); }
static void OnControlChangedRequest(MySyncEntity entity, ref ControlChangedMsg msg, MyNetworkClient sender) { PlayerId id = new PlayerId(msg.ClientSteamId, msg.PlayerSerialId); MyTrace.Send(TraceWindow.Multiplayer, "OnControlChanged to entity: " + msg.EntityId, id.ToString()); Sync.Players.SetControlledEntityInternal(id, entity.Entity); Debug.Assert(sender.SteamUserId == msg.ClientSteamId); msg.ClientSteamId = sender.SteamUserId; Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); }
static void EntityClosedRequest(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender) { // Test right to closing entity (e.g. is creative mode?) EntityClosedSuccess(sync, ref msg, Sync.Clients.LocalClient); Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); }
/// <summary> /// For direct calls by inherited classes /// </summary> protected static bool ResponsibleForUpdate(MySyncEntity entity) { return entity.ResponsibleForUpdate(Sync.Clients.LocalClient); }
/// <summary> /// For direct calls by inherited classes /// </summary> protected static bool ResponsibleForUpdate(MySyncEntity entity) { return(entity.IsResponsibleForUpdate); }
/// <summary> /// For direct calls by inherited classes /// </summary> protected static bool ResponsibleForUpdate(MySyncEntity entity) { return(entity.ResponsibleForUpdate(Sync.Clients.LocalClient)); }
static void UseRequestCallback(MySyncEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender) { var usableEntity = sync.Entity as IMyUsableEntity; MyEntity controlledEntity; bool entityExists = MyEntities.TryGetEntityById<MyEntity>(msg.UsedByEntityId, out controlledEntity); IMyControllableEntity controllableEntity = controlledEntity as IMyControllableEntity; Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity"); Debug.Assert(entityExists && usableEntity != null); if (entityExists && usableEntity != null && (msg.UseResult = usableEntity.CanUse(msg.UseAction, controllableEntity)) == UseActionResult.OK) { MySession.Static.SyncLayer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); UseSuccessCallback(sync as MySyncControllableEntity, ref msg, Sync.Clients.LocalClient); } else { MySession.Static.SyncLayer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure); } }
static void EntityClosedSuccess(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender) { if (!sync.Entity.MarkedForClose) sync.Entity.Close(); }
static void EntityClosedRequest(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender) { // Test right to closing entity (e.g. is creative mode?) EntityClosedSuccess(sync, ref msg, Sync.Clients.LocalClient); Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); }
static void OnCharacterChanged(MySyncEntity entity, ref CharacterChangedMsg msg, MyNetworkClient sender) { MyCharacter characterEntity = entity.Entity as MyCharacter; MyEntity controlledEntity; if (!MyEntities.TryGetEntity(msg.ControlledEntityId, out controlledEntity)) { MySandboxGame.Log.WriteLine("Controlled entity not found"); Debug.Fail("Controlled entity not found"); } PlayerId id = new PlayerId(msg.ClientSteamId, msg.PlayerSerialId); MyPlayer player = Sync.Players.TryGetPlayerById(id); ChangePlayerCharacterInternal(player, characterEntity, controlledEntity); }
static void UpdateCallback(MySyncEntity sync, ref PositionUpdateMsg msg, MyNetworkClient sender) { sync.OnPositionUpdate(ref msg, sender); }
static void OnControlReleased(MySyncEntity entity, ref ControlReleasedMsg msg, MyNetworkClient sender) { Sync.Players.RemoveControlledEntityInternal(entity.Entity); if (Sync.IsServer) { Sync.Layer.SendMessageToAll(ref msg); } }
static void EntityClosedRequest(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender) { // Test right to closing entity (e.g. is creative mode?) if (!sync.Entity.MarkedForClose) sync.Entity.Close(); // close only on server, server uses replication to propagate it to clients }