예제 #1
0
        public AggregatePingTracker(PingConfiguration config, GameAddressDetector addressDetector, GameNetwork network) : base(config, addressDetector, PingTrackerKind.Aggregate)
        {
            // Define trackers
            this.trackerInfos = new Dictionary <string, TrackerInfo>();

            RegisterTracker(COMTrackerKey, new ComponentModelPingTracker(config, addressDetector)
            {
                Verbose = false
            });
            RegisterTracker(IpHlpApiTrackerKey, new IpHlpApiPingTracker(config, addressDetector)
            {
                Verbose = false
            });
            RegisterTracker(PacketTrackerKey, new PacketPingTracker(config, addressDetector, network)
            {
                Verbose = false
            });

            // Create decision tree to solve tracker selection problem
            this.decisionTree = new DecisionTree <string>(
                // If COM is errored
                () => TrackerIsErrored(COMTrackerKey),
                // Just use IpHlpApi
                pass: new DecisionTree <string>(() => TreeResult.Resolve(IpHlpApiTrackerKey)),
                fail: new DecisionTree <string>(
                    // If difference between pings is more than 30
                    () => Math.Abs((long)GetTrackerRTT(COMTrackerKey) - (long)GetTrackerRTT(IpHlpApiTrackerKey)) > 30,
                    pass: new DecisionTree <string>(
                        // Use greater ping value, something's probably subtly broken
                        () => GetTrackerRTT(COMTrackerKey) < GetTrackerRTT(IpHlpApiTrackerKey),
                        pass: new DecisionTree <string>(() => TreeResult.Resolve(IpHlpApiTrackerKey)),
                        fail: new DecisionTree <string>(() => TreeResult.Resolve(COMTrackerKey))
                        ),
                    fail: new DecisionTree <string>(
                        // If both of these trackers report a ping of 0
                        () => GetTrackerRTT(COMTrackerKey) == 0 && GetTrackerRTT(IpHlpApiTrackerKey) == 0,
                        // Just use packets (inaccurate)
                        pass: new DecisionTree <string>(() => TreeResult.Resolve(PacketTrackerKey)),
                        fail: new DecisionTree <string>(
                            // Otherwise use the lower ping value, we'll assume it's more accurate
                            () => GetTrackerRTT(COMTrackerKey) < GetTrackerRTT(IpHlpApiTrackerKey),
                            pass: new DecisionTree <string>(() => TreeResult.Resolve(COMTrackerKey)),
                            fail: new DecisionTree <string>(() => TreeResult.Resolve(IpHlpApiTrackerKey))
                            )
                        )
                    )
                );
        }
예제 #2
0
 public static TreeResult <T> Resolve <T>(T result)
 {
     return(TreeResult <T> .Resolve(result));
 }