Exemple #1
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);
            }
        }
Exemple #2
0
 private void SaveRoundIdToNoSql()
 {
     try
     {
         NoSQLFacade.Save("SavedGameRoundId", context.Game.IdLong, new GenericNoSqlObject(currentValue));
     }
     catch (Exception ex)
     {
         context.Game.LogError(ex);
     }
 }
Exemple #3
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);
            }
        }