Exemplo n.º 1
0
 /// <summary>
 /// Get current p2p session state.
 /// </summary>
 /// <param name="sessionState">The session state.</param>
 /// <returns>true if session state is available, false otherwise</returns>
 public bool GetP2PSessionState(out Steamworks.P2PSessionState_t sessionState)
 {
     if (players[1] == null)
     {
         sessionState = new Steamworks.P2PSessionState_t();
         return(false);
     }
     return(Steamworks.SteamNetworking.GetP2PSessionState(players[1].SteamId, out sessionState));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Draw network statistics.
        /// </summary>
        public void Draw()
        {
            GUI.color = Color.white;
            const int WINDOW_WIDTH    = 300;
            const int WINDOW_HEIGHT   = 600;
            Rect      statsWindowRect = new Rect(Screen.width - WINDOW_WIDTH - 10,
                                                 Screen.height - WINDOW_HEIGHT - 10, WINDOW_WIDTH, WINDOW_HEIGHT);

            GUI.Window(666, statsWindowRect, (int window) => {
                // Draw traffic graph title.

                var rct = new Rect(10, 20, 200, 25);
                GUI.Label(rct, $"Traffic graph (last {HISTORY_SIZE} frames):");
                rct.y += 25;

                var graphRect = new Rect(rct.x, rct.y, WINDOW_WIDTH - 20, 100);

                // Draw graph background.

                GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.35f);
                IMGUIUtils.DrawPlainColorRect(graphRect);

                // Draw the graph itself.

                graphRect.x += statsWindowRect.x;
                graphRect.y += statsWindowRect.y;
                DrawGraph(graphRect);

                GUI.color = Color.white;
                rct.y    += 5;
                rct.x    += 5;
                IMGUIUtils.DrawSmallLabel($"{FormatBytes(maxBytesSentInHistory)} sent/frame",
                                          rct, Color.red, true);
                rct.y += 12;

                IMGUIUtils.DrawSmallLabel(
                    $"{FormatBytes(maxBytesReceivedInHistory)} recv/frame", rct, Color.green,
                    true);
                rct.y -= 12 - 5;
                rct.x -= 5;

                rct.y += graphRect.height;

                rct.height = 20;

                // Draw separator

                GUI.color = Color.black;
                IMGUIUtils.DrawPlainColorRect(new Rect(0, rct.y, WINDOW_WIDTH, 2));
                rct.y += 2;

                // Draw stats background

                GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.5f);
                IMGUIUtils.DrawPlainColorRect(
                    new Rect(0, rct.y, WINDOW_WIDTH, WINDOW_HEIGHT - rct.y));

                // Draw statistics

                DrawStatHelper(ref rct, "packetsSendTotal", packetsSendTotal);
                DrawStatHelper(ref rct, "packetsReceivedTotal", packetsReceivedTotal);
                DrawStatHelper(ref rct, "packetsSendLastFrame", packetsSendLastFrame, 1000);
                DrawStatHelper(
                    ref rct, "packetsReceivedLastFrame", packetsReceivedLastFrame, 1000);
                DrawStatHelper(
                    ref rct, "packetsSendCurrentFrame", packetsSendCurrentFrame, 1000);
                DrawStatHelper(ref rct, "packetsReceivedCurrentFrame",
                               packetsReceivedCurrentFrame, 1000);
                DrawStatHelper(ref rct, "bytesSendTotal", bytesSentTotal, -1, true);
                DrawStatHelper(ref rct, "bytesReceivedTotal", bytesReceivedTotal, -1, true);
                DrawStatHelper(
                    ref rct, "bytesSendLastFrame", bytesSentLastFrame, 1000, true);
                DrawStatHelper(
                    ref rct, "bytesReceivedLastFrame", bytesReceivedLastFrame, 1000, true);
                DrawStatHelper(
                    ref rct, "bytesSendCurrentFrame", bytesSentCurrentFrame, 1000, true);
                DrawStatHelper(ref rct, "bytesReceivedCurrentFrame",
                               bytesReceivedCurrentFrame, 1000, true);

                // Draw separator

                rct.y    += 2;
                GUI.color = Color.black;
                IMGUIUtils.DrawPlainColorRect(new Rect(0, rct.y, WINDOW_WIDTH, 2));
                rct.y += 2;

                // Draw P2P session state.

                DrawTextHelper(ref rct, "Steam session state:", "");

                Steamworks.P2PSessionState_t sessionState =
                    new Steamworks.P2PSessionState_t();
                if (netManager.GetP2PSessionState(out sessionState))
                {
                    DrawTextHelper(
                        ref rct, "Is Connecting", sessionState.m_bConnecting.ToString());
                    DrawTextHelper(ref rct, "Is connection active",
                                   sessionState.m_bConnectionActive == 0 ? "no" : "yes");
                    DrawTextHelper(ref rct, "Using relay?",
                                   sessionState.m_bConnectionActive == 0 ? "no" : "yes");
                    DrawTextHelper(ref rct, "Session error",
                                   Utils.P2PSessionErrorToString(
                                       (Steamworks.EP2PSessionError)sessionState.m_eP2PSessionError));
                    DrawTextHelper(ref rct, "Bytes queued for send",
                                   FormatBytes(sessionState.m_nBytesQueuedForSend));
                    DrawTextHelper(ref rct, "Packets queued for send",
                                   sessionState.m_nPacketsQueuedForSend.ToString());
                    uint uip  = sessionState.m_nRemoteIP;
                    string ip = string.Format("{0}.{1}.{2}.{3}", (uip >> 24) & 0xff,
                                              (uip >> 16) & 0xff, (uip >> 8) & 0xff, uip & 0xff);
                    DrawTextHelper(ref rct, "Remote ip", ip);
                    DrawTextHelper(
                        ref rct, "Remote port", sessionState.m_nRemotePort.ToString());
                }
                else
                {
                    DrawTextHelper(ref rct, "Session inactive.", "");
                }
            }, "Network statistics");
        }