Пример #1
0
        public static void KickPlayer(Client client, string reason)
        {
            FailMessage failMessage = new FailMessage();
            failMessage.op   = "Reconnect";
            failMessage.info = reason;

            client.Send(failMessage);

            FailMessage infoFailMessage = new FailMessage();
            infoFailMessage.info = reason;

            client.Send(infoFailMessage);

            Variables.sessionMap.Remove(client.account.username);
            client.account = new Account();
        }
Пример #2
0
        public static void BuyStoreItem(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("BuyStoreItem");

            BuyStoreItem buyStoreItem = JsonConvert.DeserializeObject<BuyStoreItem>(jsonPacketData);

            string purchaseMessage = "";
            StoreItem storeItem    = null;

            if (Variables.storeItemMap.ContainsKey(buyStoreItem.itemId))
            {
                storeItem = Variables.storeItemMap[buyStoreItem.itemId];

                if (buyStoreItem.payWithShards)
                {
                    if (client.account.shards >= storeItem.costShards)
                    {
                        PlayerAPI.RemoveShards(client, storeItem.costShards);
                    }
                    else { purchaseMessage  = "Not enough shards to purchase this item."; }
                }
                else
                {
                    if (client.account.gold >= storeItem.costGold)
                    {
                        PlayerAPI.RemoveGold(client, storeItem.costGold);
                    }
                    else { purchaseMessage = "Not enough gold to purchase this item."; }
                }
            }

            if (String.IsNullOrEmpty(purchaseMessage))
            {
                StoreItemHandler.PurchaseItem(client, storeItem.itemType);
                ProfileHandler.ProfileDataInfo(client);

                PlayerAPI.UpdateScrollTypeCount(client);
            }
            else
            {
                FailMessage failMessage = new FailMessage();
                failMessage.op   = "BuyStoreItem";
                failMessage.info = purchaseMessage;

                client.Send(failMessage);
            }
        }
Пример #3
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;
                }
            }
        }