public static void MakeCharacter(uint accountId, uint cid, CharaInfo charaInfo) { //Update character entry using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { try { conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = @" UPDATE characters SET state=2, currentZoneId=@zoneId, positionX=@x, positionY=@y, positionZ=@z, rotation=@r, guardian=@guardian, birthDay=@birthDay, birthMonth=@birthMonth, initialTown=@initialTown, tribe=@tribe WHERE userId=@userId AND id=@cid; INSERT INTO characters_appearance (characterId, baseId, size, voice, skinColor, hairStyle, hairColor, hairHighlightColor, hairVariation, eyeColor, faceType, faceEyebrows, faceEyeShape, faceIrisSize, faceNose, faceMouth, faceFeatures, ears, characteristics, characteristicsColor, mainhand, offhand, head, body, hands, legs, feet, waist) VALUES (@cid, 4294967295, @size, @voice, @skinColor, @hairStyle, @hairColor, @hairHighlightColor, @hairVariation, @eyeColor, @faceType, @faceEyebrows, @faceEyeShape, @faceIrisSize, @faceNose, @faceMouth, @faceFeatures, @ears, @characteristics, @characteristicsColor, @mainhand, @offhand, @head, @body, @hands, @legs, @feet, @waist) "; cmd.Parameters.AddWithValue("@userId", accountId); cmd.Parameters.AddWithValue("@cid", cid); cmd.Parameters.AddWithValue("@guardian", charaInfo.guardian); cmd.Parameters.AddWithValue("@birthDay", charaInfo.birthDay); cmd.Parameters.AddWithValue("@birthMonth", charaInfo.birthMonth); cmd.Parameters.AddWithValue("@initialTown", charaInfo.initialTown); cmd.Parameters.AddWithValue("@tribe", charaInfo.tribe); cmd.Parameters.AddWithValue("@zoneId", charaInfo.zoneId); cmd.Parameters.AddWithValue("@x", charaInfo.x); cmd.Parameters.AddWithValue("@y", charaInfo.y); cmd.Parameters.AddWithValue("@z", charaInfo.z); cmd.Parameters.AddWithValue("@r", charaInfo.rot); cmd.Parameters.AddWithValue("@size", charaInfo.appearance.size); cmd.Parameters.AddWithValue("@voice", charaInfo.appearance.voice); cmd.Parameters.AddWithValue("@skinColor", charaInfo.appearance.skinColor); cmd.Parameters.AddWithValue("@hairStyle", charaInfo.appearance.hairStyle); cmd.Parameters.AddWithValue("@hairColor", charaInfo.appearance.hairColor); cmd.Parameters.AddWithValue("@hairHighlightColor", charaInfo.appearance.hairHighlightColor); cmd.Parameters.AddWithValue("@hairVariation", charaInfo.appearance.hairVariation); cmd.Parameters.AddWithValue("@eyeColor", charaInfo.appearance.eyeColor); cmd.Parameters.AddWithValue("@faceType", charaInfo.appearance.faceType); cmd.Parameters.AddWithValue("@faceEyebrows", charaInfo.appearance.faceEyebrows); cmd.Parameters.AddWithValue("@faceEyeShape", charaInfo.appearance.faceEyeShape); cmd.Parameters.AddWithValue("@faceIrisSize", charaInfo.appearance.faceIrisSize); cmd.Parameters.AddWithValue("@faceNose", charaInfo.appearance.faceNose); cmd.Parameters.AddWithValue("@faceMouth", charaInfo.appearance.faceMouth); cmd.Parameters.AddWithValue("@faceFeatures", charaInfo.appearance.faceFeatures); cmd.Parameters.AddWithValue("@ears", charaInfo.appearance.ears); cmd.Parameters.AddWithValue("@characteristics", charaInfo.appearance.characteristics); cmd.Parameters.AddWithValue("@characteristicsColor", charaInfo.appearance.characteristicsColor); cmd.Parameters.AddWithValue("@mainhand", charaInfo.weapon1); cmd.Parameters.AddWithValue("@offhand", charaInfo.weapon2); cmd.Parameters.AddWithValue("@head", charaInfo.head); cmd.Parameters.AddWithValue("@body", charaInfo.body); cmd.Parameters.AddWithValue("@legs", charaInfo.legs); cmd.Parameters.AddWithValue("@hands", charaInfo.hands); cmd.Parameters.AddWithValue("@feet", charaInfo.feet); cmd.Parameters.AddWithValue("@waist", charaInfo.belt); cmd.ExecuteNonQuery(); } catch (MySqlException e) { Program.Log.Error(e.ToString()); conn.Dispose(); return; } finally { } //Create Level and EXP entries try { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = String.Format("INSERT INTO characters_class_levels(characterId, {0}) VALUES(@characterId, 1); INSERT INTO characters_class_exp(characterId) VALUES(@characterId)", CharacterCreatorUtils.GetClassNameForId((short)charaInfo.currentClass)); cmd.Prepare(); cmd.Parameters.AddWithValue("@characterId", cid); cmd.ExecuteNonQuery(); } catch (MySqlException e) { Program.Log.Error(e.ToString()); conn.Dispose(); return; } //Create Parameter Save try { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = String.Format("INSERT INTO characters_parametersave(characterId, hp, hpMax, mp, mpMax, mainSkill, mainSkillLevel) VALUES(@characterId, 1900, 1000, 115, 115, @mainSkill, 1);", CharacterCreatorUtils.GetClassNameForId((short)charaInfo.currentClass)); cmd.Prepare(); cmd.Parameters.AddWithValue("@characterId", cid); cmd.Parameters.AddWithValue("@mainSkill", charaInfo.currentClass); cmd.ExecuteNonQuery(); } catch (MySqlException e) { Program.Log.Error(e.ToString()); conn.Dispose(); return; } //Create Hotbar try { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT id FROM server_battle_commands WHERE classJob = @classjob AND lvl = 1 ORDER BY id DESC"; cmd.Prepare(); cmd.Parameters.AddWithValue("@classJob", charaInfo.currentClass); List <uint> defaultActions = new List <uint>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { defaultActions.Add(reader.GetUInt32("id")); } } MySqlCommand cmd2 = new MySqlCommand(); cmd2.Connection = conn; cmd2.CommandText = "INSERT INTO characters_hotbar (characterId, classId, hotbarSlot, commandId, recastTime) VALUES (@characterId, @classId, @hotbarSlot, @commandId, 0)"; cmd2.Prepare(); cmd2.Parameters.AddWithValue("@characterId", cid); cmd2.Parameters.AddWithValue("@classId", charaInfo.currentClass); cmd2.Parameters.Add("@hotbarSlot", MySqlDbType.Int16); cmd2.Parameters.Add("@commandId", MySqlDbType.Int16); for (int i = 0; i < defaultActions.Count; i++) { cmd2.Parameters["@hotbarSlot"].Value = i; cmd2.Parameters["@commandId"].Value = defaultActions[i]; cmd2.ExecuteNonQuery(); } } catch (MySqlException e) { Program.Log.Error(e.ToString()); } finally { conn.Dispose(); } } Program.Log.Debug("[SQL] CID={0} state updated to active(2).", cid); }
private void ProcessModifyCharacter(ClientConnection client, SubPacket packet) { CharacterModifyPacket charaReq = new CharacterModifyPacket(packet.data); var slot = charaReq.slot; var name = charaReq.characterName; var worldId = charaReq.worldId; uint pid = 0, cid = 0; //Get world from new char instance if (worldId == 0) { worldId = client.newCharaWorldId; } //Check if this character exists, Get world from there if (worldId == 0 && charaReq.characterId != 0) { Character chara = Database.GetCharacter(client.currentUserId, charaReq.characterId); if (chara != null) { worldId = chara.serverId; } } string worldName = null; World world = Database.GetServer(worldId); if (world != null) { worldName = world.name; } if (worldName == null) { ErrorPacket errorPacket = new ErrorPacket(charaReq.sequence, 0, 0, 13001, "World Does not exist or is inactive."); SubPacket subpacket = errorPacket.BuildPacket(); BasePacket basePacket = BasePacket.CreatePacket(subpacket, true, false); BasePacket.EncryptPacket(client.blowfish, basePacket); client.QueuePacket(basePacket); Program.Log.Info("User {0} => Error; invalid server id: \"{1}\"", client.currentUserId, worldId); return; } bool alreadyTaken; switch (charaReq.command) { case 0x01: //Reserve alreadyTaken = Database.ReserveCharacter(client.currentUserId, slot, worldId, name, out pid, out cid); if (alreadyTaken) { ErrorPacket errorPacket = new ErrorPacket(charaReq.sequence, 1003, 0, 13005, ""); //BDB - Chara Name Used, //1003 - Bad Word SubPacket subpacket = errorPacket.BuildPacket(); BasePacket basePacket = BasePacket.CreatePacket(subpacket, true, false); BasePacket.EncryptPacket(client.blowfish, basePacket); client.QueuePacket(basePacket); Program.Log.Info("User {0} => Error; name taken: \"{1}\"", client.currentUserId, charaReq.characterName); return; } else { pid = 0; client.newCharaCid = cid; client.newCharaSlot = slot; client.newCharaWorldId = worldId; client.newCharaName = name; } Program.Log.Info("User {0} => Character reserved \"{1}\"", client.currentUserId, name); break; case 0x02: //Make CharaInfo info = CharaInfo.GetFromNewCharRequest(charaReq.characterInfoEncoded); //Set Initial Appearance (items will be loaded in by map server) uint[] classAppearance = CharacterCreatorUtils.GetEquipmentForClass(info.currentClass); info.weapon1 = classAppearance[0]; info.weapon2 = classAppearance[1]; info.head = classAppearance[7]; if (classAppearance[8] != 0) { info.body = classAppearance[8]; } else { info.body = CharacterCreatorUtils.GetUndershirtForTribe(info.tribe); } info.legs = classAppearance[9]; info.hands = classAppearance[10]; info.feet = classAppearance[11]; info.belt = classAppearance[12]; //Set Initial Position switch (info.initialTown) { case 1: //ocn0Battle02 (Limsa) info.zoneId = 193; info.x = 0.016f; info.y = 10.35f; info.z = -36.91f; info.rot = 0.025f; break; case 2: //fst0Battle03 (Gridania) info.zoneId = 166; info.x = 369.5434f; info.y = 4.21f; info.z = -706.1074f; info.rot = -1.26721f; break; case 3: //wil0Battle01 (Ul'dah) info.zoneId = 184; info.x = 5.364327f; info.y = 196.0f; info.z = 133.6561f; info.rot = -2.849384f; break; } Database.MakeCharacter(client.currentUserId, client.newCharaCid, info); pid = 1; cid = client.newCharaCid; name = client.newCharaName; Program.Log.Info("User {0} => Character Created \"{1}\"", client.currentUserId, name); break; case 0x03: //Rename alreadyTaken = Database.RenameCharacter(client.currentUserId, charaReq.characterId, worldId, charaReq.characterName); if (alreadyTaken) { ErrorPacket errorPacket = new ErrorPacket(charaReq.sequence, 1003, 0, 13005, ""); //BDB - Chara Name Used, //1003 - Bad Word SubPacket subpacket = errorPacket.BuildPacket(); BasePacket basePacket = BasePacket.CreatePacket(subpacket, true, false); BasePacket.EncryptPacket(client.blowfish, basePacket); client.QueuePacket(basePacket); Program.Log.Info("User {0} => Error; name taken: \"{1}\"", client.currentUserId, charaReq.characterName); return; } Program.Log.Info("User {0} => Character renamed \"{1}\"", client.currentUserId, name); break; case 0x04: //Delete Database.DeleteCharacter(charaReq.characterId, charaReq.characterName); Program.Log.Info("User {0} => Character deleted \"{1}\"", client.currentUserId, name); break; case 0x06: //Rename Retainer Program.Log.Info("User {0} => Retainer renamed \"{1}\"", client.currentUserId, name); break; } CharaCreatorPacket charaCreator = new CharaCreatorPacket(charaReq.sequence, charaReq.command, pid, cid, 1, name, worldName); BasePacket charaCreatorPacket = BasePacket.CreatePacket(charaCreator.BuildPacket(), true, false); BasePacket.EncryptPacket(client.blowfish, charaCreatorPacket); client.QueuePacket(charaCreatorPacket); }
public static void makeCharacter(uint accountId, uint cid, CharaInfo charaInfo) { //Update character entry using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) { try { conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = @" UPDATE characters SET state=2, currentZoneId=@zoneId, positionX=@x, positionY=@y, positionZ=@z, rotation=@r, guardian=@guardian, birthDay=@birthDay, birthMonth=@birthMonth, initialTown=@initialTown, tribe=@tribe WHERE userId=@userId AND id=@cid; INSERT INTO characters_appearance (characterId, baseId, size, voice, skinColor, hairStyle, hairColor, hairHighlightColor, hairVariation, eyeColor, faceType, faceEyebrows, faceEyeShape, faceIrisSize, faceNose, faceMouth, faceFeatures, ears, characteristics, characteristicsColor, mainhand, offhand, head, body, hands, legs, feet, waist) VALUES (@cid, 4294967295, @size, @voice, @skinColor, @hairStyle, @hairColor, @hairHighlightColor, @hairVariation, @eyeColor, @faceType, @faceEyebrows, @faceEyeShape, @faceIrisSize, @faceNose, @faceMouth, @faceFeatures, @ears, @characteristics, @characteristicsColor, @mainhand, @offhand, @head, @body, @hands, @legs, @feet, @waist) "; cmd.Parameters.AddWithValue("@userId", accountId); cmd.Parameters.AddWithValue("@cid", cid); cmd.Parameters.AddWithValue("@guardian", charaInfo.guardian); cmd.Parameters.AddWithValue("@birthDay", charaInfo.birthDay); cmd.Parameters.AddWithValue("@birthMonth", charaInfo.birthMonth); cmd.Parameters.AddWithValue("@initialTown", charaInfo.initialTown); cmd.Parameters.AddWithValue("@tribe", charaInfo.tribe); cmd.Parameters.AddWithValue("@zoneId", charaInfo.zoneId); cmd.Parameters.AddWithValue("@x", charaInfo.x); cmd.Parameters.AddWithValue("@y", charaInfo.y); cmd.Parameters.AddWithValue("@z", charaInfo.z); cmd.Parameters.AddWithValue("@r", charaInfo.rot); cmd.Parameters.AddWithValue("@size", charaInfo.appearance.size); cmd.Parameters.AddWithValue("@voice", charaInfo.appearance.voice); cmd.Parameters.AddWithValue("@skinColor", charaInfo.appearance.skinColor); cmd.Parameters.AddWithValue("@hairStyle", charaInfo.appearance.hairStyle); cmd.Parameters.AddWithValue("@hairColor", charaInfo.appearance.hairColor); cmd.Parameters.AddWithValue("@hairHighlightColor", charaInfo.appearance.hairHighlightColor); cmd.Parameters.AddWithValue("@hairVariation", charaInfo.appearance.hairVariation); cmd.Parameters.AddWithValue("@eyeColor", charaInfo.appearance.eyeColor); cmd.Parameters.AddWithValue("@faceType", charaInfo.appearance.faceType); cmd.Parameters.AddWithValue("@faceEyebrows", charaInfo.appearance.faceEyebrows); cmd.Parameters.AddWithValue("@faceEyeShape", charaInfo.appearance.faceEyeShape); cmd.Parameters.AddWithValue("@faceIrisSize", charaInfo.appearance.faceIrisSize); cmd.Parameters.AddWithValue("@faceNose", charaInfo.appearance.faceNose); cmd.Parameters.AddWithValue("@faceMouth", charaInfo.appearance.faceMouth); cmd.Parameters.AddWithValue("@faceFeatures", charaInfo.appearance.faceFeatures); cmd.Parameters.AddWithValue("@ears", charaInfo.appearance.ears); cmd.Parameters.AddWithValue("@characteristics", charaInfo.appearance.characteristics); cmd.Parameters.AddWithValue("@characteristicsColor", charaInfo.appearance.characteristicsColor); cmd.Parameters.AddWithValue("@mainhand", charaInfo.weapon1); cmd.Parameters.AddWithValue("@offhand", charaInfo.weapon2); cmd.Parameters.AddWithValue("@head", charaInfo.head); cmd.Parameters.AddWithValue("@body", charaInfo.body); cmd.Parameters.AddWithValue("@legs", charaInfo.legs); cmd.Parameters.AddWithValue("@hands", charaInfo.hands); cmd.Parameters.AddWithValue("@feet", charaInfo.feet); cmd.Parameters.AddWithValue("@waist", charaInfo.belt); cmd.ExecuteNonQuery(); } catch (MySqlException e) { conn.Dispose(); return; } finally { } //Create Level and EXP entries try { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = String.Format("INSERT INTO characters_class_levels(characterId, {0}) VALUES(@characterId, 1); INSERT INTO characters_class_exp(characterId) VALUES(@characterId)", CharacterCreatorUtils.GetClassNameForId((short)charaInfo.currentClass)); cmd.Prepare(); cmd.Parameters.AddWithValue("@characterId", cid); cmd.ExecuteNonQuery(); } catch (MySqlException e) { conn.Dispose(); return; } //Create Parameter Save try { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = String.Format("INSERT INTO characters_parametersave(characterId, hp, hpMax, mp, mpMax, mainSkill, mainSkillLevel) VALUES(@characterId, 1, 1, 1, 1, @mainSkill, 1);", CharacterCreatorUtils.GetClassNameForId((short)charaInfo.currentClass)); cmd.Prepare(); cmd.Parameters.AddWithValue("@characterId", cid); cmd.Parameters.AddWithValue("@mainSkill", charaInfo.currentClass); cmd.ExecuteNonQuery(); } catch (MySqlException e) { } finally { conn.Dispose(); } } Log.database(String.Format("CID={0} state updated to active(2).", cid)); }