This is like BadPing plugin by @JariZ however this one is tested and working.
Settings: (sv_config.ini)
MaxPing - The maximum ping allowed on the server. (default value is 200)
MaxWarnings - The maximum amount of warnings allowed before the player is kicked. (default value is 3)
Interval - How often (in seconds) to check every player's ping. (default value is 20)
MaxGraceSeconds - The maximum of seconds to ignore a player's ping after they've joined the game. (default value is 10).
Commands:
!setmaxping <value> - Sets the maximum ping allowed.
- You can add more commands using the source, I'm busy with other stuffs at the moment.
In order to use the text commands, you will Pozzuh's Permission Plugin and have to add !setmaxping to the allowed commands list. Alternatively, you can copy and paste this into your config if you don't want to use the permission plugin:
Source:
Credits:
@JariZ - Base/concept of plugin.
@Pozzuh - Permission plugin.
Settings: (sv_config.ini)
MaxPing - The maximum ping allowed on the server. (default value is 200)
MaxWarnings - The maximum amount of warnings allowed before the player is kicked. (default value is 3)
Interval - How often (in seconds) to check every player's ping. (default value is 20)
MaxGraceSeconds - The maximum of seconds to ignore a player's ping after they've joined the game. (default value is 10).
Commands:
!setmaxping <value> - Sets the maximum ping allowed.
- You can add more commands using the source, I'm busy with other stuffs at the moment.
In order to use the text commands, you will Pozzuh's Permission Plugin and have to add !setmaxping to the allowed commands list. Alternatively, you can copy and paste this into your config if you don't want to use the permission plugin:
Code:
[Permission]
//You can add more user groups here
Usergroups=Admin
//Add admin xuids here (Use the status command in console to obtain XUIDs)
Admin_xuids=xuid1,xuid2,xuid3
//Admins can use all commands (Do not change!).
Admin_commands=*ALL*
Source:
CSHARP Code
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Timers;
- using Addon;
-
- namespace PingWarn
- {
- public class PingPlugin : CPlugin
- {
- int maxPing = 200;
- int maxWarnings = 3;
- int maxGraceSeconds = 10;
-
-
- public override void OnServerLoad()
- {
- maxPing = int.Parse(CheckSetting("MaxPing", "200"));
- maxWarnings = int.Parse(CheckSetting("MaxWarnings", "3"));
- maxGraceSeconds = int.Parse(CheckSetting("MaxGraceSeconds", "10"));
-
- timerRefresh.Interval = int.Parse(CheckSetting("Interval", "20")) * 1000;
- timerRefresh.Start();
- }
-
- public override ChatType OnSay(string Message, ServerClient Client)
- {
- if (Message.StartsWith("!setmaxping") && IsAdmin(Client.XUID))
- {
- string[] command = Message.Split(' ');
- int desiredMaxPing;
-
- if (command.Length > 1 && int.TryParse(command[1], out desiredMaxPing))
- {
- maxPing = desiredMaxPing;
- SetServerCFG("PingPlugin", "MaxPing", maxPing.ToString());
- }
- else
- TellClient(Client.ClientNum, "^2[PingPlugin] ^7Unable to set max ping value!", true);
-
- return ChatType.ChatNone;
- }
-
- return ChatType.ChatContinue;
- }
-
- List<string> GetCommandsAllowedInGroup(string groupname)
- {
-
- string group_string = GetServerCFG("Permission", groupname + "_commands", " ");
-
- if (group_string != " ")
- foreach (string cmd in group_string.Split(','))
- group.Add(cmd);
-
- return group;
- }
-
- List<string> GetUsersInGroup(string groupname)
- {
-
- string group_string = GetServerCFG("Permission", groupname + "_xuids", " ");
-
- if (group_string != " ")
- foreach (string xuid in group_string.Split(','))
- group.Add(xuid);
-
- return group;
- }
-
- bool IsAdmin(string XUID)
- {
- foreach (string usergroup in GetServerCFG("Permission", "Usergroups", "").Split(','))
- if (GetCommandsAllowedInGroup(usergroup).Contains("!setmaxping") || GetCommandsAllowedInGroup(usergroup).Contains("*ALL*"))
- XUIDList.AddRange(GetUsersInGroup(usergroup));
-
- return XUIDList.Contains(XUID);
- }
-
- public override void OnPlayerConnect(ServerClient Client)
- {
- if (!graceDictionary.ContainsKey(Client.XUID))
- graceDictionary.Add(Client.XUID, DateTime.Now);
- else
- graceDictionary[Client.XUID] = DateTime.Now;
- }
-
- string CheckSetting(string key, string value)
- {
- if (string.IsNullOrEmpty(GetServerCFG("PingPlugin", key, "")))
- {
- SetServerCFG("PingPlugin", key, value);
- return value;
- }
-
- return GetServerCFG("PingPlugin", key, "");
- }
-
- void timerRefresh_Elapsed(object sender, ElapsedEventArgs e)
- {
- foreach(ServerClient sc in GetClients())
- {
- if (!graceDictionary.ContainsKey(sc.XUID))
- continue;
-
- if (graceDictionary[sc.XUID].Subtract(DateTime.Now).TotalSeconds * -1 > maxGraceSeconds && sc.Ping >= maxPing)
- {
- if(!warnDictionary.ContainsKey(sc.XUID))
- warnDictionary.Add(sc.XUID, 1);
- else
- warnDictionary[sc.XUID]++;
-
- if (warnDictionary[sc.XUID] == maxWarnings)
- {
- KickClient(sc);
- warnDictionary[sc.XUID] = 0;
- }
- else
- WarnClient(sc);
- }
- }
- }
-
- void KickClient(ServerClient sc)
- {
- ServerCommand("kickclient " + sc.ClientNum + " \"You have been kicked for having excessive ping!\"");
- ServerSay("^2" + sc.Name + " ^7has been kicked for having excessive ping!", true);
- }
-
- void WarnClient(ServerClient sc)
- {
- iPrintLn("^1WARNING: ^7Your ping is too high! Maximum allowed is " + maxPing + "ms. (" + warnDictionary[sc.XUID] + "/" + maxWarnings + ")", sc);
- ServerSay("^1WARNING: ^2" + sc.Name + "^7's ping is too high, maximum allowed is " + maxPing + "ms! (" + warnDictionary[sc.XUID] + "/" + maxWarnings + ")", true);
- }
- }
- }
Credits:
@JariZ - Base/concept of plugin.
@Pozzuh - Permission plugin.
A casual conversation between barata and I about Nukem.