Sdyess94
27-04-10, 02:04 AM
Here is a patch that I've made.
Firstly, make sure you have enabled Player Commands in the config file.
The .donorannounce command, is similar to the gamemaster announce command. Anyone that had permissions 'd' will see it. So most gamemasters and admins should see it, but player's won't. I should've added some color, but oh well.
Secondly, there is a server wide chat. It's fairly basic, and I plan to improve it when I get some time.
This includes 3 commands.
1. .chat - Can be used by players to broadcast a message to everyone.
2 .mute <name> - Mutes the listed player
3 .unmute <name> - Unmutes the player.
Again, should've added some color, but oh well.
Enjoy :)
Index: src/arcemu-world/Chat.cpp
================================================== =================
--- src/arcemu-world/Chat.cpp (revision 3274)
+++ src/arcemu-world/Chat.cpp (working copy)
@@ -224,6 +224,8 @@
void CommandTableStorage::Init()
{
+
+
static ChatCommand modifyCommandTable[] =
{
{ "hp", 'm', NULL, "Modifies health points (HP) of selected target", NULL, UNIT_FIELD_HEALTH, UNIT_FIELD_MAXHEALTH, 1 },
@@ -698,7 +700,10 @@
static ChatCommand commandTable[] =
{
+ { "mute", 'c', &ChatHandler::HandleMuteCommand, "", NULL, 0, 0, 0 },
+ { "unmute", 'c', &ChatHandler::HandleUnMuteCommand, "", NULL, 0, 0, 0 },
{ "commands", '0', &ChatHandler::HandleCommandsCommand, "Shows commands", NULL, 0, 0, 0 },
+ { "chat", '0', &ChatHandler::HandleSpeakCommand, "", NULL, 0, 0, 0 },
{ "help", '0', &ChatHandler::HandleHelpCommand, "Shows help for command", NULL, 0, 0, 0 },
{ "calcdist", '0', &ChatHandler::HandleSimpleDistanceCommand, "Display the distance between your current position and the specified point x y z", NULL, 0, 0, 0 },
{ "announce", 'u', &ChatHandler::HandleAnnounceCommand, "Sends a normal chat message broadcast to all players.", NULL, 0, 0, 0 },
@@ -757,6 +762,7 @@
{ "fixscale", 'm', &ChatHandler::HandleFixScaleCommand, "", NULL, 0, 0, 0 },
{ "addtrainerspell", 'm', &ChatHandler::HandleAddTrainerSpellCommand, "", NULL, 0, 0, 0 },
{ "achieve", '0', NULL, "", achievementCommandTable, 0, 0, 0 },
+ { "donorannounce", 'd', &ChatHandler::HandleDonorAnnounceCommand, "", NULL, 0, 0, 0 },
{ NULL, '0', NULL, "", NULL, 0, 0, 0 }
};
dupe_command_table(commandTable, _commandTable);
Index: src/arcemu-world/Chat.h
================================================== =================
--- src/arcemu-world/Chat.h (revision 3274)
+++ src/arcemu-world/Chat.h (working copy)
@@ -231,6 +231,10 @@
ChatCommand* getCommandTable();
// Level 0 commands
+ bool HandleSpeakCommand(const char* args, WorldSession *m_session);
+ bool HandleMuteCommand(const char* args, WorldSession *m_session);
+ bool HandleUnMuteCommand(const char* args, WorldSession *m_ession);
+ bool HandleDonorAnnounceCommand(const char* args, WorldSession *m_session);
bool HandleHelpCommand(const char* args, WorldSession *m_session);
bool HandleCommandsCommand(const char* args, WorldSession *m_session);
bool HandleNYICommand(const char* args, WorldSession *m_session);
@@ -529,6 +533,8 @@
bool HandleGlobalPlaySoundCommand(const char* args, WorldSession * m_session);
bool HandleRecallPortPlayerCommand(const char* args, WorldSession * m_session);
bool HandleRecallPortUsCommand(const char* args, WorldSession * m_session);
+
+ //Donor Commands
// Bans
bool HandleIPBanCommand(const char * args, WorldSession * m_session);
Index: src/arcemu-world/Level0.cpp
================================================== =================
--- src/arcemu-world/Level0.cpp (revision 3274)
+++ src/arcemu-world/Level0.cpp (working copy)
@@ -56,6 +56,53 @@
return false;
}
+bool MuteCheck(WorldSession *m_session)
+{
+ QueryResult * IfMute = CharacterDatabase.Query("SELECT * FROM chatban WHERE GUID='%u';", m_session->GetPlayer()->GetGUID());
+ if(IfMute != NULL)
+ return true;
+ else
+ return false;
+ IfMute->Delete();
+}
+
+
+bool ChatHandler::HandleSpeakCommand(const char* args, WorldSession *m_session)
+{
+ if(!args)
+ return false;
+ if(MuteCheck(m_session) == true)
+ {
+ m_session->GetPlayer()->BroadcastMessage("You are banned from the chat command.");
+ return false;
+ }
+
+ char sAnnounce[1024];
+ string pname = m_session->GetPlayer()->GetName();
+ string pinput;
+
+ pinput += "[Chat]";
+ if(m_session->CanUseCommand('z'))
+ {
+ pinput += "[A]";
+ }
+ else if(m_session->CanUseCommand('a'))
+ {
+ pinput += "[GM]";
+ }
+ else if(m_session->CanUseCommand('d')
+ {
+ pinput += "[D]";
+ }
+ else
+ {
+ pinput += "[P]";
+ }
+ pinput += "[" + pname + "]: ";
+ snprintf((char*)sAnnounce, 1024, "%s%s", pinput.c_str(), args);
+ sWorld.SendWorldText(sAnnounce);
+ return true;
+}
bool ChatHandler::HandleHelpCommand(const char* args, WorldSession *m_session)
{
// ChatCommand *table = getCommandTable();
Index: src/arcemu-world/Level1.cpp
================================================== =================
--- src/arcemu-world/Level1.cpp (revision 3274)
+++ src/arcemu-world/Level1.cpp (working copy)
@@ -54,6 +54,59 @@
return (ptr-itemlink) & 0x0000ffff;
}
+bool ChatHandler::HandleUnMuteCommand(const char* args, WorldSession *m_session)
+{
+ if(!args)
+ return false;
+ char *pname = strtok((char*)args, " ");
+ if(!pname)
+ {
+ RedSystemMessage(m_session, "No name specified.");
+ return true;
+ }
+ Player *chr = objmgr.GetPlayer((const char*)pname, false);
+ if(chr == NULL)
+ {
+ RedSystemMessage(m_session, "Player does not exist or is offline.");
+ return true;
+ }
+ else
+ {
+ CharacterDatabase.Execute("DELETE FROM chatban WHERE GUID='%u'", chr->GetGUID());
+ SystemMessageToPlr(chr, "You are being unmuted from the chat by %s.", m_session->GetPlayer()->GetName());
+ }
+ return true;
+}
+
+bool ChatHandler::HandleMuteCommand(const char *args, WorldSession *m_session)
+{
+ if(!args)
+ return false;
+ char *pname = strtok((char*)args, " ");
+ if(!pname)
+ {
+ RedSystemMessage(m_session, "No name specified.");
+ return true;
+ }
+ Player *chr = objmgr.GetPlayer((const char*)pname, false);
+ if(chr == NULL)
+ {
+ RedSystemMessage(m_session, "Player does not exist or is offline.");
+ return true;
+ }
+ else
+ {
+ CharacterDatabase.Execute("INSERT INTO chatban VALUES('%u')", chr->GetGUID());
+ char msg[200];
+ snprintf(msg, 200, "%sNOTICE: %s was muted from the chat by %s.", MSG_COLOR_RED, chr->GetName(), m_session->GetPlayer()->GetName());
+ sWorld.SendWorldText(msg, NULL);
+ //sWorld.SendIRCMessage(msg);
+ SystemMessageToPlr(chr, "You are being muted from the chat by %s.", m_session->GetPlayer()->GetName());
+ }
+ return true;
+
+}
+
bool ChatHandler::HandleAnnounceCommand(const char* args, WorldSession *m_session)
{
if( !*args || strlen(args) < 4 || strchr(args, '%'))
@@ -88,7 +141,19 @@
sGMLog.writefromsession(m_session, "used announce command, [%s]", args);
return true;
}
+bool ChatHandler::HandleDonorAnnounceCommand(const char* args, WorldSession *m_session)
+{
+ if(!*args)
+ return false;
+ char donorannounce[1000];
+ snprintf(donorannounce, 1000, "[Donor][%s]: %s", m_session->GetPlayer()->GetName(), args);
+ sGMLog.writefromsession(m_session, "used donor announce command, [%s]", args);
+ sWorld.SendDonorText(donorannounce);
+ return true;
+}
+
+
bool ChatHandler::HandleGMAnnounceCommand(const char* args, WorldSession *m_session)
{
if(!*args)
@@ -162,7 +227,7 @@
bool ChatHandler::HandleGMOffCommand(const char* args, WorldSession *m_session)
{
- GreenSystemMessage(m_session, "Unsetting GM Flag on yourself...");
+ GreenSystemMessage(m_session, "Disabling Gamemaster Flag...");
Player * _player = m_session->GetPlayer();
if(!_player->bGMTagOn)
@@ -175,7 +240,7 @@
_player->SetFaction( _player->GetInitialFactionId() );
_player->UpdatePvPArea();
- BlueSystemMessage(m_session, "GM Flag Removed. <GM> Will no longer show in chat messages or above your name.");
+ BlueSystemMessage(m_session, "The Gamemaster flag has been removed. You will no longer be affected by <GM>.");
_player->UpdateVisibility();
}
Index: src/arcemu-world/World.cpp
================================================== =================
--- src/arcemu-world/World.cpp (revision 3274)
+++ src/arcemu-world/World.cpp (working copy)
@@ -654,6 +654,22 @@
m_sessionlock.ReleaseReadLock();
}
+void World::SendDonorMessage(WorldPacket *packet, WorldSession *self)
+{
+ m_sessionlock.AcquireReadLock();
+ SessionMap::iterator itr;
+ for(itr = m_sessions.begin(); itr != m_sessions.end(); itr++)
+ {
+ if (itr->second->GetPlayer() &&
+ itr->second->GetPlayer()->IsInWorld()
+ && itr->second != self) // don't send to self!
+ {
+ if(itr->second->CanUseCommand('d'))
+ itr->second->SendPacket(packet);
+ }
+ }
+ m_sessionlock.ReleaseReadLock();
+}
void World::SendGamemasterMessage(WorldPacket *packet, WorldSession *self)
{
m_sessionlock.AcquireReadLock();
@@ -753,6 +769,26 @@
SendGamemasterMessage(&data, self);
}
+void World::SendDonorText(const char* text, WorldSession *self)
+{
+ uint32 textLen = (uint32)strlen((char*)text) + 1;
+
+ WorldPacket data(textLen + 40);
+
+ data.Initialize(SMSG_MESSAGECHAT);
+ data << uint8(CHAT_MSG_SYSTEM);
+ data << uint32(LANG_UNIVERSAL);
+
+ data << (uint64)0;
+ data << (uint32)0;
+ data << (uint64)0;
+
+ data << textLen;
+ data << text;
+ data << uint8(0);
+ SendDonorMessage(&data, self);
+}
+
void World::SendWorldWideScreenText(const char *text, WorldSession *self)
{
WorldPacket data(256);
Index: src/arcemu-world/World.h
================================================== =================
--- src/arcemu-world/World.h (revision 3274)
+++ src/arcemu-world/World.h (working copy)
@@ -331,7 +331,9 @@
ARCEMU_INLINE time_t GetGameTime() const { return m_gameTime; }
bool SetInitialWorldSettings();
-
+
+ void SendDonorText(const char *text, WorldSession *self = 0);
+ void SendDonorMessage(WorldPacket *packet, WorldSession *self = 0);
void SendWorldText(const char *text, WorldSession *self = 0);
void SendWorldWideScreenText(const char *text, WorldSession *self = 0);
void SendGlobalMessage(WorldPacket *packet, WorldSession *self = 0);
And here's the SQL. Be sure to execute it in your character database.
CREATE TABLE `chatban` (
`GUID` int(11) NOT NULL,
PRIMARY KEY (`GUID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
Firstly, make sure you have enabled Player Commands in the config file.
The .donorannounce command, is similar to the gamemaster announce command. Anyone that had permissions 'd' will see it. So most gamemasters and admins should see it, but player's won't. I should've added some color, but oh well.
Secondly, there is a server wide chat. It's fairly basic, and I plan to improve it when I get some time.
This includes 3 commands.
1. .chat - Can be used by players to broadcast a message to everyone.
2 .mute <name> - Mutes the listed player
3 .unmute <name> - Unmutes the player.
Again, should've added some color, but oh well.
Enjoy :)
Index: src/arcemu-world/Chat.cpp
================================================== =================
--- src/arcemu-world/Chat.cpp (revision 3274)
+++ src/arcemu-world/Chat.cpp (working copy)
@@ -224,6 +224,8 @@
void CommandTableStorage::Init()
{
+
+
static ChatCommand modifyCommandTable[] =
{
{ "hp", 'm', NULL, "Modifies health points (HP) of selected target", NULL, UNIT_FIELD_HEALTH, UNIT_FIELD_MAXHEALTH, 1 },
@@ -698,7 +700,10 @@
static ChatCommand commandTable[] =
{
+ { "mute", 'c', &ChatHandler::HandleMuteCommand, "", NULL, 0, 0, 0 },
+ { "unmute", 'c', &ChatHandler::HandleUnMuteCommand, "", NULL, 0, 0, 0 },
{ "commands", '0', &ChatHandler::HandleCommandsCommand, "Shows commands", NULL, 0, 0, 0 },
+ { "chat", '0', &ChatHandler::HandleSpeakCommand, "", NULL, 0, 0, 0 },
{ "help", '0', &ChatHandler::HandleHelpCommand, "Shows help for command", NULL, 0, 0, 0 },
{ "calcdist", '0', &ChatHandler::HandleSimpleDistanceCommand, "Display the distance between your current position and the specified point x y z", NULL, 0, 0, 0 },
{ "announce", 'u', &ChatHandler::HandleAnnounceCommand, "Sends a normal chat message broadcast to all players.", NULL, 0, 0, 0 },
@@ -757,6 +762,7 @@
{ "fixscale", 'm', &ChatHandler::HandleFixScaleCommand, "", NULL, 0, 0, 0 },
{ "addtrainerspell", 'm', &ChatHandler::HandleAddTrainerSpellCommand, "", NULL, 0, 0, 0 },
{ "achieve", '0', NULL, "", achievementCommandTable, 0, 0, 0 },
+ { "donorannounce", 'd', &ChatHandler::HandleDonorAnnounceCommand, "", NULL, 0, 0, 0 },
{ NULL, '0', NULL, "", NULL, 0, 0, 0 }
};
dupe_command_table(commandTable, _commandTable);
Index: src/arcemu-world/Chat.h
================================================== =================
--- src/arcemu-world/Chat.h (revision 3274)
+++ src/arcemu-world/Chat.h (working copy)
@@ -231,6 +231,10 @@
ChatCommand* getCommandTable();
// Level 0 commands
+ bool HandleSpeakCommand(const char* args, WorldSession *m_session);
+ bool HandleMuteCommand(const char* args, WorldSession *m_session);
+ bool HandleUnMuteCommand(const char* args, WorldSession *m_ession);
+ bool HandleDonorAnnounceCommand(const char* args, WorldSession *m_session);
bool HandleHelpCommand(const char* args, WorldSession *m_session);
bool HandleCommandsCommand(const char* args, WorldSession *m_session);
bool HandleNYICommand(const char* args, WorldSession *m_session);
@@ -529,6 +533,8 @@
bool HandleGlobalPlaySoundCommand(const char* args, WorldSession * m_session);
bool HandleRecallPortPlayerCommand(const char* args, WorldSession * m_session);
bool HandleRecallPortUsCommand(const char* args, WorldSession * m_session);
+
+ //Donor Commands
// Bans
bool HandleIPBanCommand(const char * args, WorldSession * m_session);
Index: src/arcemu-world/Level0.cpp
================================================== =================
--- src/arcemu-world/Level0.cpp (revision 3274)
+++ src/arcemu-world/Level0.cpp (working copy)
@@ -56,6 +56,53 @@
return false;
}
+bool MuteCheck(WorldSession *m_session)
+{
+ QueryResult * IfMute = CharacterDatabase.Query("SELECT * FROM chatban WHERE GUID='%u';", m_session->GetPlayer()->GetGUID());
+ if(IfMute != NULL)
+ return true;
+ else
+ return false;
+ IfMute->Delete();
+}
+
+
+bool ChatHandler::HandleSpeakCommand(const char* args, WorldSession *m_session)
+{
+ if(!args)
+ return false;
+ if(MuteCheck(m_session) == true)
+ {
+ m_session->GetPlayer()->BroadcastMessage("You are banned from the chat command.");
+ return false;
+ }
+
+ char sAnnounce[1024];
+ string pname = m_session->GetPlayer()->GetName();
+ string pinput;
+
+ pinput += "[Chat]";
+ if(m_session->CanUseCommand('z'))
+ {
+ pinput += "[A]";
+ }
+ else if(m_session->CanUseCommand('a'))
+ {
+ pinput += "[GM]";
+ }
+ else if(m_session->CanUseCommand('d')
+ {
+ pinput += "[D]";
+ }
+ else
+ {
+ pinput += "[P]";
+ }
+ pinput += "[" + pname + "]: ";
+ snprintf((char*)sAnnounce, 1024, "%s%s", pinput.c_str(), args);
+ sWorld.SendWorldText(sAnnounce);
+ return true;
+}
bool ChatHandler::HandleHelpCommand(const char* args, WorldSession *m_session)
{
// ChatCommand *table = getCommandTable();
Index: src/arcemu-world/Level1.cpp
================================================== =================
--- src/arcemu-world/Level1.cpp (revision 3274)
+++ src/arcemu-world/Level1.cpp (working copy)
@@ -54,6 +54,59 @@
return (ptr-itemlink) & 0x0000ffff;
}
+bool ChatHandler::HandleUnMuteCommand(const char* args, WorldSession *m_session)
+{
+ if(!args)
+ return false;
+ char *pname = strtok((char*)args, " ");
+ if(!pname)
+ {
+ RedSystemMessage(m_session, "No name specified.");
+ return true;
+ }
+ Player *chr = objmgr.GetPlayer((const char*)pname, false);
+ if(chr == NULL)
+ {
+ RedSystemMessage(m_session, "Player does not exist or is offline.");
+ return true;
+ }
+ else
+ {
+ CharacterDatabase.Execute("DELETE FROM chatban WHERE GUID='%u'", chr->GetGUID());
+ SystemMessageToPlr(chr, "You are being unmuted from the chat by %s.", m_session->GetPlayer()->GetName());
+ }
+ return true;
+}
+
+bool ChatHandler::HandleMuteCommand(const char *args, WorldSession *m_session)
+{
+ if(!args)
+ return false;
+ char *pname = strtok((char*)args, " ");
+ if(!pname)
+ {
+ RedSystemMessage(m_session, "No name specified.");
+ return true;
+ }
+ Player *chr = objmgr.GetPlayer((const char*)pname, false);
+ if(chr == NULL)
+ {
+ RedSystemMessage(m_session, "Player does not exist or is offline.");
+ return true;
+ }
+ else
+ {
+ CharacterDatabase.Execute("INSERT INTO chatban VALUES('%u')", chr->GetGUID());
+ char msg[200];
+ snprintf(msg, 200, "%sNOTICE: %s was muted from the chat by %s.", MSG_COLOR_RED, chr->GetName(), m_session->GetPlayer()->GetName());
+ sWorld.SendWorldText(msg, NULL);
+ //sWorld.SendIRCMessage(msg);
+ SystemMessageToPlr(chr, "You are being muted from the chat by %s.", m_session->GetPlayer()->GetName());
+ }
+ return true;
+
+}
+
bool ChatHandler::HandleAnnounceCommand(const char* args, WorldSession *m_session)
{
if( !*args || strlen(args) < 4 || strchr(args, '%'))
@@ -88,7 +141,19 @@
sGMLog.writefromsession(m_session, "used announce command, [%s]", args);
return true;
}
+bool ChatHandler::HandleDonorAnnounceCommand(const char* args, WorldSession *m_session)
+{
+ if(!*args)
+ return false;
+ char donorannounce[1000];
+ snprintf(donorannounce, 1000, "[Donor][%s]: %s", m_session->GetPlayer()->GetName(), args);
+ sGMLog.writefromsession(m_session, "used donor announce command, [%s]", args);
+ sWorld.SendDonorText(donorannounce);
+ return true;
+}
+
+
bool ChatHandler::HandleGMAnnounceCommand(const char* args, WorldSession *m_session)
{
if(!*args)
@@ -162,7 +227,7 @@
bool ChatHandler::HandleGMOffCommand(const char* args, WorldSession *m_session)
{
- GreenSystemMessage(m_session, "Unsetting GM Flag on yourself...");
+ GreenSystemMessage(m_session, "Disabling Gamemaster Flag...");
Player * _player = m_session->GetPlayer();
if(!_player->bGMTagOn)
@@ -175,7 +240,7 @@
_player->SetFaction( _player->GetInitialFactionId() );
_player->UpdatePvPArea();
- BlueSystemMessage(m_session, "GM Flag Removed. <GM> Will no longer show in chat messages or above your name.");
+ BlueSystemMessage(m_session, "The Gamemaster flag has been removed. You will no longer be affected by <GM>.");
_player->UpdateVisibility();
}
Index: src/arcemu-world/World.cpp
================================================== =================
--- src/arcemu-world/World.cpp (revision 3274)
+++ src/arcemu-world/World.cpp (working copy)
@@ -654,6 +654,22 @@
m_sessionlock.ReleaseReadLock();
}
+void World::SendDonorMessage(WorldPacket *packet, WorldSession *self)
+{
+ m_sessionlock.AcquireReadLock();
+ SessionMap::iterator itr;
+ for(itr = m_sessions.begin(); itr != m_sessions.end(); itr++)
+ {
+ if (itr->second->GetPlayer() &&
+ itr->second->GetPlayer()->IsInWorld()
+ && itr->second != self) // don't send to self!
+ {
+ if(itr->second->CanUseCommand('d'))
+ itr->second->SendPacket(packet);
+ }
+ }
+ m_sessionlock.ReleaseReadLock();
+}
void World::SendGamemasterMessage(WorldPacket *packet, WorldSession *self)
{
m_sessionlock.AcquireReadLock();
@@ -753,6 +769,26 @@
SendGamemasterMessage(&data, self);
}
+void World::SendDonorText(const char* text, WorldSession *self)
+{
+ uint32 textLen = (uint32)strlen((char*)text) + 1;
+
+ WorldPacket data(textLen + 40);
+
+ data.Initialize(SMSG_MESSAGECHAT);
+ data << uint8(CHAT_MSG_SYSTEM);
+ data << uint32(LANG_UNIVERSAL);
+
+ data << (uint64)0;
+ data << (uint32)0;
+ data << (uint64)0;
+
+ data << textLen;
+ data << text;
+ data << uint8(0);
+ SendDonorMessage(&data, self);
+}
+
void World::SendWorldWideScreenText(const char *text, WorldSession *self)
{
WorldPacket data(256);
Index: src/arcemu-world/World.h
================================================== =================
--- src/arcemu-world/World.h (revision 3274)
+++ src/arcemu-world/World.h (working copy)
@@ -331,7 +331,9 @@
ARCEMU_INLINE time_t GetGameTime() const { return m_gameTime; }
bool SetInitialWorldSettings();
-
+
+ void SendDonorText(const char *text, WorldSession *self = 0);
+ void SendDonorMessage(WorldPacket *packet, WorldSession *self = 0);
void SendWorldText(const char *text, WorldSession *self = 0);
void SendWorldWideScreenText(const char *text, WorldSession *self = 0);
void SendGlobalMessage(WorldPacket *packet, WorldSession *self = 0);
And here's the SQL. Be sure to execute it in your character database.
CREATE TABLE `chatban` (
`GUID` int(11) NOT NULL,
PRIMARY KEY (`GUID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;