public PingPlugin(DalamudPluginInterface pluginInterface, CommandManager commands, DtrBar dtrBar, GameNetwork network) { this.pluginInterface = pluginInterface; this.network = network; this.config = (PingConfiguration)this.pluginInterface.GetPluginConfig() ?? new PingConfiguration(); this.config.Initialize(this.pluginInterface); this.addressDetector = this.pluginInterface.Create <AggregateAddressDetector>(); if (this.addressDetector == null) { throw new InvalidOperationException("Failed to create game address detector. The provided arguments may be incorrect."); } this.pingTracker = RequestNewPingTracker(this.config.TrackingMode); this.pingTracker.Start(); InitIpc(); // Most of these can't be created using service injection because the service container only checks ctors for // exact types. this.ui = new PingUI(this.pingTracker, this.pluginInterface, dtrBar, this.config, RequestNewPingTracker); this.pingTracker.OnPingUpdated += this.ui.UpdateDtrBarPing; this.pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi; this.pluginInterface.UiBuilder.Draw += this.ui.Draw; this.pluginCommandManager = new PluginCommandManager <PingPlugin>(this, commands); }
public void Initialize(DalamudPluginInterface pluginInterface) { this.pluginInterface = pluginInterface; this.config = (PingConfiguration)this.pluginInterface.GetPluginConfig() ?? new PingConfiguration(); this.pingTracker = new PingTracker(); this.ui = new PingUI(this.pingTracker, this.config); ui.IsVisible = true; this.pluginInterface.UiBuilder.OnBuildUi += this.ui.Draw; this.pluginInterface.CommandManager.AddHandler("/ping", new CommandInfo((command, args) => this.ui.IsVisible = !this.ui.IsVisible)); this.pluginInterface.Framework.Network.OnNetworkMessage += OnNetworkMessage; }
private PingTracker RequestNewPingTracker(PingTrackerKind kind) { this.pingTracker?.Dispose(); PingTracker newTracker = kind switch { PingTrackerKind.Aggregate => new AggregatePingTracker(this.config, this.addressDetector, this.network), PingTrackerKind.COM => new ComponentModelPingTracker(this.config, this.addressDetector), PingTrackerKind.IpHlpApi => new IpHlpApiPingTracker(this.config, this.addressDetector), PingTrackerKind.Packets => new PacketPingTracker(this.config, this.addressDetector, this.network), _ => throw new ArgumentOutOfRangeException(nameof(kind)), }; this.pingTracker = newTracker; if (this.pingTracker == null) { throw new InvalidOperationException($"Failed to create ping tracker \"{kind}\". The provided arguments may be incorrect."); } this.pingTracker.Start(); return(newTracker); }
public PingUI(PingTracker pingTracker, PingConfiguration config) { this.config = config; this.pingTracker = pingTracker; }