2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
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 "WorldPacket.h"
21 #include "WorldSession.h"
23 #include "ObjectMgr.h"
27 #include "GossipDef.h"
28 #include "SocialMgr.h"
30 void WorldSession::HandleGuildQueryOpcode(WorldPacket
& recvPacket
)
32 CHECK_PACKET_SIZE(recvPacket
, 4);
37 //sLog.outDebug("WORLD: Received CMSG_GUILD_QUERY");
39 recvPacket
>> guildId
;
41 guild
= objmgr
.GetGuildById(guildId
);
44 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
51 void WorldSession::HandleGuildCreateOpcode(WorldPacket
& recvPacket
)
53 CHECK_PACKET_SIZE(recvPacket
, 1);
57 //sLog.outDebug("WORLD: Received CMSG_GUILD_CREATE");
61 if(GetPlayer()->GetGuildId())
64 Guild
*guild
= new Guild
;
65 if(!guild
->create(GetPlayer(),gname
))
71 objmgr
.AddGuild(guild
);
74 void WorldSession::HandleGuildInviteOpcode(WorldPacket
& recvPacket
)
76 CHECK_PACKET_SIZE(recvPacket
, 1);
78 std::string Invitedname
, plname
;
80 //sLog.outDebug("WORLD: Received CMSG_GUILD_INVITE");
82 Player
* player
= NULL
;
84 recvPacket
>> Invitedname
;
86 if(normalizePlayerName(Invitedname
))
87 player
= ObjectAccessor::Instance().FindPlayerByName(Invitedname
.c_str());
91 SendGuildCommandResult(GUILD_INVITE_S
, Invitedname
, GUILD_PLAYER_NOT_FOUND
);
95 Guild
*guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
98 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
102 // OK result but not send invite
103 if(player
->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
106 // not let enemies sign guild charter
107 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != GetPlayer()->GetTeam())
109 SendGuildCommandResult(GUILD_INVITE_S
, Invitedname
, GUILD_NOT_ALLIED
);
113 if(player
->GetGuildId())
115 plname
= player
->GetName();
116 SendGuildCommandResult(GUILD_INVITE_S
, plname
, ALREADY_IN_GUILD
);
120 if(player
->GetGuildIdInvited())
122 plname
= player
->GetName();
123 SendGuildCommandResult(GUILD_INVITE_S
, plname
, ALREADY_INVITED_TO_GUILD
);
127 if(!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_INVITE
))
129 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
133 sLog
.outDebug("Player %s Invited %s to Join his Guild", GetPlayer()->GetName(), Invitedname
.c_str());
135 player
->SetGuildIdInvited(GetPlayer()->GetGuildId());
136 // Put record into guildlog
137 guild
->LogGuildEvent(GUILD_EVENT_LOG_INVITE_PLAYER
, GetPlayer()->GetGUIDLow(), player
->GetGUIDLow(), 0);
139 WorldPacket
data(SMSG_GUILD_INVITE
, (8+10)); // guess size
140 data
<< GetPlayer()->GetName();
141 data
<< guild
->GetName();
142 player
->GetSession()->SendPacket(&data
);
144 //sLog.outDebug("WORLD: Sent (SMSG_GUILD_INVITE)");
147 void WorldSession::HandleGuildRemoveOpcode(WorldPacket
& recvPacket
)
149 CHECK_PACKET_SIZE(recvPacket
, 1);
153 //sLog.outDebug("WORLD: Received CMSG_GUILD_REMOVE");
155 recvPacket
>> plName
;
157 if(!normalizePlayerName(plName
))
160 Guild
* guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
163 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
167 if(!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_REMOVE
))
169 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
174 MemberSlot
* slot
= guild
->GetMemberSlot(plName
, plGuid
);
177 SendGuildCommandResult(GUILD_INVITE_S
, plName
, GUILD_PLAYER_NOT_IN_GUILD_S
);
181 if(slot
->RankId
== GR_GUILDMASTER
)
183 SendGuildCommandResult(GUILD_QUIT_S
, "", GUILD_LEADER_LEAVE
);
187 guild
->DelMember(plGuid
);
188 // Put record into guildlog
189 guild
->LogGuildEvent(GUILD_EVENT_LOG_UNINVITE_PLAYER
, GetPlayer()->GetGUIDLow(), GUID_LOPART(plGuid
), 0);
191 WorldPacket
data(SMSG_GUILD_EVENT
, (2+20)); // guess size
192 data
<< (uint8
)GE_REMOVED
;
193 data
<< (uint8
)2; // strings count
195 data
<< GetPlayer()->GetName();
196 guild
->BroadcastPacket(&data
);
199 void WorldSession::HandleGuildAcceptOpcode(WorldPacket
& /*recvPacket*/)
202 Player
*player
= GetPlayer();
204 //sLog.outDebug("WORLD: Received CMSG_GUILD_ACCEPT");
206 guild
= objmgr
.GetGuildById(player
->GetGuildIdInvited());
207 if(!guild
|| player
->GetGuildId())
210 // not let enemies sign guild charter
211 if (!sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD
) && player
->GetTeam() != objmgr
.GetPlayerTeamByGUID(guild
->GetLeader()))
214 if(!guild
->AddMember(GetPlayer()->GetGUID(),guild
->GetLowestRank()))
216 // Put record into guildlog
217 guild
->LogGuildEvent(GUILD_EVENT_LOG_JOIN_GUILD
, GetPlayer()->GetGUIDLow(), 0, 0);
219 WorldPacket
data(SMSG_GUILD_EVENT
, (2+10)); // guess size
220 data
<< (uint8
)GE_JOINED
;
222 data
<< player
->GetName();
223 guild
->BroadcastPacket(&data
);
225 //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
228 void WorldSession::HandleGuildDeclineOpcode(WorldPacket
& /*recvPacket*/)
230 //sLog.outDebug("WORLD: Received CMSG_GUILD_DECLINE");
232 GetPlayer()->SetGuildIdInvited(0);
233 GetPlayer()->SetInGuild(0);
236 void WorldSession::HandleGuildInfoOpcode(WorldPacket
& /*recvPacket*/)
239 //sLog.outDebug("WORLD: Received CMSG_GUILD_INFO");
241 guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
244 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
248 WorldPacket
data(SMSG_GUILD_INFO
, (5*4 + guild
->GetName().size() + 1));
249 data
<< guild
->GetName();
250 data
<< guild
->GetCreatedDay();
251 data
<< guild
->GetCreatedMonth();
252 data
<< guild
->GetCreatedYear();
253 data
<< guild
->GetMemberSize();
254 data
<< guild
->GetMemberSize();
259 void WorldSession::HandleGuildRosterOpcode(WorldPacket
& /*recvPacket*/)
261 //sLog.outDebug("WORLD: Received CMSG_GUILD_ROSTER");
263 Guild
* guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
270 void WorldSession::HandleGuildPromoteOpcode(WorldPacket
& recvPacket
)
272 CHECK_PACKET_SIZE(recvPacket
, 1);
276 //sLog.outDebug("WORLD: Received CMSG_GUILD_PROMOTE");
278 recvPacket
>> plName
;
280 if(!normalizePlayerName(plName
))
283 Guild
* guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
286 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
289 if(!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_PROMOTE
))
291 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
296 MemberSlot
* slot
= guild
->GetMemberSlot(plName
, plGuid
);
300 SendGuildCommandResult(GUILD_INVITE_S
, plName
, GUILD_PLAYER_NOT_IN_GUILD_S
);
304 if(plGuid
== GetPlayer()->GetGUID())
306 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_NAME_INVALID
);
310 if(slot
->RankId
< 2 || (slot
->RankId
-1) < GetPlayer()->GetRank())
313 uint32 newRankId
= slot
->RankId
< guild
->GetNrRanks() ? slot
->RankId
-1 : guild
->GetNrRanks()-1;
315 guild
->ChangeRank(plGuid
, newRankId
);
316 // Put record into guildlog
317 guild
->LogGuildEvent(GUILD_EVENT_LOG_PROMOTE_PLAYER
, GetPlayer()->GetGUIDLow(), GUID_LOPART(plGuid
), newRankId
);
319 WorldPacket
data(SMSG_GUILD_EVENT
, (2+30)); // guess size
320 data
<< (uint8
)GE_PROMOTION
;
322 data
<< GetPlayer()->GetName();
324 data
<< guild
->GetRankName(newRankId
);
325 guild
->BroadcastPacket(&data
);
328 void WorldSession::HandleGuildDemoteOpcode(WorldPacket
& recvPacket
)
330 CHECK_PACKET_SIZE(recvPacket
, 1);
334 //sLog.outDebug("WORLD: Received CMSG_GUILD_DEMOTE");
336 recvPacket
>> plName
;
338 if(!normalizePlayerName(plName
))
341 Guild
* guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
345 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
349 if(!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_DEMOTE
))
351 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
356 MemberSlot
* slot
= guild
->GetMemberSlot(plName
, plGuid
);
360 SendGuildCommandResult(GUILD_INVITE_S
, plName
, GUILD_PLAYER_NOT_IN_GUILD_S
);
364 if(plGuid
== GetPlayer()->GetGUID())
366 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_NAME_INVALID
);
370 if((slot
->RankId
+1) >= guild
->GetNrRanks() || slot
->RankId
<= GetPlayer()->GetRank())
373 guild
->ChangeRank(plGuid
, (slot
->RankId
+1));
374 // Put record into guildlog
375 guild
->LogGuildEvent(GUILD_EVENT_LOG_DEMOTE_PLAYER
, GetPlayer()->GetGUIDLow(), GUID_LOPART(plGuid
), slot
->RankId
);
377 WorldPacket
data(SMSG_GUILD_EVENT
, (2+30)); // guess size
378 data
<< (uint8
)GE_DEMOTION
;
380 data
<< GetPlayer()->GetName();
382 data
<< guild
->GetRankName(slot
->RankId
);
383 guild
->BroadcastPacket(&data
);
386 void WorldSession::HandleGuildLeaveOpcode(WorldPacket
& /*recvPacket*/)
391 //sLog.outDebug("WORLD: Received CMSG_GUILD_LEAVE");
393 guild
= objmgr
.GetGuildById(_player
->GetGuildId());
396 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
399 if(_player
->GetGUID() == guild
->GetLeader() && guild
->GetMemberSize() > 1)
401 SendGuildCommandResult(GUILD_QUIT_S
, "", GUILD_LEADER_LEAVE
);
405 if(_player
->GetGUID() == guild
->GetLeader())
411 plName
= _player
->GetName();
413 guild
->DelMember(_player
->GetGUID());
414 // Put record into guildlog
415 guild
->LogGuildEvent(GUILD_EVENT_LOG_LEAVE_GUILD
, _player
->GetGUIDLow(), 0, 0);
417 WorldPacket
data(SMSG_GUILD_EVENT
, (2+10)); // guess size
418 data
<< (uint8
)GE_LEFT
;
421 guild
->BroadcastPacket(&data
);
423 //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
425 SendGuildCommandResult(GUILD_QUIT_S
, guild
->GetName(), GUILD_PLAYER_NO_MORE_IN_GUILD
);
428 void WorldSession::HandleGuildDisbandOpcode(WorldPacket
& /*recvPacket*/)
433 //sLog.outDebug("WORLD: Received CMSG_GUILD_DISBAND");
435 guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
438 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
441 if(GetPlayer()->GetGUID() != guild
->GetLeader())
443 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
449 //sLog.outDebug("WORLD: Guild Sucefully Disbanded");
452 void WorldSession::HandleGuildLeaderOpcode(WorldPacket
& recvPacket
)
454 CHECK_PACKET_SIZE(recvPacket
, 1);
457 Player
*oldLeader
= GetPlayer();
460 //sLog.outDebug("WORLD: Received CMSG_GUILD_LEADER");
464 if(!normalizePlayerName(name
))
467 guild
= objmgr
.GetGuildById(oldLeader
->GetGuildId());
471 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
475 if (oldLeader
->GetGUID() != guild
->GetLeader())
477 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
481 uint64 newLeaderGUID
;
482 MemberSlot
* slot
= guild
->GetMemberSlot(name
, newLeaderGUID
);
486 SendGuildCommandResult(GUILD_INVITE_S
, name
, GUILD_PLAYER_NOT_IN_GUILD_S
);
490 guild
->SetLeader(newLeaderGUID
);
491 guild
->ChangeRank(oldLeader
->GetGUID(), GR_OFFICER
);
493 WorldPacket
data(SMSG_GUILD_EVENT
, (2+20)); // guess size
494 data
<< (uint8
)GE_LEADER_CHANGED
;
496 data
<< oldLeader
->GetName();
497 data
<< name
.c_str();
498 guild
->BroadcastPacket(&data
);
500 //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
503 void WorldSession::HandleGuildMOTDOpcode(WorldPacket
& recvPacket
)
508 //sLog.outDebug("WORLD: Received CMSG_GUILD_MOTD");
510 guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
513 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
516 if(!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_SETMOTD
))
518 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
522 if(!recvPacket
.empty())
527 guild
->SetMOTD(MOTD
);
529 WorldPacket
data(SMSG_GUILD_EVENT
, (2+MOTD
.size()+1));
530 data
<< (uint8
)GE_MOTD
;
533 guild
->BroadcastPacket(&data
);
535 //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
538 void WorldSession::HandleGuildSetPublicNoteOpcode(WorldPacket
& recvPacket
)
540 CHECK_PACKET_SIZE(recvPacket
, 1);
542 std::string name
,PNOTE
;
544 //sLog.outDebug("WORLD: Received CMSG_GUILD_SET_PUBLIC_NOTE");
548 if(!normalizePlayerName(name
))
551 Guild
* guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
555 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
559 if (!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EPNOTE
))
561 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
566 MemberSlot
* slot
= guild
->GetMemberSlot(name
, plGuid
);
570 SendGuildCommandResult(GUILD_INVITE_S
, name
, GUILD_PLAYER_NOT_IN_GUILD_S
);
575 guild
->SetPNOTE(plGuid
, PNOTE
);
580 void WorldSession::HandleGuildSetOfficerNoteOpcode(WorldPacket
& recvPacket
)
582 CHECK_PACKET_SIZE(recvPacket
, 1);
584 std::string plName
, OFFNOTE
;
586 //sLog.outDebug("WORLD: Received CMSG_GUILD_SET_OFFICER_NOTE");
588 recvPacket
>> plName
;
590 if (!normalizePlayerName(plName
))
593 Guild
* guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
597 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
600 if (!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EOFFNOTE
))
602 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
607 MemberSlot
* slot
= guild
->GetMemberSlot(plName
, plGuid
);
611 SendGuildCommandResult(GUILD_INVITE_S
, plName
, GUILD_PLAYER_NOT_IN_GUILD_S
);
615 recvPacket
>> OFFNOTE
;
616 guild
->SetOFFNOTE(plGuid
, OFFNOTE
);
621 void WorldSession::HandleGuildRankOpcode(WorldPacket
& recvPacket
)
623 CHECK_PACKET_SIZE(recvPacket
, 4+4+1+4*13);
624 //recvPacket.hexlike();
627 std::string rankname
;
629 uint32 rights
, MoneyPerDay
;
631 uint32 BankSlotPerDay
;
633 //sLog.outDebug("WORLD: Received CMSG_GUILD_RANK");
635 guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
638 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
642 else if(GetPlayer()->GetGUID() != guild
->GetLeader())
644 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
648 recvPacket
>> rankId
;
649 recvPacket
>> rights
;
650 recvPacket
>> rankname
;
651 recvPacket
>> MoneyPerDay
;
653 for (int i
= 0; i
< GUILD_BANK_MAX_TABS
; ++i
)
655 recvPacket
>> BankRights
;
656 recvPacket
>> BankSlotPerDay
;
657 guild
->SetBankRightsAndSlots(rankId
, uint8(i
), uint16(BankRights
& 0xFF), uint16(BankSlotPerDay
), true);
659 sLog
.outDebug("WORLD: Changed RankName to %s , Rights to 0x%.4X", rankname
.c_str(), rights
);
661 guild
->SetBankMoneyPerDay(rankId
, MoneyPerDay
);
662 guild
->SetRankName(rankId
, rankname
);
664 if(rankId
==GR_GUILDMASTER
) // prevent loss leader rights
665 rights
= GR_RIGHT_ALL
;
667 guild
->SetRankRights(rankId
, rights
);
673 void WorldSession::HandleGuildAddRankOpcode(WorldPacket
& recvPacket
)
675 CHECK_PACKET_SIZE(recvPacket
, 1);
678 std::string rankname
;
680 //sLog.outDebug("WORLD: Received CMSG_GUILD_ADD_RANK");
682 guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
685 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
689 if(GetPlayer()->GetGUID() != guild
->GetLeader())
691 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
695 if(guild
->GetNrRanks() >= GUILD_MAX_RANKS
) // client not let create more 10 than ranks
698 recvPacket
>> rankname
;
700 guild
->CreateRank(rankname
, GR_RIGHT_GCHATLISTEN
| GR_RIGHT_GCHATSPEAK
);
706 void WorldSession::HandleGuildDelRankOpcode(WorldPacket
& /*recvPacket*/)
709 std::string rankname
;
711 //sLog.outDebug("WORLD: Received CMSG_GUILD_DEL_RANK");
713 guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
716 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
720 else if(GetPlayer()->GetGUID() != guild
->GetLeader())
722 SendGuildCommandResult(GUILD_INVITE_S
, "", GUILD_PERMISSIONS
);
732 void WorldSession::SendGuildCommandResult(uint32 typecmd
, const std::string
& str
,uint32 cmdresult
)
734 WorldPacket
data(SMSG_GUILD_COMMAND_RESULT
, (8+str
.size()+1));
740 //sLog.outDebug("WORLD: Sent (SMSG_GUILD_COMMAND_RESULT)");
743 void WorldSession::HandleGuildChangeInfoOpcode(WorldPacket
& recvPacket
)
745 CHECK_PACKET_SIZE(recvPacket
, 1);
747 //sLog.outDebug("WORLD: Received CMSG_GUILD_INFO_TEXT");
753 Guild
*guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
756 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
760 if(!guild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_MODIFY_GUILD_INFO
))
762 SendGuildCommandResult(GUILD_CREATE_S
, "", GUILD_PERMISSIONS
);
766 guild
->SetGINFO(GINFO
);
769 void WorldSession::HandleGuildSaveEmblemOpcode(WorldPacket
& recvPacket
)
771 CHECK_PACKET_SIZE(recvPacket
, 8+4+4+4+4+4);
773 //sLog.outDebug("WORLD: Received MSG_SAVE_GUILD_EMBLEM");
781 uint32 BackgroundColor
;
783 recvPacket
>> vendorGuid
;
785 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, vendorGuid
,UNIT_NPC_FLAG_TABARDDESIGNER
);
788 //"That's not an emblem vendor!"
789 SendSaveGuildEmblem(ERR_GUILDEMBLEM_INVALIDVENDOR
);
790 sLog
.outDebug("WORLD: HandleGuildSaveEmblemOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(vendorGuid
));
795 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
796 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
798 recvPacket
>> EmblemStyle
;
799 recvPacket
>> EmblemColor
;
800 recvPacket
>> BorderStyle
;
801 recvPacket
>> BorderColor
;
802 recvPacket
>> BackgroundColor
;
804 Guild
*guild
= objmgr
.GetGuildById(GetPlayer()->GetGuildId());
807 //"You are not part of a guild!";
808 SendSaveGuildEmblem(ERR_GUILDEMBLEM_NOGUILD
);
812 if (guild
->GetLeader() != GetPlayer()->GetGUID())
814 //"Only guild leaders can create emblems."
815 SendSaveGuildEmblem(ERR_GUILDEMBLEM_NOTGUILDMASTER
);
819 if(GetPlayer()->GetMoney() < 10*GOLD
)
821 //"You can't afford to do that."
822 SendSaveGuildEmblem(ERR_GUILDEMBLEM_NOTENOUGHMONEY
);
826 GetPlayer()->ModifyMoney(-10*GOLD
);
827 guild
->SetEmblem(EmblemStyle
, EmblemColor
, BorderStyle
, BorderColor
, BackgroundColor
);
829 //"Guild Emblem saved."
830 SendSaveGuildEmblem(ERR_GUILDEMBLEM_SUCCESS
);
835 void WorldSession::HandleGuildEventLogOpcode(WorldPacket
& /* recvPacket */)
838 sLog
.outDebug("WORLD: Received (MSG_GUILD_EVENT_LOG_QUERY)");
839 //recvPacket.hexlike();
841 uint32 GuildId
= GetPlayer()->GetGuildId();
845 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
849 pGuild
->DisplayGuildEventlog(this);
852 /****** GUILD BANK *******/
854 void WorldSession::HandleGuildBankGetMoneyAmount( WorldPacket
& /* recv_data */ )
856 sLog
.outDebug("WORLD: Received (MSG_GUILD_BANK_MONEY_WITHDRAWN)");
857 //recv_data.hexlike();
859 uint32 GuildId
= GetPlayer()->GetGuildId();
863 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
867 pGuild
->SendMoneyInfo(this, GetPlayer()->GetGUIDLow());
870 void WorldSession::HandleGuildBankGetRights( WorldPacket
& /* recv_data */ )
872 sLog
.outDebug("WORLD: Received (MSG_GUILD_PERMISSIONS)");
874 uint32 GuildId
= GetPlayer()->GetGuildId();
878 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
882 uint32 rankId
= GetPlayer()->GetRank();
884 WorldPacket
data(MSG_GUILD_PERMISSIONS
, 4*15+1);
885 data
<< uint32(rankId
); // guild rank id
886 data
<< uint32(pGuild
->GetRankRights(rankId
)); // rank rights
887 // money per day left
888 data
<< uint32(pGuild
->GetMemberMoneyWithdrawRem(GetPlayer()->GetGUIDLow()));
889 data
<< uint8(pGuild
->GetPurchasedTabs()); // tabs count
890 for(int i
= 0; i
< GUILD_BANK_MAX_TABS
; ++i
)
892 data
<< uint32(pGuild
->GetBankRights(rankId
, uint8(i
)));
893 data
<< uint32(pGuild
->GetMemberSlotWithdrawRem(GetPlayer()->GetGUIDLow(), uint8(i
)));
896 sLog
.outDebug("WORLD: Sent (MSG_GUILD_PERMISSIONS)");
899 /* Called when clicking on Guild bank gameobject */
900 void WorldSession::HandleGuildBankQuery( WorldPacket
& recv_data
)
902 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANKER_ACTIVATE)");
903 CHECK_PACKET_SIZE(recv_data
,8+1);
906 recv_data
>> GoGuid
>> unk
;
908 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
911 if (uint32 GuildId
= GetPlayer()->GetGuildId())
913 if(Guild
*pGuild
= objmgr
.GetGuildById(GuildId
))
915 pGuild
->DisplayGuildBankTabsInfo(this);
920 SendGuildCommandResult(GUILD_BANK_S
, "", GUILD_PLAYER_NOT_IN_GUILD
);
923 /* Called when opening guild bank tab only (first one) */
924 void WorldSession::HandleGuildBankTabColon( WorldPacket
& recv_data
)
926 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANK_QUERY_TAB)");
927 CHECK_PACKET_SIZE(recv_data
,8+1+1);
930 recv_data
>> GoGuid
>> TabId
>> unk1
;
932 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
935 uint32 GuildId
= GetPlayer()->GetGuildId();
939 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
943 // Let's update the amount of gold the player can withdraw before displaying the content
944 // This is usefull if money withdraw right has changed
945 pGuild
->SendMoneyInfo(this, GetPlayer()->GetGUIDLow());
947 pGuild
->DisplayGuildBankContent(this, TabId
);
950 void WorldSession::HandleGuildBankDeposit( WorldPacket
& recv_data
)
952 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANK_DEPOSIT_MONEY)");
953 CHECK_PACKET_SIZE(recv_data
,8+4);
956 recv_data
>> GoGuid
>> money
;
961 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
964 uint32 GuildId
= GetPlayer()->GetGuildId();
968 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
972 if (GetPlayer()->GetMoney() < money
)
975 CharacterDatabase
.BeginTransaction();
977 pGuild
->SetBankMoney(pGuild
->GetGuildBankMoney()+money
);
978 GetPlayer()->ModifyMoney(-int(money
));
979 GetPlayer()->SaveDataFieldToDB(); //contains money
981 CharacterDatabase
.CommitTransaction();
984 if(_player
->GetSession()->GetSecurity() > SEC_PLAYER
&& sWorld
.getConfig(CONFIG_GM_LOG_TRADE
))
986 sLog
.outCommand(_player
->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit money (Amount: %u) to guild bank (Guild ID %u)",
987 _player
->GetName(),_player
->GetSession()->GetAccountId(),money
,GuildId
);
991 pGuild
->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_MONEY
, uint8(0), GetPlayer()->GetGUIDLow(), money
);
993 pGuild
->DisplayGuildBankTabsInfo(this);
994 pGuild
->DisplayGuildBankContent(this, 0);
995 pGuild
->DisplayGuildBankMoneyUpdate();
998 void WorldSession::HandleGuildBankWithdraw( WorldPacket
& recv_data
)
1000 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANK_WITHDRAW_MONEY)");
1001 CHECK_PACKET_SIZE(recv_data
,8+4);
1004 recv_data
>> GoGuid
>> money
;
1009 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
1012 uint32 GuildId
= GetPlayer()->GetGuildId();
1016 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1020 if (pGuild
->GetGuildBankMoney()<money
) // not enough money in bank
1023 if (!pGuild
->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_WITHDRAW_GOLD
))
1026 CharacterDatabase
.BeginTransaction();
1028 if (!pGuild
->MemberMoneyWithdraw(money
, GetPlayer()->GetGUIDLow()))
1030 CharacterDatabase
.RollbackTransaction();
1034 GetPlayer()->ModifyMoney(money
);
1035 GetPlayer()->SaveDataFieldToDB(); // contains money
1037 CharacterDatabase
.CommitTransaction();
1040 pGuild
->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_MONEY
, uint8(0), GetPlayer()->GetGUIDLow(), money
);
1042 pGuild
->SendMoneyInfo(this, GetPlayer()->GetGUIDLow());
1043 pGuild
->DisplayGuildBankTabsInfo(this);
1044 pGuild
->DisplayGuildBankContent(this, 0);
1045 pGuild
->DisplayGuildBankMoneyUpdate();
1048 void WorldSession::HandleGuildBankDepositItem( WorldPacket
& recv_data
)
1050 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANK_SWAP_ITEMS)");
1051 //recv_data.hexlike();
1056 uint8 BankTab
, BankTabSlot
, AutoStore
, AutoStoreCount
, PlayerSlot
, PlayerBag
, SplitedAmount
= 0;
1057 uint8 BankTabDst
, BankTabSlotDst
, unk2
, ToChar
= 1;
1058 uint32 ItemEntry
, unk1
;
1060 CHECK_PACKET_SIZE(recv_data
,8+1);
1061 recv_data
>> GoGuid
>> BankToBank
;
1065 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+1+1+4+1+1+4+1+1);
1066 recv_data
>> BankTabDst
;
1067 recv_data
>> BankTabSlotDst
;
1068 recv_data
>> unk1
; // always 0
1069 recv_data
>> BankTab
;
1070 recv_data
>> BankTabSlot
;
1071 recv_data
>> ItemEntry
;
1072 recv_data
>> unk2
; // always 0
1073 recv_data
>> SplitedAmount
;
1075 if (BankTabSlotDst
>= GUILD_BANK_MAX_SLOTS
)
1077 if (BankTabDst
== BankTab
&& BankTabSlotDst
== BankTabSlot
)
1083 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+1+1+4+1);
1084 recv_data
>> BankTab
;
1085 recv_data
>> BankTabSlot
;
1086 recv_data
>> ItemEntry
;
1087 recv_data
>> AutoStore
;
1091 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+1);
1092 recv_data
>> AutoStoreCount
;
1095 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+1+1);
1096 recv_data
>> PlayerBag
;
1097 recv_data
>> PlayerSlot
;
1101 CHECK_PACKET_SIZE(recv_data
, recv_data
.rpos()+1+1);
1102 recv_data
>> ToChar
;
1103 recv_data
>> SplitedAmount
;
1106 if (BankTabSlot
>= GUILD_BANK_MAX_SLOTS
&& BankTabSlot
!= 0xFF)
1110 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
1113 uint32 GuildId
= GetPlayer()->GetGuildId();
1117 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1121 Player
*pl
= GetPlayer();
1127 if(BankTab
==BankTabDst
&& BankTabSlot
==BankTabSlotDst
)
1130 Item
*pItemSrc
= pGuild
->GetItem(BankTab
, BankTabSlot
);
1131 if (!pItemSrc
) // may prevent crash
1134 if(SplitedAmount
> pItemSrc
->GetCount())
1135 return; // cheating?
1136 else if(SplitedAmount
== pItemSrc
->GetCount())
1137 SplitedAmount
= 0; // no split
1139 Item
*pItemDst
= pGuild
->GetItem(BankTabDst
, BankTabSlotDst
);
1141 if(BankTab
!=BankTabDst
)
1143 // check dest pos rights (if different tabs)
1144 if(!pGuild
->IsMemberHaveRights(pl
->GetGUIDLow(), BankTabDst
, GUILD_BANK_RIGHT_DEPOSIT_ITEM
))
1147 // check source pos rights (if different tabs)
1148 uint32 remRight
= pGuild
->GetMemberSlotWithdrawRem(pl
->GetGUIDLow(), BankTab
);
1154 { // Bank -> Bank item split (in empty or non empty slot
1155 GuildItemPosCountVec dest
;
1156 uint8 msg
= pGuild
->CanStoreItem(BankTabDst
,BankTabSlotDst
,dest
,SplitedAmount
,pItemSrc
,false);
1157 if( msg
!= EQUIP_ERR_OK
)
1159 pl
->SendEquipError( msg
, pItemSrc
, NULL
);
1163 Item
*pNewItem
= pItemSrc
->CloneItem( SplitedAmount
);
1166 pl
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pItemSrc
, NULL
);
1170 CharacterDatabase
.BeginTransaction();
1171 pGuild
->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemSrc
->GetEntry(), SplitedAmount
, BankTabDst
);
1173 pl
->ItemRemovedQuestCheck( pItemSrc
->GetEntry(), SplitedAmount
);
1174 pItemSrc
->SetCount( pItemSrc
->GetCount() - SplitedAmount
);
1175 pItemSrc
->FSetState(ITEM_CHANGED
);
1176 pItemSrc
->SaveToDB(); // not in inventory and can be save standalone
1177 pGuild
->StoreItem(BankTabDst
,dest
,pNewItem
);
1178 CharacterDatabase
.CommitTransaction();
1182 GuildItemPosCountVec gDest
;
1183 uint8 msg
= pGuild
->CanStoreItem(BankTabDst
,BankTabSlotDst
,gDest
,pItemSrc
->GetCount(),pItemSrc
,false);
1184 if( msg
== EQUIP_ERR_OK
) // merge to
1186 CharacterDatabase
.BeginTransaction();
1187 pGuild
->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemSrc
->GetEntry(), pItemSrc
->GetCount(), BankTabDst
);
1189 pGuild
->RemoveItem(BankTab
, BankTabSlot
);
1190 pGuild
->StoreItem(BankTabDst
, gDest
, pItemSrc
);
1191 CharacterDatabase
.CommitTransaction();
1196 uint8 msg
= pGuild
->CanStoreItem(BankTabDst
,BankTabSlotDst
,gDest
,pItemSrc
->GetCount(),pItemSrc
,true);
1197 if( msg
!= EQUIP_ERR_OK
)
1199 pl
->SendEquipError( msg
, pItemSrc
, NULL
);
1203 GuildItemPosCountVec gSrc
;
1204 msg
= pGuild
->CanStoreItem(BankTab
,BankTabSlot
,gSrc
,pItemDst
->GetCount(),pItemDst
,true);
1205 if( msg
!= EQUIP_ERR_OK
)
1207 pl
->SendEquipError( msg
, pItemDst
, NULL
);
1211 if(BankTab
!=BankTabDst
)
1213 // check source pos rights (item swapped to src)
1214 if(!pGuild
->IsMemberHaveRights(pl
->GetGUIDLow(), BankTab
, GUILD_BANK_RIGHT_DEPOSIT_ITEM
))
1217 // check dest pos rights (item swapped to src)
1218 uint32 remRightDst
= pGuild
->GetMemberSlotWithdrawRem(pl
->GetGUIDLow(), BankTabDst
);
1219 if(remRightDst
<= 0)
1223 CharacterDatabase
.BeginTransaction();
1224 pGuild
->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemSrc
->GetEntry(), pItemSrc
->GetCount(), BankTabDst
);
1225 pGuild
->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM
, BankTabDst
, pl
->GetGUIDLow(), pItemDst
->GetEntry(), pItemDst
->GetCount(), BankTab
);
1227 pGuild
->RemoveItem(BankTab
, BankTabSlot
);
1228 pGuild
->RemoveItem(BankTabDst
, BankTabSlotDst
);
1229 pGuild
->StoreItem(BankTab
, gSrc
, pItemDst
);
1230 pGuild
->StoreItem(BankTabDst
, gDest
, pItemSrc
);
1231 CharacterDatabase
.CommitTransaction();
1234 pGuild
->DisplayGuildBankContentUpdate(BankTab
,BankTabSlot
,BankTab
==BankTabDst
? BankTabSlotDst
: -1);
1235 if(BankTab
!=BankTabDst
)
1236 pGuild
->DisplayGuildBankContentUpdate(BankTabDst
,BankTabSlotDst
);
1242 // char->bank autostore click return BankTabSlot = 255 = NULL_SLOT
1243 // do similar for bank->char
1244 if(AutoStore
&& ToChar
)
1246 PlayerBag
= NULL_BAG
;
1247 PlayerSlot
= NULL_SLOT
;
1250 // allow work with inventory only
1251 if(!Player::IsInventoryPos(PlayerBag
,PlayerSlot
) && !(PlayerBag
== NULL_BAG
&& PlayerSlot
== NULL_SLOT
) )
1253 _player
->SendEquipError( EQUIP_ERR_NONE
, NULL
, NULL
);
1257 Item
*pItemBank
= pGuild
->GetItem(BankTab
, BankTabSlot
);
1258 Item
*pItemChar
= GetPlayer()->GetItemByPos(PlayerBag
, PlayerSlot
);
1259 if (!pItemChar
&& !pItemBank
) // Nothing to do
1262 if (!pItemChar
&& !ToChar
) // Problem to get item from player
1265 if (!pItemBank
&& ToChar
) // Problem to get bank item
1268 // BankToChar swap or char to bank remaining
1270 if (ToChar
) // Bank -> Char cases
1272 if(SplitedAmount
> pItemBank
->GetCount())
1273 return; // cheating?
1274 else if(SplitedAmount
== pItemBank
->GetCount())
1275 SplitedAmount
= 0; // no split
1278 { // Bank -> Char split to slot (patly move)
1279 Item
*pNewItem
= pItemBank
->CloneItem( SplitedAmount
);
1282 pl
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pItemBank
, NULL
);
1286 ItemPosCountVec dest
;
1287 uint8 msg
= pl
->CanStoreItem(PlayerBag
, PlayerSlot
, dest
, pNewItem
, false);
1288 if( msg
!= EQUIP_ERR_OK
)
1290 pl
->SendEquipError( msg
, pNewItem
, NULL
);
1295 // check source pos rights (item moved to inventory)
1296 uint32 remRight
= pGuild
->GetMemberSlotWithdrawRem(pl
->GetGUIDLow(), BankTab
);
1303 CharacterDatabase
.BeginTransaction();
1304 pGuild
->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemBank
->GetEntry(), SplitedAmount
);
1306 pItemBank
->SetCount(pItemBank
->GetCount()-SplitedAmount
);
1307 pItemBank
->FSetState(ITEM_CHANGED
);
1308 pItemBank
->SaveToDB(); // not in inventory and can be save standalone
1309 pl
->MoveItemToInventory(dest
,pNewItem
,true);
1310 pl
->SaveInventoryAndGoldToDB();
1312 pGuild
->MemberItemWithdraw(BankTab
, pl
->GetGUIDLow());
1313 CharacterDatabase
.CommitTransaction();
1315 else // Bank -> Char swap with slot (move)
1317 ItemPosCountVec dest
;
1318 uint8 msg
= pl
->CanStoreItem(PlayerBag
, PlayerSlot
, dest
, pItemBank
, false);
1319 if( msg
== EQUIP_ERR_OK
) // merge case
1321 // check source pos rights (item moved to inventory)
1322 uint32 remRight
= pGuild
->GetMemberSlotWithdrawRem(pl
->GetGUIDLow(), BankTab
);
1326 CharacterDatabase
.BeginTransaction();
1327 pGuild
->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemBank
->GetEntry(), pItemBank
->GetCount());
1329 pGuild
->RemoveItem(BankTab
, BankTabSlot
);
1330 pl
->MoveItemToInventory(dest
,pItemBank
,true);
1331 pl
->SaveInventoryAndGoldToDB();
1333 pGuild
->MemberItemWithdraw(BankTab
, pl
->GetGUIDLow());
1334 CharacterDatabase
.CommitTransaction();
1336 else // Bank <-> Char swap items
1338 // check source pos rights (item swapped to bank)
1339 if(!pGuild
->IsMemberHaveRights(pl
->GetGUIDLow(), BankTab
, GUILD_BANK_RIGHT_DEPOSIT_ITEM
))
1344 if(!pItemChar
->CanBeTraded())
1346 _player
->SendEquipError( EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
, pItemChar
, NULL
);
1351 ItemPosCountVec iDest
;
1352 msg
= pl
->CanStoreItem(PlayerBag
, PlayerSlot
, iDest
, pItemBank
, true);
1353 if( msg
!= EQUIP_ERR_OK
)
1355 pl
->SendEquipError( msg
, pItemBank
, NULL
);
1359 GuildItemPosCountVec gDest
;
1362 msg
= pGuild
->CanStoreItem(BankTab
,BankTabSlot
,gDest
,pItemChar
->GetCount(),pItemChar
,true);
1363 if( msg
!= EQUIP_ERR_OK
)
1365 pl
->SendEquipError( msg
, pItemChar
, NULL
);
1370 // check source pos rights (item moved to inventory)
1371 uint32 remRight
= pGuild
->GetMemberSlotWithdrawRem(pl
->GetGUIDLow(), BankTab
);
1377 // logging item move to bank
1378 if(_player
->GetSession()->GetSecurity() > SEC_PLAYER
&& sWorld
.getConfig(CONFIG_GM_LOG_TRADE
))
1380 sLog
.outCommand(_player
->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
1381 _player
->GetName(),_player
->GetSession()->GetAccountId(),
1382 pItemChar
->GetProto()->Name1
,pItemChar
->GetEntry(),pItemChar
->GetCount(),
1387 CharacterDatabase
.BeginTransaction();
1388 pGuild
->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemBank
->GetEntry(), pItemBank
->GetCount());
1390 pGuild
->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemChar
->GetEntry(), pItemChar
->GetCount());
1392 pGuild
->RemoveItem(BankTab
, BankTabSlot
);
1395 pl
->MoveItemFromInventory(PlayerBag
, PlayerSlot
, true);
1396 pItemChar
->DeleteFromInventoryDB();
1400 pGuild
->StoreItem(BankTab
, gDest
, pItemChar
);
1401 pl
->MoveItemToInventory(iDest
,pItemBank
,true);
1402 pl
->SaveInventoryAndGoldToDB();
1404 pGuild
->MemberItemWithdraw(BankTab
, pl
->GetGUIDLow());
1405 CharacterDatabase
.CommitTransaction();
1408 pGuild
->DisplayGuildBankContentUpdate(BankTab
,BankTabSlot
);
1410 } // End "To char" part
1412 // Char -> Bank cases
1414 if(!pItemChar
->CanBeTraded())
1416 _player
->SendEquipError( EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
, pItemChar
, NULL
);
1420 // check source pos rights (item moved to bank)
1421 if(!pGuild
->IsMemberHaveRights(pl
->GetGUIDLow(), BankTab
, GUILD_BANK_RIGHT_DEPOSIT_ITEM
))
1424 if(SplitedAmount
> pItemChar
->GetCount())
1425 return; // cheating?
1426 else if(SplitedAmount
== pItemChar
->GetCount())
1427 SplitedAmount
= 0; // no split
1430 { // Char -> Bank split to empty or non-empty slot (partly move)
1431 GuildItemPosCountVec dest
;
1432 uint8 msg
= pGuild
->CanStoreItem(BankTab
,BankTabSlot
,dest
,SplitedAmount
,pItemChar
,false);
1433 if( msg
!= EQUIP_ERR_OK
)
1435 pl
->SendEquipError( msg
, pItemChar
, NULL
);
1439 Item
*pNewItem
= pItemChar
->CloneItem( SplitedAmount
);
1442 pl
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pItemChar
, NULL
);
1446 // logging item move to bank (before items merge
1447 if(_player
->GetSession()->GetSecurity() > SEC_PLAYER
&& sWorld
.getConfig(CONFIG_GM_LOG_TRADE
))
1449 sLog
.outCommand(_player
->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
1450 _player
->GetName(),_player
->GetSession()->GetAccountId(),
1451 pItemChar
->GetProto()->Name1
,pItemChar
->GetEntry(),SplitedAmount
,GuildId
);
1454 CharacterDatabase
.BeginTransaction();
1455 pGuild
->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemChar
->GetEntry(), SplitedAmount
);
1457 pl
->ItemRemovedQuestCheck( pItemChar
->GetEntry(), SplitedAmount
);
1458 pItemChar
->SetCount(pItemChar
->GetCount()-SplitedAmount
);
1459 pItemChar
->SetState(ITEM_CHANGED
);
1460 pl
->SaveInventoryAndGoldToDB();
1461 pGuild
->StoreItem(BankTab
, dest
, pNewItem
);
1462 CharacterDatabase
.CommitTransaction();
1464 pGuild
->DisplayGuildBankContentUpdate(BankTab
,dest
);
1466 else // Char -> Bank swap with empty or non-empty (move)
1468 GuildItemPosCountVec dest
;
1469 uint8 msg
= pGuild
->CanStoreItem(BankTab
,BankTabSlot
,dest
,pItemChar
->GetCount(),pItemChar
,false);
1470 if( msg
== EQUIP_ERR_OK
) // merge
1472 // logging item move to bank
1473 if(_player
->GetSession()->GetSecurity() > SEC_PLAYER
&& sWorld
.getConfig(CONFIG_GM_LOG_TRADE
))
1475 sLog
.outCommand(_player
->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
1476 _player
->GetName(),_player
->GetSession()->GetAccountId(),
1477 pItemChar
->GetProto()->Name1
,pItemChar
->GetEntry(),pItemChar
->GetCount(),
1481 CharacterDatabase
.BeginTransaction();
1482 pGuild
->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemChar
->GetEntry(), pItemChar
->GetCount());
1484 pl
->MoveItemFromInventory(PlayerBag
, PlayerSlot
, true);
1485 pItemChar
->DeleteFromInventoryDB();
1487 pGuild
->StoreItem(BankTab
,dest
,pItemChar
);
1488 pl
->SaveInventoryAndGoldToDB();
1489 CharacterDatabase
.CommitTransaction();
1491 pGuild
->DisplayGuildBankContentUpdate(BankTab
,dest
);
1493 else // Char <-> Bank swap items (posible NULL bank item)
1495 ItemPosCountVec iDest
;
1498 msg
= pl
->CanStoreItem(PlayerBag
, PlayerSlot
, iDest
, pItemBank
, true);
1499 if( msg
!= EQUIP_ERR_OK
)
1501 pl
->SendEquipError( msg
, pItemBank
, NULL
);
1506 GuildItemPosCountVec gDest
;
1507 msg
= pGuild
->CanStoreItem(BankTab
,BankTabSlot
,gDest
,pItemChar
->GetCount(),pItemChar
,true);
1508 if( msg
!= EQUIP_ERR_OK
)
1510 pl
->SendEquipError( msg
, pItemChar
, NULL
);
1516 // check bank pos rights (item swapped with inventory)
1517 uint32 remRight
= pGuild
->GetMemberSlotWithdrawRem(pl
->GetGUIDLow(), BankTab
);
1522 // logging item move to bank
1523 if(_player
->GetSession()->GetSecurity() > SEC_PLAYER
&& sWorld
.getConfig(CONFIG_GM_LOG_TRADE
))
1525 sLog
.outCommand(_player
->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
1526 _player
->GetName(),_player
->GetSession()->GetAccountId(),
1527 pItemChar
->GetProto()->Name1
,pItemChar
->GetEntry(),pItemChar
->GetCount(),
1531 CharacterDatabase
.BeginTransaction();
1533 pGuild
->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemBank
->GetEntry(), pItemBank
->GetCount());
1534 pGuild
->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM
, BankTab
, pl
->GetGUIDLow(), pItemChar
->GetEntry(), pItemChar
->GetCount());
1536 pl
->MoveItemFromInventory(PlayerBag
, PlayerSlot
, true);
1537 pItemChar
->DeleteFromInventoryDB();
1539 pGuild
->RemoveItem(BankTab
, BankTabSlot
);
1541 pGuild
->StoreItem(BankTab
,gDest
,pItemChar
);
1543 pl
->MoveItemToInventory(iDest
,pItemBank
,true);
1544 pl
->SaveInventoryAndGoldToDB();
1546 pGuild
->MemberItemWithdraw(BankTab
, pl
->GetGUIDLow());
1547 CharacterDatabase
.CommitTransaction();
1549 pGuild
->DisplayGuildBankContentUpdate(BankTab
,gDest
);
1554 void WorldSession::HandleGuildBankBuyTab( WorldPacket
& recv_data
)
1556 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANK_BUY_TAB)");
1557 CHECK_PACKET_SIZE(recv_data
, 8+1);
1558 //recv_data.hexlike();
1562 recv_data
>> GoGuid
;
1565 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
1568 uint32 GuildId
= GetPlayer()->GetGuildId();
1572 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1576 uint32 TabCost
= objmgr
.GetGuildBankTabPrice(TabId
) * GOLD
;
1580 if (pGuild
->GetPurchasedTabs() >= GUILD_BANK_MAX_TABS
)
1583 if (TabId
!= pGuild
->GetPurchasedTabs()) // purchased_tabs = 0 when buying Tab 0, that is why this check can be made
1585 sLog
.outError("Error: trying to buy a tab non contigous to owned ones");
1589 if (GetPlayer()->GetMoney() < TabCost
) // Should not happen, this is checked by client
1592 // Go on with creating tab
1593 pGuild
->CreateNewBankTab();
1594 GetPlayer()->ModifyMoney(-int(TabCost
));
1595 pGuild
->SetBankMoneyPerDay(GetPlayer()->GetRank(), WITHDRAW_MONEY_UNLIMITED
);
1596 pGuild
->SetBankRightsAndSlots(GetPlayer()->GetRank(), TabId
, GUILD_BANK_RIGHT_FULL
, WITHDRAW_SLOT_UNLIMITED
, true);
1597 pGuild
->Roster(this);
1598 pGuild
->DisplayGuildBankTabsInfo(this);
1601 void WorldSession::HandleGuildBankModifyTab( WorldPacket
& recv_data
)
1603 sLog
.outDebug("WORLD: Received (CMSG_GUILD_BANK_UPDATE_TAB)");
1604 //recv_data.hexlike();
1605 CHECK_PACKET_SIZE(recv_data
, 8+1+1+1);
1609 std::string IconIndex
;
1611 recv_data
>> GoGuid
;
1614 recv_data
>> IconIndex
;
1619 if(IconIndex
.empty())
1622 if (!objmgr
.IsGuildVaultGameObject(_player
, GoGuid
))
1625 uint32 GuildId
= GetPlayer()->GetGuildId();
1629 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1633 pGuild
->SetGuildBankTabInfo(TabId
, Name
, IconIndex
);
1634 pGuild
->DisplayGuildBankTabsInfo(this);
1635 pGuild
->DisplayGuildBankContent(this, TabId
);
1638 void WorldSession::HandleGuildBankLog( WorldPacket
& recv_data
)
1640 sLog
.outDebug("WORLD: Received (MSG_GUILD_BANK_LOG_QUERY)");
1641 CHECK_PACKET_SIZE(recv_data
, 1);
1643 uint32 GuildId
= GetPlayer()->GetGuildId();
1647 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1654 pGuild
->DisplayGuildBankLogs(this, TabId
);
1657 void WorldSession::HandleGuildBankTabText(WorldPacket
&recv_data
)
1659 sLog
.outDebug("WORLD: Received MSG_QUERY_GUILD_BANK_TEXT");
1660 CHECK_PACKET_SIZE(recv_data
, 1);
1662 uint32 GuildId
= GetPlayer()->GetGuildId();
1666 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1673 pGuild
->SendGuildBankTabText(this, TabId
);
1676 void WorldSession::HandleGuildBankSetTabText(WorldPacket
&recv_data
)
1678 sLog
.outDebug("WORLD: Received CMSG_SET_GUILD_BANK_TEXT");
1679 CHECK_PACKET_SIZE(recv_data
, 1+1);
1681 uint32 GuildId
= GetPlayer()->GetGuildId();
1685 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
1694 pGuild
->SetGuildBankTabText(TabId
, Text
);
1697 void WorldSession::SendSaveGuildEmblem( uint32 msg
)
1699 WorldPacket
data(MSG_SAVE_GUILD_EMBLEM
, 4);
1700 data
<< uint32(msg
); // not part of guild
1701 SendPacket( &data
);