Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Configurable Match Start Timeout #147

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Source/Configuration/PluginConfigSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public bool SETTING_DEBUGShowPlayerList
public bool ForceHighPingMode { get; set; } = false;
public bool RunThroughOnServerStop { get; set; } = true;

public int WaitingTimeBeforeStart { get; private set; }

public int BlackScreenOnDeathTime
{
get
Expand Down Expand Up @@ -155,6 +157,9 @@ public void GetSettings()
ForceHighPingMode = StayInTarkovPlugin.Instance.Config.Bind("Coop", "ForceHighPingMode", false
, new ConfigDescription("Forces the High Ping Mode which allows some actions to not round-trip. This may be useful if you have large input lag")).Value;

WaitingTimeBeforeStart = Config.Bind("Coop", "WaitingTimeBeforeStart", 120
, new ConfigDescription("Time in seconds to wait for players before starting the game automatically")).Value;

SETTING_ShowSITStatistics = StayInTarkovPlugin.Instance.Config.Bind
("Coop", "ShowSITStatistics", true, new ConfigDescription("Enable the SIT statistics on the top left of the screen which shows ping, player count, etc.")).Value;

Expand Down
38 changes: 26 additions & 12 deletions Source/Coop/SITGameModes/CoopSITGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,46 +662,60 @@

// ---------------------------------------------
// Here we can wait for other players, if desired
TimeSpan waitTimeout = TimeSpan.FromSeconds(PluginConfigSettings.Instance.CoopSettings.WaitingTimeBeforeStart);

await Task.Run(async () =>
{
if (coopGameComponent != null)
{
System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); // Start the stopwatch immediately.

while (coopGameComponent.PlayerUsers == null)
{
Logger.LogDebug($"{nameof(vmethod_2)}: {nameof(coopGameComponent.PlayerUsers)} is null");
await Task.Delay(1000);
}

var numbersOfPlayersToWaitFor = SITMatchmaking.HostExpectedNumberOfPlayers - coopGameComponent.PlayerUsers.Count();
do
{
if (coopGameComponent.PlayerUsers == null)

if (coopGameComponent.PlayerUsers == null || coopGameComponent.PlayerUsers.Count() == 0)
{
Logger.LogDebug($"{nameof(vmethod_2)}: {nameof(coopGameComponent.PlayerUsers)} is null");
await Task.Delay(1000);
continue;
}

if (coopGameComponent.PlayerUsers.Count() == 0)
{
Logger.LogDebug($"{nameof(vmethod_2)}: {nameof(coopGameComponent.PlayerUsers)} is empty");
Logger.LogDebug($"{nameof(vmethod_2)}: PlayerUsers is null or empty");
await Task.Delay(1000);
continue;
}

var progress = coopGameComponent.PlayerUsers.Count() / SITMatchmaking.HostExpectedNumberOfPlayers;
numbersOfPlayersToWaitFor = SITMatchmaking.HostExpectedNumberOfPlayers - coopGameComponent.PlayerUsers.Count();
var numbersOfPlayersToWaitFor = SITMatchmaking.HostExpectedNumberOfPlayers - coopGameComponent.PlayerUsers.Count();

if (SITMatchmaking.TimeHasComeScreenController != null)
{
SITMatchmaking.TimeHasComeScreenController.ChangeStatus($"Waiting for {numbersOfPlayersToWaitFor} Player(s)", progress);
}

if (coopGameComponent.PlayerUsers.Count() >= SITMatchmaking.HostExpectedNumberOfPlayers)
{
Logger.LogInfo("Desired number of players reached. Starting the game.");
break;
}

if (stopwatch.Elapsed >= waitTimeout)
{
Logger.LogInfo("Timeout reached. Proceeding with current players.");
break;
}

await Task.Delay(1000);

} while (numbersOfPlayersToWaitFor > 0);
} while (true);

stopwatch.Stop();
}
});



// ---------------------------------------------

CoopPatches.EnableDisablePatches();
Expand Down Expand Up @@ -754,7 +768,7 @@
//return base.vmethod_2(playerId, position, rotation, layerName, prefix, pointOfView, profile, aiControl, updateQueue, armsUpdateMode, bodyUpdateMode, characterControllerMode, getSensitivity, getAimingSensitivity, statisticsManager, questController);
}

public static async void SendPlayerDataToServer(LocalPlayer player)

Check warning on line 771 in Source/Coop/SITGameModes/CoopSITGame.cs

View workflow job for this annotation

GitHub Actions / Build-SIT (Debug)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Logger.LogDebug($"{nameof(SendPlayerDataToServer)}");
var profileJson = player.Profile.SITToJson();
Expand Down
Loading