예제 #1
0
        public void Process(byte[] buffer, IConnection connection)
        {
            var msg = new ByteBuffer(buffer);

            var userIndex = msg.ReadInt32();
            var name      = msg.ReadString();
            var sex       = msg.ReadByte();
            var classe    = msg.ReadByte();
            var sprite    = msg.ReadInt32();
            var charnum   = msg.ReadInt32();

            var database = new DBGameDatabase();
            var dbError  = database.Open();

            if (dbError.Number > 0)
            {
                Global.WriteLog(LogType.System, $"Failed to check if exist Character Name: {name}", LogColor.Red);
                Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);
            }
            else
            {
                var result = database.ExistName(name);
                database.Close();

                new SpExistName(userIndex, result, name, sex, classe, sprite, charnum).Send(connection);
            }
        }
예제 #2
0
 public void SaveCharacter(ref DBGameDatabase database, Character character)
 {
     database.UpdateCharacter(character);
     database.UpdateAchievement(character.CharacterId, character.Achievement);
     database.UpdateCraft(character.CharacterId, character.Craft);
     database.UpdateCurrency(character.CharacterId, character.Currency);
     database.UpdateHotbar(character.CharacterId, character.Hotbar);
     database.UpdateSpell(character.CharacterId, character.Spell);
     database.UpdateSpellBuff(character.CharacterId, character.SpellBuff);
     database.UpdateTitle(character.CharacterId, character.Title);
     database.UpdateEquipment(character.CharacterId, character.Equipment);
     database.UpdateInventory(character.CharacterId, character.Inventory);
     database.UpdateWarehouse(character.CharacterId, character.Warehouse);
     database.UpdateVariable(character.CharacterId, character.Variable);
 }
예제 #3
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);
            }
        }
예제 #4
0
        public static void LoadAccounts()
        {
            var database = new DBGameDatabase();
            var dbError  = database.Open();

            if (dbError.Number > 0)
            {
                WriteLog(LogType.System, $"Failed to load accounts", LogColor.Red);
                WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);
            }
            else
            {
                Accounts = database.GetAccountList();
                database.Close();

                WriteLog(LogType.System, $"{Accounts.Count} accounts loaded", LogColor.Green);
            }
        }
        private Character GetCharacterAsync(int accountId, int characterIndex)
        {
            var character = Global.FindCharacterByIndexAndAccountId(accountId, characterIndex);

            if (character == null)
            {
                // Quando não encontrado, procura no banco de dados.
                var database = new DBGameDatabase();
                var dbError  = database.Open();

                if (dbError.Number > 0)
                {
                    Global.WriteLog(LogType.System, $"Failed to get character from database 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
                {
                    character             = database.GetCharacter(accountId, characterIndex);
                    character.Spell       = database.GetCharacterSpells(character.CharacterId);
                    character.Inventory   = database.GetCharacterItems(character.CharacterId, InventoryType.Inventory);
                    character.Equipment   = database.GetCharacterItems(character.CharacterId, InventoryType.Equipment);
                    character.Warehouse   = database.GetCharacterItems(character.CharacterId, InventoryType.Warehouse);
                    character.Hotbar      = database.GetCharacterHotbar(character.CharacterId);
                    character.Title       = database.GetCharacterTitle(character.CharacterId);
                    character.Variable    = database.GetCharacterVariable(character.CharacterId);
                    character.SpellBuff   = database.GetCharacterSpellBuff(character.CharacterId);
                    character.Currency    = database.GetCharacterCurrency(character.CharacterId);
                    character.Craft       = database.GetCharacterCraft(character.CharacterId);
                    character.Achievement = database.GetCharacterAchievements(character.CharacterId);

                    database.Close();

                    // Adiciona o personagem quando válido.
                    Global.Characters.Add(character);
                }
            }

            return(character);
        }
예제 #6
0
        private void InsertCharacterData(int index, ref Character character, IConnection connection)
        {
            var logs = string.Empty;

            if (character.CharacterId <= 0)
            {
                var database = new DBGameDatabase();
                var dbError  = database.Open();

                if (dbError.Number > 0)
                {
                    Global.WriteLog(LogType.System, $"Failed to insert character Character Id: {character.CharacterId}", LogColor.Red);
                    Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                    Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);
                }
                else
                {
                    // Se o personagem for inserido.
                    if (database.InsertCharacter(character) > 0)
                    {
                        // Obter o Id do personagem.
                        character.CharacterId = database.GetCharacterId(character.AccountId, character.CharacterIndex);

                        new SpCharacterId(index, character.CharacterId).Send(connection);

                        logs = $"Character Id: {character.CharacterId} Name: {character.Name} has been saved";
                        Global.WriteLog(LogType.Player, logs, LogColor.Green);
                    }
                    else
                    {
                        logs = $"Character Id: {character.CharacterId} Name: {character.Name} has not saved";
                        Global.WriteLog(LogType.Player, logs, LogColor.Red);
                    }

                    database.Close();
                }
            }
        }
        private int SaveCharacter(Character character)
        {
            var result     = 0;
            var management = new CharacterManagement();
            var database   = new DBGameDatabase();
            var dbError    = database.Open();

            if (dbError.Number > 0)
            {
                Global.WriteLog(LogType.System, $"Failed to save Character Id: {character.CharacterId}", LogColor.Red);
                Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);
            }
            else
            {
                management.SaveCharacter(ref database, character);
                database.Close();

                result = 1;
            }

            return(result);
        }
예제 #8
0
        public int SaveCharacters()
        {
            // -1 = Database fechada.
            var result     = -1;
            var saved      = 0;
            var management = new CharacterManagement();
            var database   = new DBGameDatabase();
            var dbError    = database.Open();

            if (dbError.Number > 0)
            {
                WriteLog(LogType.System, $"Failed to save characters", LogColor.Red);
                WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red);
                WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red);
            }
            else
            {
                // 0 = Database aberta ou Sem personagens para salvar.
                result = 0;

                for (var n = 0; n < Characters.Count; n++)
                {
                    if (Characters[n].NeedSave)
                    {
                        management.SaveCharacter(ref database, Characters[n]);
                        saved++;
                    }

                    result = saved;
                }

                database.Close();
            }

            return(result);
        }
예제 #9
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();
                }
            }
        }