diff --git a/sql/characlass.sql b/sql/characlass.sql index 807d6a6a..a1966375 100644 --- a/sql/characlass.sql +++ b/sql/characlass.sql @@ -13,62 +13,10 @@ -- Dumping structure for table sapphire.characlass CREATE TABLE IF NOT EXISTS `characlass` ( - `Lv_0` int(5) DEFAULT '0', - `Exp_0` int(10) DEFAULT '0', - `Lv_1` int(5) DEFAULT '0', - `Exp_1` int(10) DEFAULT '0', - `Lv_2` int(5) DEFAULT '0', - `Exp_2` int(10) DEFAULT '0', - `Lv_3` int(5) DEFAULT '0', - `Exp_3` int(10) DEFAULT '0', - `Lv_4` int(5) DEFAULT '0', - `Exp_4` int(10) DEFAULT '0', - `Lv_5` int(5) DEFAULT '0', - `Exp_5` int(10) DEFAULT '0', - `Lv_6` int(5) DEFAULT '0', - `Exp_6` int(10) DEFAULT '0', - `Lv_7` int(5) DEFAULT '0', - `Exp_7` int(10) DEFAULT '0', - `Lv_8` int(5) DEFAULT '0', - `Exp_8` int(10) DEFAULT '0', - `Lv_9` int(5) DEFAULT '0', - `Exp_9` int(10) DEFAULT '0', - `Lv_10` int(5) DEFAULT '0', - `Exp_10` int(10) DEFAULT '0', - `Lv_11` int(5) DEFAULT '0', - `Exp_11` int(10) DEFAULT '0', - `Lv_12` int(5) DEFAULT '0', - `Exp_12` int(10) DEFAULT '0', - `Lv_13` int(5) DEFAULT '0', - `Exp_13` int(10) DEFAULT '0', - `Lv_14` int(5) DEFAULT '0', - `Exp_14` int(10) DEFAULT '0', - `Lv_15` int(5) DEFAULT '0', - `Exp_15` int(10) DEFAULT '0', - `Lv_16` int(5) DEFAULT '0', - `Exp_16` int(10) DEFAULT '0', - `Lv_17` int(5) DEFAULT '0', - `Exp_17` int(10) DEFAULT '0', - `Lv_18` int(5) DEFAULT '0', - `Exp_18` int(10) DEFAULT '0', - `Lv_19` int(5) NOT NULL DEFAULT '0', - `Exp_19` int(10) NOT NULL DEFAULT '0', - `Lv_20` int(5) NOT NULL DEFAULT '0', - `Exp_20` int(10) NOT NULL DEFAULT '0', - `Lv_21` int(5) NOT NULL DEFAULT '0', - `Exp_21` int(10) NOT NULL DEFAULT '0', - `Lv_22` int(5) NOT NULL DEFAULT '0', - `Exp_22` int(10) NOT NULL DEFAULT '0', - `Lv_23` int(5) DEFAULT '0', - `Exp_23` int(10) DEFAULT '0', - `Lv_24` int(5) NOT NULL DEFAULT '0', - `Exp_24` int(10) NOT NULL DEFAULT '0', - `Lv_25` int(5) NOT NULL DEFAULT '0', - `Exp_25` int(19) NOT NULL DEFAULT '0', `CharacterId` int(20) NOT NULL DEFAULT '0', - `IS_DELETE` int(3) DEFAULT '0', - `IS_NOT_ACTIVE_FLG` int(3) DEFAULT '0', - `UPDATE_DATE` datetime DEFAULT NULL, + `ClassIdx` int(3) DEFAULT '0', + `Exp` int(10) DEFAULT '0', + `Lvl` int(5) DEFAULT '0', PRIMARY KEY (`CharacterId`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/sql/update.sql b/sql/update.sql index e9fb826a..2b8c4555 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -10,10 +10,6 @@ -- ADD `container_33` INT(20) NOT NULL AFTER `container_32`, -- ADD `container_34` INT(20) NOT NULL AFTER `container_33`; -- --- ALTER TABLE `characlass` ADD `Lv_24` INT(5) NOT NULL DEFAULT '0' AFTER `Exp_23`, --- ADD `Exp_24` INT(10) NOT NULL DEFAULT '0' AFTER `Lv_24`, --- ADD `Lv_25` INT(5) NOT NULL DEFAULT '0' AFTER `Exp_24`, --- ADD `Exp_25` INT(19) NOT NULL DEFAULT '0' AFTER `Lv_25`; -- ------------------------------------------- -- update.sql Before Merge into Other SQL's 30/08/2017 -- ------------------------------------------- diff --git a/src/servers/Server_Common/Database/CharaDbConnection.cpp b/src/servers/Server_Common/Database/CharaDbConnection.cpp index 4af4c29b..8a5bdad3 100644 --- a/src/servers/Server_Common/Database/CharaDbConnection.cpp +++ b/src/servers/Server_Common/Database/CharaDbConnection.cpp @@ -51,10 +51,6 @@ void Core::Db::CharaDbConnection::doPrepareStatements() "Class, ContentId, BirthDay, BirthMonth " "FROM charainfo WHERE CharacterId = ?;", CONNECTION_SYNC ); - prepareStatement( CHARA_CLASSINFO_SEL_LOAD, "SELECT * FROM characlass WHERE CharacterId = ?;", CONNECTION_SYNC ); - prepareStatement( CHARA_SEARCHINFO_SEL_LOAD, "SELECT * FROM charainfosearch WHERE CharacterId = ?;", CONNECTION_SYNC ); - prepareStatement( CHARA_QUESTINFO_SEL_LOAD, "SELECT * FROM charaquestnew WHERE CharacterId = ?;", CONNECTION_SYNC ); - prepareStatement( CHARA_INS, "INSERT INTO charainfo (AccountId, CharacterId, ContentId, Name, Hp, Mp, " "Customize, Voice, IsNewGame, TerritoryId, PosX, PosY, PosZ, PosR, ModelEquip, " "IsNewAdventurer, GuardianDeity, Birthday, BirthMonth, Class, Status, FirstClass, " @@ -104,12 +100,13 @@ void Core::Db::CharaDbConnection::doPrepareStatements() prepareStatement( CHARA_UP_UNLOCKS, "UPDATE charainfo SET Unlocks = ? WHERE CharacterId = ?;", CONNECTION_ASYNC ); prepareStatement( CHARA_UP_CFPENATLY, "UPDATE charainfo SET CFPenaltyUntil = ? WHERE CharacterId = ?;", CONNECTION_ASYNC ); - /// SEARCHINFO + /// SEARCH INFO prepareStatement( CHARA_SEARCHINFO_UP_SELECTCLASS, "UPDATE charainfosearch SET SelectClassId = ? WHERE CharacterId = ?;", CONNECTION_ASYNC ); prepareStatement( CHARA_SEARCHINFO_UP_SELECTREGION, "UPDATE charainfosearch SET SelectRegion = ? WHERE CharacterId = ?;", CONNECTION_ASYNC ); prepareStatement( CHARA_SEARCHINFO_UP_SEARCHCOMMENT, "UPDATE charainfosearch SET SearchComment = ? WHERE CharacterId = ?;", CONNECTION_ASYNC ); + prepareStatement( CHARA_SEARCHINFO_SEL, "SELECT * FROM charainfosearch WHERE CharacterId = ?;", CONNECTION_SYNC ); - /// QUEST + /// QUEST INFO prepareStatement( CHARA_QUEST_INS, "INSERT INTO charaquestnew ( CharacterId, SlotId, QuestId, Sequence, Flags, Variables_0, " "Variables_1, Variables_2, Variables_3, Variables_4, " "Variables_5, Variables_6 ) VALUES( ?,?,?,?,?,?,?,?,?,?,?,? );", CONNECTION_ASYNC ); @@ -121,6 +118,15 @@ void Core::Db::CharaDbConnection::doPrepareStatements() prepareStatement( CHARA_QUEST_DEL, "DELETE FROM charaquestnew WHERE CharacterId = ? AND QuestId = ?;", CONNECTION_ASYNC ); + prepareStatement( CHARA_QUEST_SEL, "SELECT * FROM charaquestnew WHERE CharacterId = ?;", CONNECTION_SYNC ); + + + /// CLASS INFO + prepareStatement( CHARA_CLASS_SEL, "SELECT ClassIdx, Exp, Lvl FROM characlass WHERE CharacterId = ?;", CONNECTION_SYNC ); + prepareStatement( CHARA_CLASS_INS, "INSERT INTO characlass ( CharacterId, ClassIdx, Exp, Lvl ) VALUES( ?,?,?,?);", CONNECTION_ASYNC ); + prepareStatement( CHARA_CLASS_UP, "UPDATE characlass SET Exp = ?, SET Lvl = ? ) WHERE CharacterId = ? AND ClassIdx = ?;", CONNECTION_ASYNC ); + prepareStatement( CHARA_CLASS_DEL, "DELETE FROM characlass WHERE CharacterId = ?;", CONNECTION_ASYNC ); + diff --git a/src/servers/Server_Common/Database/CharaDbConnection.h b/src/servers/Server_Common/Database/CharaDbConnection.h index b4008843..16d3e17a 100644 --- a/src/servers/Server_Common/Database/CharaDbConnection.h +++ b/src/servers/Server_Common/Database/CharaDbConnection.h @@ -13,9 +13,8 @@ enum CharaDbStatements : uint32_t { CHARA_SEL, CHARA_SEL_MINIMAL, - CHARA_CLASSINFO_SEL_LOAD, - CHARA_SEARCHINFO_SEL_LOAD, - CHARA_QUESTINFO_SEL_LOAD, + CHARA_SEARCHINFO_SEL, + CHARA_QUEST_SEL, CHARA_INS, CHARA_UP, CHARA_UP_NAME, @@ -66,6 +65,11 @@ enum CharaDbStatements : uint32_t CHARA_QUEST_UP, CHARA_QUEST_DEL, + CHARA_CLASS_SEL, + CHARA_CLASS_INS, + CHARA_CLASS_UP, + CHARA_CLASS_DEL, + MAX_STATEMENTS }; diff --git a/src/servers/Server_REST/SapphireAPI.cpp b/src/servers/Server_REST/SapphireAPI.cpp index 59ccb6e8..ba5fdd03 100644 --- a/src/servers/Server_REST/SapphireAPI.cpp +++ b/src/servers/Server_REST/SapphireAPI.cpp @@ -190,9 +190,8 @@ void Core::Network::SapphireAPI::deleteCharacter( std::string name, uint32_t acc int32_t id = deletePlayer.getId(); - g_database.execute( "DELETE FROM charabase WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); + g_database.execute( "DELETE FROM charainfo WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); g_database.execute( "DELETE FROM characlass WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); - g_database.execute( "DELETE FROM charadetail WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); g_database.execute( "DELETE FROM charaglobalitem WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); g_database.execute( "DELETE FROM charainfoblacklist WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); g_database.execute( "DELETE FROM charainfofriendlist WHERE CharacterId LIKE '" + std::to_string( id ) + "';" ); diff --git a/src/servers/Server_Zone/Actor/Player.h b/src/servers/Server_Zone/Actor/Player.h index 537dacc4..32ab455a 100644 --- a/src/servers/Server_Zone/Actor/Player.h +++ b/src/servers/Server_Zone/Actor/Player.h @@ -518,10 +518,11 @@ public: // Database - void updateAllQuests() const; + void updateDbAllQuests() const; void deleteQuest( uint16_t questId ) const; void insertQuest( uint16_t questId, uint8_t index, uint8_t seq ) const; - + void updateDbSearchInfo() const; + void updateDbClass() const; private: uint32_t m_lastWrite; @@ -529,15 +530,12 @@ private: bool m_bIsLogin; - // ==== CHARABASE uint64_t m_contentId; // This id will be the name of the folder for character settings in "My Games" uint8_t m_mode; private: - uint8_t m_mount; - uint8_t m_ignore; - uint8_t m_invincibleGM; + uint8_t m_voice; uint64_t m_modelMainWeapon; @@ -546,31 +544,8 @@ private: uint32_t m_modelEquip[10]; - uint8_t m_emoteModeType; - - // timestamp of first login - uint32_t m_firstLogin; - - // id of initial language - uint32_t m_language; - bool m_bNewGame; - uint32_t m_primaryTerritoryType; - uint32_t m_primaryTerritoryId; - uint32_t m_primaryLayoutId; - uint32_t m_primaryExclusiveId; - uint32_t m_primaryMoveType; - uint32_t m_primaryContentId; - - uint32_t m_secondaryTerritoryType; - uint32_t m_secondaryTerritoryId; - Common::FFXIVARR_POSITION3 m_secondaryPos; - float m_secondaryRot; - uint32_t m_secondaryLayoutId; - // !! END CHARABASE - - // ==== CHARADETAIL uint8_t m_guardianDeity; uint8_t m_birthDay; uint8_t m_birthMonth; @@ -587,16 +562,13 @@ private: uint16_t m_title; uint8_t m_titleList[48]; - uint8_t m_achievement[16]; uint8_t m_howTo[33]; uint8_t m_minions[33]; uint8_t m_mounts[13]; uint8_t m_homePoint; uint8_t m_startTown; - uint8_t m_favoritePoint[3]; uint16_t m_townWarpFstFlags; uint8_t m_questCompleteFlags[200]; - uint8_t m_chocoboTaxiStandFlags[8]; uint8_t m_discovery[420]; uint32_t m_playTime; diff --git a/src/servers/Server_Zone/Actor/PlayerSql.cpp b/src/servers/Server_Zone/Actor/PlayerSql.cpp index bc4dab6e..bd56ca5f 100644 --- a/src/servers/Server_Zone/Actor/PlayerSql.cpp +++ b/src/servers/Server_Zone/Actor/PlayerSql.cpp @@ -208,7 +208,7 @@ bool Core::Entity::Player::load( uint32_t charId, Core::SessionPtr pSession ) bool Core::Entity::Player::loadActiveQuests() { - auto stmt = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_QUESTINFO_SEL_LOAD ); + auto stmt = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_QUEST_SEL ); stmt->setUInt( 1, m_id ); auto res = g_charaDb.query( stmt ); @@ -244,18 +244,19 @@ bool Core::Entity::Player::loadActiveQuests() bool Core::Entity::Player::loadClassData() { - auto stmt = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_CLASSINFO_SEL_LOAD ); + // ClassIdx, Exp, Lvl + auto stmt = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_CLASS_SEL ); stmt->setUInt( 1, m_id ); auto res = g_charaDb.query( stmt ); - if( !res->next() ) - return false; - - for( uint8_t i = 0; i < 25; i++ ) + while( res->next() ) { - uint8_t index = i * 2; - m_classArray[i] = res->getUInt16( index + 1 ); - m_expArray[i] = res->getUInt( index + 2 ); + auto index = res->getUInt16( 1 ); + auto exp = res->getUInt( 2 ); + auto lvl = res->getUInt8( 3 ); + + m_classArray[index] = lvl; + m_expArray[index] = exp; } return true; @@ -263,7 +264,7 @@ bool Core::Entity::Player::loadClassData() bool Core::Entity::Player::loadSearchInfo() { - auto stmt = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_SEARCHINFO_SEL_LOAD ); + auto stmt = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_SEARCHINFO_SEL ); stmt->setUInt( 1, m_id ); auto res = g_charaDb.query( stmt ); @@ -399,67 +400,68 @@ void Core::Entity::Player::updateSql() g_charaDb.execute( stmt ); ////// Searchinfo - auto stmtS = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_SEARCHINFO_UP_SELECTCLASS ); + updateDbSearchInfo(); + + ////// QUESTS + updateDbAllQuests(); + + ////// Class + updateDbClass(); + +} + +void Core::Entity::Player::updateDbClass() const +{ + uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( getClass() )].exp_idx; + + auto stmtS = g_charaDb.getPreparedStatement( Core::Db::CHARA_CLASS_UP ); + stmtS->setInt( 1, getLevel() ); + stmtS->setInt( 2, getExp() ); + stmtS->setInt( 3, m_id ); + stmtS->setInt( 4, classJobIndex ); + g_charaDb.execute( stmtS ); +} + +void Core::Entity::Player::updateDbSearchInfo() const +{ + auto stmtS = g_charaDb.getPreparedStatement( Core::Db::CHARA_SEARCHINFO_UP_SELECTCLASS ); stmtS->setInt( 1, m_searchSelectClass ); stmtS->setInt( 2, m_id ); g_charaDb.execute( stmtS ); - auto stmtS1 = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_SEARCHINFO_UP_SELECTREGION ); + auto stmtS1 = g_charaDb.getPreparedStatement( Core::Db::CHARA_SEARCHINFO_UP_SELECTREGION ); stmtS1->setInt( 1, m_searchSelectRegion ); stmtS1->setInt( 2, m_id ); g_charaDb.execute( stmtS1 ); - auto stmtS2 = g_charaDb.getPreparedStatement( Core::Db::CharaDbStatements::CHARA_SEARCHINFO_UP_SELECTREGION ); - stmtS2->setString( 1, std::string( m_searchMessage != nullptr ? m_searchMessage : "" ) ); + auto stmtS2 = g_charaDb.getPreparedStatement( Core::Db::CHARA_SEARCHINFO_UP_SELECTREGION ); + stmtS2->setString( 1, string( m_searchMessage != nullptr ? m_searchMessage : "" ) ); stmtS2->setInt( 2, m_id ); g_charaDb.execute( stmtS2 ); - - ////// QUESTS - updateAllQuests(); - - std::set< std::string > charaClassSet; - - std::string dbName = g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Mysql.Database", "sapphire" ); - std::string updateCharaClass = "UPDATE " + dbName + ".characlass SET "; - - std::string condition = " UPDATE_DATE = NOW() WHERE CharacterId = " + std::to_string( m_id ) + ";"; - - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( getClass() )].exp_idx; - charaClassSet.insert( " Lv_" + std::to_string( classJobIndex ) + " = " + std::to_string( static_cast< uint32_t >( getLevel() ) ) ); - charaClassSet.insert( " Exp_" + std::to_string( classJobIndex ) + " = " + std::to_string( getExp() ) ); - - - if( !charaClassSet.empty() ) - { - for( auto entry : charaClassSet ) - updateCharaClass += entry + ", "; - - updateCharaClass += condition; - g_database.execute( updateCharaClass ); - } } -void Core::Entity::Player::updateAllQuests() const +void Core::Entity::Player::updateDbAllQuests() const { for( int32_t i = 0; i < 30; i++ ) { - if( m_activeQuests[i] != nullptr ) - { - auto stmtS3 = g_charaDb.getPreparedStatement( Core::Db::CHARA_QUEST_UP ); - stmtS3->setInt( 1, m_activeQuests[i]->c.sequence ); - stmtS3->setInt( 2, m_activeQuests[i]->c.flags ); - stmtS3->setInt( 3, m_activeQuests[i]->c.UI8A ); - stmtS3->setInt( 4, m_activeQuests[i]->c.UI8B ); - stmtS3->setInt( 5, m_activeQuests[i]->c.UI8C ); - stmtS3->setInt( 6, m_activeQuests[i]->c.UI8D ); - stmtS3->setInt( 7, m_activeQuests[i]->c.UI8E ); - stmtS3->setInt( 8, m_activeQuests[i]->c.UI8F ); - stmtS3->setInt( 9, m_activeQuests[i]->c.padding1 ); - stmtS3->setInt( 10, m_id); - stmtS3->setInt( 11, m_activeQuests[i]->c.questId ); - g_charaDb.execute( stmtS3 ); - } + if( !m_activeQuests[i] ) + continue; + + auto stmtS3 = g_charaDb.getPreparedStatement( Core::Db::CHARA_QUEST_UP ); + stmtS3->setInt( 1, m_activeQuests[i]->c.sequence ); + stmtS3->setInt( 2, m_activeQuests[i]->c.flags ); + stmtS3->setInt( 3, m_activeQuests[i]->c.UI8A ); + stmtS3->setInt( 4, m_activeQuests[i]->c.UI8B ); + stmtS3->setInt( 5, m_activeQuests[i]->c.UI8C ); + stmtS3->setInt( 6, m_activeQuests[i]->c.UI8D ); + stmtS3->setInt( 7, m_activeQuests[i]->c.UI8E ); + stmtS3->setInt( 8, m_activeQuests[i]->c.UI8F ); + stmtS3->setInt( 9, m_activeQuests[i]->c.padding1 ); + stmtS3->setInt( 10, m_id); + stmtS3->setInt( 11, m_activeQuests[i]->c.questId ); + g_charaDb.execute( stmtS3 ); + } }