Exemple #1
0
        public static void RunClient()
        {
            Console.WriteLine("My Guid: " + UdpMeshCommon.GetMeshAddress());
            Console.WriteLine("Ip addresses:");
            IPAddress[] addresses = UdpMeshCommon.GetLocalIPAddresses();
            foreach (IPAddress ip in UdpMeshCommon.GetLocalIPAddresses())
            {
                Console.WriteLine("IP: " + ip + ", family: " + ip.AddressFamily);
            }
            IPAddress[] ipAddrs = Dns.GetHostAddresses("godarklight.privatedns.org");
            IPAddress   ipAddr  = IPAddress.None;
            IPAddress   ipAddr6 = IPAddress.None;

            foreach (IPAddress ip in ipAddrs)
            {
                if (UdpMeshCommon.IsIPv4(ip))
                {
                    ipAddr = ip;
                }
                if (UdpMeshCommon.IsIPv6(ip))
                {
                    ipAddr6 = ip;
                }
            }
            if (ipAddr == IPAddress.None)
            {
                Console.WriteLine("Unable to lookup godarklight.privatedns.org v4");
            }
            else
            {
                Console.WriteLine("Connecting to " + ipAddr);
            }
            if (ipAddr6 == IPAddress.None)
            {
                Console.WriteLine("Unable to lookup godarklight.privatedns.org v6");
            }
            else
            {
                Console.WriteLine("Connecting to " + ipAddr6);
            }
            if (ipAddr == IPAddress.None && ipAddr6 == IPAddress.None)
            {
                return;
            }
            UdpMeshClient udpmc = new UdpMeshClient(new IPEndPoint(ipAddr, 6702), new IPEndPoint(ipAddr6, 6702), addresses, Console.WriteLine);

            udpmc.RegisterCallback(0, UpdateClientTest);
            Thread clientTask = udpmc.Start();

            while (true)
            {
                Thread.Sleep(5000);
                Console.WriteLine("Guids on server: ");
                var peers = udpmc.GetPeers();
                Console.Write("Us, " + UdpMeshCommon.GetMeshAddress() + ", Connected: ");
                if (udpmc.connectedv4)
                {
                    Console.Write("V4 ");
                }
                if (udpmc.connectedv6)
                {
                    Console.Write("V6 ");
                }
                Console.WriteLine();
                foreach (UdpPeer peer in peers)
                {
                    if (peer.guid == UdpMeshCommon.GetMeshAddress())
                    {
                        continue;
                    }
                    udpmc.SendMessageToClient(peer.guid, 0, null);
                    Console.Write(peer.guid + ", Connected on: ");
                    if (peer.usev4)
                    {
                        Console.Write("V4 ");
                    }
                    if (peer.usev6)
                    {
                        Console.Write("V6 ");
                    }
                    double latency4 = peer.latency4 / (double)TimeSpan.TicksPerMillisecond;
                    double latency6 = peer.latency6 / (double)TimeSpan.TicksPerMillisecond;
                    double offset   = peer.offset / (double)TimeSpan.TicksPerSecond;
                    Console.Write("Latency v4 (ms): " + Math.Round(latency4, 2));
                    Console.Write(", Latency v6 (ms): " + Math.Round(latency6, 2));
                    Console.Write(", Offset (s): " + Math.Round(offset, 2));
                    long lastTest;
                    if (testTime.TryGetValue(peer.guid, out lastTest))
                    {
                        if ((DateTime.UtcNow.Ticks - lastTest) > (TimeSpan.TicksPerMinute / 2))
                        {
                            Console.Write(", LOST CONTACT");
                        }
                    }
                    else
                    {
                        Console.Write(", NO CONTACT");
                    }
                    Console.WriteLine();
                }
            }
        }
