Exemplo n.º 1
0
    public static void MatchNotFoundListener()
    {
        MatchNotFoundMessage.Listener = (message) =>
        {
            Debug.Log("Couldn't find Match!");
            ShowToast.MyShowToastMethod("Couldn't Find Match");
            if (!MainMenu.friendList_canvas.GetComponent <CanvasGroup>().interactable)
            {
                MainMenu.friendList_canvas.GetComponent <CanvasGroup>().interactable = true;
            }
            if (MainMenu.challengeResponse_canvas.enabled)
            {
                MainMenu.challengeResponse_canvas.enabled = false;
            }
            MainMenu.searchingForPlayer_canvas.enabled = false;
            MainMenu.searchingForPlayer_anim.SetActive(false);
            MainMenu.searchingForPlayerTimeRemaining_text.enabled = false;
            MainMenu.isSearchingForPlayer   = false;
            MainMenu.timeLeftToSearchPlayer = 60.0f;

            if (!LoginWithFB.FacebookLoggedIn)
            {
                MainMenu.messageBox_text.text      = "Couldn't Find Match!";
                MainMenu.messageBox_canvas.enabled = true;
                MainMenu.disableMessageBox         = true;
            }
        };
    }
Exemplo n.º 2
0
    private void CheckIfUserisAlreadyLoggedIn()
    {
        if (Application.internetReachability != NetworkReachability.NotReachable)
        {
            //internet reachable
            if (Database.GetLoginStatus() == GameConstants.LOGGED_IN_WITH_GAMESPARK)
            {
                new AuthenticationRequest().SetUserName(Database.GetUserName()).SetPassword(Database.GetPassword()).Send((response) =>
                {
                    Register.userId = response.UserId;
                    if (!response.HasErrors)
                    {
                        Debug.Log("Player Authenticated...");
                        Database.LoadPlayerDataFromGameSpark();

                        //change scene
                        SceneManager.LoadScene(GameConstants.STARTMENU_SCENE);
                        ShowToast.MyShowToastMethod("Player Logged In!");
                    }
                    else
                    {
                        Debug.Log("Error Logging in Player!");
                        ShowToast.MyShowToastMethod("Error Logging in Player!");
                        SceneManager.LoadScene(GameConstants.REGISTER_SCENE);
                    }
                });
            }
            else if (Database.GetLoginStatus() == GameConstants.LOGGED_IN_WITH_FB)
            {
                if (!FB.IsInitialized)
                {
                    Debug.Log("Initializing Facebook...");
                    FB.Init(ConnectGameSparksToGameSparks, null);
                }
                else
                {
                    FB.ActivateApp();
                    ConnectGameSparksToGameSparks();
                }
            }
            else
            {
                StartCoroutine(ChangeScene(GameConstants.REGISTER_SCENE));
            }
        }
        else
        {
            // internet not reachable
            Debug.Log("Internet Not Reachable");
            ShowToast.MyShowToastMethod("Internet Not Reachable!");
            StartCoroutine(ChangeScene(GameConstants.REGISTER_SCENE));
        }
    }
Exemplo n.º 3
0
    private void ResetPasswordCanvasContinueBtn()
    {
        if (Register.isSoundPlaying)
        {
            audioSource.Play();
        }
        string token       = resetPasswordCanvas_token.text;
        string newPassword = resetPasswordCanvas_newPassword.text;

        if (token == "")
        {
            ShowToast.MyShowToastMethod("Please Enter Token!");
            return;
        }
        if (newPassword == "")
        {
            ShowToast.MyShowToastMethod("Please Enter New Password!");
            return;
        }
        GSRequestData gSRequestData = new GSRequestData();

        gSRequestData.AddString("action", "resetPassword");
        gSRequestData.AddString("token", token);
        gSRequestData.AddString("password", newPassword);
        new GameSparks.Api.Requests.AuthenticationRequest().SetUserName("").SetPassword("").SetScriptData(gSRequestData).Send((response) =>
        {
            Register.userId = response.UserId;

            if (response.Errors.GetString("action") == "complete")
            {
                ShowToast.MyShowToastMethod("Password Changed Successfully");
                Debug.Log("Password Changed Successfully");
                forgetPassword_canvas.enabled = false;
                resetPassword_canvas.enabled  = false;
                createOne_btn.enabled         = true;
                login_btn.interactable        = true;
                playAsGuest_btn.interactable  = true;
            }
            else
            {
                ShowToast.MyShowToastMethod("Error Resetting Password!");
                Debug.Log(response.Errors.GetString("action"));
                forgetPassword_canvas.enabled = false;
                login_btn.interactable        = true;
                createOne_btn.interactable    = true;
                playAsGuest_btn.interactable  = true;
            }
        });
    }
