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); }
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)); }