1 | /* |
---|
2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
3 | * |
---|
4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "Common.h" |
---|
22 | #include "Database/DatabaseEnv.h" |
---|
23 | #include "WorldPacket.h" |
---|
24 | #include "WorldSession.h" |
---|
25 | #include "World.h" |
---|
26 | #include "Player.h" |
---|
27 | #include "Opcodes.h" |
---|
28 | #include "Chat.h" |
---|
29 | #include "MapManager.h" |
---|
30 | #include "ObjectAccessor.h" |
---|
31 | #include "Language.h" |
---|
32 | #include "AccountMgr.h" |
---|
33 | #include "SystemConfig.h" |
---|
34 | #include "Util.h" |
---|
35 | |
---|
36 | bool ChatHandler::HandleHelpCommand(const char* args) |
---|
37 | { |
---|
38 | if(!*args) |
---|
39 | return false; |
---|
40 | |
---|
41 | char* cmd = strtok((char*)args, " "); |
---|
42 | if(!cmd) |
---|
43 | return false; |
---|
44 | |
---|
45 | if(!ShowHelpForCommand(getCommandTable(), cmd)) |
---|
46 | SendSysMessage(LANG_NO_HELP_CMD); |
---|
47 | |
---|
48 | return true; |
---|
49 | } |
---|
50 | |
---|
51 | bool ChatHandler::HandleCommandsCommand(const char* args) |
---|
52 | { |
---|
53 | ShowHelpForCommand(getCommandTable(), ""); |
---|
54 | return true; |
---|
55 | } |
---|
56 | |
---|
57 | bool ChatHandler::HandleAcctCommand(const char* /*args*/) |
---|
58 | { |
---|
59 | uint32 gmlevel = m_session->GetSecurity(); |
---|
60 | PSendSysMessage(LANG_ACCOUNT_LEVEL, gmlevel); |
---|
61 | return true; |
---|
62 | } |
---|
63 | |
---|
64 | bool ChatHandler::HandleStartCommand(const char* /*args*/) |
---|
65 | { |
---|
66 | Player *chr = m_session->GetPlayer(); |
---|
67 | |
---|
68 | if(chr->isInFlight()) |
---|
69 | { |
---|
70 | SendSysMessage(LANG_YOU_IN_FLIGHT); |
---|
71 | SetSentErrorMessage(true); |
---|
72 | return false; |
---|
73 | } |
---|
74 | |
---|
75 | if(chr->isInCombat()) |
---|
76 | { |
---|
77 | SendSysMessage(LANG_YOU_IN_COMBAT); |
---|
78 | SetSentErrorMessage(true); |
---|
79 | return false; |
---|
80 | } |
---|
81 | |
---|
82 | // cast spell Stuck |
---|
83 | chr->CastSpell(chr,7355,false); |
---|
84 | return true; |
---|
85 | } |
---|
86 | |
---|
87 | bool ChatHandler::HandleInfoCommand(const char* /*args*/) |
---|
88 | { |
---|
89 | uint32 activeClientsNum = sWorld.GetActiveSessionCount(); |
---|
90 | uint32 queuedClientsNum = sWorld.GetQueuedSessionCount(); |
---|
91 | uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount(); |
---|
92 | uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount(); |
---|
93 | std::string str = secsToTimeString(sWorld.GetUptime()); |
---|
94 | |
---|
95 | PSendSysMessage(_FULLVERSION); |
---|
96 | PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum); |
---|
97 | PSendSysMessage(LANG_UPTIME, str.c_str()); |
---|
98 | |
---|
99 | return true; |
---|
100 | } |
---|
101 | |
---|
102 | bool ChatHandler::HandleDismountCommand(const char* /*args*/) |
---|
103 | { |
---|
104 | //If player is not mounted, so go out :) |
---|
105 | if (!m_session->GetPlayer( )->IsMounted()) |
---|
106 | { |
---|
107 | SendSysMessage(LANG_CHAR_NON_MOUNTED); |
---|
108 | SetSentErrorMessage(true); |
---|
109 | return false; |
---|
110 | } |
---|
111 | |
---|
112 | if(m_session->GetPlayer( )->isInFlight()) |
---|
113 | { |
---|
114 | SendSysMessage(LANG_YOU_IN_FLIGHT); |
---|
115 | SetSentErrorMessage(true); |
---|
116 | return false; |
---|
117 | } |
---|
118 | |
---|
119 | m_session->GetPlayer()->Unmount(); |
---|
120 | m_session->GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); |
---|
121 | return true; |
---|
122 | } |
---|
123 | |
---|
124 | bool ChatHandler::HandleSaveCommand(const char* /*args*/) |
---|
125 | { |
---|
126 | Player *player=m_session->GetPlayer(); |
---|
127 | |
---|
128 | // save GM account without delay and output message (testing, etc) |
---|
129 | if(m_session->GetSecurity()) |
---|
130 | { |
---|
131 | player->SaveToDB(); |
---|
132 | SendSysMessage(LANG_PLAYER_SAVED); |
---|
133 | return true; |
---|
134 | } |
---|
135 | |
---|
136 | // 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 |
---|
137 | uint32 save_interval = sWorld.getConfig(CONFIG_INTERVAL_SAVE); |
---|
138 | if(save_interval==0 || save_interval > 20*1000 && player->GetSaveTimer() <= save_interval - 20*1000) |
---|
139 | player->SaveToDB(); |
---|
140 | |
---|
141 | return true; |
---|
142 | } |
---|
143 | |
---|
144 | bool ChatHandler::HandleGMListCommand(const char* /*args*/) |
---|
145 | { |
---|
146 | bool first = true; |
---|
147 | |
---|
148 | HashMapHolder<Player>::MapType &m = HashMapHolder<Player>::GetContainer(); |
---|
149 | HashMapHolder<Player>::MapType::iterator itr = m.begin(); |
---|
150 | for(; itr != m.end(); ++itr) |
---|
151 | { |
---|
152 | if( itr->second->GetSession()->GetSecurity() && (itr->second->isGameMaster() || sWorld.getConfig(CONFIG_GM_IN_GM_LIST) ) && |
---|
153 | itr->second->IsVisibleGloballyFor(m_session->GetPlayer()) ) |
---|
154 | { |
---|
155 | if(first) |
---|
156 | { |
---|
157 | SendSysMessage(LANG_GMS_ON_SRV); |
---|
158 | first = false; |
---|
159 | } |
---|
160 | |
---|
161 | SendSysMessage(itr->second->GetName()); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | if(first) |
---|
166 | SendSysMessage(LANG_GMS_NOT_LOGGED); |
---|
167 | |
---|
168 | return true; |
---|
169 | } |
---|
170 | |
---|
171 | bool ChatHandler::HandlePasswordCommand(const char* args) |
---|
172 | { |
---|
173 | if(!*args) |
---|
174 | return false; |
---|
175 | |
---|
176 | char *old_pass = strtok ((char*)args, " "); |
---|
177 | char *new_pass = strtok (NULL, " "); |
---|
178 | char *new_pass_c = strtok (NULL, " "); |
---|
179 | |
---|
180 | if( !old_pass || !new_pass || !new_pass_c ) |
---|
181 | return false; |
---|
182 | |
---|
183 | std::string password_old = old_pass; |
---|
184 | std::string password_new = new_pass; |
---|
185 | std::string password_new_c = new_pass_c; |
---|
186 | |
---|
187 | if(!accmgr.CheckPassword(m_session->GetAccountId(), password_old) || password_new != password_new_c) |
---|
188 | { |
---|
189 | SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD); |
---|
190 | SetSentErrorMessage(true); |
---|
191 | return false; |
---|
192 | } |
---|
193 | |
---|
194 | AccountOpResult result = accmgr.ChangePassword(m_session->GetAccountId(), password_new); |
---|
195 | |
---|
196 | switch(result) |
---|
197 | { |
---|
198 | case AOR_OK: |
---|
199 | SendSysMessage(LANG_COMMAND_PASSWORD); |
---|
200 | break; |
---|
201 | default: |
---|
202 | SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD); |
---|
203 | SetSentErrorMessage(true); |
---|
204 | return false; |
---|
205 | } |
---|
206 | |
---|
207 | return true; |
---|
208 | } |
---|
209 | |
---|
210 | bool ChatHandler::HandleLockAccountCommand(const char* args) |
---|
211 | { |
---|
212 | if (!*args) |
---|
213 | { |
---|
214 | SendSysMessage(LANG_USE_BOL); |
---|
215 | return true; |
---|
216 | } |
---|
217 | |
---|
218 | std::string argstr = (char*)args; |
---|
219 | if (argstr == "on") |
---|
220 | { |
---|
221 | loginDatabase.PExecute( "UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId()); |
---|
222 | PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); |
---|
223 | return true; |
---|
224 | } |
---|
225 | |
---|
226 | if (argstr == "off") |
---|
227 | { |
---|
228 | loginDatabase.PExecute( "UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId()); |
---|
229 | PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); |
---|
230 | return true; |
---|
231 | } |
---|
232 | |
---|
233 | SendSysMessage(LANG_USE_BOL); |
---|
234 | return true; |
---|
235 | } |
---|