Exemplo n.º 4
0
    private void LoginUser()
    {
        if (Register.isSoundPlaying)
        {
            audioSource.Play();
        }
        StartMenu.playAsGuest = false;
        string _username = USERNAME.text;
        string _password = PASSWORD.text;

        if (_username == "")
        {
            ShowToast.MyShowToastMethod("Enter you Username!");
            return;
        }
        if (_password == "")
        {
            ShowToast.MyShowToastMethod("Enter you Password!");
            return;
        }

        login_btn.interactable = false;
        Debug.Log("Authorizing Player.....");
        new GameSparks.Api.Requests.AuthenticationRequest().SetUserName(_username).SetPassword(_password).Send((response) =>
        {
            Register.userId = response.UserId;
            if (!response.HasErrors)
            {
                Debug.Log("Player Authenticated...");
                Database.LoadPlayerDataFromGameSpark();

                //change scene
                SceneManager.LoadScene(GameConstants.STARTMENU_SCENE);
                ShowToast.MyShowToastMethod("Player Logged In!");
                login_btn.interactable = true;
            }
            else
            {
                Debug.Log("Error Authenticating Player...");
                ShowToast.MyShowToastMethod("Error in Authentication!");
                login_btn.interactable = true;
            }
        });
    }
Exemplo n.º 5
0
 public static void MatchFoundListener()
 {
     MatchFoundMessage.Listener = (message) =>
     {
         if (LoginWithFB.FacebookLoggedIn)
         {
             isOppnentsImageID_received = false;
             messageToSend = LoginWithFB.url;
         }
         ShowToast.MyShowToastMethod("Match Made:");
         GSEnumerable <MatchFoundMessage._Participant> participants = message.Participants;
         foreach (MatchFoundMessage._Participant i in participants)
         {
             playerNames[count] = i.DisplayName;
             playerIDs[count]   = i.Id;
             count++;
         }
     };
 }
Exemplo n.º 6
0
    private void ForgetPasswordContinueBtn()
    {
        if (Register.isSoundPlaying)
        {
            audioSource.Play();
        }

        string userName = forgetPasswordUserName.text;
        string email    = forgetPasswordEmail.text;

        if (userName == "")
        {
            ShowToast.MyShowToastMethod("Please Enter User Name!");
            return;
        }
        if (email == "")
        {
            ShowToast.MyShowToastMethod("Please Enter Email Address!");
            return;
        }
        GSRequestData gSRequestData = new GSRequestData();

        gSRequestData.AddString("action", "passwordRecoveryRequest");
        gSRequestData.AddString("email", email);
        new GameSparks.Api.Requests.AuthenticationRequest().SetUserName(userName).SetPassword("").SetScriptData(gSRequestData).Send((response) =>
        {
            Register.userId = response.UserId;

            if (response.Errors.GetString("action") == "complete")
            {
                ShowToast.MyShowToastMethod("Request Sent! Check You Email");
                Debug.Log("Request Sent! Check You Email");
                forgetPassword.enabled       = false;
                resetPassword_canvas.enabled = true;
            }
            else
            {
                ShowToast.MyShowToastMethod("Error Sending Requset!");
                Debug.Log("Error Sending Requset! " + response.Errors.GetString("action"));
            }
        });
    }
    private void Update()
    {
        if (gameRunning)
        {
            StartGame();
        }
        //if (startTimer)
        //{
        //    ChangeTurnIfTimeExceeds();
        //}
        //if (ActivateTurnTakenListener)
        //{
        //    ActivateTurnTakenListener = false;
        //    StartCoroutine(TurnTakenListenerDelay());
        //}

        if (!internetCheck && GameInitializer.GameType == GameConstants.ONLINE_MULTIPLAYER)
        {
            internetCheck = true;
            StartCoroutine(OnlineMultiplayer.checkInternetConnection((isConnected) =>
            {
                // handle connection status here
                if (isConnected)
                {
                    isNetworkAvaiable = true;
                    internetCheck     = false;
                }
                else
                {
                    ShowToast.MyShowToastMethod("Netowrk Error!");
                    isNetworkAvaiable = false;
                    internetCheck     = false;
                }
            }));
        }
    }
