AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
guild_commandscript Class Reference
Inheritance diagram for guild_commandscript:
CommandScript ScriptObject

Public Member Functions

 guild_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleGuildCreateCommand (ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString guildName)
 
static bool HandleGuildDeleteCommand (ChatHandler *, QuotedString guildName)
 
static bool HandleGuildInviteCommand (ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString guildName)
 
static bool HandleGuildUninviteCommand (ChatHandler *handler, Optional< PlayerIdentifier > target)
 
static bool HandleGuildRankCommand (ChatHandler *handler, Optional< PlayerIdentifier > player, uint8 rank)
 
static bool HandleGuildRenameCommand (ChatHandler *handler, QuotedString oldGuildStr, QuotedString newGuildStr)
 
static bool HandleGuildInfoCommand (ChatHandler *handler, Optional< Variant< ObjectGuid::LowType, QuotedString > > const &guildIdentifier)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ guild_commandscript()

guild_commandscript::guild_commandscript ( )
inline
35: CommandScript("guild_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable guild_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

38 {
39 static ChatCommandTable guildCommandTable =
40 {
41 { "create", HandleGuildCreateCommand, SEC_GAMEMASTER, Console::Yes },
42 { "delete", HandleGuildDeleteCommand, SEC_GAMEMASTER, Console::Yes },
43 { "invite", HandleGuildInviteCommand, SEC_GAMEMASTER, Console::Yes },
44 { "uninvite", HandleGuildUninviteCommand, SEC_GAMEMASTER, Console::Yes },
45 { "rank", HandleGuildRankCommand, SEC_GAMEMASTER, Console::Yes },
46 { "rename", HandleGuildRenameCommand, SEC_GAMEMASTER, Console::Yes },
47 { "info", HandleGuildInfoCommand, SEC_GAMEMASTER, Console::Yes }
48 };
49 static ChatCommandTable commandTable =
50 {
51 { "guild", guildCommandTable }
52 };
53 return commandTable;
54 }
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleGuildCreateCommand(ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString guildName)
Definition: cs_guild.cpp:56
static bool HandleGuildDeleteCommand(ChatHandler *, QuotedString guildName)
Definition: cs_guild.cpp:107
static bool HandleGuildInviteCommand(ChatHandler *handler, Optional< PlayerIdentifier > target, QuotedString guildName)
Definition: cs_guild.cpp:124
static bool HandleGuildUninviteCommand(ChatHandler *handler, Optional< PlayerIdentifier > target)
Definition: cs_guild.cpp:149
static bool HandleGuildRenameCommand(ChatHandler *handler, QuotedString oldGuildStr, QuotedString newGuildStr)
Definition: cs_guild.cpp:194
static bool HandleGuildInfoCommand(ChatHandler *handler, Optional< Variant< ObjectGuid::LowType, QuotedString > > const &guildIdentifier)
Definition: cs_guild.cpp:224
static bool HandleGuildRankCommand(ChatHandler *handler, Optional< PlayerIdentifier > player, uint8 rank)
Definition: cs_guild.cpp:175

References HandleGuildCreateCommand(), HandleGuildDeleteCommand(), HandleGuildInfoCommand(), HandleGuildInviteCommand(), HandleGuildRankCommand(), HandleGuildRenameCommand(), HandleGuildUninviteCommand(), and SEC_GAMEMASTER.

◆ HandleGuildCreateCommand()

static bool guild_commandscript::HandleGuildCreateCommand ( ChatHandler handler,
Optional< PlayerIdentifier target,
QuotedString  guildName 
)
inlinestatic
57 {
58 if (!target)
59 {
60 target = PlayerIdentifier::FromTargetOrSelf(handler);
61 }
62
63 if (!target || !target->IsConnected())
64 {
66 return false;
67 }
68
69 if (guildName.empty())
70 {
71 return false;
72 }
73
74 Player* playerTarget = target->GetConnectedPlayer();
75
76 if (playerTarget->GetGuildId())
77 {
79 return false;
80 }
81
82 if (sGuildMgr->GetGuildByName(guildName))
83 {
85 return false;
86 }
87
88 if (!sObjectMgr->IsValidCharterName(guildName))
89 {
91 return false;
92 }
93
94 Guild* guild = new Guild;
95 if (!guild->Create(playerTarget, guildName))
96 {
97 delete guild;
99 return false;
100 }
101
102 sGuildMgr->AddGuild(guild);
103
104 return true;
105 }
#define sObjectMgr
Definition: ObjectMgr.h:1635
#define sGuildMgr
Definition: GuildMgr.h:51
@ LANG_GUILD_NOT_CREATED
Definition: Language.h:541
@ LANG_PLAYER_IN_GUILD
Definition: Language.h:540
@ LANG_PLAYER_NOT_FOUND
Definition: Language.h:539
@ LANG_GUILD_RENAME_ALREADY_EXISTS
Definition: Language.h:126
@ LANG_BAD_VALUE
Definition: Language.h:147
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
Definition: ChatCommandTags.h:184
Definition: Player.h:1081
uint32 GetGuildId() const
Definition: Player.h:1901
Definition: Guild.h:292
bool Create(Player *pLeader, std::string_view name)
Definition: Guild.cpp:1049

References Guild::Create(), Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), Player::GetGuildId(), LANG_BAD_VALUE, LANG_GUILD_NOT_CREATED, LANG_GUILD_RENAME_ALREADY_EXISTS, LANG_PLAYER_IN_GUILD, LANG_PLAYER_NOT_FOUND, ChatHandler::SendErrorMessage(), sGuildMgr, and sObjectMgr.

