コード例 #1
0
        private void Networking_UnAuthorized(object sender, EventArgs e)
        {
            if (!waitingForAuthorization && !drawLogin)
            {
                string localSessionId = LocalData.RetrieveSession();
                if (localSessionId != null && localSessionId.Length != 0)
                {
                    waitingForAuthorization = true;

                    Networking.SessionVerificationResult += Networking_SessionVerificationResult;
                    Networking.Send(PacketName.RequestSessionVerification.ToString(), localSessionId);
                }
                else
                {
                    // User has no session.
                    LocalData.SaveSession("");
                    this.drawLogin            = true;
                    this.drawAppSelectionView = false;
                    this.drawApp = false;

                    waitingForAuthorization = false;
                    Frame.SetBackgroundColor(36, 36, 36);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Called when logout is clicked.
 /// </summary>
 private void LogOut()
 {
     LocalData.SaveSession("");
     drawApp              = false;
     drawLogin            = true;
     drawAppSelectionView = false;
 }
コード例 #3
0
        private void Networking_SessionVerificationResult(object sender, EventArgs e)
        {
            Networking.SessionVerificationResult -= Networking_SessionVerificationResult;

            GenericResponse response = (GenericResponse)sender;

            if (response != GenericResponse.Success)
            {
                CloseApp();

                LocalData.SaveSession("");
                this.drawLogin            = true;
                this.drawAppSelectionView = false;
                this.drawApp = false;
                Frame.SetBackgroundColor(36, 36, 36);
            }

            drawNetworkDisconnected = false;
        }
コード例 #4
0
        /// <summary>
        /// Draw connection error overlay. Retry connection and close.
        /// </summary>
        private void DrawConnectionErrorOverlay()
        {
            bool unused_open = true;

            ImGui.OpenPopup("NetworkDisconnected");
            if (ImGui.BeginPopupModal("NetworkDisconnected", ref unused_open, ImGuiWindowFlags.NoMove |
                                      ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.PushFont((ImFontPtr)Frame.Fonts.NormalFont);

                if (Platform == Platform.Android)
                {
                    ImGui.SetWindowFontScale(1 - downScaleNetworkDisconnectedWindow);
                }

                ImGui.TextUnformatted("Lost connection to server.");

                float buttonPositionX = ImGui.CalcTextSize("Lost connection to server.").X;
                ImGui.SetCursorPosX(buttonPositionX);
                ImGui.SetCursorPosY(ImGui.CalcTextSize("UNUSED").Y * 2);

                ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(1, 1, 1, 1));
                ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0, 0, 0, 1));

                Vector2 buttonPadding = new Vector2(14, 20);
                if (Platform == Platform.Android)
                {
                    buttonPadding = new Vector2(14, 60);
                }

                if (runningConnectCheck)
                {
                    ImGui.Button("Retrying Connection... ", ImGui.CalcTextSize("Retrying Connection... ") + buttonPadding);
                }
                else
                {
                    if (ImGui.Button("Retry Connection", ImGui.CalcTextSize("Retrying Connection... ") + buttonPadding))
                    {
                        Task.Factory.StartNew(() =>
                        {
                            runningConnectCheck = true;

                            if (Networking.ReConnect())
                            {
                                string localSessionId = LocalData.RetrieveSession();
                                if (localSessionId != null && localSessionId.Length != 0)
                                {
                                    Networking.SessionVerificationResult += Networking_SessionVerificationResult;
                                    Networking.Send(PacketName.RequestSessionVerification.ToString(), localSessionId);
                                }
                                else
                                {
                                    // User is not logged in.
                                    drawNetworkDisconnected = false;
                                }
                            }

                            runningConnectCheck = false;
                        });
                    }
                }

                ImGui.SetCursorPosX(buttonPositionX);

                if (ImGui.Button("Close app", ImGui.CalcTextSize("Retrying Connection... ") + buttonPadding))
                {
                    PlatformFunctions.Exit();
                }

                Vector2 windowSize          = ImGui.GetWindowSize();
                Vector2 screenSize          = new Vector2(Frame.Width, Frame.Height);
                Vector2 loginWindowPosition = new Vector2((screenSize.X / 2) - (windowSize.X / 2),
                                                          (screenSize.Y / 2) - (windowSize.Y / 2));

                if ((ImGui.GetWindowWidth() + (15 * PlatformFunctions.ScreenDensity())) > (screenSize.X))
                {
                    downScaleNetworkDisconnectedWindow += 0.05f;
                }

                ImGui.SetWindowPos(loginWindowPosition);

                ImGui.PopStyleColor();
                ImGui.PopFont();
                ImGui.EndPopup();
            }
        }