join method
Function to join the room
Implementation
Future join(String myName) async {
String? n = ((await ref!.child("gameName").get()).value as String?);
if (n == null) {
return;
}
if (!gameManager.getGame(n).usesLobby ||
gameManager.getGame(n).canPostjoin ||
inLobby ||
players.length <
(gameManager.getGame(n).maxPlayers ?? (players.length + 1))) {
myDataRef = ref!.child("players").child(myName.toString());
myDataRef.set(true);
myDataRef.onDisconnect().remove();
} else {
myDataRef = ref!.child("waitingPlayers").child(myName.toString());
myDataRef.set(true);
myDataRef.onDisconnect().remove();
ref!.child("inLobby").onValue.listen((event) {
if (event.snapshot.value == true) {
myDataRef.remove();
myDataRef = ref!.child("players").child(myName.toString());
myDataRef.set(true);
myDataRef.onDisconnect().remove();
}
});
}
if ((!players.contains(adminId) || adminId == "") && players.isNotEmpty) {
ref!.child("admin").set(players.first);
}
}