Exemplo n.º 1
0
 static void EntityClosedSuccess(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender)
 {
     if (!sync.Entity.MarkedForClose)
     {
         sync.Entity.Close();
     }
 }
Exemplo n.º 2
0
 static void RequestUpdateCallback(MySyncEntity sync, ref RequestPositionUpdateMsg msg, MyNetworkClient sender)
 {
     if (false && Sync.IsServer || sync.IsResponsibleForUpdate)
     {
         sync.UpdatePosition();
     }
 }
Exemplo n.º 3
0
 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);
        }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 /// <summary>
 /// For direct calls by inherited classes
 /// </summary>
 protected static bool ResponsibleForUpdate(MySyncEntity entity)
 {
     return entity.ResponsibleForUpdate(Sync.Clients.LocalClient);
 }
Exemplo n.º 9
0
 /// <summary>
 /// For direct calls by inherited classes
 /// </summary>
 protected static bool ResponsibleForUpdate(MySyncEntity entity)
 {
     return(entity.IsResponsibleForUpdate);
 }
Exemplo n.º 10
0
 /// <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);
            }
        }
Exemplo n.º 12
0
 static void EntityClosedSuccess(MySyncEntity sync, ref ClosedMsg msg, MyNetworkClient sender)
 {
     if (!sync.Entity.MarkedForClose)
         sync.Entity.Close();
 }
Exemplo n.º 13
0
 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);
        }
Exemplo n.º 15
0
 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);
            }
        }
Exemplo n.º 17
0
 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
 }