Skip to content

Commit

Permalink
feat: adds console command to remove all tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ndorin committed Sep 16, 2024
1 parent 58ec192 commit cee8e8e
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ private void AddConsoleCommands()
CrestronConsole.AddNewConsoleCommand(GenerateClientTokenFromConsole, "MobileAddUiClient", "Adds a client and generates a token. ? for more help", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(RemoveToken, "MobileRemoveUiClient", "Removes a client. ? for more help", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand((s) => PrintClientInfo(), "MobileGetClientInfo", "Displays the current client info", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(RemoveAllTokens, "MobileRemoveAllUiClients", "Removes all clients", ConsoleAccessLevelEnum.AccessOperator);
}


Expand Down Expand Up @@ -794,6 +795,40 @@ private void GenerateClientTokenFromConsole(string s)
return (key, path);
}

/// <summary>
/// Removes all clients from the server
/// </summary>
private void RemoveAllTokens(string s)
{
if (s == "?" || string.IsNullOrEmpty(s))
{
CrestronConsole.ConsoleCommandResponse(@"Removes all clients from the server");
return;
}

foreach (var client in UiClients)
{
if (client.Value.Client != null && client.Value.Client.Context.WebSocket.IsAlive)
{
client.Value.Client.Context.WebSocket.Close(CloseStatusCode.Normal, "Server Shutting Down");
}

var path = _wsPath + client.Key;
if (_server.RemoveWebSocketService(path))
{
UiClients.Remove(client.Key);

CrestronConsole.ConsoleCommandResponse(string.Format("Client removed with token: {0}", client.Key));
}
else
{
CrestronConsole.ConsoleCommandResponse(string.Format("Unable to remove client with token : {0}", client.Key));
}
}

UpdateSecret();
}

/// <summary>
/// Removes a client with the specified token value
/// </summary>
Expand Down

0 comments on commit cee8e8e

Please sign in to comment.