Example #1
0
        private List <string> ParseContents(string json)
        {
            var           code = GiftCode.FromJson(json);
            List <string> ret  = new List <string>();

            if (code == null)
            {
                return(ret);
            }
            var added = new List <int>();

            if (code.Fame != 0)
            {
                ret.Add($"Fame: {code.Fame}");
            }
            if (code.Gold != 0)
            {
                ret.Add($"Gold: {code.Gold}");
            }
            if (code.VaultChests != 0)
            {
                ret.Add($"Vault Chest{(code.VaultChests > 1 ? "s" : String.Empty)}: {code.VaultChests}");
            }
            if (code.CharSlots != 0)
            {
                ret.Add($"Char Slot{(code.CharSlots > 1 ? "s" : String.Empty)}: {code.CharSlots}");
            }

            foreach (var item in code.Gifts)
            {
                if (!added.Contains(item))
                {
                    ret.Add($"{code.Gifts.Count(_ => _ == item)} {Program.GameData.Items[(ushort)item].ObjectId}");
                    added.Add(item);
                }
            }
            return(ret);
        }
        private bool ParseContents(Account acc, string json)
        {
            try
            {
                using (var db = new Database())
                {
                    var code = GiftCode.FromJson(json);
                    if (code == null)
                    {
                        return(false);
                    }
                    var cmd = db.CreateQuery();

                    if (code.Gifts.Count > 0)
                    {
                        List <int> gifts = acc.Gifts;
                        foreach (var i in code.Gifts)
                        {
                            gifts.Add(i);
                        }

                        cmd             = db.CreateQuery();
                        cmd.CommandText =
                            "UPDATE accounts SET gifts=@gifts WHERE uuid=@uuid AND password=SHA1(@password);";
                        cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString <int>(gifts.ToArray()));
                        cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                        cmd.Parameters.AddWithValue("@password", Query["password"]);
                        cmd.ExecuteNonQuery();
                    }

                    if (code.CharSlots > 0)
                    {
                        cmd             = db.CreateQuery();
                        cmd.CommandText =
                            "UPDATE accounts SET maxCharSlot=maxCharSlot + @amount WHERE uuid=@uuid AND password=SHA1(@password);";
                        cmd.Parameters.AddWithValue("@amount", code.CharSlots);
                        cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                        cmd.Parameters.AddWithValue("@password", Query["password"]);
                        cmd.ExecuteNonQuery();
                    }

                    if (code.VaultChests > 0)
                    {
                        for (int j = 0; j < code.VaultChests; j++)
                        {
                            db.CreateChest(acc);
                        }
                    }

                    if (code.Gold > 0)
                    {
                        db.UpdateCredit(acc, code.Gold);
                    }

                    if (code.Fame > 0)
                    {
                        db.UpdateFame(acc, code.Fame);
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }