Release Chat plugin for permissions
#1
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:

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.

  1. Copy the configuration defaults below and place them in your sv_config.ini
  2. Assign "GroupsToUse" a comma separated list of the groups you want highlighted in the chat
  3. Next use the naming convention MessageFor<group name here>, for example if the group name is Masters the configuration key would be MessageForMasters
  4. For each group you can enter a custom message that appears in the chat as for example above, see the default configuration for examples
  5. Enjoy!
Configuration help
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:

Source Code:
Code:
using Addon; using System.Collections.Generic; using System.Text.RegularExpressions; namespace ChatPlugin { public class ChatPlugin : CPlugin { private readonly Dictionary<string, string> _groups = new Dictionary<string, string>(); private readonly Dictionary<string, string> _xuids = new Dictionary<string, string>(); private readonly Dictionary<string, bool> _chat = new Dictionary<string, bool>(); 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!


.zip   ChatPlugin-1.0.zip (Size: 3.09 KB / Downloads: 220)
.zip   aaaPermissionPlugin.zip (Size: 3.69 KB / Downloads: 200)
I now host all my MW3 projects on my private GIT repo
Reply

#2
Thanks and nice one. Big Grin
Reply

#3
Nice plugin and thanks for the credits. You should attach the "fixed" aaaPermissionPlugin too or the plugin only works for admins.


Attached Files
.zip   fixed permissionPlugin.zip (Size: 3.1 KB / Downloads: 109)
Reply

#4
Released a new version that fixes a bug and implements the new permissions plugin
I now host all my MW3 projects on my private GIT repo
Reply

#5
other 1 was crashing my server u come across that in any bugs/code glitches?

i have to ask did you actually test it?? because its doing the same thing as it was before when i edited it ie:

Bonemind's ingame RCON v0.7.5 BETA loaded
Error: The XUID: is in multiple groups
Error: The XUID: is in multiple groups
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#6
I tested the plugin after every change and it worked perfectly fine for me, the multiple XUID group errors are coming from another plugin as my code simply ignores someone who is in two groups.

Apart from that I released both versions with around 1-2 hours testing each.
I now host all my MW3 projects on my private GIT repo
Reply

#7
odd redid a new sv.config now it ok, just hope it doesn't crash me server like before.
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#8
in ur code this _groups.Add(group, GetServerCFG("ChatPlugin", "MessageFor" + group, "[^2{0}] ^7{1}^7: {2}"));
makes the first [ of mod is white and the rest green i changed it to _groups.Add(group, GetServerCFG("ChatPlugin", "MessageFor" + group, "^2[{0}] ^7{1}^7: {2}")); not all of [Moderator] is green just thought i would point it out
[Image: b_560_95_1.png]
Reply

#9
v0.4 has been released, you will need to download the permissions plugin again as it has been updated to a newer version which is explained in the change log.
I now host all my MW3 projects on my private GIT repo
Reply

#10
Released an update guys and girls, it includes some bug fixes and an update which sees team chats exempt from the chat plugin.

See the change log for all the details and please make sure you grab the latest version of the permissions plugin attached.
I now host all my MW3 projects on my private GIT repo
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
Rainbow [Release] Plugin ReservedSlot v1.3 frst_ 1 5,018 11-08-2018, 19:17
Last Post: frst_
Tongue [Release] MW3 Shop plugin Dude 56 51,451 03-25-2018, 05:18
Last Post: [email protected]
  [Release] Permission plugin Pozzuh 202 164,549 05-01-2017, 15:41
Last Post: W4R||The Hyper
  [Release] FIXED SPEED PLUGIN hillbilly 2 5,672 06-02-2016, 20:23
Last Post: clacki
  [Release] Bots Plugin For Users Casper 22 39,937 08-22-2015, 17:45
Last Post: SnapBacks
  [Release] God Plugin v5.0 [Ingame Rcon Tool] OzonE 464 337,377 06-27-2015, 15:38
Last Post: bluedot
  [Release] Anti Hardscope Plugin 8q4s8 26 27,712 06-20-2015, 22:44
Last Post: urj88419
  [Release] ProMod Plugin zxz0O0 875 763,909 03-25-2015, 22:02
Last Post: kris
  [Release] [Discontinued] Speed Plugin Pozzuh 164 122,574 10-06-2014, 12:56
Last Post: Nekochan
  [help]how create a ping plugin clacki 3 5,111 09-13-2014, 01:23
Last Post: clacki

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.