• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release AntiVoteAbuse
#1
Hello,

As requested in this thread [Request] Anti Vote-Abuse , i made this plugin.

Features
- Set a minimum interval between 2 allowed votes.
- Choose if the plugin affect only the vote-kick or all the vote types.
- Choose if Moderators from Permission plugin are immunized (for "kick" votes)
- Add a list of Immunized players (xuids)
- Set the number of warns before vote-ban a player (vote-ban = the player can no more vote on the server)
- Set the text of the displayed messages (Warn message, Ban message, Try to Kick Admin message, Try to Kick Immunized message)
- type "!vi playername" in the chat to add playername to the immunized list.

Installation:
- Extract the zip file attached.
- Put the .dll in the plugin folder.
- Add the lines below in the "sv_config.ini": (showed as csharp to keep correct lines (txt = long lines showed in multiple lines))
CSHARP Code
  1. [AntiVoteAbuse]
  2. Vote_Interval=60
  3. // Minimum time in seconds between 2 votes // No interval for admins <img src="https://www.itsmods.com/forum/images/smilies/wink.gif" alt="Wink" title="Wink" class="smilie smilie_2" />
  4. Vote_Kick_Only=0
  5. // 0 = all the vote types, 1 = only votekick affected
  6. Immunize_Moderators=1
  7. // 1 = The moderators from permission plugin will be vote-kick immunized, 0 = not
  8. Immunized_Xuids=xuid_1,xuid_2,xuid_3
  9. // A list of Immunized players xuids separated by comas
  10. Warns_Nbr=3
  11. // Maximum number of warn before vote-ban a player
  12. Ban_Message=^1You have been vote banned! You can no more vote on this server!
  13. // The message that will be displayed to players when they get vote-banned
  14. Warn_Message=^1No spam vote!!! @[email protected] more spam in the interval of @[email protected] seconds = Vote Banned!
  15. // The message that will be displayed to players when they get vote-warned, (don't forget to keep the @[email protected] and the @[email protected] tokens if you want them to be displayed in the message...)
  16. Try_Admin_Kick_Message=^1Don't try to kick an admin!!! @[email protected] more in the interval of @[email protected] seconds = Vote Banned!
  17. // The message that will be displayed to players when they try to kick an admin
  18. Try_Immunized_Kick_Message=^1Don't try to kick an immunized player (@[email protected])!!! @[email protected] more in the interval of @[email protected] seconds = Vote Banned!
  19. // The message that will be displayed to players when they try to kick an immunized player


