[8483] Implement glyph 43361.
[getmangos.git] / src / game / Level0.cpp
blob937f1b9cc9594925c917e59334c5e5f7d9e47d31
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 "ObjectAccessor.h"
26 #include "Language.h"
27 #include "AccountMgr.h"
28 #include "SystemConfig.h"
29 #include "revision.h"
30 #include "revision_nr.h"
31 #include "Util.h"
33 bool ChatHandler::HandleHelpCommand(const char* args)
35 char* cmd = strtok((char*)args, " ");
36 if(!cmd)
38 ShowHelpForCommand(getCommandTable(), "help");
39 ShowHelpForCommand(getCommandTable(), "");
41 else
43 if(!ShowHelpForCommand(getCommandTable(), cmd))
44 SendSysMessage(LANG_NO_HELP_CMD);
47 return true;
50 bool ChatHandler::HandleCommandsCommand(const char* /*args*/)
52 ShowHelpForCommand(getCommandTable(), "");
53 return true;
56 bool ChatHandler::HandleAccountCommand(const char* /*args*/)
58 AccountTypes gmlevel = m_session->GetSecurity();
59 PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmlevel));
60 return true;
63 bool ChatHandler::HandleStartCommand(const char* /*args*/)
65 Player *chr = m_session->GetPlayer();
67 if(chr->isInFlight())
69 SendSysMessage(LANG_YOU_IN_FLIGHT);
70 SetSentErrorMessage(true);
71 return false;
74 if(chr->isInCombat())
76 SendSysMessage(LANG_YOU_IN_COMBAT);
77 SetSentErrorMessage(true);
78 return false;
81 // cast spell Stuck
82 chr->CastSpell(chr,7355,false);
83 return true;
86 bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
88 uint32 activeClientsNum = sWorld.GetActiveSessionCount();
89 uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
90 uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
91 uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
92 std::string str = secsToTimeString(sWorld.GetUptime());
94 char const* full;
95 if(m_session)
96 full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
97 else
98 full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID);
100 SendSysMessage(full);
101 PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion());
102 PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion());
103 PSendSysMessage(LANG_USING_EVENT_AI,sWorld.GetCreatureEventAIVersion());
104 PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
105 PSendSysMessage(LANG_UPTIME, str.c_str());
107 return true;
110 bool ChatHandler::HandleDismountCommand(const char* /*args*/)
112 //If player is not mounted, so go out :)
113 if (!m_session->GetPlayer( )->IsMounted())
115 SendSysMessage(LANG_CHAR_NON_MOUNTED);
116 SetSentErrorMessage(true);
117 return false;
120 if(m_session->GetPlayer( )->isInFlight())
122 SendSysMessage(LANG_YOU_IN_FLIGHT);
123 SetSentErrorMessage(true);
124 return false;
127 m_session->GetPlayer()->Unmount();
128 m_session->GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
129 return true;
132 bool ChatHandler::HandleSaveCommand(const char* /*args*/)
134 Player *player=m_session->GetPlayer();
136 // save GM account without delay and output message (testing, etc)
137 if(m_session->GetSecurity() > SEC_PLAYER)
139 player->SaveToDB();
140 SendSysMessage(LANG_PLAYER_SAVED);
141 return true;
144 // 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
145 uint32 save_interval = sWorld.getConfig(CONFIG_INTERVAL_SAVE);
146 if (save_interval==0 || (save_interval > 20*IN_MILISECONDS && player->GetSaveTimer() <= save_interval - 20*IN_MILISECONDS))
147 player->SaveToDB();
149 return true;
152 bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
154 bool first = true;
156 HashMapHolder<Player>::MapType &m = HashMapHolder<Player>::GetContainer();
157 HashMapHolder<Player>::MapType::const_iterator itr = m.begin();
158 for(; itr != m.end(); ++itr)
160 AccountTypes itr_sec = itr->second->GetSession()->GetSecurity();
161 if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= sWorld.getConfig(CONFIG_GM_LEVEL_IN_GM_LIST))) &&
162 (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())))
164 if(first)
166 SendSysMessage(LANG_GMS_ON_SRV);
167 first = false;
170 SendSysMessage(GetNameLink(itr->second).c_str());
174 if(first)
175 SendSysMessage(LANG_GMS_NOT_LOGGED);
177 return true;
180 bool ChatHandler::HandleAccountPasswordCommand(const char* args)
182 if(!*args)
183 return false;
185 char *old_pass = strtok ((char*)args, " ");
186 char *new_pass = strtok (NULL, " ");
187 char *new_pass_c = strtok (NULL, " ");
189 if (!old_pass || !new_pass || !new_pass_c)
190 return false;
192 std::string password_old = old_pass;
193 std::string password_new = new_pass;
194 std::string password_new_c = new_pass_c;
196 if (password_new != password_new_c)
198 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
199 SetSentErrorMessage (true);
200 return false;
203 if (!accmgr.CheckPassword (m_session->GetAccountId(), password_old))
205 SendSysMessage (LANG_COMMAND_WRONGOLDPASSWORD);
206 SetSentErrorMessage (true);
207 return false;
210 AccountOpResult result = accmgr.ChangePassword(m_session->GetAccountId(), password_new);
212 switch(result)
214 case AOR_OK:
215 SendSysMessage(LANG_COMMAND_PASSWORD);
216 break;
217 case AOR_PASS_TOO_LONG:
218 SendSysMessage(LANG_PASSWORD_TOO_LONG);
219 SetSentErrorMessage(true);
220 return false;
221 case AOR_NAME_NOT_EXIST: // not possible case, don't want get account name for output
222 default:
223 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
224 SetSentErrorMessage(true);
225 return false;
228 return true;
231 bool ChatHandler::HandleAccountLockCommand(const char* args)
233 if (!*args)
235 SendSysMessage(LANG_USE_BOL);
236 return true;
239 std::string argstr = (char*)args;
240 if (argstr == "on")
242 loginDatabase.PExecute( "UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
243 PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
244 return true;
247 if (argstr == "off")
249 loginDatabase.PExecute( "UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
250 PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
251 return true;
254 SendSysMessage(LANG_USE_BOL);
255 return true;
258 /// Display the 'Message of the day' for the realm
259 bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
261 PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
262 return true;