mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
Branch for IW4X practically everything refactored
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
@ -18,7 +19,7 @@ namespace SharedLibrary
|
||||
}
|
||||
|
||||
//Execute the command
|
||||
abstract public void Execute(Event E);
|
||||
abstract public Task ExecuteAsync(Event E);
|
||||
|
||||
public String Name { get; private set; }
|
||||
public String Description { get; private set; }
|
||||
|
721
SharedLibrary/Commands/NativeCommands.cs
Normal file
721
SharedLibrary/Commands/NativeCommands.cs
Normal file
@ -0,0 +1,721 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SharedLibrary;
|
||||
using SharedLibrary.Network;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Commands
|
||||
{
|
||||
class Quit : Command
|
||||
{
|
||||
public Quit(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Owner.Manager.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
class Owner : Command
|
||||
{
|
||||
|
||||
public Owner(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Owner.clientDB.getOwner() == null)
|
||||
{
|
||||
E.Origin.setLevel(Player.Permission.Owner);
|
||||
await E.Origin.Tell("Congratulations, you have claimed ownership of this server!");
|
||||
E.Owner.owner = E.Origin;
|
||||
E.Owner.clientDB.updatePlayer(E.Origin);
|
||||
}
|
||||
else
|
||||
await E.Origin.Tell("This server already has an owner!");
|
||||
}
|
||||
}
|
||||
|
||||
class Warn : Command
|
||||
{
|
||||
public Warn(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Target.lastOffense = E.Data.RemoveWords(1);
|
||||
if (E.Origin.Level <= E.Target.Level)
|
||||
await E.Origin.Tell("You cannot warn " + E.Target.Name);
|
||||
else
|
||||
await E.Target.Warn(E.Target.lastOffense, E.Origin);
|
||||
}
|
||||
}
|
||||
|
||||
class WarnClear : Command
|
||||
{
|
||||
public WarnClear(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Target.lastOffense = String.Empty;
|
||||
E.Target.Warnings = 0;
|
||||
String Message = String.Format("All warning cleared for {0}", E.Target.Name);
|
||||
await E.Owner.Broadcast(Message);
|
||||
}
|
||||
}
|
||||
|
||||
class Kick : Command
|
||||
{
|
||||
public Kick(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Target.lastOffense = SharedLibrary.Utilities.RemoveWords(E.Data, 1);
|
||||
if (E.Origin.Level > E.Target.Level)
|
||||
await E.Target.Kick(E.Target.lastOffense, E.Origin);
|
||||
else
|
||||
await E.Origin.Tell("You cannot kick " + E.Target.Name);
|
||||
}
|
||||
}
|
||||
|
||||
class Say : Command
|
||||
{
|
||||
public Say(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.Broadcast("^1" + E.Origin.Name + " - ^6" + E.Data + "^7");
|
||||
}
|
||||
}
|
||||
|
||||
class TempBan : Command
|
||||
{
|
||||
public TempBan(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Target.lastOffense = SharedLibrary.Utilities.RemoveWords(E.Data, 1);
|
||||
String Message = E.Target.lastOffense;
|
||||
if (E.Origin.Level > E.Target.Level)
|
||||
await E.Target.TempBan(Message, E.Origin);
|
||||
else
|
||||
await E.Origin.Tell("You cannot temp ban " + E.Target.Name);
|
||||
}
|
||||
}
|
||||
|
||||
class SBan : Command
|
||||
{
|
||||
public SBan(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Target.lastOffense = SharedLibrary.Utilities.RemoveWords(E.Data, 1);
|
||||
E.Target.lastEvent = E; // needs to be fixed
|
||||
String Message;
|
||||
if (E.Owner.Website == null)
|
||||
Message = "^1Player Banned: ^5" + E.Target.lastOffense;
|
||||
else
|
||||
Message = "^1Player Banned: ^5" + E.Target.lastOffense;
|
||||
if (E.Origin.Level > E.Target.Level)
|
||||
{
|
||||
await E.Target.Ban(Message, E.Origin);
|
||||
await E.Origin.Tell(String.Format("Sucessfully banned ^5{0} ^7({1})", E.Target.Name, E.Target.npID));
|
||||
}
|
||||
else
|
||||
await E.Origin.Tell("You cannot ban " + E.Target.Name);
|
||||
}
|
||||
}
|
||||
|
||||
class Unban : Command
|
||||
{
|
||||
public Unban(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.Unban(E.Data.Trim(), E.Target);
|
||||
await E.Origin.Tell($"Successfully unbanned {E.Target.Name}::{E.Target.npID}");
|
||||
}
|
||||
}
|
||||
|
||||
class WhoAmI : Command
|
||||
{
|
||||
public WhoAmI(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
String You = String.Format("{0} [^3#{1}^7] {2} [^3@{3}^7] [{4}^7] IP: {5}", E.Origin.Name, E.Origin.clientID, E.Origin.npID, E.Origin.databaseID, SharedLibrary.Utilities.levelToColor(E.Origin.Level), E.Origin.IP);
|
||||
await E.Origin.Tell(You);
|
||||
}
|
||||
}
|
||||
|
||||
class List : Command
|
||||
{
|
||||
public List(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
StringBuilder playerList = new StringBuilder();
|
||||
int count = 0;
|
||||
for (int i = 0; i < E.Owner.Players.Count; i++)
|
||||
{
|
||||
var P = E.Owner.Players[i];
|
||||
|
||||
if (P == null)
|
||||
continue;
|
||||
|
||||
if (P.Masked)
|
||||
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.levelToColor(Player.Permission.User), P.clientID, P.Name, SharedLibrary.Utilities.getSpaces(Player.Permission.SeniorAdmin.ToString().Length - Player.Permission.User.ToString().Length));
|
||||
else
|
||||
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.levelToColor(P.Level), P.clientID, P.Name, SharedLibrary.Utilities.getSpaces(Player.Permission.SeniorAdmin.ToString().Length - P.Level.ToString().Length));
|
||||
|
||||
if (count == 2 || E.Owner.getPlayers().Count == 1)
|
||||
{
|
||||
await E.Origin.Tell(playerList.ToString());
|
||||
count = 0;
|
||||
playerList = new StringBuilder();
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Help : Command
|
||||
{
|
||||
public Help(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
String cmd = E.Data.Trim();
|
||||
|
||||
if (cmd.Length > 2)
|
||||
{
|
||||
bool found = false;
|
||||
foreach (Command C in E.Owner.Manager.GetCommands())
|
||||
{
|
||||
if (C.Name.Contains(cmd) || C.Name == cmd)
|
||||
{
|
||||
await E.Origin.Tell(" [^3" + C.Name + "^7] " + C.Description);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
await E.Origin.Tell("Could not find that command");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
int count = 0;
|
||||
StringBuilder helpResponse = new StringBuilder();
|
||||
List<Command> CommandList = E.Owner.Manager.GetCommands();
|
||||
|
||||
foreach (Command C in CommandList)
|
||||
{
|
||||
if (E.Origin.Level >= C.Permission)
|
||||
{
|
||||
helpResponse.Append(" [^3" + C.Name + "^7] ");
|
||||
if (count >= 4)
|
||||
{
|
||||
await E.Origin.Tell(helpResponse.ToString());
|
||||
helpResponse = new StringBuilder();
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
await E.Origin.Tell(helpResponse.ToString());
|
||||
await E.Origin.Tell("Type !help <cmd> to get command usage example");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FastRestart : Command
|
||||
{
|
||||
public FastRestart(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.Broadcast("Performing fast restart...");
|
||||
await Task.Delay(3000);
|
||||
await E.Owner.ExecuteCommandAsync("fast_restart");
|
||||
}
|
||||
}
|
||||
|
||||
class MapRotate : Command
|
||||
{
|
||||
public MapRotate(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.Broadcast("Performing map rotate...");
|
||||
await Task.Delay(3000);
|
||||
await E.Owner.ExecuteCommandAsync("map_rotate");
|
||||
}
|
||||
}
|
||||
|
||||
class SetLevel : Command
|
||||
{
|
||||
public SetLevel(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Target == E.Origin)
|
||||
{
|
||||
await E.Origin.Tell("You can't set your own level, silly.");
|
||||
return;
|
||||
}
|
||||
|
||||
Player.Permission newPerm = Utilities.matchPermission(Utilities.RemoveWords(E.Data, 1));
|
||||
|
||||
if (newPerm > Player.Permission.Banned)
|
||||
{
|
||||
E.Target.setLevel(newPerm);
|
||||
// prevent saving of old permissions on disconnect
|
||||
foreach (var server in E.Owner.Manager.GetServers())
|
||||
{
|
||||
foreach (var player in server.getPlayers())
|
||||
{
|
||||
if (player != null && player.npID == E.Target.npID)
|
||||
{
|
||||
player.setLevel(newPerm);
|
||||
await E.Target.Tell("Congratulations! You have been promoted to ^3" + newPerm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await E.Target.Tell("Congratulations! You have been promoted to ^3" + newPerm);
|
||||
await E.Origin.Tell(E.Target.Name + " was successfully promoted!");
|
||||
|
||||
//NEEED TO MOVE
|
||||
E.Owner.clientDB.updatePlayer(E.Target);
|
||||
}
|
||||
|
||||
else
|
||||
await E.Origin.Tell("Invalid group specified.");
|
||||
}
|
||||
}
|
||||
|
||||
class Usage : Command
|
||||
{
|
||||
public Usage(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Origin.Tell("IW4M Admin is using " + Math.Round(((System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 / 2048f) / 1200f), 1) + "MB");
|
||||
}
|
||||
}
|
||||
|
||||
class Uptime : Command
|
||||
{
|
||||
public Uptime(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
TimeSpan uptime = DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime;
|
||||
await E.Origin.Tell(String.Format("IW4M Admin has been up for {0} days, {1} hours, and {2} minutes", uptime.Days, uptime.Hours, uptime.Minutes));
|
||||
}
|
||||
}
|
||||
|
||||
class Admins : Command
|
||||
{
|
||||
public Admins(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
List<Player> activePlayers = E.Owner.getPlayers();
|
||||
|
||||
foreach (Player P in E.Owner.getPlayers())
|
||||
if (P != null && P.Level > Player.Permission.Flagged && !P.Masked)
|
||||
await E.Origin.Tell(String.Format("[^3{0}^7] {1}", Utilities.levelToColor(P.Level), P.Name));
|
||||
}
|
||||
}
|
||||
|
||||
class MapCMD : Command
|
||||
{
|
||||
public MapCMD(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
string newMap = E.Data.Trim().ToLower();
|
||||
foreach (Map m in E.Owner.maps)
|
||||
{
|
||||
if (m.Name.ToLower() == newMap || m.Alias.ToLower() == newMap)
|
||||
{
|
||||
await E.Owner.Broadcast("Changing to map ^2" + m.Alias);
|
||||
await Task.Delay(5000);
|
||||
await E.Owner.LoadMap(m.Name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await E.Owner.Broadcast("Attempting to change to unknown map ^1" + newMap);
|
||||
await Task.Delay(5000);
|
||||
await E.Owner.LoadMap(newMap);
|
||||
}
|
||||
}
|
||||
|
||||
class Find : Command
|
||||
{
|
||||
public Find(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
var db_players = E.Owner.clientDB.findPlayers(E.Data.Trim());
|
||||
|
||||
if (db_players == null)
|
||||
{
|
||||
await E.Origin.Tell("No players found");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Player P in db_players)
|
||||
{
|
||||
String mesg = String.Format("[^3{0}^7] [^3@{1}^7] - [{2}^7] - {3} | last seen {4} ago", P.Name, P.databaseID, SharedLibrary.Utilities.levelToColor(P.Level), P.IP, P.getLastConnection());
|
||||
await E.Origin.Tell(mesg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FindAll : Command
|
||||
{
|
||||
public FindAll(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Data = E.Data.Trim();
|
||||
|
||||
if (E.Data.Length < 4)
|
||||
{
|
||||
await E.Origin.Tell("You must enter at least 4 letters");
|
||||
return;
|
||||
}
|
||||
|
||||
//var db_players = E.Owner.clientDB.findPlayers(E.Data.Trim());
|
||||
var db_aliases = E.Owner.aliasDB.findPlayers(E.Data);
|
||||
|
||||
if (db_aliases == null)
|
||||
{
|
||||
await E.Origin.Tell("No players found");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Aliases P in db_aliases)
|
||||
{
|
||||
if (P == null)
|
||||
continue;
|
||||
|
||||
String lookingFor = String.Empty;
|
||||
|
||||
foreach(String S in P.Names)
|
||||
{
|
||||
if (S.Contains(E.Data))
|
||||
lookingFor = S;
|
||||
}
|
||||
|
||||
Player Current = E.Owner.clientDB.getPlayer(P.Number);
|
||||
|
||||
if (Current != null)
|
||||
{
|
||||
String mesg = String.Format("^1{0} ^7now goes by ^5{1}^7 [^3{2}^7]", lookingFor, Current.Name, Current.databaseID);
|
||||
await E.Origin.Tell(mesg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Rules : Command
|
||||
{
|
||||
public Rules(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Owner.rules.Count < 1)
|
||||
await E.Origin.Tell("This server has not set any rules.");
|
||||
else
|
||||
{
|
||||
foreach (String r in E.Owner.rules)
|
||||
await E.Origin.Tell("- " + r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PrivateMessage : Command
|
||||
{
|
||||
public PrivateMessage(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Data = Utilities.RemoveWords(E.Data, 1);
|
||||
await E.Target.Tell("^1" + E.Origin.Name + " ^3[PM]^7 - " + E.Data);
|
||||
await E.Origin.Tell(String.Format("To ^3{0} ^7-> {1}", E.Target.Name, E.Data));
|
||||
}
|
||||
}
|
||||
|
||||
class Reload : Command
|
||||
{
|
||||
public Reload(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Owner.Reload())
|
||||
await E.Origin.Tell("Sucessfully reloaded configs!");
|
||||
else
|
||||
await E.Origin.Tell("Unable to reload configs :(");
|
||||
}
|
||||
}
|
||||
|
||||
class Balance : Command
|
||||
{
|
||||
public Balance(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.ExecuteCommandAsync(String.Format("admin_lastevent {0};{1}", "balance", E.Origin.npID)); //Let gsc do the magic
|
||||
}
|
||||
}
|
||||
|
||||
class GoTo : Command
|
||||
{
|
||||
public GoTo(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.ExecuteCommandAsync(String.Format("admin_lastevent {0};{1};{2};{3}", "goto", E.Origin.npID, E.Target.Name, E.Data)); //Let gsc do the magic
|
||||
}
|
||||
}
|
||||
|
||||
class Flag : Command
|
||||
{
|
||||
public Flag(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Target.Level >= E.Origin.Level)
|
||||
{
|
||||
await E.Origin.Tell("You cannot flag " + E.Target.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (E.Target.Level == Player.Permission.Flagged)
|
||||
{
|
||||
E.Target.setLevel(Player.Permission.User);
|
||||
await E.Origin.Tell("You have ^5unflagged ^7" + E.Target.Name);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
E.Target.setLevel(Player.Permission.Flagged);
|
||||
await E.Origin.Tell("You have ^5flagged ^7" + E.Target.Name);
|
||||
}
|
||||
|
||||
E.Owner.clientDB.updatePlayer(E.Target);
|
||||
}
|
||||
}
|
||||
|
||||
class _Report : Command
|
||||
{
|
||||
public _Report(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Owner.Reports.Find(x => (x.Origin == E.Origin && x.Target.npID == E.Target.npID)) != null)
|
||||
{
|
||||
await E.Origin.Tell("You have already reported this player");
|
||||
return;
|
||||
}
|
||||
|
||||
if (E.Target == E.Origin)
|
||||
{
|
||||
await E.Origin.Tell("You cannot report yourself, silly.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (E.Target.Level > E.Origin.Level)
|
||||
{
|
||||
await E.Origin.Tell("You cannot report " + E.Target.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
E.Data = Utilities.RemoveWords(E.Data, 1);
|
||||
E.Owner.Reports.Add(new Report(E.Target, E.Origin, E.Data));
|
||||
|
||||
await E.Origin.Tell("Successfully reported " + E.Target.Name);
|
||||
await E.Owner.ExecuteEvent(new Event(Event.GType.Report, E.Data, E.Origin, E.Target, E.Owner));
|
||||
|
||||
await E.Owner.ToAdmins(String.Format("^5{0}^7->^1{1}^7: {2}", E.Origin.Name, E.Target.Name, E.Data));
|
||||
}
|
||||
}
|
||||
|
||||
class Reports : Command
|
||||
{
|
||||
public Reports(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Data != null && E.Data.ToLower().Contains("clear"))
|
||||
{
|
||||
E.Owner.Reports = new List<Report>();
|
||||
await E.Origin.Tell("Reports successfully cleared!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (E.Owner.Reports.Count < 1)
|
||||
{
|
||||
await E.Origin.Tell("No players reported yet.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Report R in E.Owner.Reports)
|
||||
await E.Origin.Tell(String.Format("^5{0}^7->^1{1}^7: {2}", R.Origin.Name, R.Target.Name, R.Reason));
|
||||
}
|
||||
}
|
||||
|
||||
class _Tell : Command
|
||||
{
|
||||
public _Tell(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Data = Utilities.RemoveWords(E.Data, 1);
|
||||
await E.Owner.ExecuteCommandAsync(String.Format("admin_lastevent tell;{0};{1};{2}", E.Origin.npID, E.Target.npID, E.Data));
|
||||
}
|
||||
}
|
||||
|
||||
class Mask : Command
|
||||
{
|
||||
public Mask(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Origin.Masked)
|
||||
{
|
||||
E.Origin.Masked = false;
|
||||
await E.Origin.Tell("You are now unmasked");
|
||||
}
|
||||
else
|
||||
{
|
||||
E.Origin.Masked = true;
|
||||
await E.Origin.Tell("You are now masked");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BanInfo : Command
|
||||
{
|
||||
public BanInfo(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Target == null)
|
||||
{
|
||||
await E.Origin.Tell("No bans for that player.");
|
||||
return;
|
||||
}
|
||||
|
||||
Penalty B = E.Owner.Bans.Find(b => b.npID.Equals(E.Target.npID));
|
||||
|
||||
if (B == null)
|
||||
{
|
||||
await E.Origin.Tell("No active ban was found for that player.");
|
||||
return;
|
||||
}
|
||||
|
||||
Player Banner = E.Owner.clientDB.getPlayer(B.bannedByID, -1);
|
||||
|
||||
if (Banner == null)
|
||||
{
|
||||
await E.Origin.Tell("Ban was found for the player, but origin of the ban is unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
await E.Origin.Tell(String.Format("^1{0} ^7was banned by ^5{1} ^7for: {2}", E.Target.Name, Banner.Name, B.Reason));
|
||||
}
|
||||
}
|
||||
|
||||
class Alias : Command
|
||||
{
|
||||
public Alias(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
E.Target.Alias = E.Owner.aliasDB.getPlayer(E.Target.databaseID);
|
||||
|
||||
if (E.Target.Alias == null)
|
||||
{
|
||||
await E.Target.Tell("Could not find alias info for that player.");
|
||||
return;
|
||||
}
|
||||
|
||||
await E.Target.Tell("[^3" + E.Target.Name + "^7]");
|
||||
StringBuilder message = new StringBuilder();
|
||||
|
||||
List<Player> playerAliases = E.Owner.getPlayerAliases(E.Target);
|
||||
|
||||
message.Append("Aliases: ");
|
||||
|
||||
foreach (Player P in playerAliases)
|
||||
{
|
||||
foreach (String S in P.Alias.Names)
|
||||
{
|
||||
if (S != String.Empty && S != E.Target.Name)
|
||||
message.Append(S + " | ");
|
||||
}
|
||||
}
|
||||
await E.Origin.Tell(message.ToString());
|
||||
|
||||
message = new StringBuilder();
|
||||
|
||||
if (E.Target.Alias.IPS != null)
|
||||
{
|
||||
message.Append("IPs: ");
|
||||
|
||||
foreach (Player P2 in playerAliases)
|
||||
{
|
||||
foreach (String IP in P2.Alias.IPS)
|
||||
{
|
||||
if (IP.Split('.').Length > 3 && IP != String.Empty && !message.ToString().Contains(IP))
|
||||
message.Append (IP + " | ");
|
||||
}
|
||||
}
|
||||
|
||||
await E.Origin.Tell(message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _RCON : Command
|
||||
{
|
||||
public _RCON(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Origin.currentServer.ExecuteCommandAsync(E.Data.Trim());
|
||||
await E.Origin.Tell("Successfuly sent RCON command!");
|
||||
}
|
||||
}
|
||||
|
||||
class Link : Command
|
||||
{
|
||||
public Link(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Data.Contains("show"))
|
||||
{
|
||||
if (E.Origin.UID == null || E.Origin.UID.Length == 0)
|
||||
await E.Origin.Tell("You have not linked an ID");
|
||||
else
|
||||
await E.Origin.Tell("Your ID is " + E.Origin.UID);
|
||||
}
|
||||
else if (E.Origin.registerUID(E.Data))
|
||||
{
|
||||
E.Owner.clientDB.updatePlayer(E.Origin);
|
||||
await E.Origin.Tell("Your ID has been linked");
|
||||
}
|
||||
else
|
||||
await E.Origin.Tell("That ID is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ namespace SharedLibrary
|
||||
Con = new SQLiteConnection(DBCon);
|
||||
}
|
||||
|
||||
catch(System.DllNotFoundException)
|
||||
catch(DllNotFoundException)
|
||||
{
|
||||
Console.WriteLine("Fatal Error: could not locate the SQLite DLL(s)!\nEnsure they are located in the 'lib' folder");
|
||||
Utilities.Wait(5);
|
||||
System.Environment.Exit(0);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
Open = false;
|
||||
@ -33,50 +33,75 @@ namespace SharedLibrary
|
||||
|
||||
protected bool Insert(String tableName, Dictionary<String, object> data)
|
||||
{
|
||||
String columns = "";
|
||||
String values = "";
|
||||
Boolean returnCode = true;
|
||||
foreach (KeyValuePair<String, object> val in data)
|
||||
string names = "";
|
||||
string parameters = "";
|
||||
foreach (string key in data.Keys)
|
||||
{
|
||||
columns += String.Format(" {0},", val.Key);
|
||||
values += String.Format(" '{0}',", val.Value);
|
||||
names += key + ',';
|
||||
parameters += '@' + key + ',';
|
||||
}
|
||||
columns = columns.Substring(0, columns.Length - 1);
|
||||
values = values.Substring(0, values.Length - 1);
|
||||
names = names.Substring(0, names.Length - 1);
|
||||
parameters = parameters.Substring(0, parameters.Length - 1);
|
||||
|
||||
SQLiteCommand insertcmd = new SQLiteCommand();
|
||||
insertcmd.Connection = this.Con;
|
||||
insertcmd.CommandText = String.Format("INSERT INTO `{0}` ({1}) VALUES ({2});", tableName, names, parameters);
|
||||
|
||||
foreach (string key in data.Keys)
|
||||
{
|
||||
insertcmd.Parameters.AddWithValue('@' + key, data[key]);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.ExecuteNonQuery(String.Format("insert into {0}({1}) values({2});", tableName, columns, values));
|
||||
Con.Open();
|
||||
insertcmd.ExecuteNonQuery();
|
||||
Con.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception fail)
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine(fail.Message);
|
||||
returnCode = false;
|
||||
//LOGME
|
||||
return false;
|
||||
}
|
||||
return returnCode;
|
||||
|
||||
}
|
||||
|
||||
protected bool Update(String tableName, Dictionary<String, object> data, String where)
|
||||
protected bool Update(String tableName, Dictionary<String, object> data, KeyValuePair<string, object> where)
|
||||
{
|
||||
String vals = "";
|
||||
Boolean returnCode = true;
|
||||
if (data.Count >= 1)
|
||||
string parameters = "";
|
||||
foreach (string key in data.Keys)
|
||||
{
|
||||
foreach (KeyValuePair<String, object> val in data)
|
||||
{
|
||||
vals += String.Format(" {0} = '{1}',", val.Key, val.Value);
|
||||
}
|
||||
vals = vals.Substring(0, vals.Length - 1);
|
||||
parameters += key + '=' + '@' + key + ',';
|
||||
}
|
||||
|
||||
parameters = parameters.Substring(0, parameters.Length - 1);
|
||||
|
||||
SQLiteCommand updatecmd = new SQLiteCommand();
|
||||
updatecmd.Connection = this.Con;
|
||||
updatecmd.CommandText = String.Format("UPDATE `{0}` SET {1} WHERE {2}=@{2}", tableName, parameters, where.Key);
|
||||
|
||||
foreach (string key in data.Keys)
|
||||
{
|
||||
updatecmd.Parameters.AddWithValue('@' + key, data[key]);
|
||||
}
|
||||
|
||||
updatecmd.Parameters.AddWithValue('@' + where.Key, where.Value);
|
||||
|
||||
try
|
||||
{
|
||||
ExecuteNonQuery(String.Format("update {0} set {1} where {2};", tableName, vals, where));
|
||||
Con.Open();
|
||||
updatecmd.ExecuteNonQuery();
|
||||
Con.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception fail)
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(fail.Message);
|
||||
returnCode = false;
|
||||
//LOGME
|
||||
return false;
|
||||
}
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
protected DataRow getDataRow(String Q)
|
||||
@ -89,17 +114,53 @@ namespace SharedLibrary
|
||||
{
|
||||
waitForClose();
|
||||
int rowsUpdated = 0;
|
||||
Request = Request.Replace("!'", "").Replace("!", "") ;
|
||||
try
|
||||
{
|
||||
lock (Con)
|
||||
{
|
||||
Con.Open();
|
||||
SQLiteCommand CMD = new SQLiteCommand(Con);
|
||||
CMD.CommandText = Request;
|
||||
rowsUpdated = CMD.ExecuteNonQuery();
|
||||
Con.Close();
|
||||
}
|
||||
return rowsUpdated;
|
||||
}
|
||||
|
||||
lock (Con)
|
||||
catch (Exception E)
|
||||
{
|
||||
Console.WriteLine(E.Message);
|
||||
Console.WriteLine(E.StackTrace);
|
||||
Console.WriteLine(Request);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected DataTable GetDataTable(string tableName, KeyValuePair<string, object> where)
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
SQLiteCommand updatecmd = new SQLiteCommand();
|
||||
updatecmd.Connection = this.Con;
|
||||
updatecmd.CommandText = String.Format("SELECT * FROM {0} WHERE `{1}`=@{1};", tableName, where.Key);
|
||||
updatecmd.Parameters.AddWithValue('@' + where.Key, where.Value);
|
||||
|
||||
try
|
||||
{
|
||||
Con.Open();
|
||||
SQLiteCommand CMD = new SQLiteCommand(Con);
|
||||
CMD.CommandText = Request;
|
||||
rowsUpdated = CMD.ExecuteNonQuery();
|
||||
SQLiteDataReader reader = updatecmd.ExecuteReader();
|
||||
dt.Load(reader);
|
||||
reader.Close();
|
||||
Con.Close();
|
||||
}
|
||||
|
||||
return rowsUpdated;
|
||||
catch (Exception e)
|
||||
{
|
||||
//LOGME
|
||||
Console.Write("Couldnotexecute");
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
protected DataTable GetDataTable(String sql)
|
||||
@ -123,7 +184,7 @@ namespace SharedLibrary
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e.Message + " GetDataTable");
|
||||
return new DataTable();
|
||||
}
|
||||
return dt;
|
||||
@ -153,7 +214,7 @@ namespace SharedLibrary
|
||||
{
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
String Create = "CREATE TABLE [CLIENTS] ( [Name] TEXT NULL, [npID] TEXT NULL, [Number] INTEGER PRIMARY KEY AUTOINCREMENT, [Level] INT DEFAULT 0 NULL, [LastOffense] TEXT NULL, [Connections] INT DEFAULT 1 NULL, [IP] TEXT NULL, [LastConnection] TEXT NULL);";
|
||||
String Create = "CREATE TABLE [CLIENTS] ( [Name] TEXT NULL, [npID] TEXT NULL, [Number] INTEGER PRIMARY KEY AUTOINCREMENT, [Level] INT DEFAULT 0 NULL, [LastOffense] TEXT NULL, [Connections] INT DEFAULT 1 NULL, [IP] TEXT NULL, [LastConnection] TEXT NULL, [UID] TEXT NULL, [Masked] INT DEFAULT 0);";
|
||||
ExecuteNonQuery(Create);
|
||||
Create = "CREATE TABLE [BANS] ( [TYPE] TEXT NULL, [Reason] TEXT NULL, [npID] TEXT NULL, [bannedByID] TEXT NULL, [IP] TEXT NULL, [TIME] TEXT NULL);";
|
||||
ExecuteNonQuery(Create);
|
||||
@ -172,13 +233,33 @@ namespace SharedLibrary
|
||||
DateTime lastCon = DateTime.MinValue;
|
||||
DateTime.TryParse(ResponseRow["LastConnection"].ToString(), out lastCon);
|
||||
|
||||
return new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), cNum, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon);
|
||||
return new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), cNum, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon, ResponseRow["UID"].ToString(), ResponseRow["Masked"].ToString() == "1");
|
||||
}
|
||||
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Player> getRecentPlayers()
|
||||
{
|
||||
List<Player> returnssss = new List<Player>();
|
||||
String Query = String.Format("SELECT * FROM CLIENTS ORDER BY LastConnection desc LIMIT 25");
|
||||
DataTable Result = GetDataTable(Query);
|
||||
|
||||
if (Result != null && Result.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow ResponseRow in Result.Rows)
|
||||
{
|
||||
DateTime lastCon = DateTime.MinValue;
|
||||
DateTime.TryParse(ResponseRow["LastConnection"].ToString(), out lastCon);
|
||||
|
||||
returnssss.Add(new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), -1, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon, ResponseRow["UID"].ToString(), ResponseRow["Masked"].ToString() == "1"));
|
||||
}
|
||||
}
|
||||
|
||||
return returnssss;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers(List<String> npIDs)
|
||||
{
|
||||
List<Player> returnssss = new List<Player>();
|
||||
@ -194,7 +275,7 @@ namespace SharedLibrary
|
||||
DateTime lastCon = DateTime.MinValue;
|
||||
DateTime.TryParse(ResponseRow["LastConnection"].ToString(), out lastCon);
|
||||
|
||||
returnssss.Add(new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), -1, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon));
|
||||
returnssss.Add(new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), -1, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon, ResponseRow["UID"].ToString(), ResponseRow["Masked"].ToString() == "1"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +297,7 @@ namespace SharedLibrary
|
||||
DateTime lastCon = DateTime.MinValue;
|
||||
DateTime.TryParse(ResponseRow["LastConnection"].ToString(), out lastCon);
|
||||
|
||||
returnssss.Add(new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), -1, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon));
|
||||
returnssss.Add(new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), -1, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), ResponseRow["LastOffense"].ToString(), (int)ResponseRow["Connections"], ResponseRow["IP"].ToString(), lastCon, ResponseRow["UID"].ToString(), ResponseRow["Masked"].ToString() == "1"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,7 +323,7 @@ namespace SharedLibrary
|
||||
LC = DateTime.MinValue;
|
||||
}
|
||||
|
||||
return new Player(p["Name"].ToString(), p["npID"].ToString(), -1, (Player.Permission)(p["Level"]), Convert.ToInt32(p["Number"]), p["LastOffense"].ToString(), Convert.ToInt32(p["Connections"]), p["IP"].ToString(), LC);
|
||||
return new Player(p["Name"].ToString(), p["npID"].ToString(), -1, (Player.Permission)(p["Level"]), Convert.ToInt32(p["Number"]), p["LastOffense"].ToString(), Convert.ToInt32(p["Connections"]), p["IP"].ToString(), LC, p["UID"].ToString(), p["Masked"].ToString() == "1");
|
||||
}
|
||||
|
||||
else
|
||||
@ -264,7 +345,7 @@ namespace SharedLibrary
|
||||
try
|
||||
{
|
||||
LC = DateTime.Parse(p["LastConnection"].ToString());
|
||||
lastKnown.Add(new Player(p["Name"].ToString(), p["npID"].ToString(), -1, (Player.Permission)(p["Level"]), Convert.ToInt32(p["Number"]), p["LastOffense"].ToString(), Convert.ToInt32((DateTime.Now - LC).TotalSeconds), p["IP"].ToString(), LC));
|
||||
lastKnown.Add(new Player(p["Name"].ToString(), p["npID"].ToString(), -1, (Player.Permission)(p["Level"]), Convert.ToInt32(p["Number"]), p["LastOffense"].ToString(), Convert.ToInt32((DateTime.Now - LC).TotalSeconds), p["IP"].ToString(), LC, p["UID"].ToString(), p["Masked"].ToString() == "1"));
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
@ -301,16 +382,21 @@ namespace SharedLibrary
|
||||
foreach (DataRow p in Result.Rows)
|
||||
{
|
||||
DateTime LC;
|
||||
string Masked = null;
|
||||
try
|
||||
{
|
||||
LC = DateTime.Parse(p["LastConnection"].ToString());
|
||||
Masked = p["Masked"].ToString();
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (Masked == null)
|
||||
Masked = "0";
|
||||
|
||||
LC = DateTime.MinValue;
|
||||
}
|
||||
|
||||
Players.Add(new Player(p["Name"].ToString(), p["npID"].ToString(), -1, (Player.Permission)(p["Level"]), Convert.ToInt32(p["Number"]), p["LastOffense"].ToString(), Convert.ToInt32(p["Connections"]), p["IP"].ToString(), LC));
|
||||
Players.Add(new Player(p["Name"].ToString(), p["npID"].ToString(), -1, (Player.Permission)(p["Level"]), Convert.ToInt32(p["Number"]), p["LastOffense"].ToString(), Convert.ToInt32(p["Connections"]), p["IP"].ToString(), LC, p["IP"].ToString(), Masked == "1"));
|
||||
}
|
||||
return Players;
|
||||
}
|
||||
@ -352,7 +438,7 @@ namespace SharedLibrary
|
||||
if (Row["TYPE"].ToString().Length != 0)
|
||||
BanType = (Penalty.Type)Enum.Parse(typeof(Penalty.Type), Row["TYPE"].ToString());
|
||||
|
||||
Bans.Add(new Penalty(BanType, Row["Reason"].ToString(), Row["npID"].ToString(), Row["bannedByID"].ToString(), DateTime.Parse(Row["TIME"].ToString()), Row["IP"].ToString()));
|
||||
Bans.Add(new Penalty(BanType, Row["Reason"].ToString().Trim(), Row["npID"].ToString(), Row["bannedByID"].ToString(), DateTime.Parse(Row["TIME"].ToString()), Row["IP"].ToString()));
|
||||
|
||||
}
|
||||
|
||||
@ -363,11 +449,11 @@ namespace SharedLibrary
|
||||
public List<Player> getAdmins()
|
||||
{
|
||||
List<Player> Admins = new List<Player>();
|
||||
String Query = String.Format("SELECT * FROM CLIENTS WHERE LEVEL > '{0}'", 1);
|
||||
String Query = String.Format("SELECT * FROM CLIENTS WHERE Level >= '{0}'", (int)Player.Permission.Moderator);
|
||||
DataTable Result = GetDataTable(Query);
|
||||
|
||||
foreach (DataRow P in Result.Rows)
|
||||
Admins.Add(new Player(P["Name"].ToString(), P["npID"].ToString(), (Player.Permission)P["Level"], P["IP"].ToString()));
|
||||
Admins.Add(new Player(P["Name"].ToString(), P["npID"].ToString(), (Player.Permission)P["Level"], P["IP"].ToString(), P["UID"].ToString()));
|
||||
|
||||
return Admins;
|
||||
}
|
||||
@ -394,6 +480,8 @@ namespace SharedLibrary
|
||||
newPlayer.Add("Connections", 1);
|
||||
newPlayer.Add("IP", P.IP);
|
||||
newPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
||||
newPlayer.Add("UID", P.UID);
|
||||
newPlayer.Add("Masked", Convert.ToInt32(P.Masked));
|
||||
|
||||
Insert("CLIENTS", newPlayer);
|
||||
}
|
||||
@ -410,8 +498,10 @@ namespace SharedLibrary
|
||||
updatedPlayer.Add("Connections", P.Connections);
|
||||
updatedPlayer.Add("IP", P.IP);
|
||||
updatedPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
||||
updatedPlayer.Add("UID", P.UID);
|
||||
updatedPlayer.Add("Masked", Convert.ToInt32(P.Masked));
|
||||
|
||||
Update("CLIENTS", updatedPlayer, String.Format("npID = '{0}'", P.npID));
|
||||
Update("CLIENTS", updatedPlayer, new KeyValuePair<string, object>("npID", P.npID ));
|
||||
}
|
||||
|
||||
|
||||
@ -420,7 +510,7 @@ namespace SharedLibrary
|
||||
{
|
||||
Dictionary<String, object> newBan = new Dictionary<String, object>();
|
||||
|
||||
newBan.Add("Reason", B.Reason);
|
||||
newBan.Add("Reason", Utilities.removeNastyChars(B.Reason));
|
||||
newBan.Add("npID", B.npID);
|
||||
newBan.Add("bannedByID", B.bannedByID);
|
||||
newBan.Add("IP", B.IP);
|
||||
@ -515,7 +605,7 @@ namespace SharedLibrary
|
||||
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||
|
||||
newPlayer.Add("Number", Alias.Number);
|
||||
newPlayer.Add("NAMES", String.Join(";", Alias.Names));
|
||||
newPlayer.Add("NAMES", Utilities.removeNastyChars(String.Join(";", Alias.Names)));
|
||||
newPlayer.Add("IPS", String.Join(";", Alias.IPS));
|
||||
|
||||
Insert("ALIASES", newPlayer);
|
||||
@ -529,7 +619,7 @@ namespace SharedLibrary
|
||||
updatedPlayer.Add("NAMES", String.Join(";", Alias.Names));
|
||||
updatedPlayer.Add("IPS", String.Join(";", Alias.IPS));
|
||||
|
||||
Update("ALIASES", updatedPlayer, String.Format("Number = '{0}'", Alias.Number));
|
||||
Update("ALIASES", updatedPlayer, new KeyValuePair<string, object>("Number", Alias.Number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,15 @@ namespace SharedLibrary
|
||||
public int min;
|
||||
public int max;
|
||||
}
|
||||
|
||||
public class _DVAR<T>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public T Value;
|
||||
|
||||
public _DVAR(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,15 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
[Serializable]
|
||||
public class Chat
|
||||
{
|
||||
public Chat(Player O, String M, DateTime D)
|
||||
public Chat(string O, String M, DateTime D)
|
||||
{
|
||||
Origin = O;
|
||||
Name = O;
|
||||
Message = M;
|
||||
Time = D;
|
||||
|
||||
}
|
||||
|
||||
public String timeString()
|
||||
@ -19,11 +21,49 @@ namespace SharedLibrary
|
||||
return Time.ToShortTimeString();
|
||||
}
|
||||
|
||||
public Player Origin { get; private set; }
|
||||
//public Player Origin { get; private set; }
|
||||
public String Message { get; private set; }
|
||||
public DateTime Time { get; private set; }
|
||||
public string Name;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct RestEvent
|
||||
{
|
||||
public RestEvent(eType Ty, eVersion V, string M, string T, string O, string Ta)
|
||||
{
|
||||
Type = Ty;
|
||||
Version = V;
|
||||
Message = M;
|
||||
Title = T;
|
||||
Origin = O;
|
||||
Target = Ta;
|
||||
|
||||
ID = Math.Abs(DateTime.Now.GetHashCode());
|
||||
}
|
||||
|
||||
public enum eType
|
||||
{
|
||||
NOTIFICATION,
|
||||
STATUS,
|
||||
ALERT,
|
||||
}
|
||||
|
||||
public enum eVersion
|
||||
{
|
||||
IW4MAdmin
|
||||
}
|
||||
|
||||
public eType Type;
|
||||
public eVersion Version;
|
||||
public string Message;
|
||||
public string Title;
|
||||
public string Origin;
|
||||
public string Target;
|
||||
public int ID;
|
||||
}
|
||||
|
||||
|
||||
public class Event
|
||||
{
|
||||
public enum GType
|
||||
@ -44,7 +84,11 @@ namespace SharedLibrary
|
||||
Tell,
|
||||
Kick,
|
||||
Ban,
|
||||
Remote,
|
||||
Unknown,
|
||||
|
||||
//FROM PLAYER
|
||||
Report
|
||||
}
|
||||
|
||||
public Event(GType t, string d, Player O, Player T, Server S)
|
||||
@ -100,7 +144,7 @@ namespace SharedLibrary
|
||||
if (eventType == ":")
|
||||
return new Event(GType.MapEnd, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
|
||||
|
||||
if (line[0].Split('\\').Length > 5) // blaze it
|
||||
if (line[0].Contains("InitGame")) // blaze it
|
||||
return new Event(GType.MapChange, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
|
||||
|
||||
|
||||
@ -121,5 +165,6 @@ namespace SharedLibrary
|
||||
public Player Origin;
|
||||
public Player Target;
|
||||
public Server Owner;
|
||||
public Boolean Remote = false;
|
||||
}
|
||||
}
|
||||
|
15
SharedLibrary/Exceptions/CommandException.cs
Normal file
15
SharedLibrary/Exceptions/CommandException.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Exceptions
|
||||
{
|
||||
public class CommandException : ServerException
|
||||
{
|
||||
public CommandException(string msg) : base(msg) { }
|
||||
// .data contains
|
||||
// "command_name"
|
||||
}
|
||||
}
|
13
SharedLibrary/Exceptions/DvarException.cs
Normal file
13
SharedLibrary/Exceptions/DvarException.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Exceptions
|
||||
{
|
||||
public class DvarException : ServerException
|
||||
{
|
||||
public DvarException(string msg) : base(msg) { }
|
||||
}
|
||||
}
|
13
SharedLibrary/Exceptions/NetworkException.cs
Normal file
13
SharedLibrary/Exceptions/NetworkException.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Exceptions
|
||||
{
|
||||
public class NetworkException : ServerException
|
||||
{
|
||||
public NetworkException(string msg) : base(msg) { }
|
||||
}
|
||||
}
|
13
SharedLibrary/Exceptions/ServerException.cs
Normal file
13
SharedLibrary/Exceptions/ServerException.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Exceptions
|
||||
{
|
||||
public class ServerException : Exception
|
||||
{
|
||||
public ServerException(string msg) : base(msg) { }
|
||||
}
|
||||
}
|
18
SharedLibrary/Extensions/IPlugin.cs
Normal file
18
SharedLibrary/Extensions/IPlugin.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Extensions
|
||||
{
|
||||
public interface IPlugin
|
||||
{
|
||||
Task OnLoad();
|
||||
Task OnUnload();
|
||||
Task OnEvent(Event E, Server S);
|
||||
Task OnTick(Server S);
|
||||
|
||||
//for logging purposes
|
||||
String Name { get; }
|
||||
float Version { get; }
|
||||
String Author { get; }
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
@ -10,18 +11,24 @@ namespace SharedLibrary
|
||||
public IFile(String fileName)
|
||||
{
|
||||
//Not safe for directories with more than one folder but meh
|
||||
_Directory = fileName.Split('\\')[0];
|
||||
Name = (fileName.Split('\\'))[fileName.Split('\\').Length - 1];
|
||||
string[] asd = fileName.Split('/');
|
||||
|
||||
if (!Directory.Exists(_Directory))
|
||||
Directory.CreateDirectory(_Directory);
|
||||
if (asd[0] != "")
|
||||
_Directory = asd[0];
|
||||
else
|
||||
_Directory = asd[2];
|
||||
|
||||
Name = (fileName.Split('/'))[fileName.Split('/').Length - 1];
|
||||
|
||||
//if (!Directory.Exists(_Directory))
|
||||
// Directory.CreateDirectory(_Directory);
|
||||
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream penis = File.Create(fileName);
|
||||
penis.Close();
|
||||
//FileStream penis = File.Create(fileName);
|
||||
//penis.Close();
|
||||
}
|
||||
|
||||
catch
|
||||
@ -49,6 +56,16 @@ namespace SharedLibrary
|
||||
sze = 0;
|
||||
}
|
||||
|
||||
public IFile()
|
||||
{
|
||||
WebClient request = new WebClient();
|
||||
string url = $"http://raidmax.org/logs/IW4X/games_mp.log";
|
||||
byte[] newFileData = request.DownloadData(url);
|
||||
|
||||
Handle = new StreamReader(new MemoryStream(newFileData));
|
||||
sze = Handle.BaseStream.Length;
|
||||
}
|
||||
|
||||
public long getSize()
|
||||
{
|
||||
sze = Handle.BaseStream.Length;
|
||||
@ -59,8 +76,16 @@ namespace SharedLibrary
|
||||
{
|
||||
if (writeHandle != null)
|
||||
{
|
||||
writeHandle.WriteLine(line);
|
||||
writeHandle.Flush();
|
||||
try
|
||||
{
|
||||
writeHandle.WriteLine(line);
|
||||
writeHandle.Flush();
|
||||
}
|
||||
|
||||
catch (Exception E)
|
||||
{
|
||||
Console.WriteLine("Error during flush", E.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
17
SharedLibrary/Interfaces/IManager.cs
Normal file
17
SharedLibrary/Interfaces/IManager.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Interfaces
|
||||
{
|
||||
public interface IManager
|
||||
{
|
||||
void Init();
|
||||
void Start();
|
||||
void Stop();
|
||||
List<Server> GetServers();
|
||||
List<Command> GetCommands();
|
||||
}
|
||||
}
|
51
SharedLibrary/Interfaces/ISerializable.cs
Normal file
51
SharedLibrary/Interfaces/ISerializable.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace SharedLibrary.Interfaces
|
||||
{
|
||||
interface ISerializable<T>
|
||||
{
|
||||
void Write();
|
||||
}
|
||||
|
||||
public class SerializeException : Exception
|
||||
{
|
||||
public SerializeException(string msg) : base(msg) { }
|
||||
}
|
||||
|
||||
public class Serialize<T> : ISerializable<T>
|
||||
{
|
||||
public static T Read(string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
string configText = File.ReadAllText(filename);
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(configText);
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SerializeException($"Could not desialize file {filename}: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Write()
|
||||
{
|
||||
try
|
||||
{
|
||||
string configText = Newtonsoft.Json.JsonConvert.SerializeObject(this);
|
||||
File.WriteAllText(Filename(), configText);
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SerializeException($"Could not serialize file {Filename()}: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string Filename() { return this.ToString(); }
|
||||
}
|
||||
}
|
@ -15,5 +15,10 @@ namespace SharedLibrary
|
||||
|
||||
public String Name { get; private set; }
|
||||
public String Alias { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace SharedLibrary
|
||||
{
|
||||
public Penalty(Type BType, String Reas, String TargID, String From, DateTime time, String ip)
|
||||
{
|
||||
Reason = Reas;
|
||||
Reason = Reas.Replace("!","");
|
||||
npID = TargID;
|
||||
bannedByID = From;
|
||||
When = time;
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
@ -35,6 +36,11 @@ namespace SharedLibrary
|
||||
Console = 8,
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return ((Player)obj).npID == this.npID;
|
||||
}
|
||||
|
||||
public Player(string n, string id, int num, int l)
|
||||
{
|
||||
Name = n;
|
||||
@ -59,12 +65,14 @@ namespace SharedLibrary
|
||||
LastConnection = DateTime.Now;
|
||||
}
|
||||
|
||||
public Player(string n, string id, Player.Permission P, String I)
|
||||
public Player(String n, String id, Player.Permission P, String I, String UID)
|
||||
{
|
||||
Name = n;
|
||||
npID = id;
|
||||
Level = P;
|
||||
IP = I;
|
||||
clientID = -1;
|
||||
this.UID = UID;
|
||||
}
|
||||
|
||||
public Player(string n, string id, int num, Player.Permission l, int cind, String lo, int con, String IP2)
|
||||
@ -85,7 +93,7 @@ namespace SharedLibrary
|
||||
LastConnection = DateTime.Now;
|
||||
}
|
||||
|
||||
public Player(string n, string id, int num, Player.Permission l, int cind, String lo, int con, String IP2, DateTime LC)
|
||||
public Player(string n, string id, int num, Player.Permission l, int cind, String lo, int con, String IP2, DateTime LC, string UID, bool masked)
|
||||
{
|
||||
Name = n;
|
||||
npID = id;
|
||||
@ -101,6 +109,16 @@ namespace SharedLibrary
|
||||
Warnings = 0;
|
||||
Masked = false;
|
||||
LastConnection = LC;
|
||||
this.UID = UID.Trim();
|
||||
Masked = masked;
|
||||
}
|
||||
|
||||
public bool registerUID(String UID)
|
||||
{
|
||||
if (UID.Length > 5)
|
||||
this.UID = UID;
|
||||
|
||||
return this.UID == UID;
|
||||
}
|
||||
|
||||
public String getLastConnection()
|
||||
@ -124,34 +142,29 @@ namespace SharedLibrary
|
||||
Level = Perm;
|
||||
}
|
||||
|
||||
public void Tell(String Message)
|
||||
public async Task Tell(String Message)
|
||||
{
|
||||
lastEvent.Owner.Tell(Message, this);
|
||||
await lastEvent.Owner.Tell(Message, this);
|
||||
}
|
||||
|
||||
public void Kick(String Message, Player Sender)
|
||||
public async Task Kick(String Message, Player Sender)
|
||||
{
|
||||
lastEvent.Owner.Kick(Message, this, Sender);
|
||||
await lastEvent.Owner.Kick(Message, this, Sender);
|
||||
}
|
||||
|
||||
public void tempBan(String Message, Player Sender)
|
||||
public async Task TempBan(String Message, Player Sender)
|
||||
{
|
||||
lastEvent.Owner.tempBan(Message, this, Sender);
|
||||
await lastEvent.Owner.TempBan(Message, this, Sender);
|
||||
}
|
||||
|
||||
public void Warn(String Message, Player Sender)
|
||||
public async Task Warn(String Message, Player Sender)
|
||||
{
|
||||
lastEvent.Owner.Warn(Message, this, Sender);
|
||||
await lastEvent.Owner.Warn(Message, this, Sender);
|
||||
}
|
||||
|
||||
public void Ban(String Message, Player Sender)
|
||||
public async Task Ban(String Message, Player Sender)
|
||||
{
|
||||
lastEvent.Owner.Ban(Message, this, Sender);
|
||||
}
|
||||
|
||||
public void Alert()
|
||||
{
|
||||
lastEvent.Owner.Alert(this);
|
||||
await lastEvent.Owner.Ban(Message, this, Sender);
|
||||
}
|
||||
|
||||
public String Name { get; private set; }
|
||||
@ -161,6 +174,7 @@ namespace SharedLibrary
|
||||
public int databaseID { get; private set; }
|
||||
public int Connections { get; set; }
|
||||
public String IP { get; private set; }
|
||||
public String UID { get; private set; }
|
||||
public DateTime LastConnection { get; private set; }
|
||||
public Server currentServer { get; private set; }
|
||||
|
||||
@ -169,5 +183,6 @@ namespace SharedLibrary
|
||||
public int Warnings;
|
||||
public Aliases Alias;
|
||||
public bool Masked;
|
||||
public int selectedServer;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public abstract class Plugin
|
||||
{
|
||||
public abstract void onLoad();
|
||||
public abstract void onUnload();
|
||||
public abstract void onEvent(Event E);
|
||||
|
||||
//for logging purposes
|
||||
public abstract String Name { get; }
|
||||
public abstract float Version { get; }
|
||||
public abstract String Author { get; }
|
||||
}
|
||||
}
|
172
SharedLibrary/RCON.cs
Normal file
172
SharedLibrary/RCON.cs
Normal file
@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace SharedLibrary.Network
|
||||
{
|
||||
public static class RCON
|
||||
{
|
||||
enum QueryType
|
||||
{
|
||||
GET_STATUS,
|
||||
GET_INFO,
|
||||
DVAR,
|
||||
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;
|
||||
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];
|
||||
|
||||
Player P = new Player(cName, npID, cID, cIP);
|
||||
StatusPlayers.Add(P);
|
||||
}
|
||||
}
|
||||
|
||||
return StatusPlayers;
|
||||
}
|
||||
|
||||
static string[] SendQuery(QueryType Type, Server QueryServer, string Parameters = "")
|
||||
{
|
||||
var ServerOOBConnection = new System.Net.Sockets.UdpClient();
|
||||
ServerOOBConnection.Client.SendTimeout = 1000;
|
||||
ServerOOBConnection.Client.ReceiveTimeout = 1000;
|
||||
var Endpoint = new IPEndPoint(IPAddress.Parse(QueryServer.getIP()), QueryServer.getPort());
|
||||
|
||||
string QueryString = String.Empty;
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case QueryType.DVAR:
|
||||
case QueryType.COMMAND:
|
||||
QueryString = $"ÿÿÿÿrcon {QueryServer.Password} {Parameters}";
|
||||
break;
|
||||
case QueryType.GET_STATUS:
|
||||
QueryString = "ÿÿÿÿ getstatus";
|
||||
break;
|
||||
}
|
||||
|
||||
byte[] Payload = GetRequestBytes(QueryString);
|
||||
|
||||
int attempts = 0;
|
||||
retry:
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
ServerOOBConnection.Connect(Endpoint);
|
||||
ServerOOBConnection.Send(Payload, Payload.Length);
|
||||
|
||||
byte[] ReceiveBuffer = new byte[8192];
|
||||
StringBuilder QueryResponseString = new StringBuilder();
|
||||
|
||||
do
|
||||
{
|
||||
ReceiveBuffer = ServerOOBConnection.Receive(ref Endpoint);
|
||||
QueryResponseString.Append(Encoding.ASCII.GetString(ReceiveBuffer).TrimEnd('\0'));
|
||||
} while (ServerOOBConnection.Available > 0);
|
||||
|
||||
ServerOOBConnection.Close();
|
||||
|
||||
if (QueryResponseString.ToString().Contains("Invalid password"))
|
||||
throw new Exceptions.NetworkException("RCON password is invalid");
|
||||
|
||||
int num = int.Parse("0a", System.Globalization.NumberStyles.AllowHexSpecifier);
|
||||
string[] SplitResponse = QueryResponseString.ToString().Split(new char[] { (char)num }, StringSplitOptions.RemoveEmptyEntries);
|
||||
return SplitResponse;
|
||||
}
|
||||
|
||||
catch (SocketException)
|
||||
{
|
||||
attempts++;
|
||||
if (attempts > 5)
|
||||
{
|
||||
var e = new Exceptions.NetworkException("Cannot communicate with server");
|
||||
e.Data["server_address"] = ServerOOBConnection.Client.RemoteEndPoint.ToString();
|
||||
ServerOOBConnection.Close();
|
||||
throw e;
|
||||
}
|
||||
|
||||
Thread.Sleep(1000);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<_DVAR<T>> GetDvarAsync<T>(this Server server, string dvarName)
|
||||
{
|
||||
string[] LineSplit = await Task.FromResult(SendQuery(QueryType.DVAR, server, dvarName));
|
||||
|
||||
if (LineSplit.Length != 3)
|
||||
{
|
||||
var e = new Exceptions.DvarException("DVAR does not exist");
|
||||
e.Data["dvar_name"] = dvarName;
|
||||
throw e;
|
||||
}
|
||||
|
||||
string[] ValueSplit = LineSplit[1].Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (ValueSplit.Length != 5)
|
||||
{
|
||||
var e = new Exceptions.DvarException("DVAR does not exist");
|
||||
e.Data["dvar_name"] = dvarName;
|
||||
throw e;
|
||||
}
|
||||
|
||||
string DvarName = Regex.Replace(ValueSplit[0], @"\^[0-9]", "");
|
||||
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)) };
|
||||
}
|
||||
|
||||
public static async Task SetDvarAsync(this Server server, string dvarName, object dvarValue)
|
||||
{
|
||||
await Task.FromResult(SendQuery(QueryType.DVAR, server, $"{dvarName} {dvarValue}"));
|
||||
}
|
||||
|
||||
public static async Task ExecuteCommandAsync(this Server server, string commandName)
|
||||
{
|
||||
await Task.FromResult(SendQuery(QueryType.COMMAND, server, commandName));
|
||||
}
|
||||
|
||||
public static async Task<List<Player>> GetStatusAsync(this Server server)
|
||||
{
|
||||
string[] response = await Task.FromResult(SendQuery(QueryType.DVAR, server, "status"));
|
||||
return PlayersFromStatus(response);
|
||||
}
|
||||
|
||||
|
||||
static byte[] GetRequestBytes(string Request)
|
||||
{
|
||||
|
||||
Byte[] initialRequestBytes = Encoding.Unicode.GetBytes(Request);
|
||||
Byte[] fixedRequest = new Byte[initialRequestBytes.Length / 2];
|
||||
|
||||
for (int i = 0; i < initialRequestBytes.Length; i++)
|
||||
if (initialRequestBytes[i] != 0)
|
||||
fixedRequest[i / 2] = initialRequestBytes[i];
|
||||
|
||||
return fixedRequest;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
using SharedLibrary.Network;
|
||||
using SharedLibrary.Commands;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
[Guid("61d3829e-fcbe-44d3-bb7c-51db8c2d7ac5")]
|
||||
public abstract class Server
|
||||
{
|
||||
public Server(string address, int port, string password, int H, int PID)
|
||||
public Server(Interfaces.IManager mgr, string address, int port, string password)
|
||||
{
|
||||
this.PID = PID;
|
||||
Handle = H;
|
||||
Password = password;
|
||||
IP = address;
|
||||
Port = port;
|
||||
clientnum = 0;
|
||||
logFile = new IFile("admin_" + port + ".log", true);
|
||||
Manager = mgr;
|
||||
ClientNum = 0;
|
||||
logFile = new IFile($"Logs/{address}_{port}.log", true);
|
||||
#if DEBUG
|
||||
Log = new Log(logFile, Log.Level.Debug, port);
|
||||
#else
|
||||
Log = new Log(logFile, Log.Level.Production, port);
|
||||
#endif
|
||||
clientDB = new ClientsDB("clients.rm");
|
||||
aliasDB = new AliasesDB("aliases.rm");
|
||||
clientDB = new ClientsDB("Database/clients.rm");
|
||||
aliasDB = new AliasesDB("Database/aliases.rm");
|
||||
|
||||
Bans = new List<Penalty>();
|
||||
players = new List<Player>(new Player[18]);
|
||||
Players = new List<Player>(new Player[18]);
|
||||
events = new Queue<Event>();
|
||||
Macros = new Dictionary<String, Object>();
|
||||
Reports = new List<Report>();
|
||||
@ -33,22 +40,54 @@ namespace SharedLibrary
|
||||
chatHistory = new List<Chat>();
|
||||
lastWebChat = DateTime.Now;
|
||||
nextMessage = 0;
|
||||
initCommands();
|
||||
initMacros();
|
||||
initMessages();
|
||||
initMaps();
|
||||
initRules();
|
||||
|
||||
var commands = mgr.GetCommands();
|
||||
|
||||
owner = clientDB.getOwner();
|
||||
|
||||
if (owner == null)
|
||||
commands.Add(new Owner("owner", "claim ownership of the server", "owner", Player.Permission.User, 0, false));
|
||||
|
||||
commands.Add(new Quit("quit", "quit IW4MAdmin", "q", Player.Permission.Owner, 0, false));
|
||||
commands.Add(new Kick("kick", "kick a player by name. syntax: !kick <player> <reason>.", "k", Player.Permission.Trusted, 2, true));
|
||||
commands.Add(new Say("say", "broadcast message to all players. syntax: !say <message>.", "s", Player.Permission.Moderator, 1, false));
|
||||
commands.Add(new TempBan("tempban", "temporarily ban a player for 1 hour. syntax: !tempban <player> <reason>.", "tb", Player.Permission.Moderator, 2, true));
|
||||
commands.Add(new SBan("ban", "permanently ban a player from the server. syntax: !ban <player> <reason>", "b", Player.Permission.SeniorAdmin, 2, true));
|
||||
commands.Add(new WhoAmI("whoami", "give information about yourself. syntax: !whoami.", "who", Player.Permission.User, 0, false));
|
||||
commands.Add(new List("list", "list active clients syntax: !list.", "l", Player.Permission.Moderator, 0, false));
|
||||
commands.Add(new Help("help", "list all available commands. syntax: !help.", "h", Player.Permission.User, 0, false));
|
||||
commands.Add(new FastRestart("fastrestart", "fast restart current map. syntax: !fastrestart.", "fr", Player.Permission.Moderator, 0, false));
|
||||
commands.Add(new MapRotate("maprotate", "cycle to the next map in rotation. syntax: !maprotate.", "mr", Player.Permission.Administrator, 0, false));
|
||||
commands.Add(new SetLevel("setlevel", "set player to specified administration level. syntax: !setlevel <player> <level>.", "sl", Player.Permission.Owner, 2, true));
|
||||
commands.Add(new Usage("usage", "get current application memory usage. syntax: !usage.", "us", Player.Permission.Moderator, 0, false));
|
||||
commands.Add(new Uptime("uptime", "get current application running time. syntax: !uptime.", "up", Player.Permission.Moderator, 0, false));
|
||||
commands.Add(new Warn("warn", "warn player for infringing rules syntax: !warn <player> <reason>.", "w", Player.Permission.Trusted, 2, true));
|
||||
commands.Add(new WarnClear("warnclear", "remove all warning for a player syntax: !warnclear <player>.", "wc", Player.Permission.Trusted, 1, true));
|
||||
commands.Add(new Unban("unban", "unban player by database id. syntax: !unban @<id>.", "ub", Player.Permission.SeniorAdmin, 1, true));
|
||||
commands.Add(new Admins("admins", "list currently connected admins. syntax: !admins.", "a", Player.Permission.User, 0, false));
|
||||
commands.Add(new MapCMD("map", "change to specified map. syntax: !map", "m", Player.Permission.Administrator, 1, false));
|
||||
commands.Add(new Find("find", "find player in database. syntax: !find <player>", "f", Player.Permission.SeniorAdmin, 1, false));
|
||||
commands.Add(new Rules("rules", "list server rules. syntax: !rules", "r", Player.Permission.User, 0, false));
|
||||
commands.Add(new PrivateMessage("privatemessage", "send message to other player. syntax: !pm <player> <message>", "pm", Player.Permission.User, 2, true));
|
||||
commands.Add(new Flag("flag", "flag a suspicious player and announce to admins on join . syntax !flag <player>:", "flag", Player.Permission.Moderator, 1, true));
|
||||
commands.Add(new _Report("report", "report a player for suspicious behaivor. syntax !report <player> <reason>", "rep", Player.Permission.User, 2, true));
|
||||
commands.Add(new Reports("reports", "get most recent reports. syntax !reports", "reports", Player.Permission.Moderator, 0, false));
|
||||
commands.Add(new _Tell("tell", "send onscreen message to player. syntax !tell <player> <message>", "t", Player.Permission.Moderator, 2, true));
|
||||
commands.Add(new Mask("mask", "hide your online presence from online admin list. syntax: !mask", "mask", Player.Permission.Administrator, 0, false));
|
||||
commands.Add(new BanInfo("baninfo", "get information about a ban for a player. syntax: !baninfo <player>", "bi", Player.Permission.Moderator, 1, true));
|
||||
commands.Add(new Alias("alias", "get past aliases and ips of a player. syntax: !alias <player>", "known", Player.Permission.Moderator, 1, true));
|
||||
commands.Add(new _RCON("rcon", "send rcon command to server. syntax: !rcon <command>", "rcon", Player.Permission.Owner, 1, false));
|
||||
commands.Add(new FindAll("findall", "find a player by their aliase(s). syntax: !findall <player>", "fa", Player.Permission.Moderator, 1, false));
|
||||
}
|
||||
|
||||
//Returns the current server name -- *STRING*
|
||||
public String getName()
|
||||
{
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public String getMap()
|
||||
{
|
||||
return mapname;
|
||||
return Hostname;
|
||||
}
|
||||
|
||||
public String getGametype()
|
||||
@ -71,29 +110,13 @@ namespace SharedLibrary
|
||||
//Returns number of active clients on server -- *INT*
|
||||
public int getNumPlayers()
|
||||
{
|
||||
return clientnum;
|
||||
}
|
||||
|
||||
//Returns the list of commands
|
||||
public List<Command> getCommands()
|
||||
{
|
||||
return commands;
|
||||
return ClientNum;
|
||||
}
|
||||
|
||||
//Returns list of all current players
|
||||
public List<Player> getPlayers()
|
||||
{
|
||||
return players;
|
||||
}
|
||||
|
||||
public int getClientNum()
|
||||
{
|
||||
return clientnum;
|
||||
}
|
||||
|
||||
public int getMaxClients()
|
||||
{
|
||||
return maxClients;
|
||||
return Players.FindAll(x => x != null);
|
||||
}
|
||||
|
||||
//Returns list of all active bans (loaded at runtime)
|
||||
@ -123,21 +146,19 @@ namespace SharedLibrary
|
||||
return clientDB.getPlayers(databaseIDs);
|
||||
}
|
||||
|
||||
abstract public void Stop();
|
||||
|
||||
/// <summary>
|
||||
/// Add a player to the server's player list
|
||||
/// </summary>
|
||||
/// <param name="P">Player pulled from memory reading</param>
|
||||
/// <returns>True if player added sucessfully, false otherwise</returns>
|
||||
abstract public bool addPlayer(Player P);
|
||||
abstract public Task<bool> AddPlayer(Player P);
|
||||
|
||||
/// <summary>
|
||||
/// Remove player by client number
|
||||
/// </summary>
|
||||
/// <param name="cNum">Client ID of player to be removed</param>
|
||||
/// <returns>true if removal succeded, false otherwise</returns>
|
||||
abstract public bool removePlayer(int cNum);
|
||||
abstract public Task RemovePlayer(int cNum);
|
||||
|
||||
/// <summary>
|
||||
/// Get the player from the server's list by line from game long
|
||||
@ -154,9 +175,9 @@ namespace SharedLibrary
|
||||
/// <returns>Matching player if found</returns>
|
||||
public Player clientFromName(String pName)
|
||||
{
|
||||
lock (players)
|
||||
lock (Players)
|
||||
{
|
||||
foreach (var P in players)
|
||||
foreach (var P in Players)
|
||||
{
|
||||
if (P != null && P.Name.ToLower().Contains(pName.ToLower()))
|
||||
return P;
|
||||
@ -179,123 +200,93 @@ namespace SharedLibrary
|
||||
/// <param name="E">Event parameter</param>
|
||||
/// <param name="C">Command requested from the event</param>
|
||||
/// <returns></returns>
|
||||
abstract public Command processCommand(Event E, Command C);
|
||||
abstract public Task<Command> ProcessCommand(Event E, Command C);
|
||||
|
||||
/// <summary>
|
||||
/// Execute a command on the server
|
||||
/// </summary>
|
||||
/// <param name="CMD">Command to execute</param>
|
||||
abstract public void executeCommand(String CMD);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a Dvar from the server
|
||||
/// </summary>
|
||||
/// <param name="DvarName">Name of Dvar to retrieve</param>
|
||||
/// <returns>Dvar if found</returns>
|
||||
abstract public dvar getDvar(String DvarName);
|
||||
|
||||
/// <summary>
|
||||
/// Set a Dvar on the server
|
||||
/// </summary>
|
||||
/// <param name="Dvar">Name of the</param>
|
||||
/// <param name="Value"></param>
|
||||
abstract public void setDvar(String Dvar, String Value);
|
||||
|
||||
/// <summary>
|
||||
/// Main loop for the monitoring processes of the server ( handles events and connects/disconnects )
|
||||
/// </summary>
|
||||
abstract public void Monitor();
|
||||
virtual public Task<int> ProcessUpdatesAsync()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set up the basic variables ( base path / hostname / etc ) that allow the monitor thread to work
|
||||
/// </summary>
|
||||
/// <returns>True if no issues initializing, false otherwise</returns>
|
||||
abstract public bool intializeBasics();
|
||||
//abstract public bool intializeBasics();
|
||||
|
||||
/// <summary>
|
||||
/// Process any server event
|
||||
/// </summary>
|
||||
/// <param name="E">Event</param>
|
||||
/// <returns>True on sucess</returns>
|
||||
abstract public bool processEvent(Event E);
|
||||
abstract protected Task ProcessEvent(Event E);
|
||||
abstract public Task ExecuteEvent(Event E);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads all the server configurations
|
||||
/// </summary>
|
||||
/// <returns>True on sucess</returns>
|
||||
abstract public bool Reload();
|
||||
abstract public bool _Reload();
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to all players
|
||||
/// </summary>
|
||||
/// <param name="Message">Message to be sent to all players</param>
|
||||
public void Broadcast(String Message)
|
||||
public async Task Broadcast(String Message)
|
||||
{
|
||||
executeCommand("sayraw " + Message);
|
||||
await this.ExecuteCommandAsync($"sayraw {Message}");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to a particular players
|
||||
/// </summary>
|
||||
/// <param name="Message">Message to send</param>
|
||||
/// <param name="Target">Player to send message to</param>
|
||||
public void Tell(String Message, Player Target)
|
||||
public async Task Tell(String Message, Player Target)
|
||||
{
|
||||
if (Target.clientID > -1 && Message.Length > 0)
|
||||
executeCommand("tellraw " + Target.clientID + " " + Message + "^7");
|
||||
if (Target.clientID > -1 && Message.Length > 0 && Target.Level != Player.Permission.Console && !Target.lastEvent.Remote)
|
||||
await this.ExecuteCommandAsync($"tellraw {Target.clientID} {Message}^7");
|
||||
|
||||
if (Target.Level == Player.Permission.Console)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine(Utilities.stripColors(Message));
|
||||
Console.WriteLine(Utilities.StripColors(Message));
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
if (Target.lastEvent.Remote)
|
||||
commandResult.Enqueue(Utilities.StripColors(Message));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to all admins on the server
|
||||
/// </summary>
|
||||
/// <param name="message">Message to send out</param>
|
||||
public void ToAdmins(String message)
|
||||
public async Task ToAdmins(String message)
|
||||
{
|
||||
lock (players) // threading can modify list while we do this
|
||||
foreach (Player P in Players)
|
||||
{
|
||||
foreach (Player P in players)
|
||||
{
|
||||
if (P == null)
|
||||
continue;
|
||||
if (P == null)
|
||||
continue;
|
||||
|
||||
if (P.Level > Player.Permission.Flagged)
|
||||
{
|
||||
P.Alert();
|
||||
P.Tell(message);
|
||||
}
|
||||
}
|
||||
if (P.Level > Player.Permission.Flagged)
|
||||
await P.Tell(message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alert a player via gsc implementation
|
||||
/// </summary>
|
||||
/// <param name="P"></param>
|
||||
public void Alert(Player P)
|
||||
{
|
||||
executeCommand("admin_lastevent alert;" + P.npID + ";0;mp_killstreak_nuclearstrike");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kick a player from the server
|
||||
/// </summary>
|
||||
/// <param name="Reason">Reason for kicking</param>
|
||||
/// <param name="Target">Player to kick</param>
|
||||
abstract public void Kick(String Reason, Player Target, Player Origin);
|
||||
abstract public Task Kick(String Reason, Player Target, Player Origin);
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily ban a player ( default 1 hour ) from the server
|
||||
/// </summary>
|
||||
/// <param name="Reason">Reason for banning the player</param>
|
||||
/// <param name="Target">The player to ban</param>
|
||||
abstract public void tempBan(String Reason, Player Target, Player Origin);
|
||||
abstract public Task TempBan(String Reason, Player Target, Player Origin);
|
||||
|
||||
/// <summary>
|
||||
/// Perm ban a player from the server
|
||||
@ -303,9 +294,9 @@ namespace SharedLibrary
|
||||
/// <param name="Reason">The reason for the ban</param>
|
||||
/// <param name="Target">The person to ban</param>
|
||||
/// <param name="Origin">The person who banned the target</param>
|
||||
abstract public void Ban(String Reason, Player Target, Player Origin);
|
||||
abstract public Task Ban(String Reason, Player Target, Player Origin);
|
||||
|
||||
abstract public void Warn(String Reason, Player Target, Player Origin);
|
||||
abstract public Task Warn(String Reason, Player Target, Player Origin);
|
||||
|
||||
/// <summary>
|
||||
/// Unban a player by npID / GUID
|
||||
@ -313,43 +304,20 @@ namespace SharedLibrary
|
||||
/// <param name="npID">npID of the player</param>
|
||||
/// <param name="Target">I don't remember what this is for</param>
|
||||
/// <returns></returns>
|
||||
abstract public bool Unban(String npID, Player Target);
|
||||
|
||||
/// <summary>
|
||||
/// Fast restart the server with a specified delay
|
||||
/// </summary>
|
||||
/// <param name="delay"></param>
|
||||
public void fastRestart(int delay)
|
||||
{
|
||||
Utilities.Wait(delay);
|
||||
executeCommand("fast_restart");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rotate the server to the next map with specified delay
|
||||
/// </summary>
|
||||
/// <param name="delay"></param>
|
||||
public void mapRotate(int delay)
|
||||
{
|
||||
Utilities.Wait(delay);
|
||||
executeCommand("map_rotate");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Map rotate without delay
|
||||
/// </summary>
|
||||
public void mapRotate()
|
||||
{
|
||||
mapRotate(0);
|
||||
}
|
||||
abstract public Task Unban(String npID, Player Target);
|
||||
|
||||
/// <summary>
|
||||
/// Change the current searver map
|
||||
/// </summary>
|
||||
/// <param name="mapName">Non-localized map name</param>
|
||||
public void Map(String mapName)
|
||||
public async Task LoadMap(string mapName)
|
||||
{
|
||||
executeCommand("map " + mapName);
|
||||
await this.ExecuteCommandAsync($"map {mapName}");
|
||||
}
|
||||
|
||||
public async Task LoadMap(Map newMap)
|
||||
{
|
||||
await this.ExecuteCommandAsync($"map {newMap.Name}");
|
||||
}
|
||||
|
||||
public void webChat(Player P, String Message)
|
||||
@ -359,13 +327,13 @@ namespace SharedLibrary
|
||||
if ((requestTime - lastWebChat).TotalSeconds > 1)
|
||||
{
|
||||
Broadcast("^1[WEBCHAT] ^5" + P.Name + "^7 - " + Message);
|
||||
while (chatHistory.Count > Math.Ceiling((double)clientnum / 2))
|
||||
while (chatHistory.Count > Math.Ceiling((double)ClientNum / 2))
|
||||
chatHistory.RemoveAt(0);
|
||||
|
||||
if (Message.Length > 50)
|
||||
Message = Message.Substring(0, 50) + "...";
|
||||
|
||||
chatHistory.Add(new Chat(P, Utilities.stripColors(Message), DateTime.Now));
|
||||
chatHistory.Add(new Chat(P.Name, Utilities.StripColors(Message), DateTime.Now));
|
||||
lastWebChat = DateTime.Now;
|
||||
}
|
||||
}
|
||||
@ -382,7 +350,7 @@ namespace SharedLibrary
|
||||
{
|
||||
maps = new List<Map>();
|
||||
|
||||
IFile mapfile = new IFile("config\\maps.cfg");
|
||||
IFile mapfile = new IFile("config/maps.cfg");
|
||||
String[] _maps = mapfile.readAll();
|
||||
mapfile.Close();
|
||||
if (_maps.Length > 2) // readAll returns minimum one empty string
|
||||
@ -408,7 +376,7 @@ namespace SharedLibrary
|
||||
{
|
||||
messages = new List<String>();
|
||||
|
||||
IFile messageCFG = new IFile("config\\messages.cfg");
|
||||
IFile messageCFG = new IFile("config/messages.cfg");
|
||||
String[] lines = messageCFG.readAll();
|
||||
messageCFG.Close();
|
||||
|
||||
@ -445,7 +413,7 @@ namespace SharedLibrary
|
||||
{
|
||||
rules = new List<String>();
|
||||
|
||||
IFile ruleFile = new IFile("config\\rules.cfg");
|
||||
IFile ruleFile = new IFile("config/rules.cfg");
|
||||
String[] _rules = ruleFile.readAll();
|
||||
ruleFile.Close();
|
||||
if (_rules.Length > 2) // readAll returns minimum one empty string
|
||||
@ -468,6 +436,7 @@ namespace SharedLibrary
|
||||
abstract public void initCommands();
|
||||
|
||||
//Objects
|
||||
public Interfaces.IManager Manager { get; protected set; }
|
||||
public Log Log { get; private set; }
|
||||
public List<Penalty> Bans;
|
||||
public Player owner;
|
||||
@ -484,21 +453,22 @@ namespace SharedLibrary
|
||||
//Info
|
||||
protected String IP;
|
||||
protected int Port;
|
||||
protected String hostname;
|
||||
protected String mapname;
|
||||
protected int clientnum;
|
||||
protected List<Player> players;
|
||||
protected List<Command> commands;
|
||||
public String Hostname { get; protected set; }
|
||||
public Map CurrentMap { get; protected set; }
|
||||
protected string FSGame;
|
||||
public int ClientNum { get; protected set; }
|
||||
public int MaxClients { get; protected set; }
|
||||
public List<Player> Players { get; protected set; }
|
||||
protected List<String> messages;
|
||||
protected int messageTime;
|
||||
protected TimeSpan lastMessage;
|
||||
protected DateTime lastPoll;
|
||||
protected int nextMessage;
|
||||
protected String IW_Ver;
|
||||
protected int maxClients;
|
||||
|
||||
protected Dictionary<String, Object> Macros;
|
||||
protected DateTime lastWebChat;
|
||||
protected int Handle;
|
||||
public string Password { get; private set; }
|
||||
public int Handle { get; private set; }
|
||||
protected int PID;
|
||||
protected IFile logFile;
|
||||
|
||||
@ -507,12 +477,13 @@ namespace SharedLibrary
|
||||
public bool isRunning;
|
||||
|
||||
// Log stuff
|
||||
protected String Basepath;
|
||||
protected String Mod;
|
||||
protected String logPath;
|
||||
|
||||
// Databases
|
||||
public ClientsDB clientDB;
|
||||
public AliasesDB aliasDB;
|
||||
|
||||
//Remote
|
||||
public Queue<String> commandResult = new Queue<string>();
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,9 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SharedLibrary</RootNamespace>
|
||||
<AssemblyName>SharedLibrary</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@ -21,6 +22,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@ -30,11 +32,16 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
@ -47,7 +54,14 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Ban.cs" />
|
||||
<Compile Include="Commands\NativeCommands.cs" />
|
||||
<Compile Include="Exceptions\CommandException.cs" />
|
||||
<Compile Include="Exceptions\DvarException.cs" />
|
||||
<Compile Include="Exceptions\NetworkException.cs" />
|
||||
<Compile Include="Exceptions\ServerException.cs" />
|
||||
<Compile Include="Interfaces\IManager.cs" />
|
||||
<Compile Include="Interfaces\ISerializable.cs" />
|
||||
<Compile Include="Penalty.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="Database.cs" />
|
||||
<Compile Include="Event.cs" />
|
||||
@ -57,15 +71,25 @@
|
||||
<Compile Include="Map.cs" />
|
||||
<Compile Include="Miscellaneous.cs" />
|
||||
<Compile Include="Player.cs" />
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="Extensions\IPlugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RCON.cs" />
|
||||
<Compile Include="Report.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="WebService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)Admin\lib\SharedLibrary.dll"</PostBuildEvent>
|
||||
<PostBuildEvent>mkdir "$(SolutionDir)Admin\$(OutDir)plugins
|
||||
copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\lib"
|
||||
copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)Admin\lib"
|
||||
copy /Y "$(TargetDir)System.Data.SQLite.dll" "$(SolutionDir)BUILD\lib"
|
||||
copy /Y "$(TargetDir)Newtonsoft.Json.dll" "$(SolutionDir)BUILD\lib"
|
||||
copy /Y "$(TargetDir)Newtonsoft.Json.dll" "$(SolutionDir)Admin\lib"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@ -1,5 +1,4 @@
|
||||
#define REPZ_BUILD
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -7,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public class Utilities
|
||||
public static class Utilities
|
||||
{
|
||||
//Get string with specified number of spaces -- really only for visual output
|
||||
public static String getSpaces(int Num)
|
||||
@ -29,8 +28,11 @@ namespace SharedLibrary
|
||||
}
|
||||
|
||||
//Remove words from a space delimited string
|
||||
public static String removeWords(String str, int num)
|
||||
public static String RemoveWords(this string str, int num)
|
||||
{
|
||||
if (str == null || str.Length == 0)
|
||||
return "";
|
||||
|
||||
String newStr = String.Empty;
|
||||
String[] tmp = str.Split(' ');
|
||||
|
||||
@ -62,27 +64,15 @@ namespace SharedLibrary
|
||||
public static String removeNastyChars(String str)
|
||||
{
|
||||
if (str != null)
|
||||
return str.Replace("`", "").Replace("\\", "").Replace("\"", "").Replace(""", "").Replace("&", "&").Replace("\"", "''").Replace("'", "");
|
||||
{
|
||||
return str.Replace("`", "").Replace("\\", "").Replace("\"", "").Replace(""", "").Replace("&", "&").Replace("\"", "''").Replace("'", "").Replace("?", "");
|
||||
}
|
||||
|
||||
else
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public static int GetLineNumber(Exception ex)
|
||||
{
|
||||
var lineNumber = 0;
|
||||
const string lineSearch = ":line ";
|
||||
var index = ex.StackTrace.LastIndexOf(lineSearch);
|
||||
if (index != -1)
|
||||
{
|
||||
var lineNumberText = ex.StackTrace.Substring(index + lineSearch.Length);
|
||||
if (int.TryParse(lineNumberText, out lineNumber))
|
||||
{
|
||||
}
|
||||
}
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
public static String cleanChars(String S)
|
||||
public static String CleanChars(this string S)
|
||||
{
|
||||
if (S == null)
|
||||
return "";
|
||||
@ -99,11 +89,11 @@ namespace SharedLibrary
|
||||
/// </summary>
|
||||
/// <param name="str">String containing color codes</param>
|
||||
/// <returns></returns>
|
||||
public static String stripColors(String str)
|
||||
public static String StripColors(this string str)
|
||||
{
|
||||
if (str == null)
|
||||
return "";
|
||||
return Regex.Replace(str, @"\^[0-9]", "");
|
||||
return Regex.Replace(str, @"\^([0-9]|\:)", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -130,83 +120,7 @@ namespace SharedLibrary
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HTML formatted level color
|
||||
/// </summary>
|
||||
/// <param name="Level">Specified player level</param>
|
||||
/// <returns></returns>
|
||||
public static String levelHTMLFormatted(Player.Permission Level)
|
||||
{
|
||||
switch (Level)
|
||||
{
|
||||
case Player.Permission.User:
|
||||
return "<span style='color:rgb(87, 150, 66)'>" + Level + "</span>";
|
||||
case Player.Permission.Moderator:
|
||||
return "<span style='color:#e7b402'>" + Level + "</span>";
|
||||
case Player.Permission.Administrator:
|
||||
return "<span style='color:#ec82de'>" + Level + "</span>";
|
||||
case Player.Permission.SeniorAdmin:
|
||||
return "<span style='color:#2eb6bf'>" + Level + "</span>";
|
||||
case Player.Permission.Owner:
|
||||
return "<span style='color:rgb(38,120,230)'>" + Level + "</span>";
|
||||
case Player.Permission.Creator:
|
||||
return "<span style='color:rgb(38,120,230)'>" + Level + "</span>";
|
||||
case Player.Permission.Banned:
|
||||
return "<span style='color:rgb(196, 22, 28)'>" + Level + "</span>";
|
||||
case Player.Permission.Flagged:
|
||||
return "<span style='color:rgb(251, 124, 98)'>" + Level + "</span>";
|
||||
case Player.Permission.Trusted:
|
||||
return "<span style='color:orange'>" + Level + "</span>";
|
||||
default:
|
||||
return "<i>" + Level + "</i>";
|
||||
}
|
||||
}
|
||||
|
||||
public static String nameHTMLFormatted(Player P)
|
||||
{
|
||||
switch (P.Level)
|
||||
{
|
||||
case Player.Permission.User:
|
||||
return "<span style='color:rgb(87, 150, 66)'>" + P.Name + "</span>";
|
||||
case Player.Permission.Moderator:
|
||||
return "<span style='color:#e7b402'>" + P.Name + "</span>";
|
||||
case Player.Permission.Administrator:
|
||||
return "<span style='color:#ec82de'>" + P.Name + "</span>";
|
||||
case Player.Permission.SeniorAdmin:
|
||||
return "<span style='color:#2eb6bf'>" + P.Name + "</span>";
|
||||
case Player.Permission.Owner:
|
||||
return "<span style='color:rgb(38,120,230)'>" + P.Name + "</span>";
|
||||
case Player.Permission.Creator:
|
||||
return "<span style='color:rgb(38,120,230)'>" + P.Name + "</span>";
|
||||
case Player.Permission.Banned:
|
||||
return "<span style='color:rgb(196, 22, 28)'>" + P.Name + "</span>";
|
||||
case Player.Permission.Flagged:
|
||||
return "<span style='color:rgb(251, 124, 98)'>" + P.Name + "</span>";
|
||||
case Player.Permission.Trusted:
|
||||
return "<span style='color:orange'>" + P.Name + "</span>";
|
||||
default:
|
||||
return "<i>" + P.Name + "</i>";
|
||||
}
|
||||
}
|
||||
|
||||
public static String penaltyHTMLFormatted(Penalty.Type BType)
|
||||
{
|
||||
switch(BType)
|
||||
{
|
||||
case Penalty.Type.Ban:
|
||||
return "<span style='color:rgb(196, 22, 28)'>" + BType.ToString() + "</span>";
|
||||
case Penalty.Type.TempBan:
|
||||
return "<span style='color:#E6840C'>" + BType.ToString() + "</span>";
|
||||
case Penalty.Type.Kick:
|
||||
return "<span style='color:#8A0578'>" + BType.ToString() + "</span>";
|
||||
case Penalty.Type.Warning:
|
||||
return "<span style='color:#CAB11D'>" + BType.ToString() + "</span>";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String processMacro(Dictionary<String, Object> Dict, String str)
|
||||
public static String LoadMacro(Dictionary<String, Object> Dict, String str)
|
||||
{
|
||||
MatchCollection Found = Regex.Matches(str, @"\{\{[A-Z]+\}\}", RegexOptions.IgnoreCase);
|
||||
foreach (Match M in Found)
|
||||
@ -280,32 +194,46 @@ namespace SharedLibrary
|
||||
case "oneflag":
|
||||
return "One Flag CTF";
|
||||
default:
|
||||
return "Unknown";
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public static String DateTimeSQLite(DateTime datetime)
|
||||
{
|
||||
string dateTimeFormat = "{0}-{1}-{2} {3}:{4}:{5}.{6}";
|
||||
return string.Format(dateTimeFormat, datetime.Year, datetime.Month, datetime.Day, datetime.Hour, datetime.Minute, datetime.Second, datetime.Millisecond);
|
||||
return datetime.ToString("yyyy-MM-dd H:mm:ss");
|
||||
}
|
||||
|
||||
public static String timePassed(DateTime start)
|
||||
{
|
||||
TimeSpan Elapsed = DateTime.Now - start;
|
||||
|
||||
if (Elapsed.TotalSeconds < 30)
|
||||
return "just now";
|
||||
if (Elapsed.TotalMinutes < 120)
|
||||
{
|
||||
if (Elapsed.TotalMinutes < 1.5)
|
||||
return "1 minute";
|
||||
return Math.Round(Elapsed.TotalMinutes, 0) + " minutes";
|
||||
}
|
||||
if (Elapsed.TotalHours <= 24)
|
||||
{
|
||||
if (Elapsed.TotalHours < 1.5)
|
||||
return "1 hour";
|
||||
return Math.Round(Elapsed.TotalHours, 0) + " hours";
|
||||
}
|
||||
if (Elapsed.TotalDays <= 365)
|
||||
{
|
||||
if (Elapsed.TotalDays < 1.5)
|
||||
return "1 day";
|
||||
return Math.Round(Elapsed.TotalDays, 0) + " days";
|
||||
}
|
||||
else
|
||||
return "a very long time";
|
||||
}
|
||||
|
||||
public static String timesConnected(int connection)
|
||||
public static String TimesConnected(this Player P)
|
||||
{
|
||||
int connection = P.Connections;
|
||||
String Prefix = String.Empty;
|
||||
if (connection % 10 > 3 || connection % 10 == 0 || (connection % 100 > 9 && connection % 100 < 19))
|
||||
Prefix = "th";
|
||||
@ -349,17 +277,5 @@ namespace SharedLibrary
|
||||
return connection.ToString() + Prefix;
|
||||
}
|
||||
}
|
||||
|
||||
public static Int64 getForumIDFromStr(String npID)
|
||||
{
|
||||
Int64 forumID = 0;
|
||||
if (npID.Length == 16)
|
||||
{
|
||||
forumID = Int64.Parse(npID.Substring(0, 16), System.Globalization.NumberStyles.AllowHexSpecifier);
|
||||
forumID = forumID - 76561197960265728;
|
||||
}
|
||||
|
||||
return forumID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
102
SharedLibrary/WebService.cs
Normal file
102
SharedLibrary/WebService.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public class WebService
|
||||
{
|
||||
public static List<IPage> pageList { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
pageList = new List<IPage>();
|
||||
}
|
||||
}
|
||||
|
||||
public struct HttpResponse
|
||||
{
|
||||
public string contentType;
|
||||
public string content;
|
||||
public Dictionary<string, string> additionalHeaders;
|
||||
}
|
||||
|
||||
public interface IPage
|
||||
{
|
||||
string getPath();
|
||||
string getName();
|
||||
HttpResponse getPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers);
|
||||
bool isVisible();
|
||||
}
|
||||
|
||||
public abstract class HTMLPage : IPage
|
||||
{
|
||||
private bool visible;
|
||||
|
||||
public HTMLPage()
|
||||
{
|
||||
visible = true;
|
||||
}
|
||||
|
||||
public HTMLPage(bool visible)
|
||||
{
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
protected string getContentType()
|
||||
{
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
protected string loadFile(string filename)
|
||||
{
|
||||
string s;
|
||||
|
||||
IFile HTML = new IFile(filename);
|
||||
s = HTML.getLines();
|
||||
HTML.Close();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
protected string loadHeader()
|
||||
{
|
||||
return loadFile("webfront\\header.html");
|
||||
}
|
||||
|
||||
protected string loadFooter()
|
||||
{
|
||||
return loadFile("webfront\\footer.html");
|
||||
}
|
||||
|
||||
public bool isVisible()
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
|
||||
virtual public string getPath()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
abstract public string getName();
|
||||
virtual public Dictionary<string, string> getHeaders(IDictionary<string, string> requestHeaders)
|
||||
{
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
abstract public string getContent(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers);
|
||||
|
||||
|
||||
public HttpResponse getPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> headers)
|
||||
{
|
||||
HttpResponse resp = new HttpResponse()
|
||||
{
|
||||
content = getContent(querySet, headers),
|
||||
contentType = getContentType(),
|
||||
additionalHeaders = getHeaders(headers)
|
||||
};
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
}
|
4
SharedLibrary/packages.config
Normal file
4
SharedLibrary/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
|
||||
</packages>
|
Reference in New Issue
Block a user