Added high ping kick functionality to Welcome Plugin
Added response to RCON command if applicable Added more maps into the map config
This commit is contained in:
parent
bd99add434
commit
11d37d4cd6
@ -93,8 +93,9 @@ namespace IW4MAdmin
|
||||
|
||||
static private String CheckUpdate()
|
||||
{
|
||||
Connection Ver = new Connection("http://raidmax.org/IW4M/Admin/version.php");
|
||||
return Ver.Read();
|
||||
//Connection Ver = new Connection("http://raidmax.org/IW4M/Admin/version.php");
|
||||
//return Ver.Read();
|
||||
return "0";
|
||||
}
|
||||
|
||||
static void CheckDirectories()
|
||||
|
@ -13,7 +13,6 @@ namespace IW4MAdmin
|
||||
{
|
||||
public IW4MServer(SharedLibrary.Interfaces.IManager mgr, string address, int port, string password) : base(mgr, address, port, password)
|
||||
{
|
||||
commandQueue = new Queue<string>();
|
||||
initCommands();
|
||||
}
|
||||
|
||||
@ -138,7 +137,7 @@ namespace IW4MAdmin
|
||||
if (aP.Level == Player.Permission.Flagged)
|
||||
NewPlayer.setLevel(Player.Permission.Flagged);
|
||||
|
||||
Penalty B = isBanned(aP);
|
||||
Penalty B = IsBanned(aP);
|
||||
|
||||
if (B != null && B.BType == Penalty.Type.Ban)
|
||||
{
|
||||
@ -196,7 +195,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
|
||||
//Another version of client from line, written for the line created by a kill or death event
|
||||
override public Player clientFromEventLine(String[] L, int cIDPos)
|
||||
override public Player ParseClientFromString(String[] L, int cIDPos)
|
||||
{
|
||||
if (L.Length < cIDPos)
|
||||
{
|
||||
@ -235,7 +234,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
|
||||
//Check ban list for every banned player and return ban if match is found
|
||||
override public Penalty isBanned(Player C)
|
||||
override public Penalty IsBanned(Player C)
|
||||
{
|
||||
return Manager.GetClientPenalties().FindPenalties(C).Where(b => b.BType == Penalty.Type.Ban).FirstOrDefault();
|
||||
}
|
||||
@ -269,13 +268,13 @@ namespace IW4MAdmin
|
||||
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} does not have access to \"{C.Name}\"");
|
||||
}
|
||||
|
||||
if (Args.Length < (C.requiredArgNum))
|
||||
if (Args.Length < (C.RequiredArgumentCount))
|
||||
{
|
||||
await E.Origin.Tell($"Not enough arguments supplied! ^5({C.requiredArgNum} ^7required)");
|
||||
await E.Origin.Tell($"Not enough arguments supplied! ^5({C.RequiredArgumentCount} ^7required)");
|
||||
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
|
||||
}
|
||||
|
||||
if (C.needsTarget || Args.Length > 0)
|
||||
if (C.RequiresTarget || Args.Length > 0)
|
||||
{
|
||||
int cNum = -1;
|
||||
int.TryParse(Args[0], out cNum);
|
||||
@ -306,9 +305,9 @@ namespace IW4MAdmin
|
||||
}
|
||||
|
||||
else
|
||||
E.Target = clientFromName(Args[0]);
|
||||
E.Target = GetClientByName(Args[0]);
|
||||
|
||||
if (E.Target == null && C.needsTarget)
|
||||
if (E.Target == null && C.RequiresTarget)
|
||||
{
|
||||
await E.Origin.Tell("Unable to find specified player.");
|
||||
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} specified invalid player for \"{C.Name}\"");
|
||||
@ -435,7 +434,7 @@ namespace IW4MAdmin
|
||||
else
|
||||
{
|
||||
string[] game_event = lines[count].Split(';');
|
||||
Event event_ = Event.requestEvent(game_event, this);
|
||||
Event event_ = Event.ParseEventString(game_event, this);
|
||||
if (event_ != null)
|
||||
{
|
||||
if (event_.Origin == null)
|
||||
@ -591,7 +590,7 @@ namespace IW4MAdmin
|
||||
|
||||
if (C != null)
|
||||
{
|
||||
if (C.needsTarget && E.Target == null)
|
||||
if (C.RequiresTarget && E.Target == null)
|
||||
{
|
||||
Logger.WriteWarning("Requested event (command) requiring target does not have a target!");
|
||||
return;
|
||||
@ -765,18 +764,11 @@ namespace IW4MAdmin
|
||||
|
||||
}
|
||||
|
||||
public override bool Reload()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool _Reload()
|
||||
public override bool Reload()
|
||||
{
|
||||
try
|
||||
{
|
||||
messages = null;
|
||||
maps = null;
|
||||
rules = null;
|
||||
initMaps();
|
||||
initMessages();
|
||||
initRules();
|
||||
@ -808,13 +800,5 @@ namespace IW4MAdmin
|
||||
Manager.GetCommands().Add(new Plugins("plugins", "view all loaded plugins. syntax: !plugins", "p", Player.Permission.Administrator, 0, false));
|
||||
|
||||
}
|
||||
|
||||
public bool commandQueueEmpty()
|
||||
{
|
||||
return commandQueue.Count == 0;
|
||||
}
|
||||
|
||||
//Objects
|
||||
private Queue<String> commandQueue;
|
||||
}
|
||||
}
|
||||
|
@ -29,4 +29,16 @@ mp_complex:Bailout
|
||||
mp_compact:Salvage
|
||||
mp_nuked:Nuketown
|
||||
iw4_credits:IW4 Credits
|
||||
mp_killhouse:Killhouse
|
||||
mp_bog_sh:Bog
|
||||
mp_cargoship_sh:Freighter
|
||||
mp_shipment:Shipment
|
||||
mp_shipment_long:Shipment - Long
|
||||
mp_rust_long:Rust - Long
|
||||
mp_firingrange:Firing Range
|
||||
mp_storm_spring:Chemical Plant
|
||||
mp_fav_tropical:Favela - Tropical
|
||||
mp_estate_tropical:Estate - Tropical
|
||||
mp_crash_tropical:Crash - Tropical
|
||||
mp_bloc_sh:Forgotten City
|
||||
mp_raidmax:^1L^23^33^4T^5M^6A^75^8T^93^0R
|
Binary file not shown.
@ -14,8 +14,8 @@ namespace SharedLibrary
|
||||
Description = D;
|
||||
Alias = A;
|
||||
Permission = P;
|
||||
requiredArgNum = args;
|
||||
needsTarget = nT;
|
||||
RequiredArgumentCount = args;
|
||||
RequiresTarget = nT;
|
||||
}
|
||||
|
||||
//Execute the command
|
||||
@ -24,8 +24,8 @@ namespace SharedLibrary
|
||||
public String Name { get; private set; }
|
||||
public String Description { get; private set; }
|
||||
public String Alias { get; private set; }
|
||||
public int requiredArgNum { get; private set; }
|
||||
public bool needsTarget { get; private set; }
|
||||
public int RequiredArgumentCount { get; private set; }
|
||||
public bool RequiresTarget { get; private set; }
|
||||
public Player.Permission Permission { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@ -496,9 +496,9 @@ namespace SharedLibrary.Commands
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Owner.Reload())
|
||||
await E.Origin.Tell("Sucessfully reloaded configs!");
|
||||
await E.Origin.Tell("Sucessfully reloaded configuration files");
|
||||
else
|
||||
await E.Origin.Tell("Unable to reload configs :(");
|
||||
await E.Origin.Tell("Unable to reload configuration files");
|
||||
}
|
||||
}
|
||||
|
||||
@ -690,8 +690,11 @@ namespace SharedLibrary.Commands
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.ExecuteCommandAsync(E.Data.Trim());
|
||||
await E.Origin.Tell("Successfuly sent RCON command!");
|
||||
var Response = await E.Owner.ExecuteCommandAsync(E.Data.Trim());
|
||||
foreach (string S in Response)
|
||||
await E.Origin.Tell(S.StripColors());
|
||||
if (Response.Length == 0)
|
||||
await E.Origin.Tell("Successfully sent RCON command!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public struct dvar
|
||||
{
|
||||
public String name;
|
||||
public String description;
|
||||
public int flags;
|
||||
public short type;
|
||||
public String current;
|
||||
public String latched;
|
||||
public String _default;
|
||||
public int min;
|
||||
public int max;
|
||||
}
|
||||
|
||||
public class _DVAR<T>
|
||||
public class DVAR<T>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public T Value;
|
||||
|
||||
public _DVAR(string name)
|
||||
public DVAR(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ namespace SharedLibrary
|
||||
Owner = S;
|
||||
}
|
||||
|
||||
public static Event requestEvent(String[] line, Server SV)
|
||||
public static Event ParseEventString(String[] line, Server SV)
|
||||
{
|
||||
#if DEBUG == false
|
||||
try
|
||||
@ -118,20 +118,20 @@ namespace SharedLibrary
|
||||
Data.Append(line[i] + ";");
|
||||
}
|
||||
|
||||
return new Event(GType.Kill, Data.ToString(), SV.clientFromEventLine(line, 6), SV.clientFromEventLine(line, 2), SV);
|
||||
return new Event(GType.Kill, Data.ToString(), SV.ParseClientFromString(line, 6), SV.ParseClientFromString(line, 2), SV);
|
||||
}
|
||||
|
||||
if (line[0].Substring(line[0].Length - 3).Trim() == "say")
|
||||
{
|
||||
Regex rgx = new Regex("[^a-zA-Z0-9 -! -_]");
|
||||
string message = rgx.Replace(line[4], "");
|
||||
return new Event(GType.Say, Utilities.removeNastyChars(message), SV.clientFromEventLine(line, 2), null, SV) { Message = Utilities.removeNastyChars(message) };
|
||||
return new Event(GType.Say, Utilities.removeNastyChars(message).StripColors(), SV.ParseClientFromString(line, 2), null, SV) { Message = Utilities.removeNastyChars(message).StripColors() };
|
||||
}
|
||||
|
||||
if (eventType == ":")
|
||||
return new Event(GType.MapEnd, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
|
||||
|
||||
if (line[0].Contains("InitGame")) // blaze it
|
||||
if (line[0].Contains("InitGame"))
|
||||
return new Event(GType.MapChange, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
|
||||
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
@ -17,7 +14,7 @@ namespace SharedLibrary
|
||||
this.BType = BType;
|
||||
}
|
||||
|
||||
public String getWhen()
|
||||
public String GetWhenFormatted()
|
||||
{
|
||||
return When.ToString("MM/dd/yy HH:mm:ss"); ;
|
||||
}
|
||||
|
@ -20,34 +20,6 @@ namespace SharedLibrary.Network
|
||||
COMMAND,
|
||||
}
|
||||
|
||||
public static List<Player> PlayersFromStatus(String[] Status)
|
||||
{
|
||||
List<Player> StatusPlayers = new List<Player>();
|
||||
|
||||
foreach (String S in Status)
|
||||
{
|
||||
String responseLine = S.Trim();
|
||||
|
||||
if (Regex.Matches(responseLine, @"\d+$", RegexOptions.IgnoreCase).Count > 0 && responseLine.Length > 72) // its a client line!
|
||||
{
|
||||
String[] playerInfo = responseLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
int cID = -1;
|
||||
int Ping = -1;
|
||||
Int32.TryParse(playerInfo[2], out Ping);
|
||||
String cName = Utilities.StripColors(responseLine.Substring(46, 18)).Trim();
|
||||
String npID = responseLine.Substring(29, 17).Trim(); // DONT TOUCH PLZ
|
||||
int.TryParse(playerInfo[0], out cID);
|
||||
String cIP = responseLine.Substring(72, 20).Trim().Split(':')[0];
|
||||
if (cIP.Split(' ').Count() > 1)
|
||||
cIP = cIP.Split(' ')[1];
|
||||
Player P = new Player(cName, npID, cID, cIP) { Ping = Ping };
|
||||
StatusPlayers.Add(P);
|
||||
}
|
||||
}
|
||||
|
||||
return StatusPlayers;
|
||||
}
|
||||
|
||||
static string[] SendQuery(QueryType Type, Server QueryServer, string Parameters = "")
|
||||
{
|
||||
var ServerOOBConnection = new UdpClient();
|
||||
@ -113,7 +85,7 @@ namespace SharedLibrary.Network
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<_DVAR<T>> GetDvarAsync<T>(this Server server, string dvarName)
|
||||
public static async Task<DVAR<T>> GetDvarAsync<T>(this Server server, string dvarName)
|
||||
{
|
||||
string[] LineSplit = await Task.FromResult(SendQuery(QueryType.DVAR, server, dvarName));
|
||||
|
||||
@ -137,7 +109,7 @@ namespace SharedLibrary.Network
|
||||
string DvarCurrentValue = Regex.Replace(ValueSplit[2], @"\^[0-9]", "");
|
||||
string DvarDefaultValue = Regex.Replace(ValueSplit[4], @"\^[0-9]", "");
|
||||
|
||||
return new _DVAR<T>(DvarName) { Value = (T)Convert.ChangeType(DvarCurrentValue, typeof(T)) };
|
||||
return new DVAR<T>(DvarName) { Value = (T)Convert.ChangeType(DvarCurrentValue, typeof(T)) };
|
||||
}
|
||||
|
||||
public static async Task SetDvarAsync(this Server server, string dvarName, object dvarValue)
|
||||
@ -145,15 +117,15 @@ namespace SharedLibrary.Network
|
||||
await Task.FromResult(SendQuery(QueryType.DVAR, server, $"{dvarName} {dvarValue}"));
|
||||
}
|
||||
|
||||
public static async Task ExecuteCommandAsync(this Server server, string commandName)
|
||||
public static async Task<string[]> ExecuteCommandAsync(this Server server, string commandName)
|
||||
{
|
||||
await Task.FromResult(SendQuery(QueryType.COMMAND, server, commandName));
|
||||
return await Task.FromResult(SendQuery(QueryType.COMMAND, server, commandName).Skip(1).ToArray());
|
||||
}
|
||||
|
||||
public static async Task<List<Player>> GetStatusAsync(this Server server)
|
||||
{
|
||||
string[] response = await Task.FromResult(SendQuery(QueryType.DVAR, server, "status"));
|
||||
return PlayersFromStatus(response);
|
||||
return Utilities.PlayersFromStatus(response);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
|
@ -150,25 +150,16 @@ namespace SharedLibrary
|
||||
/// <param name="L">Game log line containing event</param>
|
||||
/// <param name="cIDPos">Position in the line where the cliet ID is written</param>
|
||||
/// <returns>Matching player if found</returns>
|
||||
abstract public Player clientFromEventLine(String[] L, int cIDPos);
|
||||
abstract public Player ParseClientFromString(String[] L, int cIDPos);
|
||||
|
||||
/// <summary>
|
||||
/// Get a player by name
|
||||
/// </summary>
|
||||
/// <param name="pName">Player name to search for</param>
|
||||
/// <returns>Matching player if found</returns>
|
||||
public Player clientFromName(String pName)
|
||||
public Player GetClientByName(String pName)
|
||||
{
|
||||
lock (Players)
|
||||
{
|
||||
foreach (var P in Players)
|
||||
{
|
||||
if (P != null && P.Name.ToLower().Contains(pName.ToLower()))
|
||||
return P;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return Players.FirstOrDefault(p => p.Name.ToLower() == pName.ToLower());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -176,7 +167,7 @@ namespace SharedLibrary
|
||||
/// </summary>
|
||||
/// <param name="C">Player to check if banned</param>
|
||||
/// <returns>Matching ban if found</returns>
|
||||
abstract public Penalty isBanned(Player C);
|
||||
abstract public Penalty IsBanned(Player C);
|
||||
|
||||
/// <summary>
|
||||
/// Process requested command correlating to an event
|
||||
@ -210,7 +201,6 @@ namespace SharedLibrary
|
||||
/// </summary>
|
||||
/// <returns>True on sucess</returns>
|
||||
abstract public bool Reload();
|
||||
abstract public bool _Reload();
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to all players
|
||||
|
@ -46,6 +46,34 @@ namespace SharedLibrary
|
||||
return newStr;
|
||||
}
|
||||
|
||||
public static List<Player> PlayersFromStatus(String[] Status)
|
||||
{
|
||||
List<Player> StatusPlayers = new List<Player>();
|
||||
|
||||
foreach (String S in Status)
|
||||
{
|
||||
String responseLine = S.Trim();
|
||||
|
||||
if (Regex.Matches(responseLine, @"\d+$", RegexOptions.IgnoreCase).Count > 0 && responseLine.Length > 72) // its a client line!
|
||||
{
|
||||
String[] playerInfo = responseLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
int cID = -1;
|
||||
int Ping = -1;
|
||||
Int32.TryParse(playerInfo[2], out Ping);
|
||||
String cName = Utilities.StripColors(responseLine.Substring(46, 18)).Trim();
|
||||
String npID = responseLine.Substring(29, 17).Trim(); // DONT TOUCH PLZ
|
||||
int.TryParse(playerInfo[0], out cID);
|
||||
String cIP = responseLine.Substring(72, 20).Trim().Split(':')[0];
|
||||
if (cIP.Split(' ').Count() > 1)
|
||||
cIP = cIP.Split(' ')[1];
|
||||
Player P = new Player(cName, npID, cID, cIP) { Ping = Ping };
|
||||
StatusPlayers.Add(P);
|
||||
}
|
||||
}
|
||||
|
||||
return StatusPlayers;
|
||||
}
|
||||
|
||||
public static Player.Permission matchPermission(String str)
|
||||
{
|
||||
String lookingFor = str.ToLower();
|
||||
|
@ -1,12 +1,18 @@
|
||||
using System;
|
||||
using SharedLibrary;
|
||||
using System.Collections.Generic;
|
||||
using SharedLibrary.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SharedLibrary.Network;
|
||||
|
||||
namespace Welcome_Plugin
|
||||
{
|
||||
public class Plugin : IPlugin
|
||||
{
|
||||
Dictionary<int, float> PlayerPings;
|
||||
int PingAverageCount;
|
||||
|
||||
public string Author
|
||||
{
|
||||
get
|
||||
@ -33,17 +39,33 @@ namespace Welcome_Plugin
|
||||
|
||||
public async Task OnLoadAsync()
|
||||
{
|
||||
return;
|
||||
PlayerPings = new Dictionary<int, float>();
|
||||
PingAverageCount = 1;
|
||||
}
|
||||
|
||||
public async Task OnUnloadAsync()
|
||||
{
|
||||
return;
|
||||
PlayerPings.Clear();
|
||||
PlayerPings = null;
|
||||
}
|
||||
|
||||
public async Task OnTickAsync(Server S)
|
||||
{
|
||||
return;
|
||||
int MaxPing = (await S.GetDvarAsync<int>("sv_maxping")).Value;
|
||||
|
||||
if (MaxPing == 0)
|
||||
return;
|
||||
|
||||
foreach (int PlayerID in PlayerPings.Keys)
|
||||
{
|
||||
var Player = S.Players.Find(p => p.DatabaseID == PlayerID);
|
||||
PlayerPings[PlayerID] = PlayerPings[PlayerID] + (Player.Ping - PlayerPings[PlayerID]) / PingAverageCount;
|
||||
if (PlayerPings[PlayerID] > MaxPing)
|
||||
await Player.Kick($"Your average ping of ^5{PlayerPings[PlayerID]} ^7is too high for this server", null);
|
||||
}
|
||||
|
||||
if (PingAverageCount > 100)
|
||||
PingAverageCount = 1;
|
||||
}
|
||||
|
||||
public async Task OnEventAsync(Event E, Server S)
|
||||
@ -58,7 +80,7 @@ namespace Welcome_Plugin
|
||||
await newPlayer.Tell($"Welcome ^5{newPlayer.Name}^7, this your ^5{newPlayer.TimesConnected()} ^7time connecting!");
|
||||
|
||||
if (newPlayer.Level == Player.Permission.Flagged)
|
||||
await E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name}^7 has joined!");
|
||||
await E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name}^7 has joined!");
|
||||
|
||||
else
|
||||
{
|
||||
@ -72,8 +94,15 @@ namespace Welcome_Plugin
|
||||
{
|
||||
E.Owner.Manager.GetLogger().WriteError("Could not open file Plugins/GeoIP.dat for Welcome Plugin");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
PlayerPings.Add(E.Origin.DatabaseID, 1.0f);
|
||||
}
|
||||
|
||||
if (E.Type == Event.GType.Disconnect)
|
||||
{
|
||||
PlayerPings.Remove(E.Origin.DatabaseID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user