[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / Level0.cpp
blobb6012d47ccf678bf7b89f803ae5ff86d7f1e6c8d
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "Player.h"
25 #include "Opcodes.h"
26 #include "Chat.h"
27 #include "MapManager.h"
28 #include "ObjectAccessor.h"
29 #include "Language.h"
30 #include "AccountMgr.h"
31 #include "SystemConfig.h"
32 #include "revision.h"
33 #include "revision_nr.h"
34 #include "Util.h"
36 bool ChatHandler::HandleHelpCommand(const char* args)
38 char* cmd = strtok((char*)args, " ");
39 if(!cmd)
41 ShowHelpForCommand(getCommandTable(), "help");
42 ShowHelpForCommand(getCommandTable(), "");
44 else
46 if(!ShowHelpForCommand(getCommandTable(), cmd))
47 SendSysMessage(LANG_NO_HELP_CMD);
50 return true;
53 bool ChatHandler::HandleCommandsCommand(const char* /*args*/)
55 ShowHelpForCommand(getCommandTable(), "");
56 return true;
59 bool ChatHandler::HandleAccountCommand(const char* /*args*/)
61 uint32 gmlevel = m_session->GetSecurity();
62 PSendSysMessage(LANG_ACCOUNT_LEVEL, gmlevel);
63 return true;
66 bool ChatHandler::HandleStartCommand(const char* /*args*/)
68 Player *chr = m_session->GetPlayer();
70 if(chr->isInFlight())
72 SendSysMessage(LANG_YOU_IN_FLIGHT);
73 SetSentErrorMessage(true);
74 return false;
77 if(chr->isInCombat())
79 SendSysMessage(LANG_YOU_IN_COMBAT);
80 SetSentErrorMessage(true);
81 return false;
84 // cast spell Stuck
85 chr->CastSpell(chr,7355,false);
86 return true;
89 bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
91 uint32 activeClientsNum = sWorld.GetActiveSessionCount();
92 uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
93 uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
94 uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
95 std::string str = secsToTimeString(sWorld.GetUptime());
97 char const* full;
98 if(m_session)
99 full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
100 else
101 full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID);
103 SendSysMessage(full);
104 PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion());
105 PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion());
106 PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
107 PSendSysMessage(LANG_UPTIME, str.c_str());
109 return true;
112 bool ChatHandler::HandleDismountCommand(const char* /*args*/)
114 //If player is not mounted, so go out :)
115 if (!m_session->GetPlayer( )->IsMounted())
117 SendSysMessage(LANG_CHAR_NON_MOUNTED);
118 SetSentErrorMessage(true);
119 return false;
122 if(m_session->GetPlayer( )->isInFlight())
124 SendSysMessage(LANG_YOU_IN_FLIGHT);
125 SetSentErrorMessage(true);
126 return false;
129 m_session->GetPlayer()->Unmount();
130 m_session->GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
131 return true;
134 bool ChatHandler::HandleSaveCommand(const char* /*args*/)
136 Player *player=m_session->GetPlayer();
138 // save GM account without delay and output message (testing, etc)
139 if(m_session->GetSecurity())
141 player->SaveToDB();
142 SendSysMessage(LANG_PLAYER_SAVED);
143 return true;
146 // save or plan save after 20 sec (logout delay) if current next save time more this value and _not_ output any messages to prevent cheat planning
147 uint32 save_interval = sWorld.getConfig(CONFIG_INTERVAL_SAVE);
148 if(save_interval==0 || save_interval > 20*1000 && player->GetSaveTimer() <= save_interval - 20*1000)
149 player->SaveToDB();
151 return true;
154 bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
156 bool first = true;
158 HashMapHolder<Player>::MapType &m = HashMapHolder<Player>::GetContainer();
159 HashMapHolder<Player>::MapType::iterator itr = m.begin();
160 for(; itr != m.end(); ++itr)
162 if (itr->second->GetSession()->GetSecurity() &&
163 (itr->second->isGameMaster() || sWorld.getConfig(CONFIG_GM_IN_GM_LIST)) &&
164 (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())) )
166 if(first)
168 SendSysMessage(LANG_GMS_ON_SRV);
169 first = false;
172 SendSysMessage(itr->second->GetName());
176 if(first)
177 SendSysMessage(LANG_GMS_NOT_LOGGED);
179 return true;
182 bool ChatHandler::HandlePasswordCommand(const char* args)
184 if(!*args)
185 return false;
187 char *old_pass = strtok ((char*)args, " ");
188 char *new_pass = strtok (NULL, " ");
189 char *new_pass_c = strtok (NULL, " ");
191 if (!old_pass || !new_pass || !new_pass_c)
192 return false;
194 std::string password_old = old_pass;
195 std::string password_new = new_pass;
196 std::string password_new_c = new_pass_c;
198 if (password_new != password_new_c)
200 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
201 SetSentErrorMessage (true);
202 return false;
205 if (!accmgr.CheckPassword (m_session->GetAccountId(), password_old))
207 SendSysMessage (LANG_COMMAND_WRONGOLDPASSWORD);
208 SetSentErrorMessage (true);
209 return false;
212 AccountOpResult result = accmgr.ChangePassword(m_session->GetAccountId(), password_new);
214 switch(result)
216 case AOR_OK:
217 SendSysMessage(LANG_COMMAND_PASSWORD);
218 break;
219 case AOR_PASS_TOO_LONG:
220 SendSysMessage(LANG_PASSWORD_TOO_LONG);
221 SetSentErrorMessage(true);
222 return false;
223 case AOR_NAME_NOT_EXIST: // not possible case, don't want get account name for output
224 default:
225 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
226 SetSentErrorMessage(true);
227 return false;
230 return true;
233 bool ChatHandler::HandleLockAccountCommand(const char* args)
235 if (!*args)
237 SendSysMessage(LANG_USE_BOL);
238 return true;
241 std::string argstr = (char*)args;
242 if (argstr == "on")
244 loginDatabase.PExecute( "UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
245 PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
246 return true;
249 if (argstr == "off")
251 loginDatabase.PExecute( "UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
252 PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
253 return true;
256 SendSysMessage(LANG_USE_BOL);
257 return true;
260 /// Display the 'Message of the day' for the realm
261 bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
263 PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
264 return true;