08-05-2015, 10:49
ENG Text (Click to View)
Hello everyone! And you would like to block the chat for some players?
If Yes, this is possible!
P.S. If you use the plugin "Permissions" and blocked the chat of the player in the group "USER", then the person is free to write in chat. Make another group for casual players
If Yes, this is possible!
P.S. If you use the plugin "Permissions" and blocked the chat of the player in the group "USER", then the person is free to write in chat. Make another group for casual players
RUS Text (Click to View)
! ?
, !
P.S. "Permissions" "USER", .
, !
P.S. "Permissions" "USER", .
Source code
PHP Code:
using System;
using Addon;
using System.IO;
using System.Collections.Generic;
namespace SC
{
public class BlockChat : CPlugin
{
string Chat = "plugins\\chatblocked.txt";
string Chat2;
public override void OnServerLoad()
{
ServerPrint("BlockerChat by S3VDIT0");
Chat2 = GetServerCFG("ServerControl", "BannedChatPlayerMess", "^2 !");
}
public override ChatType OnSay(string Message, ServerClient Client)
{
string[] parsed = Message.Split(null as char[], StringSplitOptions.RemoveEmptyEntries);
if (BlockedXUIDs(Client) == Client.XUID)
{
TellClient(Client.ClientNum, Chat2, true);
return ChatType.ChatNone;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (Message.StartsWith("!block") || Message.StartsWith("!b"))
{
if (parsed.Length > 1)
{
ServerClient client = findClient(parsed[1]);
if (client != null)
{
ServerClient client2 = findClient(parsed[1]);
using (StreamWriter writer = new StreamWriter(Chat, true))
{
writer.WriteLine(client2.XUID.ToLower());
}
String block = GetServerCFG("ServerControl", "SayCB", "^2 ^7<playername> ^2 !");
block = block.Replace("<playername>", client2.Name);
ServerSay(block, true);
return ChatType.ChatNone;
}
if (client == null)
{
TellClient(Client.ClientNum, "^1 !", true);
return ChatType.ChatNone;
}
}
else
{
TellClient(Client.ClientNum, "^7: ^2!block/!b ^7<playername>", true);
}
return ChatType.ChatNone;
}
/////////////////////////////////////////////////////////////////////////////////////////
return ChatType.ChatContinue;
}
public string BlockedXUIDs(ServerClient Client)
{
List<string> XUID = new List<string>(File.ReadAllLines(Chat));
for (int i = 0; i < XUID.Count; i++)
{
string line = XUID[i];
string CX = XUID[i];
if (CX == Client.XUID)
{
return CX;
}
}
return null;
}
//FindClient
public ServerClient findClient(String clientName)
{
clientName = clientName.Trim();
int clientCount = 0;
ServerClient client = null;
List<ServerClient> clientList = GetClients();
foreach (ServerClient currClient in clientList)
{
if (0 <= currClient.Name.IndexOf(clientName, StringComparison.InvariantCultureIgnoreCase))
{
client = currClient;
clientCount++;
}
}
if (clientCount > 1)
{
return null;
}
else if (clientCount == 1)
{
return client;
}
return null;
}
}
}
Credits:
@S3VDIT0 - Made the plugin
@frst_ - Special thanks