Massive refactoring and rudimentary plugin support.
This commit is contained in:
parent
d3e42541ea
commit
cd85a5c384
186
Admin/Command.cs
186
Admin/Command.cs
@ -1,64 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
abstract class Command
|
|
||||||
{
|
|
||||||
public Command(String N, String D, String U, Player.Permission P, int args, bool nT)
|
|
||||||
{
|
|
||||||
Name = N;
|
|
||||||
Description = D;
|
|
||||||
Usage = U;
|
|
||||||
Permission = P;
|
|
||||||
Arguments = args;
|
|
||||||
hasTarget = nT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get command name
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
//Get description on command
|
|
||||||
public String getDescription()
|
|
||||||
{
|
|
||||||
return Description;
|
|
||||||
}
|
|
||||||
//Get the example usage of the command
|
|
||||||
public String getAlias()
|
|
||||||
{
|
|
||||||
return Usage;
|
|
||||||
}
|
|
||||||
//Get the required permission to execute the command
|
|
||||||
public Player.Permission getNeededPerm()
|
|
||||||
{
|
|
||||||
return Permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumArgs()
|
|
||||||
{
|
|
||||||
return Arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool needsTarget()
|
|
||||||
{
|
|
||||||
return hasTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Execute the command
|
|
||||||
abstract public void Execute(Event E);
|
|
||||||
|
|
||||||
private String Name;
|
|
||||||
private String Description;
|
|
||||||
private String Usage;
|
|
||||||
private int Arguments;
|
|
||||||
private bool hasTarget;
|
|
||||||
|
|
||||||
public Player.Permission Permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Owner : Command
|
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 Owner(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||||
@ -83,13 +29,13 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
if (E.Origin.getLevel() <= E.Target.getLevel())
|
if (E.Origin.Level <= E.Target.Level)
|
||||||
E.Origin.Tell("You cannot warn " + E.Target.getName());
|
E.Origin.Tell("You cannot warn " + E.Target.Name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E.Target.LastOffense = Utilities.removeWords(E.Data, 1);
|
E.Target.lastOffense = Utilities.removeWords(E.Data, 1);
|
||||||
E.Target.Warnings++;
|
E.Target.Warnings++;
|
||||||
String Message = String.Format("^1WARNING ^7[^3{0}^7]: ^3{1}^7, {2}", E.Target.Warnings, E.Target.getName(), E.Target.LastOffense);
|
String Message = String.Format("^1WARNING ^7[^3{0}^7]: ^3{1}^7, {2}", E.Target.Warnings, E.Target.Name, E.Target.lastOffense);
|
||||||
E.Owner.Broadcast(Message);
|
E.Owner.Broadcast(Message);
|
||||||
if (E.Target.Warnings >= 4)
|
if (E.Target.Warnings >= 4)
|
||||||
E.Target.Kick("You were kicked for too many warnings!");
|
E.Target.Kick("You were kicked for too many warnings!");
|
||||||
@ -103,9 +49,9 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Target.LastOffense = String.Empty;
|
E.Target.lastOffense = String.Empty;
|
||||||
E.Target.Warnings = 0;
|
E.Target.Warnings = 0;
|
||||||
String Message = String.Format("All warning cleared for {0}", E.Target.getName());
|
String Message = String.Format("All warning cleared for {0}", E.Target.Name);
|
||||||
E.Owner.Broadcast(Message);
|
E.Owner.Broadcast(Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,12 +62,12 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Target.LastOffense = Utilities.removeWords(E.Data, 1);
|
E.Target.lastOffense = Utilities.removeWords(E.Data, 1);
|
||||||
String Message = "^1Player Kicked: ^5" + E.Target.LastOffense + " ^1Admin: ^5" + E.Origin.getName();
|
String Message = "^1Player Kicked: ^5" + E.Target.lastOffense + " ^1Admin: ^5" + E.Origin.Name;
|
||||||
if (E.Origin.getLevel() > E.Target.getLevel())
|
if (E.Origin.Level > E.Target.Level)
|
||||||
E.Target.Kick(Message);
|
E.Target.Kick(Message);
|
||||||
else
|
else
|
||||||
E.Origin.Tell("You cannot kick " + E.Target.getName());
|
E.Origin.Tell("You cannot kick " + E.Target.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +77,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Owner.Broadcast("^1" + E.Origin.getName() + " - ^6" + E.Data + "^7");
|
E.Owner.Broadcast("^1" + E.Origin.Name + " - ^6" + E.Data + "^7");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,12 +87,12 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Target.LastOffense = Utilities.removeWords(E.Data, 1);
|
E.Target.lastOffense = Utilities.removeWords(E.Data, 1);
|
||||||
String Message = "^1Player Temporarily Banned: ^5" + E.Target.LastOffense + "^7 (1 hour)";
|
String Message = "^1Player Temporarily Banned: ^5" + E.Target.lastOffense + "^7 (1 hour)";
|
||||||
if (E.Origin.getLevel() > E.Target.getLevel())
|
if (E.Origin.Level > E.Target.Level)
|
||||||
E.Target.tempBan(Message);
|
E.Target.tempBan(Message);
|
||||||
else
|
else
|
||||||
E.Origin.Tell("You cannot temp ban " + E.Target.getName());
|
E.Origin.Tell("You cannot temp ban " + E.Target.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,20 +102,20 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Target.LastOffense = Utilities.removeWords(E.Data, 1);
|
E.Target.lastOffense = Utilities.removeWords(E.Data, 1);
|
||||||
E.Target.lastEvent = E; // needs to be fixed
|
E.Target.lastEvent = E; // needs to be fixed
|
||||||
String Message;
|
String Message;
|
||||||
if (E.Owner.Website == null)
|
if (E.Owner.Website == null)
|
||||||
Message = "^1Player Banned: ^5" + E.Target.LastOffense;
|
Message = "^1Player Banned: ^5" + E.Target.lastOffense;
|
||||||
else
|
else
|
||||||
Message = "^1Player Banned: ^5" + E.Target.LastOffense + "^7 (appeal " + E.Owner.Website;
|
Message = "^1Player Banned: ^5" + E.Target.lastOffense + "^7 (appeal " + E.Owner.Website;
|
||||||
if (E.Origin.getLevel() > E.Target.getLevel())
|
if (E.Origin.Level > E.Target.Level)
|
||||||
{
|
{
|
||||||
E.Target.Ban(Message, E.Origin);
|
E.Target.Ban(Message, E.Origin);
|
||||||
E.Origin.Tell(String.Format("Sucessfully banned ^5{0} ^7({1})", E.Target.getName(), E.Target.getID()));
|
E.Origin.Tell(String.Format("Sucessfully banned ^5{0} ^7({1})", E.Target.Name, E.Target.npID));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
E.Origin.Tell("You cannot ban " + E.Target.getName());
|
E.Origin.Tell("You cannot ban " + E.Target.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +126,7 @@ namespace IW4MAdmin
|
|||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
if (E.Owner.Unban(E.Data.Trim(), E.Target))
|
if (E.Owner.Unban(E.Data.Trim(), E.Target))
|
||||||
E.Origin.Tell("Successfully unbanned " + E.Target.getName());
|
E.Origin.Tell("Successfully unbanned " + E.Target.Name);
|
||||||
else
|
else
|
||||||
E.Origin.Tell("Unable to find a ban for that GUID");
|
E.Origin.Tell("Unable to find a ban for that GUID");
|
||||||
}
|
}
|
||||||
@ -192,7 +138,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
String You = String.Format("{0} [^3#{1}^7] {2} [^3@{3}^7] [{4}^7] IP: {5}", E.Origin.getName(), E.Origin.getClientNum(), E.Origin.getID(), E.Origin.getDBID(), Utilities.levelToColor(E.Origin.getLevel()), E.Origin.getIP());
|
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, Utilities.levelToColor(E.Origin.Level), E.Origin.IP);
|
||||||
E.Origin.Tell(You);
|
E.Origin.Tell(You);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +156,7 @@ namespace IW4MAdmin
|
|||||||
if (P == null)
|
if (P == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
E.Origin.Tell(String.Format("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.levelToColor(P.getLevel()), P.getClientNum(), P.getName(), Utilities.getSpaces(Player.Permission.SeniorAdmin.ToString().Length - P.getLevel().ToString().Length)));
|
E.Origin.Tell(String.Format("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.levelToColor(P.Level), P.clientID, P.Name, Utilities.getSpaces(Player.Permission.SeniorAdmin.ToString().Length - P.Level.ToString().Length)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,9 +175,9 @@ namespace IW4MAdmin
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (Command C in E.Owner.getCommands())
|
foreach (Command C in E.Owner.getCommands())
|
||||||
{
|
{
|
||||||
if (C.getName().Contains(cmd) || C.getName() == cmd)
|
if (C.Name.Contains(cmd) || C.Name == cmd)
|
||||||
{
|
{
|
||||||
E.Origin.Tell(" [^3" + C.getName() + "^7] " + C.getDescription());
|
E.Origin.Tell(" [^3" + C.Name + "^7] " + C.Description);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,9 +193,9 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
foreach (Command C in E.Owner.getCommands())
|
foreach (Command C in E.Owner.getCommands())
|
||||||
{
|
{
|
||||||
if (E.Origin.getLevel() >= C.getNeededPerm())
|
if (E.Origin.Level >= C.Permission)
|
||||||
{
|
{
|
||||||
_commands = _commands + " [^3" + C.getName() + "^7] ";
|
_commands = _commands + " [^3" + C.Name + "^7] ";
|
||||||
if (count >= 4)
|
if (count >= 4)
|
||||||
{
|
{
|
||||||
E.Origin.Tell(_commands);
|
E.Origin.Tell(_commands);
|
||||||
@ -305,7 +251,7 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
E.Target.setLevel(newPerm);
|
E.Target.setLevel(newPerm);
|
||||||
E.Target.Tell("Congratulations! You have been promoted to ^3" + newPerm);
|
E.Target.Tell("Congratulations! You have been promoted to ^3" + newPerm);
|
||||||
E.Origin.Tell(E.Target.getName() + " was successfully promoted!");
|
E.Origin.Tell(E.Target.Name + " was successfully promoted!");
|
||||||
//NEEED TO MOVE
|
//NEEED TO MOVE
|
||||||
E.Owner.clientDB.updatePlayer(E.Target);
|
E.Owner.clientDB.updatePlayer(E.Target);
|
||||||
}
|
}
|
||||||
@ -347,26 +293,15 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
foreach (Player P in E.Owner.getPlayers())
|
foreach (Player P in E.Owner.getPlayers())
|
||||||
{
|
{
|
||||||
if (P != null && P.getLevel() > Player.Permission.Flagged && !P.Masked)
|
if (P != null && P.Level > Player.Permission.Flagged && !P.Masked)
|
||||||
{
|
{
|
||||||
E.Origin.Tell(String.Format("[^3{0}^7] {1}", Utilities.levelToColor(P.getLevel()), P.getName()));
|
E.Origin.Tell(String.Format("[^3{0}^7] {1}", Utilities.levelToColor(P.Level), P.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Wisdom : Command
|
|
||||||
{
|
|
||||||
public Wisdom(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
|
||||||
|
|
||||||
public override void Execute(Event E)
|
|
||||||
{
|
|
||||||
E.Owner.Broadcast(E.Owner.Wisdom());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class MapCMD : Command
|
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 MapCMD(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||||
@ -407,7 +342,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
foreach (Player P in db_players)
|
foreach (Player P in db_players)
|
||||||
{
|
{
|
||||||
String mesg = String.Format("[^3{0}^7] [^3@{1}^7] - [{2}^7] - {3} | last seen {4} ago", P.getName(), P.getDBID(), Utilities.levelToColor(P.getLevel()), P.getIP(), P.getLastConnection());
|
String mesg = String.Format("[^3{0}^7] [^3@{1}^7] - [{2}^7] - {3} | last seen {4} ago", P.Name, P.databaseID, Utilities.levelToColor(P.Level), P.IP, P.getLastConnection());
|
||||||
E.Origin.Tell(mesg);
|
E.Origin.Tell(mesg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -453,7 +388,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
if (Current != null)
|
if (Current != null)
|
||||||
{
|
{
|
||||||
String mesg = String.Format("^1{0} ^7now goes by ^5{1}^7 [^3{2}^7]", lookingFor, Current.getName(), Current.getDBID());
|
String mesg = String.Format("^1{0} ^7now goes by ^5{1}^7 [^3{2}^7]", lookingFor, Current.Name, Current.databaseID);
|
||||||
E.Origin.Tell(mesg);
|
E.Origin.Tell(mesg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,8 +419,8 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
E.Data = Utilities.removeWords(E.Data, 1);
|
E.Data = Utilities.removeWords(E.Data, 1);
|
||||||
E.Target.Alert();
|
E.Target.Alert();
|
||||||
E.Target.Tell("^1" + E.Origin.getName() + " ^3[PM]^7 - " + E.Data);
|
E.Target.Tell("^1" + E.Origin.Name + " ^3[PM]^7 - " + E.Data);
|
||||||
E.Origin.Tell(String.Format("To ^3{0} ^7-> {1}", E.Target.getName(), E.Data));
|
E.Origin.Tell(String.Format("To ^3{0} ^7-> {1}", E.Target.Name, E.Data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,11 +440,11 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E.Target.stats = E.Owner.statDB.getStats(E.Target.getDBID());
|
E.Target.stats = E.Owner.statDB.getStats(E.Target.databaseID);
|
||||||
if (E.Target.stats == null)
|
if (E.Target.stats == null)
|
||||||
E.Origin.Tell("That person does not have any stats at this time!");
|
E.Origin.Tell("That person does not have any stats at this time!");
|
||||||
else
|
else
|
||||||
E.Origin.Tell(String.Format("[^3{4}^7] ^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", E.Target.stats.Kills, E.Target.stats.Deaths, E.Target.stats.KDR, E.Target.stats.Skill, E.Target.getName()));
|
E.Origin.Tell(String.Format("[^3{4}^7] ^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", E.Target.stats.Kills, E.Target.stats.Deaths, E.Target.stats.KDR, E.Target.stats.Skill, E.Target.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,7 +461,7 @@ namespace IW4MAdmin
|
|||||||
foreach (Stats S in Top)
|
foreach (Stats S in Top)
|
||||||
{
|
{
|
||||||
Player P = E.Owner.clientDB.getPlayer(S.statIndex);
|
Player P = E.Owner.clientDB.getPlayer(S.statIndex);
|
||||||
if (P != null && P.getLevel() != Player.Permission.Banned)
|
if (P != null && P.Level != Player.Permission.Banned)
|
||||||
{
|
{
|
||||||
P.stats = S;
|
P.stats = S;
|
||||||
TopP.Add(P);
|
TopP.Add(P);
|
||||||
@ -539,7 +474,7 @@ namespace IW4MAdmin
|
|||||||
foreach (Player P in TopP)
|
foreach (Player P in TopP)
|
||||||
{
|
{
|
||||||
if (P != null)
|
if (P != null)
|
||||||
E.Origin.Tell(String.Format("^3{0}^7 - ^5{1} ^7KDR | ^5{2} ^7SKILL", P.getName(), P.stats.KDR, P.stats.Skill));
|
E.Origin.Tell(String.Format("^3{0}^7 - ^5{1} ^7KDR | ^5{2} ^7SKILL", P.Name, P.stats.KDR, P.stats.Skill));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +502,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Owner.RCON.addRCON(String.Format("admin_lastevent {0};{1}", "balance", E.Origin.getID())); //Let gsc do the magic
|
E.Origin.currentServer.executeCommand(String.Format("admin_lastevent {0};{1}", "balance", E.Origin.npID)); //Let gsc do the magic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,7 +512,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Owner.RCON.addRCON(String.Format("admin_lastevent {0};{1};{2};{3}", "goto", E.Origin.getID(), E.Target.getName(), E.Data)); //Let gsc do the magic
|
E.Origin.currentServer.executeCommand(String.Format("admin_lastevent {0};{1};{2};{3}", "goto", E.Origin.npID, E.Target.Name, E.Data)); //Let gsc do the magic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,22 +522,22 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
if (E.Target.getLevel() >= E.Origin.getLevel())
|
if (E.Target.Level >= E.Origin.Level)
|
||||||
{
|
{
|
||||||
E.Origin.Tell("You cannot flag " + E.Target.getName());
|
E.Origin.Tell("You cannot flag " + E.Target.Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (E.Target.getLevel() == Player.Permission.Flagged)
|
if (E.Target.Level == Player.Permission.Flagged)
|
||||||
{
|
{
|
||||||
E.Target.setLevel(Player.Permission.User);
|
E.Target.setLevel(Player.Permission.User);
|
||||||
E.Origin.Tell("You have ^5unflagged ^7" + E.Target.getName());
|
E.Origin.Tell("You have ^5unflagged ^7" + E.Target.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
E.Target.setLevel(Player.Permission.Flagged);
|
E.Target.setLevel(Player.Permission.Flagged);
|
||||||
E.Origin.Tell("You have ^5flagged ^7" + E.Target.getName());
|
E.Origin.Tell("You have ^5flagged ^7" + E.Target.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
E.Owner.clientDB.updatePlayer(E.Target);
|
E.Owner.clientDB.updatePlayer(E.Target);
|
||||||
@ -621,17 +556,17 @@ namespace IW4MAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (E.Target.getLevel() > E.Origin.getLevel())
|
if (E.Target.Level > E.Origin.Level)
|
||||||
{
|
{
|
||||||
E.Origin.Tell("You cannot report " + E.Target.getName());
|
E.Origin.Tell("You cannot report " + E.Target.Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
E.Data = Utilities.removeWords(E.Data, 1);
|
E.Data = Utilities.removeWords(E.Data, 1);
|
||||||
E.Owner.Reports.Add(new Report(E.Target, E.Origin, E.Data));
|
E.Owner.Reports.Add(new Report(E.Target, E.Origin, E.Data));
|
||||||
E.Origin.Tell("Successfully reported " + E.Target.getName());
|
E.Origin.Tell("Successfully reported " + E.Target.Name);
|
||||||
|
|
||||||
E.Owner.ToAdmins(String.Format("^5{0}^7->^1{1}^7: {2}", E.Origin.getName(), E.Target.getName(), E.Data));
|
E.Owner.ToAdmins(String.Format("^5{0}^7->^1{1}^7: {2}", E.Origin.Name, E.Target.Name, E.Data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,7 +588,7 @@ namespace IW4MAdmin
|
|||||||
if (count > 8)
|
if (count > 8)
|
||||||
i = count - 8;
|
i = count - 8;
|
||||||
Report R = E.Owner.Reports[i];
|
Report R = E.Owner.Reports[i];
|
||||||
E.Origin.Tell(String.Format("^5{0}^7->^1{1}^7: {2}", R.Origin.getName(), R.Target.getName(), R.Reason));
|
E.Origin.Tell(String.Format("^5{0}^7->^1{1}^7: {2}", R.Origin.Name, R.Target.Name, R.Reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,7 +600,7 @@ namespace IW4MAdmin
|
|||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Data = Utilities.removeWords(E.Data, 1);
|
E.Data = Utilities.removeWords(E.Data, 1);
|
||||||
E.Owner.RCON.addRCON(String.Format("admin_lastevent tell;{0};{1};{2}", E.Origin.getID(), E.Target.getID(), E.Data));
|
E.Origin.currentServer.executeCommand(String.Format("admin_lastevent tell;{0};{1};{2}", E.Origin.npID, E.Target.npID, E.Data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,7 +635,7 @@ namespace IW4MAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ban B = E.Owner.Bans.Find(b => b.getID().Equals(E.Target.getID()));
|
Ban B = E.Owner.Bans.Find(b => b.npID.Equals(E.Target.npID));
|
||||||
|
|
||||||
if (B == null)
|
if (B == null)
|
||||||
{
|
{
|
||||||
@ -708,7 +643,7 @@ namespace IW4MAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player Banner = E.Owner.clientDB.getPlayer(B.getBanner(), -1);
|
Player Banner = E.Owner.clientDB.getPlayer(B.bannedByID, -1);
|
||||||
|
|
||||||
if (Banner == null)
|
if (Banner == null)
|
||||||
{
|
{
|
||||||
@ -716,7 +651,7 @@ namespace IW4MAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
E.Origin.Tell(String.Format("^1{0} ^7was banned by ^5{1} ^7for: {2}", E.Target.getName(), Banner.getName(), B.getReason()));
|
E.Origin.Tell(String.Format("^1{0} ^7was banned by ^5{1} ^7for: {2}", E.Target.Name, Banner.Name, B.Reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,7 +661,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
E.Target.Alias = E.Owner.aliasDB.getPlayer(E.Target.getDBID());
|
E.Target.Alias = E.Owner.aliasDB.getPlayer(E.Target.databaseID);
|
||||||
|
|
||||||
if (E.Target.Alias == null)
|
if (E.Target.Alias == null)
|
||||||
{
|
{
|
||||||
@ -734,7 +669,7 @@ namespace IW4MAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
E.Target.Tell("[^3" + E.Target.getName() + "^7]");
|
E.Target.Tell("[^3" + E.Target.Name + "^7]");
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
|
|
||||||
List<Player> playerAliases = new List<Player>();
|
List<Player> playerAliases = new List<Player>();
|
||||||
@ -746,7 +681,7 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
foreach (String S in P.Alias.getNames())
|
foreach (String S in P.Alias.getNames())
|
||||||
{
|
{
|
||||||
if (S != String.Empty && S != E.Target.getName())
|
if (S != String.Empty && S != E.Target.Name)
|
||||||
message.Append(S + " | ");
|
message.Append(S + " | ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -778,8 +713,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public override void Execute(Event E)
|
public override void Execute(Event E)
|
||||||
{
|
{
|
||||||
String[] Response = E.Owner.RCON.addRCON(E.Data.Trim());
|
E.Origin.currentServer.executeCommand(E.Data.Trim());
|
||||||
if (Response != null && Response.Length > 0)
|
|
||||||
E.Origin.Tell("Successfuly sent RCON command!");
|
E.Origin.Tell("Successfuly sent RCON command!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,11 @@ using System.Data;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
abstract class Database
|
abstract class DatabaseA : SharedLibrary.Database
|
||||||
{
|
{
|
||||||
public Database(String FN)
|
public Database(String FN)
|
||||||
{
|
{
|
||||||
@ -336,12 +337,12 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
newPlayer.Add("Name", Utilities.removeNastyChars(P.getName()));
|
newPlayer.Add("Name", Utilities.removeNastyChars(P.Name));
|
||||||
newPlayer.Add("npID", P.getID());
|
newPlayer.Add("npID", P.npID);
|
||||||
newPlayer.Add("Level", (int)P.getLevel());
|
newPlayer.Add("Level", (int)P.Level);
|
||||||
newPlayer.Add("LastOffense", "");
|
newPlayer.Add("LastOffense", "");
|
||||||
newPlayer.Add("Connections", 1);
|
newPlayer.Add("Connections", 1);
|
||||||
newPlayer.Add("IP", P.getIP());
|
newPlayer.Add("IP", P.IP);
|
||||||
newPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
newPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
||||||
|
|
||||||
Insert("CLIENTS", newPlayer);
|
Insert("CLIENTS", newPlayer);
|
||||||
@ -352,15 +353,15 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
Dictionary<String, Object> updatedPlayer = new Dictionary<String, Object>();
|
Dictionary<String, Object> updatedPlayer = new Dictionary<String, Object>();
|
||||||
|
|
||||||
updatedPlayer.Add("Name", P.getName());
|
updatedPlayer.Add("Name", P.Name);
|
||||||
updatedPlayer.Add("npID", P.getID());
|
updatedPlayer.Add("npID", P.npID);
|
||||||
updatedPlayer.Add("Level", (int)P.getLevel());
|
updatedPlayer.Add("Level", (int)P.Level);
|
||||||
updatedPlayer.Add("LastOffense", P.getLastO());
|
updatedPlayer.Add("LastOffense", P.LastOffense);
|
||||||
updatedPlayer.Add("Connections", P.getConnections());
|
updatedPlayer.Add("Connections", P.Connections);
|
||||||
updatedPlayer.Add("IP", P.getIP());
|
updatedPlayer.Add("IP", P.IP);
|
||||||
updatedPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
updatedPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
||||||
|
|
||||||
Update("CLIENTS", updatedPlayer, String.Format("npID = '{0}'", P.getID()));
|
Update("CLIENTS", updatedPlayer, String.Format("npID = '{0}'", P.npID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -433,7 +434,7 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
newPlayer.Add("Number", P.getDBID());
|
newPlayer.Add("Number", P.databaseID);
|
||||||
newPlayer.Add("KILLS", 0);
|
newPlayer.Add("KILLS", 0);
|
||||||
newPlayer.Add("DEATHS", 0);
|
newPlayer.Add("DEATHS", 0);
|
||||||
newPlayer.Add("KDR", 0);
|
newPlayer.Add("KDR", 0);
|
||||||
@ -456,10 +457,10 @@ namespace IW4MAdmin
|
|||||||
updatedPlayer.Add("DEATHS", P.stats.Deaths);
|
updatedPlayer.Add("DEATHS", P.stats.Deaths);
|
||||||
updatedPlayer.Add("KDR", Math.Round(P.stats.KDR, 2));
|
updatedPlayer.Add("KDR", Math.Round(P.stats.KDR, 2));
|
||||||
updatedPlayer.Add("SKILL", P.stats.Skill);
|
updatedPlayer.Add("SKILL", P.stats.Skill);
|
||||||
updatedPlayer.Add("MEAN", P.stats.Rating.Mean);
|
//updatedPlayer.Add("MEAN", P.stats.Rating.Mean);
|
||||||
updatedPlayer.Add("DEV", P.stats.Rating.StandardDeviation);
|
//updatedPlayer.Add("DEV", P.stats.Rating.StandardDeviation);
|
||||||
|
|
||||||
Update("STATS", updatedPlayer, String.Format("Number = '{0}'", P.getDBID()));
|
Update("STATS", updatedPlayer, String.Format("Number = '{0}'", P.databaseID));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns top 5 players (we filter through them later)
|
//Returns top 5 players (we filter through them later)
|
||||||
|
@ -5,9 +5,9 @@ using System.IO;
|
|||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
class file
|
class IFile
|
||||||
{
|
{
|
||||||
public file(String fileName)
|
public IFile(String fileName)
|
||||||
{
|
{
|
||||||
//Not safe for directories with more than one folder but meh
|
//Not safe for directories with more than one folder but meh
|
||||||
_Directory = fileName.Split('\\')[0];
|
_Directory = fileName.Split('\\')[0];
|
||||||
@ -42,11 +42,10 @@ namespace IW4MAdmin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public file(String file, bool write)
|
public IFile(String file, bool write)
|
||||||
{
|
{
|
||||||
Name = file;
|
Name = file;
|
||||||
writeHandle = new StreamWriter(new FileStream(Name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
|
writeHandle = new StreamWriter(new FileStream(Name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
|
||||||
// writeHandle.AutoFlush = true;
|
|
||||||
sze = 0;
|
sze = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,11 +79,6 @@ namespace IW4MAdmin
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumLines()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
if(Handle != null)
|
if(Handle != null)
|
||||||
@ -93,46 +87,6 @@ namespace IW4MAdmin
|
|||||||
writeHandle.Close();
|
writeHandle.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//FROM http://stackoverflow.com/questions/398378/get-last-10-lines-of-very-large-text-file-10gb-c-sharp
|
|
||||||
public string ReadEndTokens()
|
|
||||||
{
|
|
||||||
Encoding encoding = Encoding.ASCII;
|
|
||||||
string tokenSeparator = "\n";
|
|
||||||
int numberOfTokens = 2;
|
|
||||||
|
|
||||||
int sizeOfChar = encoding.GetByteCount("\n");
|
|
||||||
byte[] buffer = encoding.GetBytes(tokenSeparator);
|
|
||||||
|
|
||||||
using (FileStream fs = new FileStream(this.Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
||||||
{
|
|
||||||
Int64 tokenCount = 0;
|
|
||||||
Int64 endPosition = fs.Length / sizeOfChar;
|
|
||||||
|
|
||||||
for (Int64 position = sizeOfChar; position < endPosition; position += sizeOfChar)
|
|
||||||
{
|
|
||||||
fs.Seek(-position, SeekOrigin.End);
|
|
||||||
fs.Read(buffer, 0, buffer.Length);
|
|
||||||
|
|
||||||
if (encoding.GetString(buffer) == tokenSeparator)
|
|
||||||
{
|
|
||||||
tokenCount++;
|
|
||||||
if (tokenCount == numberOfTokens)
|
|
||||||
{
|
|
||||||
byte[] returnBuffer = new byte[fs.Length - fs.Position];
|
|
||||||
fs.Read(returnBuffer, 0, returnBuffer.Length);
|
|
||||||
return encoding.GetString(returnBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle case where number of tokens in file is less than numberOfTokens
|
|
||||||
fs.Seek(0, SeekOrigin.Begin);
|
|
||||||
buffer = new byte[fs.Length];
|
|
||||||
fs.Read(buffer, 0, buffer.Length);
|
|
||||||
return encoding.GetString(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] readAll()
|
public String[] readAll()
|
||||||
{
|
{
|
||||||
return Handle.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
return Handle.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@ -143,22 +97,6 @@ namespace IW4MAdmin
|
|||||||
return Handle.ReadToEnd();
|
return Handle.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] end(int neededLines)
|
|
||||||
{
|
|
||||||
var lines = new List<String>();
|
|
||||||
while (!Handle.EndOfStream)
|
|
||||||
{
|
|
||||||
String lins = Handle.ReadLine();
|
|
||||||
lines.Add(lins.ToString());
|
|
||||||
if (lines.Count > neededLines)
|
|
||||||
{
|
|
||||||
lines.RemoveAt(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] Tail(int lineCount)
|
public String[] Tail(int lineCount)
|
||||||
{
|
{
|
||||||
var buffer = new List<string>(lineCount);
|
var buffer = new List<string>(lineCount);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
|
@ -71,56 +71,59 @@
|
|||||||
<ApplicationIcon>IW4MAdmin.ico</ApplicationIcon>
|
<ApplicationIcon>IW4MAdmin.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<StartupObject>IW4MAdmin.Program</StartupObject>
|
<StartupObject>
|
||||||
|
</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup />
|
<PropertyGroup />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
|
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<GenerateManifests>true</GenerateManifests>
|
<GenerateManifests>false</GenerateManifests>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup />
|
||||||
|
<PropertyGroup />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Kayak">
|
<Reference Include="Kayak">
|
||||||
<HintPath>..\packages\Kayak.0.7.2\lib\Kayak.dll</HintPath>
|
<HintPath>..\packages\Kayak.0.7.2\lib\Kayak.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Moserware.Skills, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Moserware.Skills, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>bin\Debug\Moserware.Skills.dll</HintPath>
|
<HintPath>bin\Debug\Moserware.Skills.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SharedLibary">
|
||||||
|
<HintPath>..\SharedLibary\SharedLibary\bin\Debug\SharedLibary.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Data.SQLite, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
|
<Reference Include="System.Data.SQLite, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>libs\System.Data.SQLite.dll</HintPath>
|
<HintPath>libs\System.Data.SQLite.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Bans.cs" />
|
|
||||||
<Compile Include="Command.cs" />
|
<Compile Include="Command.cs" />
|
||||||
<Compile Include="Connection.cs" />
|
<Compile Include="Connection.cs" />
|
||||||
<Compile Include="Database.cs" />
|
|
||||||
<Compile Include="Event.cs" />
|
|
||||||
<Compile Include="File.cs" />
|
|
||||||
<Compile Include="Heartbeat.cs" />
|
<Compile Include="Heartbeat.cs" />
|
||||||
<Compile Include="Helpers.cs" />
|
<Compile Include="Helpers.cs" />
|
||||||
<Compile Include="Log.cs" />
|
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="Manager.cs" />
|
<Compile Include="Manager.cs" />
|
||||||
<Compile Include="Maps.cs" />
|
<Compile Include="Plugins.cs" />
|
||||||
<Compile Include="Player.cs" />
|
|
||||||
<Compile Include="Properties\Settings.Designer.cs">
|
<Compile Include="Properties\Settings.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="RCON.cs" />
|
|
||||||
<Compile Include="Report.cs" />
|
|
||||||
<Compile Include="Server.cs" />
|
<Compile Include="Server.cs" />
|
||||||
<Compile Include="TrueSkill.cs" />
|
<Compile Include="TrueSkill.cs" />
|
||||||
<Compile Include="Utilities.cs" />
|
<Compile Include="Utilities.cs" />
|
||||||
@ -128,6 +131,7 @@
|
|||||||
<Compile Include="IW4_GameStructs.cs" />
|
<Compile Include="IW4_GameStructs.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="app.manifest" />
|
||||||
<None Include="lib\AdminInterface.dll">
|
<None Include="lib\AdminInterface.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
@ -141,8 +145,12 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="lib\System.Data.SQLite.dll">
|
<None Include="lib\System.Data.SQLite.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<Content Include="lib\SharedLibary.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="plugins\SamplePlugin.dll" />
|
||||||
<Content Include="version.txt">
|
<Content Include="version.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
@ -177,9 +185,6 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
<Content Include="IW4MAdmin.exe.config">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<None Include="m2demo\admin\commands.gsc">
|
<None Include="m2demo\admin\commands.gsc">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
@ -298,15 +303,13 @@
|
|||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>cd "$(TargetDir)"
|
<PostBuildEvent>cd "$(TargetDir)"
|
||||||
del *.dll
|
|
||||||
del *.config
|
del *.config
|
||||||
del *.application
|
del *.application
|
||||||
del *.pdb
|
del *.pdb
|
||||||
|
del *.dll
|
||||||
del *.manifest
|
del *.manifest
|
||||||
del *.rm
|
del *.rm
|
||||||
cd ..
|
del *.log</PostBuildEvent>
|
||||||
cd ..
|
|
||||||
copy IW4MAdmin.exe.config $(TargetDir)\IW4MAdmin.exe.config</PostBuildEvent>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<configuration>
|
|
||||||
<startup>
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
|
||||||
</startup>
|
|
||||||
<runtime>
|
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<probing privatePath="lib" />
|
|
||||||
</assemblyBinding>
|
|
||||||
</runtime>
|
|
||||||
</configuration>
|
|
@ -90,20 +90,6 @@ namespace IW4MAdmin
|
|||||||
public IntPtr max;
|
public IntPtr max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not iw4
|
|
||||||
public struct dvar
|
|
||||||
{
|
|
||||||
public String name;
|
|
||||||
public String description;
|
|
||||||
public int flags;
|
|
||||||
public short type;
|
|
||||||
public String current;
|
|
||||||
public String latched;
|
|
||||||
public String _default;
|
|
||||||
public int min;
|
|
||||||
public int max;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
public static String NET_AdrToString(netadr_t a)
|
public static String NET_AdrToString(netadr_t a)
|
||||||
|
@ -14,7 +14,7 @@ namespace IW4MAdmin
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log(file logf, Level mode, int port)
|
public Log(IFile logf, Level mode, int port)
|
||||||
{
|
{
|
||||||
logFile = logf;
|
logFile = logf;
|
||||||
logMode = mode;
|
logMode = mode;
|
||||||
@ -53,7 +53,7 @@ namespace IW4MAdmin
|
|||||||
return DateTime.Now.ToString("HH:mm:ss");
|
return DateTime.Now.ToString("HH:mm:ss");
|
||||||
}
|
}
|
||||||
|
|
||||||
private file logFile;
|
private IFile logFile;
|
||||||
private Level logMode;
|
private Level logMode;
|
||||||
private int Port;
|
private int Port;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
@ -13,6 +14,7 @@ namespace IW4MAdmin
|
|||||||
static public double latestVersion;
|
static public double latestVersion;
|
||||||
static public bool usingMemory = true;
|
static public bool usingMemory = true;
|
||||||
static private Manager serverManager;
|
static private Manager serverManager;
|
||||||
|
static private IW4MAdmin_Web.WebFront frontEnd;
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -28,22 +30,11 @@ namespace IW4MAdmin
|
|||||||
else
|
else
|
||||||
Console.WriteLine(" Version " + Version + " (unable to retrieve latest)");
|
Console.WriteLine(" Version " + Version + " (unable to retrieve latest)");
|
||||||
Console.WriteLine("=====================================================");
|
Console.WriteLine("=====================================================");
|
||||||
#if DEBUG2
|
|
||||||
if (viableServers.Count < 1)
|
|
||||||
viableServers = checkConfig(); // fall back to config
|
|
||||||
Servers = viableServers;
|
|
||||||
|
|
||||||
foreach (Server IW4M in viableServers)
|
|
||||||
{
|
|
||||||
//Threading seems best here
|
|
||||||
Server SV = IW4M;
|
|
||||||
Thread monitorThread = new Thread(new ThreadStart(SV.Monitor));
|
|
||||||
monitorThread.Start();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
serverManager = new IW4MAdmin.Manager();
|
serverManager = new IW4MAdmin.Manager();
|
||||||
|
|
||||||
Thread serverMGRThread = new Thread(serverManager.Init);
|
Thread serverMGRThread = new Thread(serverManager.Init);
|
||||||
|
serverMGRThread.Name = "Server Manager thread";
|
||||||
serverMGRThread.Start();
|
serverMGRThread.Start();
|
||||||
|
|
||||||
while(!serverManager.isReady())
|
while(!serverManager.isReady())
|
||||||
@ -56,34 +47,14 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
if (serverManager.getServers().Count > 0)
|
if (serverManager.getServers().Count > 0)
|
||||||
{
|
{
|
||||||
IW4MAdmin_Web.WebFront frontEnd = new IW4MAdmin_Web.WebFront();
|
frontEnd = new IW4MAdmin_Web.WebFront();
|
||||||
frontEnd.Init();
|
frontEnd.Init();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#if DEBUG2
|
|
||||||
static void setupConfig()
|
|
||||||
{
|
|
||||||
bool validPort = false;
|
|
||||||
Console.WriteLine("Hey there, it looks like you haven't set up a server yet. Let's get started!");
|
|
||||||
|
|
||||||
Console.Write("Please enter the IP: ");
|
serverMGRThread.Join();
|
||||||
IP = Console.ReadLine();
|
serverManager.mainLog.Write("Shutting down IW4MAdmin...", Log.Level.Debug);
|
||||||
|
|
||||||
while (!validPort)
|
|
||||||
{
|
|
||||||
Console.Write("Please enter the Port: ");
|
|
||||||
int.TryParse(Console.ReadLine(), out Port);
|
|
||||||
if (Port != 0)
|
|
||||||
validPort = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.Write("Please enter the RCON password: ");
|
|
||||||
RCON = Console.ReadLine();
|
|
||||||
file Config = new file("config\\servers.cfg", true);
|
|
||||||
Console.WriteLine("Great! Let's go ahead and start 'er up.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static ConsoleEventDelegate handler;
|
static ConsoleEventDelegate handler;
|
||||||
|
|
||||||
static private bool OnProcessExit(int e)
|
static private bool OnProcessExit(int e)
|
||||||
@ -95,13 +66,17 @@ namespace IW4MAdmin
|
|||||||
if (S == null)
|
if (S == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Utilities.shutdownInterface(S.pID(), IntPtr.Zero))
|
S.isRunning = false;
|
||||||
|
|
||||||
|
if (Utilities.shutdownInterface(S.pID()))
|
||||||
Program.getManager().mainLog.Write("Successfully removed IW4MAdmin from server with PID " + S.pID(), Log.Level.Debug);
|
Program.getManager().mainLog.Write("Successfully removed IW4MAdmin from server with PID " + S.pID(), Log.Level.Debug);
|
||||||
else
|
else
|
||||||
Program.getManager().mainLog.Write("Could not remove IW4MAdmin from server with PID " + S.pID(), Log.Level.Debug);
|
Program.getManager().mainLog.Write("Could not remove IW4MAdmin from server with PID " + S.pID(), Log.Level.Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
Program.getManager().shutDown();
|
Program.getManager().shutDown();
|
||||||
|
frontEnd.webSchedule.Stop();
|
||||||
|
frontEnd.webSchedule.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch
|
catch
|
||||||
|
@ -6,6 +6,7 @@ using System.Diagnostics;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
@ -20,7 +21,7 @@ namespace IW4MAdmin
|
|||||||
public Manager()
|
public Manager()
|
||||||
{
|
{
|
||||||
ThreadList = new SortedDictionary<int, Thread>();
|
ThreadList = new SortedDictionary<int, Thread>();
|
||||||
file logFile = new file("IW4MAdminManager.log", true);
|
IFile logFile = new IFile("IW4MAdminManager.log", true);
|
||||||
mainLog = new Log(logFile, Log.Level.All, 0);
|
mainLog = new Log(logFile, Log.Level.All, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ namespace IW4MAdmin
|
|||||||
Utilities.Wait(10);
|
Utilities.Wait(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PluginImporter.Load();
|
||||||
|
|
||||||
activePIDs = getCurrentIW4MProcesses();
|
activePIDs = getCurrentIW4MProcesses();
|
||||||
Servers = loadServers();
|
Servers = loadServers();
|
||||||
|
|
||||||
@ -39,13 +42,14 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
Server IW4MServer = S;
|
Server IW4MServer = S;
|
||||||
Thread IW4MServerThread = new Thread(IW4MServer.Monitor);
|
Thread IW4MServerThread = new Thread(IW4MServer.Monitor);
|
||||||
|
IW4MServerThread.Name = "Monitor thread for " + S.pID();
|
||||||
ThreadList.Add(IW4MServer.pID(), IW4MServerThread);
|
ThreadList.Add(IW4MServer.pID(), IW4MServerThread);
|
||||||
IW4MServerThread.Start();
|
IW4MServerThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
while (true)
|
while (activePIDs.Count > 0)
|
||||||
{
|
{
|
||||||
List<Server> defunctServers = new List<Server>();
|
List<Server> defunctServers = new List<Server>();
|
||||||
lock (Servers)
|
lock (Servers)
|
||||||
@ -59,9 +63,10 @@ namespace IW4MAdmin
|
|||||||
if (!isIW4MStillRunning(S.pID()))
|
if (!isIW4MStillRunning(S.pID()))
|
||||||
{
|
{
|
||||||
Thread Defunct = ThreadList[S.pID()];
|
Thread Defunct = ThreadList[S.pID()];
|
||||||
|
S.isRunning = false;
|
||||||
if (Defunct != null)
|
if (Defunct != null)
|
||||||
{
|
{
|
||||||
Defunct.Abort();
|
Defunct.Join();
|
||||||
ThreadList[S.pID()] = null;
|
ThreadList[S.pID()] = null;
|
||||||
}
|
}
|
||||||
mainLog.Write("Server with PID #" + S.pID() + " no longer appears to be running.", Log.Level.All);
|
mainLog.Write("Server with PID #" + S.pID() + " no longer appears to be running.", Log.Level.All);
|
||||||
@ -78,6 +83,8 @@ namespace IW4MAdmin
|
|||||||
scanForNewServers();
|
scanForNewServers();
|
||||||
Utilities.Wait(5);
|
Utilities.Wait(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainLog.Write("Manager shutting down...");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutDown()
|
public void shutDown()
|
||||||
@ -85,11 +92,10 @@ namespace IW4MAdmin
|
|||||||
foreach (Server S in Servers)
|
foreach (Server S in Servers)
|
||||||
S.isRunning = false;
|
S.isRunning = false;
|
||||||
|
|
||||||
foreach (int PID in activePIDs)
|
activePIDs = new List<int>();
|
||||||
{
|
|
||||||
ThreadList[PID].Abort();
|
foreach (KeyValuePair<int, Thread> T in ThreadList)
|
||||||
mainLog.Write("Exited thread for PID " + PID);
|
ThreadList[T.Key].Join();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Server> getServers()
|
public List<Server> getServers()
|
||||||
@ -215,7 +221,7 @@ namespace IW4MAdmin
|
|||||||
dvar net_ip = Utilities.getDvarOld(0x64A1DF8, (int)Handle);
|
dvar net_ip = Utilities.getDvarOld(0x64A1DF8, (int)Handle);
|
||||||
dvar net_port = Utilities.getDvarOld(0x64A3004, (int)Handle);
|
dvar net_port = Utilities.getDvarOld(0x64A3004, (int)Handle);
|
||||||
|
|
||||||
return new Server(net_ip.current, Convert.ToInt32(net_port.current), "", (int)Handle, pID);
|
return new IW4MServer(net_ip.current, Convert.ToInt32(net_port.current), "", (int)Handle, pID);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
64
Admin/Plugins.cs
Normal file
64
Admin/Plugins.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
|
namespace IW4MAdmin
|
||||||
|
{
|
||||||
|
public class PluginImporter
|
||||||
|
{
|
||||||
|
public static List<Command> potentialPlugins = new List<Command>();
|
||||||
|
|
||||||
|
public static bool Load()
|
||||||
|
{
|
||||||
|
string[] dllFileNames = null;
|
||||||
|
|
||||||
|
if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins"))
|
||||||
|
{
|
||||||
|
dllFileNames = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins", "*.dll");
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Program.getManager().mainLog.Write("Plugin folder does not exist!", Log.Level.Debug);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dllFileNames == null || dllFileNames.Length == 0)
|
||||||
|
{
|
||||||
|
Program.getManager().mainLog.Write("No plugins to load", Log.Level.Debug);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length);
|
||||||
|
foreach (string dllFile in dllFileNames)
|
||||||
|
{
|
||||||
|
AssemblyName an = AssemblyName.GetAssemblyName(dllFile);
|
||||||
|
Assembly assembly = Assembly.Load(an);
|
||||||
|
assemblies.Add(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Assembly Plugin in assemblies)
|
||||||
|
{
|
||||||
|
if (Plugin != null)
|
||||||
|
{
|
||||||
|
Type[] types = Plugin.GetTypes();
|
||||||
|
foreach(Type assemblyType in types)
|
||||||
|
{
|
||||||
|
if(assemblyType.IsClass && assemblyType.BaseType.Name == "Command")
|
||||||
|
{
|
||||||
|
Object commandObject = Activator.CreateInstance(assemblyType);
|
||||||
|
Command newCommand = (Command)commandObject;
|
||||||
|
potentialPlugins.Add(newCommand);
|
||||||
|
Program.getManager().mainLog.Write("Loaded command plugin \"" + newCommand.Name + "\"", Log.Level.Debug);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Program.getManager().mainLog.Write("Ignoring invalid command plugin \"" + assemblyType.Name + "\"", Log.Level.Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
Admin/Properties/Settings.Designer.cs
generated
2
Admin/Properties/Settings.Designer.cs
generated
@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.18408
|
// Runtime Version:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
|
699
Admin/Server.cs
699
Admin/Server.cs
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Moserware.Skills.TrueSkill;
|
using Moserware.Skills.TrueSkill;
|
||||||
using IW4MAdmin;
|
using IW4MAdmin;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
|
|
||||||
namespace Moserware
|
namespace Moserware
|
||||||
@ -17,8 +18,8 @@ namespace Moserware
|
|||||||
|
|
||||||
public void updateNewSkill(Player P1, Player P2)
|
public void updateNewSkill(Player P1, Player P2)
|
||||||
{
|
{
|
||||||
var player1 = new Skills.Player(P1.getDBID());
|
/* var player1 = new Skills.Player(P1.databaseID);
|
||||||
var player2 = new Skills.Player(P2.getDBID());
|
var player2 = new Skills.Player(P2.databaseID);
|
||||||
|
|
||||||
var team1 = new Skills.Team(player1, P1.stats.Rating);
|
var team1 = new Skills.Team(player1, P1.stats.Rating);
|
||||||
var team2 = new Skills.Team(player2, P2.stats.Rating);
|
var team2 = new Skills.Team(player2, P2.stats.Rating);
|
||||||
@ -29,7 +30,7 @@ namespace Moserware
|
|||||||
P2.stats.Rating = newRatings[player2];
|
P2.stats.Rating = newRatings[player2];
|
||||||
|
|
||||||
P1.stats.Skill = Math.Round(P1.stats.Rating.ConservativeRating, 3)*10;
|
P1.stats.Skill = Math.Round(P1.stats.Rating.ConservativeRating, 3)*10;
|
||||||
P2.stats.Skill = Math.Round(P2.stats.Rating.ConservativeRating, 3)*10;
|
P2.stats.Skill = Math.Round(P2.stats.Rating.ConservativeRating, 3)*10;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private Skills.SkillCalculator calculator;
|
private Skills.SkillCalculator calculator;
|
||||||
|
@ -5,6 +5,7 @@ using System.Threading;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using SharedLibrary;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
@ -159,26 +160,26 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
public static String nameHTMLFormatted(Player P)
|
public static String nameHTMLFormatted(Player P)
|
||||||
{
|
{
|
||||||
switch (P.getLevel())
|
switch (P.Level)
|
||||||
{
|
{
|
||||||
case Player.Permission.User:
|
case Player.Permission.User:
|
||||||
return "<span style='color:rgb(87, 150, 66)'>" + P.getName() + "</span>";
|
return "<span style='color:rgb(87, 150, 66)'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.Moderator:
|
case Player.Permission.Moderator:
|
||||||
return "<span style='color:#e7b402'>" + P.getName() + "</span>";
|
return "<span style='color:#e7b402'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.Administrator:
|
case Player.Permission.Administrator:
|
||||||
return "<span style='color:#ec82de'>" + P.getName() + "</span>";
|
return "<span style='color:#ec82de'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.SeniorAdmin:
|
case Player.Permission.SeniorAdmin:
|
||||||
return "<span style='color:#2eb6bf'>" + P.getName() + "</span>";
|
return "<span style='color:#2eb6bf'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.Owner:
|
case Player.Permission.Owner:
|
||||||
return "<span style='color:rgb(38,120,230)'>" + P.getName() + "</span>";
|
return "<span style='color:rgb(38,120,230)'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.Creator:
|
case Player.Permission.Creator:
|
||||||
return "<span style='color:rgb(38,120,230)'>" + P.getName() + "</span>";
|
return "<span style='color:rgb(38,120,230)'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.Banned:
|
case Player.Permission.Banned:
|
||||||
return "<span style='color:rgb(196, 22, 28)'>" + P.getName() + "</span>";
|
return "<span style='color:rgb(196, 22, 28)'>" + P.Name+ "</span>";
|
||||||
case Player.Permission.Flagged:
|
case Player.Permission.Flagged:
|
||||||
return "<span style='color:rgb(251, 124, 98)'>" + P.getName() + "</span>";
|
return "<span style='color:rgb(251, 124, 98)'>" + P.Name+ "</span>";
|
||||||
default:
|
default:
|
||||||
return "<i>" + P.getName() + "</i>";
|
return "<i>" + P.Name+ "</i>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,13 +638,12 @@ namespace IW4MAdmin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool shutdownInterface(int pID, IntPtr moduleHandle, params IntPtr[] cleanUp)
|
public static bool shutdownInterface(int pID, params IntPtr[] cleanUp)
|
||||||
{
|
{
|
||||||
IntPtr threadID;
|
IntPtr threadID;
|
||||||
IntPtr ProcessHandle = OpenProcess(ProcessAccessFlags.All, false, pID);
|
IntPtr ProcessHandle = OpenProcess(ProcessAccessFlags.All, false, pID);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Program.getManager().mainLog.Write("Process handle is: " + ProcessHandle);
|
Program.getManager().mainLog.Write("Process handle is: " + ProcessHandle);
|
||||||
Program.getManager().mainLog.Write("Module handle is " + moduleHandle);
|
|
||||||
#endif
|
#endif
|
||||||
if (ProcessHandle == IntPtr.Zero)
|
if (ProcessHandle == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
@ -675,9 +675,13 @@ namespace IW4MAdmin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientId clientid = new ClientId();
|
//ClientId clientid = new ClientId();
|
||||||
threadID = new IntPtr();
|
//threadID = new IntPtr();
|
||||||
RtlCreateUserThread(ProcessHandle, IntPtr.Zero, false, 0, (uint)0, IntPtr.Zero, lpLLAddress, baseAddress, out threadID, out clientid);
|
uint ThreadID2;
|
||||||
|
threadID = IntPtr.Zero;
|
||||||
|
//RtlCreateUserThread(ProcessHandle, IntPtr.Zero, false, 0, (uint)0, IntPtr.Zero, lpLLAddress, baseAddress, out threadID, out clientid);
|
||||||
|
//SCreateRemoteThread(ProcessHandle, IntPtr.Zero, 0, lpLLAddress, baseAddress, 0, out ThreadID2);
|
||||||
|
return true;
|
||||||
|
|
||||||
if (threadID == IntPtr.Zero)
|
if (threadID == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
@ -703,13 +707,13 @@ namespace IW4MAdmin
|
|||||||
{
|
{
|
||||||
if (Pointer != IntPtr.Zero)
|
if (Pointer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
if (!VirtualFreeEx(ProcessHandle, Pointer, 0, AllocationType.Release))
|
// if (!VirtualFreeEx(ProcessHandle, Pointer, 0, AllocationType.Release))
|
||||||
Program.getManager().mainLog.Write("Virtual Free Failed During Exit Cleanup -- Error #" + Marshal.GetLastWin32Error());
|
// Program.getManager().mainLog.Write("Virtual Free Failed During Exit Cleanup -- Error #" + Marshal.GetLastWin32Error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Program.getManager().mainLog.Write("shutdown finished -- last error : " + Marshal.GetLastWin32Error());
|
Program.getManager().mainLog.Write("Shutdown finished -- last error : " + Marshal.GetLastWin32Error());
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ using System.Web;
|
|||||||
using Kayak;
|
using Kayak;
|
||||||
using Kayak.Http;
|
using Kayak.Http;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using SharedLibrary;
|
||||||
|
using IW4MAdmin;
|
||||||
|
|
||||||
|
|
||||||
#if ENABLED_CRAP_CODE_THAT_NEEDS_TO_BE_REWRITTEN
|
#if ENABLED_CRAP_CODE_THAT_NEEDS_TO_BE_REWRITTEN
|
||||||
@ -15,7 +17,7 @@ namespace IW4MAdmin_Web
|
|||||||
{
|
{
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
public Client ( WebFront.Page req, int cur, IDictionary<String, String> inc, String D, IW4MAdmin.Player P)
|
public Client ( WebFront.Page req, int cur, IDictionary<String, String> inc, String D, Player P)
|
||||||
{
|
{
|
||||||
requestedPage = req;
|
requestedPage = req;
|
||||||
requestedPageNumber = cur;
|
requestedPageNumber = cur;
|
||||||
@ -28,13 +30,13 @@ namespace IW4MAdmin_Web
|
|||||||
public int requestedPageNumber { get; private set; }
|
public int requestedPageNumber { get; private set; }
|
||||||
public IDictionary<String, String> requestOrigin { get; private set; }
|
public IDictionary<String, String> requestOrigin { get; private set; }
|
||||||
public String requestData { get; private set; }
|
public String requestData { get; private set; }
|
||||||
public IW4MAdmin.Player playerRequesting { get; private set; }
|
public Player playerRequesting { get; private set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WebFront
|
class WebFront
|
||||||
{
|
{
|
||||||
private IW4MAdmin.Server[] Servers;
|
private Server[] Servers;
|
||||||
|
|
||||||
public enum Page
|
public enum Page
|
||||||
{
|
{
|
||||||
@ -46,7 +48,7 @@ namespace IW4MAdmin_Web
|
|||||||
|
|
||||||
public WebFront()
|
public WebFront()
|
||||||
{
|
{
|
||||||
Servers = IW4MAdmin.Program.getServers();
|
Servers = Program.getServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
@ -62,7 +64,7 @@ namespace IW4MAdmin_Web
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IScheduler webSchedule;
|
public IScheduler webSchedule;
|
||||||
private IServer webServer;
|
private IServer webServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,14 +90,14 @@ namespace IW4MAdmin_Web
|
|||||||
static public String parseMacros(String input, WebFront.Page Page, int server, int Pagination, bool logged, String Data)
|
static public String parseMacros(String input, WebFront.Page Page, int server, int Pagination, bool logged, String Data)
|
||||||
{
|
{
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
IW4MAdmin.Server[] Servers= IW4MAdmin.Program.getServers();
|
Server[] Servers= Program.getServers();
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case "SERVERS":
|
case "SERVERS":
|
||||||
int cycleFix = 0;
|
int cycleFix = 0;
|
||||||
for (int i = 0; i < Servers.Count(); i++)
|
for (int i = 0; i < Servers.Count(); i++)
|
||||||
{
|
{
|
||||||
if (IW4MAdmin.Program.getServers()[i] == null)
|
if (Program.getServers()[i] == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
StringBuilder players = new StringBuilder();
|
StringBuilder players = new StringBuilder();
|
||||||
@ -106,7 +108,7 @@ namespace IW4MAdmin_Web
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
double currentPlayers = Servers[i].statusPlayers.Count;
|
double currentPlayers = Servers[i].statusPlayers.Count;
|
||||||
|
|
||||||
foreach (IW4MAdmin.Player P in Servers[i].getPlayers())
|
foreach (Player P in Servers[i].getPlayers())
|
||||||
{
|
{
|
||||||
if (P == null)
|
if (P == null)
|
||||||
continue;
|
continue;
|
||||||
@ -126,7 +128,7 @@ namespace IW4MAdmin_Web
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
players.AppendFormat("<td><a href='/{0}/{1}/userip/?player'>{2}</a></td>", i, P.getDBID(), IW4MAdmin.Utilities.nameHTMLFormatted(P));
|
players.AppendFormat("<td><a href='/{0}/{1}/userip/?player'>{2}</a></td>", i, P.databaseID, Utilities.nameHTMLFormatted(P));
|
||||||
|
|
||||||
if (count % 2 != 0)
|
if (count % 2 != 0)
|
||||||
{
|
{
|
||||||
@ -151,7 +153,7 @@ namespace IW4MAdmin_Web
|
|||||||
<table cellpadding='0' cellspacing='0' class='players'>
|
<table cellpadding='0' cellspacing='0' class='players'>
|
||||||
{5}
|
{5}
|
||||||
</table>",
|
</table>",
|
||||||
Servers[i].getName(), Servers[i].getMap(), Servers[i].getClientNum() + "/" + Servers[i].getMaxClients(), IW4MAdmin.Utilities.gametypeLocalized(Servers[i].getGametype()), i, players.ToString());
|
Servers[i].getName(), Servers[i].getMap(), Servers[i].getClientNum() + "/" + Servers[i].getMaxClients(), Utilities.gametypeLocalized(Servers[i].getGametype()), i, players.ToString());
|
||||||
buffer.AppendFormat("<div class='chatHistory' id='chatHistory_{0}'></div><script type='text/javascript'>$( document ).ready(function() {{ setInterval({1}loadChatMessages({0}, '#chatHistory_{0}'){1}, 2500); }});</script><div class='null' style='clear:both;'></div>", i, '\"');
|
buffer.AppendFormat("<div class='chatHistory' id='chatHistory_{0}'></div><script type='text/javascript'>$( document ).ready(function() {{ setInterval({1}loadChatMessages({0}, '#chatHistory_{0}'){1}, 2500); }});</script><div class='null' style='clear:both;'></div>", i, '\"');
|
||||||
if (Servers[i].getClientNum() > 0)
|
if (Servers[i].getClientNum() > 0)
|
||||||
buffer.AppendFormat("<form class='chatOutFormat' action={1}javascript:chatRequest({0}, 'chatEntry_{0}'){1}><input class='chatFormat_text' type='text' placeholder='Enter a message...' id='chatEntry_{0}'/><input class='chatFormat_submit' type='submit'/></form>", i, '\"');
|
buffer.AppendFormat("<form class='chatOutFormat' action={1}javascript:chatRequest({0}, 'chatEntry_{0}'){1}><input class='chatFormat_text' type='text' placeholder='Enter a message...' id='chatEntry_{0}'/><input class='chatFormat_submit' type='submit'/></form>", i, '\"');
|
||||||
@ -162,7 +164,7 @@ namespace IW4MAdmin_Web
|
|||||||
return "IW4M Administration";
|
return "IW4M Administration";
|
||||||
case "BANS":
|
case "BANS":
|
||||||
buffer.Append("<table cellspacing=0 class=bans>");
|
buffer.Append("<table cellspacing=0 class=bans>");
|
||||||
int totalBans = IW4MAdmin.Program.getServers()[0].Bans.Count;
|
int totalBans = Program.getServers()[0].Bans.Count;
|
||||||
int range;
|
int range;
|
||||||
int start = Pagination*30;
|
int start = Pagination*30;
|
||||||
cycleFix = 0;
|
cycleFix = 0;
|
||||||
@ -174,38 +176,38 @@ namespace IW4MAdmin_Web
|
|||||||
else
|
else
|
||||||
range = 30;
|
range = 30;
|
||||||
|
|
||||||
List<IW4MAdmin.Ban> Bans = new List<IW4MAdmin.Ban>();
|
List<Ban> Bans = new List<Ban>();
|
||||||
|
|
||||||
if (totalBans > 0)
|
if (totalBans > 0)
|
||||||
Bans = IW4MAdmin.Program.getServers()[0].Bans.GetRange(start, range).OrderByDescending(x => x.getTime()).ToList();
|
Bans = Program.getServers()[0].Bans.GetRange(start, range).OrderByDescending(x => x.When).ToList();
|
||||||
else
|
else
|
||||||
Bans.Add(new IW4MAdmin.Ban("No Bans", "0", "0", DateTime.Now, ""));
|
Bans.Add(new Ban("No Bans", "0", "0", DateTime.Now, ""));
|
||||||
|
|
||||||
|
|
||||||
buffer.Append("<h1 style=margin-top: 0;>{{TIME}}</h1><hr /><tr><th>Name</th><th style=text-align:left;>Offense</th><th style=text-align:left;>Banned By</th><th style='width: 175px; text-align:right;padding-right: 80px;'>Time</th></tr>");
|
buffer.Append("<h1 style=margin-top: 0;>{{TIME}}</h1><hr /><tr><th>Name</th><th style=text-align:left;>Offense</th><th style=text-align:left;>Banned By</th><th style='width: 175px; text-align:right;padding-right: 80px;'>Time</th></tr>");
|
||||||
|
|
||||||
if (Bans[0] != null)
|
if (Bans[0] != null)
|
||||||
buffer = buffer.Replace("{{TIME}}", "From " + IW4MAdmin.Utilities.timePassed(Bans[0].getTime()) + " ago" + " — " + totalBans + " total");
|
buffer = buffer.Replace("{{TIME}}", "From " + Utilities.timePassed(Bans[0].When) + " ago" + " — " + totalBans + " total");
|
||||||
|
|
||||||
for (int i = 0; i < Bans.Count; i++)
|
for (int i = 0; i < Bans.Count; i++)
|
||||||
{
|
{
|
||||||
if (Bans[i] == null)
|
if (Bans[i] == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
IW4MAdmin.Player P = IW4MAdmin.Program.getServers()[0].clientDB.getPlayer(Bans[i].getID(), -1);
|
Player P = Program.getServers()[0].clientDB.getPlayer(Bans[i].npID, -1);
|
||||||
IW4MAdmin.Player B = IW4MAdmin.Program.getServers()[0].clientDB.getPlayer(Bans[i].getBanner(), -1);
|
Player B = Program.getServers()[0].clientDB.getPlayer(Bans[i].bannedByID, -1);
|
||||||
|
|
||||||
if (P == null)
|
if (P == null)
|
||||||
P = new IW4MAdmin.Player("Unknown", "n/a", 0, 0, 0, "Unknown", 0, "");
|
P = new Player("Unknown", "n/a", 0, 0, 0, "Unknown", 0, "");
|
||||||
if (B == null)
|
if (B == null)
|
||||||
B = new IW4MAdmin.Player("Unknown", "n/a", 0, 0, 0, "Unknown", 0, "");
|
B = new Player("Unknown", "n/a", 0, 0, 0, "Unknown", 0, "");
|
||||||
|
|
||||||
if (P.getLastO() == String.Empty)
|
if (P.lastOffense == String.Empty)
|
||||||
P.LastOffense = "Evade";
|
P.lastOffense = "Evade";
|
||||||
|
|
||||||
if (P != null && B != null)
|
if (P != null && B != null)
|
||||||
{
|
{
|
||||||
if (B.getID() == P.getID())
|
if (B.npID == P.npID)
|
||||||
B.updateName("IW4MAdmin"); // shh it will all be over soon
|
B.updateName("IW4MAdmin"); // shh it will all be over soon
|
||||||
|
|
||||||
String Prefix;
|
String Prefix;
|
||||||
@ -213,8 +215,8 @@ namespace IW4MAdmin_Web
|
|||||||
Prefix = "class=row-grey";
|
Prefix = "class=row-grey";
|
||||||
else
|
else
|
||||||
Prefix = "class=row-white";
|
Prefix = "class=row-white";
|
||||||
String Link = "/" + server + "/" + P.getDBID() + "/userip/?player";
|
String Link = "/" + server + "/" + P.databaseID + "/userip/?player";
|
||||||
buffer.AppendFormat("<tr {4}><td><a href='{5}'>{0}</a></th><td style='border-left: 3px solid #bbb; text-align:left;'>{1}</td><td style='border-left: 3px solid #bbb;text-align:left;'>{2}</td><td style='width: 175px; text-align:right;'>{3}</td></tr></div>", P.getName(), P.getLastO(), IW4MAdmin.Utilities.nameHTMLFormatted(B), Bans[i].getWhen(), Prefix, Link);
|
buffer.AppendFormat("<tr {4}><td><a href='{5}'>{0}</a></th><td style='border-left: 3px solid #bbb; text-align:left;'>{1}</td><td style='border-left: 3px solid #bbb;text-align:left;'>{2}</td><td style='width: 175px; text-align:right;'>{3}</td></tr></div>", P.Name, P.lastOffense, Utilities.nameHTMLFormatted(B), Bans[i].getWhen(), Prefix, Link);
|
||||||
cycleFix++;
|
cycleFix++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,7 +239,7 @@ namespace IW4MAdmin_Web
|
|||||||
range = (totalStats - start);
|
range = (totalStats - start);
|
||||||
else
|
else
|
||||||
range = 30;
|
range = 30;
|
||||||
List<IW4MAdmin.Stats> Stats = Servers[server].statDB.getMultipleStats(start, range).OrderByDescending(x => x.Skill).ToList();
|
List<Stats> Stats = Servers[server].statDB.getMultipleStats(start, range).OrderByDescending(x => x.Skill).ToList();
|
||||||
buffer.Append("<tr><th style=text-align:left;>Name</th><th style=text-align:left;>Kills</th><th style=text-align:left;>Deaths</th><th style=text-align:left;>KDR</th><th style='width: 175px; text-align:right;'>Rating</th></tr>");
|
buffer.Append("<tr><th style=text-align:left;>Name</th><th style=text-align:left;>Kills</th><th style=text-align:left;>Deaths</th><th style=text-align:left;>KDR</th><th style='width: 175px; text-align:right;'>Rating</th></tr>");
|
||||||
cycleFix = 0;
|
cycleFix = 0;
|
||||||
for (int i = 0; i < totalStats; i++)
|
for (int i = 0; i < totalStats; i++)
|
||||||
@ -245,7 +247,7 @@ namespace IW4MAdmin_Web
|
|||||||
if (i >= Stats.Count -1 || Stats[i] == null )
|
if (i >= Stats.Count -1 || Stats[i] == null )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
IW4MAdmin.Player P = Servers[server].clientDB.getPlayer(Stats[i].statIndex);
|
Player P = Servers[server].clientDB.getPlayer(Stats[i].statIndex);
|
||||||
|
|
||||||
if (P == null)
|
if (P == null)
|
||||||
continue;
|
continue;
|
||||||
@ -261,8 +263,8 @@ namespace IW4MAdmin_Web
|
|||||||
else
|
else
|
||||||
Prefix = "class=row-white";
|
Prefix = "class=row-white";
|
||||||
|
|
||||||
String Link = "/" + server + "/" + P.getDBID() + "/userip/?player";
|
String Link = "/" + server + "/" + P.databaseID + "/userip/?player";
|
||||||
buffer.AppendFormat("<tr {5}><td><a href='{6}'>{0}</a></td><td style='border-left: 3px solid #bbb; text-align:left;'>{1}</td><td style='border-left: 3px solid #bbb;text-align:left;'>{2}</td><td style='border-left: 3px solid #bbb;text-align:left;'>{3}</td><td style='width: 175px; text-align:right;'>{4}</td></tr></div>", P.getName(), P.stats.Kills, P.stats.Deaths, P.stats.KDR, P.stats.Skill, Prefix, Link);
|
buffer.AppendFormat("<tr {5}><td><a href='{6}'>{0}</a></td><td style='border-left: 3px solid #bbb; text-align:left;'>{1}</td><td style='border-left: 3px solid #bbb;text-align:left;'>{2}</td><td style='border-left: 3px solid #bbb;text-align:left;'>{3}</td><td style='width: 175px; text-align:right;'>{4}</td></tr></div>", P.Name, P.stats.Kills, P.stats.Deaths, P.stats.KDR, P.stats.Skill, Prefix, Link);
|
||||||
cycleFix++;
|
cycleFix++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,7 +273,7 @@ namespace IW4MAdmin_Web
|
|||||||
return buffer.ToString().Replace("{{TOP}}", (start + 1).ToString());
|
return buffer.ToString().Replace("{{TOP}}", (start + 1).ToString());
|
||||||
case "PLAYER":
|
case "PLAYER":
|
||||||
buffer.Append("<table class='player_info'><tr><th>Name</th><th>Aliases</th><th>IP</th><th>Rating</th><th>Level</th><th>Connections</th><th>Last Seen</th><th>Profile</th>");
|
buffer.Append("<table class='player_info'><tr><th>Name</th><th>Aliases</th><th>IP</th><th>Rating</th><th>Level</th><th>Connections</th><th>Last Seen</th><th>Profile</th>");
|
||||||
List<IW4MAdmin.Player> matchingPlayers = new List<IW4MAdmin.Player>();
|
List<Player> matchingPlayers = new List<Player>();
|
||||||
|
|
||||||
if (Data == null)
|
if (Data == null)
|
||||||
matchingPlayers.Add(Servers[server].clientDB.getPlayer(Pagination));
|
matchingPlayers.Add(Servers[server].clientDB.getPlayer(Pagination));
|
||||||
@ -284,12 +286,12 @@ namespace IW4MAdmin_Web
|
|||||||
var p = Servers[server].clientDB.getPlayer(a.getNumber());
|
var p = Servers[server].clientDB.getPlayer(a.getNumber());
|
||||||
if (p != null)
|
if (p != null)
|
||||||
{
|
{
|
||||||
List<IW4MAdmin.Player> aliases = new List<IW4MAdmin.Player>();
|
List<Player> aliases = new List<Player>();
|
||||||
Servers[server].getAliases(aliases, p);
|
Servers[server].getAliases(aliases, p);
|
||||||
|
|
||||||
foreach (var pa in aliases)
|
foreach (var pa in aliases)
|
||||||
{
|
{
|
||||||
if (!matchingPlayers.Exists(x => x.getDBID() == pa.getDBID()))
|
if (!matchingPlayers.Exists(x => x.databaseID == pa.databaseID))
|
||||||
matchingPlayers.Add(pa);
|
matchingPlayers.Add(pa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,31 +303,31 @@ namespace IW4MAdmin_Web
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (IW4MAdmin.Player Player in matchingPlayers)
|
foreach (Player Player in matchingPlayers)
|
||||||
{
|
{
|
||||||
if (Player == null)
|
if (Player == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buffer.Append("<tr>");
|
buffer.Append("<tr>");
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
List<IW4MAdmin.Player> aliases = new List<IW4MAdmin.Player>();
|
List<Player> aliases = new List<Player>();
|
||||||
Servers[server].getAliases(aliases, Player);
|
Servers[server].getAliases(aliases, Player);
|
||||||
|
|
||||||
foreach (IW4MAdmin.Player a in aliases)
|
foreach (Player a in aliases)
|
||||||
{
|
{
|
||||||
if (Data != null)
|
if (Data != null)
|
||||||
{
|
{
|
||||||
if (a.Alias.getNames().Exists(p => p.ToLower().Contains(Data.ToLower())) && a.getDBID() != Player.getDBID())
|
if (a.Alias.getNames().Exists(p => p.ToLower().Contains(Data.ToLower())) && a.databaseID != Player.databaseID)
|
||||||
{
|
{
|
||||||
str.AppendFormat("<span>{0}</span><br/>", a.getName());
|
str.AppendFormat("<span>{0}</span><br/>", a.Name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
str.AppendFormat("<span>{0}</span><br/>", a.getName());
|
str.AppendFormat("<span>{0}</span><br/>", a.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.stats = Servers[server].statDB.getStats(Player.getDBID());
|
Player.stats = Servers[server].statDB.getStats(Player.databaseID);
|
||||||
String Rating = String.Empty;
|
String Rating = String.Empty;
|
||||||
|
|
||||||
if (Player.stats == null)
|
if (Player.stats == null)
|
||||||
@ -337,7 +339,7 @@ namespace IW4MAdmin_Web
|
|||||||
|
|
||||||
if (logged)
|
if (logged)
|
||||||
{
|
{
|
||||||
foreach (IW4MAdmin.Player a in aliases)
|
foreach (Player a in aliases)
|
||||||
{
|
{
|
||||||
foreach (String ip in a.Alias.getIPS())
|
foreach (String ip in a.Alias.getIPS())
|
||||||
{
|
{
|
||||||
@ -351,18 +353,18 @@ namespace IW4MAdmin_Web
|
|||||||
IPs.Append("XXX.XXX.XXX.XXX");
|
IPs.Append("XXX.XXX.XXX.XXX");
|
||||||
|
|
||||||
Int64 forumID = 0;
|
Int64 forumID = 0;
|
||||||
if (Player.getID().Length == 16)
|
if (Player.npID.Length == 16)
|
||||||
{
|
{
|
||||||
forumID = Int64.Parse(Player.getID().Substring(0, 16), NumberStyles.AllowHexSpecifier);
|
forumID = Int64.Parse(Player.npID.Substring(0, 16), NumberStyles.AllowHexSpecifier);
|
||||||
forumID = forumID - 76561197960265728;
|
forumID = forumID - 76561197960265728;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Screenshot = String.Empty;
|
String Screenshot = String.Empty;
|
||||||
|
|
||||||
if (logged)
|
if (logged)
|
||||||
Screenshot = String.Format("<a href='http://server.nbsclan.org/screen.php?id={0}&name={1}'><div style='background-image:url(http://server.nbsclan.org/shutter.png); width: 20px; height: 20px;float: right; position:relative; right: 21%; background-size: contain;'></div></a>", forumID, Player.getName());
|
Screenshot = String.Format("<a href='http://server.nbsclan.org/screen.php?id={0}&name={1}'><div style='background-image:url(http://server.nbsclan.org/shutter.png); width: 20px; height: 20px;float: right; position:relative; right: 21%; background-size: contain;'></div></a>", forumID, Player.Name);
|
||||||
|
|
||||||
buffer.AppendFormat("<td><a style='float: left;' href='{9}'>{0}</a>{10}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6} ago</td><td><a href='https://repziw4.de/memberlist.php?mode=viewprofile&u={7}'>{8}</a></td>", Player.getName(), str, IPs, Rating, IW4MAdmin.Utilities.nameHTMLFormatted(Player.getLevel()), Player.getConnections(), Player.getLastConnection(), forumID, Player.getName(), "/0/" + Player.getDBID() + "/userip/?player", Screenshot);
|
buffer.AppendFormat("<td><a style='float: left;' href='{9}'>{0}</a>{10}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6} ago</td><td><a href='https://repziw4.de/memberlist.php?mode=viewprofile&u={7}'>{8}</a></td>", Player.Name, str, IPs, Rating, Utilities.nameHTMLFormatted(Player.Level), Player.Connections, Player.getLastConnection(), forumID, Player.Name, "/0/" + Player.databaseID + "/userip/?player", Screenshot);
|
||||||
buffer.Append("</tr>");
|
buffer.Append("</tr>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +381,7 @@ namespace IW4MAdmin_Web
|
|||||||
{
|
{
|
||||||
String output = input;
|
String output = input;
|
||||||
|
|
||||||
bool logged = IW4MAdmin.Program.getServers()[server].clientDB.getAdmins().Exists(player => player.getIP() == C.requestOrigin["Host"].Split(':')[0]);
|
bool logged = Program.getServers()[server].clientDB.getAdmins().Exists(player => player.IP == C.requestOrigin["Host"].Split(':')[0]);
|
||||||
|
|
||||||
switch (C.requestedPage)
|
switch (C.requestedPage)
|
||||||
{
|
{
|
||||||
@ -393,12 +395,12 @@ namespace IW4MAdmin_Web
|
|||||||
output = output.Replace("{{STATS}}", parseMacros("STATS", C.requestedPage, server, C.requestedPageNumber, logged, C.requestData));
|
output = output.Replace("{{STATS}}", parseMacros("STATS", C.requestedPage, server, C.requestedPageNumber, logged, C.requestData));
|
||||||
break;
|
break;
|
||||||
case WebFront.Page.player:
|
case WebFront.Page.player:
|
||||||
output = output.Replace("{{PLAYER}}", parseMacros("PLAYER", C.requestedPage, server, C.requestedPageNumber, (C.playerRequesting.getLevel() > IW4MAdmin.Player.Permission.Flagged), C.requestData));
|
output = output.Replace("{{PLAYER}}", parseMacros("PLAYER", C.requestedPage, server, C.requestedPageNumber, (C.playerRequesting.Level > Player.Permission.Flagged), C.requestData));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = output.Replace("{{TITLE}}", "IW4M Administration");
|
output = output.Replace("{{TITLE}}", "IW4M Administration");
|
||||||
output = output.Replace("{{VERSION}}", IW4MAdmin.Program.Version.ToString());
|
output = output.Replace("{{VERSION}}", Program.Version.ToString());
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -411,7 +413,7 @@ namespace IW4MAdmin_Web
|
|||||||
//Program.getManager().mainLog.Write(e.InnerException.Message);
|
//Program.getManager().mainLog.Write(e.InnerException.Message);
|
||||||
//Console.Write(e.InnerException);
|
//Console.Write(e.InnerException);
|
||||||
// e.DebugStackTrace();
|
// e.DebugStackTrace();
|
||||||
IW4MAdmin.Program.getManager().mainLog.Write("Web front encountered an error!");
|
Program.getManager().mainLog.Write("Web front encountered an error!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnStop(IScheduler scheduler)
|
public void OnStop(IScheduler scheduler)
|
||||||
@ -432,11 +434,11 @@ namespace IW4MAdmin_Web
|
|||||||
|
|
||||||
if (request.Uri.StartsWith("/"))
|
if (request.Uri.StartsWith("/"))
|
||||||
{
|
{
|
||||||
IW4MAdmin.file Header = new IW4MAdmin.file("webfront\\header.html");
|
IFile Header = new IFile("webfront\\header.html");
|
||||||
var header = Header.getLines();
|
var header = Header.getLines();
|
||||||
Header.Close();
|
Header.Close();
|
||||||
|
|
||||||
IW4MAdmin.file Footer = new IW4MAdmin.file("webfront\\footer.html");
|
IFile Footer = new IFile("webfront\\footer.html");
|
||||||
var footer = Footer.getLines();
|
var footer = Footer.getLines();
|
||||||
Footer.Close();
|
Footer.Close();
|
||||||
|
|
||||||
@ -451,14 +453,14 @@ namespace IW4MAdmin_Web
|
|||||||
Int32.TryParse(req[1], out page);
|
Int32.TryParse(req[1], out page);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IW4MAdmin.Program.getServers().Length < 1)
|
if (Program.getServers().Length < 1)
|
||||||
{
|
{
|
||||||
body = "<h1 style='font-family: Segoe UI;'>IT SEEMS LIKE THERE ARE NO LONGER ANY SERVERS BEING MONITORED!</h1>";
|
body = "<h1 style='font-family: Segoe UI;'>IT SEEMS LIKE THERE ARE NO LONGER ANY SERVERS BEING MONITORED!</h1>";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (request.QueryString == "bans")
|
else if (request.QueryString == "bans")
|
||||||
{
|
{
|
||||||
IW4MAdmin.file Bans = new IW4MAdmin.file("webfront\\bans.html");
|
IFile Bans = new IFile("webfront\\bans.html");
|
||||||
var bans = Bans.getLines();
|
var bans = Bans.getLines();
|
||||||
Bans.Close();
|
Bans.Close();
|
||||||
Client toSend = new Client(WebFront.Page.bans, page, request.Headers, null, null);
|
Client toSend = new Client(WebFront.Page.bans, page, request.Headers, null, null);
|
||||||
@ -467,7 +469,7 @@ namespace IW4MAdmin_Web
|
|||||||
|
|
||||||
else if (request.QueryString == "stats")
|
else if (request.QueryString == "stats")
|
||||||
{
|
{
|
||||||
IW4MAdmin.file Stats = new IW4MAdmin.file("webfront\\stats.html");
|
IFile Stats = new IFile("webfront\\stats.html");
|
||||||
var stats = Stats.getLines();
|
var stats = Stats.getLines();
|
||||||
Stats.Close();
|
Stats.Close();
|
||||||
Client toSend = new Client(WebFront.Page.stats, page, request.Headers, null, null);
|
Client toSend = new Client(WebFront.Page.stats, page, request.Headers, null, null);
|
||||||
@ -477,24 +479,25 @@ namespace IW4MAdmin_Web
|
|||||||
else if (request.QueryString == "playerhistory")
|
else if (request.QueryString == "playerhistory")
|
||||||
{
|
{
|
||||||
//type = "text/plain";
|
//type = "text/plain";
|
||||||
if (IW4MAdmin.Program.getServers().Length < server)
|
if (Program.getServers().Length < server)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
StringBuilder test = new StringBuilder();
|
StringBuilder test = new StringBuilder();
|
||||||
test.Append("<script type='text/javascript' src='//www.google.com/jsapi'></script><div id='chart_div'></div>");
|
test.Append("<script type='text/javascript' src='//www.google.com/jsapi'></script><div id='chart_div'></div>");
|
||||||
test.Append("<script> var players = [");
|
test.Append("<script> var players = [");
|
||||||
int count = 1;
|
int count = 1;
|
||||||
List<IW4MAdmin.pHistory> run = IW4MAdmin.Program.getServers()[server].playerHistory.ToList();
|
IW4MServer castServer = (IW4MServer)Program.getServers()[server];
|
||||||
foreach (IW4MAdmin.pHistory i in run) //need to reverse for proper timeline
|
List<pHistory> run = castServer.playerHistory.ToList();
|
||||||
|
foreach (pHistory i in run) //need to reverse for proper timeline
|
||||||
{
|
{
|
||||||
test.AppendFormat("[new Date({0}, {1}, {2}, {3}, {4}), {5}]", i.When.Year, i.When.Month - 1, i.When.Day, i.When.Hour, i.When.Minute, i.Players);
|
test.AppendFormat("[new Date({0}, {1}, {2}, {3}, {4}), {5}]", i.When.Year, i.When.Month - 1, i.When.Day, i.When.Hour, i.When.Minute, i.Players);
|
||||||
if (count < IW4MAdmin.Program.getServers()[server].playerHistory.Count)
|
if (count < run.Count)
|
||||||
test.Append(",\n");
|
test.Append(",\n");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
test.Append("];\n");
|
test.Append("];\n");
|
||||||
test.Append("</script>");
|
test.Append("</script>");
|
||||||
IW4MAdmin.file Graph = new IW4MAdmin.file("webfront\\graph.html");
|
IFile Graph = new IFile("webfront\\graph.html");
|
||||||
var graph = Graph.getLines();
|
var graph = Graph.getLines();
|
||||||
Graph.Close();
|
Graph.Close();
|
||||||
body = test.ToString() + graph ;
|
body = test.ToString() + graph ;
|
||||||
@ -502,7 +505,7 @@ namespace IW4MAdmin_Web
|
|||||||
|
|
||||||
else if (request.QueryString == "player")
|
else if (request.QueryString == "player")
|
||||||
{
|
{
|
||||||
IW4MAdmin.file Player = new IW4MAdmin.file("webfront\\player.html");
|
IFile Player = new IFile("webfront\\player.html");
|
||||||
var player = Player.getLines();
|
var player = Player.getLines();
|
||||||
Player.Close();
|
Player.Close();
|
||||||
String Data = null, IP = null, ID = null;
|
String Data = null, IP = null, ID = null;
|
||||||
@ -519,12 +522,12 @@ namespace IW4MAdmin_Web
|
|||||||
IP = req[2];
|
IP = req[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IW4MAdmin.Program.getServers().Length < server)
|
if (Program.getServers().Length < server)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IW4MAdmin.Player P = IW4MAdmin.Program.getServers()[server].clientDB.getPlayer(IP);
|
Player P = Program.getServers()[server].clientDB.getPlayer(IP);
|
||||||
if (P == null)
|
if (P == null)
|
||||||
P = new IW4MAdmin.Player("Guest", "Guest", 0, 0);
|
P = new Player("Guest", "Guest", 0, 0);
|
||||||
|
|
||||||
Client toSend = new Client(WebFront.Page.player, page, request.Headers, Data, P);
|
Client toSend = new Client(WebFront.Page.player, page, request.Headers, Data, P);
|
||||||
body = Macro.findMacros(header + player + footer, toSend, server);
|
body = Macro.findMacros(header + player + footer, toSend, server);
|
||||||
@ -534,17 +537,17 @@ namespace IW4MAdmin_Web
|
|||||||
{
|
{
|
||||||
StringBuilder chatMessages = new StringBuilder();
|
StringBuilder chatMessages = new StringBuilder();
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
// if (IW4MAdmin.Program.Servers[server].chatHistory.Count < 8)
|
// if (Program.Servers[server].chatHistory.Count < 8)
|
||||||
// IW4MAdmin.Program.Servers[server].chatHistory.Add(new IW4MAdmin.Chat(new IW4MAdmin.Player("TEST", "xuid", 0, 0), "TEST MESSAGE", DateTime.Now));
|
// Program.Servers[server].chatHistory.Add(new Chat(new Player("TEST", "xuid", 0, 0), "TEST MESSAGE", DateTime.Now));
|
||||||
#endif
|
#endif
|
||||||
if (IW4MAdmin.Program.getServers().Length < server)
|
if (Program.getServers().Length < server)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String IP, Text;
|
String IP, Text;
|
||||||
if (req.Length > 3)
|
if (req.Length > 3)
|
||||||
{
|
{
|
||||||
IP = req[2];
|
IP = req[2];
|
||||||
Text = IW4MAdmin.Utilities.cleanChars(HttpUtility.UrlDecode(req[3]));
|
Text = Utilities.cleanChars(HttpUtility.UrlDecode(req[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -553,21 +556,21 @@ namespace IW4MAdmin_Web
|
|||||||
Text = null;
|
Text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IP == null && IW4MAdmin.Program.getServers()[server].getClientNum() > 0)
|
if (IP == null && Program.getServers()[server].getClientNum() > 0)
|
||||||
{
|
{
|
||||||
chatMessages.Append("<table id='table_chatHistory'>");
|
chatMessages.Append("<table id='table_chatHistory'>");
|
||||||
foreach (IW4MAdmin.Chat Message in IW4MAdmin.Program.getServers()[server].chatHistory)
|
foreach (Chat Message in Program.getServers()[server].chatHistory)
|
||||||
chatMessages.AppendFormat("<tr><td class='chat_name' style='text-align: left;'>{0}</td><td class='chat_message'>{1}</td><td class='chat_time' style='text-align: right;'>{2}</td></tr>", IW4MAdmin.Utilities.nameHTMLFormatted(Message.Origin), Message.Message, Message.timeString());
|
chatMessages.AppendFormat("<tr><td class='chat_name' style='text-align: left;'>{0}</td><td class='chat_message'>{1}</td><td class='chat_time' style='text-align: right;'>{2}</td></tr>", Utilities.nameHTMLFormatted(Message.Origin), Message.Message, Message.timeString());
|
||||||
chatMessages.Append("</table>");
|
chatMessages.Append("</table>");
|
||||||
body = chatMessages.ToString();
|
body = chatMessages.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Text != null && Text.Length > 4)
|
else if (Text != null && Text.Length > 4)
|
||||||
{
|
{
|
||||||
IW4MAdmin.Player requestPlayer = IW4MAdmin.Program.getServers()[server].clientDB.getPlayer(IP);
|
Player requestPlayer = Program.getServers()[server].clientDB.getPlayer(IP);
|
||||||
|
|
||||||
if (requestPlayer != null)
|
if (requestPlayer != null)
|
||||||
IW4MAdmin.Program.getServers()[server].webChat(requestPlayer, Text);
|
Program.getServers()[server].webChat(requestPlayer, Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,24 +579,24 @@ namespace IW4MAdmin_Web
|
|||||||
type = "text/plain";
|
type = "text/plain";
|
||||||
StringBuilder banTXT = new StringBuilder();
|
StringBuilder banTXT = new StringBuilder();
|
||||||
banTXT.AppendFormat("===========================================\nIW4M ADMIN PUBLIC BAN LIST\nGENERATED {0}\nIP---GUID---REASON---TIME\n===========================================\n", DateTime.Now.ToString());
|
banTXT.AppendFormat("===========================================\nIW4M ADMIN PUBLIC BAN LIST\nGENERATED {0}\nIP---GUID---REASON---TIME\n===========================================\n", DateTime.Now.ToString());
|
||||||
foreach (IW4MAdmin.Ban B in IW4MAdmin.Program.getServers()[0].Bans)
|
foreach (Ban B in Program.getServers()[0].Bans)
|
||||||
{
|
{
|
||||||
if (B.getIP() != null && B.getIP() != String.Empty && B.getReason() != null && B.getReason() != String.Empty)
|
if (B.IP != null && B.IP != String.Empty && B.Reason != null && B.Reason != String.Empty)
|
||||||
banTXT.AppendFormat("{0}---{1}---{2}---{3}\n", B.getIP(), B.getID(), B.getReason().Trim(), Math.Round((B.getTime()-DateTime.MinValue).TotalSeconds, 0));
|
banTXT.AppendFormat("{0}---{1}---{2}---{3}\n", B.IP, B.npID, B.Reason.Trim(), Math.Round((B.When-DateTime.MinValue).TotalSeconds, 0));
|
||||||
}
|
}
|
||||||
body = banTXT.ToString();
|
body = banTXT.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IW4MAdmin.file Main = new IW4MAdmin.file("webfront\\main.html");
|
IFile Main = new IFile("webfront\\main.html");
|
||||||
var main = Main.getLines();
|
var main = Main.getLines();
|
||||||
Main.Close();
|
Main.Close();
|
||||||
Client toSend = new Client(WebFront.Page.main, page, request.Headers, null, null);
|
Client toSend = new Client(WebFront.Page.main, page, request.Headers, null, null);
|
||||||
body = Macro.findMacros(header + main + footer, toSend, server);
|
body = Macro.findMacros(header + main + footer, toSend, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
//IW4MAdmin.Program.getServers()[server].Log.Write("Webfront processed request for " + request.Uri, IW4MAdmin.Log.Level.Debug);
|
//Program.getServers()[server].Log.Write("Webfront processed request for " + request.Uri, Log.Level.Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
var headers = new HttpResponseHead()
|
var headers = new HttpResponseHead()
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||||
|
</startup>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<probing privatePath="lib" />
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
||||||
|
54
Admin/app.manifest
Normal file
54
Admin/app.manifest
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
|
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||||
|
<security>
|
||||||
|
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<!-- UAC Manifest Options
|
||||||
|
If you want to change the Windows User Account Control level replace the
|
||||||
|
requestedExecutionLevel node with one of the following.
|
||||||
|
|
||||||
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||||
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||||
|
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
||||||
|
|
||||||
|
Specifying requestedExecutionLevel node will disable file and registry virtualization.
|
||||||
|
If you want to utilize File and Registry Virtualization for backward
|
||||||
|
compatibility then delete the requestedExecutionLevel node.
|
||||||
|
-->
|
||||||
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||||
|
</requestedPrivileges>
|
||||||
|
<applicationRequestMinimum>
|
||||||
|
<PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
|
||||||
|
<defaultAssemblyRequest permissionSetReference="Custom" />
|
||||||
|
</applicationRequestMinimum>
|
||||||
|
</security>
|
||||||
|
</trustInfo>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- A list of all Windows versions that this application is designed to work with.
|
||||||
|
Windows will automatically select the most compatible environment.-->
|
||||||
|
<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
|
||||||
|
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
|
||||||
|
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
|
||||||
|
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
|
||||||
|
<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
|
||||||
|
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
|
||||||
|
<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
|
||||||
|
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
|
||||||
|
<!-- <dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity
|
||||||
|
type="win32"
|
||||||
|
name="Microsoft.Windows.Common-Controls"
|
||||||
|
version="6.0.0.0"
|
||||||
|
processorArchitecture="*"
|
||||||
|
publicKeyToken="6595b64144ccf1df"
|
||||||
|
language="*"
|
||||||
|
/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>-->
|
||||||
|
</asmv1:assembly>
|
BIN
Admin/lib/SharedLibary.dll
Normal file
BIN
Admin/lib/SharedLibary.dll
Normal file
Binary file not shown.
BIN
Admin/plugins/SamplePlugin.dll
Normal file
BIN
Admin/plugins/SamplePlugin.dll
Normal file
Binary file not shown.
@ -1,10 +1,14 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2013
|
# Visual Studio 2013
|
||||||
VisualStudioVersion = 12.0.40629.0
|
VisualStudioVersion = 12.0.30723.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IW4M ADMIN", "Admin\IW4M ADMIN.csproj", "{DD5DCDA2-51DB-4B1A-922F-5705546E6115}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IW4M ADMIN", "Admin\IW4M ADMIN.csproj", "{DD5DCDA2-51DB-4B1A-922F-5705546E6115}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLibrary", "SharedLibary\SharedLibrary.csproj", "{D51EECEB-438A-47DA-870F-7D7B41BC24D6}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{4785AB75-66F3-4391-985D-63A5A049A0FA}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -15,6 +19,14 @@ Global
|
|||||||
{DD5DCDA2-51DB-4B1A-922F-5705546E6115}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{DD5DCDA2-51DB-4B1A-922F-5705546E6115}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{DD5DCDA2-51DB-4B1A-922F-5705546E6115}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{DD5DCDA2-51DB-4B1A-922F-5705546E6115}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{DD5DCDA2-51DB-4B1A-922F-5705546E6115}.Release|Any CPU.Build.0 = Release|Any CPU
|
{DD5DCDA2-51DB-4B1A-922F-5705546E6115}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4785AB75-66F3-4391-985D-63A5A049A0FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4785AB75-66F3-4391-985D-63A5A049A0FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4785AB75-66F3-4391-985D-63A5A049A0FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4785AB75-66F3-4391-985D-63A5A049A0FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
45
SamplePlugin/Main.cs
Normal file
45
SamplePlugin/Main.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using SharedLibrary;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SamplePlugin
|
||||||
|
{
|
||||||
|
public class SampleCommand : Command
|
||||||
|
{
|
||||||
|
public SampleCommand() : base("testplugin", "sample plugin command. syntax !testplugin", "tp", Player.Permission.User, 0, false) { }
|
||||||
|
|
||||||
|
public override void Execute(Event E)
|
||||||
|
{
|
||||||
|
Player clientWhoSent = E.Origin;
|
||||||
|
Server originatingServer = E.Owner;
|
||||||
|
|
||||||
|
String[] messageToClient = {
|
||||||
|
String.Format("The command {0} was requested by ^3{1}", Name, clientWhoSent.Name),
|
||||||
|
String.Format("The command was request on server ^1{0}", originatingServer.getName())
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (String Line in messageToClient)
|
||||||
|
clientWhoSent.Tell(Line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AnotherSampleCommand : Command
|
||||||
|
{
|
||||||
|
public AnotherSampleCommand() : base("scream", "broadcast your message. syntax !scream <message>", "s", Player.Permission.Moderator, 1, false) { }
|
||||||
|
|
||||||
|
public override void Execute(Event E)
|
||||||
|
{
|
||||||
|
Server originatingServer = E.Owner;
|
||||||
|
String Message = E.Data;
|
||||||
|
String Sender = E.Origin.Name;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
originatingServer.Broadcast(String.Format("^7{0}: {1}", Sender, Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InvalidCommandExample
|
||||||
|
{
|
||||||
|
private void doNotDoThis() { }
|
||||||
|
}
|
||||||
|
}
|
36
SamplePlugin/Properties/AssemblyInfo.cs
Normal file
36
SamplePlugin/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("SamplePlugin")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("SamplePlugin")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("1d848d36-bf25-4bc0-acdd-67db2d014d45")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
57
SamplePlugin/SamplePlugin.csproj
Normal file
57
SamplePlugin/SamplePlugin.csproj
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{4785AB75-66F3-4391-985D-63A5A049A0FA}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>SamplePlugin</RootNamespace>
|
||||||
|
<AssemblyName>SamplePlugin</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="SharedLibary">
|
||||||
|
<HintPath>..\SharedLibary\bin\Release\SharedLibary.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Main.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- 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.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
30
SharedLibary/Ban.cs
Normal file
30
SharedLibary/Ban.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public class Ban
|
||||||
|
{
|
||||||
|
public Ban(String Reas, String TargID, String From, DateTime time, String ip)
|
||||||
|
{
|
||||||
|
Reason = Reas;
|
||||||
|
npID = TargID;
|
||||||
|
bannedByID = From;
|
||||||
|
When = time;
|
||||||
|
IP = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWhen()
|
||||||
|
{
|
||||||
|
return When.ToString("MM/dd/yy HH:mm:ss"); ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Reason { get; private set; }
|
||||||
|
public String npID { get; private set; }
|
||||||
|
public String bannedByID { get; private set; }
|
||||||
|
public DateTime When { get; private set; }
|
||||||
|
public String IP { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
30
SharedLibary/Command.cs
Normal file
30
SharedLibary/Command.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public abstract class Command
|
||||||
|
{
|
||||||
|
public Command(String N, String D, String A, Player.Permission P, int args, bool nT)
|
||||||
|
{
|
||||||
|
Name = N;
|
||||||
|
Description = D;
|
||||||
|
Alias = A;
|
||||||
|
Permission = P;
|
||||||
|
requiredArgNum = args;
|
||||||
|
needsTarget = nT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Execute the command
|
||||||
|
abstract public void Execute(Event E);
|
||||||
|
|
||||||
|
public String Name { get; private set; }
|
||||||
|
public String Description { get; private set; }
|
||||||
|
public String Alias { get; private set; }
|
||||||
|
public int requiredArgNum { get; private set; }
|
||||||
|
public bool needsTarget { get; private set; }
|
||||||
|
public Player.Permission Permission { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
630
SharedLibary/Database.cs
Normal file
630
SharedLibary/Database.cs
Normal file
@ -0,0 +1,630 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public abstract class Database
|
||||||
|
{
|
||||||
|
public Database(String FN)
|
||||||
|
{
|
||||||
|
FileName = FN;
|
||||||
|
DBCon = String.Format("Data Source={0}", FN);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Con = new SQLiteConnection(DBCon);
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(System.DllNotFoundException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Could not locate the SQLite DLL!\nEnsure it is located in the 'lib' folder");
|
||||||
|
Utilities.Wait(5);
|
||||||
|
System.Environment.Exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Open = false;
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void Init();
|
||||||
|
|
||||||
|
protected bool Insert(String tableName, Dictionary<String, object> data)
|
||||||
|
{
|
||||||
|
String columns = "";
|
||||||
|
String values = "";
|
||||||
|
Boolean returnCode = true;
|
||||||
|
foreach (KeyValuePair<String, object> val in data)
|
||||||
|
{
|
||||||
|
columns += String.Format(" {0},", val.Key);
|
||||||
|
values += String.Format(" '{0}',", val.Value);
|
||||||
|
}
|
||||||
|
columns = columns.Substring(0, columns.Length - 1);
|
||||||
|
values = values.Substring(0, values.Length - 1);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.ExecuteNonQuery(String.Format("insert into {0}({1}) values({2});", tableName, columns, values));
|
||||||
|
}
|
||||||
|
catch (Exception fail)
|
||||||
|
{
|
||||||
|
Console.WriteLine(fail.Message);
|
||||||
|
returnCode = false;
|
||||||
|
}
|
||||||
|
return returnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool Update(String tableName, Dictionary<String, object> data, String where)
|
||||||
|
{
|
||||||
|
String vals = "";
|
||||||
|
Boolean returnCode = true;
|
||||||
|
if (data.Count >= 1)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<String, object> val in data)
|
||||||
|
{
|
||||||
|
vals += String.Format(" {0} = '{1}',", val.Key, val.Value);
|
||||||
|
}
|
||||||
|
vals = vals.Substring(0, vals.Length - 1);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ExecuteNonQuery(String.Format("update {0} set {1} where {2};", tableName, vals, where));
|
||||||
|
}
|
||||||
|
catch (Exception fail)
|
||||||
|
{
|
||||||
|
Console.WriteLine(fail.Message);
|
||||||
|
returnCode = false;
|
||||||
|
}
|
||||||
|
return returnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DataRow getDataRow(String Q)
|
||||||
|
{
|
||||||
|
DataRow Result = GetDataTable(Q).Rows[0];
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int ExecuteNonQuery(String Request)
|
||||||
|
{
|
||||||
|
waitForClose();
|
||||||
|
int rowsUpdated = 0;
|
||||||
|
|
||||||
|
lock (Con)
|
||||||
|
{
|
||||||
|
Con.Open();
|
||||||
|
SQLiteCommand CMD = new SQLiteCommand(Con);
|
||||||
|
CMD.CommandText = Request;
|
||||||
|
rowsUpdated = CMD.ExecuteNonQuery();
|
||||||
|
Con.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rowsUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DataTable GetDataTable(String sql)
|
||||||
|
{
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
waitForClose();
|
||||||
|
lock (Con)
|
||||||
|
{
|
||||||
|
Con.Open();
|
||||||
|
SQLiteCommand mycommand = new SQLiteCommand(Con);
|
||||||
|
mycommand.CommandText = sql;
|
||||||
|
SQLiteDataReader reader = mycommand.ExecuteReader();
|
||||||
|
dt.Load(reader);
|
||||||
|
reader.Close();
|
||||||
|
Con.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
throw new Exception(e.Message);
|
||||||
|
}
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void waitForClose()
|
||||||
|
{
|
||||||
|
while (Con.State == ConnectionState.Open)
|
||||||
|
{
|
||||||
|
Utilities.Wait(0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String FileName;
|
||||||
|
protected String DBCon;
|
||||||
|
protected SQLiteConnection Con;
|
||||||
|
protected bool Open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ClientsDB : Database
|
||||||
|
{
|
||||||
|
public ClientsDB(String FN) : base(FN) { }
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
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);";
|
||||||
|
ExecuteNonQuery(Create);
|
||||||
|
Create = "CREATE TABLE [BANS] ( [Reason] TEXT NULL, [npID] TEXT NULL, [bannedByID] TEXT NULL, [IP] TEXT NULL, [TIME] TEXT NULL);";
|
||||||
|
ExecuteNonQuery(Create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns a single player object with matching GUID, false if no matches
|
||||||
|
public Player getPlayer(String ID, int cNum)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM CLIENTS WHERE npID = '{0}' LIMIT 1", ID);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
DataRow ResponseRow = Result.Rows[0];
|
||||||
|
DateTime LC;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LC = DateTime.Parse(ResponseRow["LastConnection"].ToString());
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
LC = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(), LC);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Overloaded method for getPlayer, returns Client with matching DBIndex, null if none found
|
||||||
|
public Player getPlayer(int dbIndex)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM CLIENTS WHERE Number = '{0}' LIMIT 1", dbIndex);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
DataRow p = Result.Rows[0];
|
||||||
|
DateTime LC;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LC = DateTime.Parse(p["LastConnection"].ToString());
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
LC = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//get player by ip, (used for webfront)
|
||||||
|
public Player getPlayer(String IP)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM CLIENTS WHERE IP='{0}'", IP);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
List<Player> lastKnown = new List<Player>();
|
||||||
|
foreach (DataRow p in Result.Rows)
|
||||||
|
{
|
||||||
|
DateTime LC;
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastKnown.Count > 0)
|
||||||
|
{
|
||||||
|
List<Player> Returning = lastKnown.OrderBy(t => t.Connections).ToList();
|
||||||
|
return Returning[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns a list of players matching name parameter, null if no players found matching
|
||||||
|
public List<Player> findPlayers(String name)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM CLIENTS WHERE Name LIKE '%{0}%' LIMIT 8", name);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
List<Player> Players = new List<Player>();
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow p in Result.Rows)
|
||||||
|
{
|
||||||
|
DateTime LC;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LC = DateTime.Parse(p["LastConnection"].ToString());
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
LC = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
return Players;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns any player with level 4 permissions, null if no owner found
|
||||||
|
public Player getOwner()
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM CLIENTS WHERE Level > '{0}'", 4);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
DataRow ResponseRow = Result.Rows[0];
|
||||||
|
if (ResponseRow["IP"].ToString().Length < 6)
|
||||||
|
ResponseRow["IP"] = "0";
|
||||||
|
return new Player(ResponseRow["Name"].ToString(), ResponseRow["npID"].ToString(), -1, (Player.Permission)(ResponseRow["Level"]), Convert.ToInt32(ResponseRow["Number"]), null, 0, ResponseRow["IP"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns list of bans in database
|
||||||
|
public List<Ban> getBans()
|
||||||
|
{
|
||||||
|
List<Ban> Bans = new List<Ban>();
|
||||||
|
DataTable Result = GetDataTable("SELECT * FROM BANS ORDER BY TIME DESC");
|
||||||
|
|
||||||
|
foreach (DataRow Row in Result.Rows)
|
||||||
|
{
|
||||||
|
if (Row["TIME"].ToString().Length < 2) //compatibility with my old database
|
||||||
|
Row["TIME"] = DateTime.Now.ToString();
|
||||||
|
|
||||||
|
Bans.Add(new Ban(Row["Reason"].ToString(), Row["npID"].ToString(), Row["bannedByID"].ToString(), DateTime.Parse(Row["TIME"].ToString()), Row["IP"].ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Bans;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns all players with level > Flagged
|
||||||
|
public List<Player> getAdmins()
|
||||||
|
{
|
||||||
|
List<Player> Admins = new List<Player>();
|
||||||
|
String Query = String.Format("SELECT * FROM CLIENTS WHERE LEVEL > '{0}'", 1);
|
||||||
|
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()));
|
||||||
|
|
||||||
|
return Admins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns total number of player entries in database
|
||||||
|
public int totalPlayers()
|
||||||
|
{
|
||||||
|
DataTable Result = GetDataTable("SELECT * from CLIENTS ORDER BY Number DESC LIMIT 1");
|
||||||
|
if (Result.Rows.Count > 0)
|
||||||
|
return Convert.ToInt32(Result.Rows[0]["Number"]);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add specified player to database
|
||||||
|
public void addPlayer(Player P)
|
||||||
|
{
|
||||||
|
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
|
newPlayer.Add("Name", Utilities.removeNastyChars(P.Name));
|
||||||
|
newPlayer.Add("npID", P.npID);
|
||||||
|
newPlayer.Add("Level", (int)P.Level);
|
||||||
|
newPlayer.Add("LastOffense", "");
|
||||||
|
newPlayer.Add("Connections", 1);
|
||||||
|
newPlayer.Add("IP", P.IP);
|
||||||
|
newPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
||||||
|
|
||||||
|
Insert("CLIENTS", newPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Update information of specified player
|
||||||
|
public void updatePlayer(Player P)
|
||||||
|
{
|
||||||
|
Dictionary<String, Object> updatedPlayer = new Dictionary<String, Object>();
|
||||||
|
|
||||||
|
updatedPlayer.Add("Name", P.Name);
|
||||||
|
updatedPlayer.Add("npID", P.npID);
|
||||||
|
updatedPlayer.Add("Level", (int)P.Level);
|
||||||
|
updatedPlayer.Add("LastOffense", P.lastOffense);
|
||||||
|
updatedPlayer.Add("Connections", P.Connections);
|
||||||
|
updatedPlayer.Add("IP", P.IP);
|
||||||
|
updatedPlayer.Add("LastConnection", Utilities.DateTimeSQLite(DateTime.Now));
|
||||||
|
|
||||||
|
Update("CLIENTS", updatedPlayer, String.Format("npID = '{0}'", P.npID));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Add specified ban to database
|
||||||
|
public void addBan(Ban B)
|
||||||
|
{
|
||||||
|
Dictionary<String, object> newBan = new Dictionary<String, object>();
|
||||||
|
|
||||||
|
newBan.Add("Reason", B.Reason);
|
||||||
|
newBan.Add("npID", B.npID);
|
||||||
|
newBan.Add("bannedByID", B.bannedByID);
|
||||||
|
newBan.Add("IP", B.IP);
|
||||||
|
newBan.Add("TIME", Utilities.DateTimeSQLite(DateTime.Now));
|
||||||
|
|
||||||
|
Insert("BANS", newBan);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Deletes ban with matching GUID
|
||||||
|
public void removeBan(String GUID)
|
||||||
|
{
|
||||||
|
String Query = String.Format("DELETE FROM BANS WHERE npID = '{0}'", GUID);
|
||||||
|
ExecuteNonQuery(Query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeBan(String GUID, String IP)
|
||||||
|
{
|
||||||
|
String Query = String.Format("DELETE FROM BANS WHERE npID = '{0}' or IP= '%{1}%'", GUID, IP);
|
||||||
|
ExecuteNonQuery(Query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StatsDB : Database
|
||||||
|
{
|
||||||
|
public StatsDB(String FN) : base(FN) { }
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
if (!File.Exists(FileName))
|
||||||
|
{
|
||||||
|
String Create = "CREATE TABLE [STATS] ( [Number] INTEGER, [KILLS] INTEGER DEFAULT 0, [DEATHS] INTEGER DEFAULT 0, [KDR] REAL DEFAULT 0, [SKILL] REAL DEFAULT 0, [MEAN] REAL DEFAULT 0, [DEV] REAL DEFAULT 0 );";
|
||||||
|
ExecuteNonQuery(Create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return stats for player specified by Database ID, null if no matches
|
||||||
|
public Stats getStats(int DBID)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM STATS WHERE Number = '{0}'", DBID);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
DataRow ResponseRow = Result.Rows[0];
|
||||||
|
if (ResponseRow["MEAN"] == DBNull.Value)
|
||||||
|
ResponseRow["MEAN"] = 0; // Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.Mean;
|
||||||
|
if (ResponseRow["DEV"] == DBNull.Value)
|
||||||
|
ResponseRow["DEV"] = 0; // Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.StandardDeviation;
|
||||||
|
if (ResponseRow["SKILL"] == DBNull.Value)
|
||||||
|
ResponseRow["SKILL"] = 0;
|
||||||
|
|
||||||
|
return new Stats(Convert.ToInt32(ResponseRow["Number"]), Convert.ToInt32(ResponseRow["KILLS"]), Convert.ToInt32(ResponseRow["DEATHS"]), Convert.ToDouble(ResponseRow["KDR"]), Convert.ToDouble(ResponseRow["SKILL"]), Convert.ToDouble(ResponseRow["MEAN"]), Convert.ToDouble(ResponseRow["DEV"]));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayer(Player P)
|
||||||
|
{
|
||||||
|
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
|
newPlayer.Add("Number", P.databaseID);
|
||||||
|
newPlayer.Add("KILLS", 0);
|
||||||
|
newPlayer.Add("DEATHS", 0);
|
||||||
|
newPlayer.Add("KDR", 0);
|
||||||
|
newPlayer.Add("SKILL", 0); //Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.ConservativeRating);
|
||||||
|
newPlayer.Add("MEAN", 0); //Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.Mean);
|
||||||
|
newPlayer.Add("DEV", 0); //Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.StandardDeviation);
|
||||||
|
|
||||||
|
Insert("STATS", newPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Update stat information of specified player
|
||||||
|
public void updatePlayer(Player P)
|
||||||
|
{
|
||||||
|
if (P.stats == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Dictionary<String, object> updatedPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
|
updatedPlayer.Add("KILLS", P.stats.Kills);
|
||||||
|
updatedPlayer.Add("DEATHS", P.stats.Deaths);
|
||||||
|
updatedPlayer.Add("KDR", Math.Round(P.stats.KDR, 2));
|
||||||
|
updatedPlayer.Add("SKILL", P.stats.Skill);
|
||||||
|
//updatedPlayer.Add("MEAN", P.stats.Rating.Mean);
|
||||||
|
//updatedPlayer.Add("DEV", P.stats.Rating.StandardDeviation);
|
||||||
|
|
||||||
|
Update("STATS", updatedPlayer, String.Format("Number = '{0}'", P.databaseID));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns top 5 players (we filter through them later)
|
||||||
|
public List<Stats> topStats()
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM STATS WHERE KILLS > '{0}' AND KDR < '{1}' AND SKILL > '{2}' ORDER BY SKILL DESC LIMIT 5", 250, 7, 245);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
List<Stats> Top = new List<Stats>();
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow D in Result.Rows)
|
||||||
|
{
|
||||||
|
if (D["MEAN"] == DBNull.Value || D["DEV"] == DBNull.Value || D["SKILL"] == DBNull.Value)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Stats S = new Stats(Convert.ToInt32(D["Number"]), Convert.ToInt32(D["KILLS"]), Convert.ToInt32(D["DEATHS"]), Convert.ToDouble(D["KDR"]), Convert.ToDouble(D["SKILL"]), Convert.ToDouble(D["MEAN"]), Convert.ToDouble(D["DEV"]));
|
||||||
|
Top.Add(S);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Top;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stats> getMultipleStats(int start, int length)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM STATS ORDER BY SKILL DESC LIMIT '{0}' OFFSET '{1}'", length, start);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
List<Stats> Stats = new List<Stats>();
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow D in Result.Rows)
|
||||||
|
{
|
||||||
|
if (D["MEAN"] == DBNull.Value)
|
||||||
|
continue;
|
||||||
|
if (D["DEV"] == DBNull.Value)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (D["SKILL"] == DBNull.Value)
|
||||||
|
D["SKILL"] = 0;
|
||||||
|
|
||||||
|
Stats S = new Stats(Convert.ToInt32(D["Number"]), Convert.ToInt32(D["KILLS"]), Convert.ToInt32(D["DEATHS"]), Convert.ToDouble(D["KDR"]), Convert.ToDouble(D["SKILL"]), Convert.ToDouble(D["MEAN"]), Convert.ToDouble(D["DEV"]));
|
||||||
|
Stats.Add(S);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int totalStats()
|
||||||
|
{
|
||||||
|
DataTable Result = GetDataTable("SELECT * FROM STATS");
|
||||||
|
return Result.Rows.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearSkill()
|
||||||
|
{
|
||||||
|
String Query = "SELECT * FROM STATS";
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow D in Result.Rows)
|
||||||
|
Update("STATS", new Dictionary<String, Object>() { { "SKILL", 1 } }, String.Format("Number = '{0}'", D["Number"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AliasesDB : Database
|
||||||
|
{
|
||||||
|
public AliasesDB(String FN) : base(FN) { }
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
if (!File.Exists(FileName))
|
||||||
|
{
|
||||||
|
String Create = "CREATE TABLE [ALIASES] ( [Number] INTEGER, [NAMES] TEXT NULL, [IPS] TEXTNULL );";
|
||||||
|
ExecuteNonQuery(Create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Aliases getPlayer(int dbIndex)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM ALIASES WHERE Number = '{0}' LIMIT 1", dbIndex);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
DataRow p = Result.Rows[0];
|
||||||
|
return new Aliases(Convert.ToInt32(p["Number"]), p["NAMES"].ToString(), p["IPS"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Aliases> getPlayer(String IP)
|
||||||
|
{
|
||||||
|
String Query = String.Format("SELECT * FROM ALIASES WHERE IPS LIKE '%{0}%'", IP);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
List<Aliases> players = new List<Aliases>();
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow p in Result.Rows)
|
||||||
|
players.Add(new Aliases(Convert.ToInt32(p["Number"]), p["NAMES"].ToString(), p["IPS"].ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Aliases> findPlayers(String name)
|
||||||
|
{
|
||||||
|
String[] EyePee = name.Split('.');
|
||||||
|
String Penor = "THISISNOTANIP";
|
||||||
|
if (EyePee.Length > 1)
|
||||||
|
Penor = (EyePee[0] + '.' + EyePee[1] + '.');
|
||||||
|
|
||||||
|
String Query = String.Format("SELECT * FROM ALIASES WHERE NAMES LIKE '%{0}%' OR IPS LIKE '%{1}%' LIMIT 15", name, Penor);
|
||||||
|
DataTable Result = GetDataTable(Query);
|
||||||
|
|
||||||
|
List<Aliases> players = new List<Aliases>();
|
||||||
|
|
||||||
|
if (Result != null && Result.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (DataRow p in Result.Rows)
|
||||||
|
players.Add(new Aliases(Convert.ToInt32(p["Number"]), p["NAMES"].ToString(), p["IPS"].ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayer(Aliases Alias)
|
||||||
|
{
|
||||||
|
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
|
newPlayer.Add("Number", Alias.getNumber());
|
||||||
|
newPlayer.Add("NAMES", Alias.getNamesDB());
|
||||||
|
newPlayer.Add("IPS", Alias.getIPSDB());
|
||||||
|
|
||||||
|
Insert("ALIASES", newPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePlayer(Aliases Alias)
|
||||||
|
{
|
||||||
|
Dictionary<String, object> updatedPlayer = new Dictionary<String, object>();
|
||||||
|
|
||||||
|
updatedPlayer.Add("Number", Alias.getNumber());
|
||||||
|
updatedPlayer.Add("NAMES", Alias.getNamesDB());
|
||||||
|
updatedPlayer.Add("IPS", Alias.getIPSDB());
|
||||||
|
|
||||||
|
Update("ALIASES", updatedPlayer, String.Format("Number = '{0}'", Alias.getNumber()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
SharedLibary/Dvar.cs
Normal file
19
SharedLibary/Dvar.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public struct dvar
|
||||||
|
{
|
||||||
|
public String name;
|
||||||
|
public String description;
|
||||||
|
public int flags;
|
||||||
|
public short type;
|
||||||
|
public String current;
|
||||||
|
public String latched;
|
||||||
|
public String _default;
|
||||||
|
public int min;
|
||||||
|
public int max;
|
||||||
|
}
|
||||||
|
}
|
@ -3,11 +3,11 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace SharedLibrary
|
||||||
{
|
{
|
||||||
class Chat
|
public class Chat
|
||||||
{
|
{
|
||||||
public Chat ( Player O, String M, DateTime D)
|
public Chat(Player O, String M, DateTime D)
|
||||||
{
|
{
|
||||||
Origin = O;
|
Origin = O;
|
||||||
Message = M;
|
Message = M;
|
||||||
@ -24,7 +24,7 @@ namespace IW4MAdmin
|
|||||||
public DateTime Time { get; private set; }
|
public DateTime Time { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Event
|
public class Event
|
||||||
{
|
{
|
||||||
public enum GType
|
public enum GType
|
||||||
{
|
{
|
||||||
@ -42,7 +42,6 @@ namespace IW4MAdmin
|
|||||||
Tell,
|
Tell,
|
||||||
Kick,
|
Kick,
|
||||||
Ban,
|
Ban,
|
||||||
|
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +54,6 @@ namespace IW4MAdmin
|
|||||||
Owner = S;
|
Owner = S;
|
||||||
}
|
}
|
||||||
|
|
||||||
//This needs to be here
|
|
||||||
public Command isValidCMD(List<Command> list)
|
public Command isValidCMD(List<Command> list)
|
||||||
{
|
{
|
||||||
if (this.Data.Substring(0, 1) == "!")
|
if (this.Data.Substring(0, 1) == "!")
|
||||||
@ -64,7 +62,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
foreach (Command C in list)
|
foreach (Command C in list)
|
||||||
{
|
{
|
||||||
if (C.getName() == cmd[0].ToLower() || C.getAlias() == cmd[0].ToLower())
|
if (C.Name == cmd[0].ToLower() || C.Alias == cmd[0].ToLower())
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +122,5 @@ namespace IW4MAdmin
|
|||||||
public Player Origin;
|
public Player Origin;
|
||||||
public Player Target;
|
public Player Target;
|
||||||
public Server Owner;
|
public Server Owner;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
134
SharedLibary/File.cs
Normal file
134
SharedLibary/File.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public class IFile
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
|
||||||
|
if (!Directory.Exists(_Directory))
|
||||||
|
Directory.CreateDirectory(_Directory);
|
||||||
|
|
||||||
|
if (!File.Exists(fileName))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileStream penis = File.Create(fileName);
|
||||||
|
penis.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to create file!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Handle = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
|
||||||
|
sze = Handle.BaseStream.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//Console.WriteLine("Unable to open log file for writing!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IFile(String file, bool write)
|
||||||
|
{
|
||||||
|
Name = file;
|
||||||
|
writeHandle = new StreamWriter(new FileStream(Name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
|
||||||
|
sze = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSize()
|
||||||
|
{
|
||||||
|
sze = Handle.BaseStream.Length;
|
||||||
|
return sze;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(String line)
|
||||||
|
{
|
||||||
|
if (writeHandle != null)
|
||||||
|
{
|
||||||
|
writeHandle.WriteLine(line);
|
||||||
|
writeHandle.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getParameters(int num)
|
||||||
|
{
|
||||||
|
if (sze > 0)
|
||||||
|
{
|
||||||
|
String firstLine = Handle.ReadLine();
|
||||||
|
String[] Parms = firstLine.Split(':');
|
||||||
|
if (Parms.Length < num)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return Parms;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
if (Handle != null)
|
||||||
|
Handle.Close();
|
||||||
|
if (writeHandle != null)
|
||||||
|
writeHandle.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] readAll()
|
||||||
|
{
|
||||||
|
return Handle.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLines()
|
||||||
|
{
|
||||||
|
return Handle.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] Tail(int lineCount)
|
||||||
|
{
|
||||||
|
var buffer = new List<string>(lineCount);
|
||||||
|
string line;
|
||||||
|
for (int i = 0; i < lineCount; i++)
|
||||||
|
{
|
||||||
|
line = Handle.ReadLine();
|
||||||
|
if (line == null) return buffer.ToArray();
|
||||||
|
buffer.Add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lastLine = lineCount - 1; //The index of the last line read from the buffer. Everything > this index was read earlier than everything <= this indes
|
||||||
|
|
||||||
|
while (null != (line = Handle.ReadLine()))
|
||||||
|
{
|
||||||
|
lastLine++;
|
||||||
|
if (lastLine == lineCount) lastLine = 0;
|
||||||
|
buffer[lastLine] = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastLine == lineCount - 1) return buffer.ToArray();
|
||||||
|
var retVal = new string[lineCount];
|
||||||
|
buffer.CopyTo(lastLine + 1, retVal, 0, lineCount - lastLine - 1);
|
||||||
|
buffer.CopyTo(0, retVal, lineCount - lastLine - 1, lastLine + 1);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
//END
|
||||||
|
|
||||||
|
private long sze;
|
||||||
|
private String Name;
|
||||||
|
private String _Directory;
|
||||||
|
private StreamReader Handle;
|
||||||
|
private StreamWriter writeHandle;
|
||||||
|
}
|
||||||
|
}
|
61
SharedLibary/Log.cs
Normal file
61
SharedLibary/Log.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public class Log
|
||||||
|
{
|
||||||
|
public enum Level
|
||||||
|
{
|
||||||
|
All,
|
||||||
|
Debug,
|
||||||
|
Production,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log(IFile logf, Level mode, int port)
|
||||||
|
{
|
||||||
|
logFile = logf;
|
||||||
|
logMode = mode;
|
||||||
|
Identifier = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(String line)
|
||||||
|
{
|
||||||
|
Write(line, Level.Debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(String line, Level lv)
|
||||||
|
{
|
||||||
|
String Line = String.Format("{1} - [{0}]: {2}", Identifier, getTime(), line);
|
||||||
|
switch (logMode)
|
||||||
|
{
|
||||||
|
case Level.All:
|
||||||
|
if (lv == Level.All || lv == Level.Debug || lv == Level.Production)
|
||||||
|
Console.WriteLine(Line);
|
||||||
|
break;
|
||||||
|
case Level.Debug:
|
||||||
|
if (lv == Level.All || lv == Level.Debug)
|
||||||
|
Console.WriteLine(Line);
|
||||||
|
break;
|
||||||
|
case Level.Production:
|
||||||
|
if (lv == Level.Production)
|
||||||
|
Console.WriteLine(Line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
logFile.Write(Line);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string getTime()
|
||||||
|
{
|
||||||
|
return DateTime.Now.ToString("HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
private IFile logFile;
|
||||||
|
private Level logMode;
|
||||||
|
private int Identifier;
|
||||||
|
}
|
||||||
|
}
|
19
SharedLibary/Map.cs
Normal file
19
SharedLibary/Map.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public class Map
|
||||||
|
{
|
||||||
|
public Map(String N, String A)
|
||||||
|
{
|
||||||
|
Name = N;
|
||||||
|
Alias = A;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Name { get; private set; }
|
||||||
|
public String Alias { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
235
SharedLibary/Player.cs
Normal file
235
SharedLibary/Player.cs
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public class Stats
|
||||||
|
{
|
||||||
|
public Stats(int n, int K, int D, double kdr, double skill, double mean, double dev)
|
||||||
|
{
|
||||||
|
statIndex = n;
|
||||||
|
Kills = K;
|
||||||
|
Deaths = D;
|
||||||
|
KDR = Math.Round(kdr, 2);
|
||||||
|
|
||||||
|
//Rating = new Moserware.Skills.Rating(mean, dev);
|
||||||
|
//Skill = Math.Round(Rating.ConservativeRating, 3) * 10;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateKDR()
|
||||||
|
{
|
||||||
|
int tempDeaths = Deaths; // cuz we don't want undefined!
|
||||||
|
if (Deaths == 0)
|
||||||
|
tempDeaths = 1;
|
||||||
|
|
||||||
|
KDR = Math.Round((double)((double)Kills / (double)tempDeaths), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Kills;
|
||||||
|
public int Deaths;
|
||||||
|
public double KDR;
|
||||||
|
public double Skill;
|
||||||
|
public int statIndex;
|
||||||
|
// public Moserware.Skills.Rating Rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Aliases
|
||||||
|
{
|
||||||
|
public Aliases(int Num, String N, String I)
|
||||||
|
{
|
||||||
|
Number = Num;
|
||||||
|
Names = N;
|
||||||
|
IPS = I;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getNames()
|
||||||
|
{
|
||||||
|
return new List<String>(Names.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getIPS()
|
||||||
|
{
|
||||||
|
return new List<String>(IPS.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIPSDB()
|
||||||
|
{
|
||||||
|
return IPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNamesDB()
|
||||||
|
{
|
||||||
|
return Names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumber()
|
||||||
|
{
|
||||||
|
return Number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addName(String Name)
|
||||||
|
{
|
||||||
|
if (Name.Trim() != String.Empty && Name != null)
|
||||||
|
Names += ';' + Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addIP(String IP)
|
||||||
|
{
|
||||||
|
if (IP.Trim() != String.Empty && IP != null)
|
||||||
|
IPS += ';' + IP;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String Names;
|
||||||
|
private String IPS;
|
||||||
|
private int Number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Player
|
||||||
|
{
|
||||||
|
public enum Permission
|
||||||
|
{
|
||||||
|
Banned = -1,
|
||||||
|
User = 0,
|
||||||
|
Flagged = 1,
|
||||||
|
Moderator = 2,
|
||||||
|
Administrator = 3,
|
||||||
|
SeniorAdmin = 4,
|
||||||
|
Owner = 5,
|
||||||
|
Creator = 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(string n, string id, int num, int l)
|
||||||
|
{
|
||||||
|
Name = n;
|
||||||
|
npID = id;
|
||||||
|
clientID = num;
|
||||||
|
Level = (Player.Permission)l;
|
||||||
|
lastOffense = String.Empty;
|
||||||
|
Connections = 0;
|
||||||
|
IP = "";
|
||||||
|
Warnings = 0;
|
||||||
|
Alias = new Aliases(0, "", "");
|
||||||
|
//stats = new Stats(0, 0, 0, 0, Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.ConservativeRating, Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.Mean, Moserware.Skills.GameInfo.DefaultGameInfo.DefaultRating.StandardDeviation);
|
||||||
|
LastConnection = DateTime.Now;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(string n, string id, int num, String I)
|
||||||
|
{
|
||||||
|
Name = n;
|
||||||
|
npID = id;
|
||||||
|
clientID = num;
|
||||||
|
IP = I;
|
||||||
|
LastConnection = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(string n, string id, Player.Permission P, String I)
|
||||||
|
{
|
||||||
|
Name = n;
|
||||||
|
npID = id;
|
||||||
|
Level = P;
|
||||||
|
IP = I;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(string n, string id, int num, Player.Permission l, int cind, String lo, int con, String IP2)
|
||||||
|
{
|
||||||
|
Name = n;
|
||||||
|
npID = id;
|
||||||
|
clientID = num;
|
||||||
|
Level = l;
|
||||||
|
databaseID = cind;
|
||||||
|
if (lo == null)
|
||||||
|
lastOffense = String.Empty;
|
||||||
|
else
|
||||||
|
lastOffense = lo;
|
||||||
|
Connections = con;
|
||||||
|
IP = IP2;
|
||||||
|
Warnings = 0;
|
||||||
|
Masked = false;
|
||||||
|
LastConnection = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player(string n, string id, int num, Player.Permission l, int cind, String lo, int con, String IP2, DateTime LC)
|
||||||
|
{
|
||||||
|
Name = n;
|
||||||
|
npID = id;
|
||||||
|
clientID = num;
|
||||||
|
Level = l;
|
||||||
|
databaseID = cind;
|
||||||
|
if (lo == null)
|
||||||
|
lastOffense = String.Empty;
|
||||||
|
else
|
||||||
|
lastOffense = lo;
|
||||||
|
Connections = con;
|
||||||
|
IP = IP2;
|
||||||
|
Warnings = 0;
|
||||||
|
Masked = false;
|
||||||
|
LastConnection = LC;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastConnection()
|
||||||
|
{
|
||||||
|
return Utilities.timePassed(LastConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateName(String n)
|
||||||
|
{
|
||||||
|
if (n.Trim() != String.Empty)
|
||||||
|
Name = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateIP(String I)
|
||||||
|
{
|
||||||
|
IP = I;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(Player.Permission Perm)
|
||||||
|
{
|
||||||
|
Level = Perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tell(String Message)
|
||||||
|
{
|
||||||
|
lastEvent.Owner.Tell(Message, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Kick(String Message)
|
||||||
|
{
|
||||||
|
currentServer.Kick(Message, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tempBan(String Message)
|
||||||
|
{
|
||||||
|
currentServer.tempBan(Message, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ban(String Message, Player Sender)
|
||||||
|
{
|
||||||
|
currentServer.Ban(Message, this, Sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Alert()
|
||||||
|
{
|
||||||
|
currentServer.Alert(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String Name { get; private set; }
|
||||||
|
public string npID { get; private set; }
|
||||||
|
public int clientID { get; private set; }
|
||||||
|
public Player.Permission Level { get; private set; }
|
||||||
|
public int databaseID { get; private set; }
|
||||||
|
public int Connections { get; set; }
|
||||||
|
public String IP { get; private set; }
|
||||||
|
public DateTime LastConnection { get; private set; }
|
||||||
|
public Server currentServer { get; private set; }
|
||||||
|
|
||||||
|
public Event lastEvent;
|
||||||
|
public String lastOffense;
|
||||||
|
public int Warnings;
|
||||||
|
public Stats stats;
|
||||||
|
public Aliases Alias;
|
||||||
|
public bool Masked;
|
||||||
|
}
|
||||||
|
}
|
36
SharedLibary/Properties/AssemblyInfo.cs
Normal file
36
SharedLibary/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("SharedLibary")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("SharedLibary")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("c434bf30-cd8f-4270-a386-e3b970f02f21")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
21
SharedLibary/Report.cs
Normal file
21
SharedLibary/Report.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public class Report
|
||||||
|
{
|
||||||
|
public Report(Player T, Player O, String R)
|
||||||
|
{
|
||||||
|
Target = T;
|
||||||
|
Origin = O;
|
||||||
|
Reason = R;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player Target { get; private set; }
|
||||||
|
public Player Origin { get; private set; }
|
||||||
|
public String Reason { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
403
SharedLibary/Server.cs
Normal file
403
SharedLibary/Server.cs
Normal file
@ -0,0 +1,403 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
public abstract class Server
|
||||||
|
{
|
||||||
|
public Server(string address, int port, string password, int H, int PID)
|
||||||
|
{
|
||||||
|
this.PID = PID;
|
||||||
|
Handle = H;
|
||||||
|
IP = address;
|
||||||
|
Port = port;
|
||||||
|
clientnum = 0;
|
||||||
|
logFile = new IFile("admin_" + 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");
|
||||||
|
statDB = new StatsDB("stats_" + Port + ".rm");
|
||||||
|
aliasDB = new AliasesDB("aliases.rm");
|
||||||
|
|
||||||
|
players = new List<Player>(new Player[18]);
|
||||||
|
events = new Queue<Event>();
|
||||||
|
Macros = new Dictionary<String, Object>();
|
||||||
|
Reports = new List<Report>();
|
||||||
|
statusPlayers = new Dictionary<string, Player>();
|
||||||
|
chatHistory = new List<Chat>();
|
||||||
|
lastWebChat = DateTime.Now;
|
||||||
|
nextMessage = 0;
|
||||||
|
initCommands();
|
||||||
|
initMacros();
|
||||||
|
initMessages();
|
||||||
|
initMaps();
|
||||||
|
initRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns the current server name -- *STRING*
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMap()
|
||||||
|
{
|
||||||
|
return mapname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGametype()
|
||||||
|
{
|
||||||
|
return Gametype;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns current server IP set by `net_ip` -- *STRING*
|
||||||
|
public String getIP()
|
||||||
|
{
|
||||||
|
return IP;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns current server port set by `net_port` -- *INT*
|
||||||
|
public int getPort()
|
||||||
|
{
|
||||||
|
return Port;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns number of active clients on server -- *INT*
|
||||||
|
public int getNumPlayers()
|
||||||
|
{
|
||||||
|
return clientnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns the list of commands
|
||||||
|
public List<Command> getCommands()
|
||||||
|
{
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns list of all current players
|
||||||
|
public List<Player> getPlayers()
|
||||||
|
{
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getClientNum()
|
||||||
|
{
|
||||||
|
return clientnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxClients()
|
||||||
|
{
|
||||||
|
return maxClients;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns list of all active bans (loaded at runtime)
|
||||||
|
public List<Ban> getBans()
|
||||||
|
{
|
||||||
|
return Bans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int pID()
|
||||||
|
{
|
||||||
|
return this.PID;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void getAliases(List<Player> returnPlayers, Player Origin);
|
||||||
|
|
||||||
|
//Add player object p to `players` list
|
||||||
|
abstract public bool addPlayer(Player P);
|
||||||
|
|
||||||
|
//Remove player by CLIENT NUMBER
|
||||||
|
abstract public bool removePlayer(int cNum);
|
||||||
|
|
||||||
|
abstract public Player clientFromEventLine(String[] L, int cIDPos);
|
||||||
|
|
||||||
|
public Player clientFromName(String pName)
|
||||||
|
{
|
||||||
|
lock (players)
|
||||||
|
{
|
||||||
|
foreach (var P in players)
|
||||||
|
{
|
||||||
|
if (P != null && P.Name.ToLower().Contains(pName.ToLower()))
|
||||||
|
return P;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check ban list for every banned player and return ban if match is found
|
||||||
|
abstract public Ban isBanned(Player C);
|
||||||
|
|
||||||
|
//Procses requested command correlating to an event
|
||||||
|
abstract public Command processCommand(Event E, Command C);
|
||||||
|
|
||||||
|
//push a new event into the queue
|
||||||
|
private void addEvent(Event E)
|
||||||
|
{
|
||||||
|
events.Enqueue(E);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void executeCommand(String CMD);
|
||||||
|
|
||||||
|
abstract public dvar getDvar(String DvarName);
|
||||||
|
|
||||||
|
abstract public void setDvar(String Dvar, String Value);
|
||||||
|
|
||||||
|
//Starts the monitoring process
|
||||||
|
abstract public void Monitor();
|
||||||
|
|
||||||
|
abstract public bool intializeBasics();
|
||||||
|
|
||||||
|
//Process any server event
|
||||||
|
abstract public bool processEvent(Event E);
|
||||||
|
|
||||||
|
public bool Reload()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
messages = null;
|
||||||
|
maps = null;
|
||||||
|
rules = null;
|
||||||
|
initMaps();
|
||||||
|
initMessages();
|
||||||
|
initRules();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception E)
|
||||||
|
{
|
||||||
|
Log.Write("Unable to reload configs! - " + E.Message, Log.Level.Debug);
|
||||||
|
messages = new List<String>();
|
||||||
|
maps = new List<Map>();
|
||||||
|
rules = new List<String>();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//THESE MAY NEED TO BE MOVED
|
||||||
|
public void Broadcast(String Message)
|
||||||
|
{
|
||||||
|
executeCommand("sayraw " + Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tell(String Message, Player Target)
|
||||||
|
{
|
||||||
|
if (Target.clientID > -1)
|
||||||
|
executeCommand("tellraw " + Target.clientID + " " + Message + "^7");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Kick(String Message, Player Target)
|
||||||
|
{
|
||||||
|
if (Target.clientID > -1)
|
||||||
|
executeCommand("clientkick " + Target.clientID + " \"" + Message + "^7\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void Ban(String Message, Player Target, Player Origin);
|
||||||
|
|
||||||
|
abstract public bool Unban(String GUID, Player Target);
|
||||||
|
|
||||||
|
|
||||||
|
public void fastRestart(int delay)
|
||||||
|
{
|
||||||
|
Utilities.Wait(delay);
|
||||||
|
executeCommand("fast_restart");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mapRotate(int delay)
|
||||||
|
{
|
||||||
|
Utilities.Wait(delay);
|
||||||
|
executeCommand("map_rotate");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tempBan(String Message, Player Target)
|
||||||
|
{
|
||||||
|
executeCommand("tempbanclient " + Target.clientID + " \"" + Message + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mapRotate()
|
||||||
|
{
|
||||||
|
mapRotate(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Map(String mapName)
|
||||||
|
{
|
||||||
|
executeCommand("map " + mapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToAdmins(String message)
|
||||||
|
{
|
||||||
|
lock (players) // threading can modify list while we do this
|
||||||
|
{
|
||||||
|
foreach (Player P in players)
|
||||||
|
{
|
||||||
|
if (P == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (P.Level > Player.Permission.Flagged)
|
||||||
|
{
|
||||||
|
P.Alert();
|
||||||
|
P.Tell(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Alert(Player P)
|
||||||
|
{
|
||||||
|
executeCommand("admin_lastevent alert;" + P.npID + ";0;mp_killstreak_nuclearstrike");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void webChat(Player P, String Message)
|
||||||
|
{
|
||||||
|
DateTime requestTime = DateTime.Now;
|
||||||
|
|
||||||
|
if ((requestTime - lastWebChat).TotalSeconds > 1)
|
||||||
|
{
|
||||||
|
Broadcast("^1[WEBCHAT] ^5" + P.Name + "^7 - " + Message);
|
||||||
|
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));
|
||||||
|
lastWebChat = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void initMacros();
|
||||||
|
|
||||||
|
private void initMaps()
|
||||||
|
{
|
||||||
|
maps = new List<Map>();
|
||||||
|
|
||||||
|
IFile mapfile = new IFile("config\\maps.cfg");
|
||||||
|
String[] _maps = mapfile.readAll();
|
||||||
|
mapfile.Close();
|
||||||
|
if (_maps.Length > 2) // readAll returns minimum one empty string
|
||||||
|
{
|
||||||
|
foreach (String m in _maps)
|
||||||
|
{
|
||||||
|
String[] m2 = m.Split(':');
|
||||||
|
if (m2.Length > 1)
|
||||||
|
{
|
||||||
|
Map map = new Map(m2[0].Trim(), m2[1].Trim());
|
||||||
|
maps.Add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Log.Write("Maps configuration appears to be empty - skipping...", Log.Level.All);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMessages()
|
||||||
|
{
|
||||||
|
messages = new List<String>();
|
||||||
|
|
||||||
|
IFile messageCFG = new IFile("config\\messages.cfg");
|
||||||
|
String[] lines = messageCFG.readAll();
|
||||||
|
messageCFG.Close();
|
||||||
|
|
||||||
|
if (lines.Length < 2) //readAll returns minimum one empty string
|
||||||
|
{
|
||||||
|
Log.Write("Messages configuration appears empty - skipping...", Log.Level.All);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mTime = -1;
|
||||||
|
int.TryParse(lines[0], out mTime);
|
||||||
|
|
||||||
|
if (messageTime == -1)
|
||||||
|
messageTime = 60;
|
||||||
|
else
|
||||||
|
messageTime = mTime;
|
||||||
|
|
||||||
|
foreach (String l in lines)
|
||||||
|
{
|
||||||
|
if (lines[0] != l && l.Length > 1)
|
||||||
|
messages.Add(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
messageCFG.Close();
|
||||||
|
|
||||||
|
//if (Program.Version != Program.latestVersion && Program.latestVersion != 0)
|
||||||
|
// messages.Add("^5IW4M Admin ^7is outdated. Please ^5update ^7to version " + Program.latestVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRules()
|
||||||
|
{
|
||||||
|
rules = new List<String>();
|
||||||
|
|
||||||
|
IFile ruleFile = new IFile("config\\rules.cfg");
|
||||||
|
String[] _rules = ruleFile.readAll();
|
||||||
|
ruleFile.Close();
|
||||||
|
if (_rules.Length > 2) // readAll returns minimum one empty string
|
||||||
|
{
|
||||||
|
foreach (String r in _rules)
|
||||||
|
{
|
||||||
|
if (r.Length > 1)
|
||||||
|
rules.Add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Log.Write("Rules configuration appears empty - skipping...", Log.Level.All);
|
||||||
|
|
||||||
|
ruleFile.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void initCommands();
|
||||||
|
abstract public void initAbstractObj();
|
||||||
|
|
||||||
|
//Objects
|
||||||
|
public Log Log;
|
||||||
|
public List<Ban> Bans;
|
||||||
|
public Player owner;
|
||||||
|
public List<Map> maps;
|
||||||
|
public List<String> rules;
|
||||||
|
public Queue<Event> events;
|
||||||
|
public String Website;
|
||||||
|
public String Gametype;
|
||||||
|
public int totalKills = 0;
|
||||||
|
public List<Report> Reports;
|
||||||
|
public List<Chat> chatHistory;
|
||||||
|
|
||||||
|
//Info
|
||||||
|
protected String IP;
|
||||||
|
protected int Port;
|
||||||
|
protected String hostname;
|
||||||
|
protected String mapname;
|
||||||
|
protected int clientnum;
|
||||||
|
protected List<Player> players;
|
||||||
|
protected List<Command> commands;
|
||||||
|
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;
|
||||||
|
protected int PID;
|
||||||
|
protected IFile logFile;
|
||||||
|
|
||||||
|
// Will probably move this later
|
||||||
|
public Dictionary<String, Player> statusPlayers;
|
||||||
|
public bool isRunning;
|
||||||
|
|
||||||
|
// Log stuff
|
||||||
|
protected String Basepath;
|
||||||
|
protected String Mod;
|
||||||
|
protected String logPath;
|
||||||
|
|
||||||
|
// Databases
|
||||||
|
public ClientsDB clientDB;
|
||||||
|
public AliasesDB aliasDB;
|
||||||
|
public StatsDB statDB;
|
||||||
|
}
|
||||||
|
}
|
72
SharedLibary/SharedLibrary.csproj
Normal file
72
SharedLibary/SharedLibrary.csproj
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{D51EECEB-438A-47DA-870F-7D7B41BC24D6}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>SharedLibrary</RootNamespace>
|
||||||
|
<AssemblyName>SharedLibary</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject />
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Data.SQLite">
|
||||||
|
<HintPath>..\..\Admin\lib\System.Data.SQLite.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Ban.cs" />
|
||||||
|
<Compile Include="Command.cs" />
|
||||||
|
<Compile Include="Database.cs" />
|
||||||
|
<Compile Include="Event.cs" />
|
||||||
|
<Compile Include="File.cs" />
|
||||||
|
<Compile Include="Dvar.cs" />
|
||||||
|
<Compile Include="Log.cs" />
|
||||||
|
<Compile Include="Map.cs" />
|
||||||
|
<Compile Include="Player.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Report.cs" />
|
||||||
|
<Compile Include="Server.cs" />
|
||||||
|
<Compile Include="Utilities.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- 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.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
22
SharedLibary/SharedLibrary.sln
Normal file
22
SharedLibary/SharedLibrary.sln
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 2013
|
||||||
|
VisualStudioVersion = 12.0.30723.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLibrary", "SharedLibrary.csproj", "{D51EECEB-438A-47DA-870F-7D7B41BC24D6}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D51EECEB-438A-47DA-870F-7D7B41BC24D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
243
SharedLibary/Utilities.cs
Normal file
243
SharedLibary/Utilities.cs
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SharedLibrary
|
||||||
|
{
|
||||||
|
class Utilities
|
||||||
|
{
|
||||||
|
//Get string with specified number of spaces -- really only for visual output
|
||||||
|
public static String getSpaces(int Num)
|
||||||
|
{
|
||||||
|
String SpaceString = String.Empty;
|
||||||
|
while (Num > 0)
|
||||||
|
{
|
||||||
|
SpaceString += ' ';
|
||||||
|
Num--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SpaceString;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sleep for x amount of seconds
|
||||||
|
public static void Wait(double time)
|
||||||
|
{
|
||||||
|
Thread.Sleep((int)Math.Ceiling(time * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Remove words from a space delimited string
|
||||||
|
public static String removeWords(String str, int num)
|
||||||
|
{
|
||||||
|
String newStr = String.Empty;
|
||||||
|
String[] tmp = str.Split(' ');
|
||||||
|
|
||||||
|
for (int i = 0; i < tmp.Length; i++)
|
||||||
|
{
|
||||||
|
if (i >= num)
|
||||||
|
newStr += tmp[i] + ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
return newStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Player.Permission matchPermission(String str)
|
||||||
|
{
|
||||||
|
String lookingFor = str.ToLower();
|
||||||
|
|
||||||
|
for (Player.Permission Perm = Player.Permission.User; Perm < Player.Permission.Owner; Perm++)
|
||||||
|
{
|
||||||
|
if (lookingFor.Contains(Perm.ToString().ToLower()))
|
||||||
|
return Perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Player.Permission.Banned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String removeNastyChars(String str)
|
||||||
|
{
|
||||||
|
if (str != null)
|
||||||
|
return str.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)
|
||||||
|
{
|
||||||
|
if (S == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
StringBuilder Cleaned = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (char c in S)
|
||||||
|
if (c < 127 && c > 31 && c != 37 && c != 34 && c != 92) Cleaned.Append(c);
|
||||||
|
return Cleaned.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String stripColors(String str)
|
||||||
|
{
|
||||||
|
if (str == null)
|
||||||
|
return "";
|
||||||
|
return Regex.Replace(str, @"\^[0-9]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String levelToColor(Player.Permission level)
|
||||||
|
{
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case Player.Permission.Banned:
|
||||||
|
return "^1" + Player.Permission.Banned;
|
||||||
|
case Player.Permission.Flagged:
|
||||||
|
return "^0" + Player.Permission.Flagged;
|
||||||
|
case Player.Permission.Owner:
|
||||||
|
return "^5" + Player.Permission.Owner;
|
||||||
|
case Player.Permission.User:
|
||||||
|
return "^2" + Player.Permission.User;
|
||||||
|
default:
|
||||||
|
return "^3" + level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String processMacro(Dictionary<String, Object> Dict, String str)
|
||||||
|
{
|
||||||
|
MatchCollection Found = Regex.Matches(str, @"\{\{[A-Z]+\}\}", RegexOptions.IgnoreCase);
|
||||||
|
foreach (Match M in Found)
|
||||||
|
{
|
||||||
|
String Match = M.Value;
|
||||||
|
String Identifier = M.Value.Substring(2, M.Length - 4);
|
||||||
|
String Replacement = Dict[Identifier].ToString();
|
||||||
|
str = str.Replace(Match, Replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String gametypeLocalized(String input)
|
||||||
|
{
|
||||||
|
switch (input)
|
||||||
|
{
|
||||||
|
case "dm":
|
||||||
|
return "Deathmatch";
|
||||||
|
case "war":
|
||||||
|
return "Team Deathmatch";
|
||||||
|
case "koth":
|
||||||
|
return "Headquarters";
|
||||||
|
case "ctf":
|
||||||
|
return "Capture The Flag";
|
||||||
|
case "dd":
|
||||||
|
return "Demolition";
|
||||||
|
case "dom":
|
||||||
|
return "Domination";
|
||||||
|
case "sab":
|
||||||
|
return "Sabotage";
|
||||||
|
case "sd":
|
||||||
|
return "Search & Destroy";
|
||||||
|
case "vip":
|
||||||
|
return "Very Important Person";
|
||||||
|
case "gtnw":
|
||||||
|
return "Global Thermonuclear War";
|
||||||
|
case "oitc":
|
||||||
|
return "One In The Chamber";
|
||||||
|
case "arena":
|
||||||
|
return "Arena";
|
||||||
|
case "dzone":
|
||||||
|
return "Drop Zone";
|
||||||
|
case "gg":
|
||||||
|
return "Gun Game";
|
||||||
|
case "snipe":
|
||||||
|
return "Sniping";
|
||||||
|
case "ss":
|
||||||
|
return "Sharp Shooter";
|
||||||
|
case "m40a3":
|
||||||
|
return "M40A3";
|
||||||
|
case "fo":
|
||||||
|
return "Face Off";
|
||||||
|
case "dmc":
|
||||||
|
return "Deathmatch Classic";
|
||||||
|
case "killcon":
|
||||||
|
return "Kill Confirmed";
|
||||||
|
case "oneflag":
|
||||||
|
return "One Flag CTF";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String timePassed(DateTime start)
|
||||||
|
{
|
||||||
|
TimeSpan Elapsed = DateTime.Now - start;
|
||||||
|
|
||||||
|
if (Elapsed.TotalMinutes < 120)
|
||||||
|
return Math.Round(Elapsed.TotalMinutes, 0) + " minutes";
|
||||||
|
if (Elapsed.TotalHours <= 24)
|
||||||
|
return Math.Round(Elapsed.TotalHours, 0) + " hours";
|
||||||
|
if (Elapsed.TotalDays <= 365)
|
||||||
|
return Math.Round(Elapsed.TotalDays, 0) + " days";
|
||||||
|
else
|
||||||
|
return "a very long time";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String timesConnected(int connection)
|
||||||
|
{
|
||||||
|
String Prefix = String.Empty;
|
||||||
|
if (connection % 10 > 3 || connection % 10 == 0 || (connection % 100 > 9 && connection % 100 < 19))
|
||||||
|
Prefix = "th";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (connection % 10)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
Prefix = "st";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Prefix = "nd";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Prefix = "rd";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (connection)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
return "first";
|
||||||
|
case 2:
|
||||||
|
return "second";
|
||||||
|
case 3:
|
||||||
|
return "third";
|
||||||
|
case 4:
|
||||||
|
return "fourth";
|
||||||
|
case 5:
|
||||||
|
return "fifth";
|
||||||
|
case 100:
|
||||||
|
return "One-Hundreth (amazing!)";
|
||||||
|
default:
|
||||||
|
return connection.ToString() + Prefix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user