bool HasLowerSecurityAccount(WorldSession target, uint target_account, bool strong = false) { uint target_sec; // allow everything from console and RA console if (session == null) { return(false); } // ignore only for non-players for non strong checks (when allow apply command at least to same sec level) if (!ObjMgr.IsPlayerAccount(session.GetSecurity()) && !strong)// && !sWorld->getBoolConfig(CONFIG_GM_LOWER_SECURITY)) { return(false); } if (target != null) { target_sec = (uint)target.GetSecurity(); } else if (target_account != 0) { target_sec = AcctMgr.GetSecurity(target_account); } else { return(true); // caller must report error for (target == NULL && target_account == 0) } AccountTypes target_ac_sec = (AccountTypes)target_sec; if (session.GetSecurity() < target_ac_sec || (strong && session.GetSecurity() <= target_ac_sec)) { SendSysMessage(CypherStrings.YoursSecurityIsLow); SetSentErrorMessage(true); return(true); } return(false); }
public static bool SetGMLevel(string[] args, CommandGroup command) { if (args.Length < 3) { return(false); } string targetAccountName = ""; uint targetAccountId = 0; uint targetSecurity = 0; uint gm = 0; string arg1 = args[0]; string arg2 = args[1]; string arg3 = args[2]; bool isAccountNameGiven = true; if (!string.IsNullOrEmpty(arg1) && string.IsNullOrEmpty(arg3)) { if (command.getSelectedPlayer() == null) { return(false); } isAccountNameGiven = false; } // Check for second parameter if (!isAccountNameGiven && !string.IsNullOrEmpty(arg2)) { return(false); } // Check for account if (isAccountNameGiven) { targetAccountName = arg1; if (!targetAccountName.IsNormalized())//need checked { command.SendErrorMessage(CypherStrings.AccountNotExist, targetAccountName); return(false); } } // Check for invalid specified GM level. gm = isAccountNameGiven ? uint.Parse(arg2) : uint.Parse(arg1); if (gm > (uint)AccountTypes.Console) { command.SendErrorMessage(CypherStrings.BadValue); return(false); } // handler->getSession() == NULL only for console targetAccountId = (isAccountNameGiven) ? AcctMgr.GetId(targetAccountName) : command.getSelectedPlayer().GetSession().GetAccountId(); int gmRealmID = (isAccountNameGiven) ? int.Parse(arg3) : int.Parse(arg2); uint playerSecurity; if (command.GetSession() != null) { playerSecurity = AcctMgr.GetSecurity(command.GetSession().GetAccountId(), gmRealmID); } else { playerSecurity = (uint)AccountTypes.Console; } // 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 targetSecurity = AcctMgr.GetSecurity(targetAccountId, gmRealmID); if (targetSecurity >= playerSecurity || gm >= playerSecurity) { command.SendErrorMessage(CypherStrings.YoursSecurityIsLow); return(false); } PreparedStatement stmt; // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1 if (gmRealmID == -1 && !AcctMgr.IsConsoleAccount((AccountTypes)playerSecurity)) { stmt = DB.Auth.GetPreparedStatement(LoginStatements.Sel_account_accessGMLevelTest); stmt.AddValue(0, targetAccountId); stmt.AddValue(1, gm); SQLResult result = DB.Auth.Select(stmt); if (result.Count > 0) { command.SendErrorMessage(CypherStrings.YoursSecurityIsLow); return(false); } } // Check if provided realmID has a negative value other than -1 if (gmRealmID < -1) { command.SendErrorMessage(CypherStrings.InvalidRealmid); return(false); } // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID if (gmRealmID == -1) { stmt = DB.Auth.GetPreparedStatement(LoginStatements.Del_account_access); stmt.AddValue(0, targetAccountId); } else { stmt = DB.Auth.GetPreparedStatement(LoginStatements.Del_account_accessByRealm); stmt.AddValue(0, targetAccountId); stmt.AddValue(1, WorldConfig.RealmId); } DB.Auth.Execute(stmt); if (gm != 0) { stmt = DB.Auth.GetPreparedStatement(LoginStatements.Ins_account_access); stmt.AddValue(0, targetAccountId); stmt.AddValue(1, gm); stmt.AddValue(2, gmRealmID); DB.Auth.Execute(stmt); } command.SendSysMessage(CypherStrings.YouChangeSecurity, targetAccountName, gm); return(true); }