fixed ping bug showing origin ping instead of target

event parser has GetGameDir
made parsers choosen more dynamically
profile shows online/offline status of client
This commit is contained in:
RaidMax 2018-04-14 23:26:27 -05:00
parent cd2bbfb3d4
commit 2964fd71b2
10 changed files with 66 additions and 17 deletions

View File

@ -104,5 +104,8 @@ namespace Application.EventParsers
Owner = server
};
}
// other parsers can derive from this parser so we make it virtual
public virtual string GetGameDir() => "userraw";
}
}

View File

@ -0,0 +1,12 @@
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
namespace Application.EventParsers
{
class IW5EventParser : IW4EventParser
{
public override string GetGameDir() => "rzodemo";
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using SharedLibraryCore;
@ -88,5 +89,7 @@ namespace Application.EventParsers
Owner = server
};
}
public string GetGameDir() => $"t6r{Path.DirectorySeparatorChar}data";
}
}

View File

@ -89,9 +89,6 @@ namespace Application.RconParsers
long npID = Regex.Match(responseLine, @"([a-z]|[0-9]){16}", RegexOptions.IgnoreCase).Value.ConvertLong();
int.TryParse(playerInfo[0], out cID);
var regex = Regex.Match(responseLine, @"\d+\.\d+\.\d+.\d+\:\d{1,5}");
#if DEBUG
Ping = 1;
#endif
int cIP = regex.Value.Split(':')[0].ConvertToIP();
regex = Regex.Match(responseLine, @"[0-9]{1,2}\s+[0-9]+\s+");
int score = Int32.Parse(regex.Value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1]);

View File

@ -17,6 +17,7 @@ using IW4MAdmin.Application.Misc;
using Application.RconParsers;
using Application.EventParsers;
using SharedLibraryCore.Exceptions;
using System.Runtime.InteropServices;
namespace IW4MAdmin
{
@ -573,13 +574,20 @@ namespace IW4MAdmin
public async Task Initialize()
{
RconParser = ServerConfig.UseT6MParser ? (IRConParser)new T6MRConParser() : new IW4RConParser();
EventParser = ServerConfig.UseT6MParser ? (IEventParser)new T6MEventParser() : new IW4EventParser();
var version = await this.GetDvarAsync<string>("version");
GameName = Utilities.GetGame(version.Value);
if (GameName == Game.UKN)
if (GameName == Game.IW4)
EventParser = new IW4EventParser();
else if (GameName == Game.IW5)
EventParser = new IW5EventParser();
else if (GameName == Game.T6M)
EventParser = new T6MEventParser();
else if (GameName == Game.UKN)
Logger.WriteWarning($"Game name not recognized: {version}");
else
EventParser = new IW4EventParser();
var shortversion = await this.GetDvarAsync<string>("shortversion");
var hostname = await this.GetDvarAsync<string>("sv_hostname");
@ -617,7 +625,7 @@ namespace IW4MAdmin
Website = website.Value;
}
catch (SharedLibraryCore.Exceptions.DvarException)
catch (DvarException)
{
Website = "this server's website";
}
@ -643,19 +651,21 @@ namespace IW4MAdmin
}
CustomCallback = await ScriptLoaded();
string mainPath = (GameName == Game.IW4 && onelog.Value >= 0) ? "userraw" : "main";
// patch for T5M:V2 log path
mainPath = (GameName == Game.T5M) ? "rzodemo" : mainPath;
// patch for T6M:PLUTONIUM
mainPath = (GameName == Game.T6M) ? $"t6r{Path.DirectorySeparatorChar}data" : mainPath;
string mainPath = EventParser.GetGameDir();
mainPath = (GameName == Game.IW4 && onelog.Value > 0) ? "main" : mainPath;
#if DEBUG
// basepath.Value = @"\\192.168.88.253\Call of Duty Black Ops II";
#endif
string logPath = (game.Value == "" || onelog?.Value == 1) ?
string logPath = game.Value == string.Empty ?
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
// hopefully fix wine drive name mangling
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
logPath = Regex.Replace(logPath, @"[A-Z]:", "");
}
if (!File.Exists(logPath))
{
Logger.WriteError($"Gamelog {logPath} does not exist!");

View File

@ -1090,14 +1090,14 @@ namespace SharedLibraryCore.Commands
if (E.Target == null)
await E.Owner.Broadcast($"{E.Origin.Name}'s ping is ^5{E.Origin.Ping}^7ms");
else
await E.Owner.Broadcast($"{E.Target.Name}'s ping is ^5{E.Origin.Ping}^7ms");
await E.Owner.Broadcast($"{E.Target.Name}'s ping is ^5{E.Target.Ping}^7ms");
}
else
{
if (E.Target == null)
await E.Origin.Tell($"Your ping is ^5{E.Origin.Ping}^7ms");
else
await E.Origin.Tell($"{E.Target.Name}'s ping is ^5{E.Origin.Ping}^7ms");
await E.Origin.Tell($"{E.Target.Name}'s ping is ^5{E.Target.Ping}^7ms");
}
}
}

