Пример #1
0
        public async Task Update()
        {
            if (this.m_ended)
            {
                return;
            }

            Task t1 = this.UpdateAllianceRankingList(0);
            Task t2 = this.UpdateAllianceRankingList(1);
            Task t3 = this.UpdateAvatarRankingList();
            Task t4 = this.UpdateAvatarDuelRankingList();

            await t1;
            await t2;
            await t3;
            await t4;

            if (this.EndTime < DateTime.UtcNow)
            {
                this.m_ended = true;
            }

            if (this.NextCheckTime < DateTime.UtcNow)
            {
                foreach (AllianceRankingEntry rankingEntry in this.m_allianceRankingList[0].Values)
                {
                    rankingEntry.SetPreviousOrder(rankingEntry.GetOrder());
                }
                foreach (AllianceRankingEntry rankingEntry in this.m_allianceRankingList[1].Values)
                {
                    rankingEntry.SetPreviousOrder(rankingEntry.GetOrder());
                }
                foreach (AvatarRankingEntry rankingEntry in this.m_avatarRankingList.Values)
                {
                    rankingEntry.SetPreviousOrder(rankingEntry.GetOrder());
                }
                foreach (AvatarDuelRankingEntry rankingEntry in this.m_avatarDuelRankingList.Values)
                {
                    rankingEntry.SetPreviousOrder(rankingEntry.GetOrder());
                }

                this.NextCheckTime = DateTime.UtcNow.Date.AddDays(1);
            }

            await ServerScoring.SeasonDatabase.Update(this.Id, CouchbaseDocument.Save(this));
        }
 public static void Save(Alliance alliance)
 {
     ServerStream.AllianceDatabase.InsertOrUpdate(alliance.Id, CouchbaseDocument.Save(alliance));
 }
        public static void Save(AvatarStreamEntry entry)
        {
            StreamDocument document = StreamManager.m_avatarStreams[entry.GetId()];

            ServerStream.StreamDatabase.InsertOrUpdate(document.Id, CouchbaseDocument.Save(document));
        }
 private static void Save(StreamDocument document)
 {
     ServerStream.StreamDatabase.InsertOrUpdate(document.Id, CouchbaseDocument.Save(document));
 }
        private async void UpdatePlayTimeSeconds()
        {
            IOperationResult <string> getResult = await ServerProxy.AccountDatabase.Get(this.AccountId);

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

                accountDocument.SessionCount    += 1;
                accountDocument.PlayTimeSeconds += (int)DateTime.UtcNow.Subtract(this.m_startSessionTime).TotalSeconds;

                IOperationResult <string> updateResult = await ServerProxy.AccountDatabase.Update(this.AccountId, CouchbaseDocument.Save(accountDocument), getResult.Cas);

                if (!updateResult.Success)
                {
                    this.UpdatePlayTimeSeconds();
                }
            }
        }
        private async void UnlockAccountMessageReceived(UnlockAccountMessage message)
        {
            if (this.m_connection.State == ClientConnectionState.LOGIN_FAILED)
            {
                if (ServerStatus.Status == ServerStatusType.SHUTDOWN_STARTED || ServerStatus.Status == ServerStatusType.MAINTENANCE)
                {
                    UnlockAccountFailedMessage unlockAccountFailedMessage = new UnlockAccountFailedMessage();
                    unlockAccountFailedMessage.SetErrorCode(UnlockAccountFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                    this.SendMessage(unlockAccountFailedMessage);
                    return;
                }

                IOperationResult <string> getResult = await ServerProxy.AccountDatabase.Get(message.GetAccountId());

                if (!getResult.Success)
                {
                    UnlockAccountFailedMessage unlockAccountFailedMessage = new UnlockAccountFailedMessage();
                    unlockAccountFailedMessage.SetErrorCode(UnlockAccountFailedMessage.ErrorCode.UNLOCK_UNAVAILABLE);
                    this.SendMessage(unlockAccountFailedMessage);
                    return;
                }

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

                if (accountDocument.PassToken != message.GetPassToken() || accountDocument.State != AccountState.LOCKED)
                {
                    UnlockAccountFailedMessage unlockAccountFailedMessage = new UnlockAccountFailedMessage();
                    unlockAccountFailedMessage.SetErrorCode(UnlockAccountFailedMessage.ErrorCode.UNLOCK_UNAVAILABLE);
                    this.SendMessage(unlockAccountFailedMessage);
                    return;
                }

                if (accountDocument.StateArg != null && !accountDocument.StateArg.Equals(message.GetUnlockCode(), StringComparison.InvariantCultureIgnoreCase))
                {
                    UnlockAccountFailedMessage unlockAccountFailedMessage = new UnlockAccountFailedMessage();
                    unlockAccountFailedMessage.SetErrorCode(UnlockAccountFailedMessage.ErrorCode.UNLOCK_FAILED);
                    this.SendMessage(unlockAccountFailedMessage);
                    return;
                }

                accountDocument.State    = AccountState.NORMAL;
                accountDocument.StateArg = null;

                IOperationResult <string> updateResult = await ServerProxy.AccountDatabase.Update(accountDocument.Id, CouchbaseDocument.Save(accountDocument));

                if (!updateResult.Success)
                {
                    UnlockAccountFailedMessage unlockAccountFailedMessage = new UnlockAccountFailedMessage();
                    unlockAccountFailedMessage.SetErrorCode(UnlockAccountFailedMessage.ErrorCode.UNLOCK_UNAVAILABLE);
                    this.SendMessage(unlockAccountFailedMessage);
                    return;
                }

                UnlockAccountOkMessage unlockAccountOkMessage = new UnlockAccountOkMessage();
                unlockAccountOkMessage.SetAccountId(message.GetAccountId());
                unlockAccountOkMessage.SetPassToken(message.GetPassToken());
                this.SendMessage(unlockAccountOkMessage);
            }
        }
        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();
                }
            }
        }
 public static async void SaveAccount(AccountDocument document)
 {
     await ServerAdmin.AccountDatabase.Update(document.Id, CouchbaseDocument.Save(document));
 }
 public static async void Save(GameAvatar document)
 {
     await ServerGame.GameDatabase.InsertOrUpdate(document.Id, CouchbaseDocument.Save(document));
 }
Пример #10
0
        private static ScoringSeason LoadOrCreateSeason(LogicLong id)
        {
            ScoringSeason scoringSeason = ScoringManager.LoadSeason(id);

            if (scoringSeason == null)
            {
                IOperationResult <string> result = ServerScoring.SeasonDatabase.Insert(id, CouchbaseDocument.Save(scoringSeason = new ScoringSeason(id))).Result;

                if (!result.Success)
                {
                    throw result.Exception;
                }

                scoringSeason.NextCheckTime = DateTime.UtcNow.Date.AddDays(1);
                scoringSeason.Init();
            }

            return(scoringSeason);
        }