Exemple #1
0
        public void GenerateToken()
        {
            ITokenValidator tokenValidator = new TokenValidator();
            SessionManager  manager        = new SessionManager(
                new EncryptionManager(
                    new Codenesium.Encryption.BCryptor(),
                    new Codenesium.Encryption.JWTHelper(),
                    new Codenesium.Encryption.HashSHA256(),
                    new Codenesium.Encryption.SaltBCrypt()
                    ),
                tokenValidator,
                "W1hRoFcbrm8BmqwCXPmeuE9C021VDc46",
                60 * 60 * 24 * 7,
                "fermatafish"
                );
            string result = manager.PackagePayload(manager.GenerateSessionPayload(DateTime.UtcNow.ToCompleteDateString(), DateTime.UtcNow.AddDays(7).ToCompleteDateString(), "*****@*****.**", 1, "fermatafish"));

            System.Diagnostics.Debug.Print(result);

            SessionPayload requestSessionPayload = new SessionPayload();
            string         unpackagedToken       = manager.UnpackageToken(result);

            requestSessionPayload.LoadJson(unpackagedToken);

            Assert.IsTrue(tokenValidator.IsTokenActive(requestSessionPayload.CreatedDate.ToDateTime(), 60 * 60 * 24 * 7));
        }
Exemple #2
0
 public CashTransporter(SessionPayload session, long domainId, VendorID vendor)
 {
     _vendorApi   = new VendorApiClient(vendor.ToString());
     _domainId    = domainId;
     _userSession = session;
     _vendor      = vendor;
 }
Exemple #3
0
        public async Task <User> SessionInfoToUser(SessionPayload sessionPayload)
        {
            var users = await _userLogic.GetAll();

            var user = users.FirstOrDefault(x => x.Username == sessionPayload.Username && x.Password == sessionPayload.PasswordHash);

            return(user);
        }
Exemple #4
0
        /// <summary>
        /// Checks whether user is authenticated or not
        /// </summary>
        /// <param name="sessionPayload"></param>
        /// <returns></returns>
        public async Task <bool> IsAuthenticated(SessionPayload sessionPayload)
        {
            // Nothing needs to be done
            if (sessionPayload == null)
            {
                return(false);
            }

            var(username, passwordHash) = (sessionPayload.Username, sessionPayload.PasswordHash);

            return(await Task.FromResult(_authenticatedUsers.Any(x => x.Key == username && x.Value == passwordHash)));
        }
