2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
28 #include "MapManager.h"
29 #include "ObjectAccessor.h"
32 bool ChatHandler::ShowHelpForCommand(ChatCommand
*table
, const char* cmd
)
34 for(uint32 i
= 0; table
[i
].Name
!= NULL
; i
++)
36 if(!hasStringAbbr(table
[i
].Name
, cmd
))
39 if(m_session
->GetSecurity() < table
[i
].SecurityLevel
)
42 if(table
[i
].ChildCommands
!= NULL
)
44 cmd
= strtok(NULL
, " ");
45 if(cmd
&& ShowHelpForCommand(table
[i
].ChildCommands
, cmd
))
49 if(table
[i
].Help
== "")
51 SendSysMessage(LANG_NO_HELP_CMD
);
55 SendSysMultilineMessage(table
[i
].Help
.c_str());
63 bool ChatHandler::HandleHelpCommand(const char* args
)
68 char* cmd
= strtok((char*)args
, " ");
72 if(!ShowHelpForCommand(getCommandTable(), cmd
))
74 SendSysMessage(LANG_NO_CMD
);
80 bool ChatHandler::HandleCommandsCommand(const char* args
)
82 ChatCommand
*table
= getCommandTable();
84 SendSysMessage(LANG_AVIABLE_CMD
);
86 for(uint32 i
= 0; table
[i
].Name
!= NULL
; i
++)
88 if(*args
&& !hasStringAbbr(table
[i
].Name
, (char*)args
))
91 if(m_session
->GetSecurity() < table
[i
].SecurityLevel
)
94 SendSysMessage(table
[i
].Name
);
100 bool ChatHandler::HandleAcctCommand(const char* args
)
102 uint32 gmlevel
= m_session
->GetSecurity();
103 PSendSysMessage(LANG_ACCOUNT_LEVEL
, gmlevel
);
107 bool ChatHandler::HandleStartCommand(const char* args
)
109 Player
*chr
= m_session
->GetPlayer();
111 if(chr
->isInFlight())
113 SendSysMessage(LANG_YOU_IN_FLIGHT
);
117 if(chr
->isInCombat())
119 SendSysMessage(LANG_YOU_IN_COMBAT
);
123 // not let used .start command as free replacement for hearthstone
124 if(chr
->HaveSpellCooldown(8690))
126 SendSysMessage(LANG_YOU_USED_IT_RECENTLY
);
130 chr
->SetUInt32Value(PLAYER_FARSIGHT
, 0x01);
132 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(chr
->getRace(), chr
->getClass());
134 chr
->TeleportTo(info
->mapId
, info
->positionX
, info
->positionY
,info
->positionZ
,chr
->GetOrientation());
136 chr
->SetUInt32Value(PLAYER_FARSIGHT
, 0x00);
138 // set hearthstone cooldown
139 chr
->AddSpellCooldown(8690,time(NULL
)+3600);
144 bool ChatHandler::HandleInfoCommand(const char* args
)
146 uint32 clientsNum
= sWorld
.GetSessionCount();
148 PSendSysMessage(LANG_CONNECTED_USERS
, (int) clientsNum
);
153 bool ChatHandler::HandleDismountCommand(const char* args
)
156 //If player is not mounted, so go out :)
157 if (!m_session
->GetPlayer( )->IsMounted())
159 SendSysMessage(LANG_CHAR_NON_MOUNTED
);
163 if(m_session
->GetPlayer( )->isInFlight())
165 SendSysMessage(LANG_YOU_IN_FLIGHT
);
169 m_session
->GetPlayer( )->Unmount();
170 m_session
->GetPlayer( )->SetPlayerSpeed(MOVE_RUN
, 7.5, true);
174 bool ChatHandler::HandleSaveCommand(const char* args
)
176 m_session
->GetPlayer()->SaveToDB();
177 SendSysMessage(LANG_PLAYER_SAVED
);
181 bool ChatHandler::HandleGMListCommand(const char* args
)
185 ObjectAccessor::PlayersMapType
&m(ObjectAccessor::Instance().GetPlayers());
186 for(ObjectAccessor::PlayersMapType::iterator itr
= m
.begin(); itr
!= m
.end(); ++itr
)
188 if(itr
->second
->GetSession()->GetSecurity() && itr
->second
->isVisibleFor(m_session
->GetPlayer()))
191 SendSysMessage(LANG_GMS_ON_SRV
);
193 SendSysMessage(itr
->second
->GetName());
200 SendSysMessage(LANG_GMS_NOT_LOGGED
);
205 bool ChatHandler::HandleShowHonor(const char* args
)
207 uint32 dishonorable_kills
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LIFETIME_DISHONORABLE_KILLS
);
208 uint32 honorable_kills
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS
);
209 uint32 highest_rank
= (m_session
->GetPlayer()->GetHonorHighestRank() < 16)? m_session
->GetPlayer()->GetHonorHighestRank() : 0;
210 uint32 today_honorable_kills
= (uint16
)m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_SESSION_KILLS
);
211 uint32 today_dishonorable_kills
= (uint16
)(m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_SESSION_KILLS
)>>16);
212 uint32 yestarday_kills
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_YESTERDAY_KILLS
);
213 uint32 yestarday_honor
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
);
214 uint32 this_week_kills
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_THIS_WEEK_KILLS
);
215 uint32 this_week_honor
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_THIS_WEEK_CONTRIBUTION
);
216 uint32 last_week_kills
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LAST_WEEK_KILLS
);
217 uint32 last_week_honor
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LAST_WEEK_CONTRIBUTION
);
218 uint32 last_week_standing
= m_session
->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LAST_WEEK_RANK
);
220 std::string alliance_ranks
[] =
226 LANG_ALI_MASTER_SERGEANT
,
227 LANG_ALI_SERGEANT_MAJOR
,
229 LANG_ALI_KNIGHT_LIEUTENANT
,
230 LANG_ALI_KNIGHT_CAPTAIN
,
231 LANG_ALI_KNIGHT_CHAMPION
,
232 LANG_ALI_LIEUTENANT_COMMANDER
,
235 LANG_ALI_FIELD_MARSHAL
,
236 LANG_ALI_GRAND_MARSHAL
,
239 std::string horde_ranks
[] =
245 LANG_HRD_SENIOR_SERGEANT
,
246 LANG_HRD_FIRST_SERGEANT
,
247 LANG_HRD_STONE_GUARD
,
248 LANG_HRD_BLOOD_GUARD
,
252 LANG_HRD_LIEUTENANT_GENERAL
,
255 LANG_HRD_HIGH_WARLORD
,
258 std::string rank_name
;
259 std::string hrank_name
;
261 if ( m_session
->GetPlayer()->GetTeam() == ALLIANCE
)
263 rank_name
= alliance_ranks
[ m_session
->GetPlayer()->CalculateHonorRank( m_session
->GetPlayer()->GetTotalHonor() ) ];
264 hrank_name
= alliance_ranks
[ highest_rank
];
267 if ( m_session
->GetPlayer()->GetTeam() == HORDE
)
269 rank_name
= horde_ranks
[ m_session
->GetPlayer()->CalculateHonorRank( m_session
->GetPlayer()->GetTotalHonor() ) ];
270 hrank_name
= horde_ranks
[ highest_rank
];
274 rank_name
= LANG_NO_RANK
;
277 PSendSysMessage(LANG_RANK
, rank_name
.c_str(), m_session
->GetPlayer()->GetName(), m_session
->GetPlayer()->CalculateHonorRank( m_session
->GetPlayer()->GetTotalHonor() ));
278 PSendSysMessage(LANG_HONOR_TODAY
, today_honorable_kills
, today_dishonorable_kills
);
279 PSendSysMessage(LANG_HONOR_YESTERDAY
, yestarday_kills
, yestarday_honor
);
280 PSendSysMessage(LANG_HONOR_THIS_WEEK
, this_week_kills
, this_week_honor
);
281 PSendSysMessage(LANG_HONOR_LAST_WEEK
, last_week_kills
, last_week_honor
, last_week_standing
);
282 PSendSysMessage(LANG_HONOR_LIFE
, honorable_kills
, dishonorable_kills
, highest_rank
, hrank_name
.c_str());