• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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?!

CSHARP Code
  1. using Addon;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Timers;
  5.  
  6. namespace PingWarn
  7. {
  8. public class PingPlugin : CPlugin
  9. {
  10. private Dictionary<string, DateTime> graceDictionary = new Dictionary<string, DateTime>();
  11. private int maxGraceSeconds = 10;
  12. private int maxPing = 200;
  13. private int maxWarnings = 3;
  14. private Dictionary<string, int> warnDictionary = new Dictionary<string, int>();
  15.  
  16. private string CheckSetting(string key, string value)
  17. {
  18. if (string.IsNullOrEmpty(GetServerCFG("PingPlugin", key, "")))
  19. {
  20. SetServerCFG("PingPlugin", key, value);
  21. return value;
  22. }
  23. return GetServerCFG("PingPlugin", key, "");
  24. }
  25.  
  26. private List<string> GetCommandsAllowedInGroup(string groupname)
  27. {
  28. List<string> list = new List<string>();
  29. string str = GetServerCFG("Permission", groupname + "_commands", " ");
  30. if (str != " ")
  31. {
  32. foreach (string str2 in str.Split(new char[] { ',' }))
  33. {
  34. list.Add(str2);
  35. }
  36. }
  37. return list;
  38. }
  39.  
  40. private List<string> GetUsersInGroup(string groupname)
  41. {
  42. List<string> list = new List<string>();
  43. string str = GetServerCFG("Permission", groupname + "_xuids", " ");
  44. if (str != " ")
  45. {
  46. foreach (string str2 in str.Split(new char[] { ',' }))
  47. {
  48. list.Add(str2);
  49. }
  50. }
  51. return list;
  52. }
  53.  
  54. private bool IsAdmin(string XUID)
  55. {
  56. List<string> list = new List<string>();
  57. foreach (string str in GetServerCFG("Permission", "Usergroups", "").Split(new char[] { ',' }))
  58. {
  59. if (this.GetCommandsAllowedInGroup(str).Contains("!setmaxping") || this.GetCommandsAllowedInGroup(str).Contains("*ALL*"))
  60. {
  61. list.AddRange(this.GetUsersInGroup(str));
  62. }
  63. }
  64. return list.Contains(XUID);
  65. }
  66.  
  67. private void KickClient(ServerClient sc)
  68. {
  69. ServerCommand("kickclient " + sc.ClientNum + " \"You have been kicked for having excessive ping!\"");
  70. iPrintLn("^2" + sc.Name + " ^7has been kicked for having excessive ping!", null);
  71. }
  72.  
  73. public override void OnPlayerConnect(ServerClient Client)
  74. {
  75. if (!this.graceDictionary.ContainsKey(Client.XUID))
  76. {
  77. this.graceDictionary.Add(Client.XUID, DateTime.Now);
  78. }
  79. else
  80. {
  81. this.graceDictionary[Client.XUID] = DateTime.Now;
  82. }
  83. }
  84.  
  85. public override ChatType OnSay(string Message, ServerClient Client)
  86. {
  87. int num;
  88. if (!Message.StartsWith("!setmaxping") || !this.IsAdmin(Client.XUID))
  89. {
  90. return ChatType.ChatContinue;
  91. }
  92. string[] strArray = Message.Split(new char[] { ' ' });
  93. if ((strArray.Length > 1) && int.TryParse(strArray[1], out num))
  94. {
  95. this.maxPing = num;
  96. SetServerCFG("PingPlugin", "MaxPing", this.maxPing.ToString());
  97. }
  98. else
  99. {
  100. TellClient(Client.ClientNum, "^2[PingPlugin] ^7Unable to set max ping value!", true);
  101. }
  102. return ChatType.ChatNone;
  103. }
  104.  
  105. public override void OnServerLoad()
  106. {
  107. this.maxPing = int.Parse(this.CheckSetting("MaxPing", "200"));
  108. this.maxWarnings = int.Parse(this.CheckSetting("MaxWarnings", "3"));
  109. this.maxGraceSeconds = int.Parse(this.CheckSetting("MaxGraceSeconds", "10"));
  110. Timer timer = new Timer {
  111. Interval = int.Parse(this.CheckSetting("Interval", "20")) * 0x3e8
  112. };
  113. timer.Elapsed += new ElapsedEventHandler(this.timerRefresh_Elapsed);
  114. timer.Start();
  115. ServerPrint("Max Ping Plugin (v1.7) By master131 loaded. (Updated to V1.7 by Gravzy)");
  116. }
  117.  
  118. private void timerRefresh_Elapsed(object sender, ElapsedEventArgs e)
  119. {
  120. foreach (ServerClient client in GetClients())
  121. {
  122. if (this.graceDictionary.ContainsKey(client.XUID))
  123. {
  124. DateTime time = this.graceDictionary[client.XUID];
  125. if (((time.Subtract(DateTime.Now).TotalSeconds * -1.0) > this.maxGraceSeconds) && (client.Ping >= this.maxPing))
  126. {
  127. if (!this.warnDictionary.ContainsKey(client.XUID))
  128. {
  129. this.warnDictionary.Add(client.XUID, 1);
  130. }
  131. else
  132. {
  133. Dictionary<string, int> dictionary;
  134. string str;
  135. (dictionary = this.warnDictionary)[str = client.XUID] = dictionary[str] + 1;
  136. }
  137. if (this.warnDictionary[client.XUID] == this.maxWarnings)
  138. {
  139. this.KickClient(client);
  140. this.warnDictionary[client.XUID] = 0;
  141. }
  142. else
  143. {
  144. this.WarnClient(client);
  145. }
  146. }
  147. }
  148. }
  149. }
  150.  
  151. private void WarnClient(ServerClient sc)
  152. {
  153. iPrintLn(string.Concat(new object[] { "^1WARNING: ^7Your ping is too high! Maximum allowed is ", this.maxPing, "ms. (", this.warnDictionary[sc.XUID], "/", this.maxWarnings, ")" }), sc);
  154. }
  155. }
  156. }
  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)
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using Addon;
  4.  
  5. namespace Ping
  6. {
  7. public class Class1:CPlugin
  8. {
  9. System.Diagnostics.Stopwatch Time;
  10. int Seconds = 10;
  11. bool Permission = false;
  12. List<string> ProtectedXuid = new List<string>();
  13. public override void OnServerLoad()
  14. {
  15. Time = new System.Diagnostics.Stopwatch();
  16. ServerPrint("Ping plugin by Archit loaded!");
  17. Time.Start();
  18. Permission = bool.Parse(GetServerCFG("Ping", "UsePermission", "false"));
  19. if (Permission)
  20. {
  21. ProtectedXuid.AddRange(GetServerCFG("Permission",GetServerCFG("Ping","ProtectedXuidKey","Admin_xuids"),string.Empty).Split(new string[]{" ",","},StringSplitOptions.None));
  22. }
  23. Seconds=int.Parse(GetServerCFG("Ping", "Re-Check", "10"));
  24. }
  25.  
  26. Dictionary<int, int> Warns = new Dictionary<int, int>();
  27. public override void OnPlayerDisconnect(ServerClient Client)
  28. {
  29. if (Warns.ContainsKey(Client.ClientNum))
  30. {
  31. Warns.Remove(Client.ClientNum);
  32. }
  33. }
  34. public override ChatType OnSay(string Message, ServerClient Client,bool TeamChat)
  35. {
  36. if (Message.ToLower().StartsWith("!setmaxping") && ProtectedXuid.Contains(Client.XUID))
  37. {
  38. SetServerCFG("Ping", "MaxPing", Message.Split(' ')[1]);
  39. TellClient(Client.ClientNum, "Max ping set to " + Message.Split(' ')[1], true);
  40. return ChatType.ChatNone;
  41. }
  42. else if (Message.ToLower().StartsWith("!setmaxping") && !ProtectedXuid.Contains(Client.XUID))
  43. {
  44. TellClient(Client.ClientNum, "Error:You don't have permission to do that!", true);
  45. return ChatType.ChatNone;
  46. }
  47. else
  48. {
  49. return ChatType.ChatContinue;
  50. }
  51. }
  52. public override void OnServerFrame()
  53. {
  54. if (GetClients() != null && Time.Elapsed.Seconds == Seconds)
  55. {
  56. Time.Reset();
  57. Time.Start();
  58. foreach (ServerClient Client in GetClients())
  59. {
  60. if (Client.Ping > int.Parse(GetServerCFG("Ping", "MaxPing", "300")))
  61. {
  62. if (!Warns.ContainsKey(Client.ClientNum))
  63. {
  64. Warns.Add(Client.ClientNum, 1);
  65. }
  66. else if (Warns.ContainsKey(Client.ClientNum) && Warns[Client.ClientNum] != int.Parse(GetServerCFG("Ping", "MaxWarns", "5")))
  67. {
  68. Warns[Client.ClientNum]++;
  69. TellClient(Client.ClientNum, "Reduce your ping else you will be kicked", true);
  70. }
  71. else if (Warns[Client.ClientNum] == int.Parse(GetServerCFG("Ping", "MaxWarns", "5"))&&Permission&&!ProtectedXuid.Contains(Client.XUID))
  72. {
  73. ServerCommand("dropclient " + Client.ClientNum + " \"You have been kicked because of excess ping\"");
  74. Warns.Remove(Client.ClientNum);
  75. }
  76.  
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }

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
[-] The following 1 user says Thank You to archit for this post:
  • raminr63
  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 1,646 09-12-2013, 17:32
Last Post: Yamato
  [Release] Ping Warn Plugin v1.1 master131 28 13,405 07-10-2013, 09:34
Last Post: spike17
  Players alive on hud spiderabd11 5 1,468 01-06-2013, 18:50
Last Post: DidUknowiPwn
  ping warn 1.1, I passed from the server kpoviv 1 900 12-13-2012, 09:47
Last Post: XxBRxX
Sad [HELP]- fs_game is write protected DriesHard 9 3,409 10-06-2012, 17:01
Last Post: surtek
  Help problem in warn code!! raminr63 3 945 09-29-2012, 22:52
Last Post: raminr63
Tongue Weapon Remover For Players downy 3 1,002 09-11-2012, 20:32
Last Post: JariZ
  looking for black ops zombie players kokole 12 1,797 08-26-2012, 21:14
Last Post: kokole
  more than 18 players ryan2pro 10 1,917 07-02-2012, 01:16
Last Post: estebespt
  [Request] Players join as Axis DidUknowiPwn 11 2,076 04-24-2012, 20:41
Last Post: DidUknowiPwn

Forum Jump:


Users browsing this thread: 1 Guest(s)