Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RaidMax committed Oct 25, 2022
1 parent 5112d88 commit fe0929d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Application/IW4MServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ await this.SetDvarAsync("sv_sayname", Manager.GetApplicationSettings().Configura
this.MaxClients = maxplayers;
this.FSGame = game.Value;
this.Gametype = gametype;
this.IP = ip.Value == "localhost" ? ServerConfig.IPAddress : ip.Value ?? ServerConfig.IPAddress;
this.IP = ip.Value is "localhost" or "0.0.0.0" ? ServerConfig.IPAddress : ip.Value ?? ServerConfig.IPAddress;
this.GamePassword = gamePassword.Value;
UpdateMap(mapname);

Expand Down
18 changes: 14 additions & 4 deletions Application/Misc/ScriptPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public async Task Initialize(IManager manager, IScriptCommandFactory scriptComma
}
}

_scriptEngine?.Dispose();
_scriptEngine = new Engine(cfg =>
cfg.AddExtensionMethods(typeof(Utilities), typeof(Enumerable), typeof(Queryable),
typeof(ScriptPluginExtensions))
Expand Down Expand Up @@ -247,9 +248,12 @@ public async Task OnEventAsync(GameEvent gameEvent, Server server)
return;
}

var shouldRelease = false;

try
{
await _onProcessing.WaitAsync();
shouldRelease = true;
WrapJavaScriptErrorHandling(() =>
{
_scriptEngine.SetValue("_gameEvent", gameEvent);
Expand All @@ -260,15 +264,15 @@ public async Task OnEventAsync(GameEvent gameEvent, Server server)
}
finally
{
if (_onProcessing.CurrentCount == 0)
if (_onProcessing.CurrentCount == 0 && shouldRelease)
{
_onProcessing.Release(1);
}
}

}

public Task OnLoadAsync(IManager manager)
public Task OnLoadAsync(IManager manager)
{
_logger.LogDebug("OnLoad executing for {Name}", Name);

Expand Down Expand Up @@ -320,11 +324,14 @@ public async Task OnUnloadAsync()

public T ExecuteAction<T>(Delegate action, CancellationToken token, params object[] param)
{
var shouldRelease = false;

try
{
using var forceTimeout = new CancellationTokenSource(5000);
using var combined = CancellationTokenSource.CreateLinkedTokenSource(forceTimeout.Token, token);
_onProcessing.Wait(combined.Token);
shouldRelease = true;

_logger.LogDebug("Executing action for {Name}", Name);

Expand All @@ -343,7 +350,7 @@ public T ExecuteAction<T>(Delegate action, CancellationToken token, params objec
}
finally
{
if (_onProcessing.CurrentCount == 0)
if (_onProcessing.CurrentCount == 0 && shouldRelease)
{
_onProcessing.Release(1);
}
Expand All @@ -352,11 +359,14 @@ public T ExecuteAction<T>(Delegate action, CancellationToken token, params objec

public T WrapDelegate<T>(Delegate act, CancellationToken token, params object[] args)
{
var shouldRelease = false;

try
{
using var forceTimeout = new CancellationTokenSource(5000);
using var combined = CancellationTokenSource.CreateLinkedTokenSource(forceTimeout.Token, token);
_onProcessing.Wait(combined.Token);
shouldRelease = true;

_logger.LogDebug("Wrapping delegate action for {Name}", Name);

Expand All @@ -373,7 +383,7 @@ public T WrapDelegate<T>(Delegate act, CancellationToken token, params object[]
}
finally
{
if (_onProcessing.CurrentCount == 0)
if (_onProcessing.CurrentCount == 0 && shouldRelease)
{
_onProcessing.Release(1);
}
Expand Down

0 comments on commit fe0929d

Please sign in to comment.