Exemplo n.º 1
0
    // Upon project start, execute the battery of Enjin SDK runtime function tests.
    void Start()
    {
        Debug.Log("=== Executing Enjin SDK runtime tests. ===");
        Enjin.IsDebugLogActive = DEBUG;

        Debug.Log("(1/8) Initializing the platform for use as game server ... ");
        Enjin.StartPlatform(PLATFORM_URL, SERVER_EMAIL, SERVER_PASSWORD, APP_ID);
        DEVELOPER_TOKEN = Enjin.AccessToken;
        Debug.Log(" ... PASSED.");

        Debug.Log("(2/8) Creating a new testing account ... ");
        long   timestamp    = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
        string testName     = "test" + timestamp;
        string testEmail    = testName + "@mail.com";
        string testPassword = "******";
        User   testUser     = new User
        {
            name     = testName,
            email    = testEmail,
            password = testPassword
        };

        Enjin.CreateUser(testUser.name, testUser.email, testUser.password, "Platform Owner");
        if (Enjin.ServerResponse == ResponseCodes.SUCCESS)
        {
            Debug.Log(" ... PASSED.");

            Debug.Log("(3/8) Verifying login credentials for the testing account ... ");
            loginUser = Enjin.VerifyLogin(testEmail, testPassword);
            LoginState loginState = Enjin.LoginState;
            if (loginState == LoginState.VALID)
            {
                Debug.Log(" ... PASSED.");
                TESTER_TOKEN = loginUser.access_token;
                foreach (Identity identity in loginUser.identities)
                {
                    if (identity.app_id == APP_ID)
                    {
                        Debug.Log("****** " + identity.app_id + " / " + APP_ID + ": " + identity.linking_code);
                        testingIdentityID = identity.id;
                    }
                }
                testingIdentity = Enjin.GetIdentity(testingIdentityID);
                string linkingCode = testingIdentity.linking_code;

                Debug.Log("(4/8) Establishing wallet link for the testing account. Please link with code " + linkingCode + " ... ");
                Enjin.ListenForLink(testingIdentityID, linkingData =>
                {
                    USER_ADDRESS = linkingData.data.ethereum_address;
                    Debug.Log(" ... PASSED.");
                    sequenceOne = true;
                });
            }
            else
            {
                Debug.LogError(" ... FAILED.");
            }
        }
        else
        {
            Debug.LogError(" ... FAILED.");
        }
    }
Exemplo n.º 2
0
    // Fetch the user's login details and log them in.
    public void Login()
    {
        // Retrieve and verify the user's login details.
        string email    = loginEmail.text;
        string password = loginPassword.text;

        user = Enjin.VerifyLogin(email, password);

        // If the login was successful, proceed.
        switch (Enjin.LoginState)
        {
        case LoginState.VALID:
        {
            // Find the identity for this app and confirm it has been linked.
            foreach (Identity identity in user.identities)
            {
                if (identity.app_id == Enjin.AppID)
                {
                    linkingCode = identity.linking_code;
                    identityId  = identity.id;
                    userAddress = identity.ethereum_address;
                    break;
                }
            }

            // If the user has already linked, proceed directly to play.
            bool hasLinked = (linkingCode == "");
            if (hasLinked)
            {
                SetupPlay();
            }

            // Otherwise register a listener to trigger once we have succeeded in linking.
            else
            {
                SetStatus("Your wallet is unlinked.\nPlease use code: " + linkingCode);
                tutorial.text = Resources.Load <TextAsset>("link-wallet-tutorial").text;
                ShowPanel(null);
                Enjin.ListenForLink(identityId, (requestEvent) =>
                    {
                        identityId  = requestEvent.data.id;
                        userAddress = requestEvent.data.ethereum_address;
                        pendingActions.Add(SetupPlay);
                    });
            }

            break;
        }

        case LoginState.INVALIDUSERPASS:
            SetStatus("You entered an invalid\nusername or password.");
            break;

        case LoginState.INVALIDTPURL:
            SetStatus("This app is trying to reach an\ninvalid Trusted Cloud URL:\n" + Enjin.APIURL);
            break;

        case LoginState.UNAUTHORIZED:
            SetStatus("You are unauthorized for this login.");
            break;
        }
    }