Compare commits

...

3 Commits

Author SHA1 Message Date
6ce91bbae7 more uniform usage of this 2024-01-17 03:23:49 +01:00
81fbc36b77 More accurate MatchStart Event 2024-01-17 03:22:21 +01:00
b17b2a8067 Fix duplicate round win/loss events 2024-01-17 03:22:12 +01:00
2 changed files with 17 additions and 14 deletions

View File

@ -32,15 +32,18 @@ internal static class CS2EventGenerator
if(newGameState.Round?.Phase == Round.RoundPhase.Over && lastGameState.Round?.Phase == Round.RoundPhase.Live)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundOver, new CS2EventArgs()));
if (newGameState.Map?.Round is not null && newGameState.Map?.Round != previousPlayerState.Map?.Round)
{
if(newGameState.Round?.WinnerTeam is not null && newGameState.Round?.WinnerTeam == previousPlayerState.Player?.Team)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundWin, new CS2EventArgs()));
if(newGameState.Round?.WinnerTeam is not null && newGameState.Round?.WinnerTeam == previousPlayerState.Player?.Team)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundWin, new CS2EventArgs()));
if(newGameState.Round?.WinnerTeam is not null && newGameState.Round?.WinnerTeam != previousPlayerState.Player?.Team)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundLoss, new CS2EventArgs()));
if(newGameState.Round?.WinnerTeam is not null && newGameState.Round?.WinnerTeam != previousPlayerState.Player?.Team)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnRoundLoss, new CS2EventArgs()));
}
}
if(newGameState.Map?.Phase == Map.MapPhase.Live && lastGameState.Map?.Phase != Map.MapPhase.Live)
if(newGameState.Map?.Phase == Map.MapPhase.Live && lastGameState.Map?.Phase == Map.MapPhase.Warmup)
events.Add(new ValueTuple<CS2Event, CS2EventArgs>(CS2Event.OnMatchStart, new CS2EventArgs()));
if(newGameState.Map?.Phase == Map.MapPhase.GameOver && lastGameState.Map?.Phase != Map.MapPhase.GameOver)

View File

@ -19,20 +19,20 @@ internal class GSIServer
{
this.logger = logger;
string prefix = $"http://127.0.0.1:{port}/";
HttpListener = new HttpListener();
HttpListener.Prefixes.Add(prefix);
HttpListener.Start();
this.HttpListener = new HttpListener();
this.HttpListener.Prefixes.Add(prefix);
this.HttpListener.Start();
this.logger?.Log(LogLevel.Information, $"Listening on {prefix}");
Thread connectionListener = new (HandleConnection);
connectionListener.Start();
IsRunning = true;
this.IsRunning = true;
}
private async void HandleConnection()
{
while (_keepRunning)
while (this._keepRunning)
{
HttpListenerContext context = await HttpListener.GetContextAsync();
HttpListenerRequest request = context.Request;
@ -47,15 +47,15 @@ internal class GSIServer
this.logger?.Log(LogLevel.Debug, $"Message Content:\n{content}");
OnMessage?.Invoke(content);
}
HttpListener.Close();
IsRunning = false;
this.HttpListener.Close();
this.IsRunning = false;
this.logger?.Log(LogLevel.Information, "Stopped GSIServer.");
}
internal void Dispose()
{
this.logger?.Log(LogLevel.Information, "Stopping GSIServer.");
_keepRunning = false;
this._keepRunning = false;
}
}