using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Addon;
namespace AntiVoteAbuse
{
public class AntiVoteAbuse : CPlugin
{
//* Attributs
// Store the datetime of the latest vote of each players
private DateTime
[] Players_Last_Vote
= new DateTime
[18];
// Store the admins xuids
private ArrayList Admins
= new ArrayList
();
// Store the xuids of the immunized players
private ArrayList Immunized_Xuids
= new ArrayList
();
// Store the players that can no more use vote
private ArrayList Players_No_Vote
= new ArrayList
();
// Store the players vote spam ticks
private int[] Players_Spam_Vote_Ticks
= new int[18];
// Minimum time in seconds between 2 votes ( No interval for admins yeahhh )
private int Vote_Interval = 60;
// Maximum number of warn before vote-ban a player
private int Warns_Nbr = 3;
// Vote-ban message
private string Ban_Message = "^1You have been vote banned! You can no more vote on this server!";
// Vote-warn message
private string Warn_Message = "^1No spam vote!!! @WARN_LEFT@ more spam in the interval of @VOTE_INTERVAL@ seconds = Vote Banned!";
// Vote-warn "try to kick an admin" message
private string Try_Admin_Kick_Message = "^1Don't try to kick an admin!!! @WARN_LEFT@ more in the interval of @VOTE_INTERVAL@ seconds = Vote Banned!";
// Vote-warn "try to kick an immunized player" message
private string Try_Immunized_Kick_Message = "^1Don't try to kick an immunized player (@PLAYER_NAME@)!!! @WARN_LEFT@ more in the interval of @VOTE_INTERVAL@ seconds = Vote Banned!";
//* Functions
// OnServerLoad
public override void OnServerLoad()
{
try
{
// Get the admins xuids from permission plugin
string[] get_admins = GetServerCFG("Permission", "Admin_xuids", "").Split(',');
// Loop the admins to add them to the list
foreach (string admin in get_admins)
{
this.Admins.Add(admin);
}
// Get if the mods of permission plugin are immunized
int Immunize_Moderators = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Immunize_Moderators", "1"));
if (Immunize_Moderators == 1)
{
// Get the moderators xuids from permission plugin
string[] get_moderators = GetServerCFG("Permission", "Moderator_xuids", "").Split(',');
// Loop the admins and add them to the list
foreach (string moderator in get_moderators)
{
this.Immunized_Xuids.Add(moderator);
}
}
// Get the immunized players xuids
string[] get_immunized_xuids = GetServerCFG("AntiVoteAbuse", "Immunized_Xuids", "").Split(',');
// loop the immunized players xuids and add them to the list
foreach (string xuid in get_immunized_xuids)
{
this.Immunized_Xuids.Add(xuid);
}
// Get the Interval between 2 votes
this.Vote_Interval = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Vote_Interval", "60"));
// Get the number of warn before vote-ban a player
this.Warns_Nbr = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Warns_Nbr", "3"));
// Get the vote-ban message
this.Ban_Message = GetServerCFG("AntiVoteAbuse", "Ban_Message", "^1You have been vote banned! You can no more vote on this server!");
// Get the vote-warn message
this.Warn_Message = GetServerCFG("AntiVoteAbuse", "Warn_Message", "^1No spam vote!!! @WARN_LEFT@ more spam in the interval of @VOTE_INTERVAL@ seconds = Vote Banned!");
// Get the try to kick an admin message
this.Try_Admin_Kick_Message = GetServerCFG("AntiVoteAbuse", "Try_Admin_Kick_Message", "^1Don't try to kick an admin!!! @WARN_LEFT@ more in the interval of @VOTE_INTERVAL@ seconds = Vote Banned!");
// Get the try to kick an immunized player message
this.Try_Immunized_Kick_Message = GetServerCFG("AntiVoteAbuse", "Try_Immunized_Kick_Message", "^1Don't try to kick an immunized player (@PLAYER_NAME@)!!! @WARN_LEFT@ more in the interval of @VOTE_INTERVAL@ seconds = Vote Banned!");
// Indicate that the plugin is loaded.
ServerPrint("Plugin AntiVoteAbuse loaded! Author: Narkos");
}
catch(Exception e)
{
ServerPrint("Plugin AntiVoteAbuse: OnServerLoad catched exception: " + e.Message);
}
}
// OnPlayerConnect
public override void OnPlayerConnect(ServerClient Client)
{
try
{
// 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)
this.Players_Last_Vote[Client.ClientNum] = DateTime.Now;
}
catch(Exception e)
{
ServerPrint("Plugin AntiVoteAbuse: OnPlayerConnect catched exception: " + e.Message);
}
}
// OnPlayerDisconnect
public override void OnPlayerDisconnect(ServerClient Client)
{
try
{
// Set the player ticks to 0
this.Players_Spam_Vote_Ticks[Client.ClientNum] = 0;
// If the player is vote banned, delete him or keep him banned???
/*if (this.Players_No_Vote.Contains(Client.XUID))
{
this.Players_No_Vote.Remove(Client.XUID);
}*/
}
catch (Exception e)
{
ServerPrint("Plugin AntiVoteAbuse: OnPlayerDisconnect catched exception: " + e.Message);
}
}
// OnVote
public override bool OnVote(String Vote, ServerClient Client, String OptionalArg)
{
try
{
// If the vote caller is not an admin
if (!Admins.Contains(Client.XUID))
{
// If the player is not allowed to vote
if (this.Players_No_Vote.Contains(Client.XUID))
{
// The player is no more allowed to vote
TellClient(Client.ClientNum, "You can not vote on this server!!!", true);
return false;
}
else
{
if (DateTime.Now.Subtract(this.Players_Last_Vote[Client.ClientNum]).TotalSeconds < this.Vote_Interval)
{
// Interval not Ok, vote not allowed
this.Players_Spam_Vote_Ticks[Client.ClientNum] += 1;
if (this.Players_Spam_Vote_Ticks[Client.ClientNum] == Warns_Nbr)
{
// reached the max warn number => vote-ban player
Players_No_Vote.Add(Client.XUID);
// Tell to the client that he has been vote-banned
TellClient(Client.ClientNum, this.Ban_Message, true);
}
else
{
// Warn the player
String Vote_Warn_Message2 = this.Warn_Message;
Vote_Warn_Message2.Replace("@WARN_LEFT@", "" + (Warns_Nbr - this.Players_Spam_Vote_Ticks[Client.ClientNum]));
Vote_Warn_Message2.Replace("@VOTE_INTERVAL@", "" + this.Vote_Interval);
TellClient(Client.ClientNum, Vote_Warn_Message2, true);
}
return false;
}
else
{
// Reset the player spam ticks
this.Players_Spam_Vote_Ticks[Client.ClientNum] = 0;
// Set Players_Last_Vote[Client.ClientNum] to the current time
this.Players_Last_Vote[Client.ClientNum] = DateTime.Now;
// If the vote is for kicking
if (Vote == "kick")
{
// Get the clients list
List<ServerClient> Clients = GetClients();
// If not null
if (Clients != null)
{
// Loop the clients list
foreach (ServerClient player in Clients)
{
// If the current player is the player to kick
if (player.Name == OptionalArg)
{
// Check if the player to kick is an admin
if (this.Admins.Contains(player.XUID))
{
// Ohoh try to kick an admin ahah!!
this.Players_Spam_Vote_Ticks[Client.ClientNum] += 1;
if (this.Players_Spam_Vote_Ticks[Client.ClientNum] == Warns_Nbr)
{
// reached the max warn number => vote-ban player
Players_No_Vote.Add(Client.XUID);
// Tell to the client that he has been vote-banned
TellClient(Client.ClientNum, this.Ban_Message, true);
}
else
{
// Warn the player that trying to vote-kick an admin is stupid lol
String Vote_Admin_Kick_Message = this.Try_Admin_Kick_Message;
Vote_Admin_Kick_Message.Replace("@WARN_LEFT@", "" + (Warns_Nbr - this.Players_Spam_Vote_Ticks[Client.ClientNum]));
Vote_Admin_Kick_Message.Replace("@VOTE_INTERVAL@", "" + this.Vote_Interval);
TellClient(Client.ClientNum, Vote_Admin_Kick_Message, true);
}
return false;
}
if (this.Immunized_Xuids.Contains(player.XUID))
{
// Ohoh try to kick an immunized player ahah!!
this.Players_Spam_Vote_Ticks[Client.ClientNum] += 1;
if (this.Players_Spam_Vote_Ticks[Client.ClientNum] == Warns_Nbr)
{
// reached the max warn number => vote-ban player
Players_No_Vote.Add(Client.XUID);
// Tell to the client that he has been vote-banned
TellClient(Client.ClientNum, this.Ban_Message, true);
}
else
{
// Warn the player that trying to vote-kick an immunized player is not allowed
String Try_Immunized_Kick_Message2 = this.Try_Immunized_Kick_Message;
Try_Immunized_Kick_Message2.Replace("@WARN_LEFT@", "" + (Warns_Nbr - this.Players_Spam_Vote_Ticks[Client.ClientNum]));
Try_Immunized_Kick_Message2.Replace("@VOTE_INTERVAL@", "" + this.Vote_Interval);
Try_Immunized_Kick_Message2.Replace("@PLAYER_NAME@", player.Name);
TellClient(Client.ClientNum, Try_Immunized_Kick_Message2, true);
}
return false;
}
}
}
}
}
}
}
}
return true;
}
catch (Exception e)
{
ServerPrint("Plugin AntiVoteAbuse: OnVote catched exception: " + e.Message);
// Error so let the vote happend
return true;
}
}
public override ChatType OnSay(string Message, ServerClient Client, bool Teamchat)
{
// If the message starts with !vi
if (Message.StartsWith("!vi"))
{
// Split the message by spaces
string[] message_words = Message.Split(' ');
// If there is more than 1 word
if (message_words.Length > 1)
{
// Get the clients list
List<ServerClient> Clients = GetClients();
string player_to_found = Message.Substring(4);
// If not null
if (Clients != null)
{
// Loop the clients list
foreach (ServerClient player in Clients)
{
if (player.Name == player_to_found)
{
if (this.Immunized_Xuids.Contains(player.XUID))
{
TellClient(Client.ClientNum, "This player is already immunized!", true);
}
else
{
// Add the player to the immunized list
this.Immunized_Xuids.Add(player.XUID);
// Save the player in the servercfg
SetServerCFG("AntiVoteAbuse", "Immunized_Xuids", GetServerCFG("AntiVoteAbuse", "Immunized_Xuids", "") + "," + player.XUID);
return ChatType.ChatNone;
}
}
}
}
TellClient(Client.ClientNum, "Impossible to found the player to immunize!", true);
}
}
return ChatType.ChatContinue;
}
}
}