Skip to content

Commit 4500fbb

Browse files
authored
Added some logging and simplified session over logic (#130)
1 parent 95dfa52 commit 4500fbb

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

AssettoServer/Server/SessionManager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class SessionManager : CriticalBackgroundService
3535
public bool IsOpen => CurrentSession.Configuration.IsOpen switch
3636
{
3737
IsOpenMode.Open => true,
38-
IsOpenMode.CloseAtStart => !CurrentSession.IsStarted,
38+
IsOpenMode.CloseAtStart => !CurrentSession.IsCutoffReached,
3939
_ => false,
4040
};
4141

@@ -286,25 +286,25 @@ private bool IsSessionOver()
286286

287287
if (CurrentSession.Configuration.IsOpen == IsOpenMode.Closed && connectedCount < 2)
288288
{
289+
Log.Information("Skipping race session: didn't reach minimum player count before cutoff ({PlayerCount}/2). Use 'IS_OPEN=1' to allow joining during the race", connectedCount);
289290
return true;
290291
}
291292

292293
if (CurrentSession.Configuration.IsOpen != IsOpenMode.CloseAtStart)
293294
{
294-
return connectedCount == 0;
295+
if (connectedCount > 0) return false;
296+
297+
Log.Information("Skipping race session: no player connected");
298+
return true;
295299
}
296300

297-
switch (CurrentSession.Configuration.Type)
301+
if (connectedCount < 2 && CurrentSession.IsCutoffReached)
298302
{
299-
case SessionType.Race when connectedCount > 0 && Program.IsDebugBuild:
300-
return false;
301-
case SessionType.Race when connectedCount == 0 && Program.IsDebugBuild:
302-
return true;
303-
case SessionType.Race when connectedCount <= 1:
304-
return true;
305-
default:
306-
return false;
303+
Log.Information("Skipping race session: didn't reach minimum player count before cutoff ({PlayerCount}/2). Use 'IS_OPEN=1' to allow joining during the race", connectedCount);
304+
return true;
307305
}
306+
307+
return false;
308308
}
309309

310310
private void CalcOverTime()

AssettoServer/Server/SessionState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SessionState
1616
public uint TargetLap { get; set; } = 0;
1717
public uint LeaderLapCount { get; set; } = 0;
1818
public bool LeaderHasCompletedLastLap { get; set; } = false;
19-
public bool IsStarted { get; set; } = false;
19+
public bool IsCutoffReached => _timeSource.ServerTimeMilliseconds > StartTimeMilliseconds - 20_000;
2020

2121
public bool SessionOverFlag => Configuration switch
2222
{

0 commit comments

Comments
 (0)