protected void doJoin() { ChessService.CurrentGame.updateBoard(); // since board is not initialised until both players are in. var conn = new ConnectionBroadcast(this, Side == PlayerSide.None ? "spectate" : "join"); Broadcast(new ChessPacket(PacketId.ConnectionMade, conn.ToJson())); foreach (var p in CurrentGame.GetPlayers()) { if (p.ID == this.ID) { continue; } var jobj = new JObject(); jobj["id"] = p.Player.Id; jobj["player"] = p?.ToJson() ?? JObject.FromObject(null); Send(new ChessPacket(PacketId.PlayerIdent, jobj)); System.Threading.Thread.Sleep(500); } if (Player.Permission.HasFlag(ChessPerm.Moderator) && Side == PlayerSide.None) { // must be a Mod/Justice AND must be Spectating - not playing System.Threading.Thread.Sleep(500); Send(new ChessPacket(PacketId.NotifyAdmin, new JObject())); } System.Threading.Thread.Sleep(500); Broadcast(new ChessPacket(PacketId.GameStatus, CurrentGame.ToJson((CurrentGame.InnerGame?.move_number ?? 0) > 1))); if (ChessService.CurrentGame.InnerGame == null) { return; // black hasnt joined yet } if (ChessService.CurrentGame.InnerGame.move_number == 1 && ChessService.CurrentGame.InnerGame.turn == OtherGame.WHITE) { // moves havnt been made yet if (ChessService.CurrentGame.White is ChessAIPlayer ai) { // and the ai needs to make their turn if (ChessService.CurrentGame.Black is ChessAIPlayer) { // increase delay since thats an oof. ChessService.CurrentGame.AiDelay = 5000; } System.Threading.Thread.Sleep(500); // delay for packets to be sent ai.MakeAIMove(); } } }