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:
Code:
using Addon; using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading; namespace ChatLocker { public class ChatLocker : CPlugin { private readonly Dictionary<string, DateTime> _playerLocks = new Dictionary<string, DateTime>(); private List<string> _immunePlayers; /// <summary> /// Executes when the MW3 server loads /// </summary> public override void OnServerLoad() { ServerPrint("Chat Locker created by SgtLegend. Version 0.3"); // Get the configuration _immunePlayers = new List<string>(GetServerCFG("ChatLocker", "ImmunePlayers", "").Split(',')); } /// <summary> /// Executes when a client 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) { List<string> cmd = new List<string>(message.Split(' ')); // Check if the current player has been chat locked if (!message.StartsWith("!") && _playerLocks.ContainsKey(client.XUID)) { TimeSpan remaining = DateTime.Now - _playerLocks[client.XUID]; // If the time span is greater than the remaining time let the player know they are still chat locked if (TimeSpan.Zero > remaining) { iPrintLnBold(string.Format( "You are still chat locked for ^:{0} ^7hour(s) ^:{1} ^7minute(s) and ^:{2} ^7second(s)", Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes), Math.Abs(remaining.Seconds)), client); return ChatType.ChatNone; } // If the time span is less or equal to the remaining time remove the players current chat lock status if (TimeSpan.Zero <= remaining) { _playerLocks.Remove(client.XUID); } } // Check if the given command is associated with the Chat Locker plugin Match matches = Regex.Match(cmd[0], @"\!((?:(?:un|whos)?lock(?:ed)?)c?)", RegexOptions.IgnoreCase); if (matches.Success) { string match = matches.Groups[1].Value.ToLower(); cmd.RemoveAt(0); switch (match) { case "lock": case "lockc": LockPlayerChat(cmd, client, (match == "lockc")); break; case "unlock": case "unlockc": UnlockPlayerChat(cmd, client, (match == "unlockc")); break; case "whoslocked": FindChatLockedPlayers(client); break; } return ChatType.ChatNone; } return ChatType.ChatContinue; } /// <summary> /// Locks the given players chat for X amount of minutes /// </summary> /// <param name="cmd"></param> /// <param name="issuer"></param> /// <param name="byClientId"></param> private void LockPlayerChat(List<string> cmd, ServerClient issuer, bool byClientId) { if (cmd.Count == 0 || string.IsNullOrEmpty(cmd[0])) { TellClient(issuer.ClientNum, "^1[Chat Lock] ^7Please enter a valid player id or name", true); } else { double timeToLock = 0; if (cmd.Count < 2 || (cmd[1] != null && !double.TryParse(cmd[1], out timeToLock) && timeToLock > 0)) { TellClient(issuer.ClientNum, "^1[Chat Lock] ^7Please enter a valid number for the lock minutes", true); } else { ServerClient client = (byClientId ? FindClientByCommandInput(int.Parse(cmd[0])) : FindClientByCommandInput(cmd[0])); if (client != null) { if (_immunePlayers.Contains(client.XUID)) { TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is immune to chat locks", client.Name), true); } else if (_playerLocks.ContainsKey(client.XUID)) { TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7has already been chat locked", client.Name), true); } else { // Get the time span for the current date and the new date TimeSpan remaining = TimeSpan.FromMinutes(timeToLock); // Add the play chat lock status _playerLocks.Add(client.XUID, DateTime.Now + remaining); // Log the chat lock in the server locks and let the player know ServerPrint( string.Format( "[Chat Lock] {0} was chat locked for {1} hour(s) and {2} minute(s) by {3}", client.Name, Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes), issuer.Name)); TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7has been chat locked successfully!", client.Name), true); TellClient(client.ClientNum, string.Format( "^1[Chat Lock] ^7You have been chat locked for {0} hour(s) and {1} minute(s)", Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes)), true); } } else { TellClient(issuer.ClientNum, "^1[Chat Lock] ^7No players were found", true); } } } } /// <summary> /// Un-locks the given players chat so they can speak again /// </summary> /// <param name="cmd"></param> /// <param name="issuer"></param> /// <param name="byClientId"></param> private void UnlockPlayerChat(List<string> cmd, ServerClient issuer, bool byClientId) { if (cmd.Count == 0 || string.IsNullOrEmpty(cmd[0])) { TellClient(issuer.ClientNum, "^1[Chat Lock] ^7Please enter a valid player id or name", true); } else { ServerClient client = (byClientId ? FindClientByCommandInput(int.Parse(cmd[0])) : FindClientByCommandInput(cmd[0])); if (client != null) { if (!_playerLocks.ContainsKey(client.XUID)) { TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is not chat locked", client.Name), true); } else { _playerLocks.Remove(client.XUID); // Set the client messages TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is aloud to chat again", client.Name), true); TellClient(client.ClientNum, "^1[Chat Lock] ^7Your chat lock is now over, be good!", true); } } else { TellClient(issuer.ClientNum, "^1[Chat Lock] ^7No players were found", true); } } } /// <summary> /// Creates a new thread to start listing the chat locked players, it runs on a thread so that the chat /// doesn't get inundated with a players information /// </summary> /// <param name="issuer"></param> private void FindChatLockedPlayers(ServerClient issuer) { if (_playerLocks.Count == 0) { TellClient(issuer.ClientNum, "^1[Chat Lock] ^7No players are currently chat locked", true); } else { new Thread(() => DisplayLockedPlayer(issuer)).Start(); } } /// <summary> /// Displays the players name and total time remaining one by one using the previously created thread /// </summary> /// <param name="issuer"></param> private void DisplayLockedPlayer(ServerClient issuer) { foreach (ServerClient client in GetClients()) { if (!_playerLocks.ContainsKey(client.XUID)) continue; // Get the time till the chat lock is over for the current player TimeSpan remaining = DateTime.Now - _playerLocks[client.XUID]; TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7is locked for", client.Name), true); TellClient(issuer.ClientNum, string.Format("^1[Chat Lock] ^:{0} ^7hour(s) ^:{1} ^7minute(s) and ^:{2} ^7second(s)", Math.Abs(remaining.Hours), Math.Abs(remaining.Minutes), Math.Abs(remaining.Seconds)), true); Thread.Sleep(2000); } } /// <summary> /// Attempts to find a client on the server based on the input value given /// </summary> /// <param name="findClient"></param> /// <returns></returns> private ServerClient FindClientByCommandInput(string findClient) { // Remove any whitespace from the string and set all the characters to lowercase findClient = findClient.ToLower().Trim(); foreach (ServerClient client in GetClients()) { string clientName = client.Name.ToLower(); if (clientName == findClient || clientName.Contains(findClient) || client.XUID.ToLower() == findClient) { return client; } } return null; } /// <summary> /// Attempts to find a client on the server based on the input value given /// </summary> /// <param name="findClient"></param> /// <returns></returns> private ServerClient FindClientByCommandInput(int findClient) { foreach (ServerClient client in GetClients()) { if (client.ClientNum == findClient) { return client; } } return null; } } }

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: 102)
.zip   aaaPermissionPlugin.zip (Size: 3.69 KB / Downloads: 76)
I now host all my MW3 projects on my private GIT repo
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-Cdeveloper. Neko engine wip
Steam: Click
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 6,576 07-20-2013, 09:24
Last Post: Pozzuh
  [Request] Names, Chat and Scoreboard Mibbix 6 6,608 06-21-2013, 22:16
Last Post: Mibbix
  Help Using chat outside in game Bandarigoda123 1 4,181 06-09-2013, 12:46
Last Post: Nekochan
  [Release] Chat plugin for permissions SgtLegend 9 10,547 06-01-2013, 15:02
Last Post: SgtLegend
  In game chat shanky 12 10,281 04-25-2013, 17:47
Last Post: 8q4s8
  Usual chat Arteq 11 8,866 04-14-2013, 20:48
Last Post: Arteq
  [Release] [C#] Chat server iAegle 7 9,638 04-01-2013, 14:23
Last Post: cagako85
  [Request] Chat on and chat of sleepunknot 0 2,735 03-25-2013, 15:27
Last Post: sleepunknot
  [Release] Chat blocker bonino33 8 9,086 11-28-2012, 00:49
Last Post: hillbilly
  Chat Message The Tronuo 8 6,781 11-12-2012, 18:05
Last Post: Nekochan

Forum Jump:


Users browsing this thread:
1 Guest(s)

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