• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release Chat Locker
#1
Hi guys and girls,

I have yet another simple plugin which I think is something every server should have to stop annoying chat spammers or just stopping someone in general from been able to chat, I designed this plugin so clients with the permission to use it are able to block users from using the chat for x amount of minutes.

PLEASE NOTE
You will need to download the custom version of the permissions plugin attached which I have modified to allow custom chat inputs otherwise the chat will double up.

What commands can I use?

How do I install the plugin?
  1. Download the latest version of the chat locker and the custom permissions plugin at the bottom of this post
  2. Unzip the archive files and upload the DLL files to your servers plugin folder
Configuration "sv_config.ini"
Code:
[ChatLocker]
// Comma seperated list of XUID's, as of version 0.2
ImmunePlayers=

Changelog:

Source Code:
CSHARP Code
  1. using Addon;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Threading;
  6.  
  7. namespace ChatLocker
  8. {
  9. public class ChatLocker : CPlugin
  10. {
  11. private readonly Dictionary<string, DateTime> _playerLocks = new Dictionary<string, DateTime>();
  12. private List<string> _immunePlayers;
  13.  
  14. /// <summary>
  15. /// Executes when the MW3 server loads
  16. /// </summary>
  17. public override void OnServerLoad()
  18. {
  19. ServerPrint("Chat Locker created by SgtLegend. Version 0.3");
  20.  
  21. // Get the configuration
  22. _immunePlayers = new List<string>(GetServerCFG("ChatLocker", "ImmunePlayers", "").Split(','));
  23. }
  24.  
  25. /// <summary>
  26. /// Executes when a client types something into the chat
  27. /// </summary>
  28. /// <param name="message"></param>
  29. /// <param name="client"></param>
  30. /// <param name="teamchat"></param>
  31. /// <returns></returns>
  32. public override ChatType OnSay(string message, ServerClient client, bool teamchat)
  33. {
  34. List<string> cmd = new List<string>(message.Split(' '));
  35.  
  36. // Check if the current player has been chat locked
  37. if (!message.StartsWith("!") && _playerLocks.ContainsKey(client.XUID))
  38. {
  39. TimeSpan remaining = DateTime.Now - _playerLocks[client.XUID];
  40.  
  41. // If the time span is greater than the remaining time let the player know they are still chat locked
  42. if (TimeSpan.Zero > remaining)
  43. {
  44. iPrintLnBold(string.Format(
  45. "You are still chat locked for ^:{0} ^7hour(s) ^:{1} ^7minute(s) and ^:{2} ^7second(s)",
  46. Math.Abs(remaining.Hours),
  47. Math.Abs(remaining.Minutes),
  48. Math.Abs(remaining.Seconds)), client);
  49.  
  50. return ChatType.ChatNone;
  51. }
  52.  
  53. // If the time span is less or equal to the remaining time remove the players current chat lock status
  54. if (TimeSpan.Zero <= remaining)
  55. {
  56. _playerLocks.Remove(client.XUID);
  57. }
  58. }
  59.  
  60. // Check if the given command is associated with the Chat Locker plugin
  61. Match matches = Regex.Match(cmd[0], @"\!((?<img src="https://www.itsmods.com/forum/images/smilies/sad.gif" alt="Sad" title="Sad" class="smilie smilie_8" />?:un|whos)?lock(?:ed)?)c?)", RegexOptions.IgnoreCase);
  62.  
  63. if (matches.Success)
  64. {
  65. string match = matches.Groups[1].Value.ToLower();
  66. cmd.RemoveAt(0);
  67.  
  68. switch (match)
  69. {
  70. case "lock":
  71. case "lockc":
  72. LockPlayerChat(cmd, client, (match == "lockc"));
  73. break;
  74.  
  75. case "unlock":
  76. case "unlockc":
  77. UnlockPlayerChat(cmd, client, (match == "unlockc"));
  78. break;
  79.  
  80. case "whoslocked":
  81. FindChatLockedPlayers(client);
  82. break;
  83. }
  84.  
  85. return ChatType.ChatNone;
  86. }
  87.  
  88. return ChatType.ChatContinue;
  89. }
  90.  
  91. /// <summary>
  92. /// Locks the given players chat for X amount of minutes
  93. /// </summary>
  94. /// <param name="cmd"></param>
  95. /// <param name="issuer"></param>
  96. /// <param name="byClientId"></param>
  97. private void LockPlayerChat(List<string> cmd, ServerClient issuer, bool byClientId)
  98. {
  99. if (cmd.Count == 0 || string.IsNullOrEmpty(cmd[0]))
  100. {
  101. TellClient(issuer.ClientNum, "^1[Chat Lock] ^7Please enter a valid player id or name", true);
  102. }
  103. else
  104. {
  105. double timeToLock = 0;
  106.  
  107. if (cmd.Count < 2 || (cmd[1] != null && !double.TryParse(cmd[1], out timeToLock) && timeToLock > 0))
  108. {
  109. TellClient(issuer.ClientNum, "^1[Chat Lock] ^7Please enter a valid number for the lock minutes", true);
  110. }
  111. else
  112. {
  113. ServerClient client = (byClientId ? FindClientByCommandInput(int.Parse(cmd[0])) : FindClientByCommandInput(cmd[0]));
  114.  
  115. if (client != null)
  116. {
  117. if (_immunePlayers.Contains(client.XUID))
  118. {
  119. TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is immune to chat locks", client.Name), true);
  120. }
  121. else if (_playerLocks.ContainsKey(client.XUID))
  122. {
  123. TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7has already been chat locked", client.Name), true);
  124. }
  125. else
  126. {
  127. // Get the time span for the current date and the new date
  128. TimeSpan remaining = TimeSpan.FromMinutes(timeToLock);
  129.  
  130. // Add the play chat lock status
  131. _playerLocks.Add(client.XUID, DateTime.Now + remaining);
  132.  
  133. // Log the chat lock in the server locks and let the player know
  134. ServerPrint(
  135. string.Format(
  136. "[Chat Lock] {0} was chat locked for {1} hour(s) and {2} minute(s) by {3}",
  137. client.Name, Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes), issuer.Name));
  138.  
  139. TellClient(issuer.ClientNum,
  140. string.Format("^1[Chat Lock] ^:{0} ^7has been chat locked successfully!",
  141. client.Name), true);
  142.  
  143. TellClient(client.ClientNum,
  144. string.Format(
  145. "^1[Chat Lock] ^7You have been chat locked for {0} hour(s) and {1} minute(s)",
  146. Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes)), true);
  147. }
  148. }
  149. else
  150. {
  151. TellClient(issuer.ClientNum, "^1[Chat Lock] ^7No players were found", true);
  152. }
  153. }
  154. }
  155. }
  156.  
  157. /// <summary>
  158. /// Un-locks the given players chat so they can speak again
  159. /// </summary>
  160. /// <param name="cmd"></param>
  161. /// <param name="issuer"></param>
  162. /// <param name="byClientId"></param>
  163. private void UnlockPlayerChat(List<string> cmd, ServerClient issuer, bool byClientId)
  164. {
  165. if (cmd.Count == 0 || string.IsNullOrEmpty(cmd[0]))
  166. {
  167. TellClient(issuer.ClientNum, "^1[Chat Lock] ^7Please enter a valid player id or name", true);
  168. }
  169. else
  170. {
  171. ServerClient client = (byClientId ? FindClientByCommandInput(int.Parse(cmd[0])) : FindClientByCommandInput(cmd[0]));
  172.  
  173. if (client != null)
  174. {
  175. if (!_playerLocks.ContainsKey(client.XUID))
  176. {
  177. TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is not chat locked", client.Name), true);
  178. }
  179. else
  180. {
  181. _playerLocks.Remove(client.XUID);
  182.  
  183. // Set the client messages
  184. TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is aloud to chat again", client.Name), true);
  185. TellClient(client.ClientNum, "^1[Chat Lock] ^7Your chat lock is now over, be good!", true);
  186. }
  187. }
  188. else
  189. {
  190. TellClient(issuer.ClientNum, "^1[Chat Lock] ^7No players were found", true);
  191. }
  192. }
  193. }
  194.  
  195. /// <summary>
  196. /// Creates a new thread to start listing the chat locked players, it runs on a thread so that the chat
  197. /// doesn't get inundated with a players information
  198. /// </summary>
  199. /// <param name="issuer"></param>
  200. private void FindChatLockedPlayers(ServerClient issuer)
  201. {
  202. if (_playerLocks.Count == 0)
  203. {
  204. TellClient(issuer.ClientNum, "^1[Chat Lock] ^7No players are currently chat locked", true);
  205. }
  206. else
  207. {
  208. new Thread(() => DisplayLockedPlayer(issuer)).Start();
  209. }
  210. }
  211.  
  212. /// <summary>
  213. /// Displays the players name and total time remaining one by one using the previously created thread
  214. /// </summary>
  215. /// <param name="issuer"></param>
  216. private void DisplayLockedPlayer(ServerClient issuer)
  217. {
  218. foreach (ServerClient client in GetClients())
  219. {
  220. if (!_playerLocks.ContainsKey(client.XUID)) continue;
  221.  
  222. // Get the time till the chat lock is over for the current player
  223. TimeSpan remaining = DateTime.Now - _playerLocks[client.XUID];
  224.  
  225. TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is locked for", client.Name), true);
  226. TellClient(issuer.ClientNum,
  227. string.Format("^1[Chat Lock] ^:{0} ^7hour(s) ^:{1} ^7minute(s) and ^:{2} ^7second(s)",
  228. Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes),
  229. Math.Abs(remaining.Seconds)), true);
  230.  
  231. Thread.Sleep(2000);
  232. }
  233. }
  234.  
  235. /// <summary>
  236. /// Attempts to find a client on the server based on the input value given
  237. /// </summary>
  238. /// <param name="findClient"></param>
  239. /// <returns></returns>
  240. private ServerClient FindClientByCommandInput(string findClient)
  241. {
  242. // Remove any whitespace from the string and set all the characters to lowercase
  243. findClient = findClient.ToLower().Trim();
  244.  
  245. foreach (ServerClient client in GetClients())
  246. {
  247. string clientName = client.Name.ToLower();
  248.  
  249. if (clientName == findClient || clientName.Contains(findClient) || client.XUID.ToLower() == findClient)
  250. {
  251. return client;
  252. }
  253. }
  254.  
  255. return null;
  256. }
  257.  
  258. /// <summary>
  259. /// Attempts to find a client on the server based on the input value given
  260. /// </summary>
  261. /// <param name="findClient"></param>
  262. /// <returns></returns>
  263. private ServerClient FindClientByCommandInput(int findClient)
  264. {
  265. foreach (ServerClient client in GetClients())
  266. {
  267. if (client.ClientNum == findClient)
  268. {
  269. return client;
  270. }
  271. }
  272.  
  273. return null;
  274. }
  275. }
  276. }


Credits:
@Pozzuh - For the permissions plugin
@Nukem - For such a great code base to work with

Apart from that I hope you enjoy the plugin and as always report any bugs you find.

.zip   ChatLocker-0.3.zip (Size: 4.41 KB / Downloads: 63)
.zip   aaaPermissionPlugin.zip (Size: 3.69 KB / Downloads: 21)
I now host all my MW3 projects on my private GIT repo
[-] The following 6 users say Thank You to SgtLegend for this post:
  • 8q4s8, Casper, DidUknowiPwn, Dr3am95, Nekochan, surtek
  Reply
#2
nice one! i was wonderging if it could be possible to block the server voice chat wihout changing the sv_voice, its so annoying kids speaking. Dont tell me to mute them, plz XD
  Reply
#3
(05-17-2013, 17:45)Dr3am95 Wrote: nice one! i was wonderging if it could be possible to block the server voice chat wihout changing the sv_voice, its so annoying kids speaking. Dont tell me to mute them, plz XD

not possible.
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

  Reply
#4
Released a minor updated, you can see the changes in the change log above.
I now host all my MW3 projects on my private GIT repo
  Reply
#5
It is really useful thing. Good one.
C++/Obj-C developer. Neko engine wip
Steam: Click
[-] The following 1 user says Thank You to Nekochan for this post:
  • SgtLegend
  Reply
