Add protected players to Maxping warn
#1
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?!

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); } } }
Reply

#2
add a boolean flag and add players to a list or something in sv_Config. in the warn and kicking part make it only warn and kick when the flag is false. for each player in the list , flag is true.
therefore it does'nt kick or warn protected XUIDs.
Reply

#3
i have some problem with that may i request you, do that for me Big Grin
Reply

#4
Hi @archit

Pleas do something again i need your help Big Grin

Thank you.
Reply

#5
Why such a complicated code.
(This from my ping block plugin)
Code:
using System; using System.Collections.Generic; using Addon; namespace Ping { public class Class1:CPlugin { System.Diagnostics.Stopwatch Time; int Seconds = 10; bool Permission = false; List<string> ProtectedXuid = new List<string>(); public override void OnServerLoad() { Time = new System.Diagnostics.Stopwatch(); ServerPrint("Ping plugin by Archit loaded!"); Time.Start(); Permission = bool.Parse(GetServerCFG("Ping", "UsePermission", "false")); if (Permission) { ProtectedXuid.AddRange(GetServerCFG("Permission",GetServerCFG("Ping","ProtectedXuidKey","Admin_xuids"),string.Empty).Split(new string[]{" ",","},StringSplitOptions.None)); } Seconds=int.Parse(GetServerCFG("Ping", "Re-Check", "10")); } Dictionary<int, int> Warns = new Dictionary<int, int>(); public override void OnPlayerDisconnect(ServerClient Client) { if (Warns.ContainsKey(Client.ClientNum)) { Warns.Remove(Client.ClientNum); } } public override ChatType OnSay(string Message, ServerClient Client,bool TeamChat) { if (Message.ToLower().StartsWith("!setmaxping") && ProtectedXuid.Contains(Client.XUID)) { SetServerCFG("Ping", "MaxPing", Message.Split(' ')[1]); TellClient(Client.ClientNum, "Max ping set to " + Message.Split(' ')[1], true); return ChatType.ChatNone; } else if (Message.ToLower().StartsWith("!setmaxping") && !ProtectedXuid.Contains(Client.XUID)) { TellClient(Client.ClientNum, "Error:You don't have permission to do that!", true); return ChatType.ChatNone; } else { return ChatType.ChatContinue; } } public override void OnServerFrame() { if (GetClients() != null && Time.Elapsed.Seconds == Seconds) { Time.Reset(); Time.Start(); foreach (ServerClient Client in GetClients()) { if (Client.Ping > int.Parse(GetServerCFG("Ping", "MaxPing", "300"))) { if (!Warns.ContainsKey(Client.ClientNum)) { Warns.Add(Client.ClientNum, 1); } else if (Warns.ContainsKey(Client.ClientNum) && Warns[Client.ClientNum] != int.Parse(GetServerCFG("Ping", "MaxWarns", "5"))) { Warns[Client.ClientNum]++; TellClient(Client.ClientNum, "Reduce your ping else you will be kicked", true); } else if (Warns[Client.ClientNum] == int.Parse(GetServerCFG("Ping", "MaxWarns", "5"))&&Permission&&!ProtectedXuid.Contains(Client.XUID)) { ServerCommand("dropclient " + Client.ClientNum + " \"You have been kicked because of excess ping\""); Warns.Remove(Client.ClientNum); } } } } } } }
Let me know if it works, I will update main post
Add to sv_config.ini
Code:
[Ping] Re-Check=5 //seconds after which ping is checked again MaxPing=200 //Ping limit MaxWarns=5 //Number of warnings followed by a kick UsePermission=true //true or false using permission plugin ProtectedXuidKey=moderator_xuids //key of protected xuids in permission plugin
Reply

#6
thank you i will test that.(and i like your programing :d)
Reply

#7
Hi archit

sorry for last some days i am really busy so today i opportunity to check your code but unfortunately i must say this plugin not work at all.

look the plugin code i posted in first post work very well but i need protect my protected player from ping warn massage and ping warn kick. so if possible for you just pleas add a protect checker for that. i think its will be nice plugin for PingWarn.

And i must say my protected players is listed in this file (" Protectplayers ") with this address:

plugins\AdminPlug\Protectplayers

with this format:

Xuid ----------- Id
11000010002eefd -d(-_-)b-
011000010002eef5 LoLinga


thank you for good helping.
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Help choose 2 random players?(1 each team) 26hz 6 6,280 09-12-2013, 17:32
Last Post: Yamato
  [Release] Ping Warn Plugin v1.1 master131 28 29,328 07-10-2013, 09:34
Last Post: spike17
  Players alive on hud spiderabd11 5 5,358 01-06-2013, 18:50
Last Post: DidUknowiPwn
  ping warn 1.1, I passed from the server kpoviv 1 3,203 12-13-2012, 09:47
Last Post: XxBRxX
Sad [HELP]- fs_game is write protected DriesHard 9 10,114 10-06-2012, 17:01
Last Post: surtek
  Help problem in warn code!! raminr63 3 3,692 09-29-2012, 22:52
Last Post: raminr63
Tongue Weapon Remover For Players downy 3 4,439 09-11-2012, 20:32
Last Post: JariZ
  looking for black ops zombie players kokole 12 9,070 08-26-2012, 21:14
Last Post: kokole
  more than 18 players ryan2pro 10 8,635 07-02-2012, 01:16
Last Post: estebespt
  [Request] Players join as Axis DidUknowiPwn 11 8,790 04-24-2012, 20:41
Last Post: DidUknowiPwn

Forum Jump:


Users browsing this thread:
1 Guest(s)

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