Referenced by GetCommands().

◆ HandleGuildDeleteCommand()

static bool guild_commandscript::HandleGuildDeleteCommand ( ChatHandler ,
QuotedString  guildName 
)
inlinestatic
108 {
109 if (guildName.empty())
110 {
111 return false;
112 }
113
114 Guild* targetGuild = sGuildMgr->GetGuildByName(guildName);
115 if (!targetGuild)
116 return false;
117
118 targetGuild->Disband();
119 delete targetGuild;
120
121 return true;
122 }
void Disband()
Definition: Guild.cpp:1108

References Guild::Disband(), and sGuildMgr.

Referenced by GetCommands().

◆ HandleGuildInfoCommand()

static bool guild_commandscript::HandleGuildInfoCommand ( ChatHandler handler,
Optional< Variant< ObjectGuid::LowType, QuotedString > > const &  guildIdentifier 
)
inlinestatic
225 {
226 Guild* guild = nullptr;
227
228 if (guildIdentifier)
229 {
230 if (ObjectGuid::LowType const* guid = std::get_if<ObjectGuid::LowType>(&*guildIdentifier))
231 guild = sGuildMgr->GetGuildById(*guid);
232 else
233 guild = sGuildMgr->GetGuildByName(guildIdentifier->get<QuotedString>());
234 }
235 else if (Optional<PlayerIdentifier> target = PlayerIdentifier::FromTargetOrSelf(handler); target && target->IsConnected())
236 guild = target->GetConnectedPlayer()->GetGuild();
237
238 if (!guild)
239 return false;
240
241 // Display Guild Information
242 handler->PSendSysMessage(LANG_GUILD_INFO_NAME, guild->GetName(), guild->GetId()); // Guild Id + Name
243
244 std::string guildMasterName;
245 if (sCharacterCache->GetCharacterNameByGuid(guild->GetLeaderGUID(), guildMasterName))
246 handler->PSendSysMessage(LANG_GUILD_INFO_GUILD_MASTER, guildMasterName, guild->GetLeaderGUID().ToString()); // Guild Master
247
248 // Format creation date
249 char createdDateStr[20];
250 time_t createdDate = guild->GetCreatedDate();
251 tm localTm;
252 strftime(createdDateStr, 20, "%Y-%m-%d %H:%M:%S", localtime_r(&createdDate, &localTm));
253
254 handler->PSendSysMessage(LANG_GUILD_INFO_CREATION_DATE, createdDateStr); // Creation Date
255 handler->PSendSysMessage(LANG_GUILD_INFO_MEMBER_COUNT, guild->GetMemberCount()); // Number of Members
256 handler->PSendSysMessage(LANG_GUILD_INFO_BANK_GOLD, guild->GetTotalBankMoney() / 100 / 100); // Bank Gold (in gold coins)
257 handler->PSendSysMessage(LANG_GUILD_INFO_MOTD, guild->GetMOTD()); // Message of the Day
258 handler->PSendSysMessage(LANG_GUILD_INFO_EXTRA_INFO, guild->GetInfo()); // Extra Information
259 return true;
260 }
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
struct tm * localtime_r(time_t const *time, struct tm *result)
Definition: Timer.cpp:226
@ LANG_GUILD_INFO_GUILD_MASTER
Definition: Language.h:967
@ LANG_GUILD_INFO_BANK_GOLD
Definition: Language.h:970
@ LANG_GUILD_INFO_EXTRA_INFO
Definition: Language.h:972
@ LANG_GUILD_INFO_MEMBER_COUNT
Definition: Language.h:969
@ LANG_GUILD_INFO_MOTD
Definition: Language.h:971
@ LANG_GUILD_INFO_NAME
Definition: Language.h:966
@ LANG_GUILD_INFO_CREATION_DATE
Definition: Language.h:968
#define sCharacterCache
Definition: CharacterCache.h:83
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
Definition: ChatCommandTags.h:140
std::string ToString() const
Definition: ObjectGuid.cpp:47
uint32 LowType
Definition: ObjectGuid.h:122
ObjectGuid GetLeaderGUID() const
Definition: Guild.h:687
uint32 GetMemberCount() const
Definition: Guild.h:771
uint32 GetId() const
Definition: Guild.h:686
std::string const & GetName() const
Definition: Guild.h:688
time_t GetCreatedDate() const
Definition: Guild.h:772
std::string const & GetInfo() const
Definition: Guild.h:690
std::string const & GetMOTD() const
Definition: Guild.h:689
uint64 GetTotalBankMoney() const
Definition: Guild.h:770

References Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), Guild::GetCreatedDate(), Guild::GetId(), Guild::GetInfo(), Guild::GetLeaderGUID(), Guild::GetMemberCount(), Guild::GetMOTD(), Guild::GetName(), Guild::GetTotalBankMoney(), LANG_GUILD_INFO_BANK_GOLD, LANG_GUILD_INFO_CREATION_DATE, LANG_GUILD_INFO_EXTRA_INFO, LANG_GUILD_INFO_GUILD_MASTER, LANG_GUILD_INFO_MEMBER_COUNT, LANG_GUILD_INFO_MOTD, LANG_GUILD_INFO_NAME, localtime_r(), ChatHandler::PSendSysMessage(), sCharacterCache, sGuildMgr, and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleGuildInviteCommand()

static bool guild_commandscript::HandleGuildInviteCommand ( ChatHandler handler,
Optional< PlayerIdentifier target,
QuotedString  guildName 
)
inlinestatic
125 {
126 if (!target)
127 {
128 target = PlayerIdentifier::FromTargetOrSelf(handler);
129 }
130
131 if (!target)
132 {
133 return false;
134 }
135
136 if (guildName.empty())
137 {
138 return false;
139 }
140
141 Guild* targetGuild = sGuildMgr->GetGuildByName(guildName);
142 if (!targetGuild)
143 return false;
144
145 // player's guild membership checked in AddMember before add
146 return targetGuild->AddMember(target->GetGUID());
147 }
bool AddMember(ObjectGuid guid, uint8 rankId=GUILD_RANK_NONE)
Definition: Guild.cpp:2175

