コード例 #1
0
        public void Execute()
        {
            if (SharedConfig.IsOffline)
            {
                if (!_loginSended)
                {
                    _loginSended = true;
                    var sessionObjects             = _contexts.session.commonSession;
                    IEntityIdGenerator idGenerator = sessionObjects.EntityIdGenerator;
                    var id = idGenerator.GetNextEntityId();
                    var _offlineSelector = new OfflineSnapshotSelector(new EntityKey(id, (int)EEntityType.Player),
                                                                       _contexts.session.commonSession.GameContexts);
                    _contexts.session.clientSessionObjects.SnapshotSelectorContainer.SnapshotSelector =
                        _offlineSelector;

                    _contexts.session.clientSessionObjects.SimulationTimer.CurrentTime = 0;
                    _contexts.session.entityFactoryObject.SceneObjectEntityFactory     = new ServerSceneObjectEntityFactory(
                        _contexts.sceneObject, _contexts.player, sessionObjects.EntityIdGenerator, sessionObjects.EntityIdGenerator,
                        _contexts.session.currentTimeObject);
                    _contexts.session.entityFactoryObject.MapObjectEntityFactory =
                        new ServerMapObjectEntityFactory(_contexts.mapObject, sessionObjects.EntityIdGenerator);

                    IPlayerInfo playerInfo = TestUtility.CreateTestPlayer();
                    playerInfo.EntityId = id;
                    var player = PlayerEntityFactory.CreateNewPlayerEntity(_contexts.player,
                                                                           SingletonManager.Get <MapsDescription>().SceneParameters.PlayerBirthPosition, playerInfo, true, false);
                    _offlineSelector.Init();
                    _sessionState.FullfillExitCondition(typeof(RequestPlayerInfoSystem));
                    SingletonManager.Get <SubProgressBlackBoard>().Step();
                }
            }
            else
            {
                var channel = _contexts.session.clientSessionObjects.NetworkChannel;
                var token   = _contexts.session.clientSessionObjects.LoginToken;
                if (channel != null && channel.IsConnected)
                {
                    if (!_loginSended)
                    {
                        _loginSended = true;
                        var message = LoginMessage.Allocate();
                        message.Token      = token;
                        message.LoginStage = ELoginStage.GetPlayerInfo;
                        message.ComponentSerializerVersion = ComponentSerializerManager.HashMd5;
                        channel.SendReliable((int)EClient2ServerMessage.Login, message);

                        _logger.InfoFormat("Sending Login Message {0}", message);
                        message.ReleaseReference();
                    }

                    if (_loginSuccReceived)
                    {
                        _sessionState.FullfillExitCondition(typeof(RequestPlayerInfoSystem));
                        SingletonManager.Get <SubProgressBlackBoard>().Step();
                    }
                }
            }
        }
コード例 #2
0
        public void Handle(INetworkChannel networkChannel, int messageType, object messageBody)
        {
            if (messageType == (int)EServer2ClientMessage.PlayerInfo)
            {
                PlayerInfoMessage msg = (PlayerInfoMessage)messageBody;
                _logger.InfoFormat("recv PlayerInfo {0}", msg);
                PlayerInfo info = new PlayerInfo();
                info.ConvertFrom(msg);
                _loginSuccReceived = true;

                var playerEntity = PlayerEntityFactory.CreateNewPlayerEntity(_contexts.player, info.InitPosition, info, true, false);
                playerEntity.ReplaceNetwork(networkChannel);
                _contexts.session.commonSession.InitPosition = info.InitPosition;
            }
        }