Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (userid != -1)
                {
                    if (Request.Form["FusionResult"] == "start")
                    {
                        responseResult = userid.ToString();
                    }
                    else
                    {
                        //get request info
                        var leftCardID   = Request.Form["LeftCardID"];
                        var rightCardID  = Request.Form["RightCardID"];
                        var fusionResult = Request.Form["FusionResult"];
                        var authKey      = Request.Form["AuthKey"];

                        if (!string.IsNullOrEmpty(leftCardID) && !string.IsNullOrEmpty(rightCardID) &&
                            !string.IsNullOrEmpty(fusionResult) && !string.IsNullOrEmpty(authKey))
                        {
                            int card1, card2, result;

                            if (int.TryParse(leftCardID, out card1) && int.TryParse(rightCardID, out card2) &&
                                int.TryParse(fusionResult, out result))
                            {
                                if (ValidateAuthKey(card1.ToString(), card2.ToString(), userid.ToString(), authKey))
                                {
                                    var un1 = PlayerStrip.GetUserNumber(card1);
                                    var un2 = PlayerStrip.GetUserNumber(card2);

                                    if (un1 != null && un2 != null && un1.UserID == userid && un2.UserID == userid)
                                    {
                                        if (!un1.IsActive && !un2.IsActive &&
                                            un1.ArsenalPlayerGuid.Value == un2.ArsenalPlayerGuid.Value)
                                        {
                                            //rule 1 -- two inactive cards of same player

                                            if (fusionResult == "1")
                                            {
                                                //remove two cards and insert 1 video

                                                UserVideo.ConsolidateCards(userid, username, card1, card2);
                                                PlayerLog.LogHistory(userid, username,
                                                                     PlayerHistoryType.ConsolidateCards,
                                                                     new ConsolidateCardsDesc(un1, un2).Generate());

                                                responseResult = "1";
                                            }
                                        }
                                        else if (un1.IsActive != un2.IsActive)
                                        {
                                            //rule 2 -- one active card and one inactive card

                                            if (fusionResult == "2")
                                            {
                                                //remove two cards and insert 1 video

                                                UserVideo.ConsolidateCards(userid, username, card1, card2);
                                                PlayerLog.LogHistory(userid, username,
                                                                     PlayerHistoryType.ConsolidateCards,
                                                                     new ConsolidateCardsDesc(un1, un2).Generate());

                                                responseResult = "1";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            Response.Write("ServerMessage=" + responseResult);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var result       = "false";
            var returnURL    = string.Empty;
            var responseText = string.Empty;

            using (var conn = ConfigGlobal.SQLConnectionStrings)
            {
                conn.Open();
                var trans = conn.BeginTransaction();

                try
                {
                    if (userid != -1)
                    {
                        if (Request.Form["CardID"] != null)
                        {
                            var unID    = -1;
                            var authKey = Request.Form["AuthKey"];

                            if (int.TryParse(Request.Form["CardID"], out unID))
                            {
                                if (PlayerStrip.ValidateAuthKey(unID.ToString(), string.Empty, authKey))
                                {
                                    if (PlayerStrip.CheckUserNumActiveCondition(userid, unID))
                                    {
                                        var un = PlayerStrip.GetUserNumber(unID);

                                        if (un.ArsenalPlayerGuid.HasValue)
                                        {
                                            //normal player card
                                            PlayerStrip.SetCardAcitve(userid, unID);

                                            PlayerLog.LogHistory(userid, username, PlayerHistoryType.ActivateCard,
                                                                 new ActivateCardDesc(un).Generate());

                                            result = "true";
                                        }
                                        else
                                        {
                                            //video card
                                            var guid = UserVideo.GetRandomVideo(userid, 1, 3, true);

                                            if (!guid.HasValue)
                                            {
                                                throw new Exception("No Video Available.");
                                            }

                                            var uv = new Entity.UserVideo();

                                            uv.UserID     = userid;
                                            uv.UserName   = username;
                                            uv.VideoGuid  = guid.Value;
                                            uv.ActiveDate = DateTime.Now;
                                            uv.UserDesc   = string.Empty;
                                            uv.IsPublic   = false;

                                            uv.Insert(trans);

                                            trans.Commit();

                                            PlayerStrip.ActiveVideoCost(userid, unID);

                                            returnURL = Player.Cache.Load(
                                                Video.Cache.Load(guid.Value).GoalPlayerGuid.Value).PhotoURL;

                                            PlayerLog.LogHistory(userid, username, PlayerHistoryType.ActivateVideo,
                                                                 new ActivateVideoDesc(un).Generate());

                                            if (string.IsNullOrEmpty(returnURL))
                                            {
                                                result = "full";
                                            }
                                            else
                                            {
                                                result = "video";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    trans.Rollback();

                    result = "error";
                }

                //conn.Close();
            }

            if (!string.IsNullOrEmpty(returnURL))
            {
                responseText = $"ServerMessage={result}&PhotoURL={returnURL}";
            }
            else
            {
                responseText = $"ServerMessage={result}";
            }

            Response.Write(responseText);
        }