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;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
readonly string LogFile;
|
|
|
|
|
|
|
|
|
|
public GameLogReaderHttp(string logFile, IEventParser parser)
|
|
|
|
|
{
|
|
|
|
|
LogFile = logFile;
|
|
|
|
|
Parser = parser;
|
2018-09-06 14:25:58 -04:00
|
|
|
|
Api = RestClient.For<IGameLogServer>(logFile);
|
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>();
|
|
|
|
|
string b64Path = server.LogPath.ToBase64UrlSafeString();
|
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
|
|
|
|
{
|
2018-09-06 14:25:58 -04:00
|
|
|
|
server.Logger.WriteError($"Could not get log server info of {LogFile}/{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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|