Ejemplo n.º 1
0
        //acquire packages-----------------------------------

        public void AcquirePackage(List <string> login)
        {
            bool isOnline = false;


            for (int i = 0; i < login.Count; i++)
            {
                if (login[i] == authorization)
                {
                    isOnline = true;
                }
            }
            if (!isOnline)
            {
                string data   = "\nuser is not logged in \n";
                string status = "404 Not found";
                string mime   = "text/plain";
                ServerResponse(status, mime, data);
                return;
            }

            int    lenght     = authorization.IndexOf("-mtcgToken");
            string playername = authorization.Substring(0, lenght);

            int coins = Database.selectPlayerCoins(playername);

            if (coins < 5)
            {
                string data   = "\nplayer has not enough coins \n";
                string status = "200 Success";
                string mime   = "text/plain";
                ServerResponse(status, mime, data);
                return;
            }

            lock (anotherLock)
            {
                List <int> boosterid = Database.selectUnusedBooster();
                if (boosterid.Count == 0 || boosterid[0] == 0)
                {
                    string data   = "\nno booster available \n";
                    string status = "200 Success";
                    string mime   = "text/plain";
                    ServerResponse(status, mime, data);
                    return;
                }
                List <string> cards = Database.selectCardInBooster(boosterid[0]);
                if (cards[0] == "0")
                {
                    string data   = "\nSorry, there was a database error \n";
                    string status = "200 Success";
                    string mime   = "text/plain";
                    ServerResponse(status, mime, data);
                    return;
                }
                foreach (string mycard in cards)
                {
                    Database.insertPlayerCard(playername, mycard);
                }
                Database.updateBoosterUsed(boosterid[0]);
                Database.updatePlayerCoins(playername, 5, false);
                string mydata   = "\nYou acquired a new booster pack \n";
                string mystatus = "200 Success";
                string mymime   = "text/plain";
                ServerResponse(mystatus, mymime, mydata);
            }
        }