Exemplo n.º 1
0
        internal void SendImmediate(GSRequest request)
        {
            if (_WebSocketClient != null)
            {
                lock (_WebSocketClient)
                {
                    if (_WebSocketClient != null)
                    {
                        if (!request.Type.Equals(".AuthenticatedConnectRequest"))
                        {
                            if (request.GetString("requestId") == null)
                            {
                                request.AddString("requestId", DateTime.Now.Ticks + "_" + (_gs._requestCounter++));
                            }

                            //if (request.MaxResponseTimeInMillis != _gs.RequestTimeout) {
                            //	request.AddNumber ("timeout", request.MaxResponseTimeInMillis);
                            //}

                            lock (_pendingRequests) {
                                _pendingRequests.Add(request.GetString("requestId"), request);
                            }
                        }

                        String requestJson = request.JSON;

                        _gSPlatform.DebugMsg("SEND:" + requestJson);

                        //Wrap it in a secure request
                        if (_gs.GSPlatform.ApiSecret.Contains(":") && SessionId != null)
                        {
                            GSRequestData secureRequest = new GSRequestData();

                            secureRequest.AddString("json", requestJson);
                            secureRequest.AddString("hmac", _gs.GSPlatform.MakeHmac(requestJson, _gs.GSPlatform.ApiSecret + "-" + SessionId));

                            requestJson = secureRequest.JSON;
                        }

                        if (_gs.GSPlatform.ApiSecret.Contains(":"))
                        {
                            requestJson = Encrypt(requestJson);
                        }

                        if (_gs.TraceMessages)
                        {
                            _gSPlatform.DebugMsg("SOCKET-SEND:" + requestJson);
                        }

                        _WebSocketClient.Send(requestJson);
                    }
                }
            }
        }
        public void NewPasswordLogin()
        {
            DataController.SaveValue("password", password.text);

            Debug.Log(password.text);

            var loginRequest = new AuthenticationRequest();

            GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData();

            data.AddString("password", DataController.GetValue <string>("password"));

            data.AddString("action", "resetPassword");

            data.AddString("token", token.text);

            loginRequest.SetScriptData(data);

            loginRequest.SetUserName(DataController.GetValue <string>("username"));

            loginRequest.SetPassword(password.text);

            loginRequest.Send(response =>
            {
                if (response.Errors.GetString("action").Contains("complete"))
                {
                    Warning.SetActive(true);

                    PopUpMessage.ActivatePopUp(delegate {  }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning5"));

                    UIController.SetActivePanel(UI_Element.Login);
                }

                if (response.Errors.GetString("action").Contains("invalid"))
                {
                    Warning.SetActive(true);

                    PopUpMessage.ActivatePopUp(delegate { }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning4") + LocalisationSystem.GetLocalisedValue("password_error"));

                    UIController.SetActivePanel(UI_Element.ConfirmResetPassword);
                }


                Debug.Log("well done " + response.Errors.JSON.ToString());

                if (!response.HasErrors)
                {
                    Debug.Log("Error reseting password.../n" + response.Errors.JSON.ToString());
                }
            });
        }
    public void CancelHosting()
    {
        if (hosting)
        {
            MatchmakingRequest matchmakingRequest = new MatchmakingRequest();
            matchmakingRequest.SetMatchShortCode("HostedMatch");

            GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
            participantData.AddString("displayName", gameSparksUserID.myDisplayName);
            participantData.AddBoolean("hosting", true);
            matchmakingRequest.SetParticipantData(participantData);
            matchmakingRequest.SetMatchData(participantData);
            matchmakingRequest.SetSkill(0);
            // Cancel host
            hosting = false;
            matchmakingRequest.SetAction("cancel");
            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            // Change button text to represent hosting a game
            var buttonText = hostGameButton.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
            buttonText[0].text          = "Host Game";
            joinGameButton.interactable = true;
            onRefreshGamesButtonClick();
            UnblockMatchmakingButton();
        }
    }
    private void onRefreshGamesButtonClick()
    {
        BlockRefreshInput();
        // Make sure the user isn't currently hosting that way the refresh doesn't remove their hosted lobby/game
        if (!hosting)
        {
            GameSparksUserID gameSparksUserIDScript = GameObject.Find("GameSparksUserID").GetComponent <GameSparksUserID>();
            // Do a matchmaking request
            MatchmakingRequest matchmakingRequest = new MatchmakingRequest();
            matchmakingRequest.SetMatchShortCode("HostedMatch");

            GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
            participantData.AddString("displayName", gameSparksUserIDScript.myDisplayName);
            participantData.AddBoolean("hosting", false);
            matchmakingRequest.SetParticipantData(participantData);
            matchmakingRequest.SetMatchData(participantData);
            matchmakingRequest.SetSkill(0);
            // Store this request incase we get a throttled message
            lastMatchmakingRequest = matchmakingRequest;

            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            FindGameLobbies();
        }
        else
        {
            FindGameLobbies();
        }
    }
    public void OnHostGameButtonClick()
    {
        BlockMatchmakingButton();
        joinGameButton.interactable = false;
        EventSystem.current.SetSelectedGameObject(null);

        gameSparksUserID = GameObject.Find("GameSparksUserID").GetComponent <GameSparksUserID>();

        MatchmakingRequest matchmakingRequest = new MatchmakingRequest();

        matchmakingRequest.SetMatchShortCode("HostedMatch");

        GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
        participantData.AddString("displayName", gameSparksUserID.myDisplayName);
        participantData.AddBoolean("hosting", true);
        matchmakingRequest.SetParticipantData(participantData);
        matchmakingRequest.SetMatchData(participantData);
        matchmakingRequest.SetSkill(0);


        if (!hosting)
        {
            hosting = true;
            // Change button text to represent canceling host
            var buttonText = hostGameButton.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
            buttonText[0].text = "Cancel Host";
        }
        else
        {
            // Cancel host
            hosting = false;
            matchmakingRequest.SetAction("cancel");
            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            // Change button text to represent hosting a game
            var buttonText = hostGameButton.GetComponentsInChildren <TMPro.TextMeshProUGUI>();
            buttonText[0].text          = "Host Game";
            joinGameButton.interactable = true;
            onRefreshGamesButtonClick();
            UnblockMatchmakingButton();
        }

        matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
    }
    public void CheckHosting()
    {
        if (hosting)
        {
            MatchmakingRequest matchmakingRequest = new MatchmakingRequest();
            matchmakingRequest.SetMatchShortCode("HostedMatch");

            GameSparks.Core.GSRequestData participantData = new GameSparks.Core.GSRequestData();
            participantData.AddString("displayName", gameSparksUserID.myDisplayName);
            participantData.AddBoolean("hosting", true);
            matchmakingRequest.SetParticipantData(participantData);
            matchmakingRequest.SetMatchData(participantData);
            matchmakingRequest.SetSkill(0);
            // Store this request incase we get a throttled message
            lastMatchmakingRequest = matchmakingRequest;

            matchmakingRequest.Send(OnMatchmakingSuccess, OnMatchmakingError);
            FindGameLobbies();
        }
        hostingCheckTimer.ResetTimer();
        hostingCheckTimer.StartCountdown();
    }
        public void GetToken()
        {
            DataController.SaveValue("username", username.text);

            var loginRequest = new AuthenticationRequest();

            GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData();

            data.AddString("action", "passwordRecoveryRequest");

            data.AddString("email", email.text);

            loginRequest.SetScriptData(data);

            loginRequest.SetUserName(DataController.GetValue <string>("username"));

            loginRequest.SetPassword("");

            loginRequest.Send(response => {
                if (!response.HasErrors)
                {
                    Warning.SetActive(true);

                    Warning.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false);

                    PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ConfirmResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning1"));
                }
                else
                {
                    Debug.Log("Error authenticating player.../n" + response.Errors.JSON.ToString());

                    Debug.Log(response.Errors.GetString("action"));

                    if (response.Errors.ContainsKey("action"))
                    {
                        Warning.SetActive(true);

                        //Warning.GetComponentsInChildren<Button>()[1].gameObject.SetActive(false);

                        if (response.Errors.GetString("action").Contains("complete"))
                        {
                            Debug.Log("warn1");

                            UIController.SetActivePanel(UI_Element.ConfirmResetPassword);

                            PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ConfirmResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning1"));
                        }
                        else if (response.Errors.GetString("action").Contains("email") || response.Errors.GetString("action").Contains("invalid"))
                        {
                            Debug.Log("warn2");

                            PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning2"));
                        }
                        else
                        {
                            Debug.Log("exception");
                        }
                    }
                }
            });
        }