37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
namespace GmRelay.Shared.Domain;
|
|
|
|
public static class SessionCapacityRules
|
|
{
|
|
public static string DecideJoinStatus(int? maxPlayers, int activeParticipants)
|
|
{
|
|
if (!maxPlayers.HasValue)
|
|
{
|
|
return ParticipantRegistrationStatus.Active;
|
|
}
|
|
|
|
return activeParticipants < maxPlayers.Value
|
|
? ParticipantRegistrationStatus.Active
|
|
: ParticipantRegistrationStatus.Waitlisted;
|
|
}
|
|
|
|
public static bool CanPromoteWaitlistedPlayer(int? maxPlayers, int activeParticipants, int waitlistedParticipants)
|
|
{
|
|
if (waitlistedParticipants <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return !maxPlayers.HasValue || activeParticipants < maxPlayers.Value;
|
|
}
|
|
|
|
public static bool ShouldPromoteAfterParticipantLeaves(
|
|
string removedRegistrationStatus,
|
|
int? maxPlayers,
|
|
int activeParticipantsAfterLeave,
|
|
int waitlistedParticipants)
|
|
{
|
|
return removedRegistrationStatus == ParticipantRegistrationStatus.Active
|
|
&& CanPromoteWaitlistedPlayer(maxPlayers, activeParticipantsAfterLeave, waitlistedParticipants);
|
|
}
|
|
}
|