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

Revision 2, 6.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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