Skip to content

Commit 09af79c

Browse files
committed
Fixed server not being able to receive anything
1 parent b739c01 commit 09af79c

File tree

6 files changed

+72
-18
lines changed

6 files changed

+72
-18
lines changed

plugin_Relay/Assets/Strings/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
"id": "/Titles/RelayStatus",
4242
"translation": "Status:"
4343
},
44+
{
45+
"id": "/Titles/Settings",
46+
"translation": "Tracking Relay Settings"
47+
},
4448
{
4549
"id": "/Buttons/Copy",
4650
"translation": "Copy Error"

plugin_Relay/Beacon/Probe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Probe : IDisposable
1818
private readonly Thread _thread;
1919
private readonly UdpClient _udp = new();
2020
private readonly EventWaitHandle _waitHandle = new(false, EventResetMode.AutoReset);
21-
private IEnumerable<BeaconLocation> _currentBeacons = Enumerable.Empty<BeaconLocation>();
21+
private IEnumerable<BeaconLocation> _currentBeacons = [];
2222

2323
private bool _running = true;
2424

plugin_Relay/Pages/DeviceSettings.xaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
RowDefinitions="Auto,Auto,Auto,*" RowSpacing="20">
1111

1212
<!--The panel title header-->
13-
<TextBlock Text="Tracking Relay Settings" FontSize="32" Grid.Row="0"
14-
Margin="0,5,0,0" FontWeight="SemiBold" />
13+
<Grid ColumnDefinitions="*, Auto" Grid.Row="0">
14+
<TextBlock Text="{x:Bind Host.RequestLocalizedString('/Titles/Settings'), Mode=OneWay}"
15+
FontSize="32" Grid.Column="0" Margin="0,5,0,0" FontWeight="SemiBold" IsTabStop="True" />
16+
<ToggleSwitch Margin="0,2,-108,0" OnContent="" OffContent=""
17+
IsOn="{x:Bind RelayReceiverEnabled, Mode=TwoWay}" Grid.Column="1"
18+
VerticalAlignment="Center" />
19+
</Grid>
1520

1621
<!--Server connection controls-->
17-
<Grid ColumnDefinitions="*,*" ColumnSpacing="15" Margin="0,10,0,0" Grid.Row="1">
22+
<Grid ColumnDefinitions="*,*" ColumnSpacing="15" Margin="0,10,0,0" Grid.Row="1"
23+
Opacity="{x:Bind SettingsOpacity, Mode=OneWay}" IsHitTestVisible="{x:Bind RelayReceiverEnabled, Mode=OneWay}">
1824
<TextBox Text="{x:Bind Device.ServerIp, Mode=OneWay}" PlaceholderText="127.0.0.1" Grid.Column="0"
1925
Header="Web server address:" LostFocus="AddressTextBox_OnLostFocus" x:Name="ServerAddressBox" />
2026
<NumberBox Value="{x:Bind Device.ServerPort, Mode=OneWay}" Maximum="65535"
@@ -24,7 +30,9 @@
2430

2531
<!--Status control grid with the refresh button-->
2632
<StackPanel Style="{ThemeResource CardMiddleStyle}" Grid.Row="2"
27-
CornerRadius="4" Margin="0,0,0,8">
33+
CornerRadius="4" Margin="0,0,0,8"
34+
Opacity="{x:Bind SettingsOpacity, Mode=OneWay}"
35+
IsHitTestVisible="{x:Bind RelayReceiverEnabled, Mode=OneWay}">
2836
<Grid Margin="5,0,0,0" HorizontalAlignment="Stretch">
2937
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="SemiBold" Margin="0,-3,0,0"
3038
Text="{x:Bind Host.RequestLocalizedString('/Titles/RelayStatus'), Mode=OneWay}"
@@ -132,7 +140,9 @@
132140
<!--Devices available via the relay-->
133141
<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
134142
VerticalScrollBarVisibility="Visible" Grid.Row="3"
135-
Margin="-8,0" Padding="8,0">
143+
Margin="-8,0" Padding="8,0"
144+
Opacity="{x:Bind SettingsOpacity, Mode=OneWay}"
145+
IsHitTestVisible="{x:Bind RelayReceiverEnabled, Mode=OneWay}">
136146
<ScrollViewer.Transitions>
137147
<TransitionCollection>
138148
<RepositionThemeTransition />

plugin_Relay/Pages/DeviceSettings.xaml.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Net;
77
using System.Reflection;
8+
using System.Threading;
89
using System.Threading.Tasks;
910
using Windows.ApplicationModel.DataTransfer;
1011
using Windows.ApplicationModel.Resources.Core;
@@ -93,6 +94,19 @@ public DeviceSettings()
9394
private string DevicePingStatus { get; set; }
9495
public string DeviceStatusAppendix { get; set; } = string.Empty;
9596
public string DeviceStatusHeader => string.IsNullOrEmpty(DevicePingStatus) ? Device.StatusSplit[0] + DeviceStatusAppendix : DevicePingStatus;
97+
private double SettingsOpacity => RelayReceiverEnabled ? 1.0 : 0.5;
98+
99+
private bool RelayReceiverEnabled
100+
{
101+
get => Device.RelayReceiverEnabled;
102+
set
103+
{
104+
if (Device.RelayReceiverEnabled == value) return;
105+
Device.RelayReceiverEnabled = value;
106+
OnPropertyChanged(); // Refresh
107+
Device.TriggerDevicePull(); // Pull
108+
}
109+
}
96110

97111
private Dictionary<string, (string Name, ITrackingDevice Device)> RelayTrackingDevices
98112
{
@@ -136,14 +150,21 @@ public async void StartConnectionTest()
136150

137151
try
138152
{
139-
var ping = await Device.Service.PingService();
140-
DevicePingStatus = $"{Host.RequestLocalizedString("/Refresh/Ping")} {(DateTime.Now.Ticks - ping) / 10000} ms";
141-
RefreshStatusInterface(); // Refresh without triggering a host refresh
142-
143-
Device.RelayHostname = await Device.Service.GetRemoteHostname();
144-
Host.PluginSettings.SetSetting("CachedRelayHostname", Device.RelayHostname);
145-
await Device.PullRemoteDevices(); // Finally do the thing! \^o^/ (no exceptions)
146-
TryStopProbe(); // Stop the probe as we've connected successfully
153+
var token = new CancellationTokenSource();
154+
token.CancelAfter(5000);
155+
156+
await Task.Run(async () =>
157+
{
158+
token.Token.ThrowIfCancellationRequested();
159+
var ping = await Device.Service.PingService();
160+
DevicePingStatus = $"{Host.RequestLocalizedString("/Refresh/Ping")} {(DateTime.Now.Ticks - ping) / 10000} ms";
161+
RefreshStatusInterface(); // Refresh without triggering a host refresh
162+
163+
Device.RelayHostname = await Device.Service.GetRemoteHostname();
164+
Host.PluginSettings.SetSetting("CachedRelayHostname", Device.RelayHostname);
165+
await Device.PullRemoteDevices(); // Finally do the thing! \^o^/ (no exceptions)
166+
TryStopProbe(); // Stop the probe as we've connected successfully
167+
}, token.Token).WaitAsync(token.Token);
147168
}
148169
catch (Exception ex)
149170
{

plugin_Relay/RelayDevice.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public RelayDevice()
4848
{
4949
get
5050
{
51-
if (Host is null || !PluginLoaded) return []; // Completely give up for now
51+
if (Host is null || !PluginLoaded || !RelayReceiverEnabled) return []; // Completely give up for now
5252
var blacklist = Host.PluginSettings.GetSetting("DevicesBlacklist", new SortedSet<string>());
5353

5454
return (DeviceStatus is not 0
@@ -89,6 +89,15 @@ public int ServerPort
8989
}
9090
}
9191

92+
public bool RelayReceiverEnabled
93+
{
94+
get => PluginLoaded && (Host?.PluginSettings.GetSetting("RelayReceiverEnabled", false) ?? false);
95+
set
96+
{
97+
if (PluginLoaded) Host?.PluginSettings.SetSetting("RelayReceiverEnabled", value);
98+
}
99+
}
100+
92101
public bool IsPositionFilterBlockingEnabled => false;
93102
public bool IsPhysicsOverrideEnabled => false;
94103
public bool IsSelfUpdateEnabled => true;
@@ -146,11 +155,11 @@ public void OnLoad()
146155
VerticalAlignment = VerticalAlignment.Stretch
147156
};
148157

149-
if (!(RelayService.Instance?.IsBackfeed ?? false))
158+
if (RelayReceiverEnabled)
150159
Task.Delay(3000).ContinueWith(_ =>
151160
{
152161
Host?.Log("Trying to connect to the cached remote server...");
153-
Initialize(); // Initialize the plugin now
162+
if (!(RelayService.Instance?.IsBackfeed ?? false)) Initialize();
154163
});
155164
}
156165

plugin_Relay/RelayService.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public int Initialize()
188188
ServerHost = MagicOnionHost.CreateDefaultBuilder()
189189
.UseMagicOnion(types: [typeof(DataService)],
190190
options: new MagicOnionOptions { IsReturnExceptionStackTraceInErrorDetail = true },
191-
ports: [new ServerPort("127.0.0.1", ServerPort, ServerCredentials.Insecure)],
191+
ports: [new ServerPort("0.0.0.0", ServerPort, ServerCredentials.Insecure)],
192192
channelOptions:
193193
[
194194
new ChannelOption(ChannelOptions.MaxReceiveMessageLength, -1),
@@ -314,6 +314,16 @@ public void Shutdown()
314314

315315
try
316316
{
317+
ServerBeacon?.Stop();
318+
}
319+
catch (Exception e)
320+
{
321+
Host?.Log(e);
322+
}
323+
324+
try
325+
{
326+
ServerBeacon?.Stop();
317327
ServerToken?.Cancel();
318328
ServerHost?.StopAsync();
319329

0 commit comments

Comments
 (0)