mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 23:31:13 -05:00
added 'none' and extra m16 variants to weapon list
moved killstreak/deathstreak messages into configuration file cleaned up configuration manager fixed misc startup issue and threading added more importing stuff network id is a ulong now ip str is now ip added time played (per server)
This commit is contained in:
@ -15,13 +15,16 @@ namespace StatsPlugin.Helpers
|
||||
{
|
||||
private Dictionary<int, ServerStats> Servers;
|
||||
private Dictionary<int, ThreadSafeStatsService> ContextThreads;
|
||||
private Dictionary<int, StreakMessage> StreakMessages;
|
||||
private ILogger Log;
|
||||
private IManager Manager;
|
||||
|
||||
|
||||
public StatManager(IManager mgr)
|
||||
{
|
||||
Servers = new Dictionary<int, ServerStats>();
|
||||
ContextThreads = new Dictionary<int, ThreadSafeStatsService>();
|
||||
StreakMessages= new Dictionary<int, StreakMessage>();
|
||||
Log = mgr.GetLogger();
|
||||
Manager = mgr;
|
||||
}
|
||||
@ -44,6 +47,7 @@ namespace StatsPlugin.Helpers
|
||||
int serverId = sv.GetHashCode();
|
||||
var statsSvc = new ThreadSafeStatsService();
|
||||
ContextThreads.Add(serverId, statsSvc);
|
||||
StreakMessages.Add(serverId, new StreakMessage(sv));
|
||||
|
||||
// get the server from the database if it exists, otherwise create and insert a new one
|
||||
var server = statsSvc.ServerSvc.Find(c => c.ServerId == serverId).FirstOrDefault();
|
||||
@ -157,7 +161,7 @@ namespace StatsPlugin.Helpers
|
||||
public async Task AddScriptKill(Player attacker, Player victim, int serverId, string map, string hitLoc, string type,
|
||||
string damage, string weapon, string killOrigin, string deathOrigin)
|
||||
{
|
||||
AddStandardKill(attacker, victim);
|
||||
await AddStandardKill(attacker, victim);
|
||||
|
||||
var statsSvc = ContextThreads[serverId];
|
||||
|
||||
@ -180,12 +184,19 @@ namespace StatsPlugin.Helpers
|
||||
await statsSvc.KillStatsSvc.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void AddStandardKill(Player attacker, Player victim)
|
||||
public async Task AddStandardKill(Player attacker, Player victim)
|
||||
{
|
||||
int serverId = attacker.CurrentServer.GetHashCode();
|
||||
var attackerStats = Servers[serverId].PlayerStats[attacker.ClientNumber];
|
||||
// set to access total time played
|
||||
attackerStats.Client = attacker;
|
||||
|
||||
if (victim == null)
|
||||
{
|
||||
Log.WriteError($"Stats: Victim is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var victimStats = Servers[serverId].PlayerStats[victim.ClientNumber];
|
||||
|
||||
// update the total stats
|
||||
@ -194,6 +205,15 @@ namespace StatsPlugin.Helpers
|
||||
// calculate for the clients
|
||||
CalculateKill(attackerStats, victimStats);
|
||||
|
||||
// show encouragement/discouragement
|
||||
var streakMessageGen = StreakMessages[serverId];
|
||||
string streakMessage = (attackerStats.ClientId != victimStats.ClientId) ?
|
||||
streakMessageGen.MessageOnStreak(attackerStats.KillStreak, attackerStats.DeathStreak) :
|
||||
streakMessageGen.MessageOnStreak(-1, -1);
|
||||
|
||||
if (streakMessage != string.Empty)
|
||||
await attacker.Tell(streakMessage);
|
||||
|
||||
// immediately write changes in debug
|
||||
#if DEBUG
|
||||
var statsSvc = ContextThreads[serverId];
|
||||
@ -209,10 +229,16 @@ namespace StatsPlugin.Helpers
|
||||
/// <param name="victimStats">Stats of the victim</param>
|
||||
public void CalculateKill(EFClientStatistics attackerStats, EFClientStatistics victimStats)
|
||||
{
|
||||
attackerStats.Kills += 1;
|
||||
attackerStats.SessionKills += 1;
|
||||
attackerStats.KillStreak += 1;
|
||||
attackerStats.DeathStreak = 0;
|
||||
bool suicide = attackerStats.ClientId == victimStats.ClientId;
|
||||
|
||||
// only update their kills if they didn't kill themselves
|
||||
if (!suicide)
|
||||
{
|
||||
attackerStats.Kills += 1;
|
||||
attackerStats.SessionKills += 1;
|
||||
attackerStats.KillStreak += 1;
|
||||
attackerStats.DeathStreak = 0;
|
||||
}
|
||||
|
||||
victimStats.Deaths += 1;
|
||||
victimStats.SessionDeaths += 1;
|
||||
@ -224,6 +250,8 @@ namespace StatsPlugin.Helpers
|
||||
attackerStats.Client = null;
|
||||
|
||||
// update after calculation
|
||||
attackerStats.TimePlayed += (int)(DateTime.UtcNow - attackerStats.LastActive).TotalSeconds;
|
||||
victimStats.TimePlayed += (int)(DateTime.UtcNow - victimStats.LastActive).TotalSeconds;
|
||||
attackerStats.LastActive = DateTime.UtcNow;
|
||||
victimStats.LastActive = DateTime.UtcNow;
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using SharedLibrary;
|
||||
using SharedLibrary.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -8,30 +10,55 @@ namespace StatsPlugin.Helpers
|
||||
{
|
||||
public class StreakMessage
|
||||
{
|
||||
public static string MessageOnStreak(int killStreak, int deathStreak)
|
||||
private ConfigurationManager config;
|
||||
|
||||
public StreakMessage(Server sv)
|
||||
{
|
||||
String Message = "";
|
||||
switch (killStreak)
|
||||
config = new ConfigurationManager(sv);
|
||||
|
||||
// initialize default messages
|
||||
if (config.GetProperty<Dictionary<int, string>>("KillstreakMessages") == null)
|
||||
{
|
||||
case 5:
|
||||
Message = "Great job! You're on a ^55 killstreak!";
|
||||
break;
|
||||
case 10:
|
||||
Message = "Amazing! ^510 kills ^7without dying!";
|
||||
break;
|
||||
var killstreakMessages = new Dictionary<int, string>()
|
||||
{
|
||||
{ -1, "Try not to kill yourself anymore" },
|
||||
{ 5, "Great job! You're on a ^55 killstreak!" },
|
||||
{ 10, "Amazing! ^510 kills ^7without dying!" },
|
||||
{ 25, "You better call in that nuke, ^525 killstreak!" }
|
||||
};
|
||||
config.AddProperty(new KeyValuePair<string, object>("KillstreakMessages", killstreakMessages));
|
||||
}
|
||||
|
||||
switch (deathStreak)
|
||||
if (config.GetProperty<Dictionary<int, string>>("DeathstreakMessages") == null)
|
||||
{
|
||||
case 5:
|
||||
Message = "Pick it up soldier, you've died ^55 times ^7in a row...";
|
||||
break;
|
||||
case 10:
|
||||
Message = "Seriously? ^510 deaths ^7without getting a kill?";
|
||||
break;
|
||||
var deathstreakMessages = new Dictionary<int, string>()
|
||||
{
|
||||
{ 5, "Pick it up soldier, you've died ^55 times ^7in a row..." },
|
||||
{ 10, "Seriously? ^510 deaths ^7without getting a kill?" },
|
||||
};
|
||||
config.AddProperty(new KeyValuePair<string, object>("DeathstreakMessages", deathstreakMessages));
|
||||
}
|
||||
}
|
||||
|
||||
return Message;
|
||||
/// <summary>
|
||||
/// Get a message from the configuration encouraging or discouraging clients
|
||||
/// </summary>
|
||||
/// <param name="killStreak">how many kills the client has without dying</param>
|
||||
/// <param name="deathStreak">how many deaths the client has without getting a kill</param>
|
||||
/// <returns>message to send to the client</returns>
|
||||
public string MessageOnStreak(int killStreak, int deathStreak)
|
||||
{
|
||||
var killstreakMessage = config.GetProperty<Dictionary<int, string>>("KillstreakMessages");
|
||||
var deathstreakMessage = config.GetProperty<Dictionary<int, string>>("DeathstreakMessages");
|
||||
|
||||
string message = "";
|
||||
|
||||
if (killstreakMessage.ContainsKey(killStreak))
|
||||
message =killstreakMessage[killStreak];
|
||||
else if (deathstreakMessage.ContainsKey(deathStreak))
|
||||
message = deathstreakMessage[deathStreak];
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ namespace StatsPlugin
|
||||
|
||||
public enum WeaponName
|
||||
{
|
||||
none = 0,
|
||||
defaultweapon_mp = 1,
|
||||
riotshield_mp = 2,
|
||||
beretta_mp = 3,
|
||||
@ -1333,7 +1334,27 @@ namespace StatsPlugin
|
||||
ak74u_silencer_thermal_mp,
|
||||
ak74u_silencer_xmags_mp,
|
||||
ak74u_thermal_xmags_mp,
|
||||
m16_fmj_thermal_mp,
|
||||
m16_fmj_xmags_mp,
|
||||
m16_gl_heartbeat_mp,
|
||||
m16_gl_reflex_mp,
|
||||
m16_gl_silencer_mp,
|
||||
m16_gl_thermal_mp,
|
||||
m16_gl_xmags_mp,
|
||||
m16_reflex_silencer_mp,
|
||||
m16_heartbeat_reflex_mp,
|
||||
m16_heartbeat_shotgun_mp,
|
||||
m16_heartbeat_silencer_mp,
|
||||
m16_heartbeat_thermal_mp,
|
||||
m16_heartbeat_xmags_mp,
|
||||
m16_reflex_shotgun_mp,
|
||||
m16_reflex_xmags_mp,
|
||||
m16_shotgun_silencer_mp,
|
||||
m16_shotgun_thermal_mp,
|
||||
m16_shotgun_xmags_mp,
|
||||
m16_silencer_thermal_mp,
|
||||
m16_silencer_xmags_mp,
|
||||
m16_thermal_xmags_mp,
|
||||
m40a3_mp,
|
||||
peacekeeper_mp,
|
||||
dragunov_mp,
|
||||
|
@ -28,12 +28,14 @@ namespace StatsPlugin.Models
|
||||
[NotMapped]
|
||||
public double KDR
|
||||
{
|
||||
get => Deaths == 0 ? Kills : Math.Round((float)Kills / (float)Deaths, 2);
|
||||
get => Deaths == 0 ? Kills : Math.Round(Kills / (double)Deaths, 2);
|
||||
}
|
||||
[Required]
|
||||
public double SPM { get; set; }
|
||||
[Required]
|
||||
public double Skill { get; set; }
|
||||
[Required]
|
||||
public int TimePlayed { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public int SessionKills { get; set; }
|
||||
|
@ -10,6 +10,8 @@ namespace StatsPlugin.Pages
|
||||
{
|
||||
public class ClientMessages : HTMLPage
|
||||
{
|
||||
public ClientMessages() : base(false) { }
|
||||
|
||||
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
||||
{
|
||||
StringBuilder S = new StringBuilder();
|
||||
|
@ -10,6 +10,8 @@ namespace StatsPlugin.Pages
|
||||
{
|
||||
public class LiveStats : HTMLPage
|
||||
{
|
||||
public LiveStats() : base(false) { }
|
||||
|
||||
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
||||
{
|
||||
StringBuilder S = new StringBuilder();
|
||||
|
@ -71,6 +71,8 @@ namespace StatsPlugin
|
||||
string[] killInfo = (E.Data != null) ? E.Data.Split(';') : new string[0];
|
||||
if (killInfo.Length >= 9 && killInfo[0].Contains("ScriptKill"))
|
||||
await Manager.AddScriptKill(E.Origin, E.Target, S.GetHashCode(), S.CurrentMap.Name, killInfo[7], killInfo[8], killInfo[5], killInfo[6], killInfo[3], killInfo[4]);
|
||||
else
|
||||
await Manager.AddStandardKill(E.Origin, E.Target);
|
||||
break;
|
||||
case Event.GType.Death:
|
||||
break;
|
||||
@ -84,14 +86,14 @@ namespace StatsPlugin
|
||||
{
|
||||
var serverStats = new GenericRepository<EFServerStatistics>();
|
||||
return serverStats.Find(s => s.Active)
|
||||
.Sum(c => c.TotalKills).ToString();
|
||||
.Sum(c => c.TotalKills).ToString("#,##0");
|
||||
}
|
||||
|
||||
string totalPlayTime()
|
||||
{
|
||||
var serverStats = new GenericRepository<EFServerStatistics>();
|
||||
return serverStats.GetQuery(s => s.Active)
|
||||
.Sum(c => c.TotalPlayTime).ToString();
|
||||
return Math.Ceiling((serverStats.GetQuery(s => s.Active)
|
||||
.Sum(c => c.TotalPlayTime) / 3600.0)).ToString("#,##0");
|
||||
}
|
||||
|
||||
manager.GetMessageTokens().Add(new MessageToken("TOTALKILLS", totalKills));
|
||||
|
@ -66,7 +66,7 @@ namespace StatsPlugin
|
||||
ManagerInstance.GetMessageTokens().Add(new MessageToken("TOTALPLAYTIME", GetTotalPlaytime));
|
||||
|
||||
ClientStatsSvc = new SharedLibrary.Services.GenericService<Models.EFClientStatistics>();
|
||||
ServerSvc = new SharedLibrary.Services.GenericService<Models.EFServer>()
|
||||
ServerSvc = new SharedLibrary.Services.GenericService<Models.EFServer>();
|
||||
|
||||
ChatDB = new ChatDatabase("Database/ChatHistory.rm", ManagerInstance.GetLogger());
|
||||
|
||||
|
Reference in New Issue
Block a user