private async void LoginMessageReceived(LoginMessage message)
        {
            if (this.m_connection.State == ClientConnectionState.DEFAULT &&
                this.CheckClientVersion(message.GetClientMajorVersion(), message.GetClientBuildVersion(), message.GetAppVersion(), message.GetResourceSha(), message.IsAndroidClient()) &&
                this.CheckServerCapabilities())
            {
                this.m_connection.Messaging.SetScramblerSeed(message.GetScramblerSeed());
                this.m_connection.SetState(ClientConnectionState.LOGIN);

                AccountDocument accountDocument;

                if (message.GetAccountId().IsZero() && message.GetPassToken() == null)
                {
                    IOperationResult <ulong> incrementSeedResult = await ServerProxy.AccountDatabase.IncrementSeed();

                    if (!incrementSeedResult.Success)
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                        loginFailedMessage.SetReason("Internal server error");
                        this.SendMessage(loginFailedMessage);
                        return;
                    }

                    accountDocument = new AccountDocument((long)incrementSeedResult.Value);
                    accountDocument.Init();
                    accountDocument.Country = this.m_connection.Location;

                    IOperationResult <string> createAccountResult = await ServerProxy.AccountDatabase.Insert((long)incrementSeedResult.Value, CouchbaseDocument.Save(accountDocument));

                    if (!createAccountResult.Success)
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                        loginFailedMessage.SetReason("Internal server error");
                        this.SendMessage(loginFailedMessage);
                        return;
                    }
                }
                else
                {
                    IOperationResult <string> getResult = await ServerProxy.AccountDatabase.Get(message.GetAccountId());

                    if (!getResult.Success)
                    {
                        if (getResult.Status == ResponseStatus.KeyNotFound)
                        {
                            LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                            loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.ACCOUNT_NOT_EXISTS);
                            this.SendMessage(loginFailedMessage);
                        }
                        else
                        {
                            LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                            loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                            loginFailedMessage.SetReason("Internal server error");
                            this.SendMessage(loginFailedMessage);
                        }

                        return;
                    }

                    accountDocument = CouchbaseDocument.Load <AccountDocument>(getResult.Value);

                    if (accountDocument.PassToken != message.GetPassToken())
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.ACCOUNT_NOT_EXISTS);
                        this.SendMessage(loginFailedMessage);
                        return;
                    }
                }

                if (accountDocument.State != AccountState.NORMAL)
                {
                    switch (accountDocument.State)
                    {
                    case AccountState.BANNED:
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.BANNED);
                        loginFailedMessage.SetReason(accountDocument.StateArg);
                        this.SendMessage(loginFailedMessage);
                        return;
                    }

                    case AccountState.LOCKED:
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.ACCOUNT_LOCKED);
                        this.SendMessage(loginFailedMessage);
                        return;
                    }
                    }
                }

                ProxySession session     = ProxySessionManager.Create(this.m_connection, accountDocument);
                RedisValue   prevSession = await ServerProxy.SessionDatabase.GetSet(accountDocument.Id, session.Id.ToString());

                if (!prevSession.IsNull)
                {
                    long prevSessionId = long.Parse(prevSession);

                    ServerMessageManager.SendMessage(new StopSessionMessage
                    {
                        Reason    = 1,
                        SessionId = prevSessionId
                    }, ServerManager.GetProxySocket(prevSessionId));
                }

                session.SetSocket(ServerCore.Socket); // Proxy

                LoginOkMessage loginOkMessage = new LoginOkMessage();

                loginOkMessage.SetAccountId(accountDocument.Id);
                loginOkMessage.SetHomeId(accountDocument.Id);
                loginOkMessage.SetPassToken(accountDocument.PassToken);
                loginOkMessage.SetFacebookId(accountDocument.FacebookId);
                loginOkMessage.SetGamecenterId(accountDocument.GamecenterId);

                loginOkMessage.SetServerMajorVersion(LogicVersion.MAJOR_VERSION);
                loginOkMessage.SetServerBuildVersion(LogicVersion.BUILD_VERSION);
                loginOkMessage.SetContentVersion(ResourceManager.GetContentVersion());
                loginOkMessage.SetServerEnvironment(EnvironmentSettings.Environment);
                loginOkMessage.SetSessionCount(accountDocument.SessionCount);
                loginOkMessage.SetPlayTimeSeconds(accountDocument.PlayTimeSeconds);
                loginOkMessage.SetAccountCreatedDate(accountDocument.CreateTime.ToString());
                loginOkMessage.SetStartupCooldownSeconds(ServerProxy.GetStartupCooldownSeconds());
                loginOkMessage.SetRegion(this.m_connection.Location);

                loginOkMessage.SetFacebookAppId(ResourceSettings.FacebookAppId);
                loginOkMessage.SetGoogleServiceId(ResourceSettings.GoogleServiceId);

                loginOkMessage.SetContentUrlList(ResourceSettings.ContentUrlList);
                loginOkMessage.SetChronosContentUrlList(ResourceSettings.ChronosContentUrlList);

                this.SendMessage(loginOkMessage);
                this.m_connection.SetSession(session);
                this.m_connection.SetState(ClientConnectionState.LOGGED);

                if (this.m_connection.State == ClientConnectionState.LOGGED)
                {
                    accountDocument.SessionCount   += 1;
                    accountDocument.LastSessionTime = TimeUtil.GetTimestamp();

                    ServerRequestManager.Create(new BindServerSocketRequestMessage
                    {
                        ServerType = 9,
                        ServerId   = ServerManager.GetDocumentSocket(9, accountDocument.Id).ServerId,
                        SessionId  = session.Id
                    }, ServerCore.Socket, 5).OnComplete = this.OnGameServerBound;

                    await ServerProxy.AccountDatabase.Update(accountDocument.Id, CouchbaseDocument.Save(accountDocument));
                }
                else
                {
                    this.m_connection.DestructSession();
                }
            }
        }