remove create proxy as it's not even used anymore

more fixes for alias stuff
hopefully fix rare bug where client activity cshtml loop goes oob
add URLProtocol format to event parsers to allow connecting through webfront
This commit is contained in:
RaidMax 2019-04-06 21:48:49 -05:00
parent 863ba8b096
commit 8667532d24
18 changed files with 86 additions and 128 deletions

View File

@ -6,7 +6,7 @@
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.2.5.9</Version>
<Version>2.2.6.0</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Product>IW4MAdmin</Product>
@ -31,8 +31,8 @@
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
<AssemblyVersion>2.2.5.9</AssemblyVersion>
<FileVersion>2.2.5.8</FileVersion>
<AssemblyVersion>2.2.6.0</AssemblyVersion>
<FileVersion>2.2.6.0</FileVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -73,6 +73,8 @@ namespace IW4MAdmin.Application.EventParsers
public Game GameName { get; set; } = Game.COD;
public string URLProtocolFormat { get; set; } = "CoD://{{ip}}:{{port}}";
public virtual GameEvent GetEvent(Server server, string logLine)
{
logLine = Regex.Replace(logLine, @"([0-9]+:[0-9]+ |^[0-9]+ )", "").Trim();

View File

@ -45,19 +45,16 @@ namespace IW4MAdmin
if (client == null)
{
Logger.WriteDebug($"Client {clientFromLog} first time connecting");
clientFromLog.CurrentServer = this;
client = await Manager.GetClientService().Create(clientFromLog);
}
// client has connected in the past
else
{
// this is only a temporary version until the IPAddress is transmitted
client.CurrentAlias = new EFAlias
/// this is only a temporary version until the IPAddress is transmitted
client.CurrentAlias = new EFAlias()
{
Name = clientFromLog.Name,
IPAddress = clientFromLog.IPAddress
};
}
Logger.WriteInfo($"Client {client} connected...");
@ -209,16 +206,18 @@ namespace IW4MAdmin
// they're already connected
if (existingClient != null)
{
Logger.WriteWarning($"detected preconnect for {E.Origin}, but they are already connected");
return false;
}
CONNECT:
// we can go ahead and put them in
if (Clients[E.Origin.ClientNumber] == null)
{
#if DEBUG == true
Logger.WriteDebug($"Begin PreConnect for {E.Origin}");
#endif
// we can go ahead and put them in so that they don't get re added
Clients[E.Origin.ClientNumber] = E.Origin;
await OnClientConnected(E.Origin);
ChatHistory.Add(new ChatInfo()
@ -314,28 +313,6 @@ namespace IW4MAdmin
await Warn(E.Data, E.Target, E.Origin);
}
//else if (E.Type == GameEvent.EventType.Quit)
//{
// var origin = GetClientsAsList().FirstOrDefault(_client => _client.NetworkId.Equals(E.Origin));
// if (origin != null)
// {
// var e = new GameEvent()
// {
// Type = GameEvent.EventType.Disconnect,
// Origin = origin,
// Owner = this
// };
// Manager.GetEventHandler().AddEvent(e);
// }
// else
// {
// return false;
// }
//}
else if (E.Type == GameEvent.EventType.Disconnect)
{
ChatHistory.Add(new ChatInfo()
@ -351,13 +328,6 @@ namespace IW4MAdmin
else if (E.Type == GameEvent.EventType.PreDisconnect)
{
//if ((DateTime.UtcNow - SessionStart).TotalSeconds < 30)
//{
// Logger.WriteInfo($"Cancelling pre disconnect for {E.Origin} as it occured too close to map end");
// E.FailReason = GameEvent.EventFailReason.Invalid;
// return false;
//}
// predisconnect comes from minimal rcon polled players and minimal log players
// so we need to disconnect the "full" version of the client
var client = GetClientsAsList().FirstOrDefault(_client => _client.Equals(E.Origin));
@ -375,7 +345,7 @@ namespace IW4MAdmin
else
{
Logger.WriteDebug($"Client {E.Origin} detected as disconnecting, but could not find them in the player list");
Logger.WriteWarning($"Client {E.Origin} detected as disconnecting, but could not find them in the player list");
Logger.WriteDebug($"Expected {E.Origin} but found {GetClientsAsList().FirstOrDefault(_client => _client.ClientNumber == E.Origin.ClientNumber)}");
return false;
}
@ -488,9 +458,9 @@ namespace IW4MAdmin
return true;
}
private Task OnClientUpdate(EFClient origin)
private async Task OnClientUpdate(EFClient origin)
{
var client = Clients[origin.ClientNumber];
var client = Clients.FirstOrDefault(_client => _client.Equals(origin));
if (client != null)
{
@ -500,11 +470,9 @@ namespace IW4MAdmin
// update their IP if it hasn't been set yet
if (client.IPAddress == null && !client.IsBot)
{
return client.OnJoin(origin.IPAddress);
await client.OnJoin(origin.IPAddress);
}
}
return Task.CompletedTask;
}
/// <summary>
@ -582,7 +550,7 @@ namespace IW4MAdmin
foreach (var disconnectingClient in polledClients[1])
{
if (disconnectingClient.State == EFClient.ClientState.Disconnecting)
if (disconnectingClient.State == ClientState.Disconnecting)
{
continue;
}

View File

@ -3,7 +3,7 @@ var eventParser;
var plugin = {
author: 'FrenchFry, RaidMax',
version: 0.2,
version: 0.3,
name: 'CoD4x Parser',
isParser: true,
@ -27,6 +27,7 @@ var plugin = {
eventParser.Configuration.GameDirectory = 'main';
eventParser.Version = 'CoD4 X 1.8 win_mingw-x86 build 2055 May 2 2017';
eventParser.GameName = 1; // IW3
eventParser.URLProtocolFormat = 'cod4://{{ip}}:{{port}}';
},
onUnloadAsync: function () {

View File

@ -3,7 +3,7 @@ var eventParser;
var plugin = {
author: 'RaidMax',
version: 0.2,
version: 0.3,
name: 'IW4 Parser',
isParser: true,
@ -25,6 +25,7 @@ var plugin = {
rconParser.GameName = 2; // IW4x
eventParser.Version = 'IW4x (v0.6.0)';
eventParser.GameName = 2; // IW4x
eventParser.URLProtocolFormat = 'iw4x://{{ip}}:{{port}}';
},
onUnloadAsync: function () {

View File

@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace SharedLibraryCore.Database.Models
{
public class EFAlias : SharedEntity
public partial class EFAlias : SharedEntity
{
[Key]
public int AliasId { get; set; }

View File

@ -11,19 +11,10 @@ namespace SharedLibraryCore.Helpers
{
DateTime t = DateTime.UtcNow;
When = new DateTime(t.Year, t.Month, t.Day, t.Hour, Math.Min(59, UpdateInterval * (int)Math.Round(t.Minute / (float)UpdateInterval)), 0);
PlayerCount = cNum;
y = cNum;
}
#if DEBUG
public PlayerHistory(DateTime t, int cNum)
{
When = new DateTime(t.Year, t.Month, t.Day, t.Hour, Math.Min(59, UpdateInterval * (int)Math.Round(t.Minute / (float)UpdateInterval)), 0);
PlayerCount = cNum;
}
#endif
private DateTime When;
private int PlayerCount;
/// <summary>
/// Used by CanvasJS as a point on the x axis
@ -36,16 +27,9 @@ namespace SharedLibraryCore.Helpers
}
}
/// <summary>
/// Used by CanvasJS as a point on the y axis
/// </summary>
public int y
{
get
{
return PlayerCount;
}
}
public int y { get; }
}
}

View File

@ -27,5 +27,10 @@ namespace SharedLibraryCore.Interfaces
/// specifies the game name (usually the internal studio iteration ie: IW4, T5 etc...)
/// </summary>
Game GameName { get; set; }
/// <summary>
/// specifies the connect URI used to join game servers via web browser
/// </summary>
string URLProtocolFormat { get; set; }
}
}

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharedLibraryCore.Objects
{
public class Alias : Database.Models.EFAlias
{
}
}

View File

@ -0,0 +1,7 @@
namespace SharedLibraryCore.Database.Models
{
public partial class EFAlias
{
}
}

View File

@ -80,13 +80,12 @@ namespace SharedLibraryCore.Database.Models
{
{ "_reportCount", 0 }
};
CurrentAlias = new EFAlias();
ReceivedPenalties = new List<EFPenalty>();
}
public override string ToString()
{
return $"{Name}::{NetworkId}";
return $"{CurrentAlias?.Name ?? "--"}::{NetworkId}";
}
/// <summary>

View File

@ -17,27 +17,6 @@ namespace SharedLibraryCore.Services
public async Task<EFAlias> Create(EFAlias entity)
{
throw await Task.FromResult(new Exception());
/*using (var context = new DatabaseContext())
{
var alias = new EFAlias()
{
Active = true,
DateAdded = DateTime.UtcNow,
IPAddress = entity.IPAddress,
Name = entity.Name
};
entity.Link = await context.AliasLinks
.FirstAsync(a => a.AliasLinkId == entity.Link.AliasLinkId);
context.Aliases.Add(entity);
await context.SaveChangesAsync();
return entity;
}*/
}
public Task<EFAlias> CreateProxy()
{
return null;
}
public async Task<EFAlias> Delete(EFAlias entity)

View File

@ -28,9 +28,12 @@ namespace SharedLibraryCore.Services
if (existingAlias != null)
{
entity.CurrentServer.Logger.WriteDebug($"[create] client with new GUID {entity} has existing link {existingAlias.LinkId}");
linkId = existingAlias.LinkId;
if (existingAlias.Name == entity.Name)
{
entity.CurrentServer.Logger.WriteDebug($"[create] client with new GUID {entity} has existing alias {existingAlias.AliasId}");
aliasId = existingAlias.AliasId;
}
}
@ -44,9 +47,12 @@ namespace SharedLibraryCore.Services
NetworkId = entity.NetworkId
};
context.Clients.Add(client);
// they're just using a new GUID
if (aliasId.HasValue)
{
entity.CurrentServer.Logger.WriteDebug($"[create] setting {entity}'s alias id and linkid to ({aliasId.Value}, {linkId.Value})");
client.CurrentAliasId = aliasId.Value;
client.AliasLinkId = linkId.Value;
}
@ -54,8 +60,9 @@ namespace SharedLibraryCore.Services
// link was found but they don't have an exact alias
else if (!aliasId.HasValue && linkId.HasValue)
{
entity.CurrentServer.Logger.WriteDebug($"[create] setting {entity}'s linkid to {linkId.Value}, but creating new alias");
client.AliasLinkId = linkId.Value;
client.CurrentAlias = new Alias()
client.CurrentAlias = new EFAlias()
{
Name = entity.Name,
DateAdded = DateTime.UtcNow,
@ -67,18 +74,22 @@ namespace SharedLibraryCore.Services
// brand new players (supposedly)
else
{
client.AliasLink = new EFAliasLink();
client.CurrentAlias = new Alias()
entity.CurrentServer.Logger.WriteDebug($"[create] creating new Link and Alias for {entity}");
var link = new EFAliasLink();
var alias = new EFAlias()
{
Name = entity.Name,
DateAdded = DateTime.UtcNow,
IPAddress = entity.IPAddress,
Link = client.AliasLink,
Link = link
};
link.Children.Add(alias);
client.AliasLink = link;
client.CurrentAlias = alias;
}
context.Clients.Add(client);
await context.SaveChangesAsync();
return client;
@ -474,11 +485,6 @@ namespace SharedLibraryCore.Services
.CountAsync();
}
}
public Task<EFClient> CreateProxy()
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -68,11 +68,6 @@ namespace SharedLibraryCore.Services
return newEntity;
}
public Task<EFPenalty> CreateProxy()
{
throw new NotImplementedException();
}
public Task<EFPenalty> Delete(EFPenalty entity)
{
throw new NotImplementedException();

View File

@ -8,7 +8,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
@ -716,6 +715,20 @@ namespace SharedLibraryCore
return Assembly.GetCallingAssembly().GetName().Version.ToString();
}
public static string FormatExt(this string input, params object[] values)
{
var matches = Regex.Matches(Regex.Unescape(input), @"{{\w+}}");
string output = input;
int index = 0;
foreach (Match match in matches)
{
output = output.Replace(match.Value.ToString(), $"{{{index.ToString()}}}");
index++;
}
return string.Format(output, values);
}
#if DEBUG == true
private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo();

View File

@ -11,7 +11,7 @@ namespace WebfrontCore.Controllers
[ResponseCache(NoStore = true, Duration = 0)]
public IActionResult ClientActivity(long id)
{
var s = Manager.GetServers().FirstOrDefault(s2 => s2.EndPoint == id);
var s = Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == id);
if (s == null)
{

View File

@ -36,6 +36,10 @@
@{
for (int i = 0; i < half; i++)
{
if (i > Model.Players.Count - 1)
{
continue;
}
string levelColorClass = !ViewBag.Authorized ? "" : $"level-color-{Model.Players[i].LevelInt}";
<span>@Html.ActionLink(Model.Players[i].Name, "ProfileAsync", "Client", new { id = Model.Players[i].ClientId }, new { @class = levelColorClass })</span><br />
}
@ -45,6 +49,10 @@
@{
for (int i = half; i < Math.Min(Model.ClientCount, Model.Players.Count); i++)
{
if (i > Model.Players.Count - 1)
{
continue;
}
string levelColorClass = !ViewBag.Authorized ? "" : $"level-color-{Model.Players[i].LevelInt}";
<span>@Html.ActionLink(Model.Players[i].Name, "ProfileAsync", "Client", new { id = Model.Players[i].ClientId }, new { @class = levelColorClass })</span><br />
}

View File

@ -1,6 +1,4 @@

@model SharedLibraryCore.Dtos.ServerInfo
@model SharedLibraryCore.Dtos.ServerInfo
@{
Layout = null;
}
@ -12,8 +10,13 @@
</div>
<div id="server_clientactivity_@Model.ID" class="bg-dark row server-activity pt-2 pb-2">
<div class="col-4">
<div class="oi oi-play-circle h1"></div>
</div>
<div class="col-8">
@await Html.PartialAsync("../Server/_ClientActivity", Model)
</div>
</div>
<div class="row server-history mb-4">
<div class="server-history-row col-md-12" id="server_history_@Model.ID" data-serverid="@Model.ID" data-clienthistory='@Html.Raw(Json.Serialize(Model.PlayerHistory))' data-online="@Model.Online"></div>