moved stats to a plugin!
This commit is contained in:
parent
ec7bed8e11
commit
f4016f6691
@ -424,65 +424,6 @@ namespace IW4MAdmin
|
||||
}
|
||||
}
|
||||
|
||||
class _Stats : Command
|
||||
{
|
||||
public _Stats(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)
|
||||
{
|
||||
if (E.Target == null)
|
||||
{
|
||||
if (E.Target.stats == null)
|
||||
E.Origin.Tell("You do not have any stats!");
|
||||
else
|
||||
E.Origin.Tell(String.Format("^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", E.Origin.stats.Kills, E.Origin.stats.Deaths, E.Origin.stats.KDR, E.Origin.stats.Skill));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
E.Target.stats = E.Owner.statDB.getStats(E.Target.databaseID);
|
||||
if (E.Target.stats == null)
|
||||
E.Origin.Tell("That person does not have any stats at this time!");
|
||||
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.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TopStats : Command
|
||||
{
|
||||
public TopStats(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)
|
||||
{
|
||||
List<Stats> Top = E.Owner.statDB.topStats();
|
||||
List<Player> TopP = new List<Player>();
|
||||
|
||||
foreach (Stats S in Top)
|
||||
{
|
||||
Player P = E.Owner.clientDB.getPlayer(S.statIndex);
|
||||
if (P != null && P.Level != Player.Permission.Banned)
|
||||
{
|
||||
P.stats = S;
|
||||
TopP.Add(P);
|
||||
}
|
||||
}
|
||||
|
||||
if (TopP.Count > 0)
|
||||
{
|
||||
E.Origin.Tell("^1TOP PLAYERS");
|
||||
foreach (Player P in TopP)
|
||||
{
|
||||
if (P != null)
|
||||
E.Origin.Tell(String.Format("^3{0}^7 - ^5{1} ^7KDR | ^5{2} ^7SKILL", P.Name, P.stats.KDR, P.stats.Skill));
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
E.Origin.Tell("There are no top players yet!");
|
||||
}
|
||||
}
|
||||
|
||||
class Reload : Command
|
||||
{
|
||||
public Reload(String N, String D, String U, Player.Permission P, int args, bool nT) : base(N, D, U, P, args, nT) { }
|
||||
|
@ -128,15 +128,15 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.manifest" />
|
||||
<None Include="lib\AdminInterface.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="lib\Kayak.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="lib\System.Data.SQLite.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="lib\AdminInterface.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="lib\SharedLibary.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@ -10,14 +10,14 @@ namespace IW4MAdmin
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static public double Version = 0.92;
|
||||
static public double latestVersion;
|
||||
static public bool usingMemory = true;
|
||||
static public double Version { get; private set; }
|
||||
static private Manager serverManager;
|
||||
static private IW4MAdmin_Web.WebFront frontEnd;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Version = 0.95;
|
||||
double latestVersion = 0;
|
||||
handler = new ConsoleEventDelegate(OnProcessExit);
|
||||
SetConsoleCtrlHandler(handler, true);
|
||||
|
||||
@ -66,6 +66,7 @@ namespace IW4MAdmin
|
||||
if (S == null)
|
||||
continue;
|
||||
|
||||
S.Broadcast("^5IW4MAdmin ^7is going ^1offline^7");
|
||||
S.isRunning = false;
|
||||
|
||||
if (Utilities.shutdownInterface(S.pID()))
|
||||
@ -77,14 +78,13 @@ namespace IW4MAdmin
|
||||
Program.getManager().shutDown();
|
||||
frontEnd.webSchedule.Stop();
|
||||
frontEnd.webSchedule.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private delegate bool ConsoleEventDelegate(int eventType);
|
||||
|
@ -216,7 +216,8 @@ namespace IW4MAdmin
|
||||
return null;
|
||||
}
|
||||
|
||||
SharedLibrary.Utilities.Wait(2);
|
||||
if (timeWaiting > 5)
|
||||
SharedLibrary.Utilities.Wait(2);
|
||||
|
||||
dvar net_ip = Utilities.getDvarOld(0x64A1DF8, (int)Handle);
|
||||
dvar net_port = Utilities.getDvarOld(0x64A3004, (int)Handle);
|
||||
|
@ -8,17 +8,17 @@ namespace IW4MAdmin
|
||||
{
|
||||
public class PluginImporter
|
||||
{
|
||||
public static List<Command> potentialPlugins = new List<Command>();
|
||||
public static List<EventNotify> potentialNotifies = new List<EventNotify>();
|
||||
public static List<Command> potentialCommands;
|
||||
public static List<EventNotify> potentialNotifies;
|
||||
|
||||
public static bool Load()
|
||||
{
|
||||
string[] dllFileNames = null;
|
||||
potentialCommands = new List<Command>();
|
||||
potentialNotifies = new List<EventNotify>();
|
||||
|
||||
if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins"))
|
||||
{
|
||||
dllFileNames = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins", "*.dll");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
@ -52,6 +52,7 @@ namespace IW4MAdmin
|
||||
Object notifyObject = Activator.CreateInstance(assemblyType);
|
||||
EventNotify newNotify = (EventNotify)notifyObject;
|
||||
potentialNotifies.Add(newNotify);
|
||||
newNotify.onLoad();
|
||||
Program.getManager().mainLog.Write("Loaded event plugin \"" + assemblyType.Name + "\"", Log.Level.All);
|
||||
}
|
||||
|
||||
@ -59,7 +60,7 @@ namespace IW4MAdmin
|
||||
{
|
||||
Object commandObject = Activator.CreateInstance(assemblyType);
|
||||
Command newCommand = (Command)commandObject;
|
||||
potentialPlugins.Add(newCommand);
|
||||
potentialCommands.Add(newCommand);
|
||||
Program.getManager().mainLog.Write("Loaded command plugin \"" + newCommand.Name + "\"", Log.Level.All);
|
||||
}
|
||||
|
||||
|
@ -83,12 +83,9 @@ namespace IW4MAdmin
|
||||
clientDB.addPlayer(P);
|
||||
NewPlayer = clientDB.getPlayer(P.npID, P.clientID);
|
||||
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
|
||||
statDB.addPlayer(NewPlayer);
|
||||
}
|
||||
|
||||
NewPlayer.updateName(P.Name.Trim());
|
||||
|
||||
NewPlayer.stats = statDB.getStats(NewPlayer.databaseID);
|
||||
NewPlayer.Alias = aliasDB.getPlayer(NewPlayer.databaseID);
|
||||
|
||||
if (NewPlayer.Alias == null)
|
||||
@ -204,12 +201,6 @@ namespace IW4MAdmin
|
||||
if (NewPlayer.Level > Player.Permission.Moderator)
|
||||
NewPlayer.Tell("There are ^5" + Reports.Count + " ^7recent reports!");
|
||||
|
||||
if (NewPlayer.stats == null) // there seems to be an issue with stats with multiple servers. I think this should fix it
|
||||
{
|
||||
statDB.addPlayer(NewPlayer);
|
||||
NewPlayer.stats = statDB.getStats(NewPlayer.databaseID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#if DEBUG == false
|
||||
@ -235,7 +226,6 @@ namespace IW4MAdmin
|
||||
Player Leaving = players[cNum];
|
||||
Leaving.Connections++;
|
||||
clientDB.updatePlayer(Leaving);
|
||||
statDB.updatePlayer(Leaving);
|
||||
|
||||
Log.Write("Client at " + cNum + " disconnecting...", Log.Level.Debug);
|
||||
events.Enqueue(new Event(Event.GType.Disconnect, "", Leaving, null, this));
|
||||
@ -674,27 +664,9 @@ namespace IW4MAdmin
|
||||
return false;
|
||||
}
|
||||
|
||||
if (E.Target == null)
|
||||
{
|
||||
Log.Write("Kill event triggered, but no target found!", Log.Level.Debug);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (E.Origin.stats == null)
|
||||
{
|
||||
Log.Write("Kill event triggered, but no stats found for origin!", Log.Level.Debug);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (E.Target.stats == null)
|
||||
{
|
||||
Log.Write("Kill event triggered, but no stats found for target!", Log.Level.Debug);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (E.Origin != E.Target)
|
||||
{
|
||||
E.Origin.stats.Kills += 1;
|
||||
/*E.Origin.stats.Kills += 1;
|
||||
E.Origin.stats.updateKDR();
|
||||
|
||||
E.Target.stats.Deaths += 1;
|
||||
@ -704,17 +676,15 @@ namespace IW4MAdmin
|
||||
statDB.updatePlayer(E.Origin);
|
||||
statDB.updatePlayer(E.Target);
|
||||
|
||||
totalKills++;
|
||||
totalKills++;*/
|
||||
Log.Write(E.Origin.Name + " killed " + E.Target.Name + " with a " + E.Data, Log.Level.Debug);
|
||||
events.Enqueue(new Event(Event.GType.Death, E.Data, E.Target, null, this));
|
||||
}
|
||||
|
||||
else // suicide/falling
|
||||
{
|
||||
E.Origin.stats.Deaths++;
|
||||
E.Origin.stats.updateKDR();
|
||||
statDB.updatePlayer(E.Origin);
|
||||
Log.Write(E.Origin.Name + " suicided...", Log.Level.Debug);
|
||||
events.Enqueue(new Event(Event.GType.Death, "suicide", E.Target, null, this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -820,13 +790,6 @@ namespace IW4MAdmin
|
||||
if (E.Type == Event.GType.MapEnd)
|
||||
{
|
||||
Log.Write("Game ending...", Log.Level.Debug);
|
||||
foreach (Player P in players)
|
||||
{
|
||||
if (P == null || P.stats == null)
|
||||
continue;
|
||||
statDB.updatePlayer(P);
|
||||
Log.Write("Updated stats for client " + P.databaseID, Log.Level.Debug);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -846,8 +809,8 @@ namespace IW4MAdmin
|
||||
clientDB.addBan(newBan);
|
||||
clientDB.updatePlayer(Target);
|
||||
|
||||
// foreach (SharedLibrary.Server S in Program.getServers()) // make sure bans show up on the webfront
|
||||
// S.Bans = S.clientDB.getBans();
|
||||
foreach (SharedLibrary.Server S in Program.getServers()) // make sure bans show up on the webfront
|
||||
S.Bans = S.clientDB.getBans();
|
||||
|
||||
lock (Reports) // threading seems to do something weird here
|
||||
{
|
||||
@ -879,12 +842,37 @@ namespace IW4MAdmin
|
||||
P.setLevel(Player.Permission.User);
|
||||
clientDB.updatePlayer(P);
|
||||
|
||||
foreach (SharedLibrary.Server S in Program.getServers()) // make sure bans show up on the webfront
|
||||
S.Bans = S.clientDB.getBans();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override public bool Reload()
|
||||
{
|
||||
try
|
||||
{
|
||||
messages = null;
|
||||
maps = null;
|
||||
rules = null;
|
||||
initMaps();
|
||||
initMessages();
|
||||
initRules();
|
||||
PluginImporter.Load();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
override public void initMacros()
|
||||
{
|
||||
@ -923,8 +911,8 @@ namespace IW4MAdmin
|
||||
commands.Add(new Find("find", "find player in database. syntax: !find <player>", "f", Player.Permission.SeniorAdmin, 1, false));
|
||||
commands.Add(new Rules("rules", "list server rules. syntax: !rules", "r", Player.Permission.User, 0, false));
|
||||
commands.Add(new PrivateMessage("privatemessage", "send message to other player. syntax: !pm <player> <message>", "pm", Player.Permission.User, 2, true));
|
||||
commands.Add(new _Stats("stats", "view your stats or another player's. syntax: !stats", "xlrstats", Player.Permission.User, 0, true));
|
||||
commands.Add(new TopStats("topstats", "view the top 4 players on this server. syntax: !topstats", "xlrtopstats", Player.Permission.User, 0, false));
|
||||
//commands.Add(new _Stats("stats", "view your stats or another player's. syntax: !stats", "xlrstats", Player.Permission.User, 0, true));
|
||||
//commands.Add(new TopStats("topstats", "view the top 4 players on this server. syntax: !topstats", "xlrtopstats", Player.Permission.User, 0, false));
|
||||
commands.Add(new Reload("reload", "reload configurations. syntax: !reload", "reload", Player.Permission.Owner, 0, false));
|
||||
commands.Add(new Balance("balance", "balance teams. syntax !balance", "bal", Player.Permission.Moderator, 0, false));
|
||||
commands.Add(new GoTo("goto", "teleport to selected player. syntax !goto", "go", Player.Permission.SeniorAdmin, 1, true));
|
||||
@ -938,7 +926,7 @@ namespace IW4MAdmin
|
||||
commands.Add(new _RCON("rcon", "send rcon command to server. syntax: !rcon <command>", "rcon", Player.Permission.Owner, 1, false));
|
||||
commands.Add(new FindAll("findall", "find a player by their aliase(s). syntax: !findall <player>", "fa", Player.Permission.Moderator, 1, false));
|
||||
|
||||
foreach (Command C in PluginImporter.potentialPlugins)
|
||||
foreach (Command C in PluginImporter.potentialCommands)
|
||||
commands.Add(C);
|
||||
|
||||
}
|
||||
|
@ -367,21 +367,16 @@ namespace IW4MAdmin
|
||||
return false;
|
||||
}
|
||||
|
||||
//ClientId clientid = new ClientId();
|
||||
//threadID = new IntPtr();
|
||||
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;
|
||||
ClientId clientid = new ClientId();
|
||||
threadID = new IntPtr();
|
||||
|
||||
RtlCreateUserThread(ProcessHandle, IntPtr.Zero, false, 0, (uint)0, IntPtr.Zero, lpLLAddress, baseAddress, out threadID, out clientid);
|
||||
if (threadID == IntPtr.Zero)
|
||||
{
|
||||
Program.getManager().mainLog.Write("Could not create remote thread");
|
||||
return false;
|
||||
}
|
||||
#if DEBUG
|
||||
//Program.getManager().mainLog.Write("Thread Status is " + threadStatus);
|
||||
Program.getManager().mainLog.Write("Thread ID is " + threadID);
|
||||
#endif
|
||||
uint responseCode = WaitForSingleObject(threadID, 3000);
|
||||
@ -399,8 +394,8 @@ namespace IW4MAdmin
|
||||
{
|
||||
if (Pointer != IntPtr.Zero)
|
||||
{
|
||||
// if (!VirtualFreeEx(ProcessHandle, Pointer, 0, AllocationType.Release))
|
||||
// Program.getManager().mainLog.Write("Virtual Free Failed During Exit Cleanup -- Error #" + Marshal.GetLastWin32Error());
|
||||
if (!VirtualFreeEx(ProcessHandle, Pointer, 0, AllocationType.Release))
|
||||
Program.getManager().mainLog.Write("Virtual Free Failed During Exit Cleanup -- Error #" + Marshal.GetLastWin32Error());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ namespace IW4MAdmin_Web
|
||||
buffer.Append("<div id=pages>");
|
||||
return buffer.ToString();
|
||||
case "STATS":
|
||||
int totalStats = Servers[server].statDB.totalStats();
|
||||
int totalStats = 0;
|
||||
buffer.Append("<h1 style='margin-top: 0;'>Starting at #{{TOP}}</h1><hr />");
|
||||
buffer.Append("<table style='width:100%' cellspacing=0 class=stats>");
|
||||
|
||||
@ -239,10 +239,10 @@ namespace IW4MAdmin_Web
|
||||
range = (totalStats - start);
|
||||
else
|
||||
range = 30;
|
||||
List<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>");
|
||||
cycleFix = 0;
|
||||
for (int i = 0; i < totalStats; i++)
|
||||
/*for (int i = 0; i < totalStats; i++)
|
||||
{
|
||||
if (i >= Stats.Count -1 || Stats[i] == null )
|
||||
continue;
|
||||
@ -267,7 +267,7 @@ namespace IW4MAdmin_Web
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
buffer.Append("</table><hr/>");
|
||||
buffer.Append(parsePagination(server, totalStats, 30, Pagination, "stats"));
|
||||
return buffer.ToString().Replace("{{TOP}}", (start + 1).ToString());
|
||||
@ -327,14 +327,6 @@ namespace IW4MAdmin_Web
|
||||
str.AppendFormat("<span>{0}</span><br/>", a.Name);
|
||||
}
|
||||
|
||||
Player.stats = Servers[server].statDB.getStats(Player.databaseID);
|
||||
String Rating = String.Empty;
|
||||
|
||||
if (Player.stats == null)
|
||||
Rating = "Not Available";
|
||||
else
|
||||
Rating = Player.stats.Skill.ToString();
|
||||
|
||||
StringBuilder IPs = new StringBuilder();
|
||||
|
||||
if (logged)
|
||||
@ -364,7 +356,7 @@ namespace IW4MAdmin_Web
|
||||
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.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.Name, str, IPs, Rating, SharedLibrary.Utilities.nameHTMLFormatted(Player), Player.Connections, Player.getLastConnection(), forumID, Player.Name, "/0/" + Player.databaseID + "/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, 0, SharedLibrary.Utilities.nameHTMLFormatted(Player), Player.Connections, Player.getLastConnection(), forumID, Player.Name, "/0/" + Player.databaseID + "/userip/?player", Screenshot);
|
||||
buffer.Append("</tr>");
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Release Build/lib/AdminInterface.dll
Normal file
BIN
Release Build/lib/AdminInterface.dll
Normal file
Binary file not shown.
BIN
Release Build/lib/SharedLibary.dll
Normal file
BIN
Release Build/lib/SharedLibary.dll
Normal file
Binary file not shown.
@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using SharedLibrary;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace SamplePlugin
|
||||
{
|
||||
#if SAMPLE_CODE
|
||||
public class SampleCommand : Command
|
||||
{
|
||||
public SampleCommand() : base("testplugin", "sample plugin command. syntax !testplugin", "tp", Player.Permission.User, 0, false) { }
|
||||
@ -35,11 +39,17 @@ namespace SamplePlugin
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
originatingServer.Broadcast(String.Format("^7{0}: ^{1}{2}^7", Sender, i, Message));
|
||||
|
||||
originatingServer.Log.Write("This line is coming from the plugin " + this.Name, Log.Level.Production);
|
||||
}
|
||||
}
|
||||
|
||||
public class SampleEvent : EventNotify
|
||||
{
|
||||
public override void onLoad()
|
||||
{
|
||||
Console.WriteLine("The sample event plugin was loaded!");
|
||||
}
|
||||
public override void onEvent(Event E)
|
||||
{
|
||||
E.Owner.Broadcast("An event occured of type: ^1" + E.Type);
|
||||
@ -48,9 +58,142 @@ namespace SamplePlugin
|
||||
E.Origin.Tell(E.Data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class InvalidCommandExample
|
||||
{
|
||||
private void doNotDoThis() { }
|
||||
}
|
||||
#endif
|
||||
|
||||
public class StatCommand: Command
|
||||
{
|
||||
public StatCommand() : base("stats", "view your stats. syntax !stats", "xlrstats", Player.Permission.User, 0, false) { }
|
||||
|
||||
public override void Execute(Event E)
|
||||
{
|
||||
PlayerStats pStats = Stats.playerStats.getStats(E.Origin);
|
||||
String statLine = String.Format("^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", pStats.Kills, pStats.Deaths, pStats.KDR, pStats.Skill);
|
||||
E.Origin.Tell(statLine);
|
||||
}
|
||||
}
|
||||
|
||||
public class Stats : EventNotify
|
||||
{
|
||||
public static StatsDB playerStats { get; private set; }
|
||||
|
||||
public override void onEvent(Event E)
|
||||
{
|
||||
Console.WriteLine("event type is " + E.Type);
|
||||
if (E.Type == Event.GType.Kill)
|
||||
{
|
||||
Player Killer = E.Origin;
|
||||
PlayerStats killerStats = playerStats.getStats(Killer);
|
||||
|
||||
if (Killer != E.Target)
|
||||
{
|
||||
killerStats.Kills++;
|
||||
|
||||
if (killerStats.Deaths == 0)
|
||||
killerStats.KDR = killerStats.Kills;
|
||||
else
|
||||
killerStats.KDR = killerStats.Kills / killerStats.Deaths;
|
||||
|
||||
playerStats.updateStats(Killer, killerStats);
|
||||
}
|
||||
}
|
||||
|
||||
if (E.Type == Event.GType.Death)
|
||||
{
|
||||
Player Victim = E.Origin;
|
||||
PlayerStats victimStats = playerStats.getStats(Victim);
|
||||
|
||||
victimStats.Deaths++;
|
||||
victimStats.KDR = victimStats.Kills / victimStats.Deaths;
|
||||
playerStats.updateStats(Victim, victimStats);
|
||||
}
|
||||
}
|
||||
|
||||
public override void onLoad()
|
||||
{
|
||||
playerStats = new StatsDB("stats.rm");
|
||||
}
|
||||
}
|
||||
|
||||
public class StatsDB : Database
|
||||
{
|
||||
public StatsDB(String FN) : base(FN) { }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
String Create = "CREATE TABLE [STATS] ( [npID] TEXT, [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);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(Player P)
|
||||
{
|
||||
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||
|
||||
newPlayer.Add("npID", P.npID);
|
||||
newPlayer.Add("KILLS", 0);
|
||||
newPlayer.Add("DEATHS", 0);
|
||||
newPlayer.Add("KDR", 0);
|
||||
newPlayer.Add("SKILL", 0);
|
||||
|
||||
Insert("STATS", newPlayer);
|
||||
}
|
||||
|
||||
public PlayerStats getStats(Player P)
|
||||
{
|
||||
String Query = String.Format("SELECT * FROM STATS WHERE npID = '{0}'", P.npID);
|
||||
DataTable Result = GetDataTable(Query);
|
||||
|
||||
if (Result != null && Result.Rows.Count > 0)
|
||||
{
|
||||
DataRow ResponseRow = Result.Rows[0];
|
||||
return new PlayerStats(
|
||||
Convert.ToInt32(ResponseRow["KILLS"]),
|
||||
Convert.ToInt32(ResponseRow["DEATHS"]),
|
||||
Convert.ToDouble(ResponseRow["KDR"]),
|
||||
Convert.ToDouble(ResponseRow["SKILL"])
|
||||
);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
addPlayer(P);
|
||||
return getStats(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateStats(Player P, PlayerStats S)
|
||||
{
|
||||
Dictionary<String, object> updatedPlayer = new Dictionary<String, object>();
|
||||
|
||||
updatedPlayer.Add("KILLS", S.Kills);
|
||||
updatedPlayer.Add("DEATHS", S.Deaths);
|
||||
updatedPlayer.Add("KDR", Math.Round(S.KDR, 2));
|
||||
updatedPlayer.Add("SKILL", S.Skill);
|
||||
|
||||
Update("STATS", updatedPlayer, String.Format("npID = '{0}'", P.npID));
|
||||
}
|
||||
}
|
||||
|
||||
public struct PlayerStats
|
||||
{
|
||||
public PlayerStats(int K, int D, double DR, double S)
|
||||
{
|
||||
Kills = K;
|
||||
Deaths = D;
|
||||
KDR = DR;
|
||||
Skill = S;
|
||||
}
|
||||
|
||||
public int Kills;
|
||||
public int Deaths;
|
||||
public double KDR;
|
||||
public double Skill;
|
||||
}
|
||||
}
|
@ -125,7 +125,7 @@ namespace SharedLibrary
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
throw new Exception(e.Message);
|
||||
return new DataTable();
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
@ -403,7 +403,7 @@ namespace SharedLibrary
|
||||
}
|
||||
}
|
||||
|
||||
public class StatsDB : Database
|
||||
/*public class StatsDB : Database
|
||||
{
|
||||
public StatsDB(String FN) : base(FN) { }
|
||||
|
||||
@ -539,7 +539,7 @@ namespace SharedLibrary
|
||||
Update("STATS", new Dictionary<String, Object>() { { "SKILL", 1 } }, String.Format("Number = '{0}'", D["Number"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public class AliasesDB : Database
|
||||
{
|
||||
|
@ -130,5 +130,6 @@ namespace SharedLibrary
|
||||
public abstract class EventNotify
|
||||
{
|
||||
public abstract void onEvent(Event E);
|
||||
public abstract void onLoad();
|
||||
}
|
||||
}
|
||||
|
@ -4,37 +4,6 @@ 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)
|
||||
@ -228,7 +197,6 @@ namespace SharedLibrary
|
||||
public Event lastEvent;
|
||||
public String lastOffense;
|
||||
public int Warnings;
|
||||
public Stats stats;
|
||||
public Aliases Alias;
|
||||
public bool Masked;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ namespace SharedLibrary
|
||||
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]);
|
||||
@ -211,27 +210,7 @@ namespace SharedLibrary
|
||||
/// Reloads all the server configurations
|
||||
/// </summary>
|
||||
/// <returns>True on sucess</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
abstract public bool Reload();
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to all players
|
||||
@ -384,7 +363,7 @@ namespace SharedLibrary
|
||||
/// <summary>
|
||||
/// Read the map configuration
|
||||
/// </summary>
|
||||
private void initMaps()
|
||||
protected void initMaps()
|
||||
{
|
||||
maps = new List<Map>();
|
||||
|
||||
@ -410,7 +389,7 @@ namespace SharedLibrary
|
||||
/// <summary>
|
||||
/// Initialize the messages to be broadcasted
|
||||
/// </summary>
|
||||
private void initMessages()
|
||||
protected void initMessages()
|
||||
{
|
||||
messages = new List<String>();
|
||||
|
||||
@ -447,7 +426,7 @@ namespace SharedLibrary
|
||||
/// <summary>
|
||||
/// Initialize the rules configuration
|
||||
/// </summary>
|
||||
private void initRules()
|
||||
protected void initRules()
|
||||
{
|
||||
rules = new List<String>();
|
||||
|
||||
@ -474,7 +453,7 @@ namespace SharedLibrary
|
||||
abstract public void initCommands();
|
||||
|
||||
//Objects
|
||||
public Log Log;
|
||||
public Log Log { get; private set; }
|
||||
public List<Ban> Bans;
|
||||
public Player owner;
|
||||
public List<Map> maps;
|
||||
@ -519,6 +498,5 @@ namespace SharedLibrary
|
||||
// Databases
|
||||
public ClientsDB clientDB;
|
||||
public AliasesDB aliasDB;
|
||||
public StatsDB statDB;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user