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-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
|
|
|
|
|
|
|
|
|
public int UpdateInterval => 1000;
|
|
|
|
|
|
2018-08-30 21:53:00 -04:00
|
|
|
|
public 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
|
|
|
|
|
server.Logger.WriteDebug($"Begin reading {fileSizeDiff} from http log");
|
|
|
|
|
#endif
|
2018-09-06 14:25:58 -04:00
|
|
|
|
var events = new List<GameEvent>();
|
|
|
|
|
string b64Path = server.LogPath.ToBase64UrlSafeString();
|
|
|
|
|
var response = Api.Log(b64Path).Result;
|
|
|
|
|
|
|
|
|
|
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-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)
|
|
|
|
|
{
|
|
|
|
|
Program.ServerManager.GetLogger().WriteWarning("Could not properly parse event line");
|
|
|
|
|
Program.ServerManager.GetLogger().WriteDebug(e.Message);
|
|
|
|
|
Program.ServerManager.GetLogger().WriteDebug(eventLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return events;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|