Scripts/Commands: Implement .guild info command

Displays a information summary about the selected player guild or a given guildId or Name

Closes #12949

Signed-off-by: DDuarte <dnpd.dd@gmail.com>
This commit is contained in:
Odyssey authored and DDuarte committed 2014-08-28 23:04:52 +01:00
1 parent 37c150a74b
commit 8adde791d8
7 files changed
+96 -4

No files matched your search

+58
View File
@@ -44,6 +44,7 @@ public:
{ "uninvite", rbac::RBAC_PERM_COMMAND_GUILD_UNINVITE, true, &HandleGuildUninviteCommand, "", NULL },
{ "rank", rbac::RBAC_PERM_COMMAND_GUILD_RANK, true, &HandleGuildRankCommand, "", NULL },
{ "rename", rbac::RBAC_PERM_COMMAND_GUILD_RENAME, true, &HandleGuildRenameCommand, "", NULL },
{ "info", rbac::RBAC_PERM_COMMAND_GUILD_INFO, true, &HandleGuildInfoCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
@@ -243,6 +244,63 @@ public:
handler->PSendSysMessage(LANG_GUILD_RENAME_DONE, oldGuildStr, newGuildStr);
return true;
}
static bool HandleGuildInfoCommand(ChatHandler* handler, char const* args)
{
Player* target;
uint32 guildId;
std::string guildName;
std::string guildMasterName;
Guild* guild;
if (!*args)
{
// Look for the guild of the selected player or ourselves
if (target = handler->getSelectedPlayerOrSelf())
guild = target->GetGuild();
else
// getSelectedPlayerOrSelf will return null if there is no session
// so target becomes nullptr if the command is ran through console
// without specifying args.
return false;
}
else if (guildId = atoi(args)) // Try searching by Id
guild = sGuildMgr->GetGuildById(guildId);
else
{
// Try to extract a guild name
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
if (!tailStr)
return false;
char* guildStr = handler->extractQuotedArg((char*)args);
if (!guildStr)
return false;
guildName = guildStr;
guild = sGuildMgr->GetGuildByName(guildName);
}
if (!guild)
return false;
// Display Guild Information
handler->PSendSysMessage(LANG_GUILD_INFO_NAME, guild->GetName().c_str(), guild->GetId()); // Guild Id + Name
if (sObjectMgr->GetPlayerNameByGUID(guild->GetLeaderGUID(), guildMasterName))
handler->PSendSysMessage(LANG_GUILD_INFO_GUILD_MASTER, guildMasterName.c_str(), guild->GetLeaderGUID()); // Guild Master
// Format creation date
char createdDateStr[20];
time_t createdDate = guild->GetCreatedDate();
strftime(createdDateStr, 20, "%Y-%m-%d %H:%M:%S", localtime(&createdDate));
handler->PSendSysMessage(LANG_GUILD_INFO_CREATION_DATE, createdDateStr); // Creation Date
handler->PSendSysMessage(LANG_GUILD_INFO_MEMBER_COUNT, guild->GetMemberCount()); // Number of Members
handler->PSendSysMessage(LANG_GUILD_INFO_BANK_GOLD, guild->GetBankMoney() / 100 / 100); // Bank Gold (in gold coins)
handler->PSendSysMessage(LANG_GUILD_INFO_MOTD, guild->GetMOTD().c_str()); // Message of the Day
handler->PSendSysMessage(LANG_GUILD_INFO_EXTRA_INFO, guild->GetInfo().c_str()); // Extra Information
return true;
}
};
void AddSC_guild_commandscript()