public bool SubscribeToGame(string gameUID = "") { if (gameUID != "") { this.GameUID = gameUID; } gameDisposble = FirebaseManager.GetInstance().GetClient().Child(AplicationConstants.GAME_LIST).Child(this.GameUID).Child(AplicationConstants.GAME_NODE).Child(AplicationConstants.PUBLIC_GAME_DATA).AsObservable <GameInstance>().Subscribe(Job => { LogManager.Print("found some updates", "FirebaseGameManager"); if (Job.Object != null) { if (Job.EventType == FirebaseEventType.InsertOrUpdate) { LogManager.Print("Game update", "FirebaseGameManager"); MessagingCenter.Send <FirebaseGameManager, GameInstance>(this, AplicationConstants.GAME_UPDATE_MSG, Job.Object); this.gameCache = Job.Object; } else { LogManager.Print("Not UpdateOrInsert", "FirebaseGameManager"); } } else { LogManager.Print("Object null", "FirebaseGameManager"); } }); LogManager.Print("game subscribed.."); return(true); }
public static FirebaseManager GetInstance() { if (instance == null) { instance = new FirebaseManager(); } return(instance); }
public static async Task SendDecision(string GameUID, int playerId, PlayerDecision goingFurtherDecision) { //DecisionToken decision = new DecisionToken(goingFurtherDecision); LogManager.Print("Send decision " + goingFurtherDecision.ToString() + ":> " + goingFurtherDecision, "DecisionManager"); await FirebaseManager.GetInstance().GetClient() .Child(AplicationConstants.GAME_LIST) .Child(GameUID) .Child(AplicationConstants.GAME_NODE) .Child(AplicationConstants.PRIVATE_GAME_DATA) .Child(AplicationConstants.PLAYERS_PRIVATE_NODE) .Child(playerId.ToString()) .Child(AplicationConstants.DECISION_PROPERTIES).PutAsync(goingFurtherDecision); }
public static async Task <bool> SignSelfToGameList(GameMode type, String UserUID) { if (UserUID != string.Empty) { Player player = new Player(string.Empty, "Adventurer", UserUID); try { await FirebaseManager.GetInstance().GetClient().Child(AplicationConstants.USER_LIST).Child(UserUID).Child("user").PatchAsync(player); playerDisposble = FirebaseManager.GetInstance().GetClient().Child(AplicationConstants.USER_LIST).Child(UserUID).AsObservable <Player>().Subscribe(Job => { if (Job.EventType == FirebaseEventType.InsertOrUpdate && !string.IsNullOrEmpty(Job.Object.GameUID)) { if (FirebaseGameManager.Initialize(Job.Object.GameUID).SubscribeToGame()) { LogManager.Print("Game subscribed: " + Job.Object.GameUID, "LobbyManager"); MessagingCenter.Send <LobbyManager>(new LobbyManager(), AplicationConstants.GAME_FOUND_MSG); UnsubscribePlayerAccount(); } else { LogManager.Print("Game subscribe error", "LobbyManager"); } } }); QueueToken token = new QueueToken(UserUID, type.ToString()); await FirebaseManager.GetInstance().GetClient().Child(AplicationConstants.QUEUE).Child(UserUID).PatchAsync(token); return(true); }catch (Firebase.Database.FirebaseException ex) { LogManager.Print("Account subscribe FirebaseException: " + ex, "LobbyManager"); return(false); } catch (System.Exception ex) { LogManager.Print("Account subscribe Exception: " + ex, "LobbyManager"); return(false); } } else { return(false); } }
public async Task <GameInstance> GetGame() { this.gameCache = (await FirebaseManager.GetInstance().GetClient().Child(AplicationConstants.GAME_LIST).Child(GameUID).Child(GameUID).Child(AplicationConstants.GAME_NODE).Child(AplicationConstants.PUBLIC_GAME_DATA).OnceSingleAsync <GameInstance>()); return(gameCache); }