diff --git a/ZkLobbyServer/ServerBattle.cs b/ZkLobbyServer/ServerBattle.cs index ecd0e1a44..61a9b8a18 100644 --- a/ZkLobbyServer/ServerBattle.cs +++ b/ZkLobbyServer/ServerBattle.cs @@ -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 StartGame() { diff --git a/ZkLobbyServer/autohost/Commands/BattleCommand.cs b/ZkLobbyServer/autohost/Commands/BattleCommand.cs index 749f95194..1e6673b2c 100644 --- a/ZkLobbyServer/autohost/Commands/BattleCommand.cs +++ b/ZkLobbyServer/autohost/Commands/BattleCommand.cs @@ -99,6 +99,8 @@ public bool IsSpectator(ServerBattle battle, string userName, UserBattleStatus u return isSpectator; } + + /// /// Determines the required margin for a majority vote to pass /// @@ -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) { @@ -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;