/// <summary> /// Sends account information. Response will be negative if account is null. /// </summary> /// <param name="client"></param> public static void AccountInfoRequestResponse(LoginClient client, Account account) { var packet = new MabiPacket(Op.AccountInfoRequestR, Id.Login); if (account != null) { packet.PutByte(true); packet.Add(account); } else { packet.PutByte(false); } client.Send(packet); }
/// <summary> /// Sends positive response to login. /// </summary> /// <param name="client"></param> /// <param name="account"></param> /// <param name="sessionKey"></param> /// <param name="serverList"></param> public static void LoginR(LoginClient client, Account account, long sessionKey, ICollection<ServerInfo> serverList) { var packet = new Packet(Op.LoginR, MabiId.Login); packet.PutByte((byte)LoginResult.Success); packet.PutString(account.Name); // [160XXX] Double account name { packet.PutString(account.Name); } packet.PutLong(sessionKey); packet.PutByte(0); // Servers // -------------------------------------------------------------- packet.AddServerList(serverList, ServerInfoType.Client); // Account Info // -------------------------------------------------------------- packet.Add(account); client.Send(packet); }
/// <summary> /// Returns account or null if account doesn't exist. /// </summary> /// <param name="accountId"></param> /// <returns></returns> public Account GetAccount(string accountId) { using (var conn = this.Connection) using (var mc = new MySqlCommand("SELECT * FROM `accounts` WHERE `accountId` = @accountId", conn)) { mc.Parameters.AddWithValue("@accountId", accountId); using (var reader = mc.ExecuteReader()) { if (!reader.Read()) return null; var account = new Account(); account.Name = reader.GetStringSafe("accountId"); account.Password = reader.GetStringSafe("password"); account.SecondaryPassword = reader.GetStringSafe("secondaryPassword"); account.SessionKey = reader.GetInt64("sessionKey"); account.BannedExpiration = reader.GetDateTimeSafe("banExpiration"); account.BannedReason = reader.GetStringSafe("banReason"); return account; } } }
/// <summary> /// Updates secondary password. /// </summary> /// <param name="account"></param> public void UpdateAccountSecondaryPassword(Account account) { using (var conn = this.Connection) using (var mc = new MySqlCommand("UPDATE `accounts` SET `secondaryPassword` = @secondaryPassword WHERE `accountId` = @accountId", conn)) { mc.Parameters.AddWithValue("@accountId", account.Name); mc.Parameters.AddWithValue("@secondaryPassword", account.SecondaryPassword); mc.ExecuteNonQuery(); } }
/// <summary> /// Updates lastLogin and loggedIn from the account. /// </summary> /// <param name="account"></param> public void UpdateAccount(Account account) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `accounts` SET `lastLogin` = @lastLogin, `loggedIn` = @loggedIn WHERE `accountId` = @accountId", conn)) { cmd.Set("accountId", account.Name); cmd.Set("lastLogin", account.LastLogin); cmd.Set("loggedIn", account.LoggedIn); cmd.Execute(); } }
/// <summary> /// Updates secondary password. /// </summary> /// <param name="account"></param> public void UpdateAccountSecondaryPassword(Account account) { using (var conn = MabiDb.Instance.GetConnection()) { var mc = new MySqlCommand("UPDATE `accounts` SET `secPassword` = @secPassword WHERE `accountId` = @id", conn); mc.Parameters.AddWithValue("@id", account.Name); mc.Parameters.AddWithValue("@secPassword", account.SecondaryPassword); mc.ExecuteNonQuery(); } }
/// <summary> /// Updates lastLogin, lastIp, and login status. /// </summary> /// <param name="account"></param> public void UpdateAccount(Account account) { using (var conn = MabiDb.Instance.GetConnection()) { var mc = new MySqlCommand("UPDATE `accounts` SET `password` = @password, `passwordType` = @passwordType, `lastlogin` = @lastlogin, `lastip` = @lastip, `loggedIn` = @loggedIn WHERE `accountId` = @id", conn); mc.Parameters.AddWithValue("@id", account.Name); mc.Parameters.AddWithValue("@password", account.Password); mc.Parameters.AddWithValue("@passwordType", account.PasswordType); mc.Parameters.AddWithValue("@lastlogin", account.LastLogin); mc.Parameters.AddWithValue("@lastip", account.LastIp); mc.Parameters.AddWithValue("@loggedIn", account.LoggedIn); mc.ExecuteNonQuery(); } }
/// <summary> /// Adds account information to packet. /// </summary> /// <param name="packet"></param> /// <param name="account"></param> private static void Add(this Packet packet, Account account) { packet.PutLong(DateTime.Now); // Last Login packet.PutLong(DateTime.Now); // Last Logout packet.PutInt(0); packet.PutByte(1); packet.PutByte(34); packet.PutInt(0); // 0x800200FF packet.PutByte(1); // Premium services, listed in char selection // -------------------------------------------------------------- // All 3 are visible, if one is set. packet.PutByte(false); // Nao's Support packet.PutLong(0); packet.PutByte(false); // Extra Storage packet.PutLong(0); packet.PutByte(false); // Advanced Play packet.PutLong(0); packet.PutByte(0); packet.PutByte(1); // Always visible? packet.PutByte(account.PremiumServices.HasInventoryPlusService); packet.PutLong(account.PremiumServices.InventoryPlusExpiration); packet.PutByte(account.PremiumServices.HasPremiumService); packet.PutLong(account.PremiumServices.PremiumExpiration); packet.PutByte(account.PremiumServices.HasVipService); packet.PutLong(account.PremiumServices.VipExpiration); // [170402, TW170300] New premium thing { // Invisible? packet.PutByte(0); packet.PutLong(0); } // [180800, NA196 (14.10.2014)] ? { packet.PutByte(0); packet.PutLong(0); } packet.PutByte(0); packet.PutByte(0); // 1: 프리미엄 PC방 서비스 사용중, 16: Free Play Event packet.PutByte(false); // Free Beginner Service // [200100, NA229 (2016-06-16)] ? { packet.PutByte(1); } // Characters // -------------------------------------------------------------- packet.PutShort((short)account.Characters.Count); foreach (var character in account.Characters) { packet.PutString(character.Server); packet.PutLong(character.EntityId); packet.PutString(character.Name); packet.PutByte((byte)character.DeletionFlag); packet.PutLong(0); packet.PutInt(0); packet.PutByte(0); // 0: Human, 1: Elf, 2: Giant packet.PutByte(0); // Assist character ? packet.PutByte(0); // >0 hides all characters? } // Pets // -------------------------------------------------------------- packet.PutShort((short)account.Pets.Count); foreach (var pet in account.Pets) { packet.PutString(pet.Server); packet.PutLong(pet.EntityId); packet.PutString(pet.Name); packet.PutByte((byte)pet.DeletionFlag); packet.PutLong(0); packet.PutInt(pet.Race); packet.PutLong(0); packet.PutLong(0); packet.PutInt(0); packet.PutByte(0); } // Character cards // -------------------------------------------------------------- packet.PutShort((short)account.CharacterCards.Count); foreach (var card in account.CharacterCards) { packet.PutByte(1); packet.PutLong(card.Id); packet.PutInt(card.Type); packet.PutLong(0); packet.PutLong(0); packet.PutInt(0); } // Pet cards // -------------------------------------------------------------- packet.PutShort((short)account.PetCards.Count); foreach (var card in account.PetCards) { packet.PutByte(1); packet.PutLong(card.Id); packet.PutInt(card.Type); packet.PutInt(card.Race); packet.PutLong(0); packet.PutLong(0); packet.PutInt(0); } // Gifts // -------------------------------------------------------------- packet.PutShort((short)account.Gifts.Count); foreach (var gift in account.Gifts) { packet.PutLong(gift.Id); packet.PutByte(gift.IsCharacter); packet.PutInt(gift.Type); packet.PutInt(gift.Race); packet.PutString(gift.Sender); packet.PutString(gift.SenderServer); packet.PutString(gift.Message); packet.PutString(gift.Receiver); packet.PutString(gift.ReceiverServer); packet.PutLong(gift.Added); } packet.PutByte(0); }
/// <summary> /// Sends LoginR with request for secondary password to client. /// </summary> /// <param name="client"></param> /// <param name="account"></param> /// <param name="sessionKey"></param> public static void LoginR_Secondary(LoginClient client, Account account, long sessionKey) { var packet = new Packet(Op.LoginR, MabiId.Login); packet.PutByte((byte)LoginResult.SecondaryReq); packet.PutString(account.Name); // Official seems to send this packet.PutString(account.Name); // back hashed. packet.PutLong(sessionKey); if (account.SecondaryPassword == null) packet.PutString("FIRST"); else packet.PutString("NOT_FIRST"); client.Send(packet); }
/// <summary> /// Adds trade item and points of card to character. /// </summary> /// <param name="account"></param> /// <param name="targetCharacter"></param> /// <param name="charCard"></param> public void TradeCard(Account account, Character targetCharacter, CharCardData charCard) { // Add item using (var conn = this.Connection) using (var cmd = new InsertCommand("INSERT INTO `items` {0}", conn)) { cmd.Set("creatureId", targetCharacter.CreatureId); cmd.Set("itemId", charCard.TradeItem); cmd.Set("pocket", Pocket.Temporary); cmd.Set("color1", 0x808080); cmd.Set("color2", 0x808080); cmd.Set("color3", 0x808080); cmd.Execute(); } // Add points using (var conn = this.Connection) using (var cmd = new InsertCommand("UPDATE `accounts` SET `points` = `points` + @points WHERE `accountId` = @accountId", conn)) { cmd.Set("accountId", account.Name); cmd.Set("points", charCard.TradePoints); cmd.Execute(); } }
/// <summary> /// Adds account information to packet. /// </summary> /// <param name="packet"></param> /// <param name="account"></param> private static void Add(this Packet packet, Account account) { packet.PutLong(ErinnTime.Now.TimeStamp); // Last Login packet.PutLong(ErinnTime.Now.TimeStamp); // Last Logout packet.PutInt(0); packet.PutByte(1); packet.PutByte(34); packet.PutInt(0); // 0x800200FF packet.PutByte(1); // Premium services, listed in char selection // -------------------------------------------------------------- // All 3 are visible, if one is set. packet.PutByte(false); // Nao's Support packet.PutLong(0); packet.PutByte(false); // Extra Storage packet.PutLong(0); packet.PutByte(false); // Advanced Play packet.PutLong(0); packet.PutByte(0); packet.PutByte(1); // Always visible? packet.PutByte(false); // Inventory Plus Kit packet.PutLong(0); // DateTime packet.PutByte(false); // Mabinogi Premium Pack packet.PutLong(0); packet.PutByte(false); // Mabinogi VIP packet.PutLong(0); // [170402, TW170300] New premium thing { // Invisible? packet.PutByte(0); packet.PutLong(0); } packet.PutByte(0); packet.PutByte(0); // 1: 프리미엄 PC방 서비스 사용중, 16: Free Play Event packet.PutByte(false); // Free Beginner Service // Characters // -------------------------------------------------------------- packet.PutShort((short)account.Characters.Count); foreach (var character in account.Characters) { packet.PutString(character.Server); packet.PutLong(character.EntityId); packet.PutString(character.Name); packet.PutByte((byte)character.DeletionFlag); packet.PutLong(0); packet.PutInt(0); packet.PutByte(0); // 0: Human, 1: Elf, 2: Giant packet.PutByte(0); packet.PutByte(0); } // Pets // -------------------------------------------------------------- packet.PutShort((short)account.Pets.Count); foreach (var pet in account.Pets) { packet.PutString(pet.Server); packet.PutLong(pet.EntityId); packet.PutString(pet.Name); packet.PutByte((byte)pet.DeletionFlag); packet.PutLong(0); packet.PutInt(pet.Race); packet.PutLong(0); packet.PutLong(0); packet.PutInt(0); packet.PutByte(0); } // Character cards // -------------------------------------------------------------- packet.PutShort((short)account.CharacterCards.Count); foreach (var card in account.CharacterCards) { packet.PutByte(1); packet.PutLong(card.Id); packet.PutInt(card.Type); packet.PutLong(0); packet.PutLong(0); packet.PutInt(0); } // Pet cards // -------------------------------------------------------------- packet.PutShort((short)account.PetCards.Count); foreach (var card in account.PetCards) { packet.PutByte(1); packet.PutLong(card.Id); packet.PutInt(card.Type); packet.PutInt(card.Race); packet.PutLong(0); packet.PutLong(0); packet.PutInt(0); } // Gifts // -------------------------------------------------------------- packet.PutShort((short)account.Gifts.Count); foreach (var gift in account.Gifts) { packet.PutLong(gift.Id); packet.PutByte(gift.IsCharacter); packet.PutInt(gift.Type); packet.PutInt(gift.Race); packet.PutString(gift.Sender); packet.PutString(gift.SenderServer); packet.PutString(gift.Message); packet.PutString(gift.Receiver); packet.PutString(gift.ReceiverServer); packet.PutLong(gift.Added); } packet.PutByte(0); }
/// <summary> /// Sends positive response to login. /// </summary> /// <param name="client"></param> /// <param name="account"></param> /// <param name="sessionKey"></param> /// <param name="servers"></param> public static void LoginR(LoginClient client, Account account, long sessionKey, List<ServerInfo> servers) { var packet = new Packet(Op.LoginR, MabiId.Login); packet.PutByte((byte)LoginResult.Success); packet.PutString(account.Name); // [160XXX] Double account name { packet.PutString(account.Name); } packet.PutLong(sessionKey); packet.PutByte(0); // Servers // -------------------------------------------------------------- packet.PutByte((byte)servers.Count); foreach (var server in servers) packet.Add(server); // Account Info // -------------------------------------------------------------- packet.Add(account); client.Send(packet); }