root/trunk/src/game/Level0.cpp @ 123

Revision 112, 7.0 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge CLI Commands with regular commands and give them level4 access. sec_console. Source mangos - thanks to ogeraisi for the amalgamated patch.
* Redid/Fixed/Added some lang strings.
* As usual remember this is a trunk rev so stability only guaranteed on northern countries of Mars and western parts of Pluto. No warranties outside the solar system, sorry :( . Check with your local government or dictator on regulations regarding export.

Original author: KingPin?
Date: 2008-10-26 13:32:42-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.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
36bool ChatHandler::HandleHelpCommand(const char* args)
37{
38        char* cmd = strtok((char*)args, " ");
39    if(!cmd)
40        {
41                ShowHelpForCommand(getCommandTable(), "help");
42                ShowHelpForCommand(getCommandTable(), "");
43        }
44        else
45        {
46                if(!ShowHelpForCommand(getCommandTable(), cmd))
47                        SendSysMessage(LANG_NO_HELP_CMD);
48        }
49
50    return true;
51}
52
53bool ChatHandler::HandleCommandsCommand(const char* args)
54{
55    ShowHelpForCommand(getCommandTable(), "");
56    return true;
57}
58
59bool ChatHandler::HandleAccountCommand(const char* /*args*/)
60{
61    uint32 gmlevel = m_session->GetSecurity();
62    PSendSysMessage(LANG_ACCOUNT_LEVEL, gmlevel);
63    return true;
64}
65
66bool ChatHandler::HandleStartCommand(const char* /*args*/)
67{
68    Player *chr = m_session->GetPlayer();
69
70    if(chr->isInFlight())
71    {
72        SendSysMessage(LANG_YOU_IN_FLIGHT);
73        SetSentErrorMessage(true);
74        return false;
75    }
76
77    if(chr->isInCombat())
78    {
79        SendSysMessage(LANG_YOU_IN_COMBAT);
80        SetSentErrorMessage(true);
81        return false;
82    }
83
84    // cast spell Stuck
85    chr->CastSpell(chr,7355,false);
86    return true;
87}
88
89bool ChatHandler::HandleInfoCommand(const char* /*args*/)
90{
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());
96
97    PSendSysMessage(_FULLVERSION);
98    PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
99    PSendSysMessage(LANG_UPTIME, str.c_str());
100
101    return true;
102}
103
104bool ChatHandler::HandleDismountCommand(const char* /*args*/)
105{
106    //If player is not mounted, so go out :)
107    if (!m_session->GetPlayer( )->IsMounted())
108    {
109        SendSysMessage(LANG_CHAR_NON_MOUNTED);
110        SetSentErrorMessage(true);
111        return false;
112    }
113
114    if(m_session->GetPlayer( )->isInFlight())
115    {
116        SendSysMessage(LANG_YOU_IN_FLIGHT);
117        SetSentErrorMessage(true);
118        return false;
119    }
120
121    m_session->GetPlayer()->Unmount();
122    m_session->GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
123    return true;
124}
125
126bool ChatHandler::HandleSaveCommand(const char* /*args*/)
127{
128    Player *player=m_session->GetPlayer();
129
130    // save GM account without delay and output message (testing, etc)
131    if(m_session->GetSecurity())
132    {
133        player->SaveToDB();
134        SendSysMessage(LANG_PLAYER_SAVED);
135        return true;
136    }
137
138    // 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
139    uint32 save_interval = sWorld.getConfig(CONFIG_INTERVAL_SAVE);
140    if(save_interval==0 || save_interval > 20*1000 && player->GetSaveTimer() <= save_interval - 20*1000)
141        player->SaveToDB();
142
143    return true;
144}
145
146bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
147{
148    bool first = true;
149
150    HashMapHolder<Player>::MapType &m = HashMapHolder<Player>::GetContainer();
151    HashMapHolder<Player>::MapType::iterator itr = m.begin();
152    for(; itr != m.end(); ++itr)
153    {
154        if (itr->second->GetSession()->GetSecurity() &&
155                        (itr->second->isGameMaster() || sWorld.getConfig(CONFIG_GM_IN_GM_LIST)) &&
156                        (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())) )
157        {
158            if(first)
159            {
160                SendSysMessage(LANG_GMS_ON_SRV);
161                first = false;
162            }
163
164            SendSysMessage(itr->second->GetName());
165        }
166    }
167
168    if(first)
169        SendSysMessage(LANG_GMS_NOT_LOGGED);
170
171    return true;
172}
173
174bool ChatHandler::HandlePasswordCommand(const char* args)
175{
176    if(!*args)
177        return false;
178
179    char *old_pass = strtok ((char*)args, " ");
180    char *new_pass = strtok (NULL, " ");
181    char *new_pass_c  = strtok (NULL, " ");
182
183    if (!old_pass || !new_pass || !new_pass_c)
184        return false;
185
186    std::string password_old = old_pass;
187    std::string password_new = new_pass;
188    std::string password_new_c = new_pass_c;
189
190    if (password_new != password_new_c)
191    {
192        SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
193                SetSentErrorMessage (true);
194                return false;
195        }
196
197        if (!accmgr.CheckPassword (m_session->GetAccountId(), password_old))
198        {
199                SendSysMessage (LANG_COMMAND_WRONGOLDPASSWORD);
200                SetSentErrorMessage (true);
201        return false;
202    }
203
204    AccountOpResult result = accmgr.ChangePassword(m_session->GetAccountId(), password_new);
205
206    switch(result)
207    {
208        case AOR_OK:
209            SendSysMessage(LANG_COMMAND_PASSWORD);
210            break;
211                case AOR_PASS_TOO_LONG:
212                        SendSysMessage(LANG_PASSWORD_TOO_LONG);
213                        SetSentErrorMessage(true);
214                        return false;
215                case AOR_NAME_NOT_EXIST:                            // not possible case, don't want get account name for output
216        default:
217            SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
218            SetSentErrorMessage(true);
219            return false;
220    }
221
222    return true;
223}
224
225bool ChatHandler::HandleLockAccountCommand(const char* args)
226{
227    if (!*args)
228    {
229        SendSysMessage(LANG_USE_BOL);
230        return true;
231    }
232
233    std::string argstr = (char*)args;
234    if (argstr == "on")
235    {
236        loginDatabase.PExecute( "UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
237        PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
238        return true;
239    }
240
241    if (argstr == "off")
242    {
243        loginDatabase.PExecute( "UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
244        PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
245        return true;
246    }
247
248    SendSysMessage(LANG_USE_BOL);
249    return true;
250}
251
252/// Display the 'Message of the day' for the realm
253bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
254{
255        PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
256        return true;
257}
Note: See TracBrowser for help on using the browser.