mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-07-04 19:08:55 -05:00
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
This commit is contained in:
72
Application/IO/GameLogEvent.cs
Normal file
72
Application/IO/GameLogEvent.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IW4MAdmin.Application.IO
|
||||
{
|
||||
class GameLogEvent
|
||||
{
|
||||
FileSystemWatcher LogPathWatcher;
|
||||
Server Server;
|
||||
long PreviousFileSize;
|
||||
GameLogReader Reader;
|
||||
Timer RefreshInfoTimer;
|
||||
string GameLogFile;
|
||||
FileInfo Info;
|
||||
|
||||
public GameLogEvent(Server server, string gameLogPath, string gameLogName)
|
||||
{
|
||||
GameLogFile = gameLogPath;
|
||||
Reader = new GameLogReader(gameLogPath, server.EventParser);
|
||||
Server = server;
|
||||
RefreshInfoTimer = new Timer((sender) =>
|
||||
{
|
||||
var newInfo = new FileInfo(GameLogFile);
|
||||
if (newInfo.Length - Info?.Length > 0)
|
||||
LogPathWatcher_Changed(this, new FileSystemEventArgs(WatcherChangeTypes.Changed, "", ""));
|
||||
Info = newInfo;
|
||||
|
||||
}, null, 0, 100);
|
||||
LogPathWatcher = new FileSystemWatcher()
|
||||
{
|
||||
Path = gameLogPath.Replace(gameLogName, ""),
|
||||
Filter = gameLogName,
|
||||
NotifyFilter = (NotifyFilters)383,
|
||||
InternalBufferSize = 4096
|
||||
};
|
||||
|
||||
LogPathWatcher.Changed += LogPathWatcher_Changed;
|
||||
LogPathWatcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
~GameLogEvent()
|
||||
{
|
||||
LogPathWatcher.EnableRaisingEvents = false;
|
||||
}
|
||||
|
||||
private void LogPathWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
// retrieve the new file size
|
||||
long newFileSize = new FileInfo(GameLogFile).Length;
|
||||
|
||||
if (PreviousFileSize == 0)
|
||||
PreviousFileSize = newFileSize;
|
||||
|
||||
long fileDiff = newFileSize - PreviousFileSize;
|
||||
|
||||
if (fileDiff < 1)
|
||||
return;
|
||||
|
||||
var events = Reader.EventsFromLog(Server, fileDiff);
|
||||
foreach (var ev in events)
|
||||
Server.Manager.GetEventHandler().AddEvent(ev);
|
||||
|
||||
PreviousFileSize = newFileSize;
|
||||
}
|
||||
}
|
||||
}
|
49
Application/IO/GameLogReader.cs
Normal file
49
Application/IO/GameLogReader.cs
Normal file
@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user