コード例 #1
0
ファイル: MySession.cs プロジェクト: liiir1985/SpaceEngineers
        private bool TryFindSavingPlayerId(SerializableDictionaryCompat<long, MyObjectBuilder_Checkpoint.PlayerId, ulong> controlledEntities, long controlledObject, out MyPlayer.PlayerId playerId)
        {
            playerId = new MyPlayer.PlayerId();
            if (MyFakes.REUSE_OLD_PLAYER_IDENTITY == false) return false;
            if (!Sync.IsServer || Sync.Clients.Count != 1) return false;
            //Never reuse identity in dedicated server!
            if (Engine.Platform.Game.IsDedicated) return false;
            if (controlledEntities == null) return false;

            bool foundLocalPlayer = false;

            foreach (var controlledEntityIt in controlledEntities.Dictionary)
            {
                // This can used if we load an existing game and want to impersonate the saving player
                if (controlledEntityIt.Key == controlledObject)
                {
                    playerId = new MyPlayer.PlayerId(controlledEntityIt.Value.ClientId, controlledEntityIt.Value.SerialId);
                }
                if (controlledEntityIt.Value.ClientId == Sync.MyId && controlledEntityIt.Value.SerialId == 0)
                {
                    foundLocalPlayer = true;
                }
            }

            // We can impersonate the other player only if we don't have an identity set on the server already
            return foundLocalPlayer == false;
        }
コード例 #2
0
        public void LoadControlledEntities(SerializableDictionaryCompat<long, MyObjectBuilder_Checkpoint.PlayerId, ulong> controlledEntities, long controlledObject, MyPlayer.PlayerId? savingPlayerId = null)
        {
            if (controlledEntities == null) return;

            foreach (var controlledEntityIt in controlledEntities.Dictionary)
            {
                MyEntity controlledEntity;
                MyEntities.TryGetEntityById(controlledEntityIt.Key, out controlledEntity);

                var playerId = new PlayerId(controlledEntityIt.Value.ClientId, controlledEntityIt.Value.SerialId);
                if (savingPlayerId != null && playerId == savingPlayerId) playerId = new PlayerId(MySteam.UserId);

                MyPlayer player = Sync.Players.TryGetPlayerById(playerId);

                if (player != null && controlledEntity != null)
                {
                    if (!MySandboxGame.IsDedicated && controlledEntity is IMyControllableEntity)
                    {
                        player.Controller.TakeControl(controlledEntity as IMyControllableEntity);
                        if (controlledEntity is MyCharacter)
                            player.Identity.ChangeCharacter(controlledEntity as MyCharacter);
                        if (controlledEntity is MyShipController)
                            player.Identity.ChangeCharacter((controlledEntity as MyShipController).Pilot);
                        if (controlledEntity is MyLargeTurretBase)
                            player.Identity.ChangeCharacter((controlledEntity as MyLargeTurretBase).Pilot);
                    }
                    else
                    {
                        m_controlledEntities.Add(controlledEntityIt.Key, playerId, true);
                    }
                }
            }
        }
コード例 #3
0
        public SerializableDictionaryCompat<long, MyObjectBuilder_Checkpoint.PlayerId, ulong> SerializeControlledEntities()
        {
            var output = new SerializableDictionaryCompat<long,MyObjectBuilder_Checkpoint.PlayerId,ulong>();

            foreach (var entry in m_controlledEntities)
            {
                MyObjectBuilder_Checkpoint.PlayerId playerId = new MyObjectBuilder_Checkpoint.PlayerId();
                playerId.ClientId = entry.Value.SteamId;
                playerId.SerialId = entry.Value.SerialId;
                output.Dictionary.Add(entry.Key, playerId);
            }

            return output;
        }
コード例 #4
0
        public void LoadControlledEntities(SerializableDictionaryCompat<long, MyObjectBuilder_Checkpoint.PlayerId, ulong> controlledEntities, long controlledObject, MyPlayer.PlayerId? savingPlayerId = null)
        {
            if (controlledEntities == null) return;

            foreach (var controlledEntityIt in controlledEntities.Dictionary)
            {
                var playerId = new PlayerId(controlledEntityIt.Value.ClientId, controlledEntityIt.Value.SerialId);
                if (savingPlayerId != null && playerId.SteamId == savingPlayerId.Value.SteamId) playerId = new PlayerId(Sync.MyId, playerId.SerialId);

                MyPlayer player = Sync.Players.GetPlayerById(playerId);

                if (player != null)
                {
                    TryTakeControll(player, controlledEntityIt.Key);
                }
            }
        }