void updateRooms() { // check each room thats not the lobby for (int roomIndex = 1; roomIndex < rooms.Count; ++roomIndex) { Room room = rooms[roomIndex]; List <PlayerState> playersInRoom = rooms[roomIndex].players; //if game not going if (room.countdownTimer > 0) { // check if all players are ready bool allReady = true; for (int i = 0; i < playersInRoom.Count; ++i) { if (!playersInRoom[i].ready) { allReady = false; break; } } if (allReady && playersInRoom.Count >= 2) { int btime = (int)(room.countdownTimer + 1); room.countdownTimer -= Time.deltaTime; int ptime = (int)(room.countdownTimer + 1); if (ptime != btime) { if (ptime == 0) { generateAndSendStartPackets(roomIndex); } else { Packet cdPacket = new Packet(PacketType.GAME_COUNTDOWN); cdPacket.Write(ptime); broadcastPacket(cdPacket, roomIndex); } } } else { room.countdownTimer = 5.0f; } continue; } // find number of alive players in this room (also check for winner while your at it) PlayerState winner = null; int numAlive = 0; for (int i = 0; i < playersInRoom.Count; ++i) { if (playersInRoom[i].alive) { ++numAlive; winner = playersInRoom[i]; } } if (numAlive <= 1) // if either of these then game is over { Packet gpacket = new Packet(PacketType.GAME_END); string message = ""; if (numAlive == 0) { message = LobbyUIController.getTextWithColor("It's a Draw!", Color.yellow); } else { message = LobbyUIController.getTextWithColor(winner.name, winner.color) + " Wins!"; } gpacket.Write(message); broadcastPacket(gpacket, roomIndex); for (int i = 0; i < playersInRoom.Count; ++i) { Debug.Log("SERVER: moving " + playersInRoom[i].name + " back to lobby"); movePlayerToRoom(playersInRoom[i], 0); // move them back to lobby } --roomIndex; // a room got removed from room list so do this continue; } // else game still going so send state updates Packet updatePacket = new Packet(PacketType.STATE_UPDATE); updatePacket.Write(numAlive); // send positions of other alive players in room for (int i = 0; i < playersInRoom.Count; ++i) { if (playersInRoom[i].alive) { updatePacket.Write(playersInRoom[i].id); updatePacket.Write(playersInRoom[i].pos); } } // send out packet to all players in room broadcastPacket(updatePacket, roomIndex); } }