Exemplo n.º 1
0
        private void CheckAccount(int userIndex, string username, IConnection connection)
        {
            var database = new DBGameDatabase();
            var dbError  = database.Open();

            if (dbError.Number > 0)
            {
                Global.WriteLog(LogType.System, $"Failed to check Account: {username}", LogColor.Red);
                Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);

                return;
            }

            // Procura pelo usuário na lista de cache.
            var account = Global.FindAccountByName(username);

            // Quando nulo, procura no banco de dados.
            if (account == null)
            {
                account = database.GetAccountData(username);

                // Quando o usuário é válido, adiciona na lista.
                if (account.AccountID > 0)
                {
                    Global.Accounts.Add(account);
                }
            }

            account.Banned = Convert.ToByte(database.IsBanned(account.AccountID));

            var characters = database.GetCharacterList(account.AccountID);

            database.Close();

            // Envia os personagens.
            new SpAccountData(userIndex, account, characters).Send(connection);

            Global.WriteLog(LogType.Player, $"Request account data: {account.AccountName}", LogColor.Black);
            Global.WriteLog(LogType.Player, $"UserIndex: {userIndex} Id: {account.AccountID} Status: {account.Banned} UserGroup: {account.UserGroup}", LogColor.Black);

            foreach (var character in characters)
            {
                Global.WriteLog(LogType.Player, $"Account Id: {account.AccountID} Character Id: {character.CharacterID} Name: {character.Name} ", LogColor.Black);
            }
        }
Exemplo n.º 2
0
        public void Process(byte[] buffer, IConnection connection)
        {
            var msg = new ByteBuffer(buffer);

            var userIndex      = msg.ReadInt32();
            var accountID      = msg.ReadInt32();
            var characterIndex = msg.ReadInt32();

            if (accountID > 0 && userIndex > 0)
            {
                var database = new DBGameDatabase();
                var dbError  = database.Open();

                if (dbError.Number > 0)
                {
                    Global.WriteLog(LogType.System, $"Failed to delete character from Account Id: {accountID}", LogColor.Red);
                    Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                    Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);
                }
                else
                {
                    database.DeleteCharacter(accountID, characterIndex);

                    var character = Global.FindCharacterByIndexAndAccountId(accountID, characterIndex);
                    if (character != null)
                    {
                        Global.Characters.Remove(character);
                    }

                    var characters = database.GetCharacterList(accountID);
                    new SpCharacterList(userIndex, characters).Send(connection);

                    database.Close();
                }
            }
        }