Exemplo n.º 8
0
 private void ConnectGameSparksToGameSparks()
 {
     if (FB.IsInitialized)
     {
         FB.ActivateApp();
         Debug.Log("Logging Into Facebook...");
         var perms = new List <string>()
         {
             "public_profile", "email", "user_friends"
         };
         FB.LogInWithReadPermissions(perms, (result) =>
         {
             if (FB.IsLoggedIn)
             {
                 Debug.Log("Logged In, Connecting GS via FB..");
                 new GameSparks.Api.Requests.FacebookConnectRequest()
                 .SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
                 .SetSyncDisplayName(true)
                 .SetDoNotLinkToCurrentPlayer(true)      // we don't want to create a new account so link to the player that is currently logged in
                 .SetSwitchIfPossible(true)              //this will switch to the player with this FB account id they already have an account from a separate login
                 .Send((fbauth_response) =>
                 {
                     if (!fbauth_response.HasErrors)
                     {
                         new AccountDetailsRequest().Send((response) =>
                         {
                             LoginWithFB.fb_id = response.ExternalIds.GetString("FB");
                             LoginWithFB.id    = response.UserId;
                             Debug.Log("Ludo Challenge Authenticated With Facebook!");
                             ShowToast.MyShowToastMethod("Ludo Challenge Authenticated With FB!");
                             LoginWithFB.FacebookLoggedIn = true;
                             LoginWithFB.displayName_FB   = fbauth_response.DisplayName;
                             LoginWithFB.countryName      = Register.countryName.text;
                             LoginWithFB.url = "http://graph.facebook.com/" + LoginWithFB.fb_id + "/picture?width=100&height=100";
                             StartCoroutine(DownloadFBImage(LoginWithFB.url));
                             Database.SetLoginStatus(GameConstants.LOGGED_IN_WITH_FB);
                             Register.userId = LoginWithFB.id;
                         });
                     }
                     else
                     {
                         Debug.LogWarning(fbauth_response.Errors.JSON); //if we have errors, print them out
                     }
                 });
             }
             else
             {
                 Debug.LogWarning("Facebook Login Failed:" + result.Error);
                 ShowToast.MyShowToastMethod("Facebook Login Failed!");
                 LoginWithFB.FacebookLoggedIn = false;
                 SceneManager.LoadScene(GameConstants.REGISTER_SCENE);
             }
         });// lastly call another method to login, and when logged in we have a callback
     }
     else
     {
         if (!FB.IsInitialized)
         {
             Debug.Log("Initializing Facebook...");
             FB.Init(ConnectGameSparksToGameSparks, null);
         }
         else
         {
             FB.ActivateApp();
             ConnectGameSparksToGameSparks();
         }
     }
 }
