OregonCore  revision 3611e8a-git
Your Favourite TBC server
Level0.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "Database/DatabaseEnv.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "World.h"
23 #include "Player.h"
24 #include "Opcodes.h"
25 #include "Chat.h"
26 #include "MapManager.h"
27 #include "ObjectMgr.h"
28 #include "ObjectAccessor.h"
29 #include "Language.h"
30 #include "AccountMgr.h"
31 #include "SystemConfig.h"
32 #include "revision.h"
33 #include "Util.h"
34 #include "Spell.h"
35 
36 bool ChatHandler::HandleHelpCommand(const char* args)
37 {
38  char* cmd = strtok((char*)args, " ");
39  if (!cmd)
40  {
43  }
44  else
45  {
48  }
49 
50  return true;
51 }
52 
53 bool ChatHandler::HandleCommandsCommand(const char* /*args*/)
54 {
56  return true;
57 }
58 
59 bool ChatHandler::HandleAccountCommand(const char* /*args*/)
60 {
61  uint32 gmlevel = m_session->GetSecurity();
63  return true;
64 }
65 
66 bool ChatHandler::HandleStartCommand(const char* /*args*/)
67 {
68  Player* chr = m_session->GetPlayer();
69 
70  if (chr->isInFlight())
71  {
73  SetSentErrorMessage(true);
74  return false;
75  }
76 
77  if (chr->IsInCombat())
78  {
80  SetSentErrorMessage(true);
81  return false;
82  }
83 
84  // Teleport to starting location
85  chr->TeleportTo(chr->GetStartPosition());
86  return true;
87 }
88 
89 bool ChatHandler::HandleServerInfoCommand(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  uint32 updateTime = sWorld.GetUpdateTime();
97 
99  //if (m_session)
100  // full = _FULLVERSION(REVISION_DATE,REVISION_TIME,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
101  //else
102  // full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_ID);
103 
104  //SendSysMessage(full);
105  //PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion());
106  PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
107  PSendSysMessage(LANG_UPTIME, str.c_str());
108  PSendSysMessage(LANG_UPDATE_DIFF, updateTime);
110  if (sWorld.IsShuttingDown())
111  PSendSysMessage(LANG_SHUTDOWN_TIMELEFT, secsToTimeString(sWorld.GetShutDownTimeLeft()).c_str());
112 
113  return true;
114 }
115 
116 bool ChatHandler::HandleDismountCommand(const char* /*args*/)
117 {
118  //If player is not mounted, so go out :)
119  if (!m_session->GetPlayer()->IsMounted())
120  {
122  SetSentErrorMessage(true);
123  return false;
124  }
125 
126  if (m_session->GetPlayer()->isInFlight())
127  {
129  SetSentErrorMessage(true);
130  return false;
131  }
132 
135  return true;
136 }
137 
138 bool ChatHandler::HandleSaveCommand(const char* /*args*/)
139 {
140  Player* player = m_session->GetPlayer();
141 
142  // save GM account without delay and output message (testing, etc)
143  if (m_session->GetSecurity())
144  {
145  if (Player* target = getSelectedPlayer())
146  target->SaveToDB();
147  else
148  player->SaveToDB();
150  return true;
151  }
152 
153  // 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
154  uint32 save_interval = sWorld.getConfig(CONFIG_INTERVAL_SAVE);
155  if (save_interval == 0 || (save_interval > 20 * IN_MILLISECONDS && player->GetSaveTimer() <= save_interval - 20 * IN_MILLISECONDS))
156  player->SaveToDB();
157 
158  return true;
159 }
160 
161 bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
162 {
163  bool first = true;
164 
167  for (HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
168  {
169  if (itr->second->GetSession()->GetSecurity() &&
170  (itr->second->IsGameMaster() || sWorld.getConfig(CONFIG_GM_IN_GM_LIST)) &&
171  (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())))
172  {
173  if (first)
174  {
176  first = false;
177  }
178 
179  SendSysMessage(itr->second->GetName());
180  }
181  }
182 
183  if (first)
185 
186  return true;
187 }
188 
190 {
191  if (!*args)
192  return false;
193 
194  char* old_pass = strtok ((char*)args, " ");
195  char* new_pass = strtok (NULL, " ");
196  char* new_pass_c = strtok (NULL, " ");
197 
198  if (!old_pass || !new_pass || !new_pass_c)
199  return false;
200 
201  std::string password_old = old_pass;
202  std::string password_new = new_pass;
203  std::string password_new_c = new_pass_c;
204 
205  if (strcmp(new_pass, new_pass_c) != 0)
206  {
208  SetSentErrorMessage (true);
209  return false;
210  }
211 
212  if (!sAccountMgr->CheckPassword (m_session->GetAccountId(), password_old))
213  {
215  SetSentErrorMessage (true);
216  return false;
217  }
218 
219  AccountOpResult result = sAccountMgr->ChangePassword(m_session->GetAccountId(), password_new);
220 
221  switch (result)
222  {
223  case AOR_OK:
225  break;
226  case AOR_PASS_TOO_LONG:
228  SetSentErrorMessage(true);
229  return false;
230  case AOR_NAME_NOT_EXIST: // not possible case, don't want get account name for output
231  default:
233  SetSentErrorMessage(true);
234  return false;
235  }
236 
237  return true;
238 }
239 
241 {
242  if (!*args)
243  {
245  return true;
246  }
247 
248  std::string argstr = (char*)args;
249  if (argstr == "on")
250  {
251  LoginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'", m_session->GetAccountId());
253  return true;
254  }
255 
256  if (argstr == "off")
257  {
258  LoginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'", m_session->GetAccountId());
260  return true;
261  }
262 
264  return true;
265 }
266 
267 // Display the 'Message of the day' for the realm
268 bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
269 {
271  return true;
272 }
273 
275 {
277  return true;
278 
280  return true;
281 }
282 
284 {
286  return true;
287 
288  Player* buddy = sObjectMgr.GetRAFLinkedBuddyForPlayer(m_session->GetPlayer());
289  if (!buddy || !buddy->IsInWorld())
290  {
291  PSendSysMessage("Couldn't find you friend");
292  return true;
293  }
294 
295  PackedGuid guid = buddy->GetPackGUID();
296 
297  WorldPacket data(CMSG_GRANT_LEVEL, guid.size());
298  data << guid;
300 
301  return true;
302 }
void SetSentErrorMessage(bool val)
Definition: Chat.h:590
WorldLocation GetStartPosition() const
Definition: Player.cpp:1824
bool HandleRAFSummonCommand(const char *args)
Definition: Level0.cpp:274
void SaveToDB()
Definition: Player.cpp:16219
HashMapHolder< Player >::MapType & GetPlayers()
bool ShowHelpForCommand(ChatCommand *table, const char *cmd)
Definition: Chat.cpp:1457
void Dismount()
Definition: Unit.cpp:9229
bool HandleAccountPasswordCommand(const char *args)
Definition: Level0.cpp:189
void RemoveSpellsCausingAura(AuraType auraType)
Definition: Unit.cpp:648
bool IsInCombat() const
Definition: Unit.h:1318
virtual void SendSysMessage(const char *str)
Definition: Chat.cpp:787
uint32 GetAccountId() const
Definition: WorldSession.h:100
UNORDERED_MAP< uint64, T * > MapType
Player * GetPlayer() const
Definition: WorldSession.h:104
WorldSession * m_session
Definition: Chat.h:593
#define sObjectMgr
Definition: ObjectMgr.h:1285
uint32 GetSaveTimer() const
Definition: Player.h:2433
bool HandleHelpCommand(const char *args)
Definition: Level0.cpp:36
bool HandleDismountCommand(const char *args)
Definition: Level0.cpp:116
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Definition: Player.cpp:1556
bool HandleAccountLockCommand(const char *args)
Definition: Level0.cpp:240
const bool & IsInWorld() const
Definition: Object.h:129
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition: Chat.cpp:855
DatabaseType LoginDatabase
Accessor to the realm/login database.
Definition: Main.cpp:55
bool HandleSaveCommand(const char *args)
Definition: Level0.cpp:138
bool HandleGMListIngameCommand(const char *args)
Definition: Level0.cpp:161
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1174
size_t size() const
Definition: ObjectGuid.h:314
AccountOpResult
Definition: AccountMgr.h:26
PackedGuid const & GetPackGUID() const
Definition: Object.h:172
bool HandleServerMotdCommand(const char *args)
Definition: Level0.cpp:268
bool HandleServerInfoCommand(const char *args)
Definition: Level0.cpp:89
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
#define sAccountMgr
Definition: AccountMgr.h:60
#define _FULLVERSION
Definition: SystemConfig.h:40
void HandleGrantLevel(WorldPacket &recv_data)
std::string secsToTimeString(uint32 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:148
static ChatCommand * getCommandTable()
Definition: Chat.cpp:38
Player * getSelectedPlayer()
Definition: Chat.cpp:1593
bool HandleRAFGrantLevelCommand(const char *args)
Definition: Level0.cpp:283
bool HandleStartCommand(const char *args)
Definition: Level0.cpp:66
bool IsMounted() const
Definition: Unit.h:1173
bool HandleAccountCommand(const char *args)
Definition: Level0.cpp:59
#define sWorld
Definition: World.h:860
void uint32 GetSecurity() const
Definition: WorldSession.h:96
bool isInFlight() const
Definition: Unit.h:1308
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Player.h:922
bool HandleCommandsCommand(const char *args)
Definition: Level0.cpp:53