#6
(05-18-2013, 13:32)SailorMoon Wrote: It is really useful thing. Good one.

Thanks, I just realised that I left the server message in there so no visual feedback is shown to the issuer.
I now host all my MW3 projects on my private GIT repo
  Reply
#7
I cant get it to work, i get 2 errors, The first one, the ChatPlugin gets double like before with that permission plugin, and the second one, they can speak as normal, i locked them, bu they keep speaking. Thanks
  Reply
#8
I will update the Chat Plugin tonight, as for the user been able to speak it sounds like an error is occurring. Can you please look in your addon/logs/console.log file for any errors that refer to this plugin and post them.
I now host all my MW3 projects on my private GIT repo
  Reply
#9
I tried to use this plugin in 1.4.382 version and it seems not to be working because it does not recognize the commands when i type them, i believe it has something to do with the Regex match, probably because it always returns false when it should return true.

EDIT: it is not the regex, it is because the OnSay method that has 3 parameters and in server addon 1.206 version it has only 2

EDIT2: it seems to not work as Dr3am95 said
  Reply
#10
1.4.382 of what?

Quote:EDIT: it is not the regex, it is because the OnSay method that has 3 parameters and in server addon 1.206 version it has only 2
Version 1.2 is extremely old and outdated, I would highly recommend you use 1.4 as that is what a lot of plugins are now developed for
I now host all my MW3 projects on my private GIT repo
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  how to remove commands in the chat ExoGamer* 6 1,796 07-20-2013, 09:24
Last Post: Pozzuh
  [Request] Names, Chat and Scoreboard Mibbix 6 2,065 06-21-2013, 22:16
Last Post: Mibbix
  Help Using chat outside in game Bandarigoda123 1 1,352 06-09-2013, 12:46
Last Post: Nekochan
  [Release] Chat plugin for permissions SgtLegend 9 4,880 06-01-2013, 15:02
Last Post: SgtLegend
  In game chat shanky 12 3,310 04-25-2013, 17:47
Last Post: 8q4s8
  Usual chat Arteq 11 2,075 04-14-2013, 20:48
Last Post: Arteq
  [Release] [C#] Chat server iAegle 7 5,209 04-01-2013, 14:23
Last Post: cagako85
  [Request] Chat on and chat of sleepunknot 0 843 03-25-2013, 15:27
Last Post: sleepunknot
  [Release] Chat blocker bonino33 8 3,219 11-28-2012, 00:49
Last Post: hillbilly
  Chat Message The Tronuo 8 2,069 11-12-2012, 18:05
Last Post: Nekochan

Forum Jump:


Users browsing this thread: 1 Guest(s)