Ejemplo n.º 1
0
        public static void DeckSave(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("DeckSave");

            int lastId;
            bool deckValidated = true;
            string failMessage = "";

            DeckSave deckSave = JsonConvert.DeserializeObject<DeckSave>(jsonPacketData);

            foreach (int cardId in deckSave.cards)
            {
                if (!client.account.deckValidate.Contains(cardId))
                {
                    deckValidated = false;
                    failMessage   = client.account.username + " failed deck validation: Card ID " + cardId + " isn't validated!";
                }
            }

            if (deckValidated == true)
            {
                string cards     = "";
                string resources = "";

                Deck deck = new Deck();
                deck.name      = deckSave.name;
                deck.timestamp = DateTime.Now.Ticks;
                deck.metadata  = deckSave.metadata;

                foreach (int cardId in client.account.deckValidate)
                {
                    string resource = CardAPI.GetCardType(CardAPI.GetCard(client, cardId).typeId).GetResourceType();

                    if (!deck.resources.Contains(resource))
                    {
                        resources += resource + "|";
                        deck.resources.Add(resource);
                    }

                    cards += cardId + "|";
                    deck.cards.Add(CardAPI.GetCard(client, cardId));
                }

                if (client.account.deckValidate.Count >= 50)
                {
                    deck.valid = true;
                }
                else
                {
                    deck.valid = false;
                }

                if (client.account.deckMap.ContainsKey(deck.name))
                {
                    DB.Database.Execute(client.connection, out lastId, true, true, "UPDATE account_decks SET name = ?, resources = ?, timestamp = ?, metadata = ?, cards = ?, valid = ? WHERE guid = ? AND name = ?",
                        deck.name, resources.TrimEnd('|'), deck.timestamp, deck.metadata, cards.TrimEnd('|'), deck.valid, client.account.id, deck.name);

                    client.account.deckMap.Remove(deck.name);
                }
                else
                {
                    DB.Database.Execute(client.connection, out lastId, true, true, "INSERT INTO account_decks VALUES (0, ?, ?, ?, ?, ?, ?, ?);",
                        client.account.id, deck.name, resources.TrimEnd('|'), deck.timestamp, deck.metadata, cards.TrimEnd('|'), deck.valid);
                }

                client.account.deckMap.Add(deck.name, deck);
            }
            else
            {
                Console.WriteLine(failMessage);
                PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!");
            }
        }
Ejemplo n.º 2
0
        private static bool InternalSignIn(Client client, string encryptedEmail, string encryptedPassword)
        {
            if (Variables.sessionMap.Count >= ConfigReader.serverMaxPlayers)
            {
                FailMessage failMessage = new FailMessage();
                failMessage.op   = "SignIn";
                failMessage.info = "Server is at currently full! Max capacity is " + ConfigReader.serverMaxPlayers + " players.";

                client.Send(failMessage);

                return false;
            }
            else
            {
                int signinStatus = 0;
                string email     = Crypt.RSA.Decrypt(encryptedEmail);
                string password  = Crypt.RSA.Decrypt(encryptedPassword);

                SQLResult accountResult = DB.Database.Select(client.connection, true, false, "SELECT * FROM account WHERE email = ?", email);

                if (accountResult.Count != 0)
                {
                    int accountId             = accountResult.Read<int>   (0, "guid");
                    string username           = accountResult.Read<string>(0, "username");
                    string remotePasswordHash = accountResult.Read<string>(0, "password");
                    bool alreadySignedIn      = accountResult.Read<bool>  (0, "signedIn");

                    string localPasswordHash = HexString(new SHA1CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(email + "|" + password)));

                    if (localPasswordHash == remotePasswordHash)
                    {
                        if (alreadySignedIn == true)
                        {
                            signinStatus = -2;
                        }
                        else
                        {
                            SQLResult banResult = DB.Database.Select(client.connection, false, false, "SELECT * FROM account_bans WHERE guid = ?", accountId);

                            if (banResult.Count != 0)
                            {
                                signinStatus = -1;
                            }
                            else
                            {
                                signinStatus = 1;
                            }
                        }
                    }
                }

                if (signinStatus <= 0)
                {
                    FailMessage failMessage = new FailMessage();
                    failMessage.op = "SignIn";

                    switch (signinStatus)
                    {
                        case -2:
                            {
                                failMessage.info = "This account is already logged in!";
                                break;
                            }
                        case -1:
                            {
                                failMessage.info = "This account is banned!";
                                break;
                            }
                        case 0:
                            {
                                failMessage.info = "Incorrect username or password!";
                                break;
                            }
                    }

                    client.Send(failMessage);
                    client.connection.Close();

                    return false;
                }
                else
                {
                    client.account.id               = accountResult.Read<int>   (0, "guid").ToString();
                    client.account.email            = accountResult.Read<string>(0, "email");
                    client.account.username         = accountResult.Read<string>(0, "username");
                    client.account.acceptChallenges = true;
                    client.account.acceptTrades     = true;

                    switch (accountResult.Read<int>(0, "adminRole"))
                    {
                        case 0: { client.account.adminRole = "None";      break; }
                        case 1: { client.account.adminRole = "Moderator"; break; }
                        case 2: { client.account.adminRole = "Mojang";    break; }
                    }

                    SQLResult profileDataResult = DB.Database.Select(client.connection, false, false, "SELECT * FROM account_data WHERE guid = ?", client.account.id);
                    client.account.gold                   = profileDataResult.Read<int>(0, "gold");
                    client.account.shards                 = profileDataResult.Read<int>(0, "shards");
                    client.account.gamesPlayed            = profileDataResult.Read<int>(0, "gamesPlayed");
                    client.account.gamesWon               = profileDataResult.Read<int>(0, "gamesWon");
                    client.account.gamesSurrendered       = profileDataResult.Read<int>(0, "gamesSurrendered");
                    client.account.selectedPreconstructed = profileDataResult.Read<int>(0, "selectedPreconstructed");

                    SQLResult avatarResult = DB.Database.Select(client.connection, false, false, "SELECT * FROM account_avatar WHERE guid = ?", client.account.id);
                    client.account.avatar.head     = avatarResult.Read<int>(0, "head");
                    client.account.avatar.body     = avatarResult.Read<int>(0, "body");
                    client.account.avatar.leg      = avatarResult.Read<int>(0, "leg");
                    client.account.avatar.armBack  = avatarResult.Read<int>(0, "armBack");
                    client.account.avatar.armFront = avatarResult.Read<int>(0, "armFront");

                    SQLResult cardResult = DB.Database.Select(client.connection, false, false, "SELECT * FROM account_cards WHERE guid = ?", client.account.id);

                    for (int i = 0; i < cardResult.Count; i++)
                    {
                        Card card = new Card();
                        card.id       = cardResult.Read<int>(i, "id");
                        card.typeId   = cardResult.Read<int>(i, "typeId");
                        card.level    = cardResult.Read<int>(i, "level");
                        card.tradable = cardResult.Read<int>(i, "tradable") == 1;
                        card.isToken  = cardResult.Read<int>(i, "isToken") == 1;

                        client.account.cardMap.Add(card.id, card);
                    }

                    PlayerAPI.UpdateScrollTypeCount(client);

                    SQLResult deckResult = DB.Database.Select(client.connection, false, false, "SELECT * FROM account_decks WHERE guid = ?", client.account.id);

                    for (int i = 0; i < deckResult.Count; i++)
                    {
                        Deck deck = new Deck();
                        deck.name      = deckResult.Read<string>(i, "name");
                        deck.timestamp = deckResult.Read<long>  (i, "timestamp");
                        deck.metadata  = deckResult.Read<string>(i, "metadata");
                        deck.valid     = deckResult.Read<int>   (i, "valid") == 1;

                        foreach (string resource in deckResult.Read<string>(i, "resources").Split('|'))
                        {
                            deck.resources.Add(resource);
                        }

                        foreach (string cardId in deckResult.Read<string>(i, "cards").Split('|'))
                        {
                            int iCardId = Convert.ToInt16(cardId);

                            if (CardAPI.Exists(client, iCardId))
                            {
                                deck.cards.Add(CardAPI.GetCard(client, iCardId));
                            }
                        }

                        client.account.deckMap.Add(deck.name, deck);
                    }

                    Variables.sessionMap.Add(client.account.username, client);

                    int lastId;
                    DB.Database.Execute(client.connection, out lastId, false, false, "UPDATE account SET signedIn = 1 WHERE guid = ?", client.account.id);

                    client.account.authenticated = true;
                    client.connection.Close();

                    return true;
                }
            }
        }
