Exemple #1
0
        public async Task DeleteCharacter(Client player, int slot, string firstName_, string lastName_, string password_)
        {
            if (Characters[slot - 1] == -1 || Characters[slot - 1] == -2)
            {
                return;
            }

            var result = await MySQL.QueryReadAsync($"SELECT `firstname`,`lastname`,`biz`,`sim`,`bank` FROM `characters` WHERE uuid={Characters[slot - 1]}");

            if (result == null || result.Rows.Count == 0)
            {
                return;
            }
            Ban ban = Ban.Get2(Characters[slot - 1]);

            if (ban != null && ban.CheckDate())
            {
                Notify.Send(player, NotifyType.Error, NotifyPosition.BottomCenter, "Невозможно удалить персонажа, который находится в бане.", 3000);
                return;
            }
            var row       = result.Rows[0];
            var firstName = row["firstname"].ToString();
            var lastName  = row["lastname"].ToString();
            var biz       = JsonConvert.DeserializeObject <List <int> >(row["biz"].ToString());
            var sim       = Convert.ToInt32(row["sim"]);
            var bank      = Convert.ToInt32(row["bank"]);
            var uuid      = Characters[slot - 1];

            if (firstName != firstName_ || lastName != lastName_)
            {
                Notify.Send(player, NotifyType.Error, NotifyPosition.BottomCenter, "Имя и фамилия не соответствуют персонажу на выбранном слоте", 3000);
                return;
            }

            password_ = GetSha256(password_);
            if (Password != password_)
            {
                Notify.Send(player, NotifyType.Error, NotifyPosition.BottomCenter, "Неправильный пароль от аккаунта", 3000);
                return;
            }

            foreach (var b in biz)
            {
                BusinessManager.changeOwner($"{firstName}_{lastName}", "Государство");
            }

            await MySQL.QueryAsync("DELETE FROM `customization` WHERE uuid=" + uuid);

            nInventory.Items.Remove(uuid);
            await MySQL.QueryAsync("DELETE FROM `inventory` WHERE uuid=" + uuid);

            MoneySystem.Bank.Remove(bank, $"{firstName}_{lastName}");

            var vehicles = VehicleManager.getAllPlayerVehicles($"{firstName}_{lastName}");

            foreach (var v in vehicles)
            {
                VehicleManager.Remove(v);
            }

            await MySQL.QueryAsync("DELETE FROM `characters` WHERE uuid=" + uuid);

            Main.UUIDs.Remove(uuid);
            Main.PlayerNames.Remove(uuid);
            Main.PlayerUUIDs.Remove($"{firstName}_{lastName}");
            Main.PlayerBankAccs.Remove($"{firstName}_{lastName}");
            Main.SimCards.Remove(sim);
            Main.PlayerSlotsInfo.Remove(uuid);
            Customization.CustomPlayerData.Remove(uuid);

            Characters[slot - 1] = -1;
            await MySQL.QueryAsync($"UPDATE accounts SET character{slot}=-1 WHERE login='******'");

            GameLog.CharacterDelete($"{firstName}_{lastName}", uuid, Login);

            Notify.Send(player, NotifyType.Success, NotifyPosition.BottomCenter, $"Персонаж {firstName} {lastName} успешно удален", 3000);
            NAPI.Task.Run(() => Trigger.ClientEvent(player, "delCharSuccess", slot));
        }