mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
Core/Commands: Convert guild commands in commandscript
This commit is contained in:
@@ -112,16 +112,6 @@ ChatCommand* ChatHandler::getCommandTable()
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand guildCommandTable[] =
|
||||
{
|
||||
{ "create", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleGuildCreateCommand>, "", NULL },
|
||||
{ "delete", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleGuildDeleteCommand>, "", NULL },
|
||||
{ "invite", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleGuildInviteCommand>, "", NULL },
|
||||
{ "uninvite", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleGuildUninviteCommand>, "", NULL },
|
||||
{ "rank", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleGuildRankCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand lookupPlayerCommandTable[] =
|
||||
{
|
||||
{ "ip", SEC_GAMEMASTER, true, OldHandler<&ChatHandler::HandleLookupPlayerIpCommand>, "", NULL },
|
||||
@@ -215,7 +205,6 @@ ChatCommand* ChatHandler::getCommandTable()
|
||||
{
|
||||
{ "lookup", SEC_ADMINISTRATOR, true, NULL, "", lookupCommandTable },
|
||||
{ "pdump", SEC_ADMINISTRATOR, true, NULL, "", pdumpCommandTable },
|
||||
{ "guild", SEC_ADMINISTRATOR, true, NULL, "", guildCommandTable },
|
||||
{ "group", SEC_ADMINISTRATOR, false, NULL, "", groupCommandTable },
|
||||
|
||||
{ "channel", SEC_ADMINISTRATOR, true, NULL, "", channelCommandTable },
|
||||
|
||||
@@ -157,12 +157,6 @@ class ChatHandler
|
||||
bool HandleBindSightCommand(const char* args);
|
||||
bool HandleUnbindSightCommand(const char* args);
|
||||
|
||||
bool HandleGuildCreateCommand(const char* args);
|
||||
bool HandleGuildInviteCommand(const char* args);
|
||||
bool HandleGuildUninviteCommand(const char* args);
|
||||
bool HandleGuildRankCommand(const char* args);
|
||||
bool HandleGuildDeleteCommand(const char* args);
|
||||
|
||||
bool HandleLookupAreaCommand(const char* args);
|
||||
bool HandleLookupCreatureCommand(const char* args);
|
||||
bool HandleLookupEventCommand(const char* args);
|
||||
|
||||
@@ -1300,145 +1300,6 @@ bool ChatHandler::HandleLookupMapCommand(const char *args)
|
||||
return true;
|
||||
}
|
||||
|
||||
/** \brief GM command level 3 - Create a guild.
|
||||
*
|
||||
* This command allows a GM (level 3) to create a guild.
|
||||
*
|
||||
* The "args" parameter contains the name of the guild leader
|
||||
* and then the name of the guild.
|
||||
*
|
||||
*/
|
||||
bool ChatHandler::HandleGuildCreateCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
// if not guild name only (in "") then player name
|
||||
Player* target;
|
||||
if (!extractPlayerTarget(*args != '"' ? (char*)args : NULL, &target))
|
||||
return false;
|
||||
|
||||
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
|
||||
if (!tailStr)
|
||||
return false;
|
||||
|
||||
char* guildStr = extractQuotedArg(tailStr);
|
||||
if (!guildStr)
|
||||
return false;
|
||||
|
||||
std::string guildname = guildStr;
|
||||
|
||||
if (target->GetGuildId())
|
||||
{
|
||||
SendSysMessage(LANG_PLAYER_IN_GUILD);
|
||||
return true;
|
||||
}
|
||||
|
||||
Guild* guild = new Guild;
|
||||
if (!guild->Create(target, guildname))
|
||||
{
|
||||
delete guild;
|
||||
SendSysMessage(LANG_GUILD_NOT_CREATED);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
sGuildMgr->AddGuild(guild);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleGuildInviteCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
// if not guild name only (in "") then player name
|
||||
uint64 target_guid;
|
||||
if (!extractPlayerTarget(*args != '"' ? (char*)args : NULL, NULL, &target_guid))
|
||||
return false;
|
||||
|
||||
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
|
||||
if (!tailStr)
|
||||
return false;
|
||||
|
||||
char* guildStr = extractQuotedArg(tailStr);
|
||||
if (!guildStr)
|
||||
return false;
|
||||
|
||||
std::string glName = guildStr;
|
||||
Guild* targetGuild = sGuildMgr->GetGuildByName(glName);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
// player's guild membership checked in AddMember before add
|
||||
return targetGuild->AddMember(target_guid);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleGuildUninviteCommand(const char *args)
|
||||
{
|
||||
Player* target;
|
||||
uint64 target_guid;
|
||||
if (!extractPlayerTarget((char*)args, &target, &target_guid))
|
||||
return false;
|
||||
|
||||
uint32 glId = target ? target->GetGuildId() : Player::GetGuildIdFromDB(target_guid);
|
||||
if (!glId)
|
||||
return false;
|
||||
|
||||
Guild* targetGuild = sGuildMgr->GetGuildById(glId);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
targetGuild->DeleteMember(target_guid, false, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleGuildRankCommand(const char *args)
|
||||
{
|
||||
char* nameStr;
|
||||
char* rankStr;
|
||||
extractOptFirstArg((char*)args, &nameStr, &rankStr);
|
||||
if (!rankStr)
|
||||
return false;
|
||||
|
||||
Player* target;
|
||||
uint64 target_guid;
|
||||
std::string target_name;
|
||||
if (!extractPlayerTarget(nameStr, &target, &target_guid, &target_name))
|
||||
return false;
|
||||
|
||||
uint32 glId = target ? target->GetGuildId() : Player::GetGuildIdFromDB(target_guid);
|
||||
if (!glId)
|
||||
return false;
|
||||
|
||||
Guild* targetGuild = sGuildMgr->GetGuildById (glId);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
uint32 newrank = uint32 (atoi (rankStr));
|
||||
return targetGuild->ChangeMemberRank(target_guid, newrank);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleGuildDeleteCommand(const char *args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* guildStr = extractQuotedArg((char*)args);
|
||||
if (!guildStr)
|
||||
return false;
|
||||
|
||||
std::string gld = guildStr;
|
||||
|
||||
Guild* targetGuild = sGuildMgr->GetGuildByName(gld);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
targetGuild->Disband();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleGetDistanceCommand(const char *args)
|
||||
{
|
||||
WorldObject* obj = NULL;
|
||||
|
||||
@@ -52,6 +52,7 @@ void AddSC_event_commandscript();
|
||||
void AddSC_gm_commandscript();
|
||||
void AddSC_go_commandscript();
|
||||
void AddSC_gobject_commandscript();
|
||||
void AddSC_guild_commandscript();
|
||||
void AddSC_honor_commandscript();
|
||||
void AddSC_instance_commandscript();
|
||||
void AddSC_learn_commandscript();
|
||||
@@ -660,6 +661,7 @@ void AddCommandScripts()
|
||||
AddSC_gm_commandscript();
|
||||
AddSC_go_commandscript();
|
||||
AddSC_gobject_commandscript();
|
||||
AddSC_guild_commandscript();
|
||||
AddSC_honor_commandscript();
|
||||
AddSC_instance_commandscript();
|
||||
AddSC_learn_commandscript();
|
||||
|
||||
@@ -19,6 +19,7 @@ set(scripts_STAT_SRCS
|
||||
Commands/cs_gm.cpp
|
||||
Commands/cs_go.cpp
|
||||
Commands/cs_gobject.cpp
|
||||
Commands/cs_guild.cpp
|
||||
Commands/cs_honor.cpp
|
||||
Commands/cs_instance.cpp
|
||||
Commands/cs_learn.cpp
|
||||
@@ -35,7 +36,6 @@ set(scripts_STAT_SRCS
|
||||
Commands/cs_wp.cpp
|
||||
# Commands/cs_lookup.cpp
|
||||
# Commands/cs_pdump.cpp
|
||||
# Commands/cs_guild.cpp
|
||||
# Commands/cs_channel.cpp
|
||||
# Commands/cs_pet.cpp
|
||||
# Commands/cs_ticket.cpp
|
||||
|
||||
199
src/server/scripts/Commands/cs_guild.cpp
Normal file
199
src/server/scripts/Commands/cs_guild.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
Name: guild_commandscript
|
||||
%Complete: 100
|
||||
Comment: All guild related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "ScriptMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "Guild.h"
|
||||
#include "GuildMgr.h"
|
||||
#include "ObjectAccessor.h"
|
||||
|
||||
class guild_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
guild_commandscript() : CommandScript("guild_commandscript") { }
|
||||
|
||||
ChatCommand* GetCommands() const
|
||||
{
|
||||
static ChatCommand guildCommandTable[] =
|
||||
{
|
||||
{ "create", SEC_GAMEMASTER, true, &HandleGuildCreateCommand, "", NULL },
|
||||
{ "delete", SEC_GAMEMASTER, true, &HandleGuildDeleteCommand, "", NULL },
|
||||
{ "invite", SEC_GAMEMASTER, true, &HandleGuildInviteCommand, "", NULL },
|
||||
{ "uninvite", SEC_GAMEMASTER, true, &HandleGuildUninviteCommand, "", NULL },
|
||||
{ "rank", SEC_GAMEMASTER, true, &HandleGuildRankCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "guild", SEC_ADMINISTRATOR, true, NULL, "", guildCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
/** \brief GM command level 3 - Create a guild.
|
||||
*
|
||||
* This command allows a GM (level 3) to create a guild.
|
||||
*
|
||||
* The "args" parameter contains the name of the guild leader
|
||||
* and then the name of the guild.
|
||||
*
|
||||
*/
|
||||
static bool HandleGuildCreateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
// if not guild name only (in "") then player name
|
||||
Player* target;
|
||||
if (!handler->extractPlayerTarget(*args != '"' ? (char*)args : NULL, &target))
|
||||
return false;
|
||||
|
||||
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
|
||||
if (!tailStr)
|
||||
return false;
|
||||
|
||||
char* guildStr = handler->extractQuotedArg(tailStr);
|
||||
if (!guildStr)
|
||||
return false;
|
||||
|
||||
std::string guildName = guildStr;
|
||||
|
||||
if (target->GetGuildId())
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_IN_GUILD);
|
||||
return true;
|
||||
}
|
||||
|
||||
Guild* guild = new Guild;
|
||||
if (!guild->Create(target, guildName))
|
||||
{
|
||||
delete guild;
|
||||
handler->SendSysMessage(LANG_GUILD_NOT_CREATED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
sGuildMgr->AddGuild(guild);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGuildDeleteCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* guildStr = handler->extractQuotedArg((char*)args);
|
||||
if (!guildStr)
|
||||
return false;
|
||||
|
||||
std::string guildName = guildStr;
|
||||
|
||||
Guild* targetGuild = sGuildMgr->GetGuildByName(guildName);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
targetGuild->Disband();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGuildInviteCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
// if not guild name only (in "") then player name
|
||||
uint64 targetGuid;
|
||||
if (!handler->extractPlayerTarget(*args != '"' ? (char*)args : NULL, NULL, &targetGuid))
|
||||
return false;
|
||||
|
||||
char* tailStr = *args != '"' ? strtok(NULL, "") : (char*)args;
|
||||
if (!tailStr)
|
||||
return false;
|
||||
|
||||
char* guildStr = handler->extractQuotedArg(tailStr);
|
||||
if (!guildStr)
|
||||
return false;
|
||||
|
||||
std::string guildName = guildStr;
|
||||
Guild* targetGuild = sGuildMgr->GetGuildByName(guildName);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
// player's guild membership checked in AddMember before add
|
||||
return targetGuild->AddMember(targetGuid);
|
||||
}
|
||||
|
||||
static bool HandleGuildUninviteCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Player* target;
|
||||
uint64 targetGuid;
|
||||
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
|
||||
return false;
|
||||
|
||||
uint32 guildId = target ? target->GetGuildId() : Player::GetGuildIdFromDB(targetGuid);
|
||||
if (!guildId)
|
||||
return false;
|
||||
|
||||
Guild* targetGuild = sGuildMgr->GetGuildById(guildId);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
targetGuild->DeleteMember(targetGuid, false, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGuildRankCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
char* nameStr;
|
||||
char* rankStr;
|
||||
handler->extractOptFirstArg((char*)args, &nameStr, &rankStr);
|
||||
if (!rankStr)
|
||||
return false;
|
||||
|
||||
Player* target;
|
||||
uint64 targetGuid;
|
||||
std::string target_name;
|
||||
if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid, &target_name))
|
||||
return false;
|
||||
|
||||
uint32 guildId = target ? target->GetGuildId() : Player::GetGuildIdFromDB(targetGuid);
|
||||
if (!guildId)
|
||||
return false;
|
||||
|
||||
Guild* targetGuild = sGuildMgr->GetGuildById(guildId);
|
||||
if (!targetGuild)
|
||||
return false;
|
||||
|
||||
uint8 newRank = uint8(atoi(rankStr));
|
||||
return targetGuild->ChangeMemberRank(targetGuid, newRank);
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_guild_commandscript()
|
||||
{
|
||||
new guild_commandscript();
|
||||
}
|
||||
Reference in New Issue
Block a user