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 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;
//* Functions
// OnServerLoad
public override void OnServerLoad()
{
try
{
// Get the admins xuids from permission plugin
string[] get_admins = GetServerCFG("Permission", "Admin_xuids", "").Split(',');
foreach (string admin in get_admins)
{
this.Admins.Add(admin);
}
// Get the Interval between 2 votes
this.Vote_Interval = Int32.Parse(GetServerCFG("AntiVoteAbuse", "Vote_Interval", "60"));
// 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] == 3)
{
// third spam vote in the same interval
Players_No_Vote.Add(Client.XUID);
TellClient(Client.ClientNum, "^1You have been vote banned! You can no more vote on this server!", true);
}
else
{
TellClient(Client.ClientNum, "^1No spam vote!!! " + (3 - this.Players_Spam_Vote_Ticks[Client.ClientNum]) + " more spam in the interval of " + this.Vote_Interval + " seconds = Vote Banned!", 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 (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] == 3)
{
// third spam vote in the same interval
Players_No_Vote.Add(Client.XUID);
TellClient(Client.ClientNum, "^1You have been vote banned! You can no more vote on this server!", true);
}
else
{
TellClient(Client.ClientNum, "^1Don't try to kick an admin!!! " + (3 - this.Players_Spam_Vote_Ticks[Client.ClientNum]) + " more in the interval of " + this.Vote_Interval + " seconds = Vote Banned!", true);
}
return false;
}
}
}
}
}
}
}
}
return true;
}
catch (Exception e)
{
ServerPrint("Plugin AntiVoteAbuse: OnVote catched exception: " + e.Message);
// Error so let the vote happend
return true;
}
}
}
}