DB/Account: update account_access table cherry-pick take 2 (with refactors)
Port From (https://github.com/TrinityCore/TrinityCore/commit/69cadae38ae7196703ea10908860a6973dbdcddf)
This commit is contained in:
@@ -86,10 +86,10 @@ namespace Framework.Database
|
|||||||
PrepareStatement(LoginStatements.SEL_CHECK_PASSWORD_BY_NAME, "SELECT salt, verifier FROM account WHERE username = ? AND salt IS NOT NULL AND verifier IS NOT NULL");
|
PrepareStatement(LoginStatements.SEL_CHECK_PASSWORD_BY_NAME, "SELECT salt, verifier FROM account WHERE username = ? AND salt IS NOT NULL AND verifier IS NOT NULL");
|
||||||
PrepareStatement(LoginStatements.SEL_PINFO, "SELECT a.username, aa.SecurityLevel, a.email, a.reg_mail, a.last_ip, DATE_FORMAT(a.last_login, '%Y-%m-%d %T'), a.mutetime, a.mutereason, a.muteby, a.failed_logins, a.locked, a.OS FROM account a LEFT JOIN account_access aa ON (a.id = aa.AccountID AND (aa.RealmID = ? OR aa.RealmID = -1)) WHERE a.id = ?");
|
PrepareStatement(LoginStatements.SEL_PINFO, "SELECT a.username, aa.SecurityLevel, a.email, a.reg_mail, a.last_ip, DATE_FORMAT(a.last_login, '%Y-%m-%d %T'), a.mutetime, a.mutereason, a.muteby, a.failed_logins, a.locked, a.OS FROM account a LEFT JOIN account_access aa ON (a.id = aa.AccountID AND (aa.RealmID = ? OR aa.RealmID = -1)) WHERE a.id = ?");
|
||||||
PrepareStatement(LoginStatements.SEL_PINFO_BANS, "SELECT unbandate, bandate = unbandate, bannedby, banreason FROM account_banned WHERE id = ? AND active ORDER BY bandate ASC LIMIT 1");
|
PrepareStatement(LoginStatements.SEL_PINFO_BANS, "SELECT unbandate, bandate = unbandate, bannedby, banreason FROM account_banned WHERE id = ? AND active ORDER BY bandate ASC LIMIT 1");
|
||||||
PrepareStatement(LoginStatements.SEL_GM_ACCOUNTS, "SELECT a.username, aa.SecurityLevel FROM account a, account_access aa WHERE a.id=aa.AccountID AND aa.SecurityLevel >= ? AND (aa.realmid = -1 OR aa.realmid = ?)");
|
PrepareStatement(LoginStatements.SEL_GM_ACCOUNTS, "SELECT a.username, aa.SecurityLevel FROM account a, account_access aa WHERE a.id = aa.AccountID AND aa.SecurityLevel >= ? AND (aa.RealmID = -1 OR aa.RealmID = ?)");
|
||||||
PrepareStatement(LoginStatements.SEL_ACCOUNT_INFO, "SELECT a.username, a.last_ip, aa.SecurityLevel, a.expansion FROM account a LEFT JOIN account_access aa ON (a.id = aa.AccountID) WHERE a.id = ?");
|
PrepareStatement(LoginStatements.SEL_ACCOUNT_INFO, "SELECT a.username, a.last_ip, aa.SecurityLevel, a.expansion FROM account a LEFT JOIN account_access aa ON a.id = aa.AccountID WHERE a.id = ?");
|
||||||
PrepareStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST, "SELECT 1 FROM account_access WHERE AccountID = ? AND SecurityLevel > ?");
|
PrepareStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST, "SELECT 1 FROM account_access WHERE AccountID = ? AND SecurityLevel > ?");
|
||||||
PrepareStatement(LoginStatements.SEL_ACCOUNT_ACCESS, "SELECT a.id, aa.SecurityLevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.AccountID) WHERE a.username = ?");
|
PrepareStatement(LoginStatements.SEL_ACCOUNT_ACCESS, "SELECT a.id, aa.SecurityLevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON a.id = aa.AccountID WHERE a.username = ?");
|
||||||
PrepareStatement(LoginStatements.SEL_ACCOUNT_WHOIS, "SELECT username, email, last_ip FROM account WHERE id = ?");
|
PrepareStatement(LoginStatements.SEL_ACCOUNT_WHOIS, "SELECT username, email, last_ip FROM account WHERE id = ?");
|
||||||
PrepareStatement(LoginStatements.SEL_LAST_ATTEMPT_IP, "SELECT last_attempt_ip FROM account WHERE id = ?");
|
PrepareStatement(LoginStatements.SEL_LAST_ATTEMPT_IP, "SELECT last_attempt_ip FROM account WHERE id = ?");
|
||||||
PrepareStatement(LoginStatements.SEL_LAST_IP, "SELECT last_ip FROM account WHERE id = ?");
|
PrepareStatement(LoginStatements.SEL_LAST_IP, "SELECT last_ip FROM account WHERE id = ?");
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ namespace Game.Chat
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Command("seclevel", RBACPermissions.CommandAccountSetSecLevel, true)]
|
[Command("seclevel", RBACPermissions.CommandAccountSetSecLevel, true)]
|
||||||
static bool HandleAccountSetSecLevelCommand(CommandHandler handler, string accountName, byte securityLevel, int realmId = -1)
|
static bool HandleAccountSetSecLevelCommand(CommandHandler handler, string accountName, byte securityLevel, int? realmId)
|
||||||
{
|
{
|
||||||
uint accountId;
|
uint accountId;
|
||||||
if (!accountName.IsEmpty())
|
if (!accountName.IsEmpty())
|
||||||
@@ -447,15 +447,19 @@ namespace Game.Chat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int realmID = -1;
|
||||||
|
if (realmId.HasValue)
|
||||||
|
realmID = realmId.Value;
|
||||||
|
|
||||||
AccountTypes playerSecurity;
|
AccountTypes playerSecurity;
|
||||||
if (handler.GetSession() != null)
|
if (handler.GetSession() != null)
|
||||||
playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), realmId);
|
playerSecurity = Global.AccountMgr.GetSecurity(handler.GetSession().GetAccountId(), realmID);
|
||||||
else
|
else
|
||||||
playerSecurity = AccountTypes.Console;
|
playerSecurity = AccountTypes.Console;
|
||||||
|
|
||||||
// can set security level only for target with less security and to less security that we have
|
// can set security level only for target with less security and to less security that we have
|
||||||
// This is also reject self apply in fact
|
// This is also reject self apply in fact
|
||||||
AccountTypes targetSecurity = Global.AccountMgr.GetSecurity(accountId, realmId);
|
AccountTypes targetSecurity = Global.AccountMgr.GetSecurity(accountId, realmID);
|
||||||
if (targetSecurity >= playerSecurity || (AccountTypes)securityLevel >= playerSecurity)
|
if (targetSecurity >= playerSecurity || (AccountTypes)securityLevel >= playerSecurity)
|
||||||
{
|
{
|
||||||
handler.SendSysMessage(CypherStrings.YoursSecurityIsLow);
|
handler.SendSysMessage(CypherStrings.YoursSecurityIsLow);
|
||||||
@@ -463,7 +467,7 @@ namespace Game.Chat
|
|||||||
}
|
}
|
||||||
PreparedStatement stmt;
|
PreparedStatement stmt;
|
||||||
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
|
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
|
||||||
if (realmId == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity))
|
if (realmID == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity))
|
||||||
{
|
{
|
||||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST);
|
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST);
|
||||||
stmt.AddValue(0, accountId);
|
stmt.AddValue(0, accountId);
|
||||||
@@ -479,13 +483,13 @@ namespace Game.Chat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if provided realmID has a negative value other than -1
|
// Check if provided realmID has a negative value other than -1
|
||||||
if (realmId < -1)
|
if (realmID < -1)
|
||||||
{
|
{
|
||||||
handler.SendSysMessage(CypherStrings.InvalidRealmid);
|
handler.SendSysMessage(CypherStrings.InvalidRealmid);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Global.AccountMgr.UpdateAccountAccess(null, accountId, (byte)securityLevel, realmId);
|
Global.AccountMgr.UpdateAccountAccess(null, accountId, (byte)securityLevel, realmID);
|
||||||
|
|
||||||
handler.SendSysMessage(CypherStrings.YouChangeSecurity, accountName, securityLevel);
|
handler.SendSysMessage(CypherStrings.YouChangeSecurity, accountName, securityLevel);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user