03-27-2012, 18:00
As requested a plugin against name changers. It checks every 4-12 seconds if a player changed his name. When he did it a specific time an action will be taken.
Requires @Nukem's Server Addon 1.290+
sv_config.ini entries:
Source code
Requires @Nukem's Server Addon 1.290+
sv_config.ini entries:
Code:
[NameChange]
//After how many name changes action should be taken
Changes=3
//Which action should be taken (kickClient, tempbanClient, banClient)
Command=kickClient
//Message to be displayed on server when an action is being taken, valid placeholder {0} = last name {1} = xuid
//Example: Player {0} with the XUID {1} has been kicked
ServerMsg=
//Reason for action (displayed to the client when action is being taken)
CommandMsg=
Source code
CSHARP Code
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Addon;
- using System.Threading;
-
- namespace AntiNameChanger
- {
- public class Class1 : CPlugin
- {
- //Store old names
- //Store name changes
- //How many changes to take action
- int Changes = 3;
- string command = "kickClient";
- string commandMsg = string.Empty;
- string srvMsg = string.Empty;
- public override void OnFastRestart()
- {
- OnMapChange();
- }
- public override void OnMapChange()
- {
- OldNames.Clear();
- NameChanges.Clear();
- }
- public override void OnServerLoad()
- {
- try
- {
- ServerPrint("\n AntiNameChanger loaded \n Author: zxz0O0 \n Thanks to Nukem, Jariz and Pozzuh\n");
- ServerPrint(" youtube.com/zxz0O0 \n itsmods.com\n");
-
- Changes = int.Parse(GetServerCFG("NameChange", "Changes", "3"));
- command = GetServerCFG("NameChange", "Command", "kickClient");
- srvMsg = GetServerCFG("NameChange", "ServerMsg", string.Empty);
- }
- catch (Exception e)
- {
- ServerPrint(e.Message);
- }
- }
-
- private void CheckWorker(object o)
- {
- while (true)
- {
- int q = i.Next(0, 80);
- Thread.Sleep(4000 + q*100);
- CheckNames();
- }
- }
-
- private void CheckNames()
- {
- try
- {
- foreach (ServerClient c in GetClients())
- {
- //If player is already registred
- if (OldNames.ContainsKey(c.XUID))
- {
- //If name didn't change
- if (OldNames[c.XUID] == c.Name)
- continue;
- //Else add to NameChanges int
- else
- {
- //If already stored increase value
- if (NameChanges.ContainsKey(c.XUID))
- NameChanges[c.XUID]++;
- else
- NameChanges.Add(c.XUID, 1);
- //Store new name again
- OldNames[c.XUID] = c.Name;
- //Check if action should be taken
- if (Changes <= NameChanges[c.XUID])
- {
- if (!string.IsNullOrEmpty(srvMsg))
- ServerSay(string.Format(srvMsg, c.Name, c.XUID), false);
-
- ServerPrint("AntiNameChanger executed: " + command + " " + c.ClientNum + " \"" + commandMsg + "\"");
- ServerPrint("AntiNameChanger Last Name: " + c.Name);
- ServerCommand(command + " " + c.ClientNum + " \"" + commandMsg + "\"");
- }
- }
- }
- else
- OldNames.Add(c.XUID, c.Name);
- }
- }
- catch (Exception e)
- {
- ServerPrint(e.Message);
- }
- }
- }
- }