示例#1
0
    private static void OnLobbyChange(object Sender, ValueChangedEventArgs Argument)
    {
        if (!(ConnectionStep != 3.1) && !(Argument.Snapshot.Value != null))
        {
            Debug.Log("Step: 3.2 - Receiving invitation");

            ConnectionStep = 3.2;
            ConnectionStepChange?.Invoke();

            BaseTracking.ValueChanged -= OnLobbyChange;
            BaseTracking = BaseReference.Child("ActiveRoom");
            BaseTracking.ValueChanged += OnActiveRoomChange;
        }
        else if (ConnectionStep != 3.1)
        {
            foreach (KeyValuePair <string, string> Data in MyData)
            {
                BaseTracking.Child(Data.Key).SetValueAsync(Data.Value);
            }

            Debug.Log("Step: 3.1 - Waiting in lobby");

            ConnectionStep = 3.1;
            ConnectionStepChange?.Invoke();
        }
    }
示例#2
0
    private static void OnActiveRoomChange(object Sender, ValueChangedEventArgs Argument)
    {
        string Search(DataSnapshot Snapshot, string Key)
        {
            string Room = "";

            foreach (DataSnapshot Child in Snapshot.Children)
            {
                if (Child.Key != Key)
                {
                    Room = Search(Child, Key);

                    if (Room != "")
                    {
                        break;
                    }
                }
                else
                {
                    Room = Snapshot.Key;

                    break;
                }
            }

            return(Room);
        }

        Debug.Log("Step: 3.3 - Checking room list");

        ConnectionStep = 3.3;
        ConnectionStepChange?.Invoke();

        DataSnapshot ActiveRoom = Argument.Snapshot;

        MyRoom = Search(ActiveRoom, MyName);

        if (MyRoom != "")
        {
            Debug.Log($"Step: 3.4 - {MyRoom}");

            ConnectionStep = 3.4;
            ConnectionStepChange?.Invoke();

            BaseTracking.ValueChanged -= OnActiveRoomChange;
            BaseTracking = BaseReference.Child("ActiveRoom").Child(MyRoom);
            BaseTracking.ValueChanged += OnRoomChange;
        }
    }
示例#3
0
    public static void Check()
    {
        Debug.Log("Step: 0.0 - Checking resources");

        ConnectionStep = 0.0;
        ConnectionStepChange?.Invoke();

        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(Task =>
        {
            if (Task.Result != DependencyStatus.Available)
            {
                return;
            }

            BaseApp = FirebaseApp.DefaultInstance;
            BaseApp.SetEditorDatabaseUrl(Link);

            FirebaseDatabase.DefaultInstance.GetReference(".info/connected").ValueChanged += CheckConnect;

            void CheckConnect(object Sender, ValueChangedEventArgs Argument)
            {
                if (Argument.Snapshot.Value.ToString() != "True")
                {
                    OnConnect = false;
                }
                else
                {
                    OnConnect = true;
                }
            }

            BaseReference = FirebaseDatabase.DefaultInstance.RootReference;

            Debug.Log("Step: 1.0 - Checking done");

            ConnectionStep = 1.0;
            ConnectionStepChange?.Invoke();
        });
    }
示例#4
0
    private static void OnRoomChange(object Sender, ValueChangedEventArgs Argument)
    {
        DataSnapshot Room = Argument.Snapshot;

        if (Room.Children.Any())
        {
            if (ConnectionStep < 4 && ConnectionStep != 3.5)
            {
                Debug.Log("Step: 3.5 - Waiting in room");

                ConnectionStep = 3.5;
                ConnectionStepChange?.Invoke();
            }
            else if (ConnectionStep < 5 && ConnectionStep != 4.3)
            {
                Debug.Log("Step: 4.3 - Waiting in room");

                ConnectionStep = 4.3;
                ConnectionStepChange?.Invoke();
            }

            if (!(ConnectionStep != 5))
            {
                if (Room.Children.Count() < RoomCapacity)
                {
                    Disconnect();
                }
                else
                {
                    Collect(Room);
                }
            }
            else if (!(Room.Children.Count() != RoomCapacity))
            {
                Collect(Room);

                Debug.Log("Step: 5.0 - Ready");

                ConnectionStep = 5.0;
                ConnectionStepChange?.Invoke();
            }
        }
        else
        {
            Debug.Log("Step: 4.1 - Checking lobby");

            ConnectionStep = 4.1;
            ConnectionStepChange?.Invoke();

            BaseReference.Child("Lobby").GetValueAsync().ContinueWith(Task =>
            {
                if (Task.IsFaulted)
                {
                    return;
                }

                DataSnapshot Lobby = Task.Result;

                foreach (KeyValuePair <string, string> Data in MyData)
                {
                    BaseTracking.Child(MyName).Child(Data.Key).SetValueAsync(Data.Value);
                }

                for (int i = 1; i < RoomCapacity; i++)
                {
                    string LastName = Lobby.Children.ElementAt(Lobby.Children.Count() - i).Key;

                    foreach (DataSnapshot Data in Lobby.Child(LastName).Children)
                    {
                        BaseTracking.Child(LastName).Child(Data.Key).SetValueAsync(Data.Value);
                    }

                    Debug.Log($"Step: 4.2 - Inviting {LastName}");

                    ConnectionStep = 4.2;
                    ConnectionStepChange?.Invoke();

                    BaseReference.Child("Lobby").Child(LastName).SetValueAsync(null);
                }
            });
        }
    }
示例#5
0
    public static void Connect()
    {
        Debug.Log("Step: 2.0 - Connecting");

        ConnectionStep = 2.0;
        ConnectionStepChange?.Invoke();

        BaseReference.GetValueAsync().ContinueWith(Task =>
        {
            if (Task.IsFaulted)
            {
                return;
            }

            DataSnapshot ActivePlayer = Task.Result.Child("ActivePlayer");
            DataSnapshot ActiveRoom   = Task.Result.Child("ActivePlayer");
            DataSnapshot Lobby        = Task.Result.Child("Lobby");

            if (!(MyName != ""))
            {
                MyName = GenerateKey(PrettyTextPlayer);

                while (!Free(ActivePlayer, MyName))
                {
                    MyName = GenerateKey(PrettyTextPlayer);
                }

                Debug.Log($"Step: 2.0 - {MyName}");

                foreach (KeyValuePair <string, string> Data in MyData)
                {
                    BaseReference.Child("ActivePlayer").Child(MyName).Child(Data.Key).SetValueAsync(Data.Value);
                }
            }

            if (Lobby.Children.Count() + 1 >= RoomCapacity)
            {
                Debug.Log("Step: 4.0 - Creating room");

                ConnectionStep = 4.0;
                ConnectionStepChange?.Invoke();

                MyRoom = GenerateKey(PrettyTextRoom);

                while (!Free(ActiveRoom, MyRoom))
                {
                    MyRoom = GenerateKey(PrettyTextRoom);
                }

                Debug.Log($"Step: 4.0 - {MyRoom}");

                BaseTracking = BaseReference.Child("ActiveRoom").Child(MyRoom);
                BaseTracking.ValueChanged += OnRoomChange;
            }
            else
            {
                Debug.Log("Step: 3.0 - Joining lobby");

                ConnectionStep = 3.0;
                ConnectionStepChange?.Invoke();

                BaseTracking = BaseReference.Child("Lobby").Child(MyName);
                BaseTracking.ValueChanged += OnLobbyChange;
            }
        });
    }