Skip to content
Open
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
16 changes: 16 additions & 0 deletions ZkLobbyServer/ServerBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,22 @@ public async Task Spectate(string name)
if (server.ConnectedUsers.TryGetValue(name, out usr)) await usr.Process(new UpdateUserBattleStatus() { Name = usr.Name, IsSpectator = true });
}

public bool IsInWaitlist(string username)
{

if (!TimeQueueEnabled) return false;
var context = GetContext();
int allowedPlayers = MaxPlayers;
if (context.Players.Where(x => !x.IsSpectator).Count() <= MaxEvenPlayers)
{
allowedPlayers = context.Players.Where(x => !x.IsSpectator).Count() & ~0x1;
}
var waitlist = context.Players.Where(x => !x.IsSpectator).OrderBy(x => x.QueueOrder).Skip(allowedPlayers).ToList();
var isInWaitlist = waitlist.Exists(x => x.Name == username);
return isInWaitlist;

}


public async Task<bool> StartGame()
{
Expand Down
6 changes: 5 additions & 1 deletion ZkLobbyServer/autohost/Commands/BattleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public bool IsSpectator(ServerBattle battle, string userName, UserBattleStatus u
return isSpectator;
}



/// <summary>
/// Determines the required margin for a majority vote to pass
/// </summary>
Expand Down Expand Up @@ -145,6 +147,7 @@ public virtual RunPermission GetRunPermissions(ServerBattle battle, string userN
var s = battle.spring;
bool isSpectator = IsSpectator(battle, userName, ubs);
bool isAway = user?.IsAway == true;
bool isInWaitlist = battle.IsInWaitlist(userName);
int count = 0;
if (s.IsRunning)
{
Expand Down Expand Up @@ -175,13 +178,14 @@ public virtual RunPermission GetRunPermissions(ServerBattle battle, string userN
return RunPermission.None;
}

var defPerm = hasElevatedRights ? RunPermission.Run : (isSpectator || isAway || user?.BanVotes == true ? RunPermission.None : RunPermission.Vote);
var defPerm = hasElevatedRights ? RunPermission.Run : (isInWaitlist || isSpectator || isAway || user?.BanVotes == true ? RunPermission.None : RunPermission.Vote);

if (defPerm == RunPermission.None)
{
reason = "This command can't be executed by spectators. Join the game to use this command.";
if (isAway) reason = "You can't vote while being AFK.";
if (user?.BanVotes == true) reason = "You have been banned from using votes. Check your user page for details.";
if (isInWaitlist) reason = "You can't vote if you are in the waitlist.";
return RunPermission.None;
}
if (defPerm == RunPermission.Vote && count<=1) defPerm = RunPermission.Run;
Expand Down