From 8baee4a73f8bff944dece9f21f11014f56941fe5 Mon Sep 17 00:00:00 2001 From: Andeeria Date: Sun, 25 Oct 2009 02:38:57 +0400 Subject: [PATCH] [8728] Store current realmid for online account in realm Db account table. * Replace old `account`.`online` field by `account`.`active_realm_id`. It have 0 if account offline. NOTE: this break all scripts that use `online` field for seelct online characters, and it required update. But from other side this reolve * Bug with reset online state active realm at restart another realm. * Let easy select online accounts for some specific realm if need. Signed-off-by: VladimirMangos --- sql/realmd.sql | 4 ++-- sql/updates/8728_01_realmd_account.sql | 5 +++++ sql/updates/Makefile.am | 2 ++ src/game/CharacterHandler.cpp | 2 +- src/game/WorldSession.cpp | 2 +- src/mangosd/Master.cpp | 5 ++--- src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 sql/updates/8728_01_realmd_account.sql diff --git a/sql/realmd.sql b/sql/realmd.sql index 9809f7043..2b8bc64a3 100644 --- a/sql/realmd.sql +++ b/sql/realmd.sql @@ -21,7 +21,7 @@ DROP TABLE IF EXISTS `realmd_db_version`; CREATE TABLE `realmd_db_version` ( - `required_8332_01_realmd_realmcharacters` bit(1) default NULL + `required_8728_01_realmd_account` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB'; -- @@ -54,7 +54,7 @@ CREATE TABLE `account` ( `failed_logins` int(11) unsigned NOT NULL default '0', `locked` tinyint(3) unsigned NOT NULL default '0', `last_login` timestamp NOT NULL default '0000-00-00 00:00:00', - `online` tinyint(4) NOT NULL default '0', + `active_realm_id` int(11) unsigned NOT NULL default '0', `expansion` tinyint(3) unsigned NOT NULL default '0', `mutetime` bigint(40) unsigned NOT NULL default '0', `locale` tinyint(3) unsigned NOT NULL default '0', diff --git a/sql/updates/8728_01_realmd_account.sql b/sql/updates/8728_01_realmd_account.sql new file mode 100644 index 000000000..9f1ee1329 --- /dev/null +++ b/sql/updates/8728_01_realmd_account.sql @@ -0,0 +1,5 @@ +ALTER TABLE realmd_db_version CHANGE COLUMN required_8332_01_realmd_realmcharacters required_8728_01_realmd_account bit; + +ALTER TABLE account + DROP COLUMN online, + ADD COLUMN active_realm_id int(11) unsigned NOT NULL default '0' AFTER last_login; diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index bcca0b602..e6f7a27b5 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -143,6 +143,7 @@ pkgdata_DATA = \ 8721_01_characters_guild.sql \ 8723_01_mangos_achievement_criteria_requirement.sql \ 8726_01_mangos_spell_proc_event.sql \ + 8728_01_realmd_account.sql \ README ## Additional files to include when running 'make dist' @@ -266,4 +267,5 @@ EXTRA_DIST = \ 8721_01_characters_guild.sql \ 8723_01_mangos_achievement_criteria_requirement.sql \ 8726_01_mangos_spell_proc_event.sql \ + 8728_01_realmd_account.sql \ README diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index 20ac51d75..aa550947b 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -705,7 +705,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder *holder) pCurrChar->SendInitialPacketsAfterAddToMap(); CharacterDatabase.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar->GetGUIDLow()); - loginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId()); + loginDatabase.PExecute("UPDATE account SET active_realm_id = %d WHERE id = '%u'", realmID, GetAccountId()); pCurrChar->SetInGameTime( getMSTime() ); // announce group about member online (must be after add to player list to receive announce to self) diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp index 075a5b8ea..3108beb73 100644 --- a/src/game/WorldSession.cpp +++ b/src/game/WorldSession.cpp @@ -375,7 +375,7 @@ void WorldSession::LogoutPlayer(bool Save) ///- Reset the online field in the account table // no point resetting online in character table here as Player::SaveToDB() will set it to 1 since player has not been removed from world at this stage //No SQL injection as AccountID is uint32 - loginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = '%u'", GetAccountId()); + loginDatabase.PExecute("UPDATE account SET active_realm_id = 0 WHERE id = '%u'", GetAccountId()); ///- If the player is in a guild, update the guild roster and broadcast a logout message to other guild members Guild *guild = objmgr.GetGuildById(_player->GetGuildId()); diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index 68113ee7d..56dd504d6 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -460,6 +460,7 @@ bool Master::_StartDB() sLog.outError("Realm ID not defined in configuration file"); return false; } + sLog.outString("Realm running as realm ID %d", realmID); ///- Clean the database before starting @@ -477,9 +478,7 @@ void Master::clearOnlineAccounts() { // Cleanup online status for characters hosted at current realm /// \todo Only accounts with characters logged on *this* realm should have online status reset. Move the online column from 'account' to 'realmcharacters'? - loginDatabase.PExecute( - "UPDATE account SET online = 0 WHERE online > 0 " - "AND id IN (SELECT acctid FROM realmcharacters WHERE realmid = '%d')",realmID); + loginDatabase.PExecute("UPDATE account SET active_realm_id = 0 WHERE active_realm_id = '%d'", realmID); CharacterDatabase.Execute("UPDATE characters SET online = 0 WHERE online<>0"); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 246d7dc20..5c1e51df3 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8727" + #define REVISION_NR "8728" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 95e7e1560..e6a314697 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -2,5 +2,5 @@ #define __REVISION_SQL_H__ #define REVISION_DB_CHARACTERS "required_8721_01_characters_guild" #define REVISION_DB_MANGOS "required_8726_01_mangos_spell_proc_event" - #define REVISION_DB_REALMD "required_8332_01_realmd_realmcharacters" + #define REVISION_DB_REALMD "required_8728_01_realmd_account" #endif // __REVISION_SQL_H__