Exemplo n.º 9
0
    public static void ChatOnChallegeListener()
    {
        ChallengeChatMessage.Listener = (message) =>
        {
            chat_message = "";
            if (message.Message.Contains("////"))
            {
                int j = 0;
                for (int i = 0; i < message.Message.Length; i++)
                {
                    if (message.Message[i] == ' ' && message.Message[i + 1] == ' ' && message.Message[i + 2] == ' ')
                    {
                        j = i + 3;
                        for (int k = j; k < message.Message.Length; k++)
                        {
                            chat_message = chat_message + message.Message[k];
                        }
                        break;
                    }
                }

                if (chat_message == "EndGame")
                {
                    if (GameInitializer.NoOfPlayers == GameConstants.TWO_PLAYERS)
                    {
                        if (GameInitializer.messageToSend != "EndGame")
                        {
                            GameInitializer.SetValues_YouWin();
                            Debug.Log("You Oppenent Left The Game!");
                            ShowToast.MyShowToastMethod("Your opponent left the Game!");
                        }
                    }
                    else
                    {
                        GameObject game_manager = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER);



                        if (message.Message.Contains(GameInitializer.Player2Name.text))
                        {
                            Debug.Log(GameInitializer.Player2Name.text + " left the Game!");
                            ShowToast.MyShowToastMethod(GameInitializer.Player2Name.text + " left the Game!");
                            game_manager.GetComponent <GameInitializer>().player[1].SetActive(false);
                            GameInitializer.player2_out = true;
                        }
                        else if (message.Message.Contains(GameInitializer.Player3Name.text))
                        {
                            Debug.Log(GameInitializer.Player3Name.text + " left the Game!");
                            ShowToast.MyShowToastMethod(GameInitializer.Player3Name.text + " left the Game!");
                            game_manager.GetComponent <GameInitializer>().player[2].SetActive(false);
                            GameInitializer.player3_out = true;
                        }
                        else if (message.Message.Contains(GameInitializer.Player4Name.text))
                        {
                            Debug.Log(GameInitializer.Player4Name.text + " left the Game!");
                            ShowToast.MyShowToastMethod(GameInitializer.Player4Name.text + " left the Game!");
                            game_manager.GetComponent <GameInitializer>().player[3].SetActive(false);
                            GameInitializer.player4_out = true;
                        }
                    }
                }

                for (int i = 0; i < opponents_name.Count; i++)
                {
                    if (message.Message.Contains(opponents_name[i]))
                    {
                        if (GameInitializer.Player2Name.text == opponents_name[i])
                        {
                            GameInitializer.player2Message = true;
                        }
                        else if (GameInitializer.Player3Name.text == opponents_name[i])
                        {
                            GameInitializer.player3Message = true;
                        }
                        else if (GameInitializer.Player4Name.text == opponents_name[i])
                        {
                            GameInitializer.player4Message = true;
                        }
                    }
                }
                return;
            }

            counter++;
            string name = "", id = "";
            bool   nameChecked = false;
            for (int i = 0; i < message.Message.Length; i++)
            {
                if (message.Message[i] != '/' && !nameChecked)
                {
                    name = name + message.Message[i];
                }
                if (nameChecked)
                {
                    id = id + message.Message[i];
                }
                if (message.Message[i] == '/')
                {
                    nameChecked = true;
                }
            }
            Debug.Log(message.Message);
            if (LoginWithFB.FacebookLoggedIn)
            {
                nameChecked = false;
                if (name != LoginWithFB.displayName_FB)
                {
                    Debug.Log("Oppenent Name: " + name);
                    Debug.Log("Oppenent ID: " + id);
                    opponents_name.Add(name);
                    opponents_image_ids.Add(id);
                }
            }
            else
            {
                nameChecked = false;
                opponents_name.Add(name);
                opponents_image_ids.Add(id);
            }

            if (GameInitializer.NoOfPlayers == 2 && counter >= 2)
            {
                isOppnentsImageID_received = true;
                if (LoginWithFB.FacebookLoggedIn)
                {
                    try
                    {
                        if (MainMenu.challengeResponse_canvas.enabled)
                        {
                            MainMenu.challengeResponse_canvas.enabled = false;
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                    }
                }
                else
                {
                    //MainMenu.searchingForPlayer_canvas.enabled = false;
                    //MainMenu.searchingForPlayer_anim.SetActive(false);
                }
                //SceneManager.LoadScene("GamePlay");
                StartMenu.startGame = true;
            }
            else if (GameInitializer.NoOfPlayers == 4 && counter >= 4)
            {
                //Start Game
                isOppnentsImageID_received = true;
                //MainMenu.searchingForPlayer_canvas.enabled = false;
                //MainMenu.searchingForPlayer_anim.SetActive(false);
                //SceneManager.LoadScene("GamePlay");
                StartMenu.startGame = true;
            }
        };
    }
Exemplo n.º 10
0
    private void RegisterUser()
    {
        if (isSoundPlaying)
        {
            buttonAudioSource.Play();
        }
        StartMenu.playAsGuest = false;
        string _name        = NAME.text;
        string _email       = EMAIL.text;
        string _username    = USERNAME.text;
        string _password    = PASSWORD.text;
        string _countryName = countryName.text;

        if (_name == "")
        {
            ShowToast.MyShowToastMethod("Enter you Name!");
            return;
        }
        if (_email == "")
        {
            ShowToast.MyShowToastMethod("Enter you Email!");
            return;
        }
        if (_username == "")
        {
            ShowToast.MyShowToastMethod("Enter you Username!");
            return;
        }
        if (_password == "")
        {
            ShowToast.MyShowToastMethod("Enter you Password!");
            return;
        }

        Debug.Log("Registering User...");
        register_btn.interactable = false;
        GSRequestData gSRequestData = new GSRequestData();

        gSRequestData.Add("email", _email);
        new RegistrationRequest().SetDisplayName(_name).SetUserName(_username).SetPassword(_password).SetScriptData(gSRequestData).Send((response) =>
        {
            if (!response.HasErrors)
            {
                Debug.Log("Player Registered");

                ShowToast.MyShowToastMethod("Player registered successfully!");

                userId = response.UserId;
                Database.setPlayerDataInGameSpark(_name, _countryName, "null");
                Database.setPlayerDataInLocalDatabase(_name, _countryName, 5000, userId);
                Database.setAllWinsAndLosesToZero(userId);
                //change scene
                SceneManager.LoadScene(GameConstants.STARTMENU_SCENE);
                register_btn.interactable = true;
                Database.SetLoginStatus(GameConstants.LOGGED_IN_WITH_GAMESPARK);
                Database.SetUserName(_username);
                Database.SetPassword(_password);
                Database.SetDisplayName(_name);
            }
            else if (response.Errors.GetString("ERROR") == "Email in use!")
            {
                ShowToast.MyShowToastMethod("Email already in use!");
                Debug.Log("Email already in use!");
                register_btn.interactable = true;
            }
            else
            {
                Debug.Log("Error Registering Player");
                ShowToast.MyShowToastMethod("Error Registering Player!");
                register_btn.interactable = true;
                Debug.Log(response.Errors.GetString("ERROR"));
            }
        });
    }
