09-30-2012, 14:44
Hi
i use this plugin for maxping warn and it is worked good but A big problem this plugin also kick the protected players too.
How to set this plugin not kick The protected players?!
i use this plugin for maxping warn and it is worked good but A big problem this plugin also kick the protected players too.
How to set this plugin not kick The protected players?!
Code:
using Addon;
using System;
using System.Collections.Generic;
using System.Timers;
namespace PingWarn
{
public class PingPlugin : CPlugin
{
private Dictionary<string, DateTime> graceDictionary = new Dictionary<string, DateTime>();
private int maxGraceSeconds = 10;
private int maxPing = 200;
private int maxWarnings = 3;
private Dictionary<string, int> warnDictionary = new Dictionary<string, int>();
private string CheckSetting(string key, string value)
{
if (string.IsNullOrEmpty(GetServerCFG("PingPlugin", key, "")))
{
SetServerCFG("PingPlugin", key, value);
return value;
}
return GetServerCFG("PingPlugin", key, "");
}
private List<string> GetCommandsAllowedInGroup(string groupname)
{
List<string> list = new List<string>();
string str = GetServerCFG("Permission", groupname + "_commands", " ");
if (str != " ")
{
foreach (string str2 in str.Split(new char[] { ',' }))
{
list.Add(str2);
}
}
return list;
}
private List<string> GetUsersInGroup(string groupname)
{
List<string> list = new List<string>();
string str = GetServerCFG("Permission", groupname + "_xuids", " ");
if (str != " ")
{
foreach (string str2 in str.Split(new char[] { ',' }))
{
list.Add(str2);
}
}
return list;
}
private bool IsAdmin(string XUID)
{
List<string> list = new List<string>();
foreach (string str in GetServerCFG("Permission", "Usergroups", "").Split(new char[] { ',' }))
{
if (this.GetCommandsAllowedInGroup(str).Contains("!setmaxping") || this.GetCommandsAllowedInGroup(str).Contains("*ALL*"))
{
list.AddRange(this.GetUsersInGroup(str));
}
}
return list.Contains(XUID);
}
private void KickClient(ServerClient sc)
{
ServerCommand("kickclient " + sc.ClientNum + " \"You have been kicked for having excessive ping!\"");
iPrintLn("^2" + sc.Name + " ^7has been kicked for having excessive ping!", null);
}
public override void OnPlayerConnect(ServerClient Client)
{
if (!this.graceDictionary.ContainsKey(Client.XUID))
{
this.graceDictionary.Add(Client.XUID, DateTime.Now);
}
else
{
this.graceDictionary[Client.XUID] = DateTime.Now;
}
}
public override ChatType OnSay(string Message, ServerClient Client)
{
int num;
if (!Message.StartsWith("!setmaxping") || !this.IsAdmin(Client.XUID))
{
return ChatType.ChatContinue;
}
string[] strArray = Message.Split(new char[] { ' ' });
if ((strArray.Length > 1) && int.TryParse(strArray[1], out num))
{
this.maxPing = num;
SetServerCFG("PingPlugin", "MaxPing", this.maxPing.ToString());
}
else
{
TellClient(Client.ClientNum, "^2[PingPlugin] ^7Unable to set max ping value!", true);
}
return ChatType.ChatNone;
}
public override void OnServerLoad()
{
this.maxPing = int.Parse(this.CheckSetting("MaxPing", "200"));
this.maxWarnings = int.Parse(this.CheckSetting("MaxWarnings", "3"));
this.maxGraceSeconds = int.Parse(this.CheckSetting("MaxGraceSeconds", "10"));
Timer timer = new Timer {
Interval = int.Parse(this.CheckSetting("Interval", "20")) * 0x3e8
};
timer.Elapsed += new ElapsedEventHandler(this.timerRefresh_Elapsed);
timer.Start();
ServerPrint("Max Ping Plugin (v1.7) By master131 loaded. (Updated to V1.7 by Gravzy)");
}
private void timerRefresh_Elapsed(object sender, ElapsedEventArgs e)
{
foreach (ServerClient client in GetClients())
{
if (this.graceDictionary.ContainsKey(client.XUID))
{
DateTime time = this.graceDictionary[client.XUID];
if (((time.Subtract(DateTime.Now).TotalSeconds * -1.0) > this.maxGraceSeconds) && (client.Ping >= this.maxPing))
{
if (!this.warnDictionary.ContainsKey(client.XUID))
{
this.warnDictionary.Add(client.XUID, 1);
}
else
{
Dictionary<string, int> dictionary;
string str;
(dictionary = this.warnDictionary)[str = client.XUID] = dictionary[str] + 1;
}
if (this.warnDictionary[client.XUID] == this.maxWarnings)
{
this.KickClient(client);
this.warnDictionary[client.XUID] = 0;
}
else
{
this.WarnClient(client);
}
}
}
}
}
private void WarnClient(ServerClient sc)
{
iPrintLn(string.Concat(new object[] { "^1WARNING: ^7Your ping is too high! Maximum allowed is ", this.maxPing, "ms. (", this.warnDictionary[sc.XUID], "/", this.maxWarnings, ")" }), sc);
}
}
}

![[Image: back_us_button.png]](http://static.squarespace.com/static/51cca4bae4b0bf9a1f4deb75/t/52ea6a9ee4b0f767960f8c35/1390493521990/back_us_button.png)