Finish preliminary parser for TeknoMW3

This commit is contained in:
RaidMax 2019-02-02 18:54:30 -06:00
parent 59e0072744
commit 3e5282df87
12 changed files with 56 additions and 31 deletions

View File

@ -7,6 +7,5 @@ namespace IW4MAdmin.Application.EventParsers
{
sealed internal class DynamicEventParser : IW4EventParser
{
public string Version { get; set; }
}
}

View File

@ -5,7 +5,6 @@ namespace IW4MAdmin.Application.EventParsers
class DynamicEventParserConfiguration : IEventParserConfiguration
{
public string GameDirectory { get; set; }
public ParserRegex Say { get; set; } = new ParserRegex();
public ParserRegex Join { get; set; } = new ParserRegex();
public ParserRegex Quit { get; set; } = new ParserRegex();

View File

@ -68,6 +68,8 @@ namespace IW4MAdmin.Application.EventParsers
public IEventParserConfiguration Configuration { get; set; }
public string Version { get; set; } = "IW4x (v0.6.0)";
public virtual GameEvent GetEvent(Server server, string logLine)
{
logLine = Regex.Replace(logLine, @"([0-9]+:[0-9]+ |^[0-9]+ )", "").Trim();

View File

@ -665,13 +665,19 @@ namespace IW4MAdmin
public async Task Initialize()
{
//RemoteConnection.SetConfiguration(Manager.AdditionalRConParsers.First().Configuration);
var rconParser = Manager.AdditionalRConParsers
.FirstOrDefault(_parser => _parser.Version == Manager.GetApplicationSettings().Configuration().CustomParserVersion);
RconParser = ServerConfig.UseT6MParser ?
(IRConParser)new T6MRConParser() :
new IW4RConParser();
var eventParser = Manager.AdditionalEventParsers
.FirstOrDefault(_parser => _parser.Version == Manager.GetApplicationSettings().Configuration().CustomParserVersion);
RemoteConnection.SetConfiguration(RconParser.Configuration);
rconParser = rconParser ?? new IW4RConParser();
eventParser = eventParser ?? new IW4EventParser();
RemoteConnection.SetConfiguration(rconParser.Configuration);
RconParser = rconParser;
EventParser = eventParser;
var version = await this.GetDvarAsync<string>("version");
Version = version.Value;
@ -693,18 +699,18 @@ namespace IW4MAdmin
EventParser = new T6MEventParser();
}
else
{
EventParser = new IW3EventParser(); // this uses the 'main' folder for log paths
}
//else
//{
// EventParser = new IW3EventParser(); // this uses the 'main' folder for log paths
//}
if (GameName == Game.UKN)
{
Logger.WriteWarning($"Game name not recognized: {version}");
//if (GameName == Game.UKN)
//{
// Logger.WriteWarning($"Game name not recognized: {version}");
EventParser = Manager.AdditionalEventParsers.FirstOrDefault(_parser => (_parser as DynamicEventParser).Version == version.Value) ?? EventParser;
RconParser = Manager.AdditionalRConParsers.FirstOrDefault(_parser => (_parser as DynamicRConParser).Version == version.Value) ?? RconParser;
}
// EventParser = Manager.AdditionalEventParsers.FirstOrDefault(_parser => _parser.Version == version.Value) ?? EventParser;
// RconParser = Manager.AdditionalRConParsers.FirstOrDefault(_parser => (_parser as DynamicRConParser).Version == version.Value) ?? RconParser;
//}
var infoResponse = RconParser.Configuration.CommandPrefixes.RConGetInfo != null ? await this.GetInfoAsync() : null;
// this is normally slow, but I'm only doing it because different games have different prefixes
@ -750,7 +756,7 @@ namespace IW4MAdmin
this.MaxClients = maxplayers;
this.FSGame = game;
this.Gametype = gametype;
this.IP = ip.Value == "localhost" ? ServerConfig.IPAddress : ip.Value;
this.IP = ip.Value == "localhost" ? ServerConfig.IPAddress : ip.Value ?? ServerConfig.IPAddress;
if (logsync.Value == 0 || logfile.Value == string.Empty)
{
@ -767,9 +773,9 @@ namespace IW4MAdmin
string mainPath = EventParser.Configuration.GameDirectory;
string logPath = string.Empty;
LogPath = game == string.Empty ?
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
LogPath = string.IsNullOrEmpty(game) ?
$"{basepath?.Value?.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile?.Value}" :
$"{basepath?.Value?.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game?.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile?.Value}";
bool remoteLog = false;
if (GameName == Game.IW5 || ServerConfig.ManualLogPath?.Length > 0)

View File

@ -7,6 +7,5 @@ namespace IW4MAdmin.Application.RconParsers
{
sealed internal class DynamicRConParser : IW4RConParser
{
public string Version { get; set; }
}
}

View File

@ -50,6 +50,8 @@ namespace IW4MAdmin.Application.RconParsers
public IRConParserConfiguration Configuration { get; set; }
public string Version { get; set; } = "IW4x (v0.6.0)";
public async Task<string[]> ExecuteCommandAsync(Connection connection, string command)
{
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND, command);
@ -61,7 +63,7 @@ namespace IW4MAdmin.Application.RconParsers
string[] lineSplit = await connection.SendQueryAsync(StaticHelpers.QueryType.DVAR, dvarName);
string response = string.Join('\n', lineSplit.Skip(1));
if (lineSplit[0] != Configuration.CommandPrefixes.RConResponse)
if (!lineSplit[0].Contains(Configuration.CommandPrefixes.RConResponse))
{
throw new DvarException($"Could not retrieve DVAR \"{dvarName}\"");
}
@ -113,9 +115,9 @@ namespace IW4MAdmin.Application.RconParsers
}
int validMatches = 0;
foreach (String S in Status)
foreach (string S in Status)
{
String responseLine = S.Trim();
string responseLine = S.Trim();
var regex = Regex.Match(responseLine, Configuration.Status.Pattern, RegexOptions.IgnoreCase);

View File

@ -14,6 +14,7 @@ namespace IW4MAdmin.Application.RconParsers
public class T6MRConParser : IRConParser
{
public IRConParserConfiguration Configuration { get; set; }
public string Version { get; set; } = "";
public T6MRConParser()
{

View File

@ -28,6 +28,7 @@ namespace SharedLibraryCore.Configuration
public string Id { get; set; }
public List<ServerConfiguration> Servers { get; set; }
public int AutoMessagePeriod { get; set; }
public string CustomParserVersion { get; set; }
public List<string> AutoMessages { get; set; }
public List<string> GlobalRules { get; set; }
public List<MapConfiguration> Maps { get; set; }

View File

@ -38,6 +38,22 @@ namespace SharedLibraryCore.Interfaces
public string Pattern { get; set; }
public Dictionary<GroupType, int> GroupMapping { get; private set; }
public void AddMapping(object mapKey, object mapValue)
{
if (int.TryParse(mapKey.ToString(), out int key) && int.TryParse(mapValue.ToString(), out int value))
{
if (GroupMapping.ContainsKey((GroupType)key))
{
GroupMapping[(GroupType)key] = value;
}
else
{
GroupMapping.Add((GroupType)key, value);
}
}
}
public ParserRegex()
{
GroupMapping = new Dictionary<GroupType, int>();

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SharedLibraryCore.Interfaces
namespace SharedLibraryCore.Interfaces
{
public interface IEventParser
{
@ -19,5 +15,6 @@ namespace SharedLibraryCore.Interfaces
/// </summary>
/// <returns>Game directory prefix</returns>
IEventParserConfiguration Configuration { get; set; }
string Version { get; set; }
}
}

View File

@ -14,5 +14,6 @@ namespace SharedLibraryCore.Interfaces
Task<string[]> ExecuteCommandAsync(Connection connection, string command);
Task<List<EFClient>> GetStatusAsync(Connection connection);
IRConParserConfiguration Configuration { get; set; }
string Version { get; set; }
}
}

View File

@ -435,7 +435,9 @@ namespace SharedLibraryCore.Database.Models
// reserved slots stuff
// todo: bots don't seem to honor party_maxplayers/sv_maxclients
if (CurrentServer.MaxClients - (CurrentServer.GetClientsAsList().Count(_client => !_client.IsPrivileged())) < CurrentServer.ServerConfig.ReservedSlotNumber &&
!this.IsPrivileged())
!this.IsPrivileged() &&
CurrentServer.GetClientsAsList().Count <= CurrentServer.MaxClients &&
CurrentServer.MaxClients != 0)
{
CurrentServer.Logger.WriteDebug($"Kicking {this} their spot is reserved");
Kick(loc["SERVER_KICK_SLOT_IS_RESERVED"], Utilities.IW4MAdminClient(CurrentServer));