Exemplo n.º 11
0
    public static void ChallengeTurnTakenListener()
    {
        ChallengeTurnTakenMessage.Listener = (message) => {
            Debug.Log(message.Who + " has taken his turn!");
            GameInitializer.fillAmount = 0.92f;
            ChallengeTurnTakenMessage._Challenge challenge_data = message.Challenge;
            playerTurn_UserId = challenge_data.NextPlayer;
            GameObject game_Manager = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER);
            if ((GameInitializer.GameType == GameConstants.ONLINE_MULTIPLAYER && GameInitializer.NoOfPlayers == GameConstants.FOUR_PLAYERS && GameController.playerTurn == 0))
            {
                GameController.playerTurn = game_Manager.GetComponent <PlayerActivation>().ChangePlayer(GameController.playerTurn);
                game_Manager.GetComponent <GameController>().dice = GameObject.FindGameObjectWithTag(GameConstants.PLAYER_DICE[GameController.playerTurn]);
                game_Manager.GetComponent <GameController>().checkLoop_AI_Dice   = false;
                game_Manager.GetComponent <GameController>().checkLoop_AI_Marker = false;
                GameController.checkChangeTurn = false;
                GameController.GAME_STATE      = GameConstants.DICE_ROLL;
            }
            who = message.Who;
            Debug.Log(who + " has taken his turn!");

            if (who != MakeAMatch.displayName)
            {
                GSData scriptData = message.Challenge.ScriptData.GetGSData("data");
                int    diceValue  = (int)scriptData.GetInt("d");
                points = (int)scriptData.GetInt("p");
                GameInitializer.points = points;

                //set points
                GameObject game_manager = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER);

                //Exit turn of leaving player
                if (GameInitializer.NoOfPlayers == 2 && points == 0)
                {
                    GameInitializer.SetValues_YouWin();
                    Debug.Log("You Oppenent Left The Game!");
                    ShowToast.MyShowToastMethod("Your opponent left the Game!");
                }
                if (points == 0)
                {
                    game_manager.GetComponent <GameInitializer>().ChangeTurn(0);
                }

                if (who == GameInitializer.Player2Name.text)
                {
                    game_manager.GetComponent <GameInitializer>().player2Points_text.text = "" + points;
                    if (points == 0)
                    {
                        game_manager.GetComponent <GameInitializer>().player[1].SetActive(false);
                        GameInitializer.player2_out = true;
                    }
                }
                else if (who == GameInitializer.Player3Name.text)
                {
                    game_manager.GetComponent <GameInitializer>().player3Points_text.text = "" + points;
                    if (points == 0)
                    {
                        game_manager.GetComponent <GameInitializer>().player[2].SetActive(false);
                        GameInitializer.player3_out = true;
                    }
                }
                else if (who == GameInitializer.Player4Name.text)
                {
                    game_manager.GetComponent <GameInitializer>().player4Points_text.text = "" + points;
                    if (points == 0)
                    {
                        game_manager.GetComponent <GameInitializer>().player[3].SetActive(false);
                        GameInitializer.player4_out = true;
                    }
                }

                if (diceValue == -1)
                {
                    GameObject gameController = GameObject.FindGameObjectWithTag(GameConstants.GAME_MANAGER);
                    gameController.GetComponent <GameInitializer>().ChangeTurn(1);
                }
                else
                {
                    markerNo_list.Add((int)scriptData.GetInt("m"));
                    dice_value_list.Add((int)scriptData.GetInt("d"));

                    Debug.Log("Counter: " + counter);
                    if (counter == 0)
                    {
                        MoveOpponent(markerNo_list[counter], dice_value_list[counter]);
                    }
                }
            }
        };
    }