Skip to content

Commit 4a390e4

Browse files
blackspherefollowerqdot
authored andcommitted
Adding disconnect button
Now you can kick the client from the server GUI. Fixes #205
1 parent ca30e84 commit 4a390e4

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Buttplug.Apps.WebsocketServerGUI/WebsocketServerControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<Label Content="Status:" Grid.Row="2" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top"/>
3333
<Label Name="ConnStatus" Content="(Not Connected)" Grid.Row="2" HorizontalAlignment="Left" Margin="100,00,0,0" VerticalAlignment="Top"/>
34+
<Button Name="DisconnectButton" Height="25" Grid.Row="2" Content="Disconnect" IsEnabled="False" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Top" Width="75" Click="DisconnectButton_Click"/>
3435
</Grid>
3536
</GroupBox>
3637

Buttplug.Apps.WebsocketServerGUI/WebsocketServerControl.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private void WebSocketConnectionAccepted(object aObj, [NotNull] ConnectionEventA
6262
Dispatcher.InvokeAsync(() =>
6363
{
6464
ConnStatus.Content = "(Connected) " + aEvent.ClientName;
65+
DisconnectButton.IsEnabled = true;
6566
});
6667
}
6768

@@ -70,6 +71,7 @@ private void WebSocketConnectionClosed(object aObj, [NotNull] ConnectionEventArg
7071
Dispatcher.InvokeAsync(() =>
7172
{
7273
ConnStatus.Content = "(Not Connected)";
74+
DisconnectButton.IsEnabled = false;
7375
});
7476
}
7577

@@ -84,6 +86,8 @@ public void StartServer()
8486
ConnectionUrl.Text = (_secure ? "wss" : "ws") + "://localhost:" + _port.ToString() + "/buttplug";
8587
TestUrl.Inlines.Clear();
8688
TestUrl.Inlines.Add((_secure ? "https" : "http") + "://localhost:" + _port.ToString());
89+
ConnStatus.Content = "(Not Connected)";
90+
DisconnectButton.IsEnabled = false;
8791
ConnInfo.Visibility = Visibility.Visible;
8892
}
8993
catch (SocketException e)
@@ -140,5 +144,10 @@ private void TestUrl_RequestNavigate(object sender, System.Windows.Navigation.Re
140144
{
141145
System.Diagnostics.Process.Start(new Uri((_secure ? "https" : "http") + "://localhost:" + _port.ToString()).AbsoluteUri);
142146
}
147+
148+
private void DisconnectButton_Click(object sender, RoutedEventArgs e)
149+
{
150+
_ws.Disconnect();
151+
}
143152
}
144153
}

Buttplug.Components.WebsocketServer/ButtplugWebsocketServer.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,23 @@ public void StopServer()
192192
{
193193
_server?.Stop();
194194
}
195+
196+
public void Disconnect(string remoteId = null)
197+
{
198+
if (remoteId == null)
199+
{
200+
foreach (var conn in _connections.Values)
201+
{
202+
conn.Close();
203+
}
204+
205+
return;
206+
}
207+
208+
if (_connections.TryGetValue(remoteId, out WebSocket ws))
209+
{
210+
ws.Close();
211+
}
212+
}
195213
}
196214
}

0 commit comments

Comments
 (0)