References Guild::AddMember(), Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), and sGuildMgr.

Referenced by GetCommands().

◆ HandleGuildRankCommand()

static bool guild_commandscript::HandleGuildRankCommand ( ChatHandler handler,
Optional< PlayerIdentifier player,
uint8  rank 
)
inlinestatic
176 {
177 if (!player)
178 player = PlayerIdentifier::FromTargetOrSelf(handler);
179
180 if (!player)
181 return false;
182
183 uint32 guildId = player->IsConnected() ? player->GetConnectedPlayer()->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(player->GetGUID());
184 if (!guildId)
185 return false;
186
187 Guild* targetGuild = sGuildMgr->GetGuildById(guildId);
188 if (!targetGuild)
189 return false;
190
191 return targetGuild->ChangeMemberRank(player->GetGUID(), rank);
192 }
std::uint32_t uint32
Definition: Define.h:107
bool ChangeMemberRank(ObjectGuid guid, uint8 newRank)
Definition: Guild.cpp:2320

References Guild::ChangeMemberRank(), Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), sCharacterCache, and sGuildMgr.

Referenced by GetCommands().

◆ HandleGuildRenameCommand()

static bool guild_commandscript::HandleGuildRenameCommand ( ChatHandler handler,
QuotedString  oldGuildStr,
QuotedString  newGuildStr 
)
inlinestatic
195 {
196 if (oldGuildStr.empty() || newGuildStr.empty())
197 {
198 return false;
199 }
200
201 Guild* guild = sGuildMgr->GetGuildByName(oldGuildStr);
202 if (!guild)
203 {
204 handler->SendErrorMessage(LANG_COMMAND_COULDNOTFIND, oldGuildStr);
205 return false;
206 }
207
208 if (sGuildMgr->GetGuildByName(newGuildStr))
209 {
211 return false;
212 }
213
214 if (!guild->SetName(newGuildStr))
215 {
217 return false;
218 }
219
220 handler->PSendSysMessage(LANG_GUILD_RENAME_DONE, oldGuildStr, newGuildStr);
221 return true;
222 }
@ LANG_GUILD_RENAME_DONE
Definition: Language.h:127
@ LANG_COMMAND_COULDNOTFIND
Definition: Language.h:466
bool SetName(std::string_view const &name)
Definition: Guild.cpp:1188

References LANG_BAD_VALUE, LANG_COMMAND_COULDNOTFIND, LANG_GUILD_RENAME_ALREADY_EXISTS, LANG_GUILD_RENAME_DONE, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), Guild::SetName(), and sGuildMgr.

Referenced by GetCommands().

◆ HandleGuildUninviteCommand()

static bool guild_commandscript::HandleGuildUninviteCommand ( ChatHandler handler,
Optional< PlayerIdentifier target 
)
inlinestatic
150 {
151 if (!target)
152 {
153 target = PlayerIdentifier::FromTargetOrSelf(handler);
154 }
155
156 if (!target)
157 {
158 return false;
159 }
160
161 Player* playerTarget = target->GetConnectedPlayer();
162
163 uint32 guildId = playerTarget ? playerTarget->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(target->GetGUID());
164 if (!guildId)
165 return false;
166
167 Guild* targetGuild = sGuildMgr->GetGuildById(guildId);
168 if (!targetGuild)
169 return false;
170
171 targetGuild->DeleteMember(target->GetGUID(), false, true, true);
172 return true;
173 }
void DeleteMember(ObjectGuid guid, bool isDisbanding=false, bool isKicked=false, bool canDeleteGuild=false)
Definition: Guild.cpp:2259

References Guild::DeleteMember(), Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), Player::GetGuildId(), sCharacterCache, and sGuildMgr.

Referenced by GetCommands().