2018-09-06 14:25:58 -04:00
|
|
|
|
using IW4MAdmin.Application.API.GameLogServer;
|
|
|
|
|
using RestEase;
|
|
|
|
|
using SharedLibraryCore;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net.Http;
|
2018-10-25 09:14:39 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2018-09-06 14:25:58 -04:00
|
|
|
|
using static SharedLibraryCore.Utilities;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.IO
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// provides capibility of reading log files over HTTP
|
|
|
|
|
/// </summary>
|
|
|
|
|
class GameLogReaderHttp : IGameLogReader
|
|
|
|
|
{
|
|
|
|
|
readonly IEventParser Parser;
|
2018-09-06 14:25:58 -04:00
|
|
|
|
readonly IGameLogServer Api;
|
2019-02-09 16:35:13 -05:00
|
|
|
|
readonly string logPath;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
2019-02-09 16:35:13 -05:00
|
|
|
|
public GameLogReaderHttp(Uri gameLogServerUri, string logPath, IEventParser parser)
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
2019-02-09 16:35:13 -05:00
|
|
|
|
this.logPath = logPath.ToBase64UrlSafeString(); ;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
Parser = parser;
|
2019-02-09 16:35:13 -05:00
|
|
|
|
Api = RestClient.For<IGameLogServer>(gameLogServerUri);
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 14:25:58 -04:00
|
|
|
|
public long Length => -1;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
public int UpdateInterval => 350;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
2018-10-25 09:14:39 -04:00
|
|
|
|
public async Task<ICollection<GameEvent>> ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
2018-08-30 21:53:00 -04:00
|
|
|
|
#if DEBUG == true
|
2018-11-25 21:00:36 -05:00
|
|
|
|
server.Logger.WriteDebug($"Begin reading from http log");
|
2018-08-30 21:53:00 -04:00
|
|
|
|
#endif
|
2018-09-06 14:25:58 -04:00
|
|
|
|
var events = new List<GameEvent>();
|
2019-02-09 16:35:13 -05:00
|
|
|
|
string b64Path = logPath;
|
2018-10-25 09:14:39 -04:00
|
|
|
|
var response = await Api.Log(b64Path);
|
2018-09-06 14:25:58 -04:00
|
|
|
|
|
|
|
|
|
if (!response.Success)
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
2019-02-09 16:35:13 -05:00
|
|
|
|
server.Logger.WriteError($"Could not get log server info of {logPath}/{b64Path} ({server.LogPath})");
|
2018-10-25 09:14:39 -04:00
|
|
|
|
return events;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse each line
|
2018-09-06 14:25:58 -04:00
|
|
|
|
foreach (string eventLine in response.Data.Split(Environment.NewLine))
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
|
|
|
|
if (eventLine.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-08-30 21:53:00 -04:00
|
|
|
|
var e = Parser.GetEvent(server, eventLine);
|
|
|
|
|
#if DEBUG == true
|
|
|
|
|
server.Logger.WriteDebug($"Parsed event with id {e.Id} from http");
|
|
|
|
|
#endif
|
|
|
|
|
events.Add(e);
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2018-10-06 12:47:14 -04:00
|
|
|
|
server.Logger.WriteWarning("Could not properly parse event line");
|
|
|
|
|
server.Logger.WriteDebug(e.Message);
|
|
|
|
|
server.Logger.WriteDebug(eventLine);
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return events;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|