Exemple #2
0
 private void DrawContent(int windowID)
 {
     GUILayout.BeginVertical();
     GUI.DragWindow(moveRect);
     GameEvents.debugEvents = GUILayout.Toggle(GameEvents.debugEvents, "Debug GameEvents", buttonStyle);
     displayFast            = GUILayout.Toggle(displayFast, "Fast debug update", buttonStyle);
     displayVectors         = GUILayout.Toggle(displayVectors, "Display vessel vectors", buttonStyle);
     if (displayVectors)
     {
         GUILayout.Label(vectorText, labelStyle);
     }
     displayNTP = GUILayout.Toggle(displayNTP, "Display NTP/Subspace statistics", buttonStyle);
     if (displayNTP)
     {
         GUILayout.Label(ntpText, labelStyle);
     }
     displayConnectionQueue = GUILayout.Toggle(displayConnectionQueue, "Display connection statistics", buttonStyle);
     if (displayConnectionQueue)
     {
         GUILayout.Label(connectionText, labelStyle);
     }
     displayDynamicTickStats = GUILayout.Toggle(displayDynamicTickStats, "Display dynamic tick statistics", buttonStyle);
     if (displayDynamicTickStats)
     {
         GUILayout.Label(dynamicTickText, labelStyle);
     }
     displayRequestedRates = GUILayout.Toggle(displayRequestedRates, "Display requested rates", buttonStyle);
     if (displayRequestedRates)
     {
         GUILayout.Label(requestedRateText, labelStyle);
     }
     profiler.samplingEnabled = GUILayout.Toggle(profiler.samplingEnabled, "Record Profiler Samples", buttonStyle);
     displayVesselRecorder    = GUILayout.Toggle(displayVesselRecorder, "Display Vessel Recorder", buttonStyle);
     if (displayVesselRecorder)
     {
         if (!vesselRecorder.active)
         {
             if (GUILayout.Button("Start Recording", buttonStyle))
             {
                 vesselRecorder.StartRecord();
             }
             if (GUILayout.Button("Playback", buttonStyle))
             {
                 vesselRecorder.StartPlayback();
             }
         }
         else
         {
             if (GUILayout.Button("Stop Recording", buttonStyle))
             {
                 vesselRecorder.StopRecord();
             }
             if (GUILayout.Button("Cancel Recording", buttonStyle))
             {
                 vesselRecorder.CancelRecord();
             }
         }
     }
     posistionStatistics.active = GUILayout.Toggle(posistionStatistics.active, "Display Posistional Error", buttonStyle);
     if (posistionStatistics.active)
     {
         if (posistionStatistics.selectedVessel != Guid.Empty)
         {
             GUILayout.Label("Posistional Error: " + Math.Round(posistionStatistics.distanceError, 2), labelStyle);
             GUILayout.Label("Velocity Error: " + Math.Round(posistionStatistics.velocityError, 2), labelStyle);
             GUILayout.Label("Rotational Error: " + Math.Round(posistionStatistics.rotationError, 2), labelStyle);
             GUILayout.Label("Update HZ: " + Math.Round(posistionStatistics.updateHz, 2), labelStyle);
         }
         else
         {
             GUILayout.Label("(no selected vessel)", labelStyle);
         }
     }
     displayVesselTimeDelay = GUILayout.Toggle(displayVesselTimeDelay, "Vessel Delay Settings", buttonStyle);
     if (displayVesselTimeDelay)
     {
         GUILayout.BeginHorizontal();
         vesselworkerTimeDelay = GUILayout.TextArea(vesselworkerTimeDelay, textAreaOptions);
         if (GUILayout.Button("Set", buttonStyle))
         {
             float newDelay = 0f;
             if (float.TryParse(vesselworkerTimeDelay, out newDelay))
             {
                 vesselWorker.delayTime = newDelay;
             }
             else
             {
                 vesselWorker.delayTime = 0f;
                 vesselworkerTimeDelay  = "0";
             }
         }
         GUILayout.EndHorizontal();
     }
     displayMeshStats = GUILayout.Toggle(displayMeshStats, "Mesh statistics", buttonStyle);
     if (displayMeshStats)
     {
         UdpMeshClient udpMesh = networkWorker.GetMesh();
         foreach (UdpPeer peer in udpMesh.GetPeers())
         {
             if (peer.guid != UdpMeshCommon.GetMeshAddress())
             {
                 string playerName = networkWorker.GetMeshPlayername(peer.guid);
                 if (playerName != null)
                 {
                     GUILayout.Label(playerName + ":", labelStyle);
                 }
                 else
                 {
                     GUILayout.Label(peer.guid + ":", labelStyle);
                 }
                 double latency4 = peer.latency4 / (double)TimeSpan.TicksPerMillisecond;
                 double latency6 = peer.latency6 / (double)TimeSpan.TicksPerMillisecond;
                 double offset   = peer.offset / (double)TimeSpan.TicksPerSecond;
                 if (peer.usev4)
                 {
                     GUILayout.Label("V4 Latency: " + Math.Round(latency4, 2) + "ms", labelStyle);
                 }
                 if (peer.usev6)
                 {
                     GUILayout.Label("V6 Latency: " + Math.Round(latency6, 2) + "ms", labelStyle);
                 }
                 if (peer.usev4 || peer.usev6)
                 {
                     GUILayout.Label("Clock offset: " + Math.Round(offset, 2), labelStyle);
                 }
                 else
                 {
                     GUILayout.Label("No contact - using server relay", labelStyle);
                 }
             }
         }
     }
     displayVesselCache = GUILayout.Toggle(displayVesselCache, "Display vessel cache", buttonStyle);
     if (displayVesselCache)
     {
         GUILayout.Label("Normal:", labelStyle);
         foreach (KeyValuePair <Guid, Queue <VesselUpdate> > kvp in vesselWorker.vesselUpdateQueue)
         {
             if (kvp.Value.Count > 0)
             {
                 GUILayout.Label(kvp.Key + ": " + kvp.Value.Count, labelStyle);
             }
         }
         GUILayout.Label("Mesh:", labelStyle);
         foreach (KeyValuePair <Guid, Queue <VesselUpdate> > kvp in vesselWorker.vesselUpdateMeshQueue)
         {
             if (kvp.Value.Count > 0)
             {
                 GUILayout.Label(kvp.Key + ": " + kvp.Value.Count, labelStyle);
             }
         }
     }
     displayRecycler = GUILayout.Toggle(displayRecycler, "Display recycler", buttonStyle);
     if (displayRecycler)
     {
         GUILayout.Label(recyclerText, labelStyle);
     }
     if (GUILayout.Button("Dump recycler", buttonStyle))
     {
         dumpRecycler = true;
     }
     GUILayout.EndVertical();
 }