diff options
author | megamage <none@none> | 2008-12-28 10:52:24 -0600 |
---|---|---|
committer | megamage <none@none> | 2008-12-28 10:52:24 -0600 |
commit | 3bbf8d6be8cd67d99fc8c1df3a971fe4e7e680ef (patch) | |
tree | 0264a08b586df36f290a6b1b6a839dcf9b829c75 /src/game/Level3.cpp | |
parent | ac9cced914fb4c9db0b2b64f7fd9f9ab8c7802ee (diff) | |
parent | 9fa37dc69344a28a585bc2dee6713d7ebaa03d28 (diff) |
HG 698.
--HG--
branch : trunk
Diffstat (limited to 'src/game/Level3.cpp')
-rw-r--r-- | src/game/Level3.cpp | 109 |
1 files changed, 58 insertions, 51 deletions
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 6bdffe0b187..ae0ea508308 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -731,43 +731,57 @@ bool ChatHandler::HandleLoadScriptsCommand(const char* args) bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args) { - char* arg1 = strtok((char*)args, " "); - if( !arg1 ) + if(!*args) return false; - /// must be NULL if targeted syntax and must be not nULL if not targeted - char* arg2 = strtok(NULL, " "); - std::string targetAccountName; uint32 targetAccountId = 0; uint32 targetSecurity = 0; + uint32 gm = 0; + char* arg1 = strtok((char*)args, " "); + char* arg2 = strtok(NULL, " "); - /// only target player different from self allowed (if targetPlayer!=NULL then not console) - Player* targetPlayer = getSelectedPlayer(); - if(targetPlayer && m_session->GetPlayer()!=targetPlayer) + if(getSelectedPlayer() && arg1 && !arg2) { - /// wrong command syntax or unexpected targeting - if(arg2) - return false; + targetAccountId = getSelectedPlayer()->GetSession()->GetAccountId(); + accmgr.GetName(targetAccountId, targetAccountName); + Player* targetPlayer = getSelectedPlayer(); + gm = atoi(arg1); - /// security level expected in arg2 after this if. - arg2 = arg1; + // Check for invalid specified GM level. + if ( (gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR) ) + { + SendSysMessage(LANG_BAD_VALUE); + SetSentErrorMessage(true); + return false; + } - targetAccountId = targetPlayer->GetSession()->GetAccountId(); + // Check if targets GM level and specified GM level is not higher than current gm level targetSecurity = targetPlayer->GetSession()->GetSecurity(); - if(!accmgr.GetName(targetAccountId,targetAccountName)) + if(targetSecurity >= m_session->GetSecurity() || gm >= m_session->GetSecurity() ) { - PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str()); + SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); SetSentErrorMessage(true); return false; } - } - else + + // Decide which string to show + if(m_session->GetPlayer()!=targetPlayer) + { + PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm); + }else{ + PSendSysMessage(LANG_YOURS_SECURITY_CHANGED, m_session->GetPlayer()->GetName(), gm); + } + + loginDatabase.PExecute("UPDATE account SET gmlevel = '%d' WHERE id = '%u'", gm, targetAccountId); + return true; + }else { - /// wrong command syntax (second arg expected) + // Check for second parameter if(!arg2) return false; - + + // Check for account targetAccountName = arg1; if(!AccountMgr::normilizeString(targetAccountName)) { @@ -775,41 +789,34 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args) SetSentErrorMessage(true); return false; } + + // Check for invalid specified GM level. + gm = atoi(arg2); + if ( (gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR) ) + { + SendSysMessage(LANG_BAD_VALUE); + SetSentErrorMessage(true); + return false; + } + + targetAccountId = accmgr.GetId(arg1); + /// m_session==NULL only for console + uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE; - targetAccountId = accmgr.GetId(targetAccountName); + /// 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 = accmgr.GetSecurity(targetAccountId); - } - - int32 gm = (int32)atoi(arg2); - if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR ) - { - SendSysMessage(LANG_BAD_VALUE); - SetSentErrorMessage(true); - return false; - } - - /// m_session==NULL only for console - uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_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 - if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity ) - { - SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); - SetSentErrorMessage(true); - return false; - } + if(targetSecurity >= plSecurity || gm >= plSecurity ) + { + SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); + SetSentErrorMessage(true); + return false; + } - if(targetPlayer) - { - ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetName(), gm); - targetPlayer->GetSession()->SetSecurity(gm); + PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm); + loginDatabase.PExecute("UPDATE account SET gmlevel = '%d' WHERE id = '%u'", gm, targetAccountId); + return true; } - - PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm); - loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId); - - return true; } /// Set password for account |