Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3502a9a7b9ba1924f4f3 to your computer and use it in GitHub Desktop.
Save anonymous/3502a9a7b9ba1924f4f3 to your computer and use it in GitHub Desktop.
#include "Chat.h"
#include "Common.h"
#define FACTION_SPECIFIC 0
std::string GetNameLink(Player* player)
{
std::string name = player->GetName();
std::string color;
switch(player->getClass())
{
case CLASS_DEATH_KNIGHT:
color = "|cffC41F3B";
break;
case CLASS_DRUID:
color = "|cffFF7D0A";
break;
case CLASS_HUNTER:
color = "|cffABD473";
break;
case CLASS_MAGE:
color = "|cff69CCF0";
break;
case CLASS_PALADIN:
color = "|cffF58CBA";
break;
case CLASS_PRIEST:
color = "|cffFFFFFF";
break;
case CLASS_ROGUE:
color = "|cffFFF569";
break;
case CLASS_SHAMAN:
color = "|cff0070DE";
break;
case CLASS_WARLOCK:
color = "|cff9482C9";
break;
case CLASS_WARRIOR:
color = "|cffC79C6E";
break;
}
return "|Hplayer:"+name+"|h|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
}
class world_chat : public CommandScript
{
public:
world_chat() : CommandScript("world_chat"){}
std::vector<ChatCommand> GetCommands() const override
{
static std::vector<ChatCommand> WorldChatCommandTable =
{
{"c", rbac::RBAC_PERM_COMMAND_WORLD_CHAT, true, &HandleWorldChatCommand, "" },
};
return WorldChatCommandTable;
}
static bool HandleWorldChatCommand(ChatHandler * handler, const char * args)
{
if (!handler->GetSession()->GetPlayer()->CanSpeak())
return false;
std::string temp = args;
if (!args || temp.find_first_not_of(' ') == std::string::npos)
return false;
std::string msg = "";
Player * player = handler->GetSession()->GetPlayer();
switch(player->GetSession()->GetSecurity())
{
// Player
case SEC_PLAYER:
if (player->GetTeam() == ALLIANCE)
{
msg += "|cff0000ff[Alliance] ";
msg += GetNameLink(player);
msg += " |cfffaeb00";
}
else
{
msg += "|cffff0000[Horde] ";
msg += GetNameLink(player);
msg += " |cfffaeb00";
}
break;
// VIP
case SEC_MODERATOR:
msg += "|cffff8a00[VIP] ";
msg += GetNameLink(player);
msg += " |cfffaeb00";
break;
// GM
case SEC_GAMEMASTER:
msg += "|cfffa9900[GM] ";
msg += GetNameLink(player);
msg += " |cfffaeb00";
break;
case SEC_ADMINISTRATOR:
msg += "|cffff8a00[Owner] ";
msg += GetNameLink(player);
msg += " |cfffaeb00";
break;
}
msg += args;
if (FACTION_SPECIFIC)
{
SessionMap sessions = sWorld->GetAllSessions();
for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
if (Player* plr = itr->second->GetPlayer())
if (plr->GetTeam() == player->GetTeam())
sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), plr);
}
else
sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), 0);
return true;
}
};
void AddSC_world_chat()
{
new world_chat();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment