public void OnSignInButtonClicked()
    {
        string     username;
        string     password;
        string     path       = Application.persistentDataPath + "/ARChessGameUserSave.json";
        string     jsonString = File.ReadAllText(path);
        JSONObject userJSON   = (JSONObject)JSON.Parse(jsonString);

        username = userJSON["Username"];
        password = userJSON["Password"];

        var sha256 = new SHA256CryptoServiceProvider();

        byte[] passwordBytes  = Encoding.ASCII.GetBytes(this.PasswordInputField_SignIn.text);
        var    sha256Password = sha256.ComputeHash(passwordBytes);

        if (!username.Equals(UserNameInputField_SignIn.text) || !Convert.ToBase64String(sha256Password).Equals(password))
        {
            SignInBox.SetActive(false);
            SignInButton.SetActive(false);
            ErrorBox_SignIn.SetActive(true);
            ErrorText_SignIn.text = "Wrong username or password!";
            return;
        }

        userJSON["IsLoggedIn"] = true;
        File.WriteAllText(path, userJSON.ToString());

        //Connect to Photon
        PhotonFunctions.ConnectToPhoton(UserNameInputField_SignIn.text);

        SceneLoader.Instance.LoadScene("Scene_PlayerSelection");
    }
Beispiel #2
0
    public void OnExitButtonClicked()
    {
        //disconnect from Photon
        PhotonFunctions.DisconnectFromPhoton();

        ExitButtonOptions.SetActive(true);
    }
Beispiel #3
0
    public void OnDeleteAccountButtonClicked()
    {
        //disconnect from Photon
        PhotonFunctions.DisconnectFromPhoton();

        File.Delete(path);
        userProfileButton.SetActive(false);
        TitleText.text = "Welcome!";
        userProfile.SetActive(false);
    }
Beispiel #4
0
    public void OnSignOutButtonClicked()
    {
        //disconnect from Photon
        PhotonFunctions.DisconnectFromPhoton();

        userProfileButton.SetActive(false);
        TitleText.text = "Welcome!";
        userProfile.SetActive(false);

        userJSON["IsLoggedIn"] = false;
        File.WriteAllText(path, userJSON.ToString());
    }
Beispiel #5
0
    public void OnPlayWithoutUserButtonClicked()
    {
        string randomUserName = "******" + Random.Range(0, 10000);

        if (File.Exists(path))
        {
            userJSON.Add("PlayWithoutUser", true);
            File.WriteAllText(path, userJSON.ToString());
        }

        PhotonFunctions.ConnectToPhoton(randomUserName);
        SceneLoader.Instance.LoadScene("Scene_PlayerSelection");
    }
    public void OnCreatePlayerButtonClicked()
    {
        if (string.IsNullOrEmpty(PlayerNameInputField.text.Trim()) || string.IsNullOrEmpty(PasswordInputField.text.Trim()) || string.IsNullOrEmpty(ConfirmPasswordInputField.text.Trim()))
        {
            CreateBox.SetActive(false);
            CreateButton.SetActive(false);
            ErrorBox_Create.SetActive(true);
            ErrorText_Create.text = "All fields must be filled!";
            return;
        }

        var sha256 = new SHA256CryptoServiceProvider();

        //password to hash
        byte[] passwordBytes  = Encoding.ASCII.GetBytes(PasswordInputField.text);
        var    sha256Password = sha256.ComputeHash(passwordBytes);

        //confirm password to hash
        byte[] confirmPasswordBytes  = Encoding.ASCII.GetBytes(ConfirmPasswordInputField.text);
        var    sha256ConfirmPassword = sha256.ComputeHash(confirmPasswordBytes);

        if (!Convert.ToBase64String(sha256Password).Equals(Convert.ToBase64String(sha256ConfirmPassword)))
        {
            CreateBox.SetActive(false);
            CreateButton.SetActive(false);
            ErrorBox_Create.SetActive(true);
            ErrorText_Create.text = "Passwords do not match!";
            return;
        }

        JSONObject user = new JSONObject();

        user.Add("ID", CreateUniqueID());
        user.Add("Username", PlayerNameInputField.text);
        user.Add("Password", Convert.ToBase64String(sha256Password));
        user.Add("NumberOfWins", 0);
        user.Add("NumberOfLosses", 0);
        user.Add("IsLoggedIn", true);

        string path = Application.persistentDataPath + "/ARChessGameUserSave.json";

        File.WriteAllText(path, user.ToString());

        //Connect to Photon
        PhotonFunctions.ConnectToPhoton(PlayerNameInputField.text);

        SceneLoader.Instance.LoadScene("Scene_PlayerSelection");
    }
Beispiel #7
0
 public void OnPlayButtonClicked()
 {
     Options.SetActive(true);
     if (File.Exists(path))
     {
         isLoggedIn = userJSON["IsLoggedIn"];
         if (isLoggedIn)
         {
             //Connect to Photon
             PhotonFunctions.ConnectToPhoton(username);
             SceneLoader.Instance.LoadScene("Scene_PlayerSelection");
         }
         else
         {
             OptionsIfFile.SetActive(true);
         }
     }
     else
     {
         OptionsIfNotFile.SetActive(true);
     }
 }