Hi guys and girls,
This is a very small release and probably won't relate to many, I had a request to update a simple plugin originally developed by @8q4s8, this release/update contain some changes that make it dynamic so you can now freely use the groups you have assigned through the permissions plugin on your server.
PLEASE NOTE
You will need to download the attached version of the permissions plugin for this plugin to work correctly!
So what does this plugin do?
This plugin will allow you to highlight the groups you've set for the chat plugin, for example instead of a boring name and message you could have the following:
What commands can I use?
See the below for the installation instructions.
sv_config.ini:
Changelog:
Source Code:
Credits:
@8q4s8 - Original plugin creator
@Pozzuh - For the permissions plugin
@Nukem - For such a great code base to work with
Apart from the commands above the plugin will work its magic in the background without any input been required by the client. Enjoy!
ChatPlugin-1.0.zip (Size: 3.09 KB / Downloads: 159)
aaaPermissionPlugin.zip (Size: 3.69 KB / Downloads: 117)
This is a very small release and probably won't relate to many, I had a request to update a simple plugin originally developed by @8q4s8, this release/update contain some changes that make it dynamic so you can now freely use the groups you have assigned through the permissions plugin on your server.
PLEASE NOTE
You will need to download the attached version of the permissions plugin for this plugin to work correctly!
So what does this plugin do?
This plugin will allow you to highlight the groups you've set for the chat plugin, for example instead of a boring name and message you could have the following:
Quote:[<group>] <name>: <message>
What commands can I use?
Quote:!chat - Disables the chat plugin for all clients
!toggletag - Toggles the plugin for the client who used the command
See the below for the installation instructions.
- Copy the configuration defaults below and place them in your sv_config.ini
- Assign "GroupsToUse" a comma separated list of the groups you want highlighted in the chat
- Next use the naming convention MessageFor<group name here>, for example if the group name is Masters the configuration key would be MessageForMasters
- For each group you can enter a custom message that appears in the chat as for example above, see the default configuration for examples
- Enjoy!
Code:
{0} = Group name
{1} = Client name
{2} = Original message entered by the client
sv_config.ini:
Code:
[ChatPlugin]
// Disable the plugin for all clients by default?
DisableChatPlugin=false
// The groups to use for the chat plugin
GroupsToUse=Admin,Moderators
// The messages for the groups specified
MessageForAdmin=^1[^4{0}^1] ^7{1}^7: {2}
MessageForModerators=[^2{0}] ^7{1}^7: {2}
Changelog:
Spoiler (Click to View)
Source Code:
CSHARP Code
- using Addon;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
-
- namespace ChatPlugin
- {
- public class ChatPlugin : CPlugin
- {
- private const string DefaultGroups = "Admin,Moderator";
- private const string InvalidGroupValueRegExp = @"\*(EVERYONE|ALL)\*";
- private string[] _groupsToUse;
- private bool _togglechat;
-
- /// <summary>
- /// Executes when the MW3 server loads
- /// </summary>
- public override void OnServerLoad()
- {
- ServerPrint("[ChatPlugin] By 8Q4S8 loaded!");
- ServerPrint("[ChatPlugin] Updated by SgtLegend on May 12, 2013");
-
- // Set the default state of the plugin
- bool.TryParse(GetServerCFG("ChatPlugin", "DisableChatPlugin", "false"), out _togglechat);
-
- // Get the configuration values we need
- _groupsToUse = GetServerCFG("ChatPlugin", "GroupsToUse", DefaultGroups).Split(',');
-
- if (_groupsToUse.Length == 0) return;
- foreach (string group in _groupsToUse)
- {
- // Add the group to a storage array
- if (!_groups.ContainsKey(group))
- {
- _groups.Add(group, GetServerCFG("ChatPlugin", "MessageFor" + group, "[^2{0}^7] ^7{1}^7: {2}"));
- }
-
- // Extract the xuids for the specified group
- string xuidsForGroup = GetServerCFG("Permission", group + "_xuids", "");
-
- if (Regex.Match(xuidsForGroup, InvalidGroupValueRegExp, RegexOptions.IgnoreCase).Success) continue;
- string[] xuids = xuidsForGroup.Split(',');
-
- if (xuids.Length == 0) continue;
- foreach (string xuid in xuids)
- {
- if (!_xuids.ContainsKey(xuid))
- {
- _xuids.Add(xuid, group);
- }
- }
- }
- }
-
- /// <summary>
- /// Executes when a player types something into the chat
- /// </summary>
- /// <param name="message"></param>
- /// <param name="client"></param>
- /// <param name="teamchat"></param>
- /// <returns></returns>
- public override ChatType OnSay(string message, ServerClient client, bool teamchat)
- {
- if (!message.StartsWith("!") && !teamchat && !_togglechat && !_chat[client.XUID] && _xuids.ContainsKey(client.XUID))
- {
- foreach (KeyValuePair<string, string> group in _groups)
- {
- if (_xuids[client.XUID] == group.Key && !string.IsNullOrEmpty(group.Value))
- {
- ServerSay(string.Format(group.Value, group.Key, client.Name, message), true);
- return ChatType.ChatNone;
- }
- }
- }
-
- // Toggle the plugin for all the clients on the server
- if (message.ToLower() == "!chat")
- {
- _togglechat = !_togglechat;
- return ChatType.ChatNone;
- }
-
- // Toggle the plugin for the client that typed this command
- if (message.ToLower() == "!toggletag")
- {
- _chat[client.XUID] = !_chat[client.XUID];
- return ChatType.ChatNone;
- }
-
- return ChatType.ChatContinue;
- }
-
- /// <summary>
- /// Executes when a player joins the server
- /// </summary>
- /// <param name="client"></param>
- public override void OnPlayerConnect(ServerClient client)
- {
- if (!_chat.ContainsKey(client.XUID))
- {
- _chat.Add(client.XUID, false);
- }
-
- AddClientToChatXuiDsList(client.XUID);
- }
-
- /// <summary>
- /// Tries to find the group for the user that has just joined the server
- /// </summary>
- /// <param name="xuid"></param>
- private void AddClientToChatXuiDsList(string xuid)
- {
- string[] userGroups = GetServerCFG("ChatPlugin", "GroupsToUse", DefaultGroups).Split(',');
-
- if (userGroups.Length == 0) return;
- foreach (string group in userGroups)
- {
- string xuidsForGroup = GetServerCFG("Permission", group + "_xuids", "");
-
- if (Regex.Match(xuidsForGroup, InvalidGroupValueRegExp, RegexOptions.IgnoreCase).Success &&
- !_xuids.ContainsKey(xuid))
- {
- _xuids.Add(xuid, group);
- }
- }
- }
- }
- }
Credits:
@8q4s8 - Original plugin creator
@Pozzuh - For the permissions plugin
@Nukem - For such a great code base to work with
Apart from the commands above the plugin will work its magic in the background without any input been required by the client. Enjoy!


I now host all my MW3 projects on my private GIT repo