[8577] Remove redundent #include "ObjectAccessor.h"
[getmangos.git] / src / game / Level0.cpp
blob8f5b4b5adf13b5ed55cf349d66002b90211bad4b
1 /*
2 * Copyright (C) 2005-2009 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 "World.h"
22 #include "Player.h"
23 #include "Opcodes.h"
24 #include "Chat.h"
25 #include "Language.h"
26 #include "AccountMgr.h"
27 #include "SystemConfig.h"
28 #include "revision.h"
29 #include "revision_nr.h"
30 #include "Util.h"
32 bool ChatHandler::HandleHelpCommand(const char* args)
34 char* cmd = strtok((char*)args, " ");
35 if(!cmd)
37 ShowHelpForCommand(getCommandTable(), "help");
38 ShowHelpForCommand(getCommandTable(), "");
40 else
42 if(!ShowHelpForCommand(getCommandTable(), cmd))
43 SendSysMessage(LANG_NO_HELP_CMD);
46 return true;
49 bool ChatHandler::HandleCommandsCommand(const char* /*args*/)
51 ShowHelpForCommand(getCommandTable(), "");
52 return true;
55 bool ChatHandler::HandleAccountCommand(const char* /*args*/)
57 AccountTypes gmlevel = m_session->GetSecurity();
58 PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmlevel));
59 return true;
62 bool ChatHandler::HandleStartCommand(const char* /*args*/)
64 Player *chr = m_session->GetPlayer();
66 if(chr->isInFlight())
68 SendSysMessage(LANG_YOU_IN_FLIGHT);
69 SetSentErrorMessage(true);
70 return false;
73 if(chr->isInCombat())
75 SendSysMessage(LANG_YOU_IN_COMBAT);
76 SetSentErrorMessage(true);
77 return false;
80 // cast spell Stuck
81 chr->CastSpell(chr,7355,false);
82 return true;
85 bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
87 uint32 activeClientsNum = sWorld.GetActiveSessionCount();
88 uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
89 uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
90 uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
91 std::string str = secsToTimeString(sWorld.GetUptime());
93 char const* full;
94 if(m_session)
95 full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
96 else
97 full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID);
99 SendSysMessage(full);
100 PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion());
101 PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion());
102 PSendSysMessage(LANG_USING_EVENT_AI,sWorld.GetCreatureEventAIVersion());
103 PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
104 PSendSysMessage(LANG_UPTIME, str.c_str());
106 return true;
109 bool ChatHandler::HandleDismountCommand(const char* /*args*/)
111 //If player is not mounted, so go out :)
112 if (!m_session->GetPlayer( )->IsMounted())
114 SendSysMessage(LANG_CHAR_NON_MOUNTED);
115 SetSentErrorMessage(true);
116 return false;
119 if(m_session->GetPlayer( )->isInFlight())
121 SendSysMessage(LANG_YOU_IN_FLIGHT);
122 SetSentErrorMessage(true);
123 return false;
126 m_session->GetPlayer()->Unmount();
127 m_session->GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
128 return true;
131 bool ChatHandler::HandleSaveCommand(const char* /*args*/)
133 Player *player=m_session->GetPlayer();
135 // save GM account without delay and output message (testing, etc)
136 if(m_session->GetSecurity() > SEC_PLAYER)
138 player->SaveToDB();
139 SendSysMessage(LANG_PLAYER_SAVED);
140 return true;
143 // 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
144 uint32 save_interval = sWorld.getConfig(CONFIG_INTERVAL_SAVE);
145 if (save_interval==0 || (save_interval > 20*IN_MILISECONDS && player->GetSaveTimer() <= save_interval - 20*IN_MILISECONDS))
146 player->SaveToDB();
148 return true;
151 bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
153 bool first = true;
155 HashMapHolder<Player>::MapType &m = HashMapHolder<Player>::GetContainer();
156 HashMapHolder<Player>::MapType::const_iterator itr = m.begin();
157 for(; itr != m.end(); ++itr)
159 AccountTypes itr_sec = itr->second->GetSession()->GetSecurity();
160 if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= sWorld.getConfig(CONFIG_GM_LEVEL_IN_GM_LIST))) &&
161 (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())))
163 if(first)
165 SendSysMessage(LANG_GMS_ON_SRV);
166 first = false;
169 SendSysMessage(GetNameLink(itr->second).c_str());
173 if(first)
174 SendSysMessage(LANG_GMS_NOT_LOGGED);
176 return true;
179 bool ChatHandler::HandleAccountPasswordCommand(const char* args)
181 if(!*args)
182 return false;
184 char *old_pass = strtok ((char*)args, " ");
185 char *new_pass = strtok (NULL, " ");
186 char *new_pass_c = strtok (NULL, " ");
188 if (!old_pass || !new_pass || !new_pass_c)
189 return false;
191 std::string password_old = old_pass;
192 std::string password_new = new_pass;
193 std::string password_new_c = new_pass_c;
195 if (password_new != password_new_c)
197 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
198 SetSentErrorMessage (true);
199 return false;
202 if (!accmgr.CheckPassword (m_session->GetAccountId(), password_old))
204 SendSysMessage (LANG_COMMAND_WRONGOLDPASSWORD);
205 SetSentErrorMessage (true);
206 return false;
209 AccountOpResult result = accmgr.ChangePassword(m_session->GetAccountId(), password_new);
211 switch(result)
213 case AOR_OK:
214 SendSysMessage(LANG_COMMAND_PASSWORD);
215 break;
216 case AOR_PASS_TOO_LONG:
217 SendSysMessage(LANG_PASSWORD_TOO_LONG);
218 SetSentErrorMessage(true);
219 return false;
220 case AOR_NAME_NOT_EXIST: // not possible case, don't want get account name for output
221 default:
222 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
223 SetSentErrorMessage(true);
224 return false;
227 return true;
230 bool ChatHandler::HandleAccountLockCommand(const char* args)
232 if (!*args)
234 SendSysMessage(LANG_USE_BOL);
235 return true;
238 std::string argstr = (char*)args;
239 if (argstr == "on")
241 loginDatabase.PExecute( "UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
242 PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
243 return true;
246 if (argstr == "off")
248 loginDatabase.PExecute( "UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
249 PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
250 return true;
253 SendSysMessage(LANG_USE_BOL);
254 return true;
257 /// Display the 'Message of the day' for the realm
258 bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
260 PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
261 return true;