void OnClickAuth()
    {
        if (string.IsNullOrWhiteSpace(inputFieldID.text))
        {
            Debug.Log("ID field is empty!!!! ");
        }
        else if (inputFieldID.text.Length < 4)
        {
            Debug.Log("Please enter at least 4 digits.");
        }
        else
        {
            PlayerPrefs.SetString(Constants.KEY_USER_ID, inputFieldID.text);
            PlayerPrefs.SetString(Constants.KEY_UUID, inputFieldUUID.text);

            // 다중 클릭 막음
            buttonAuth.interactable = false;

            // 인증에 필요한 프로토콜 데이터 설정
            var authenticationReq = new Com.Nhn.Gameanvil.Sample.Protocol.AuthenticationReq
            {
                AccessToken = Constants.AUTH_ACCESS_TOKEN
            };
            Debug.Log("authenticationReq " + authenticationReq);

            // ===========================================================================================>>> GameAnvil
            // 서버에 인증 시도. 현재는 deviceid, id, pw 모두 uuid값으로 전달
            ConnectHandler.Instance.GetConnectionAgent().Authenticate(inputFieldUUID.text, inputFieldID.text, inputFieldID.text, new Payload().Add(new Packet(authenticationReq)),
                                                                      (ConnectionAgent connectionAgent, ResultCodeAuth result, List <ConnectionAgent.LoginedUserInfo> loginedUserInfoList, string message, Payload payload) =>
            {
                Debug.Log("Auth " + result);

                // 성공인 경우 다음 단계로 진행.
                if (result == ResultCodeAuth.AUTH_SUCCESS)
                {
                    // 성공시 입력 UI 처리
                    buttonAuth.gameObject.SetActive(false);
                    buttonLogin.gameObject.SetActive(true);
                    inputFieldID.enabled = false;
                }
                else
                {
                    // 실패시 처리
                }
                buttonAuth.interactable = true;
            }
                                                                      );
            // ===========================================================================================>>> GameAnvil
        }
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        // 기본값 지정
//        textUUID.text = PlayerPrefs.GetString(Constants.KEY_UUID);
        textUUID.text = "123456789999";
        if (string.IsNullOrWhiteSpace(textUUID.text))
        {
            OnClickGenerateUUID();
        }
        textGamebaseUserId.text = GamebaseInfo.Instance.GamebaseUserId;
        textGameServerIp.text   = GamebaseInfo.Instance.GameServerIp;
        textGameServerPort.text = GamebaseInfo.Instance.GameServerPort;

        // 버튼 클릭에 대한 리스너등록
        buttonLogin.onClick.AddListener(() => { OnClickLogin(); });
        buttonGenerateUUID.onClick.AddListener(() => { OnClickGenerateUUID(); });

        // ===========================================================================================>>> GameAnvil
        // 연결 끊기는 부분 처리 리스너 등록
        ConnectHandler.Instance.GetConnectionAgent().onDisconnectListeners += (ConnectionAgent connectionAgent, ResultCodeDisconnect result, bool force, Payload payload) =>
        {
            Debug.LogFormat("onDisconnect - {0}", result);
            MessageUi.Instance.SetTextMessage("onDisconnect..... " + result);
            UserInfo.Instance.MoveScene(Constants.SCENE_GAME_LOGIN);
        };

        // 세션 연결 리스너
        ConnectHandler.Instance.GetConnectionAgent().onConnectListeners += (ConnectionAgent connectionAgent, ResultCodeConnect result) =>
        {
            if (result == ResultCodeConnect.CONNECT_SUCCESS)
            {
                // 인증에 필요한 프로토콜 데이터 설정
                var authenticationReq = new Com.Nhn.Gameanvil.Sample.Protocol.AuthenticationReq
                {
                    AccessToken = GamebaseInfo.Instance.GamebaseToken
                };
                Debug.Log("authenticationReq " + authenticationReq);

                // 서버에 인증 시도. 현재는 deviceid uuid, id, pw Gamebase userId 값으로 전달
                ConnectHandler.Instance.GetConnectionAgent().Authenticate(textUUID.text, textGamebaseUserId.text, textGamebaseUserId.text, new Payload().Add(new Packet(authenticationReq)));
            }
            else
            {
                // 서버 접속 실패 처리
                buttonLogin.interactable = true;
                MessageUi.Instance.SetTextMessage("onConnect Fail..... " + result);
            }
        };

        // 인증 리스너
        ConnectHandler.Instance.GetConnectionAgent().onAuthenticationListeners +=
            (ConnectionAgent connectionAgent, ResultCodeAuth result, List <ConnectionAgent.LoginedUserInfo> loginedUserInfoList, string message, Payload payload) =>
        {
            Debug.Log("Auth " + result);

            // 성공인 경우 다음 단계로 진행.
            if (result == ResultCodeAuth.AUTH_SUCCESS)
            {
                // 성공시 로그인 요청
                GameAnvilLogin();
            }
            else
            {
                // 실패시 처리
                buttonLogin.interactable = true;
                MessageUi.Instance.SetTextMessage("onAutentication Fail..... " + result);
            }
        };
        // ===========================================================================================>>> GameAnvil
    }