[2771] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Level1.cpp
blob86c0c61119020c5c0320691459fbd7a13478672f
1 /*
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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "Opcodes.h"
27 #include "Chat.h"
28 #include "Log.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
31 #include "Language.h"
32 #include "RedZoneDistrict.h"
33 #include "Transports.h"
35 bool ChatHandler::HandleAnnounceCommand(const char* args)
37 WorldPacket data;
39 if(!*args)
40 return false;
42 char pAnnounce[256];
44 sprintf((char*)pAnnounce, LANG_BROADCAST, args);
45 sWorld.SendWorldText(pAnnounce);
47 return true;
50 bool ChatHandler::HandleGMOnCommand(const char* args)
52 m_session->GetPlayer()->SetGameMaster(true);
53 m_session->GetPlayer()->CombatStop();
55 return true;
58 bool ChatHandler::HandleGMOffCommand(const char* args)
60 m_session->GetPlayer()->SetGameMaster(false);
62 return true;
65 bool ChatHandler::HandleVisibleCommand(const char* args)
67 int option = atoi((char*)args);
69 if (option != 0 && option != 1 || !*args)
71 SendSysMessage(LANG_USE_BOL);
72 PSendSysMessage("Your are: %s", m_session->GetPlayer()->isGMVisible() ? "visible" : "invisible");
73 return true;
76 if ( option )
78 SendSysMessage( LANG_INVISIBLE_VISIBLE );
79 m_session->GetPlayer()->SetGMVisible(true);
81 else
83 if(m_session->GetPlayer()->GetGuildId())
85 SendSysMessage( LANG_INVISIBLE_GUILD );
86 return true;
89 SendSysMessage( LANG_INVISIBLE_INVISIBLE );
90 m_session->GetPlayer()->SetGMVisible(false);
93 return true;
96 bool ChatHandler::HandleGPSCommand(const char* args)
98 Object *obj = getSelectedUnit();
100 if(!obj)
102 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
103 return true;
106 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
107 Cell cell = RedZone::GetZone(cell_val);
109 PSendSysMultilineMessage(LANG_MAP_POSITION,
110 obj->GetMapId(), obj->GetZoneId(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(),
111 obj->GetOrientation(),cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY());
113 sLog.outDebug("Player %s GPS call %s %u " LANG_MAP_POSITION, m_session->GetPlayer()->GetName(),
114 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetGUIDLow(),
115 obj->GetMapId(), obj->GetZoneId(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(),
116 obj->GetOrientation(), cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY());
118 return true;
121 bool ChatHandler::HandleNamegoCommand(const char* args)
123 if(m_session->GetPlayer()->isInFlight())
125 SendSysMessage(LANG_YOU_IN_FLIGHT);
126 return true;
129 WorldPacket data;
131 if(!*args)
132 return false;
134 std::string name = args;
135 normalizePlayerName(name);
136 sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
138 Player *chr = objmgr.GetPlayer(name.c_str());
139 if (chr)
142 if(chr->IsBeingTeleported()==true)
144 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
145 return true;
148 if(chr->isInFlight())
150 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
151 return true;
154 PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
156 char buf0[256];
157 snprintf((char*)buf0,256,LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
158 FillSystemMessageData(&data, m_session, buf0);
159 chr->GetSession()->SendPacket( &data );
161 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),
162 m_session->GetPlayer()->GetPositionX(),
163 m_session->GetPlayer()->GetPositionY(),
164 m_session->GetPlayer()->GetPositionZ(),
165 chr->GetOrientation());
167 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
169 PSendSysMessage(LANG_SUMMONING, name.c_str()," (offline)");
171 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
172 m_session->GetPlayer()->GetPositionX(),
173 m_session->GetPlayer()->GetPositionY(),
174 m_session->GetPlayer()->GetPositionZ(),m_session->GetPlayer()->GetOrientation(),guid);
176 else
177 PSendSysMessage(LANG_NO_PLAYER, args);
179 return true;
182 bool ChatHandler::HandleGonameCommand(const char* args)
184 if(m_session->GetPlayer()->isInFlight())
186 SendSysMessage(LANG_YOU_IN_FLIGHT);
187 return true;
190 if(!*args)
191 return false;
193 std::string name = args;
194 normalizePlayerName(name);
195 sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
197 Player *chr = objmgr.GetPlayer(name.c_str());
198 if (chr)
200 PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
202 if (m_session->GetPlayer()->isVisibleFor(chr))
204 char buf0[256];
205 sprintf((char*)buf0,LANG_APPEARING_TO, m_session->GetPlayer()->GetName());
207 WorldPacket data;
208 FillSystemMessageData(&data, m_session, buf0);
209 chr->GetSession()->SendPacket(&data);
212 m_session->GetPlayer()->TeleportTo(chr->GetMapId(), chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(),m_session->GetPlayer()->GetOrientation());
213 return true;
216 if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
218 PSendSysMessage(LANG_APPEARING_AT, name.c_str());
220 float x,y,z,o;
221 uint32 map;
222 if(Player::LoadPositionFromDB(map,x,y,z,o,guid))
224 m_session->GetPlayer()->TeleportTo(map, x, y, z,m_session->GetPlayer()->GetOrientation());
225 return true;
229 PSendSysMessage(LANG_NO_PLAYER, args);
231 return true;
234 bool ChatHandler::HandleRecallCommand(const char* args)
236 if(!*args)
237 return false;
239 if(m_session->GetPlayer()->isInFlight())
241 SendSysMessage(LANG_YOU_IN_FLIGHT);
242 return true;
245 if (strncmp((char*)args,"sunr",5)==0)
246 m_session->GetPlayer()->TeleportTo(1, -180.949f, -296.467f, 11.5384f,0.0f);
247 else if (strncmp((char*)args,"thun",5)==0)
248 m_session->GetPlayer()->TeleportTo(1, -1196.22f, 29.0941f, 176.949f,0.0f);
249 else if (strncmp((char*)args,"cross",6)==0)
250 m_session->GetPlayer()->TeleportTo(1, -443.128f, -2598.87f, 96.2114f,0.0f);
251 else if (strncmp((char*)args,"orgr",5)==0)
252 m_session->GetPlayer()->TeleportTo(1, 1676.21f, -4315.29f, 61.5293f,0.0f);
253 else if (strncmp((char*)args,"neth",5)==0)
254 m_session->GetPlayer()->TeleportTo(0, -10996.9f, -3427.67f, 61.996f,0.0f);
255 else if (strncmp((char*)args,"thel",5)==0)
256 m_session->GetPlayer()->TeleportTo(0, -5395.57f, -3015.79f, 327.58f,0.0f);
257 else if (strncmp((char*)args,"storm",6)==0)
258 m_session->GetPlayer()->TeleportTo(0, -8913.23f, 554.633f, 93.7944f,0.0f);
259 else if (strncmp((char*)args,"iron",5)==0)
260 m_session->GetPlayer()->TeleportTo(0, -4981.25f, -881.542f, 501.66f,0.0f);
261 else if (strncmp((char*)args,"under",6)==0)
262 m_session->GetPlayer()->TeleportTo(0, 1586.48f, 239.562f, -52.149f,0.0f);
263 else if (strncmp((char*)args,"darn",5)==0)
264 m_session->GetPlayer()->TeleportTo(1, 10037.6f, 2496.8f, 1318.4f,0.0f);
265 else if (strncmp((char*)args,"gm",5)==0)
266 m_session->GetPlayer()->TeleportTo(1, 16202.5, 16205, 1,1.15);
267 else if (strncmp((char*)args,"g",2)==0)
268 m_session->GetPlayer()->TeleportTo(1, 1335.3f, -4646.8f, 53.54f, 3.6909f);
269 else
270 return false;
272 return true;
275 bool ChatHandler::HandleModifyHPCommand(const char* args)
277 WorldPacket data;
279 // char* pHp = strtok((char*)args, " ");
280 // if (!pHp)
281 // return false;
283 // char* pHpMax = strtok(NULL, " ");
284 // if (!pHpMax)
285 // return false;
287 // int32 hpm = atoi(pHpMax);
288 // int32 hp = atoi(pHp);
290 int32 hp = atoi((char*)args);
291 int32 hpm = atoi((char*)args);
293 if (hp <= 0 || hpm <= 0 || hpm < hp)
295 SendSysMessage(LANG_BAD_VALUE);
296 return true;
299 Player *chr = getSelectedPlayer();
300 if (chr == NULL)
302 SendSysMessage(LANG_NO_CHAR_SELECTED);
303 return true;
306 PSendSysMessage(LANG_YOU_CHANGE_HP, hp, hpm, chr->GetName());
308 char buf[256];
309 sprintf((char*)buf,LANG_YOURS_HP_CHANGED, m_session->GetPlayer()->GetName(), hp, hpm);
310 FillSystemMessageData(&data, m_session, buf);
312 chr->GetSession()->SendPacket(&data);
314 chr->SetMaxHealth( hpm );
315 chr->SetHealth( hp );
317 return true;
320 bool ChatHandler::HandleModifyManaCommand(const char* args)
322 WorldPacket data;
324 // char* pmana = strtok((char*)args, " ");
325 // if (!pmana)
326 // return false;
328 // char* pmanaMax = strtok(NULL, " ");
329 // if (!pmanaMax)
330 // return false;
332 // int32 manam = atoi(pmanaMax);
333 // int32 mana = atoi(pmana);
334 int32 mana = atoi((char*)args);
335 int32 manam = atoi((char*)args);
337 if (mana <= 0 || manam <= 0 || manam < mana)
339 SendSysMessage(LANG_BAD_VALUE);
340 return true;
343 Player *chr = getSelectedPlayer();
344 if (chr == NULL)
346 SendSysMessage(LANG_NO_CHAR_SELECTED);
347 return true;
350 PSendSysMessage(LANG_YOU_CHANGE_MANA, mana, manam, chr->GetName());
352 char buf[256];
353 sprintf((char*)buf,LANG_YOURS_MANA_CHANGED, m_session->GetPlayer()->GetName(), mana, manam);
354 FillSystemMessageData(&data, m_session, buf);
356 chr->GetSession()->SendPacket(&data);
358 chr->SetMaxPower(POWER_MANA,manam );
359 chr->SetPower(POWER_MANA, mana );
361 return true;
364 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
366 WorldPacket data;
368 // char* pmana = strtok((char*)args, " ");
369 // if (!pmana)
370 // return false;
372 // char* pmanaMax = strtok(NULL, " ");
373 // if (!pmanaMax)
374 // return false;
376 // int32 manam = atoi(pmanaMax);
377 // int32 mana = atoi(pmana);
378 int32 mana = atoi((char*)args)*10;
379 int32 manam = atoi((char*)args)*10;
381 if (mana <= 0 || manam <= 0 || manam < mana)
383 SendSysMessage(LANG_BAD_VALUE);
384 return true;
387 Player *chr = getSelectedPlayer();
388 if (chr == NULL)
390 PSendSysMessage(LANG_NO_CHAR_SELECTED);
391 return true;
394 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, mana/10, manam/10, chr->GetName());
396 char buf[256];
397 sprintf((char*)buf,LANG_YOURS_ENERGY_CHANGED, m_session->GetPlayer()->GetName(), mana/10, manam/10);
398 FillSystemMessageData(&data, m_session, buf);
400 chr->GetSession()->SendPacket(&data);
402 chr->SetMaxPower(POWER_ENERGY,manam );
403 chr->SetPower(POWER_ENERGY, mana );
405 sLog.outDetail(LANG_CURRENT_ENERGY,chr->GetMaxPower(POWER_ENERGY));
407 return true;
410 bool ChatHandler::HandleModifyRageCommand(const char* args)
412 WorldPacket data;
414 // char* pmana = strtok((char*)args, " ");
415 // if (!pmana)
416 // return false;
418 // char* pmanaMax = strtok(NULL, " ");
419 // if (!pmanaMax)
420 // return false;
422 // int32 manam = atoi(pmanaMax);
423 // int32 mana = atoi(pmana);
424 int32 mana = atoi((char*)args)*10;
425 int32 manam = atoi((char*)args)*10;
427 if (mana <= 0 || manam <= 0 || manam < mana)
429 SendSysMessage(LANG_BAD_VALUE);
430 return true;
433 Player *chr = getSelectedPlayer();
434 if (chr == NULL)
436 SendSysMessage(LANG_NO_CHAR_SELECTED);
437 return true;
440 PSendSysMessage(LANG_YOU_CHANGE_RAGE, mana/10, manam/10, chr->GetName());
442 char buf[256];
443 sprintf((char*)buf,LANG_YOURS_RAGE_CHANGED, m_session->GetPlayer()->GetName(), mana/10, manam/10);
444 FillSystemMessageData(&data, m_session, buf);
446 chr->GetSession()->SendPacket(&data);
448 chr->SetMaxPower(POWER_RAGE,manam );
449 chr->SetPower(POWER_RAGE, mana );
451 return true;
454 bool ChatHandler::HandleModifyFactionCommand(const char* args)
457 uint32 factionid;
458 uint32 flag;
459 uint32 npcflag;
460 uint32 dyflag;
462 char* pfactionid = strtok((char*)args, " ");
464 Unit* chr = getSelectedCreature();
465 if(!chr)
467 SendSysMessage(LANG_SELECT_CREATURE);
468 return true;
471 if(!pfactionid)
473 if(chr)
475 factionid = chr->getFaction();
476 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
477 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
478 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
479 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
481 return true;
484 if (chr == NULL)
486 SendSysMessage(LANG_NO_CHAR_SELECTED);
487 return true;
490 factionid = atoi(pfactionid);
492 char* pflag = strtok(NULL, " ");
493 if (!pflag)
494 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
495 else
496 flag = atoi(pflag);
498 char* pnpcflag = strtok(NULL, " ");
499 if(!pnpcflag)
500 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
501 else
502 npcflag = atoi(pnpcflag);
504 char* pdyflag = strtok(NULL, " ");
505 if(!pdyflag)
506 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
507 else
508 dyflag = atoi(pdyflag);
510 if(!sFactionTemplateStore.LookupEntry(factionid))
512 PSendSysMessage(LANG_WRONG_FACTION, factionid);
513 return true;
516 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
518 //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
519 //FillSystemMessageData(&data, m_session, buf);
521 //chr->GetSession()->SendPacket(&data);
523 chr->setFaction(factionid);
524 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
525 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
526 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
528 return true;
531 bool ChatHandler::HandleModifySpellCommand(const char* args)
534 WorldPacket data;
536 char* pspellflatid = strtok((char*)args, " ");
537 if (!pspellflatid)
538 return false;
540 char* pop = strtok(NULL, " ");
541 if (!pop)
542 return false;
544 char* pval = strtok(NULL, " ");
545 if (!pval)
546 return false;
548 uint16 mark;
550 char* pmark = strtok(NULL, " ");
552 uint8 spellflatid = atoi(pspellflatid);
553 uint8 op = atoi(pop);
554 uint16 val = atoi(pval);
555 if(!pmark)
556 mark = 65535;
557 else
558 mark = atoi(pmark);
560 Player *chr = getSelectedPlayer();
561 if (chr == NULL)
563 SendSysMessage(LANG_NO_CHAR_SELECTED);
564 return true;
567 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
569 char buf[256];
570 sprintf((char*)buf,LANG_YOURS_SPELLFLATID_CHANGED, m_session->GetPlayer()->GetName(), spellflatid, val, mark);
571 FillSystemMessageData(&data, m_session, buf);
573 chr->GetSession()->SendPacket(&data);
575 data.Initialize(SMSG_SET_FLAT_SPELL_MODIFIER);
576 data << uint8(spellflatid);
577 data << uint8(op);
578 data << uint16(val);
579 data << uint16(mark);
580 chr->GetSession()->SendPacket(&data);
582 return true;
585 bool ChatHandler::HandleModifyTalentCommand (const char* args)
587 int tp = atoi((char*)args);
588 if (tp>0)
590 Player* player = m_session->GetPlayer();
591 if(!player)
593 SendSysMessage(LANG_NO_CHAR_SELECTED);
594 return true;
596 player->SetUInt32Value(PLAYER_CHARACTER_POINTS1, tp);
597 return true;
599 return false;
602 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
604 WorldPacket data;
606 if (!*args)
607 return false;
609 int flag = atoi((char*)args);
611 Player *chr = getSelectedPlayer();
612 if (chr == NULL)
614 SendSysMessage(LANG_NO_CHAR_SELECTED);
615 return true;
618 if (flag != 0)
620 chr->SetTaxiCheater(true);
621 PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
623 if(chr != m_session->GetPlayer())
625 WorldPacket data;
626 char buf[256];
627 sprintf((char*)buf,LANG_YOURS_TAXIS_ADDED, m_session->GetPlayer()->GetName());
628 FillSystemMessageData(&data, m_session, buf);
629 chr->GetSession()->SendPacket(&data);
632 else
634 chr->SetTaxiCheater(false);
635 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
637 if(chr != m_session->GetPlayer())
639 WorldPacket data;
640 char buf[256];
641 sprintf((char*)buf,LANG_YOURS_TAXIS_REMOVED, m_session->GetPlayer()->GetName());
642 FillSystemMessageData(&data, m_session, buf);
643 chr->GetSession()->SendPacket(&data);
647 return true;
650 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
652 WorldPacket data;
654 if (!*args)
655 return false;
657 float ASpeed = (float)atof((char*)args);
659 if (ASpeed > 50 || ASpeed <= 0)
661 SendSysMessage(LANG_BAD_VALUE);
662 return true;
665 Player *chr = getSelectedPlayer();
666 if (chr == NULL)
668 SendSysMessage(LANG_NO_CHAR_SELECTED);
669 return true;
672 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
674 char buf[256];
675 sprintf((char*)buf,LANG_YOURS_ASPEED_CHANGED, m_session->GetPlayer()->GetName(), ASpeed);
676 FillSystemMessageData(&data, m_session, buf);
678 chr->GetSession()->SendPacket(&data);
680 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE );
681 data.append(chr->GetPackGUID());
682 data << (uint32)0;
683 data << (float)ASpeed;
684 chr->SendMessageToSet( &data, true );
686 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE );
687 data.append(chr->GetPackGUID());
688 data << (uint32)0;
689 data << (float)ASpeed;
690 chr->SendMessageToSet( &data, true );
691 data.Initialize( SMSG_FORCE_RUN_BACK_SPEED_CHANGE );
692 data.append(chr->GetPackGUID());
693 data << (uint32)0;
694 data << (float)ASpeed;
695 chr->SendMessageToSet( &data, true );
696 return true;
699 bool ChatHandler::HandleModifySpeedCommand(const char* args)
701 WorldPacket data;
703 if (!*args)
704 return false;
706 float Speed = (float)atof((char*)args);
708 if (Speed > 50 || Speed <= 0)
710 SendSysMessage(LANG_BAD_VALUE);
711 return true;
714 Player *chr = getSelectedPlayer();
715 if (chr == NULL)
717 SendSysMessage(LANG_NO_CHAR_SELECTED);
718 return true;
721 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
723 char buf[256];
724 sprintf((char*)buf,LANG_YOURS_SPEED_CHANGED, m_session->GetPlayer()->GetName(), Speed);
725 FillSystemMessageData(&data, m_session, buf);
727 chr->GetSession()->SendPacket(&data);
729 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE );
730 data.append(chr->GetPackGUID());
731 data << uint32(0);
732 data << (float)Speed; //4
734 chr->SendMessageToSet( &data, true );
736 return true;
739 bool ChatHandler::HandleModifySwimCommand(const char* args)
741 WorldPacket data;
743 if (!*args)
744 return false;
746 float Swim = (float)atof((char*)args);
748 if (Swim > 50 || Swim <= 0)
750 SendSysMessage(LANG_BAD_VALUE);
751 return true;
754 Player *chr = getSelectedPlayer();
755 if (chr == NULL)
757 SendSysMessage(LANG_NO_CHAR_SELECTED);
758 return true;
761 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
763 char buf[256];
764 sprintf((char*)buf,LANG_YOURS_SWIM_SPEED_CHANGED, m_session->GetPlayer()->GetName(), Swim);
765 FillSystemMessageData(&data, m_session, buf);
767 chr->GetSession()->SendPacket(&data);
769 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE );
770 data.append(chr->GetPackGUID());
771 data << (uint32)0;
772 data << (float)Swim;
773 chr->SendMessageToSet( &data, true );
775 return true;
778 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
780 WorldPacket data;
782 if (!*args)
783 return false;
785 float BSpeed = (float)atof((char*)args);
787 if (BSpeed > 50 || BSpeed <= 0)
789 SendSysMessage(LANG_BAD_VALUE);
790 return true;
793 Player *chr = getSelectedPlayer();
794 if (chr == NULL)
796 SendSysMessage(LANG_NO_CHAR_SELECTED);
797 return true;
800 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
802 char buf[256];
803 sprintf((char*)buf,LANG_YOURS_BACK_SPEED_CHANGED, m_session->GetPlayer()->GetName(), BSpeed);
804 FillSystemMessageData(&data, m_session, buf);
806 chr->GetSession()->SendPacket(&data);
808 data.Initialize( SMSG_FORCE_RUN_BACK_SPEED_CHANGE );
809 data.append(chr->GetPackGUID());
810 data << (uint32)0;
811 data << (float)BSpeed;
812 chr->SendMessageToSet( &data, true );
814 return true;
817 bool ChatHandler::HandleModifyScaleCommand(const char* args)
819 WorldPacket data;
821 if (!*args)
822 return false;
824 float Scale = (float)atof((char*)args);
825 if (Scale > 3 || Scale <= 0)
827 SendSysMessage(LANG_BAD_VALUE);
828 return true;
831 Player *chr = getSelectedPlayer();
832 if (chr == NULL)
834 SendSysMessage(LANG_NO_CHAR_SELECTED);
835 return true;
838 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
840 char buf[256];
841 sprintf((char*)buf,LANG_YOURS_SIZE_CHANGED, m_session->GetPlayer()->GetName(), Scale);
842 FillSystemMessageData(&data, m_session, buf);
844 chr->GetSession()->SendPacket(&data);
846 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
848 return true;
851 bool ChatHandler::HandleModifyMountCommand(const char* args)
853 WorldPacket data;
855 if(!*args)
856 return false;
858 uint16 mId = 1147;
859 float speed = (float)15;
860 uint32 num = 0;
862 num = atoi((char*)args);
863 switch(num)
865 case 1:
866 mId=14340;
867 break;
868 case 2:
869 mId=4806;
870 break;
871 case 3:
872 mId=6471;
873 break;
874 case 4:
875 mId=12345;
876 break;
877 case 5:
878 mId=6472;
879 break;
880 case 6:
881 mId=6473;
882 break;
883 case 7:
884 mId=10670;
885 break;
886 case 8:
887 mId=10719;
888 break;
889 case 9:
890 mId=10671;
891 break;
892 case 10:
893 mId=10672;
894 break;
895 case 11:
896 mId=10720;
897 break;
898 case 12:
899 mId=14349;
900 break;
901 case 13:
902 mId=11641;
903 break;
904 case 14:
905 mId=12244;
906 break;
907 case 15:
908 mId=12242;
909 break;
910 case 16:
911 mId=14578;
912 break;
913 case 17:
914 mId=14579;
915 break;
916 case 18:
917 mId=14349;
918 break;
919 case 19:
920 mId=12245;
921 break;
922 case 20:
923 mId=14335;
924 break;
925 case 21:
926 mId=207;
927 break;
928 case 22:
929 mId=2328;
930 break;
931 case 23:
932 mId=2327;
933 break;
934 case 24:
935 mId=2326;
936 break;
937 case 25:
938 mId=14573;
939 break;
940 case 26:
941 mId=14574;
942 break;
943 case 27:
944 mId=14575;
945 break;
946 case 28:
947 mId=604;
948 break;
949 case 29:
950 mId=1166;
951 break;
952 case 30:
953 mId=2402;
954 break;
955 case 31:
956 mId=2410;
957 break;
958 case 32:
959 mId=2409;
960 break;
961 case 33:
962 mId=2408;
963 break;
964 case 34:
965 mId=2405;
966 break;
967 case 35:
968 mId=14337;
969 break;
970 case 36:
971 mId=6569;
972 break;
973 case 37:
974 mId=10661;
975 break;
976 case 38:
977 mId=10666;
978 break;
979 case 39:
980 mId=9473;
981 break;
982 case 40:
983 mId=9476;
984 break;
985 case 41:
986 mId=9474;
987 break;
988 case 42:
989 mId=14374;
990 break;
991 case 43:
992 mId=14376;
993 break;
994 case 44:
995 mId=14377;
996 break;
997 case 45:
998 mId=2404;
999 break;
1000 case 46:
1001 mId=2784;
1002 break;
1003 case 47:
1004 mId=2787;
1005 break;
1006 case 48:
1007 mId=2785;
1008 break;
1009 case 49:
1010 mId=2736;
1011 break;
1012 case 50:
1013 mId=2786;
1014 break;
1015 case 51:
1016 mId=14347;
1017 break;
1018 case 52:
1019 mId=14346;
1020 break;
1021 case 53:
1022 mId=14576;
1023 break;
1024 case 54:
1025 mId=9695;
1026 break;
1027 case 55:
1028 mId=9991;
1029 break;
1030 case 56:
1031 mId=6448;
1032 break;
1033 case 57:
1034 mId=6444;
1035 break;
1036 case 58:
1037 mId=6080;
1038 break;
1039 case 59:
1040 mId=6447;
1041 break;
1042 case 60:
1043 mId=4805;
1044 break;
1045 case 61:
1046 mId=9714;
1047 break;
1048 case 62:
1049 mId=6448;
1050 break;
1051 case 63:
1052 mId=6442;
1053 break;
1054 case 64:
1055 mId=14632;
1056 break;
1057 case 65:
1058 mId=14332;
1059 break;
1060 case 66:
1061 mId=14331;
1062 break;
1063 case 67:
1064 mId=8469;
1065 break;
1066 case 68:
1067 mId=2830;
1068 break;
1069 case 69:
1070 mId=2346;
1071 break;
1072 default:
1073 SendSysMessage(LANG_NO_MOUNT);
1074 return true;
1077 Player *chr = getSelectedPlayer();
1078 if (chr == NULL)
1080 SendSysMessage(LANG_NO_CHAR_SELECTED);
1081 return true;
1084 PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1086 char buf[256];
1087 sprintf((char*)buf,LANG_MOUNT_GIVED, m_session->GetPlayer()->GetName());
1088 FillSystemMessageData(&data, m_session, buf);
1090 chr->GetSession()->SendPacket(&data);
1092 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1093 chr->Mount(mId);
1095 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE );
1096 data.append(chr->GetPackGUID());
1097 data << (uint32)0;
1098 data << float(speed);
1099 chr->SendMessageToSet( &data, true );
1101 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE );
1102 data.append(chr->GetPackGUID());
1103 data << (uint32)0;
1104 data << float(speed);
1105 chr->SendMessageToSet( &data, true );
1107 return true;
1110 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1112 WorldPacket data;
1114 if (!*args)
1115 return false;
1117 Player *chr = getSelectedPlayer();
1118 if (chr == NULL)
1120 SendSysMessage(LANG_NO_CHAR_SELECTED);
1121 return true;
1124 int32 addmoney = atoi((char*)args);
1126 uint32 moneyuser = m_session->GetPlayer()->GetMoney();
1128 if(addmoney < 0)
1130 int32 newmoney = moneyuser + addmoney;
1132 sLog.outDetail(LANG_CURRENT_MONEY, moneyuser, addmoney, newmoney);
1133 if(newmoney <= 0 )
1136 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1138 char buf[256];
1139 sprintf((char*)buf,LANG_YOURS_ALL_MONEY_GONE, m_session->GetPlayer()->GetName());
1140 FillSystemMessageData(&data, m_session, buf);
1141 chr->GetSession()->SendPacket(&data);
1143 chr->SetMoney(0);
1145 else
1148 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
1150 char buf[256];
1151 sprintf((char*)buf,LANG_YOURS_MONEY_TAKEN, m_session->GetPlayer()->GetName(), abs(addmoney));
1152 FillSystemMessageData(&data, m_session, buf);
1153 chr->GetSession()->SendPacket(&data);
1155 chr->SetMoney( newmoney );
1158 else
1161 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
1163 char buf[256];
1164 sprintf((char*)buf,LANG_YOURS_MONEY_GIVEN, m_session->GetPlayer()->GetName(), addmoney);
1165 FillSystemMessageData(&data, m_session, buf);
1166 chr->GetSession()->SendPacket(&data);
1168 chr->ModifyMoney( addmoney );
1171 sLog.outDetail(LANG_NEW_MONEY, moneyuser, addmoney, chr->GetMoney() );
1173 return true;
1176 bool ChatHandler::HandleModifyBitCommand(const char* args)
1178 Player *chr = getSelectedPlayer();
1179 if (chr == NULL)
1181 SendSysMessage(LANG_NO_CHAR_SELECTED);
1182 return true;
1185 char* pField = strtok((char*)args, " ");
1186 if (!pField)
1187 return false;
1189 char* pBit = strtok(NULL, " ");
1190 if (!pBit)
1191 return false;
1193 uint16 field = atoi(pField);
1194 uint32 bit = atoi(pBit);
1196 if (field < 1 || field >= PLAYER_END)
1198 SendSysMessage(LANG_BAD_VALUE);
1199 return true;
1202 if (bit < 1 || bit > 32)
1204 SendSysMessage(LANG_BAD_VALUE);
1205 return true;
1208 if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1210 chr->RemoveFlag( field, (1<<(bit-1)) );
1211 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1213 else
1215 chr->SetFlag( field, (1<<(bit-1)) );
1216 PSendSysMessage(LANG_SET_BIT, bit, field);
1219 return true;
1222 bool ChatHandler::HandleTeleCommand(const char * args)
1224 if(m_session->GetPlayer()->isInFlight())
1226 SendSysMessage(LANG_YOU_IN_FLIGHT);
1227 return true;
1230 QueryResult *result;
1231 if(!*args)
1233 result = sDatabase.Query("SELECT `name` FROM `game_tele`");
1234 if (!result)
1236 SendSysMessage("Teleport location table is empty!");
1237 return true;
1239 std::string reply="Valid locations are:";
1240 for (uint64 i=0; i < result->GetRowCount(); i++)
1242 Field *fields = result->Fetch();
1243 reply += " ";
1244 reply += fields[0].GetCppString();
1245 result->NextRow();
1247 SendSysMessage(reply.c_str());
1248 delete result;
1249 return true;
1251 std::string name = args;
1252 sDatabase.escape_string(name);
1253 result = sDatabase.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `game_tele` WHERE `name` = '%s'",name.c_str());
1254 if (!result)
1256 SendSysMessage("Teleport location not found!");
1257 return true;
1259 Field *fields = result->Fetch();
1260 float x = fields[0].GetFloat();
1261 float y = fields[1].GetFloat();
1262 float z = fields[2].GetFloat();
1263 float ort = fields[3].GetFloat();
1264 int mapid = fields[4].GetUInt16();
1265 delete result;
1267 if(!MapManager::ExistMAP(mapid,x,y))
1269 PSendSysMessage(".tele target map not exist (X: %f Y: %f MapId:%u)",x,y,mapid);
1270 return true;
1273 m_session->GetPlayer()->TeleportTo(mapid, x, y, z, ort);
1274 return true;
1277 bool ChatHandler::HandleSearchTeleCommand(const char * args)
1279 QueryResult *result;
1280 if(!*args)
1282 SendSysMessage("Requires search parameter.");
1283 return true;
1285 char const* str = strtok((char*)args, " ");
1286 if(!str)
1287 return false;
1289 std::string namepart = str;
1290 sDatabase.escape_string(namepart);
1291 result = sDatabase.PQuery("SELECT `name` FROM `game_tele` WHERE `name` LIKE '%%%s%%'",namepart.c_str());
1292 if (!result)
1294 SendSysMessage("There are no teleport locations matching your request.");
1295 return true;
1297 std::string reply;
1298 for (uint64 i=0; i < result->GetRowCount(); i++)
1300 Field *fields = result->Fetch();
1301 reply += " ";
1302 reply += fields[0].GetCppString();
1303 reply += '\n';
1304 result->NextRow();
1306 delete result;
1308 if(reply.empty())
1309 SendSysMessage("None locations found.");
1310 else
1312 reply = "Locations found are:\n" + reply;
1313 SendSysMultilineMessage(reply.c_str());
1315 return true;
1318 bool ChatHandler::HandleWhispersCommand(const char* args)
1320 char* px = strtok((char*)args, " ");
1322 // ticket<end>
1323 if (!px)
1325 PSendSysMessage("Whispers accepting: %s", m_session->GetPlayer()->isAcceptWhispers() ? "on" : "off");
1326 return true;
1329 // ticket on
1330 if(strncmp(px,"on",3) == 0)
1332 m_session->GetPlayer()->SetAcceptWhispers(true);
1333 SendSysMessage("Whispers accepting: on");
1334 return true;
1337 // ticket off
1338 if(strncmp(px,"off",4) == 0)
1340 m_session->GetPlayer()->SetAcceptWhispers(false);
1341 SendSysMessage("Whispers accepting: off");
1342 return true;
1345 return false;
1348 bool ChatHandler::HandlePlaySoundCommand(const char* args)
1350 // USAGE: .playsound #soundid
1351 // #soundid - ID decimal number from SoundEntries.dbc (1 column)
1352 // this file have about 5000 sounds.
1353 // In this realisation only caller can hear this sound.
1354 if( *args )
1356 int dwSoundId = atoi((char*)args);
1357 if( dwSoundId >= 0 )
1359 WorldPacket data;
1360 data.Initialize(SMSG_PLAY_OBJECT_SOUND);
1361 data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1362 m_session->SendPacket(&data);
1364 sLog.outDebug("Player %s use command .playsound with #soundid=%u", m_session->GetPlayer()->GetName(), dwSoundId);
1365 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1366 return true;
1370 SendSysMessage(LANG_BAD_VALUE);
1371 return false;
1374 bool ChatHandler::HandleSaveAllCommand(const char* args)
1376 ObjectAccessor::Instance().SaveAllPlayers();
1377 SendSysMessage(LANG_PLAYERS_SAVED);
1378 return true;