async void Start()
        {
            playerEntity = await OnFacet <PlayerFacet>
                           .CallAsync <PlayerEntity>("GetPlayerEntity");

            if (playerEntity == null)
            {
                throw new Exception("Player entity does not exist?");
            }

            playerDescription.text =
                (playerEntity.Name ?? "anonymous") +
                " #" + playerEntity.Number;

            currencies.text = "<b>Coins:</b> " + playerEntity.Coins + "\n" +
                              "<b>Gems:</b> " + playerEntity.Gems;

            // TODO: hack for MatchResult scene
            // remove this later when fixed
            if (PhotonNetwork.IsConnected)
            {
                Debug.Log("Disconnected from photon.");
                PhotonNetwork.Disconnect();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method is called by Steamworks when the transaction finishes
        /// (player either authorized or aborted the transaction)
        /// </summary>
        public async void SteamworksCallbackHandler(
            MicroTxnAuthorizationResponse_t response
            )
        {
            // finish the transaction
            SteamTransactionEntity transaction;

            try
            {
                transaction = await OnFacet <SteamPurchasingServerFacet>
                              .CallAsync <SteamTransactionEntity>(
                    nameof(SteamPurchasingServerFacet.FinalizeTransaction),
                    response.m_ulOrderID,
                    response.m_bAuthorized == 1
                    );
            }
            catch (Exception e)
            {
                ReportErrorToThePlayer(e.Message);
                return;
            }

            // transaction has been aborted by the player
            if (response.m_bAuthorized != 1)
            {
                ReportErrorToThePlayer("You've aborted the transaction.");
                return;
            }

            // everything went according to plans
            TransactionHasBeenSuccessful(transaction);
        }
Esempio n. 3
0
        private async void LogoutButtonClicked()
        {
            var wasLoggedIn = await OnFacet <EmailLoginFacet> .CallAsync <bool>(
                nameof(EmailLoginFacet.Logout)
                );

            LogoutSucceeded(wasLoggedIn);
        }
Esempio n. 4
0
 private async void OnSendClicked()
 {
     await OnFacet <ChatFacet> .CallAsync(
         nameof(ChatFacet.SendMessage),
         roomName,
         userName,
         messageField.text
         );
 }
        async void Start()
        {
            collection = await OnFacet <PlayerFacet>
                         .CallAsync <PlayerCollectionEntity>("GetPlayerCollectionEntity");

            piecesText.text = Serializer
                              .ToJson(collection.OwnedPieces)
                              .ToString();
        }
Esempio n. 6
0
        private async void CallGuardedButtonClicked()
        {
            Debug.Log(
                "Calling the guarded method...\n" +
                "This will fail if no player is authenticated."
                );

            await OnFacet <WhoIsFacet> .CallAsync(
                nameof(WhoIsFacet.GuardedMethod)
                );
        }
Esempio n. 7
0
        public async void CallAddingFacet()
        {
            int result = await OnFacet <ExampleTestingFacet> .CallAsync <int>(
                nameof(ExampleTestingFacet.AddNumbers),
                4, 7
                );

            if (result != 11)
            {
                throw new Exception("The result was not 11!");
            }
        }
Esempio n. 8
0
        private async void OnEnable()
        {
            var subscription = await OnFacet <ChatFacet>
                               .CallAsync <ChannelSubscription>(
                nameof(ChatFacet.JoinRoom),
                roomName,
                userName
                );

            FromSubscription(subscription)
            .Forward <ChatMessage>(ChatMessageReceived)
            .Forward <PlayerJoinedMessage>(PlayerJoined)
            .ElseLogWarning();
        }
Esempio n. 9
0
        private async void WhoIsButtonClicked()
        {
            var player = await OnFacet <WhoIsFacet> .CallAsync <PlayerEntity>(
                nameof(WhoIsFacet.WhoIsLoggedIn)
                );

            if (player == null)
            {
                Debug.Log("There is no logged in player.");
            }
            else
            {
                Debug.Log("The logged in player is: " + player.email);
            }
        }
Esempio n. 10
0
 private async void SendTransactionProposalToPurchasingServer(
     SteamTransactionEntity transaction
     )
 {
     try
     {
         await OnFacet <SteamPurchasingServerFacet> .CallAsync(
             nameof(SteamPurchasingServerFacet.InitiateTransaction),
             transaction
             );
     }
     catch (Exception e)
     {
         ReportErrorToThePlayer(e.Message);
     }
 }
        private async void OnEnable()
        {
            var subscription = await OnFacet <BroadcastingFacet>
                               .CallAsync <ChannelSubscription>(
                nameof(BroadcastingFacet.SubscribeToMyChannel),
                channelParameter,
                sendMessageAfterSubscribing
                );

            FromSubscription(subscription)
            .Forward <MyMessage>(OnMyMessage)
            .Forward <MyOtherMessage>(OnMyOtherMessage)
            .ElseLogWarning();

            // now we can start doing experiments
            hasSettled = true;
        }
        private async void LoginButtonClicked()
        {
            bool success = await OnFacet <AuthFacet> .CallAsync <bool>(
                nameof(AuthFacet.Login),
                emailInputField.text,
                passwordInputField.text
                );

            if (success)
            {
                LoginSucceeded();
            }
            else
            {
                LoginFailed();
            }
        }
Esempio n. 13
0
        public async void OnRegisterClicked()
        {
            statusText.enabled = true;
            statusText.text    = "Registering...";

            if (passwordField.text != confirmPasswordField.text)
            {
                statusText.text = "Password confirmation does not match";
                return;
            }

            var response = await OnFacet <EmailRegisterFacet>
                           .CallAsync <EmailRegisterResponse>(
                nameof(EmailRegisterFacet.Register),
                emailField.text,
                passwordField.text
                );

            switch (response)
            {
            case EmailRegisterResponse.Ok:
                statusText.text = "Registration succeeded";
                break;

            case EmailRegisterResponse.EmailTaken:
                statusText.text = "This email has already been registered";
                break;

            case EmailRegisterResponse.InvalidEmail:
                statusText.text = "This is not a valid email address";
                break;

            case EmailRegisterResponse.WeakPassword:
                statusText.text = "Password needs to be at least 8 " +
                                  "characters long";
                break;

            default:
                statusText.text = "Unknown response: " + response;
                break;
            }
        }
Esempio n. 14
0
        public async void OnLoginClicked()
        {
            statusText.enabled = true;
            statusText.text    = "Logging in...";

            var response = await OnFacet <EmailLoginFacet> .CallAsync <bool>(
                nameof(EmailLoginFacet.Login),
                emailField.text,
                passwordField.text
                );

            if (response)
            {
                SceneManager.LoadScene(sceneAfterLogin);
            }
            else
            {
                statusText.text = "Given credentials are not valid";
            }
        }
Esempio n. 15
0
        private async void RegisterButtonClicked()
        {
            if (passwordInputField.text != passwordRepeatInputField.text)
            {
                RegistrationFailed("Passwords don't match.");
                return;
            }

            var result = await OnFacet <AuthFacet>
                         .CallAsync <AuthFacet.RegistrationResult>(
                nameof(AuthFacet.Register),
                emailInputField.text,
                passwordInputField.text
                );

            switch (result)
            {
            case AuthFacet.RegistrationResult.Ok:
                RegistrationSucceeded();
                break;

            case AuthFacet.RegistrationResult.EmailTaken:
                RegistrationFailed("Email is already registered.");
                break;

            case AuthFacet.RegistrationResult.InvalidEmail:
                RegistrationFailed("Provided email is not valid.");
                break;

            case AuthFacet.RegistrationResult.WeakPassword:
                RegistrationFailed("Provided password is too weak.");
                break;

            default:
                RegistrationFailed("Unknown error.");
                break;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Call this to perform player login via Steam
        /// </summary>
        public async void LoginViaSteam()
        {
            // already waiting for a ticket
            if (ticketPromise != null)
            {
                return;
            }

            // get a ticket
            (string ticket, HAuthTicket handle) = await GetSessionTicketAsync();

            // send it to backend to resolve the ticket into Steam ID and login
            await OnFacet <SteamLoginFacet> .CallAsync(
                nameof(SteamLoginFacet.Login),
                ticket
                );

            // we don't need the ticket anymore
            SteamUser.CancelAuthTicket(handle);

            // load the next scene
            SceneManager.LoadScene(sceneAfterLogin);
        }
        /// <summary>
        /// Registers a ticket into the matchmaker and waits for a match.
        ///
        /// Calling this while already waiting does nothing.
        /// </summary>
        public async void StartWaitingForMatch(TMatchmakerTicket ticket)
        {
            if (isWaitingForMatch)
            {
                return;
            }

            isWaitingForMatch = true;

            await OnFacet <TMatchmakerFacet> .CallAsync(
                "JoinMatchmaker", ticket
                );

            int retryCount = 0;

            while (true)
            {
                if (killPolling)
                {
                    return;
                }

                bool attemptingCancellation = cancelWaiting;

                TMatchEntity match = null;
                try
                {
                    match = await OnFacet <TMatchmakerFacet>
                            .CallAsync <TMatchEntity>(
                        "PollMatchmaker",
                        attemptingCancellation
                        );
                }
                catch (UnknownPlayerPollingException)
                {
                    if (!attemptingCancellation)
                    {
                        // server has for some reason forgotten about us
                        // so just retry matchmaker joining
                        await OnFacet <TMatchmakerFacet> .CallAsync(
                            "JoinMatchmaker", ticket
                            );

                        retryCount++;

                        // something went wrong, just blow up
                        if (retryCount > MaxRetryCount)
                        {
                            isWaitingForMatch = false;
                            cancelWaiting     = false;

                            throw new UnisaveException(
                                      "Unable to join the matchmaker. " +
                                      $"Retried {MaxRetryCount} times, but still failing."
                                      );
                        }

                        continue;
                    }
                }

                // we were matched
                if (match != null)
                {
                    cancelWaiting     = false;
                    isWaitingForMatch = false;
                    JoinedMatch(match);
                    return;
                }

                // cancellation finished
                if (attemptingCancellation)
                {
                    cancelWaiting     = false;
                    isWaitingForMatch = false;
                    WaitingCanceled();
                    return;
                }

                // poll waiting
                await Task.Delay(PollingPeriodSeconds * 1000);
            }
        }