• 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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:
CSHARP Code
  1. using Addon;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace ChatPlugin
  6. {
  7. public class ChatPlugin : CPlugin
  8. {
  9. private readonly Dictionary<string, string> _groups = new Dictionary<string, string>();
  10. private readonly Dictionary<string, string> _xuids = new Dictionary<string, string>();
  11. private readonly Dictionary<string, bool> _chat = new Dictionary<string, bool>();
  12. private const string DefaultGroups = "Admin,Moderator";
  13. private const string InvalidGroupValueRegExp = @"\*(EVERYONE|ALL)\*";
  14. private string[] _groupsToUse;
  15. private bool _togglechat;
  16.  
  17. /// <summary>
  18. /// Executes when the MW3 server loads
  19. /// </summary>
  20. public override void OnServerLoad()
  21. {
  22. ServerPrint("[ChatPlugin] By 8Q4S8 loaded!");
  23. ServerPrint("[ChatPlugin] Updated by SgtLegend on May 12, 2013");
  24.  
  25. // Set the default state of the plugin
  26. bool.TryParse(GetServerCFG("ChatPlugin", "DisableChatPlugin", "false"), out _togglechat);
  27.  
  28. // Get the configuration values we need
  29. _groupsToUse = GetServerCFG("ChatPlugin", "GroupsToUse", DefaultGroups).Split(',');
  30.  
  31. if (_groupsToUse.Length == 0) return;
  32. foreach (string group in _groupsToUse)
  33. {
  34. // Add the group to a storage array
  35. if (!_groups.ContainsKey(group))
  36. {
  37. _groups.Add(group, GetServerCFG("ChatPlugin", "MessageFor" + group, "[^2{0}^7] ^7{1}^7: {2}"));
  38. }
  39.  
  40. // Extract the xuids for the specified group
  41. string xuidsForGroup = GetServerCFG("Permission", group + "_xuids", "");
  42.  
  43. if (Regex.Match(xuidsForGroup, InvalidGroupValueRegExp, RegexOptions.IgnoreCase).Success) continue;
  44. string[] xuids = xuidsForGroup.Split(',');
  45.  
  46. if (xuids.Length == 0) continue;
  47. foreach (string xuid in xuids)
  48. {
  49. if (!_xuids.ContainsKey(xuid))
  50. {
  51. _xuids.Add(xuid, group);
  52. }
  53. }
  54. }
  55. }
  56.  
  57. /// <summary>
  58. /// Executes when a player types something into the chat
  59. /// </summary>
  60. /// <param name="message"></param>
  61. /// <param name="client"></param>
  62. /// <param name="teamchat"></param>
  63. /// <returns></returns>
  64. public override ChatType OnSay(string message, ServerClient client, bool teamchat)
  65. {
  66. if (!message.StartsWith("!") && !teamchat && !_togglechat && !_chat[client.XUID] && _xuids.ContainsKey(client.XUID))
  67. {
  68. foreach (KeyValuePair<string, string> group in _groups)
  69. {
  70. if (_xuids[client.XUID] == group.Key && !string.IsNullOrEmpty(group.Value))
  71. {
  72. ServerSay(string.Format(group.Value, group.Key, client.Name, message), true);
  73. return ChatType.ChatNone;
  74. }
  75. }
  76. }
  77.  
  78. // Toggle the plugin for all the clients on the server
  79. if (message.ToLower() == "!chat")
  80. {
  81. _togglechat = !_togglechat;
  82. return ChatType.ChatNone;
  83. }
  84.  
  85. // Toggle the plugin for the client that typed this command
  86. if (message.ToLower() == "!toggletag")
  87. {
  88. _chat[client.XUID] = !_chat[client.XUID];
  89. return ChatType.ChatNone;
  90. }
  91.  
  92. return ChatType.ChatContinue;
  93. }
  94.  
  95. /// <summary>
  96. /// Executes when a player joins the server
  97. /// </summary>
  98. /// <param name="client"></param>
  99. public override void OnPlayerConnect(ServerClient client)
  100. {
  101. if (!_chat.ContainsKey(client.XUID))
  102. {
  103. _chat.Add(client.XUID, false);
  104. }
  105.  
  106. AddClientToChatXuiDsList(client.XUID);
  107. }
  108.  
  109. /// <summary>
  110. /// Tries to find the group for the user that has just joined the server
  111. /// </summary>
  112. /// <param name="xuid"></param>
  113. private void AddClientToChatXuiDsList(string xuid)
  114. {
  115. string[] userGroups = GetServerCFG("ChatPlugin", "GroupsToUse", DefaultGroups).Split(',');
  116.  
  117. if (userGroups.Length == 0) return;
  118. foreach (string group in userGroups)
  119. {
  120. string xuidsForGroup = GetServerCFG("Permission", group + "_xuids", "");
  121.  
  122. if (Regex.Match(xuidsForGroup, InvalidGroupValueRegExp, RegexOptions.IgnoreCase).Success &&
  123. !_xuids.ContainsKey(xuid))
  124. {
  125. _xuids.Add(xuid, group);
  126. }
  127. }
  128. }
  129. }
  130. }


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: 159)
.zip   aaaPermissionPlugin.zip (Size: 3.69 KB / Downloads: 117)
I now host all my MW3 projects on my private GIT repo
[-] The following 9 users say Thank You to SgtLegend for this post:
  • 8q4s8, 99IRock, Casper, Dr3am95, hillbilly, MADD_DOGG, Nekochan, Nukem, Pozzuh
  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: 53)
[-] The following 2 users say Thank You to 8q4s8 for this post:
  • Casper, MADD_DOGG
  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
Wink Plugin with !ban !kick and !tampban clemi555 3 2,057 11-09-2013, 09:21
Last Post: clemi555
  AntiNoScope Plugin clemi555 5 2,349 11-08-2013, 19:13
Last Post: clemi555
  [Release] Bunker Plugin 1.3 archit 68 21,183 10-30-2013, 11:59
Last Post: clacki
  Help Modifying plugin maverigh 5 3,030 10-19-2013, 10:29
Last Post: Nekochan
Shocked [Request] Switch plugin axel-le-meilleur 6 2,304 10-19-2013, 06:59
Last Post: iRoNinja
  [Release] Yurio Map Plugin Yurio 101 33,928 09-26-2013, 13:38
Last Post: First_Semyon
Brick [Release] v1.1 ChangeMap/NextMap Plugin without any configuration milchshake 23 10,720 09-23-2013, 13:18
Last Post: SgtLegend
  Help !say Plugin (like the !say from GodPlugin) Hallla 0 1,326 09-13-2013, 09:31
Last Post: Hallla
Rainbow [Release] MW3: Random Weapon Plugin V1 Nekochan 50 16,748 09-11-2013, 15:11
Last Post: EnVi Sweden Rocks
  Search Plugin Fluid Killcam N3xT_974 1 1,481 09-10-2013, 20:27
Last Post: Nekochan

Forum Jump:


Users browsing this thread: 1 Guest(s)