Ejemplo n.º 3
0
 public static void ShuffleDeck(Deck deck)
 {
     deck.cards.Shuffle();
 }
Ejemplo n.º 4
0
        public static void SelectPreconstructed(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("SelectPreconstructed");

            int lastId;
            string cards   = "";
            int resourceId = 0;

            SelectPreconstructed selectPreconstructed = JsonConvert.DeserializeObject<SelectPreconstructed>(jsonPacketData);

            Deck deck = new Deck();
            deck.name      = selectPreconstructed.resourceType.Substring(0, 1) + selectPreconstructed.resourceType.ToLower().Remove(0, 1) + " Preconstructed";
            deck.timestamp = DateTime.Now.Ticks;
            deck.metadata  = "";
            deck.valid     = true;

            deck.resources.Add(selectPreconstructed.resourceType);

            client.connection.Open();

            List<int> cardTypeList = Variables.deckTypeMap[selectPreconstructed.resourceType];

            foreach (int cardType in cardTypeList)
            {
                DB.Database.Execute(client.connection, out lastId, false, false, "INSERT INTO account_cards VALUES (0, ?, ?, 0, 0, 0);", client.account.id, cardType);

                cards += lastId + "|";

                Card card = new Card();
                card.id       = lastId;
                card.typeId   = cardType;
                card.tradable = false;
                card.isToken  = false;
                card.level    = 0;

                deck.cards.Add(card);
                client.account.cardMap.Add(card.id, card);
            }

            DB.Database.Execute(client.connection, out lastId, false, false, "INSERT INTO account_decks VALUES (0, ?, ?, ?, ?, \"\", ?, 1);", client.account.id, deck.name, selectPreconstructed.resourceType, deck.timestamp, cards.TrimEnd('|'));

            switch (selectPreconstructed.resourceType)
            {
                case "DECAY":  { resourceId = 4; break; }
                case "ENERGY": { resourceId = 1; break; }
                case "GROWTH": { resourceId = 2; break; }
                case "ORDER":  { resourceId = 3; break; }
            }

            DB.Database.Execute(client.connection, out lastId, false, true, "UPDATE account_data SET selectedPreconstructed = ? WHERE guid = ?", resourceId, client.account.id);

            client.account.deckMap.Add(deck.name, deck);

            OkMessage okMessage = new OkMessage();
            okMessage.op = "SelectPreconstructed";

            client.Send(okMessage);
        }