Exemple #5
0
        public JsonResult TransferMoney(CashTransporterRequest request)
        {
            CashTransporterResponse response = new CashTransporterResponse();

            if (string.IsNullOrWhiteSpace(request.Sid) || string.IsNullOrEmpty(request.VendorName) ||
                request.DomainId == 0)
            {
                response.Success      = false;
                response.ErrorMessage = string.Format("Parameter requied. Received parameters: Sid: {0}, DomainId: {1}, VendorName: {2}, Language: {3}",
                                                      request.Sid, request.DomainId, request.VendorName, request.Language);

                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            SessionPayload session = _agentClient.GetSessionByGuid(request.Sid);

            try
            {
                if (session != null && session.IsAuthenticated == true && session.DomainID == request.DomainId)
                {
                    VendorID vendor = (VendorID)Enum.Parse(typeof(VendorID), request.VendorName, true);

                    CashTransporter cashTransporter = new CashTransporter(session, request.DomainId, vendor);

                    string language = VendorLanguageSelector.GetLanguage(vendor, request.Language);
                    cashTransporter.TransferMoney(language);
                    response.Success = true;
                }
                else
                {
                    response.ErrorMessage = "Session expired";
                }
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
            }


            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Exemple #6
0
        /// <summary>
        /// Log out the user
        /// </summary>
        /// <param name="sessionPayload"></param>
        public async Task <bool> Logout(SessionPayload sessionPayload)
        {
            // Nothing needs to be done
            if (sessionPayload == null)
            {
                return(false);
            }

            var(username, _) = (sessionPayload.Username, sessionPayload.PasswordHash);

            // Authenticate the user
            if (_authenticatedUsers.ContainsKey(username))
            {
                _authenticatedUsers.Remove(username, out _);

                // Out the flag
                return(true);
            }

            return(false);
        }
        public ActionResult MicrogamingNanoXpro(long domainID, string id, string _sid)
        {
            List <ceDomainConfigEx> domains = DomainManager.GetDomains();
            ceDomainConfigEx        domain  = domains.FirstOrDefault(d => d.DomainID == domainID);

            if (domain == null)
            {
                this.ViewData["ErrorMessage"] = "Invalid Url Parameter(s)!";
                return(this.View("Error"));
            }

            Dictionary <string, ceCasinoGameBaseEx> games = CacheManager.GetGameDictionary(domainID);
            ceCasinoGameBaseEx game;

            if (!games.TryGetValue(id, out game))
            {
                this.ViewData["ErrorMessage"] = "Error, cannot find the game!";
                return(this.View("Error"));
            }

            SessionPayload session = null;

            if (!string.IsNullOrWhiteSpace(_sid))
            {
                using (DbManager db = new DbManager())
                {
                    session = _agentClient.GetSessionByGuid(_sid);
                    if (session == null ||
                        session.IsAuthenticated != true ||
                        session.DomainID != domainID)
                    {
                        this.ViewData["ErrorMessage"] = "Error, invalid session id!";
                        return(this.View("Error"));
                    }
                }
            }


            MicrogamingNanoGameSessionInfo info = null;

            if (session != null)
            {
                string cacheKey = string.Format("MG_NANO_GAME_SESSION_{0}_{1}", domainID, session.Guid);
                info = HttpRuntime.Cache[cacheKey] as MicrogamingNanoGameSessionInfo;

                this.ViewData["HandlerUrl"] = this.Url.Action("SaveMicrogamingNanoGameSession"
                                                              , new { @domainID = domainID, @id = id, @_sid = session.Guid }
                                                              );
            }

            this.ViewData["UserSession"] = session;
            this.ViewData["Domain"]      = domain;
            this.ViewData["MicrogamingNanoGameSessionInfo"] = info;
            this.ViewData["UserSession"]      = session;
            this.ViewData["VendorID"]         = game.VendorID;
            this.ViewData["GameID"]           = game.GameID;
            this.ViewData["CasinoBaseGameID"] = game.ID;
            this.ViewData["CasinoGameID"]     = game.CasinoGameId;
            this.ViewData["GameCode"]         = game.GameCode;

            Dictionary <int, ceCasinoVendor> vendors = CacheManager.GetVendorDictionary(domain.DomainID);

            this.ViewData["UseGmGaming"] = (vendors.ContainsKey((int)game.VendorID)) &&
                                           vendors[(int)game.VendorID].EnableGmGamingAPI;
            this.ViewData["EnableLogging"] = (vendors.ContainsKey((int)game.VendorID)) &&
                                             vendors[(int)game.VendorID].EnableLogging;
            return(this.View("MicrogamingNanoXpro", game));
        }
        // GET: /Loader/
        public ActionResult Start(long domainID, string id, string _sid, string _sid64, string language, bool?funMode, string tableID)
        {
            string userAgentInfo = Request.GetRealUserAddress() + Request.UserAgent;

            if (!string.IsNullOrEmpty(_sid))
            {
                string sid64 = Encrypt(_sid, userAgentInfo, true);
                sid64 = Regex.Replace(sid64, @"(\+|\/|\=)", (Match match) =>
                {
                    switch (match.Value)
                    {
                    case "+": return(".");

                    case "/": return("_");

                    case "=": return("-");

                    default: throw new NotSupportedException();
                    }
                }, RegexOptions.Compiled);

                RouteValueDictionary routeParams = new RouteValueDictionary();
                foreach (string key in Request.QueryString.Keys)
                {
                    routeParams.Add(key, Request.QueryString[key]);
                }

                routeParams["_sid64"] = sid64;
                routeParams["_sid"]   = "";

                return(RedirectToAction("Start", routeParams));
            }
            else
            {
                if (!string.IsNullOrEmpty(_sid64))
                {
                    _sid64 = Regex.Replace(_sid64, @"(\.|_|\-)", (Match match) =>
                    {
                        switch (match.Value)
                        {
                        case ".": return("+");

                        case "_": return("/");

                        case "-": return("=");

                        default: throw new NotSupportedException();
                        }
                    }, RegexOptions.Compiled);

                    _sid = Decrypt(_sid64, userAgentInfo, true);
                }
            }

            funMode = CheckFunMode(funMode, _sid);

            //------- Domain Validation
            List <ceDomainConfigEx> domains = DomainManager.GetDomains();
            ceDomainConfigEx        domain  = domains.FirstOrDefault(d => d.DomainID == domainID);

            if (domain == null)
            {
                this.ViewData["ErrorMessage"] = "Invalid Url Parameter(s)!";
                return(this.View("Error"));
            }
            DomainManager.CurrentDomainID = domainID;

            //------- Game Validation
            Dictionary <string, ceCasinoGameBaseEx> games = CacheManager.GetGameDictionary(domain.DomainID);
            ceCasinoGameBaseEx game;

            if (!games.TryGetValue(id, out game))
            {
                throw new CeException("Game [{0}] is not available!", id);
            }
            if (!GlobalConstant.AllVendors.Contains(game.VendorID))
            {
                throw new Exception("Unsupported VendorID!");
            }


            //------- Country and IP restrictions Validation
            string vendorRestrictedCountries = GetVendorRestrictedCountries(domainID, game.VendorID);

            IPLocation ipLocation = IPLocation.GetByIP(Request.GetRealUserAddress());

            if (ipLocation.Found)
            {
                if (!string.IsNullOrWhiteSpace(game.RestrictedTerritories))
                {
                    if (game.RestrictedTerritories.IndexOf(ipLocation.CountryCode, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        Logger.FailureAudit(string.Format("Accessing from {0}({1}) to game [{2}] is denied by game rules [{3}]."
                                                          , Request.GetRealUserAddress()
                                                          , ipLocation.CountryCode
                                                          , game.GameName
                                                          , game.RestrictedTerritories
                                                          )
                                            );
                        return(this.View("Error_RestrictedCountries"));
                    }
                }
                if (!string.IsNullOrWhiteSpace(vendorRestrictedCountries))
                {
                    if (vendorRestrictedCountries.IndexOf(ipLocation.CountryCode, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        Logger.FailureAudit(string.Format("Accessing from {0}({1}) to game [{2}] is denied by vendor rules [{3}]."
                                                          , Request.GetRealUserAddress()
                                                          , ipLocation.CountryCode
                                                          , game.GameName
                                                          , vendorRestrictedCountries
                                                          )
                                            );
                        return(this.View("Error_RestrictedCountries"));
                    }
                }
            }

            SessionPayload session = null;

            if (!string.IsNullOrWhiteSpace(_sid))
            {
                {
                    session = _agentClient.GetSessionByGuid(_sid);
                    if (session == null ||
                        session.IsAuthenticated != true ||
                        session.DomainID != domain.DomainID)
                    {
                        return(this.View("Error_InvalidSession"));
                    }
                }

                if (!funMode.Value && session != null && session.IsEmailVerified != true)
                {
                    return(this.View("Error_Inactive"));
                }

                if (session != null && session.Roles != null)
                {
                    bool isExist = session.Roles.FirstOrDefault(r => string.Equals(r, "Withdraw only", StringComparison.InvariantCultureIgnoreCase)) != null;
                    if (isExist)
                    {
                        return(this.View("Error_WithdrawOnly"));
                    }
                }

                // verify the restricted countries
                if (!string.IsNullOrWhiteSpace(game.RestrictedTerritories) && !string.IsNullOrEmpty(session.UserCountryCode))
                {
                    if (game.RestrictedTerritories.IndexOf(session.UserCountryCode, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        Logger.FailureAudit(string.Format("Accessing from {0}({1} - {2}) to game [{3}] is denied by game rules [{4}]."
                                                          , session.UserID
                                                          , session.Username
                                                          , session.UserCountryCode
                                                          , game.GameName
                                                          , game.RestrictedTerritories
                                                          )
                                            );
                        return(this.View("Error_RestrictedCountries"));
                    }
                }
                if (!string.IsNullOrWhiteSpace(vendorRestrictedCountries) && !string.IsNullOrEmpty(session.UserCountryCode))
                {
                    if (vendorRestrictedCountries.IndexOf(session.UserCountryCode, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        Logger.FailureAudit(string.Format("Accessing from {0}({1} - {2}) to game [{3}] is denied by vendor rules [{4}]."
                                                          , session.UserID
                                                          , session.Username
                                                          , session.UserCountryCode
                                                          , game.GameName
                                                          , vendorRestrictedCountries
                                                          )
                                            );
                        return(this.View("Error_RestrictedCountries"));
                    }
                }
                if (game.AgeLimit)
                {
                    if (session.BirthDate.AddYears(21) > DateTime.UtcNow.Date)
                    {
                        return(this.View("Error_AgeLimit"));
                    }
                }
            }
            else if (!game.FunMode && !game.AnonymousFunMode)
            {
                return(this.View("Error_InvalidSession"));
            }


            //------- If All OK start game
            this.ViewData["UserSession"]      = session;
            this.ViewData["Domain"]           = domain;
            this.ViewData["VendorID"]         = game.VendorID;
            this.ViewData["GameID"]           = game.GameID;
            this.ViewData["CasinoBaseGameID"] = game.ID;
            this.ViewData["Slug"]             = game.Slug;
            this.ViewData["CasinoGameID"]     = game.CasinoGameId;
            this.ViewData["GameCode"]         = game.GameCode;
            this.ViewData["Language"]         = language;
            this.ViewData["FunMode"]          = funMode.Value;
            this.ViewData["TableID"]          = tableID;


            Dictionary <int, ceCasinoVendor> vendors = CacheManager.GetVendorDictionary(domain.DomainID);

            this.ViewData["UseGmGaming"] = (vendors.ContainsKey((int)game.VendorID)) &&
                                           vendors[(int)game.VendorID].EnableGmGamingAPI;
            this.ViewData["EnableLogging"] = (vendors.ContainsKey((int)game.VendorID)) &&
                                             vendors[(int)game.VendorID].EnableLogging;

            switch (game.VendorID)
            {
            case VendorID.NetEnt:
            {
                if (funMode.Value)
                {
                    this.ViewData["_sid64"] = null;
                }
                else
                {
                    this.ViewData["_sid64"] = _sid64;
                }

                if (game.GameCategories.IndexOf(",LIVEDEALER,", StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    return(View("NetEntLiveDealer", game));
                }

                bool inclusionEnabled = ConfigurationManager.AppSettings["Netent.Launch.Inclusion.Enabled"].SafeParseToBool(false);
                if (inclusionEnabled)
                {
                    return(View("NetEnt_Inclusion", game));
                }
                else
                {
                    if (game.GameID.EndsWith("_mobile_html_sw", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(View("NetEntMobile", game));
                    }

                    return(View("NetEnt", game));
                }
            }

            case VendorID.Microgaming:
            {
                if (game.GameID.StartsWith("Nano", StringComparison.InvariantCultureIgnoreCase) ||
                    game.GameID.StartsWith("Mini", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(View("MicrogamingNano", game));
                }
                if (game.GameCode.StartsWith("MGS_LG-", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(View("MicrogamingLiveDealer", game));
                }
                return(View("Microgaming", game));
            }

            case VendorID.GreenTube:
            {
                if (domain.Name.Equals("energycasino", StringComparison.OrdinalIgnoreCase) ||
                    Request.Url.Host.EndsWith("energycasino.com", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(View("GreenTube_EnergyCasino", game));
                }
                else
                {
                    return(View("GreenTube", game));
                }
            }

            case VendorID.ISoftBet:
                if (game.GameID.EndsWith("_html", StringComparison.InvariantCultureIgnoreCase) ||
                    game.GameID.EndsWith("_html5", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(View("ISoftBetNew", game));
                }

                return(View("ISoftBetNew", game));

            default:
                return(View(game.VendorID.ToString(), game));
            }
        }
Exemple #9
0
        public ActionResult GetFrequentPlayerPoints(string apiUsername, string apiPassword, string _sid)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(apiUsername))
                {
                    return(WrapResponse(ResultCode.Error_InvalidParameter, "OperatorKey cannot be empty!"));
                }

                if (string.IsNullOrWhiteSpace(apiPassword))
                {
                    return(WrapResponse(ResultCode.Error_InvalidParameter, "API password cannot be empty!"));
                }

                if (string.IsNullOrWhiteSpace(_sid))
                {
                    return(WrapResponse(ResultCode.Error_InvalidParameter, "Session ID cannot be empty!"));
                }

                var domains = DomainManager.GetApiUsername_DomainDictionary();
                ceDomainConfigEx domain;
                if (!domains.TryGetValue(apiUsername.Trim(), out domain))
                {
                    return(WrapResponse(ResultCode.Error_InvalidParameter, "Invalid OperatorKey!"));
                }

                if (!string.Equals(domain.ApiPassword, apiPassword.MD5Hash(), StringComparison.InvariantCulture))
                {
                    return(WrapResponse(ResultCode.Error_InvalidParameter, "API password is incorrect!"));
                }

                if (!IsWhitelistedIPAddress(domain, Request.GetRealUserAddress()))
                {
                    return(WrapResponse(ResultCode.Error_BlockedIPAddress, string.Format("IP Address [{0}] is denied!", Request.GetRealUserAddress())));
                }

                SessionPayload sessionPayload = _agentClient.GetSessionByGuid(_sid);

                if (sessionPayload == null || sessionPayload.IsAuthenticated != true)
                {
                    return(WrapResponse(ResultCode.Error_InvalidSession, "Session ID is not available!"));
                }


                ////////////////////////////////////////////////////////////////////////
                using (GamMatrixClient client = new GamMatrixClient())
                {
                    CasinoFPPGetClaimDetailsRequest request = new CasinoFPPGetClaimDetailsRequest()
                    {
                        UserID = sessionPayload.UserID,
                    };

                    request = client.SingleRequest <CasinoFPPGetClaimDetailsRequest>(sessionPayload.DomainID, request);

                    StringBuilder data = new StringBuilder();
                    data.AppendLine("<getFrequentPlayerPoints>");

                    if (request != null && request.ClaimRec != null)
                    {
                        data.AppendFormat(CultureInfo.InvariantCulture, "\t<points>{0:f2}</points>\n", Math.Truncate(request.ClaimRec.Points * 100) / 100.00M);
                        data.AppendFormat(CultureInfo.InvariantCulture, "\t<convertionMinClaimPoints>{0:f0}</convertionMinClaimPoints>\n", request.ClaimRec.CfgConvertionMinClaimPoints);
                        data.AppendFormat(CultureInfo.InvariantCulture, "\t<convertionPoints>{0}</convertionPoints>\n", request.ClaimRec.CfgConvertionPoints);
                        data.AppendFormat(CultureInfo.InvariantCulture, "\t<convertionCurrency>{0}</convertionCurrency>\n", request.ClaimRec.CfgConvertionCurrency.SafeHtmlEncode());
                        data.AppendFormat(CultureInfo.InvariantCulture, "\t<convertionAmount>{0}</convertionAmount>\n", request.ClaimRec.CfgConvertionAmount);
                        data.AppendFormat(CultureInfo.InvariantCulture, "\t<convertionType>{0}</convertionType>\n", request.ClaimRec.CfgConvertionType);
                    }
                    data.AppendLine("</getFrequentPlayerPoints>");
                    return(WrapResponse(ResultCode.Success, null, data));
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                return(WrapResponse(ResultCode.Error_SystemFailure, ex.Message));
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            if (string.IsNullOrWhiteSpace(context.Request.QueryString["domainid"]) ||
                string.IsNullOrWhiteSpace(context.Request.QueryString["_sid64"]))
            {
                return;
            }

            context.Response.ContentType     = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;

            try
            {
                long   domainID;
                string _sid64;
                if (!long.TryParse(context.Request.QueryString["domainid"], out domainID))
                {
                    return;
                }
                _sid64 = context.Request.QueryString["_sid64"];

                ceDomainConfigEx domain = DomainManager.GetDomains().FirstOrDefault(d => d.DomainID == domainID);
                if (domain == null)
                {
                    return;
                }

                string userAgentInfo = context.Request.GetRealUserAddress() + context.Request.UserAgent;
                string _sid          = System.Web.HttpUtility.UrlDecode(Decrypt(_sid64, userAgentInfo, true));

                if (string.IsNullOrWhiteSpace(_sid))
                {
                    throw new Exception("Invalid sid");
                }

                SessionPayload session = _agentClient.GetSessionByGuid(_sid);
                long           userID;
                if (session == null ||
                    session.IsAuthenticated != true ||
                    session.DomainID != domain.DomainID)
                {
                    if (!long.TryParse(context.Request.QueryString["userID"], out userID))
                    {
                        throw new Exception("Invalid session");
                    }
                }
                else
                {
                    userID = session.UserID;
                }

                string text = _redisClient.GetByUserID(userID, "reload_balance");

                bool reloadBalance = string.Equals(text, "true", StringComparison.InvariantCultureIgnoreCase);
                if (reloadBalance)
                {
                    _redisClient.SetByUserID(userID, "reload_balance", null).Wait();
                }

                context.Response.Write(CreateJsonResult(true, reloadBalance: reloadBalance));
            }
            catch (Exception ex)
            {
                context.Response.Write(CreateJsonResult(false, error: ex.ToString()));
            }
        }