IW4M-Admin/Application/IO/GameLogReader.cs
RaidMax 99390f1f35 fixed issue with status response erroring when incorrect length
view angle vector parse fail is now a handled exception
change local host check to byte array to make it faster than comparing string
kick command now requires moderator level or higher
tempban now requires administrator level or higher
hopefully fixed negative SPM bug
pipelined the events and consolidated them to run through GameEventHandler
uniform console colors
2018-04-26 01:13:04 -05:00

50 lines
1.5 KiB
C#

using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace IW4MAdmin.Application.IO
{
class GameLogReader
{
IEventParser Parser;
string LogFile;
public GameLogReader(string logFile, IEventParser parser)
{
LogFile = logFile;
Parser = parser;
}
public ICollection<GameEvent> EventsFromLog(Server server, long fileSizeDiff)
{
// allocate the bytes for the new log lines
byte[] fileBytes = new byte[fileSizeDiff];
// open the file as a stream
using (var rd = new BinaryReader(new FileStream(LogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Utilities.EncodingType))
{
rd.BaseStream.Seek(rd.BaseStream.Length - fileSizeDiff - 1, SeekOrigin.Begin);
// the difference should be in the range of a int :P
rd.Read(fileBytes, 0, (int)fileSizeDiff);
}
// convert to event line list
string[] logLines = Utilities.EncodingType.GetString(fileBytes).Replace("\r", "").Split('\n');
List<GameEvent> events = new List<GameEvent>();
// parse each line
foreach (string eventLine in logLines)
{
if (eventLine.Length > 0)
events.Add(Parser.GetEvent(server, eventLine));
}
return events;
}
}
}