Csharp source code:
CSHARP Code
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Addon;
  6.  
  7. namespace AntiVoteAbuse
  8. {
  9. public class AntiVoteAbuse : CPlugin
  10. {
  11. //* Attributs
  12. // Store the datetime of the latest vote of each players
  13. private DateTime[] Players_Last_Vote = new DateTime[18];
  14.  
  15. // Store the admins xuids
  16. private ArrayList Admins = new ArrayList();
  17.  
  18. // Store the xuids of the immunized players
  19. private ArrayList Immunized_Xuids = new ArrayList();
  20.  
  21. // Store the players that can no more use vote
  22. private ArrayList Players_No_Vote = new ArrayList();
  23.  
  24. // Store the players vote spam ticks
  25. private int[] Players_Spam_Vote_Ticks = new int[18];
  26.  
  27. // Minimum time in seconds between 2 votes ( No interval for admins yeahhh )
  28. private int Vote_Interval = 60;
  29.  
  30. // Maximum number of warn before vote-ban a player
  31. private int Warns_Nbr = 3;
  32.  
  33. // Vote-ban message
  34. private string Ban_Message = "^1You have been vote banned! You can no more vote on this server!";
  35.  
  36. // Vote-warn message
  37. private string Warn_Message = "^1No spam vote!!! @[email protected] more spam in the interval of @[email protected] seconds = Vote Banned!";
  38.  
  39. // Vote-warn "try to kick an admin" message
  40. private string Admin_Kick_Message = "^1Don't try to kick an admin!!! @[email protected] more in the interval of @[email protected] seconds = Vote Banned!";
  41.  
  42. // Vote-warn "try to kick an immunized player" message
  43. private string Immunized_Kick_Message = "^1Don't try to kick an immunized player (@[email protected])!!! @[email protected] more in the interval of @[email protected] seconds = Vote Banned!";
  44.  
  45. // Vote type affected, 0 = all, 1 = votekick only
  46. private int Vote_Kick_Only = 0;
  47.  
  48. //* Functions
  49. // OnServerLoad
  50. public override void OnServerLoad()
  51. {
  52. try
  53. {
  54. // Get the admins xuids from permission plugin
  55. string[] get_admins = GetServerCFG("Permission", "Admin_xuids", "").Split(',');
  56.  
  57. // Loop the admins to add them to the list
  58. foreach (string admin in get_admins)
  59. {
  60. this.Admins.Add(admin);
  61. }
  62.  
  63. // Get if the mods of permission plugin are immunized
  64. int Immunize_Moderators = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Immunize_Moderators", "1"));
  65. if (Immunize_Moderators == 1)
  66. {
  67. // Get the moderators xuids from permission plugin
  68. string[] get_moderators = GetServerCFG("Permission", "Moderator_xuids", "").Split(',');
  69. // Loop the admins and add them to the list
  70. foreach (string moderator in get_moderators)
  71. {
  72. this.Immunized_Xuids.Add(moderator);
  73. }
  74. }
  75.  
  76. // Get the immunized players xuids
  77. string[] get_immunized_xuids = GetServerCFG("AntiVoteAbuse", "Immunized_Xuids", "").Split(',');
  78. // loop the immunized players xuids and add them to the list
  79. foreach (string xuid in get_immunized_xuids)
  80. {
  81. this.Immunized_Xuids.Add(xuid);
  82. }
  83.  
  84. // Get the Interval between 2 votes
  85. this.Vote_Interval = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Vote_Interval", "60"));
  86.  
  87. // Get the number of warn before vote-ban a player
  88. this.Warns_Nbr = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Warns_Nbr", "3"));
  89.  
  90. // Get the vote-ban message
  91. this.Ban_Message = GetServerCFG("AntiVoteAbuse", "Ban_Message", "^1You have been vote banned! You can no more vote on this server!");
  92.  
  93. // Get the vote-warn message
  94. this.Warn_Message = GetServerCFG("AntiVoteAbuse", "Warn_Message", "^1No spam vote!!! @[email protected] more spam in the interval of @[email protected] seconds = Vote Banned!");
  95.  
  96. // Get the try to kick an admin message
  97. this.Admin_Kick_Message = GetServerCFG("AntiVoteAbuse", "Try_Admin_Kick_Message", "^1Don't try to kick an admin!!! @[email protected] more in the interval of @[email protected] seconds = Vote Banned!");
  98.  
  99. // Get the try to kick an immunized player message
  100. this.Immunized_Kick_Message = GetServerCFG("AntiVoteAbuse", "Try_Immunized_Kick_Message", "^1Don't try to kick an immunized player (@[email protected])!!! @[email protected] more in the interval of @[email protected] seconds = Vote Banned!");
  101.  
  102. // Get the vote type affected
  103. this.Vote_Kick_Only = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Vote_Kick_Only", "0"));
  104.  
  105. // Indicate that the plugin is loaded.
  106. ServerPrint("Plugin AntiVoteAbuse loaded! Author: Narkos");
  107. }
  108. catch(Exception e)
  109. {
  110. ServerPrint("Plugin AntiVoteAbuse: OnServerLoad catched exception: " + e.Message);
  111. }
  112. }
  113.  
  114. // OnPlayerConnect
  115. public override void OnPlayerConnect(ServerClient Client)
  116. {
  117. try
  118. {
  119. // Set the Players_Last_Vote of the player (Connecting to the server is like doing a vote, you have to wait an interval to be able to vote)
  120. this.Players_Last_Vote[Client.ClientNum] = DateTime.Now;
  121. }
  122. catch(Exception e)
  123. {
  124. ServerPrint("Plugin AntiVoteAbuse: OnPlayerConnect catched exception: " + e.Message);
  125. }
  126. }
  127.  
  128. // OnPlayerDisconnect
  129. public override void OnPlayerDisconnect(ServerClient Client)
  130. {
  131. try
  132. {
  133. // Set the player ticks to 0
  134. this.Players_Spam_Vote_Ticks[Client.ClientNum] = 0;
  135. }
  136. catch (Exception e)
  137. {
  138. ServerPrint("Plugin AntiVoteAbuse: OnPlayerDisconnect catched exception: " + e.Message);
  139. }
  140. }
  141.  
  142. // OnVote
  143. public override bool OnVote(String Vote, ServerClient Client, String OptionalArg)
  144. {
  145. try
  146. {
  147. // If the vote caller is not an admin
  148. if (!Admins.Contains(Client.XUID))
  149. {
  150. // If the player is not allowed to vote
  151. if (this.Players_No_Vote.Contains(Client.XUID))
  152. {
  153. // The player is no more allowed to vote
  154. TellClient(Client.ClientNum, "You can not vote on this server!!!", true);
  155. return false;
  156. }
  157. else
  158. {
  159. if ((this.Vote_Kick_Only == 1 && Vote == "kick") || this.Vote_Kick_Only == 0)
  160. {
  161. if (DateTime.Now.Subtract(this.Players_Last_Vote[Client.ClientNum]).TotalSeconds < this.Vote_Interval)
  162. {
  163. // Interval not Ok, vote not allowed
  164. this.Players_Spam_Vote_Ticks[Client.ClientNum] += 1;
  165. if (this.Players_Spam_Vote_Ticks[Client.ClientNum] == Warns_Nbr)
  166. {
  167. // reached the max warn number => vote-ban player
  168. Players_No_Vote.Add(Client.XUID);
  169. // Tell to the client that he has been vote-banned
  170. TellClient(Client.ClientNum, this.Ban_Message, true);
  171. }
  172. else
  173. {
  174. // Warn the player
  175. String Vote_Warn_Message2 = this.Warn_Message;
  176. Vote_Warn_Message2.Replace("@[email protected]", "" + (Warns_Nbr - this.Players_Spam_Vote_Ticks[Client.ClientNum]));
  177. Vote_Warn_Message2.Replace("@[email protected]", "" + this.Vote_Interval);
  178. TellClient(Client.ClientNum, Vote_Warn_Message2, true);
  179. }
  180.  
  181. return false;
  182. }
  183. else
  184. {
  185. // Reset the player spam ticks
  186. this.Players_Spam_Vote_Ticks[Client.ClientNum] = 0;
  187.  
  188. // Set Players_Last_Vote[Client.ClientNum] to the current time
  189. this.Players_Last_Vote[Client.ClientNum] = DateTime.Now;
  190.  
  191. // If the vote is for kicking
  192. if (Vote == "kick")
  193. {
  194. // Get the clients list
  195. List<ServerClient> Clients = GetClients();
  196.  
  197. // If not null
  198. if (Clients != null)
  199. {
  200. // Loop the clients list
  201. foreach (ServerClient player in Clients)
  202. {
  203. // If the current player is the player to kick
  204. if (player.Name == OptionalArg)
  205. {
  206. // Check if the player to kick is an admin
  207. if (this.Admins.Contains(player.XUID))
  208. {
  209. // Ohoh try to kick an admin ahah!!
  210. this.Players_Spam_Vote_Ticks[Client.ClientNum] += 1;
  211. if (this.Players_Spam_Vote_Ticks[Client.ClientNum] == Warns_Nbr)
  212. {
  213. // reached the max warn number => vote-ban player
  214. Players_No_Vote.Add(Client.XUID);
  215. // Tell to the client that he has been vote-banned
  216. TellClient(Client.ClientNum, this.Ban_Message, true);
  217. }
  218. else
  219. {
  220. // Warn the player that trying to vote-kick an admin is stupid lol
  221. String Vote_Admin_Kick_Message = this.Admin_Kick_Message;
  222. Vote_Admin_Kick_Message.Replace("@[email protected]", "" + (Warns_Nbr - this.Players_Spam_Vote_Ticks[Client.ClientNum]));
  223. Vote_Admin_Kick_Message.Replace("@[email protected]", "" + this.Vote_Interval);
  224. TellClient(Client.ClientNum, Vote_Admin_Kick_Message, true);
  225. }
  226. return false;
  227. }
  228.  
  229. if (this.Immunized_Xuids.Contains(player.XUID))
  230. {
  231. // Ohoh try to kick an immunized player ahah!!
  232. this.Players_Spam_Vote_Ticks[Client.ClientNum] += 1;
  233. if (this.Players_Spam_Vote_Ticks[Client.ClientNum] == Warns_Nbr)
  234. {
  235. // reached the max warn number => vote-ban player
  236. Players_No_Vote.Add(Client.XUID);
  237. // Tell to the client that he has been vote-banned
  238. TellClient(Client.ClientNum, this.Ban_Message, true);
  239. }
  240. else
  241. {
  242. // Warn the player that trying to vote-kick an immunized player is not allowed
  243. String Try_Immunized_Kick_Message2 = this.Immunized_Kick_Message;
  244. Try_Immunized_Kick_Message2.Replace("@[email protected]", "" + (Warns_Nbr - this.Players_Spam_Vote_Ticks[Client.ClientNum]));
  245. Try_Immunized_Kick_Message2.Replace("@[email protected]", "" + this.Vote_Interval);
  246. Try_Immunized_Kick_Message2.Replace("@[email protected]", player.Name);
  247. TellClient(Client.ClientNum, Try_Immunized_Kick_Message2, true);
  248. }
  249. return false;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259.  
  260. return true;
  261. }
  262. catch (Exception e)
  263. {
  264. ServerPrint("Plugin AntiVoteAbuse: OnVote catched exception: " + e.Message);
  265. // Error so let the vote happend
  266. return true;
  267. }
  268. }
  269.  
  270. public override ChatType OnSay(string Message, ServerClient Client, bool Teamchat)
  271. {
  272. // If the message starts with !vi
  273. if (Message.StartsWith("!vi"))
  274. {
  275. // Split the message by spaces
  276. string[] message_words = Message.Split(' ');
  277. // If there is more than 1 word
  278. if (message_words.Length > 1)
  279. {
  280. // Get the clients list
  281. List<ServerClient> Clients = GetClients();
  282. string player_to_found = Message.Substring(4);
  283. // If not null
  284. if (Clients != null)
  285. {
  286. // Loop the clients list
  287. foreach (ServerClient player in Clients)
  288. {
  289. if (player.Name == player_to_found)
  290. {
  291. if (this.Immunized_Xuids.Contains(player.XUID))
  292. {
  293. TellClient(Client.ClientNum, "This player is already immunized!", true);
  294. return ChatType.ChatNone;
  295. }
  296. else
  297. {
  298. // Add the player to the immunized list
  299. this.Immunized_Xuids.Add(player.XUID);
  300. // Save the player in the servercfg
  301. SetServerCFG("AntiVoteAbuse", "Immunized_Xuids", GetServerCFG("AntiVoteAbuse", "Immunized_Xuids", "") + "," + player.XUID);
  302. return ChatType.ChatNone;
  303. }
  304. }
  305. }
  306. }
  307.  
  308. TellClient(Client.ClientNum, "Impossible to found the player to immunize!", true);
  309. }
  310. }
  311. return ChatType.ChatContinue;
  312. }
  313. }
  314. }


Attached Files
.zip   AntiVoteAbuse.zip (Size: 3.86 KB / Downloads: 59)
[-] The following 4 users say Thank You to narkos for this post:
  • Canta, itsmods.com76, NooB_StalkeR, surtek
  Reply
#2
Very good plugin/organised code.
C++/Obj-C developer. Neko engine wip
Steam: Click
[-] The following 1 user says Thank You to Nekochan for this post:
  • narkos
  Reply
#3
Thx a lot for that comment Wink <3
  Reply
#4
I can never dream of writing that many comments
  Reply
#5
Lol!

Yeah i know i write a bit too much comments xD
But i always share the source code, so like that people can easily understand the code and modify/recompile it.

(All my codes are always open source, so feel free to modify them as you need.)
[-] The following 1 user says Thank You to narkos for this post:
  • amirdj
  Reply
#6
"Vote_Kick_Only=1
// 0 = all the vote types, 1 = only votekick affected"

It does not work. It does not disable all types of votes
[Image: b_560_95_1.png]
  Reply
#7
Vote_Kick_Only option is not used to disable vote in the Game Menus... it is used to know which type of vote are checked by the plugin...i already told you that in the request post.

In the sv_config.ini:
Vote_Kick_Only=1
=> The plugin will check when vote-kick are called.
Vote_Kick_Only=0
=> The plugin will check when vote-kick, vote-map_restart, vote-next_map are called.

When i say check i mean the plugin will control who call the vote, if he's allowed to vote etc...

(Also don't forget that admins from permission plugin are not affected by this plugin. They are always able to vote...)
[-] The following 1 user says Thank You to narkos for this post:
  • Canta
  Reply
#8
Now I understand.
Google translator, sometimes difficult to understand. Smile
thanks
[Image: b_560_95_1.png]
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)