internal static void OnC2SAskCreateCharacter(ByteBuffer buffer, Connection connection) { var incPacket = new CharacterPackets.C2SAskCreateCharacter(buffer, connection); var client = ClientManager.GetClient(connection); if (!DatabaseFunctions.CreateCharacter( client.UserId, incPacket.CharName, (byte)incPacket.ClassCode, (byte)incPacket.HeightCode, (byte)incPacket.FaceCode, (byte)incPacket.HairCode, out var character)) { return; } if (!DatabaseFunctions.AddCharacterToDB(character, out var charID)) { return; } character.Id = charID; var charInfoForPacket = new PacketStructs.CharacterInfo(character); var outPacket = new CharacterPackets.S2CAnsCreateCharacter(charInfoForPacket.ToBytes(), connection); outPacket.Send(connection); }
public static void CreateCharacterPacket(string userIdStr, string charName, string classCodeStr, string heightCodeStr, string faceCodeStr, string hairCodeStr) { int userID = Int32.Parse(userIdStr); byte classCode = Byte.Parse(classCodeStr); byte heightCode = Byte.Parse(heightCodeStr); byte faceCode = Byte.Parse(faceCodeStr); byte hairCode = Byte.Parse(hairCodeStr); if (!DatabaseFunctions.CreateCharacter(userID, charName, classCode, heightCode, faceCode, hairCode, out var character)) { return; } if (!DatabaseFunctions.AddCharacterToDB(character, out var charId)) { return; } character.Id = charId; var sendbytes2 = new PacketStructs.CharacterInfo(character).ToBytes(); var sendbytes1 = ByteUtils.ToByteArray(userID, 5); byte[] sendbytes = new byte[sendbytes2.Length + sendbytes1.Length]; Buffer.BlockCopy(sendbytes1, 0, sendbytes, 0, sendbytes1.Length); Buffer.BlockCopy(sendbytes2, 0, sendbytes, sendbytes1.Length, sendbytes2.Length); AgentConnection.connection.SendObject("CharacterCreateSuccess", sendbytes); GetAllCharacters(userID); }
public static bool getAllCharacters(int userID, out List <PacketStructs.CharacterInfo> characterInfos) { userID = 2; characterInfos = new List <PacketStructs.CharacterInfo>(); using (SqlConnection conn = new SqlConnection(DatabaseHelper.GetConnectionString())) { conn.Open(); SqlCommand cmd = new SqlCommand(DatabaseHelper.SelectString("*", "Character", "UserID", userID.ToString()) + "AND [DeleteCheck]=0", conn); var reader = cmd.ExecuteReader(); while (reader.Read()) { var slot = reader.GetByte(2); var size = 0x10; var classCode = (byte)reader.GetByte(3); var charName = reader.GetString(4); var heightCode = reader.GetByte(5); var faceCode = reader.GetByte(6); var hairCode = reader.GetByte(7); var level = ByteUtils.ToByteArray(reader.GetInt16(8), 2); var region = ByteUtils.ToByteArray(reader.GetInt32(28), 4); var locX = ByteUtils.ToByteArray(reader.GetInt16(29), 2); var locY = ByteUtils.ToByteArray(reader.GetInt16(30), 2); var locZ = ByteUtils.ToByteArray(reader.GetInt16(31), 2); var equipnumber = (byte)0; var equipInfo = (byte[])reader[38]; if (equipInfo == null || equipInfo.Length == 0) { equipInfo = new byte[] { 00 } } ; var charinfo = new PacketStructs.CharacterInfo(slot, size, charName, heightCode, faceCode, hairCode, classCode, level, region, locX, locY, locZ, equipnumber, equipInfo); characterInfos.Add(charinfo); } } return(true); }