View File

@ -22,5 +22,7 @@ namespace SharedLibraryCore.Dtos
public string TimePlayed { get; set; }
public bool Authenticated { get; set; }
public List<ProfileMeta> Meta { get; set; }
public bool Online { get; set; }
public string TimeOnline { get; set; }
}
}

View File

@ -6,6 +6,17 @@ namespace SharedLibraryCore.Interfaces
{
public interface IEventParser
{
/// <summary>
/// Generates a game event based on log line input
/// </summary>
/// <param name="server">server the event occurred on</param>
/// <param name="logLine">single log line string</param>
/// <returns></returns>
GameEvent GetEvent(Server server, string logLine);
/// <summary>
/// Get game specific folder prefix for log files
/// </summary>
/// <returns>Game directory prefix</returns>
string GetGameDir();
}
}

View File

@ -40,6 +40,8 @@ namespace WebfrontCore.Controllers
.Distinct()
.OrderBy(i => i)
.ToList(),
Online = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null,
TimeOnline = (DateTime.UtcNow - client.LastConnection).TimeSpanText()
};
var meta = await MetaService.GetMeta(client.ClientId);

View File

@ -11,6 +11,15 @@
</div>
<div id="profile_info" class="text-center text-sm-left pr-3 pl-3">
<div id="profile_name">
@if (Model.Online)
{
<span class="oi oi-media-record text-success pr-2 h4" title="Online for @Model.TimeOnline"></span>
}
else
{
<span class="oi oi-media-record text-danger pr-2 h4" title="Offline"></span>
}
<div class="client-name h1 d-flex d-inline-flex">
@Model.Name
</div>
@ -21,13 +30,13 @@
<div id="profile_aliases_btn" class="oi oi-caret-bottom h3 ml-0 ml-md-2"></div>
@if (Model.LevelInt < (int)ViewBag.User.Level &&
(SharedLibraryCore.Objects.Player.Permission)Model.LevelInt != SharedLibraryCore.Objects.Player.Permission.Banned)
(SharedLibraryCore.Objects.Player.Permission)Model.LevelInt != SharedLibraryCore.Objects.Player.Permission.Banned)
{
<div id="profile_action_ban_btn" class="profile-action oi oi-lock-unlocked text-success h3 ml-2" title="Ban Client" data-action="ban" aria-hidden="true"></div>
}
@if (Model.LevelInt < (int)ViewBag.User.Level &&
(SharedLibraryCore.Objects.Player.Permission)Model.LevelInt == SharedLibraryCore.Objects.Player.Permission.Banned)
(SharedLibraryCore.Objects.Player.Permission)Model.LevelInt == SharedLibraryCore.Objects.Player.Permission.Banned)
{
<div id="profile_action_unban_btn" class="profile-action oi oi-lock-locked text-danger h3 ml-2" title="Unban Client" data-action="unban" aria-hidden="true"></div>
}