コード例 #1
0
        public StorageHelper(string storageId, ScriptedGameContext context)
        {
            this.storageId = storageId;
            this.context   = context;
            try
            {
                var winners = NoSQLFacade.Get <NoSqlDictionarySet>("LastGameWinners", storageId);
                if (winners != null)
                {
                    lastWinners.AddRange(winners.Values);
                }

                winners = NoSQLFacade.Get <NoSqlDictionarySet>("TopGameWinners", storageId);
                if (winners != null)
                {
                    topWinners.AddRange(winners.Values);
                }
            }
            catch (Exception ex)
            {
                context.Game.LogError(ex);
            }

            isRunning = true;
            var thread = new Thread(StorageBackgroundProc)
            {
                Name = "Storage background thread for {0}".FormatString(storageId)
            };

            thread.Start();
        }
コード例 #2
0
        public RoundCounter(ScriptedGameContext context)
        {
            this.context = context;
            gameId       = context.Game.IdLong;

            currentValue = ExternalServiceFacade.GetGameCoreService().GetRoundId(gameId);
            if (currentValue == 0)
            {
                currentValue = increase();
            }

            var tmpResult = NoSQLFacade.Get <GenericNoSqlObject>("SavedGameRoundId", context.Game.IdLong);

            if (tmpResult != null)
            {
                var longValue = (long)tmpResult.Value;
                if (currentValue < longValue)
                {
                    context.Game.Log("Restoring round counter from NoSQL storage from value {0} to value {1}", currentValue, longValue);
                    currentValue      = longValue;
                    hasUnsyncedValues = true;
                    CheckSync();
                    NoSQLFacade.Delete("SavedGameRoundId", context.Game.IdLong);
                }
            }
        }
コード例 #3
0
        public void RegisterWin(UserInfo userInfo, decimal amount, object winData)
        {
            try
            {
                lock (winLock)
                {
                    IDictionary <string, object> winner;
                    if (tempWinners.ContainsKey(userInfo.sessionId) && EnvironmentHelper.CurrentTime.Subtract((DateTime)tempWinners[userInfo.sessionId]["date"]).TotalSeconds <= WINNER_AGGREGATION_PERIOD)
                    {
                        winner           = tempWinners[userInfo.sessionId];
                        winner["amount"] = ((decimal)winner["amount"]) + amount;
                    }
                    else
                    {
                        winner = tempWinners[userInfo.sessionId] = new Dictionary <string, object>
                        {
                            { "id", userInfo.UserId },
                            { "nick", userInfo.nick },
                            //{"isExternal", userInfo.isExternal},
                            { "date", EnvironmentHelper.CurrentTime },
                            { "currencyName", userInfo.locale.currency },
                            { "currency", userInfo.locale.currencySign },
                            { "amount", amount }
                        };
                    }

                    if (!lastWinners.Contains(winner))
                    {
                        lastWinners.Insert(0, winner);
                        if (lastWinners.Count > MAX_WINNERS_LENGTH)
                        {
                            lastWinners.RemoveAt(lastWinners.Count - 1);
                        }
                    }

                    NoSQLFacade.Save("LastGameWinners", storageId, new NoSqlDictionarySet(lastWinners.ToArray()));

                    var index = topWinners.Count > MAX_WINNERS_LENGTH?topWinners.FindIndex(w => ((decimal)w["amount"]) <= amount) : topWinners.Count;

                    if (index >= 0)
                    {
                        if (!topWinners.Contains(winner))
                        {
                            topWinners.Insert(index, winner);
                            if (topWinners.Count > MAX_WINNERS_LENGTH)
                            {
                                topWinners.RemoveAt(topWinners.Count - 1);
                            }
                        }

                        NoSQLFacade.Save("TopGameWinners", storageId, new NoSqlDictionarySet(topWinners.ToArray()));
                    }
                }
            }
            catch (Exception ex)
            {
                context.Game.LogError(ex);
            }
        }
コード例 #4
0
 private void SaveRoundIdToNoSql()
 {
     try
     {
         NoSQLFacade.Save("SavedGameRoundId", context.Game.IdLong, new GenericNoSqlObject(currentValue));
     }
     catch (Exception ex)
     {
         context.Game.LogError(ex);
     }
 }
コード例 #5
0
 public object getData(string id)
 {
     try
     {
         id = storageId.ConcatString("_", id);
         var result = NoSQLFacade.Get <GenericNoSqlObject>("GameDataRegistry", id);
         return(result?.Value);
     }
     catch (Exception ex)
     {
         context.Game.LogError(ex);
         return(null);
     }
 }
コード例 #6
0
        public bool saveData(string id, object data)
        {
            try
            {
                id = storageId.ConcatString("_", id);
                if (data == null)
                {
                    NoSQLFacade.Delete("GameDataRegistry", id);
                }

                var container = new GenericNoSqlObject(data);
                NoSQLFacade.Save("GameDataRegistry", id, container);
                return(true);
            }
            catch (Exception ex)
            {
                context.Game.LogError(ex);
                return(false);
            }
        }