fix a fun little race condition
This commit is contained in:
parent
4f4e23cb8a
commit
ee387ac9cc
2 changed files with 16 additions and 16 deletions
|
@ -152,7 +152,7 @@ public class User
|
|||
this.vm = vm;
|
||||
await this.SendAsync(Guacutils.Encode("connect", "1", "1", vm.Controller.Snapshots ? "1" : "0", "0"));
|
||||
List<string> usermsg = new(new[] { "adduser", vm.Users.Count.ToString() });
|
||||
foreach (User user in vm.Users)
|
||||
foreach (User user in vm.Users.ToArray())
|
||||
{
|
||||
usermsg.Add(user.Username);
|
||||
usermsg.Add(((int)user.Rank).ToString());
|
||||
|
|
|
@ -40,7 +40,7 @@ public class VM
|
|||
private void ControllerOnScreenSize(object? sender, Size e)
|
||||
{
|
||||
// Send the new size to all users
|
||||
foreach (User user in this.Users)
|
||||
foreach (User user in this.Users.ToArray())
|
||||
{
|
||||
if (screenHidden && user.Rank == Rank.Unregistered) continue;
|
||||
user.SendScreenSize(e);
|
||||
|
@ -66,7 +66,7 @@ public class VM
|
|||
var jpeg = ms.GetBuffer();
|
||||
var jpg64 = Convert.ToBase64String(jpeg);
|
||||
// Send the dirty rect to all users
|
||||
foreach (User user in this.Users)
|
||||
foreach (User user in this.Users.ToArray())
|
||||
{
|
||||
if (screenHidden && user.Rank == Rank.Unregistered) continue;
|
||||
user.SendRect(jpg64, e.X, e.Y);
|
||||
|
@ -122,7 +122,7 @@ public class VM
|
|||
};
|
||||
user.Renamed += async (_, e) =>
|
||||
{
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
{
|
||||
await u.SendRename(e, user.Username!, user.Rank);
|
||||
}
|
||||
|
@ -136,15 +136,15 @@ public class VM
|
|||
{
|
||||
this.Vote.ClearVote(user);
|
||||
var status = this.Vote.GetStatus();
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
await u.SendVoteUpdate(status);
|
||||
}
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
{
|
||||
await u.SendDisconnect(user.Username!);
|
||||
}
|
||||
};
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
{
|
||||
await u.SendNewUser(user.Username!, user.Rank);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public class VM
|
|||
public async Task SendChat(User user, string message, bool xss = false, bool excludeAdmins = false)
|
||||
{
|
||||
var messageSanitized = WebUtility.HtmlEncode(message);
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
{
|
||||
if (xss && (u.Rank != Rank.Admin || !excludeAdmins))
|
||||
await u.SendChat(user.Username!, message);
|
||||
|
@ -175,7 +175,7 @@ public class VM
|
|||
|
||||
public async Task ReannounceUser(User user)
|
||||
{
|
||||
foreach (var u in this.Users)
|
||||
foreach (var u in this.Users.ToArray())
|
||||
{
|
||||
await u.SendNewUser(user.Username, user.Rank);
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class VM
|
|||
public async Task SendTurnQueue(TurnStatus? s = null)
|
||||
{
|
||||
TurnStatus status = s ?? this.TurnQueue.CurrentTurn();
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
{
|
||||
u.IPData!.IsTurning = status.Queue.Contains(u);
|
||||
await u.SendTurnUpdate(status);
|
||||
|
@ -200,34 +200,34 @@ public class VM
|
|||
{
|
||||
this.Vote = null;
|
||||
this.VoteCooldown.Run();
|
||||
foreach (var u in Users)
|
||||
foreach (var u in Users.ToArray())
|
||||
{
|
||||
u.IPData!.IsVoting = false;
|
||||
await u.SendAsync(Guacutils.Encode("vote", "2"));
|
||||
}
|
||||
if (e.Result)
|
||||
{
|
||||
foreach (var u in Users)
|
||||
foreach (var u in Users.ToArray())
|
||||
await u.SendChat("", "The vote to reset the VM has won.");
|
||||
await this.Controller.Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var u in Users)
|
||||
foreach (var u in Users.ToArray())
|
||||
await u.SendChat("", "The vote to reset the VM has lost.");
|
||||
}
|
||||
};
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
{
|
||||
await u.SendAsync(Guacutils.Encode("vote", "0"));
|
||||
await u.SendChat("", $"{user.Username} has started a vote to reset the VM.");
|
||||
}
|
||||
} else
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
await u.SendChat("", $"{user.Username} has voted {(vote ? "yes" : "no")}.");
|
||||
this.Vote.Vote(user, vote);
|
||||
var status = this.Vote.GetStatus();
|
||||
foreach (User u in this.Users)
|
||||
foreach (User u in this.Users.ToArray())
|
||||
await u.SendVoteUpdate(status);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue