[0014] Updated realmd to use account_access. This allows for different security levels per account for each realm in realmlist.

This commit is contained in:
Surion 2012-08-07 19:34:25 -05:00 committed by Antz
parent cca3dfd883
commit 1597b90686
11 changed files with 97 additions and 30 deletions

View file

@ -21,7 +21,7 @@
DROP TABLE IF EXISTS `realmd_db_version`;
CREATE TABLE `realmd_db_version` (
`required_0001_xxxxx_01_realmd` bit(1) default NULL
`required_00014_01_realmd_account_access` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB';
--
@ -77,6 +77,19 @@ INSERT INTO `account` VALUES
/*!40000 ALTER TABLE `account` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table Stucture for table `account `account_access`
--
DROP TABLE IF EXISTS `account_access`;
CREATE TABLE `account_access` (
`id` int(10) unsigned NOT NULL,
`gmlevel` tinyint(3) unsigned NOT NULL,
`RealmID` int(11) NOT NULL DEFAULT '-1',
PRIMARY KEY (`id`,`RealmID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table `account_banned`
--

View file

@ -0,0 +1,14 @@
ALTER TABLE realmd_db_version CHANGE COLUMN required_0001_xxxxx_01_realmd required_00014_01_realmd_account_access bit;
--
-- Table Stucture for table `account `account_access`
--
DROP TABLE IF EXISTS `account_access`;
CREATE TABLE `account_access` (
`id` int(10) unsigned NOT NULL,
`gmlevel` tinyint(3) unsigned NOT NULL,
`RealmID` int(11) NOT NULL DEFAULT '-1',
PRIMARY KEY (`id`,`RealmID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View file

@ -88,6 +88,7 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
bool res =
LoginDatabase.PExecute("DELETE FROM account WHERE id='%u'", accid) &&
LoginDatabase.PExecute("DELETE FROM account_access WHERE id ='%d'", accid) &&
LoginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid='%u'", accid);
LoginDatabase.CommitTransaction();
@ -160,7 +161,7 @@ uint32 AccountMgr::GetId(std::string username)
AccountTypes AccountMgr::GetSecurity(uint32 acc_id)
{
QueryResult* result = LoginDatabase.PQuery("SELECT gmlevel FROM account WHERE id = '%u'", acc_id);
QueryResult* result = LoginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id);
if (result)
{
AccountTypes sec = AccountTypes((*result)[0].GetInt32());

View file

@ -972,6 +972,8 @@ enum MangosStrings
// Use for not-in-offcial-sources patches
// 10000-10999
LANG_INVALID_REALMID = 11001,
// Use for custom patches 11000-11999
// NOT RESERVED IDS 12000-1999999999

View file

@ -2579,7 +2579,7 @@ bool ChatHandler::HandlePInfoCommand(char* args)
AccountTypes security = SEC_PLAYER;
std::string last_login = GetMangosString(LANG_ERROR);
QueryResult* result = LoginDatabase.PQuery("SELECT username,gmlevel,last_ip,last_login FROM account WHERE id = '%u'", accId);
QueryResult* result = LoginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.last_ip,a.last_login FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE id = '%u'", accId);
if (result)
{
Field* fields = result->Fetch();
@ -4460,7 +4460,7 @@ bool ChatHandler::HandleLookupAccountEmailCommand(char* args)
std::string email = emailStr;
LoginDatabase.escape_string(email);
// 0 1 2 3 4
QueryResult* result = LoginDatabase.PQuery("SELECT id, username, last_ip, gmlevel, expansion FROM account WHERE email "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'"), email.c_str());
QueryResult* result = LoginDatabase.PQuery("SELECT a.id, a.username, a.last_ip, aa.gmlevel, a.expansion FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE email "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'"), email.c_str());
return ShowAccountListHelper(result, &limit);
}
@ -4479,7 +4479,7 @@ bool ChatHandler::HandleLookupAccountIpCommand(char* args)
LoginDatabase.escape_string(ip);
// 0 1 2 3 4
QueryResult* result = LoginDatabase.PQuery("SELECT id, username, last_ip, gmlevel, expansion FROM account WHERE last_ip "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'"), ip.c_str());
QueryResult* result = LoginDatabase.PQuery("SELECT a.id, a.username, a.last_ip, aa.gmlevel, a.expansion FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE last_ip "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'"), ip.c_str());
return ShowAccountListHelper(result, &limit);
}
@ -4500,7 +4500,7 @@ bool ChatHandler::HandleLookupAccountNameCommand(char* args)
LoginDatabase.escape_string(account);
// 0 1 2 3 4
QueryResult* result = LoginDatabase.PQuery("SELECT id, username, last_ip, gmlevel, expansion FROM account WHERE username "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'"), account.c_str());
QueryResult* result = LoginDatabase.PQuery("SELECT a.id, a.username, a.last_ip, aa.gmlevel, a.expansion FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE username "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'"), account.c_str());
return ShowAccountListHelper(result, &limit);
}

View file

@ -1143,6 +1143,7 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(char* args)
return false;
int32 gm;
uint32 gmRealmID = realmID;
if (!ExtractInt32(&args, gm))
return false;
@ -1160,12 +1161,19 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(char* args)
/// account can't set security to same or grater level, need more power GM or console
AccountTypes plSecurity = GetAccessLevel();
if (AccountTypes(gm) >= plSecurity)
if (AccountTypes(gm) >= plSecurity || (gmRealmID != realmID && plSecurity < SEC_CONSOLE))
{
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
SetSentErrorMessage(true);
return false;
}
// Check if provided realmID is not current realmID, or isn't -1
if (gmRealmID != realmID && gmRealmID != -1)
{
SendSysMessage(LANG_INVALID_REALMID);
SetSentErrorMessage(true);
return false;
}
if (targetPlayer)
{
@ -1174,7 +1182,18 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(char* args)
}
PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
LoginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
// If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID
if (gmRealmID == -1)
{
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u', '%d', -1)", targetAccountId, gm);
}
else
{
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND RealmID = '%d'", targetAccountId, realmID);
LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
}
//LoginDatabase.PExecute("UPDATE account_access SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
return true;
}
@ -6589,7 +6608,7 @@ bool ChatHandler::HandleInstanceSaveDataCommand(char* /*args*/)
bool ChatHandler::HandleGMListFullCommand(char* /*args*/)
{
///- Get the accounts with GM Level >0
QueryResult* result = LoginDatabase.Query("SELECT username,gmlevel FROM account WHERE gmlevel > 0");
QueryResult* result = LoginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE gmlevel > 0");
if (result)
{
SendSysMessage(LANG_GMLIST);

View file

@ -828,15 +828,14 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
QueryResult* result =
LoginDatabase.PQuery("SELECT "
"id, " //0
"gmlevel, " //1
"sessionkey, " //2
"last_ip, " //3
"locked, " //4
"v, " //5
"s, " //6
"expansion, " //7
"mutetime, " //8
"locale " //9
"sessionkey, " //1
"last_ip, " //2
"locked, " //3
"v, " //4
"s, " //5
"expansion, " //6
"mutetime, " //7
"locale " //8
"FROM account "
"WHERE username = '%s'",
safe_account.c_str());
@ -857,13 +856,13 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
Field* fields = result->Fetch ();
expansion = ((sWorld.getConfig(CONFIG_UINT32_EXPANSION) > fields[7].GetUInt8()) ? fields[7].GetUInt8() : sWorld.getConfig(CONFIG_UINT32_EXPANSION));
expansion = ((sWorld.getConfig(CONFIG_UINT32_EXPANSION) > fields[6].GetUInt8()) ? fields[6].GetUInt8() : sWorld.getConfig(CONFIG_UINT32_EXPANSION));
N.SetHexStr ("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
g.SetDword (7);
v.SetHexStr(fields[5].GetString());
s.SetHexStr (fields[6].GetString());
v.SetHexStr(fields[4].GetString());
s.SetHexStr (fields[5].GetString());
m_s = s;
const char* sStr = s.AsHexStr (); //Must be freed by OPENSSL_free()
@ -877,9 +876,9 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
OPENSSL_free ((void*) vStr);
///- Re-check ip locking (same check as in realmd).
if (fields[4].GetUInt8 () == 1) // if ip is locked
if (fields[3].GetUInt8 () == 1) // if ip is locked
{
if (strcmp (fields[3].GetString (), GetRemoteAddress ().c_str ()))
if (strcmp (fields[2].GetString (), GetRemoteAddress ().c_str ()))
{
packet.Initialize (SMSG_AUTH_RESPONSE, 2);
packet.WriteBit(false);
@ -898,16 +897,35 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
if(security > SEC_ADMINISTRATOR) // prevent invalid security settings in DB
security = SEC_ADMINISTRATOR;
K.SetHexStr (fields[2].GetString ());
K.SetHexStr (fields[1].GetString ());
time_t mutetime = time_t (fields[8].GetUInt64 ());
time_t mutetime = time_t (fields[7].GetUInt64 ());
locale = LocaleConstant (fields[9].GetUInt8 ());
locale = LocaleConstant (fields[8].GetUInt8 ());
if (locale >= MAX_LOCALE)
locale = LOCALE_enUS;
delete result;
// Checks gmlevel per Realm
result =
LoginDatabase.PQuery ("SELECT "
"RealmID, " //0
"gmlevel " //1
"FROM account_access "
"WHERE id = '%d'"
" AND (RealmID = '%d'"
" OR RealmID = '-1')",
id, realmID);
if(!result)
security = 0;
else
{
fields = result->Fetch ();
security = fields[1].GetInt32();
delete result;
}
// Re-check account ban (same check as in realmd)
QueryResult *banresult =
LoginDatabase.PQuery ("SELECT 1 FROM account_banned WHERE id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)"

View file

@ -462,7 +462,7 @@ bool ChatHandler::HandleAccountOnlineListCommand(char* args)
///- Get the list of accounts ID logged to the realm
// 0 1 2 3 4
QueryResult* result = LoginDatabase.PQuery("SELECT id, username, last_ip, gmlevel, expansion FROM account WHERE active_realm_id = %u", realmID);
QueryResult* result = LoginDatabase.PQuery("SELECT a.id, a.username, a.last_ip, aa.gmlevel, a.expansion FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE active_realm_id = %u", realmID);
return ShowAccountListHelper(result, &limit);
}

View file

@ -390,7 +390,7 @@ bool AuthSocket::_HandleLogonChallenge()
///- Get the account details from the account table
// No SQL injection (escaped user name)
result = LoginDatabase.PQuery("SELECT sha_pass_hash,id,locked,last_ip,gmlevel,v,s FROM account WHERE username = '%s'", _safelogin.c_str());
result = LoginDatabase.PQuery("SELECT a.sha_pass_hash,a.id,a.locked,a.last_ip,aa.gmlevel,a.v,a.s FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE username = '%s'", _safelogin.c_str());
if (result)
{
///- If the IP is 'locked', check that the player comes indeed from the correct IP address

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "0013"
#define REVISION_NR "0014"
#endif // __REVISION_NR_H__

View file

@ -2,5 +2,5 @@
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_0001_xxxxx_01_characters"
#define REVISION_DB_MANGOS "required_0001_xxxxx_01_mangos"
#define REVISION_DB_REALMD "required_0001_xxxxx_01_realmd"
#define REVISION_DB_REALMD "required_00014_01_realmd_account_access"
#endif // __REVISION_SQL_H__