OregonCore  revision 3611e8a-git
Your Favourite TBC server
GuildHandler.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 "WorldPacket.h"
20 #include "WorldSession.h"
21 #include "World.h"
22 #include "ObjectMgr.h"
23 #include "Log.h"
24 #include "Guild.h"
25 #include "MapManager.h"
26 #include "SocialMgr.h"
27 
29 {
30  uint32 guildId;
31  Guild* guild;
32 
33  //sLog.outDebug("WORLD: Received CMSG_GUILD_QUERY");
34 
35  recvPacket >> guildId;
36 
37  guild = sObjectMgr.GetGuildById(guildId);
38  if (!guild)
39  {
41  return;
42  }
43 
44  guild->Query(this);
45 }
46 
48 {
49  //sLog.outDebug("WORLD: Received CMSG_GUILD_CREATE");
50 
51  std::string gname;
52  recvPacket >> gname;
53 
54  if (GetPlayer()->GetGuildId())
55  return;
56 
57  Guild* guild = new Guild;
58  if (!guild->Create(GetPlayer(), gname))
59  {
60  delete guild;
61  return;
62  }
63 
64  sObjectMgr.AddGuild(guild);
65 }
66 
68 {
69  //sLog.outDebug("WORLD: Received CMSG_GUILD_INVITE");
70 
71  std::string Invitedname, plname;
72  Player* player = NULL;
73  recvPacket >> Invitedname;
74 
75  if (normalizePlayerName(Invitedname))
76  player = ObjectAccessor::Instance().FindPlayerByName(Invitedname.c_str());
77 
78  if (!player)
79  {
81  return;
82  }
83 
84  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
85  if (!guild)
86  {
88  return;
89  }
90 
91  // OK result but not send invite
92  if (player->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()))
93  return;
94 
95  // not let enemies sign guild charter
96  if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && player->GetTeam() != GetPlayer()->GetTeam())
97  {
99  return;
100  }
101 
102  if (player->GetGuildId())
103  {
104  plname = player->GetName();
106  return;
107  }
108 
109  if (player->GetGuildIdInvited())
110  {
111  plname = player->GetName();
113  return;
114  }
115 
116  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_INVITE))
117  {
119  return;
120  }
121 
122  sLog.outDebug("Player %s Invited %s to Join his Guild", GetPlayer()->GetName(), Invitedname.c_str());
123 
124  player->SetGuildIdInvited(GetPlayer()->GetGuildId());
125  // Put record into guildlog
126  guild->LogGuildEvent(GUILD_EVENT_LOG_INVITE_PLAYER, GetPlayer()->GetGUIDLow(), player->GetGUIDLow(), 0);
127 
128  WorldPacket data(SMSG_GUILD_INVITE, (8 + 10)); // guess size
129  data << GetPlayer()->GetName();
130  data << guild->GetName();
131  player->GetSession()->SendPacket(&data);
132 
133  //sLog.outDebug("WORLD: Sent (SMSG_GUILD_INVITE)");
134 }
135 
137 {
138  //sLog.outDebug("WORLD: Received CMSG_GUILD_REMOVE");
139 
140  std::string plName;
141  recvPacket >> plName;
142 
143  if (!normalizePlayerName(plName))
144  return;
145 
146  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
147  if (!guild)
148  {
150  return;
151  }
152 
153  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_REMOVE))
154  {
156  return;
157  }
158 
159  uint64 plGuid;
160  MemberSlot* slot = guild->GetMemberSlot(plName, plGuid);
161  if (!slot)
162  {
164  return;
165  }
166 
167  if (slot->RankId == GR_GUILDMASTER)
168  {
170  return;
171  }
172 
173  guild->DelMember(plGuid);
174  // Put record into guildlog
175  guild->LogGuildEvent(GUILD_EVENT_LOG_UNINVITE_PLAYER, GetPlayer()->GetGUIDLow(), GUID_LOPART(plGuid), 0);
176 
177  WorldPacket data(SMSG_GUILD_EVENT, (2 + 20)); // guess size
178  data << (uint8)GE_REMOVED;
179  data << (uint8)2; // strings count
180  data << plName;
181  data << GetPlayer()->GetName();
182  guild->BroadcastPacket(&data);
183 }
184 
186 {
187  Guild* guild;
188  Player* player = GetPlayer();
189 
190  //sLog.outDebug("WORLD: Received CMSG_GUILD_ACCEPT");
191 
192  guild = sObjectMgr.GetGuildById(player->GetGuildIdInvited());
193  if (!guild || player->GetGuildId())
194  return;
195 
196  // not let enemies sign guild charter
197  if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && player->GetTeam() != sObjectMgr.GetPlayerTeamByGUID(guild->GetLeader()))
198  return;
199 
200  if (!guild->AddMember(GetPlayer()->GetGUID(), guild->GetLowestRank()))
201  return;
202  // Put record into guildlog
203  guild->LogGuildEvent(GUILD_EVENT_LOG_JOIN_GUILD, GetPlayer()->GetGUIDLow(), 0, 0);
204 
205  WorldPacket data(SMSG_GUILD_EVENT, (2 + 10)); // guess size
206  data << (uint8)GE_JOINED;
207  data << (uint8)1;
208  data << player->GetName();
209  guild->BroadcastPacket(&data);
210 
211  //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
212 }
213 
215 {
216  //sLog.outDebug("WORLD: Received CMSG_GUILD_DECLINE");
217 
219  GetPlayer()->SetInGuild(0);
220 }
221 
223 {
224  Guild* guild;
225  //sLog.outDebug("WORLD: Received CMSG_GUILD_INFO");
226 
227  guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
228  if (!guild)
229  {
231  return;
232  }
233 
234  WorldPacket data(SMSG_GUILD_INFO, (5 * 4 + guild->GetName().size() + 1));
235  data << guild->GetName();
236  data << guild->GetCreatedDay();
237  data << guild->GetCreatedMonth();
238  data << guild->GetCreatedYear();
239  data << guild->GetMemberSize(); // char amount
240  data << guild->GetAccountsNumber(); // acct amount
241 
242  SendPacket(&data);
243 }
244 
246 {
247  //sLog.outDebug("WORLD: Received CMSG_GUILD_ROSTER");
248 
249  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
250  if (!guild)
251  return;
252 
253  guild->Roster(this);
254 }
255 
257 {
258  //sLog.outDebug("WORLD: Received CMSG_GUILD_PROMOTE");
259 
260  std::string plName;
261  recvPacket >> plName;
262 
263  if (!normalizePlayerName(plName))
264  return;
265 
266  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
267  if (!guild)
268  {
270  return;
271  }
272  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_PROMOTE))
273  {
275  return;
276  }
277 
278  uint64 plGuid;
279  MemberSlot* slot = guild->GetMemberSlot(plName, plGuid);
280 
281  if (!slot)
282  {
284  return;
285  }
286 
287  if (plGuid == GetPlayer()->GetGUID())
288  {
290  return;
291  }
292 
293  if (slot->RankId < 2 || (slot->RankId - 1) < GetPlayer()->GetRank())
294  return;
295 
296  uint32 newRankId = slot->RankId < guild->GetNrRanks() ? slot->RankId - 1 : guild->GetNrRanks() - 1;
297 
298  guild->ChangeRank(plGuid, newRankId);
299  // Put record into guildlog
300  guild->LogGuildEvent(GUILD_EVENT_LOG_PROMOTE_PLAYER, GetPlayer()->GetGUIDLow(), GUID_LOPART(plGuid), newRankId);
301 
302  WorldPacket data(SMSG_GUILD_EVENT, (2 + 30)); // guess size
303  data << (uint8)GE_PROMOTION;
304  data << (uint8)3;
305  data << GetPlayer()->GetName();
306  data << plName;
307  data << guild->GetRankName(newRankId);
308  guild->BroadcastPacket(&data);
309 }
310 
312 {
313  //sLog.outDebug("WORLD: Received CMSG_GUILD_DEMOTE");
314 
315  std::string plName;
316  recvPacket >> plName;
317 
318  if (!normalizePlayerName(plName))
319  return;
320 
321  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
322 
323  if (!guild)
324  {
326  return;
327  }
328 
329  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_DEMOTE))
330  {
332  return;
333  }
334 
335  uint64 plGuid;
336  MemberSlot* slot = guild->GetMemberSlot(plName, plGuid);
337 
338  if (!slot)
339  {
341  return;
342  }
343 
344  if (plGuid == GetPlayer()->GetGUID())
345  {
347  return;
348  }
349 
350  if ((slot->RankId + 1) >= guild->GetNrRanks() || slot->RankId <= GetPlayer()->GetRank())
351  return;
352 
353  guild->ChangeRank(plGuid, (slot->RankId + 1));
354  // Put record into guildlog
355  guild->LogGuildEvent(GUILD_EVENT_LOG_DEMOTE_PLAYER, GetPlayer()->GetGUIDLow(), GUID_LOPART(plGuid), (slot->RankId));
356 
357  WorldPacket data(SMSG_GUILD_EVENT, (2 + 30)); // guess size
358  data << (uint8)GE_DEMOTION;
359  data << (uint8)3;
360  data << GetPlayer()->GetName();
361  data << plName;
362  data << guild->GetRankName(slot->RankId);
363  guild->BroadcastPacket(&data);
364 }
365 
367 {
368  std::string plName;
369  Guild* guild;
370  bool disband = false;
371 
372  guild = sObjectMgr.GetGuildById(_player->GetGuildId());
373 
374  // Check that the guild exists
375  // before going any further.
376  if (!guild)
377  {
379  return;
380  }
381  // Leader cannot leave if he is not the last member
382  if (_player->GetGUID() == guild->GetLeader())
383  {
384  if (guild->GetMemberSize() > 1)
386  else
387  {
388  // Guild is disbanded if leader leaves.
389  guild->Disband();
390  disband = true;
391  }
392  return;
393  }
394 
395  plName = _player->GetName();
396 
397  guild->DelMember(_player->GetGUID());
398  // Put record into guildlog
400 
401  WorldPacket data(SMSG_GUILD_EVENT, (2 + 10)); // guess size
402  data << (uint8)GE_LEFT;
403  data << (uint8)1;
404  data << plName;
405  guild->BroadcastPacket(&data);
406 
408 
409  if (disband)
410  delete this;
411 }
412 
414 {
415  Guild* guild;
416 
417  guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
418  if (!guild)
419  {
421  return;
422  }
423  if (GetPlayer()->GetGUID() != guild->GetLeader())
424  {
426  return;
427  }
428 
429  guild->Disband();
430  delete guild;
431 }
432 
434 {
435  std::string name;
436  Player* oldLeader = GetPlayer();
437  Guild* guild;
438 
439  //sLog.outDebug("WORLD: Received CMSG_GUILD_LEADER");
440 
441  recvPacket >> name;
442 
443  if (!normalizePlayerName(name))
444  return;
445 
446  guild = sObjectMgr.GetGuildById(oldLeader->GetGuildId());
447 
448  if (!guild)
449  {
451  return;
452  }
453 
454  if (oldLeader->GetGUID() != guild->GetLeader())
455  {
457  return;
458  }
459 
460  uint64 newLeaderGUID;
461  MemberSlot* slot = guild->GetMemberSlot(name, newLeaderGUID);
462 
463  if (!slot)
464  {
466  return;
467  }
468 
469  guild->SetLeader(newLeaderGUID);
470  guild->ChangeRank(oldLeader->GetGUID(), GR_OFFICER);
471 
472  WorldPacket data(SMSG_GUILD_EVENT, (2 + 20)); // guess size
473  data << (uint8)GE_LEADER_CHANGED;
474  data << (uint8)2;
475  data << oldLeader->GetName();
476  data << name.c_str();
477  guild->BroadcastPacket(&data);
478 
479  //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
480 }
481 
483 {
484  Guild* guild;
485  std::string MOTD;
486 
487  //sLog.outDebug("WORLD: Received CMSG_GUILD_MOTD");
488 
489  guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
490  if (!guild)
491  {
493  return;
494  }
495  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_SETMOTD))
496  {
498  return;
499  }
500 
501  if (!recvPacket.empty())
502  recvPacket >> MOTD;
503  else
504  MOTD = "";
505 
506  guild->SetMOTD(MOTD);
507 
508  WorldPacket data(SMSG_GUILD_EVENT, (2 + MOTD.size() + 1));
509  data << (uint8)GE_MOTD;
510  data << (uint8)1;
511  data << MOTD;
512  guild->BroadcastPacket(&data);
513 
514  //sLog.outDebug("WORLD: Sent (SMSG_GUILD_EVENT)");
515 }
516 
518 {
519  //sLog.outDebug("WORLD: Received CMSG_GUILD_SET_PUBLIC_NOTE");
520 
521  std::string name, PNOTE;
522  recvPacket >> name;
523 
524  if (!normalizePlayerName(name))
525  return;
526 
527  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
528  if (!guild)
529  {
531  return;
532  }
533 
534  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EPNOTE))
535  {
537  return;
538  }
539 
540  uint64 plGuid;
541  MemberSlot* slot = guild->GetMemberSlot(name, plGuid);
542 
543  if (!slot)
544  {
546  return;
547  }
548 
549  recvPacket >> PNOTE;
550 
551  guild->SetPNOTE(plGuid, PNOTE);
552 
553  guild->Roster(this);
554 }
555 
557 {
558  //sLog.outDebug("WORLD: Received CMSG_GUILD_SET_OFFICER_NOTE");
559 
560  std::string plName, OFFNOTE;
561  recvPacket >> plName;
562 
563  if (!normalizePlayerName(plName))
564  return;
565 
566  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
567  if (!guild)
568  {
570  return;
571  }
572  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EOFFNOTE))
573  {
575  return;
576  }
577 
578  uint64 plGuid;
579  MemberSlot* slot = guild->GetMemberSlot(plName, plGuid);
580 
581  if (!slot)
582  {
584  return;
585  }
586 
587  recvPacket >> OFFNOTE;
588 
589  guild->SetOFFNOTE(plGuid, OFFNOTE);
590 
591  guild->Roster(this);
592 }
593 
595 {
596  Guild* guild;
597  std::string rankname;
598  uint32 rankId;
599  uint32 rights, MoneyPerDay;
600  uint32 BankRights;
601  uint32 BankSlotPerDay;
602 
603  //sLog.outDebug("WORLD: Received CMSG_GUILD_RANK");
604 
605  guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
606  if (!guild)
607  {
609  return;
610  }
611 
612  else if (GetPlayer()->GetGUID() != guild->GetLeader())
613  {
615  return;
616  }
617 
618  recvPacket >> rankId;
619  recvPacket >> rights;
620  recvPacket >> rankname;
621  recvPacket >> MoneyPerDay;
622 
623  for (int i = 0; i < GUILD_BANK_MAX_TABS; ++i)
624  {
625  recvPacket >> BankRights;
626  recvPacket >> BankSlotPerDay;
627  guild->SetBankRightsAndSlots(rankId, uint8(i), uint16(BankRights & 0xFF), uint16(BankSlotPerDay), true);
628  }
629  sLog.outDebug("WORLD: Changed RankName to %s , Rights to 0x%.4X", rankname.c_str(), rights);
630 
631  guild->SetBankMoneyPerDay(rankId, MoneyPerDay);
632  guild->SetRankName(rankId, rankname);
633 
634  if (rankId == GR_GUILDMASTER) // prevent loss leader rights
635  rights |= GR_RIGHT_ALL;
636 
637  guild->SetRankRights(rankId, rights);
638 
639  guild->Query(this);
640  guild->Roster(); // broadcast for tab rights update
641 }
642 
644 {
645  Guild* guild;
646  std::string rankname;
647 
648  //sLog.outDebug("WORLD: Received CMSG_GUILD_ADD_RANK");
649 
650  guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
651  if (!guild)
652  {
654  return;
655  }
656 
657  if (GetPlayer()->GetGUID() != guild->GetLeader())
658  {
660  return;
661  }
662 
663  if (guild->GetNrRanks() >= GUILD_MAX_RANKS) // client not let create more 10 than ranks
664  return;
665 
666  recvPacket >> rankname;
667 
669 
670  guild->Query(this);
671  guild->Roster(); // broadcast for tab rights update
672 }
673 
675 {
676  Guild* guild;
677  std::string rankname;
678 
679  //sLog.outDebug("WORLD: Received CMSG_GUILD_DEL_RANK");
680 
681  guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
682  if (!guild)
683  {
685  return;
686  }
687 
688  else if (GetPlayer()->GetGUID() != guild->GetLeader())
689  {
691  return;
692  }
693 
694  guild->DelRank();
695 
696  guild->Query(this);
697  guild->Roster(); // broadcast for tab rights update
698 }
699 
700 void WorldSession::SendGuildCommandResult(uint32 typecmd, const std::string& str, uint32 cmdresult)
701 {
702  WorldPacket data(SMSG_GUILD_COMMAND_RESULT, (8 + str.size() + 1));
703  data << typecmd;
704  data << str;
705  data << cmdresult;
706  SendPacket(&data);
707 
708  //sLog.outDebug("WORLD: Sent (SMSG_GUILD_COMMAND_RESULT)");
709 }
710 
712 {
713  //sLog.outDebug("WORLD: Received CMSG_GUILD_INFO_TEXT");
714 
715  std::string GINFO;
716  recvPacket >> GINFO;
717 
718  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
719  if (!guild)
720  {
722  return;
723  }
724 
725  if (!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_MODIFY_GUILD_INFO))
726  {
728  return;
729  }
730 
731  guild->SetGINFO(GINFO);
732 }
733 
735 {
736  //sLog.outDebug("WORLD: Received MSG_SAVE_GUILD_EMBLEM");
737 
738  uint64 vendorGuid;
739 
740  uint32 EmblemStyle;
741  uint32 EmblemColor;
742  uint32 BorderStyle;
743  uint32 BorderColor;
744  uint32 BackgroundColor;
745 
746  recvPacket >> vendorGuid;
747 
749  if (!pCreature)
750  {
751  //"That's not an emblem vendor!"
753  sLog.outDebug("WORLD: HandleGuildSaveEmblemOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(vendorGuid));
754  return;
755  }
756 
757  // remove fake death
758  if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
760 
761  recvPacket >> EmblemStyle;
762  recvPacket >> EmblemColor;
763  recvPacket >> BorderStyle;
764  recvPacket >> BorderColor;
765  recvPacket >> BackgroundColor;
766 
767  Guild* guild = sObjectMgr.GetGuildById(GetPlayer()->GetGuildId());
768  if (!guild)
769  {
770  //"You are not part of a guild!";
772  return;
773  }
774 
775  if (guild->GetLeader() != GetPlayer()->GetGUID())
776  {
777  //"Only guild leaders can create emblems."
779  return;
780  }
781 
782  if (GetPlayer()->GetMoney() < 10 * GOLD)
783  {
784  //"You can't afford to do that."
786  return;
787  }
788 
789  GetPlayer()->ModifyMoney(-10 * GOLD);
790  guild->SetEmblem(EmblemStyle, EmblemColor, BorderStyle, BorderColor, BackgroundColor);
791 
792  //"Guild Emblem saved."
794 
795  guild->Query(this);
796 }
797 
799 {
800  // empty
801  sLog.outDebug("WORLD: Received (MSG_GUILD_EVENT_LOG_QUERY)");
802  //recvPacket.hexlike();
803 
804  uint32 GuildId = GetPlayer()->GetGuildId();
805  if (GuildId == 0)
806  return;
807 
808  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
809  if (!pGuild)
810  return;
811 
812  pGuild->DisplayGuildEventlog(this);
813 }
814 
815 /****** GUILD BANK *******/
816 
818 {
819  sLog.outDebug("WORLD: Received (MSG_GUILD_BANK_MONEY_WITHDRAWN)");
820  //recv_data.hexlike();
821 
822  uint32 GuildId = GetPlayer()->GetGuildId();
823  if (GuildId == 0)
824  return;
825 
826  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
827  if (!pGuild)
828  return;
829 
830  pGuild->SendMoneyInfo(this, GetPlayer()->GetGUIDLow());
831 }
832 
834 {
835  sLog.outDebug("WORLD: Received (MSG_GUILD_PERMISSIONS)");
836 
837  uint32 GuildId = GetPlayer()->GetGuildId();
838  if (GuildId == 0)
839  return;
840 
841  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
842  if (!pGuild)
843  return;
844 
845  uint32 rankId = GetPlayer()->GetRank();
846 
847  WorldPacket data(MSG_GUILD_PERMISSIONS, 4 * 15 + 1);
848  data << uint32(rankId); // guild rank id
849  data << uint32(pGuild->GetRankRights(rankId)); // rank rights
850  // money per day left
851  data << uint32(pGuild->GetMemberMoneyWithdrawRem(GetPlayer()->GetGUIDLow()));
852  data << uint8(pGuild->GetPurchasedTabs()); // tabs count
853  for (int i = 0; i < GUILD_BANK_MAX_TABS; ++i)
854  {
855  data << uint32(pGuild->GetBankRights(rankId, uint8(i)));
856  data << uint32(pGuild->GetMemberSlotWithdrawRem(GetPlayer()->GetGUIDLow(), uint8(i)));
857  }
858  SendPacket(&data);
859  sLog.outDebug("WORLD: Sent (MSG_GUILD_PERMISSIONS)");
860 }
861 
862 /* Called when clicking on Guild bank GameObject*/
864 {
865  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANKER_ACTIVATE)");
866 
867  uint64 GoGuid;
868  uint8 unk;
869  recv_data >> GoGuid >> unk;
870 
871  if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK))
872  return;
873 
874  if (uint32 GuildId = GetPlayer()->GetGuildId())
875  {
876  if (Guild* pGuild = sObjectMgr.GetGuildById(GuildId))
877  {
878  pGuild->DisplayGuildBankTabsInfo(this);
879  return;
880  }
881  }
882 
884 }
885 
886 /* Called when opening guild bank tab only (first one) */
888 {
889  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANK_QUERY_TAB)");
890 
891  uint64 GoGuid;
892  uint8 TabId, unk1;
893  recv_data >> GoGuid >> TabId >> unk1;
894 
895  if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK))
896  return;
897 
898  uint32 GuildId = GetPlayer()->GetGuildId();
899  if (GuildId == 0)
900  return;
901 
902  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
903  if (!pGuild)
904  return;
905 
906  // Let's update the amount of gold the player can withdraw before displaying the content
907  // This is usefull if money withdraw right has changed
908  pGuild->SendMoneyInfo(this, GetPlayer()->GetGUIDLow());
909 
910  pGuild->DisplayGuildBankContent(this, TabId);
911 }
912 
914 {
915  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANK_DEPOSIT_MONEY)");
916 
917  uint64 GoGuid;
918  uint32 money;
919  recv_data >> GoGuid >> money;
920 
921  if (!money)
922  return;
923 
924  if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK))
925  return;
926 
927  uint32 GuildId = GetPlayer()->GetGuildId();
928  if (GuildId == 0)
929  return;
930 
931  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
932  if (!pGuild)
933  return;
934 
935  if (GetPlayer()->GetMoney() < money)
936  return;
937 
939 
940  pGuild->SetBankMoney(pGuild->GetGuildBankMoney() + money);
941  GetPlayer()->ModifyMoney(-int(money));
942  GetPlayer()->SaveDataFieldToDB(); //contains money
943 
945 
946  // logging money
948  {
949  sLog.outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) deposit money (Amount: %u) to guild bank (Guild ID %u)",
950  _player->GetName(), _player->GetSession()->GetAccountId(), money, GuildId);
951  }
952 
953  // log
954  pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_MONEY, uint8(0), GetPlayer()->GetGUIDLow(), money);
955 
956  pGuild->DisplayGuildBankTabsInfo(this);
957  pGuild->DisplayGuildBankContent(this, 0);
958  pGuild->DisplayGuildBankMoneyUpdate();
959 }
960 
962 {
963  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANK_WITHDRAW_MONEY)");
964 
965  uint64 GoGuid;
966  uint32 money;
967  recv_data >> GoGuid >> money;
968 
969  if (!money)
970  return;
971 
972  if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK))
973  return;
974 
975  uint32 GuildId = GetPlayer()->GetGuildId();
976  if (GuildId == 0)
977  return;
978 
979  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
980  if (!pGuild)
981  return;
982 
983  if (pGuild->GetGuildBankMoney() < money) // not enough money in bank
984  return;
985 
986  if (!pGuild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_WITHDRAW_GOLD))
987  return;
988 
990 
991  if (!pGuild->MemberMoneyWithdraw(money, GetPlayer()->GetGUIDLow()))
992  {
994  return;
995  }
996 
997  GetPlayer()->ModifyMoney(money);
998  GetPlayer()->SaveGoldToDB();
999 
1001 
1002  // Log
1003  pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_MONEY, uint8(0), GetPlayer()->GetGUIDLow(), money);
1004 
1005  pGuild->SendMoneyInfo(this, GetPlayer()->GetGUIDLow());
1006  pGuild->DisplayGuildBankTabsInfo(this);
1007  pGuild->DisplayGuildBankContent(this, 0);
1008  pGuild->DisplayGuildBankMoneyUpdate();
1009 }
1010 
1012 {
1013  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANK_SWAP_ITEMS)");
1014  //recv_data.hexlike();
1015 
1016  uint64 GoGuid;
1017  uint8 BankToBank;
1018 
1019  uint8 BankTab, BankTabSlot, AutoStore = 0, AutoStoreCount, PlayerSlot = 0, PlayerBag = 0, SplitedAmount = 0;
1020  uint8 BankTabDst = 0, BankTabSlotDst = 0, unk2, ToChar = 1;
1021  uint32 ItemEntry, unk1;
1022  recv_data >> GoGuid >> BankToBank;
1023  if (BankToBank)
1024  {
1025  recv_data >> BankTabDst;
1026  recv_data >> BankTabSlotDst;
1027  recv_data >> unk1; // always 0
1028  recv_data >> BankTab;
1029  recv_data >> BankTabSlot;
1030  recv_data >> ItemEntry;
1031  recv_data >> unk2; // always 0
1032  recv_data >> SplitedAmount;
1033 
1034  if (BankTabSlotDst >= GUILD_BANK_MAX_SLOTS)
1035  return;
1036  if (BankTabDst == BankTab && BankTabSlotDst == BankTabSlot)
1037  return;
1038  }
1039  else
1040  {
1041  recv_data >> BankTab;
1042  recv_data >> BankTabSlot;
1043  recv_data >> ItemEntry;
1044  recv_data >> AutoStore;
1045  if (AutoStore)
1046  recv_data >> AutoStoreCount;
1047  recv_data >> PlayerBag;
1048  recv_data >> PlayerSlot;
1049  if (!AutoStore)
1050  {
1051  recv_data >> ToChar;
1052  recv_data >> SplitedAmount;
1053  }
1054 
1055  if (BankTabSlot >= GUILD_BANK_MAX_SLOTS && BankTabSlot != 0xFF)
1056  return;
1057  }
1058 
1059  if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK))
1060  return;
1061 
1062  uint32 GuildId = GetPlayer()->GetGuildId();
1063  if (GuildId == 0)
1064  return;
1065 
1066  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
1067  if (!pGuild)
1068  return;
1069 
1070  Player* pl = GetPlayer();
1071 
1072  // player->bank or bank->bank check if tab is correct to prevent crash
1073  if (!ToChar && !pGuild->GetBankTab(BankTab))
1074  return;
1075 
1076  // Bank <-> Bank
1077  if (BankToBank)
1078  {
1079  // empty operation
1080  if (BankTab == BankTabDst && BankTabSlot == BankTabSlotDst)
1081  return;
1082 
1083  Item* pItemSrc = pGuild->GetItem(BankTab, BankTabSlot);
1084  if (!pItemSrc) // may prevent crash
1085  return;
1086 
1087  if (SplitedAmount > pItemSrc->GetCount())
1088  return; // cheating?
1089  else if (SplitedAmount == pItemSrc->GetCount())
1090  SplitedAmount = 0; // no split
1091 
1092  Item* pItemDst = pGuild->GetItem(BankTabDst, BankTabSlotDst);
1093 
1094  if (BankTab != BankTabDst)
1095  {
1096  // check dest pos rights (if different tabs)
1097  if (!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTabDst, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
1098  return;
1099 
1100  // check source pos rights (if different tabs)
1101  uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
1102  if (remRight <= 0)
1103  return;
1104  }
1105 
1106  if (SplitedAmount)
1107  {
1108  // Bank -> Bank item split (in empty or non empty slot
1109  GuildItemPosCountVec dest;
1110  uint8 msg = pGuild->CanStoreItem(BankTabDst, BankTabSlotDst, dest, SplitedAmount, pItemSrc, false);
1111  if (msg != EQUIP_ERR_OK)
1112  {
1113  pl->SendEquipError(msg, pItemSrc, NULL);
1114  return;
1115  }
1116 
1117  Item* pNewItem = pItemSrc->CloneItem(SplitedAmount);
1118  if (!pNewItem)
1119  {
1120  pl->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItemSrc, NULL);
1121  return;
1122  }
1123 
1125  pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), SplitedAmount, BankTabDst);
1126 
1127  pl->ItemRemovedQuestCheck(pItemSrc->GetEntry(), SplitedAmount);
1128  pItemSrc->SetCount(pItemSrc->GetCount() - SplitedAmount);
1129  pItemSrc->FSetState(ITEM_CHANGED);
1130  pItemSrc->SaveToDB(); // not in inventory and can be save standalone
1131  pGuild->StoreItem(BankTabDst, dest, pNewItem);
1133  }
1134  else // non split
1135  {
1136  GuildItemPosCountVec gDest;
1137  uint8 msg = pGuild->CanStoreItem(BankTabDst, BankTabSlotDst, gDest, pItemSrc->GetCount(), pItemSrc, false);
1138  if (msg == EQUIP_ERR_OK) // merge to
1139  {
1141  pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), pItemSrc->GetCount(), BankTabDst);
1142 
1143  pGuild->RemoveItem(BankTab, BankTabSlot);
1144  pGuild->StoreItem(BankTabDst, gDest, pItemSrc);
1146  }
1147  else // swap
1148  {
1149  gDest.clear();
1150  uint8 msg = pGuild->CanStoreItem(BankTabDst, BankTabSlotDst, gDest, pItemSrc->GetCount(), pItemSrc, true);
1151  if (msg != EQUIP_ERR_OK)
1152  {
1153  pl->SendEquipError(msg, pItemSrc, NULL);
1154  return;
1155  }
1156 
1157  GuildItemPosCountVec gSrc;
1158  msg = pGuild->CanStoreItem(BankTab, BankTabSlot, gSrc, pItemDst->GetCount(), pItemDst, true);
1159  if (msg != EQUIP_ERR_OK)
1160  {
1161  pl->SendEquipError(msg, pItemDst, NULL);
1162  return;
1163  }
1164 
1165  if (BankTab != BankTabDst)
1166  {
1167  // check source pos rights (item swapped to src)
1168  if (!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
1169  return;
1170 
1171  // check dest pos rights (item swapped to src)
1172  uint32 remRightDst = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTabDst);
1173  if (remRightDst <= 0)
1174  return;
1175  }
1176 
1178  pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), pItemSrc->GetCount(), BankTabDst);
1179  pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTabDst, pl->GetGUIDLow(), pItemDst->GetEntry(), pItemDst->GetCount(), BankTab);
1180 
1181  pGuild->RemoveItem(BankTab, BankTabSlot);
1182  pGuild->RemoveItem(BankTabDst, BankTabSlotDst);
1183  pGuild->StoreItem(BankTab, gSrc, pItemDst);
1184  pGuild->StoreItem(BankTabDst, gDest, pItemSrc);
1186  }
1187  }
1188  pGuild->DisplayGuildBankContentUpdate(BankTab, BankTabSlot, BankTab == BankTabDst ? BankTabSlotDst : -1);
1189  if (BankTab != BankTabDst)
1190  pGuild->DisplayGuildBankContentUpdate(BankTabDst, BankTabSlotDst);
1191  return;
1192  }
1193 
1194  // Player <-> Bank
1195 
1196  // char->bank autostore click return BankTabSlot = 255 = NULL_SLOT
1197  // do similar for bank->char
1198  if (AutoStore && ToChar)
1199  {
1200  PlayerBag = NULL_BAG;
1201  PlayerSlot = NULL_SLOT;
1202  }
1203 
1204  // allow work with inventory only
1205  if (!Player::IsInventoryPos(PlayerBag, PlayerSlot) && !(PlayerBag == NULL_BAG && PlayerSlot == NULL_SLOT))
1206  {
1207  _player->SendEquipError(EQUIP_ERR_NONE, NULL, NULL);
1208  return;
1209  }
1210 
1211  Item* pItemBank = pGuild->GetItem(BankTab, BankTabSlot);
1212  Item* pItemChar = GetPlayer()->GetItemByPos(PlayerBag, PlayerSlot);
1213  if (!pItemChar && !pItemBank) // Nothing to do
1214  return;
1215 
1216  if (!pItemChar && !ToChar) // Problem to get item from player
1217  return;
1218 
1219  if (!pItemBank && ToChar) // Problem to get bank item
1220  return;
1221 
1222  // BankToChar swap or char to bank remaining
1223 
1224  if (ToChar) // Bank -> Char cases
1225  {
1226  if (SplitedAmount > pItemBank->GetCount())
1227  return; // cheating?
1228  else if (SplitedAmount == pItemBank->GetCount())
1229  SplitedAmount = 0; // no split
1230 
1231  if (SplitedAmount)
1232  {
1233  // Bank -> Char split to slot (patly move)
1234  Item* pNewItem = pItemBank->CloneItem(SplitedAmount);
1235  if (!pNewItem)
1236  {
1237  pl->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItemBank, NULL);
1238  return;
1239  }
1240 
1241  ItemPosCountVec dest;
1242  uint8 msg = pl->CanStoreItem(PlayerBag, PlayerSlot, dest, pNewItem, false);
1243  if (msg != EQUIP_ERR_OK)
1244  {
1245  pl->SendEquipError(msg, pNewItem, NULL);
1246  delete pNewItem;
1247  return;
1248  }
1249 
1250  // check source pos rights (item moved to inventory)
1251  uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
1252  if (remRight <= 0)
1253  {
1254  delete pNewItem;
1255  return;
1256  }
1257 
1259  pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), SplitedAmount);
1260 
1261  pItemBank->SetCount(pItemBank->GetCount() - SplitedAmount);
1262  pItemBank->FSetState(ITEM_CHANGED);
1263  pItemBank->SaveToDB(); // not in inventory and can be save standalone
1264  pl->MoveItemToInventory(dest, pNewItem, true);
1266 
1267  pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
1269  }
1270  else // Bank -> Char swap with slot (move)
1271  {
1272  ItemPosCountVec dest;
1273  uint8 msg = pl->CanStoreItem(PlayerBag, PlayerSlot, dest, pItemBank, false);
1274  if (msg == EQUIP_ERR_OK) // merge case
1275  {
1276  // check source pos rights (item moved to inventory)
1277  uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
1278  if (remRight <= 0)
1279  return;
1280 
1282  pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
1283 
1284  pGuild->RemoveItem(BankTab, BankTabSlot);
1285  pl->MoveItemToInventory(dest, pItemBank, true);
1287 
1288  pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
1290  }
1291  else // Bank <-> Char swap items
1292  {
1293  // check source pos rights (item swapped to bank)
1294  if (!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
1295  return;
1296 
1297  if (pItemChar)
1298  {
1299  if (!pItemChar->CanBeTraded())
1300  {
1302  return;
1303  }
1304  }
1305 
1306  ItemPosCountVec iDest;
1307  msg = pl->CanStoreItem(PlayerBag, PlayerSlot, iDest, pItemBank, true);
1308  if (msg != EQUIP_ERR_OK)
1309  {
1310  pl->SendEquipError(msg, pItemBank, NULL);
1311  return;
1312  }
1313 
1314  GuildItemPosCountVec gDest;
1315  if (pItemChar)
1316  {
1317  msg = pGuild->CanStoreItem(BankTab, BankTabSlot, gDest, pItemChar->GetCount(), pItemChar, true);
1318  if (msg != EQUIP_ERR_OK)
1319  {
1320  pl->SendEquipError(msg, pItemChar, NULL);
1321  return;
1322  }
1323  }
1324 
1325  // check source pos rights (item moved to inventory)
1326  uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
1327  if (remRight <= 0)
1328  return;
1329 
1330  if (pItemChar)
1331  {
1332  // logging item move to bank
1334  {
1335  sLog.outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u)",
1337  pItemChar->GetProto()->Name1, pItemChar->GetEntry(), pItemChar->GetCount(),
1338  GuildId);
1339  }
1340  }
1341 
1343  pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
1344  if (pItemChar)
1345  pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
1346 
1347  pGuild->RemoveItem(BankTab, BankTabSlot);
1348  if (pItemChar)
1349  {
1350  pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
1351  pItemChar->DeleteFromInventoryDB();
1352  pGuild->StoreItem(BankTab, gDest, pItemChar);
1353  }
1354 
1355  pl->MoveItemToInventory(iDest, pItemBank, true);
1357 
1358  pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
1360  }
1361  }
1362  pGuild->DisplayGuildBankContentUpdate(BankTab, BankTabSlot);
1363  return;
1364  } // End "To char" part
1365 
1366  // Char -> Bank cases
1367 
1368  if (!pItemChar->CanBeTraded())
1369  {
1371  return;
1372  }
1373 
1374  // check source pos rights (item moved to bank)
1375  if (!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
1376  return;
1377 
1378  if (SplitedAmount > pItemChar->GetCount())
1379  return; // cheating?
1380  else if (SplitedAmount == pItemChar->GetCount())
1381  SplitedAmount = 0; // no split
1382 
1383  if (SplitedAmount)
1384  {
1385  // Char -> Bank split to empty or non-empty slot (partly move)
1386  GuildItemPosCountVec dest;
1387  uint8 msg = pGuild->CanStoreItem(BankTab, BankTabSlot, dest, SplitedAmount, pItemChar, false);
1388  if (msg != EQUIP_ERR_OK)
1389  {
1390  pl->SendEquipError(msg, pItemChar, NULL);
1391  return;
1392  }
1393 
1394  Item* pNewItem = pItemChar->CloneItem(SplitedAmount);
1395  if (!pNewItem)
1396  {
1397  pl->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItemChar, NULL);
1398  return;
1399  }
1400 
1401  // logging item move to bank (before items merge
1403  {
1404  sLog.outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u)",
1406  pItemChar->GetProto()->Name1, pItemChar->GetEntry(), SplitedAmount, GuildId);
1407  }
1408 
1410  pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), SplitedAmount);
1411 
1412  pl->ItemRemovedQuestCheck(pItemChar->GetEntry(), SplitedAmount);
1413  pItemChar->SetCount(pItemChar->GetCount() - SplitedAmount);
1414  pItemChar->SetState(ITEM_CHANGED, pl);
1416  pGuild->StoreItem(BankTab, dest, pNewItem);
1418 
1419  pGuild->DisplayGuildBankContentUpdate(BankTab, dest);
1420  }
1421  else // Char -> Bank swap with empty or non-empty (move)
1422  {
1423  GuildItemPosCountVec dest;
1424  uint8 msg = pGuild->CanStoreItem(BankTab, BankTabSlot, dest, pItemChar->GetCount(), pItemChar, false);
1425  if (msg == EQUIP_ERR_OK) // merge
1426  {
1427  // logging item move to bank
1429  {
1430  sLog.outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u)",
1432  pItemChar->GetProto()->Name1, pItemChar->GetEntry(), pItemChar->GetCount(),
1433  GuildId);
1434  }
1435 
1437  pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
1438 
1439  pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
1440  pItemChar->DeleteFromInventoryDB();
1441 
1442  pGuild->StoreItem(BankTab, dest, pItemChar);
1445 
1446  pGuild->DisplayGuildBankContentUpdate(BankTab, dest);
1447  }
1448  else // Char <-> Bank swap items (posible NULL bank item)
1449  {
1450  ItemPosCountVec iDest;
1451  if (pItemBank)
1452  {
1453  msg = pl->CanStoreItem(PlayerBag, PlayerSlot, iDest, pItemBank, true);
1454  if (msg != EQUIP_ERR_OK)
1455  {
1456  pl->SendEquipError(msg, pItemBank, NULL);
1457  return;
1458  }
1459  }
1460 
1461  GuildItemPosCountVec gDest;
1462  msg = pGuild->CanStoreItem(BankTab, BankTabSlot, gDest, pItemChar->GetCount(), pItemChar, true);
1463  if (msg != EQUIP_ERR_OK)
1464  {
1465  pl->SendEquipError(msg, pItemChar, NULL);
1466  return;
1467  }
1468 
1469  if (pItemBank)
1470  {
1471  // check bank pos rights (item swapped with inventory)
1472  uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
1473  if (remRight <= 0)
1474  return;
1475  }
1476 
1477  // logging item move to bank
1479  {
1480  sLog.outCommand(_player->GetSession()->GetAccountId(), "GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u)",
1482  pItemChar->GetProto()->Name1, pItemChar->GetEntry(), pItemChar->GetCount(),
1483  GuildId);
1484  }
1485 
1487  if (pItemBank)
1488  pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
1489  pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
1490 
1491  pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
1492  pItemChar->DeleteFromInventoryDB();
1493  if (pItemBank)
1494  pGuild->RemoveItem(BankTab, BankTabSlot);
1495 
1496  pGuild->StoreItem(BankTab, gDest, pItemChar);
1497  if (pItemBank)
1498  pl->MoveItemToInventory(iDest, pItemBank, true);
1500  if (pItemBank)
1501  pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
1503 
1504  pGuild->DisplayGuildBankContentUpdate(BankTab, gDest);
1505  }
1506  }
1507 }
1508 
1510 {
1511  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANK_BUY_TAB)");
1512 
1513  uint64 GoGuid;
1514  uint8 TabId;
1515 
1516  recv_data >> GoGuid;
1517  recv_data >> TabId;
1518 
1519  if (!GetPlayer()->GetGameObjectIfCanInteractWith(GoGuid, GAMEOBJECT_TYPE_GUILD_BANK))
1520  return;
1521 
1522  uint32 GuildId = GetPlayer()->GetGuildId();
1523  if (GuildId == 0)
1524  return;
1525 
1526  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
1527  if (!pGuild)
1528  return;
1529 
1530  uint32 TabCost = sObjectMgr.GetGuildBankTabPrice(TabId) * GOLD;
1531  if (!TabCost)
1532  return;
1533 
1534  if (pGuild->GetPurchasedTabs() >= GUILD_BANK_MAX_TABS)
1535  return;
1536 
1537  if (TabId != pGuild->GetPurchasedTabs()) // purchased_tabs = 0 when buying Tab 0, that is why this check can be made
1538  {
1539  sLog.outError("trying to buy a tab non contigous to owned ones");
1540  return;
1541  }
1542 
1543  if (GetPlayer()->GetMoney() < TabCost) // Should not happen, this is checked by client
1544  return;
1545 
1546  // Go on with creating tab
1547  pGuild->CreateNewBankTab();
1548  GetPlayer()->ModifyMoney(-int(TabCost));
1549  pGuild->SetBankMoneyPerDay(GetPlayer()->GetRank(), WITHDRAW_MONEY_UNLIMITED);
1551  pGuild->Roster(); // broadcast for tab rights update
1552  pGuild->DisplayGuildBankTabsInfo(this);
1553 }
1554 
1556 {
1557  sLog.outDebug("WORLD: Received (CMSG_GUILD_BANK_UPDATE_TAB)");
1558 
1559  uint64 GoGuid;
1560  uint8 TabId;
1561  std::string Name;
1562  std::string IconIndex;
1563 
1564  recv_data >> GoGuid;
1565  recv_data >> TabId;
1566  recv_data >> Name;
1567  recv_data >> IconIndex;
1568 
1569  if (Name.empty())
1570  return;
1571 
1572  if (IconIndex.empty())
1573  return;
1574 
1576  return;
1577 
1578  uint32 GuildId = GetPlayer()->GetGuildId();
1579  if (GuildId == 0)
1580  return;
1581 
1582  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
1583  if (!pGuild)
1584  return;
1585 
1586  pGuild->SetGuildBankTabInfo(TabId, Name, IconIndex);
1587  pGuild->DisplayGuildBankTabsInfo(this);
1588  pGuild->DisplayGuildBankContent(this, TabId);
1589 }
1590 
1592 {
1593  sLog.outDebug("WORLD: Received (MSG_GUILD_BANK_LOG_QUERY)");
1594 
1595  uint32 GuildId = GetPlayer()->GetGuildId();
1596  if (GuildId == 0)
1597  return;
1598 
1599  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
1600  if (!pGuild)
1601  return;
1602 
1603  uint8 TabId;
1604  recv_data >> TabId;
1605 
1606  pGuild->DisplayGuildBankLogs(this, TabId);
1607 }
1608 
1610 {
1611  sLog.outDebug("WORLD: Received MSG_QUERY_GUILD_BANK_TEXT");
1612 
1613  uint32 GuildId = GetPlayer()->GetGuildId();
1614  if (GuildId == 0)
1615  return;
1616 
1617  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
1618  if (!pGuild)
1619  return;
1620 
1621  uint8 TabId;
1622  recv_data >> TabId;
1623 
1624  pGuild->SendGuildBankTabText(this, TabId);
1625 }
1626 
1628 {
1629  sLog.outDebug("WORLD: Received CMSG_SET_GUILD_BANK_TEXT");
1630 
1631  uint32 GuildId = GetPlayer()->GetGuildId();
1632  if (GuildId == 0)
1633  return;
1634 
1635  Guild* pGuild = sObjectMgr.GetGuildById(GuildId);
1636  if (!pGuild)
1637  return;
1638 
1639  uint8 TabId;
1640  std::string Text;
1641  recv_data >> TabId;
1642  recv_data >> Text;
1643 
1644  pGuild->SetGuildBankTabText(TabId, Text);
1645 }
1646 
1648 {
1650  data << uint32(msg); // not part of guild
1651  SendPacket(&data);
1652 }
1653 
void LogGuildEvent(uint8 EventType, uint32 PlayerGuid1, uint32 PlayerGuid2, uint8 NewRank)
Definition: Guild.cpp:952
void HandleGuildBankBuyTab(WorldPacket &recv_data)
void SendMoneyInfo(WorldSession *session, uint32 LowGuid)
Definition: Guild.cpp:1315
uint32 GetCount() const
Definition: Item.h:251
ItemTemplate const * GetProto() const
Definition: Item.cpp:460
void HandleGuildPromoteOpcode(WorldPacket &recvPacket)
void SetState(ItemUpdateState state, Player *forplayer=NULL)
Definition: Item.cpp:661
void MoveItemFromInventory(uint8 bag, uint8 slot, bool update)
Definition: Player.cpp:10687
#define GUILD_BANK_MAX_SLOTS
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
void HandleGuildAcceptOpcode(WorldPacket &recvPacket)
void SetBankRightsAndSlots(uint32 rankId, uint8 TabId, uint32 right, uint32 SlotPerDay, bool db)
Definition: Guild.cpp:1449
void CreateRank(std::string m_Name, uint32 rights)
Definition: Guild.cpp:634
Definition: Guild.h:105
uint32 GetLowestRank() const
Definition: Guild.h:337
void SetInGuild(uint32 GuildId)
Definition: Player.h:1825
void SendGuildCommandResult(uint32 typecmd, const std::string &str, uint32 cmdresult)
void SetGuildBankTabInfo(uint8 TabId, std::string m_Name, std::string icon)
Definition: Guild.cpp:1160
void HandleGuildLeaderOpcode(WorldPacket &recvPacket)
bool BeginTransaction()
Definition: Database.cpp:533
void LogBankEvent(uint8 LogEntry, uint8 TabId, uint32 PlayerGuidLow, uint32 ItemOrMoney, uint8 ItemStackCount=0, uint8 DestTabId=0)
Definition: Guild.cpp:1652
void HandleGuildBankDepositItem(WorldPacket &recv_data)
void DelMember(uint64 guid, bool isDisbanding=false)
Definition: Guild.cpp:484
void HandleGuildBankSetTabText(WorldPacket &recv_data)
void HandleGuildBankLog(WorldPacket &recv_data)
Item * CloneItem(uint32 count, Player const *player=NULL) const
Definition: Item.cpp:963
uint32 RankId
Definition: Guild.h:234
void FSetState(ItemUpdateState state)
Definition: Item.h:358
#define WITHDRAW_MONEY_UNLIMITED
Definition: Guild.h:21
void HandleGuildBankTabText(WorldPacket &recv_data)
void SetBankMoneyPerDay(uint32 rankId, uint32 money)
Definition: Guild.cpp:1431
virtual void SaveToDB()
Definition: Item.cpp:286
bool HasIgnore(uint32 ignore_guid)
Definition: SocialMgr.cpp:162
void RemoveSpellsCausingAura(AuraType auraType)
Definition: Unit.cpp:648
uint32 GetBankRights(uint32 rankId, uint8 TabId) const
Definition: Guild.cpp:1195
void DisplayGuildBankLogs(WorldSession *session, uint8 TabId)
Definition: Guild.cpp:1610
#define sLog
Log class singleton.
Definition: Log.h:187
void HandleGuildBankWithdraw(WorldPacket &recv_data)
void HandleGuildInviteOpcode(WorldPacket &recvPacket)
void SetEmblem(uint32 m_EmblemStyle, uint32 m_EmblemColor, uint32 m_BorderStyle, uint32 m_BorderColor, uint32 m_BackgroundColor)
Definition: Guild.cpp:819
uint64 GetGuildBankMoney()
Definition: Guild.h:462
std::string const & GetName() const
Definition: Guild.h:286
void SetLeader(uint64 guid)
Definition: Guild.cpp:476
void HandleGuildBankTabColon(WorldPacket &recv_data)
bool RollbackTransaction()
Definition: Database.cpp:571
uint32 GetAccountId() const
Definition: WorldSession.h:100
void HandleGuildDelRankOpcode(WorldPacket &recvPacket)
void HandleGuildDisbandOpcode(WorldPacket &recvPacket)
void SetCount(uint32 value)
Definition: Item.h:255
Player * GetPlayer() const
Definition: WorldSession.h:104
uint32 GetGUIDLow() const
Definition: Object.h:160
void HandleGuildBankGetMoneyAmount(WorldPacket &recv_data)
#define sObjectMgr
Definition: ObjectMgr.h:1285
void SendPacket(WorldPacket const *packet)
bool CommitTransaction()
Definition: Database.cpp:551
#define GUILD_MAX_RANKS
void DisplayGuildBankContent(WorldSession *session, uint8 TabId)
Definition: Guild.cpp:979
void Disband()
Definition: Guild.cpp:716
void SetGuildBankTabText(uint8 TabId, std::string text)
Definition: Guild.cpp:1958
static bool IsInventoryPos(uint16 pos)
Definition: Player.h:1109
void HandleGuildSetPublicNoteOpcode(WorldPacket &recvPacket)
uint32 GetCreatedYear() const
Definition: Guild.h:299
void HandleGuildBankQuery(WorldPacket &recv_data)
std::vector< GuildItemPosCount > GuildItemPosCountVec
Definition: Guild.h:228
void SetRankRights(uint32 rankId, uint32 rights)
Definition: Guild.cpp:697
void HandleGuildDemoteOpcode(WorldPacket &recvPacket)
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:225
void SetGuildIdInvited(uint32 GuildId)
Definition: Player.h:1833
void HandleGuildRemoveOpcode(WorldPacket &recvPacket)
void SaveGoldToDB()
Definition: Player.cpp:16423
ACE_UINT8 uint8
Definition: Define.h:73
MemberSlot * GetMemberSlot(const std::string &name, uint64 &guid)
Definition: Guild.h:397
PlayerSocial * GetSocial()
Definition: Player.h:985
Definition: Unit.h:297
uint8 CanStoreItem(uint8 bag, uint8 slot, ItemPosCountVec &dest, Item *pItem, bool swap=false) const
Definition: Player.h:1151
void HandleGuildEventLogOpcode(WorldPacket &recvPacket)
uint32 GetMemberMoneyWithdrawRem(uint32 LowGuid)
Definition: Guild.cpp:1410
void HandleGuildRankOpcode(WorldPacket &recvPacket)
void SetRankName(uint32 rankId, std::string name)
Definition: Guild.cpp:685
void ItemRemovedQuestCheck(uint32 entry, uint32 count)
Definition: Player.cpp:13812
bool empty() const
Definition: ByteBuffer.h:340
void HandleGuildAddRankOpcode(WorldPacket &recvPacket)
int GetGuildIdInvited()
Definition: Player.h:1847
void HandleGuildInfoOpcode(WorldPacket &recvPacket)
Definition: Item.h:196
const uint64 & GetLeader() const
Definition: Guild.h:282
void BroadcastPacket(WorldPacket *packet)
Definition: Guild.cpp:611
void HandleGuildQueryOpcode(WorldPacket &recvPacket)
uint32 GetRank()
Definition: Player.h:1842
void SendEquipError(uint8 msg, Item *pItem, Item *pItem2)
Definition: Player.cpp:11571
uint32 GetRankRights(uint32 rankId)
Definition: Guild.cpp:677
void CreateNewBankTab()
Definition: Guild.cpp:1142
void HandleGuildLeaveOpcode(WorldPacket &recvPacket)
bool MemberMoneyWithdraw(uint32 amount, uint32 LowGuid)
Definition: Guild.cpp:1323
void SetPNOTE(uint64 guid, std::string pnote)
Definition: Guild.cpp:553
uint32 GetMemberSize() const
Definition: Guild.h:348
#define WITHDRAW_SLOT_UNLIMITED
Definition: Guild.h:22
void HandleGuildRosterOpcode(WorldPacket &recvPacket)
void SetMOTD(std::string motd)
Definition: Guild.cpp:175
void SendSaveGuildEmblem(uint32 msg)
void DelRank()
Definition: Guild.cpp:656
uint32 GetGuildId()
Definition: Player.h:1837
void HandleGuildBankModifyTab(WorldPacket &recv_data)
void SetOFFNOTE(uint64 guid, std::string offnote)
Definition: Guild.cpp:566
uint8 GetPurchasedTabs() const
Definition: Guild.h:439
const char * GetName() const
Definition: Object.h:692
void HandleGuildSaveEmblemOpcode(WorldPacket &recvPacket)
std::vector< ItemPosCount > ItemPosCountVec
Definition: Player.h:605
ACE_UINT64 uint64
Definition: Define.h:70
GameObject * GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const
Definition: Player.cpp:2234
void Roster(WorldSession *session=NULL)
Definition: Guild.cpp:738
uint32 GetNrRanks() const
Definition: Guild.h:380
Player * _player
Definition: WorldSession.h:729
bool IsMemberHaveRights(uint32 LowGuid, uint8 TabId, uint32 rights) const
Definition: Guild.cpp:1375
uint32 GetCreatedDay() const
Definition: Guild.h:307
std::string GetRankName(uint32 rankId)
Definition: Guild.cpp:669
void HandleGuildChangeInfoOpcode(WorldPacket &recvPacket)
void DisplayGuildBankMoneyUpdate()
Definition: Guild.cpp:1006
void SetGINFO(std::string ginfo)
Definition: Guild.cpp:184
void SendGuildBankTabText(WorldSession *session, uint8 TabId)
Definition: Guild.cpp:1981
uint8 CanStoreItem(uint8 tab, uint8 slot, GuildItemPosCountVec &dest, uint32 count, Item *pItem, bool swap=false) const
Definition: Guild.cpp:1913
uint32 GetAccountsNumber() const
Definition: Guild.h:352
uint32 GetMemberSlotWithdrawRem(uint32 LowGuid, uint8 TabId)
Definition: Guild.cpp:1387
bool AddMember(uint64 plGuid, uint32 plRank)
Definition: Guild.cpp:121
uint32 GetTeam() const
Definition: Player.h:2075
Item * StoreItem(uint8 tab, GuildItemPosCountVec const &pos, Item *pItem)
Definition: Guild.cpp:1733
bool HasRankRight(uint32 rankId, uint32 right)
Definition: Guild.h:387
Creature * GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
Definition: Player.cpp:2191
uint32 GetCreatedMonth() const
Definition: Guild.h:303
void SaveDataFieldToDB()
Definition: Player.cpp:16863
Item * GetItem(uint8 TabId, uint8 SlotId)
Definition: Guild.cpp:1106
void SaveInventoryAndGoldToDB()
Definition: Player.cpp:16417
void MoveItemToInventory(ItemPosCountVec const &dest, Item *pItem, bool update, bool in_characterInventoryDB=false)
Definition: Player.cpp:10703
void SetBankMoney(int64 money)
Definition: Guild.cpp:1344
bool CanBeTraded() const
Definition: Item.cpp:738
uint32 GetEntry() const
Definition: Object.h:186
WorldSession * GetSession() const
Definition: Player.h:1959
#define sWorld
Definition: World.h:860
void DisplayGuildEventlog(WorldSession *session)
Definition: Guild.cpp:865
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
void uint32 GetSecurity() const
Definition: WorldSession.h:96
ACE_UINT16 uint16
Definition: Define.h:72
Player * FindPlayerByName(const char *name, bool force=false)
void DisplayGuildBankTabsInfo(WorldSession *session)
Definition: Guild.cpp:1116
void ModifyMoney(int32 d)
Definition: Player.h:1528
const GuildBankTab * GetBankTab(uint8 index)
Definition: Guild.h:444
ACE_UINT32 uint32
Definition: Define.h:71
void Query(WorldSession *session)
Definition: Guild.cpp:794
Definition: Guild.h:265
Item * GetItemByPos(uint16 pos) const
Definition: Player.cpp:8612
void HandleGuildDeclineOpcode(WorldPacket &recvPacket)
void DeleteFromInventoryDB()
Definition: Item.cpp:455
void HandleGuildSetOfficerNoteOpcode(WorldPacket &recvPacket)
Definition: Player.h:922
void HandleGuildBankGetRights(WorldPacket &recv_data)
Definition: Guild.h:107
bool Create(Player *leader, std::string gname)
Definition: Guild.cpp:61
void HandleGuildMOTDOpcode(WorldPacket &recvPacket)
void RemoveItem(uint8 tab, uint8 slot)
Definition: Guild.cpp:1806
void DisplayGuildBankContentUpdate(uint8 TabId, int32 slot1, int32 slot2=-1)
Definition: Guild.cpp:1020
void ChangeRank(uint64 guid, uint32 newRank)
Definition: Guild.cpp:539
#define GUILD_BANK_MAX_TABS
void HandleGuildCreateOpcode(WorldPacket &recvPacket)
void HandleGuildBankDeposit(WorldPacket &recv_data)
bool MemberItemWithdraw(uint8 TabId, uint32 LowGuid)
Definition: Guild.cpp:1356
const uint64 & GetGUID() const
Definition: Object.h:156