mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
feat(Guild/Commands): guild rename (#10323)
* feat(Guild/Commands): guild rename
* cherry-pick commit (678cade116#)
* Update cs_guild.cpp
This commit is contained in:
@@ -155,6 +155,8 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
// 0: uint32, 1: string, 2: uint32, 3: string, 4: string, 5: uint64, 6-10: uint32, 11: uint64
|
||||
PrepareStatement(CHAR_INS_GUILD, "INSERT INTO guild (guildid, name, leaderguid, info, motd, createdate, EmblemStyle, EmblemColor, BorderStyle, BorderColor, BackgroundColor, BankMoney) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_GUILD, "DELETE FROM guild WHERE guildid = ?", CONNECTION_ASYNC); // 0: uint32
|
||||
// 0: string, 1: uint32
|
||||
PrepareStatement(CHAR_UPD_GUILD_NAME, "UPDATE guild SET name = ? WHERE guildid = ?", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: uint8, 4: string, 5: string
|
||||
PrepareStatement(CHAR_INS_GUILD_MEMBER, "INSERT INTO guild_member (guildid, guid, `rank`, pnote, offnote) VALUES (?, ?, ?, ?, ?)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_GUILD_MEMBER, "DELETE FROM guild_member WHERE guid = ?", CONNECTION_ASYNC); // 0: uint32
|
||||
|
||||
@@ -137,6 +137,7 @@ enum CharacterDatabaseStatements : uint32
|
||||
|
||||
CHAR_INS_GUILD,
|
||||
CHAR_DEL_GUILD,
|
||||
CHAR_UPD_GUILD_NAME,
|
||||
CHAR_INS_GUILD_MEMBER,
|
||||
CHAR_DEL_GUILD_MEMBER,
|
||||
CHAR_DEL_GUILD_MEMBERS,
|
||||
|
||||
@@ -1182,6 +1182,21 @@ void Guild::OnPlayerStatusChange(Player* player, uint32 flag, bool state)
|
||||
}
|
||||
}
|
||||
|
||||
bool Guild::SetName(std::string_view const& name)
|
||||
{
|
||||
if (m_name == name || name.empty() || name.length() > 24 || sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_name = name;
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GUILD_NAME);
|
||||
stmt->setString(0, m_name);
|
||||
stmt->setUInt32(1, GetId());
|
||||
CharacterDatabase.Execute(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Guild::HandleRoster(WorldSession* session)
|
||||
{
|
||||
WorldPackets::Guild::GuildRoster roster;
|
||||
|
||||
@@ -685,6 +685,8 @@ public:
|
||||
std::string const& GetMOTD() const { return m_motd; }
|
||||
std::string const& GetInfo() const { return m_info; }
|
||||
|
||||
bool SetName(std::string_view const& name);
|
||||
|
||||
// Handle client commands
|
||||
void HandleRoster(WorldSession* session);
|
||||
void HandleQuery(WorldSession* session);
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
{ "invite", SEC_GAMEMASTER, true, &HandleGuildInviteCommand, "" },
|
||||
{ "uninvite", SEC_GAMEMASTER, true, &HandleGuildUninviteCommand, "" },
|
||||
{ "rank", SEC_GAMEMASTER, true, &HandleGuildRankCommand, "" },
|
||||
{ "rename", SEC_GAMEMASTER, true, &HandleGuildRenameCommand, "" },
|
||||
{ "info", SEC_GAMEMASTER, true, &HandleGuildInfoCommand, "" }
|
||||
};
|
||||
static ChatCommandTable commandTable =
|
||||
@@ -206,6 +207,55 @@ public:
|
||||
return targetGuild->ChangeMemberRank(player->GetGUID(), rank);
|
||||
}
|
||||
|
||||
static bool HandleGuildRenameCommand(ChatHandler* handler, char const* _args)
|
||||
{
|
||||
if (!*_args)
|
||||
return false;
|
||||
|
||||
char *args = (char *)_args;
|
||||
|
||||
char const* oldGuildStr = handler->extractQuotedArg(args);
|
||||
if (!oldGuildStr)
|
||||
{
|
||||
handler->SendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char const* newGuildStr = handler->extractQuotedArg(strtok(nullptr, ""));
|
||||
if (!newGuildStr)
|
||||
{
|
||||
handler->SendSysMessage(LANG_INSERT_GUILD_NAME);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Guild* guild = sGuildMgr->GetGuildByName(oldGuildStr);
|
||||
if (!guild)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_COULDNOTFIND, oldGuildStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sGuildMgr->GetGuildByName(newGuildStr))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_GUILD_RENAME_ALREADY_EXISTS, newGuildStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!guild->SetName(newGuildStr))
|
||||
{
|
||||
handler->SendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage(LANG_GUILD_RENAME_DONE, oldGuildStr, newGuildStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGuildInfoCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Guild* guild = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user