Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AGENTS.md

## App Overview
The app is a Windows/Linux desktop application designed to manage access to global CS2 and Deadlock servers by blocking
A Windows/Linux desktop application designed to manage access to global CS2, Deadlock and other configured game servers by blocking
or unblocking specific servers based on their geographic location. The primary function of this tool is server filtering for distributed gaming networks.

## Repository Overview
Expand Down Expand Up @@ -30,7 +30,7 @@ The output binary is located under `ServerPickerX/bin/Release/net10.0/<win-x64|l
## Linting & Formatting Guidelines
```bash
# Check formatting without making changes
# Requires dotnet-format to be installed (dotnet tool install -g dotnet-format)
# Requires dotnet-format (dotnet tool install -g dotnet-format)
dotnet format ServerPickerX.slnx --verify-no-changes

# Apply formatting automatically, ask for permission first before executing this command
Expand All @@ -39,8 +39,7 @@ dotnet format ServerPickerX.slnx
```

## Testing Guidelines
> **Note**: The repository currently contains no automated tests. When adding
> tests, follow these guidelines:
> **Note**: When adding tests, follow these guidelines:
>
> * Place test projects in a sibling folder named `Tests`.
> * Target the same framework (`net10.0`).
Expand Down Expand Up @@ -69,7 +68,7 @@ dotnet test --filter "FullyQualifiedName=ServerPickerX.Models.ServerModelTests.P
## Code Style Guidelines
| Area | Guideline |
|------|-----------|
| **Imports** | System namespaces first, then project namespaces. Keep `using` statements sorted alphabetically and grouped by scope. Remove unused usings with the built‑in IDE refactor.
| **Imports** | System namespaces first, then project namespaces. Keep `using` statements sorted alphabetically and grouped by scope.
| **Formatting** | 4 spaces per indentation level; no tabs. End each file with a single newline. Do not leave trailing whitespace on any line.
| **Naming** |
| &nbsp;&nbsp;*Public members (classes, methods, properties)* | PascalCase (e.g., `LoadServers`, `ClusterUnclusterServers`).
Expand All @@ -81,15 +80,15 @@ dotnet test --filter "FullyQualifiedName=ServerPickerX.Models.ServerModelTests.P
• Log errors with `FileLoggerService` and use `MessageBoxService` to display errors inside a catch block.
| **MVVM Conventions** |
| &nbsp;&nbsp;*ViewModels* | Inherit from `ObservableObject` (CommunityToolkit.Mvvm). Use `[ObservableProperty]` for properties that should notify UI changes. Keep commands as `ICommand` or `RelayCommand`.
| &nbsp;&nbsp;*Views* | Prefer code‑behind only for view logic that cannot be expressed in XAML, such as dynamic tooltips. Keep view models free of UI references.
| &nbsp;&nbsp;*Views* | Prefer code‑behind only for view logic that cannot be expressed in XAML, such as dynamic tooltips. Keep view models free of UI references except for displaying errors using messageboxes.
| **Resources** |
| &nbsp;&nbsp;*Images* | Store in `Assets/` and reference via pack URIs (`/Assets/...`).
| &nbsp;&nbsp;*Styles* | Define reusable styles in `Styles/*.axaml`. Register new style files by appending inside App.axaml inside `<Application.Styles></Application.Styles>`.

## Build & CI Checklist
- [ ] All tests pass (`dotnet test ServerPickerX.Tests.slnx`).
- [ ] Code passes linting (`dotnet format ServerPickerX.slnx --verify-no-changes`).
- [ ] Publish output contains a single executable without unnecessary dependencies except for files `libHarfBuzzSharp.so` and `libSkiaSharp.so`.
- [ ] Publish output contains an executable and other dependencies.

## Other Instructions
- If you are unsure how to do something, use `gh_grep` tools to search code examples from GitHub or use `context7` tools to search for project/code documentations
Expand Down
39 changes: 21 additions & 18 deletions ServerPickerX/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using ServerPickerX.Constants;
using ServerPickerX.Services.Localizations;
using ServerPickerX.Services.Loggers;
using ServerPickerX.Services.MessageBoxes;
Expand Down Expand Up @@ -44,34 +43,38 @@ public override void OnFrameworkInitializationCompleted()
serviceCollection.AddSingleton<JsonSetting>();
serviceCollection.AddSingleton<HttpClient>();

// Register concrete services and contionally provide these services through parent interface service resolver
serviceCollection.AddTransient<CS2ServerDataService>();
serviceCollection.AddTransient<CS2PerfectWorldServerDataService>();
serviceCollection.AddTransient<DeadLockServerDataService>();
serviceCollection.AddTransient<MarathonServerDataService>();
// Register a provider that loads definitions once and expose it as a singleton
serviceCollection.AddSingleton<ServerDefinitionProvider>();

// Register a factory for IServerDataService using JSON server definitions
serviceCollection.AddTransient<IServerDataService>(serviceProvider =>
{
JsonSetting jsonSetting = serviceProvider.GetRequiredService<JsonSetting>();
ILoggerService loggerService = serviceProvider.GetRequiredService<ILoggerService>();
JsonSetting jsonSetting = serviceProvider.GetRequiredService<JsonSetting>();

try
{
// Factory method may be suitable if more entries are added in the future
return jsonSetting.game_mode switch
// Get server definition by current game mode that contains app related metadata
var serverDefinitionProvider = serviceProvider.GetRequiredService<ServerDefinitionProvider>();
var serverDefinition = serverDefinitionProvider.GetServerDefinitionByGameMode(jsonSetting.game_mode);

if (serverDefinition != null)
{
GameModes.CounterStrike2 => serviceProvider.GetRequiredService<CS2ServerDataService>(),
GameModes.CounterStrike2PerfectWorld => serviceProvider.GetRequiredService<CS2PerfectWorldServerDataService>(),
GameModes.Deadlock => serviceProvider.GetRequiredService<DeadLockServerDataService>(),
GameModes.Marathon => serviceProvider.GetRequiredService<MarathonServerDataService>(),
_ => throw new NotSupportedException($"Unsupported game mode: {jsonSetting.game_mode}")
};
} catch (NotSupportedException ex)
// ActivatorUtilities will instantiate a given type and injects dependencies from existing DI container
// while missing dependencies are supplied as manual argument (serverDefinition)
IServerDataService? obj = ActivatorUtilities.CreateInstance<ConfiguredServerDataService>(serviceProvider, serverDefinition);

if (obj != null) return obj;
}

throw new InvalidOperationException("Failed to register service [IServerDataService]");
}
catch (InvalidOperationException ex)
{
loggerService.LogErrorAsync(ex.Message);

throw;
}

});
serviceCollection.AddTransient<WindowsFirewallService>();
serviceCollection.AddTransient<LinuxFirewallService>();
Expand Down Expand Up @@ -130,4 +133,4 @@ private void DisableAvaloniaDataAnnotationValidation()
}
}
}
}
}
15 changes: 0 additions & 15 deletions ServerPickerX/Constants/GameModes.cs

This file was deleted.

47 changes: 47 additions & 0 deletions ServerPickerX/ServerDefinitions.json
Comment thread
FN-FAL113 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"gameMode": "Counter Strike 2",
"id": "cs2",
"displayName": "CS2",
"appId": 730,
"keywordFilterMode": "exclude",
"keywords": [ "China" ],
"clusterKeywords": [ "Hong Kong", "Sweden", "India", "Netherlands" ]
},
{
"gameMode": "Counter Strike 2 (Perfect World)",
"id": "cs2_perfect_world",
"displayName": "CS2 Perfect World",
"appId": 730,
"keywordFilterMode": "include",
"keywords": [ "China" ],
"clusterKeywords": [ "Tencent", "Alibaba", "Perfect World" ]
},
{
"gameMode": "Deadlock",
"id": "deadlock",
"displayName": "Deadlock",
"appId": 1422450,
"keywordFilterMode": "none",
"keywords": [],
"clusterKeywords": [ "China", "Hong Kong", "Sweden", "India", "Netherlands" ]
},
{
"gameMode": "Marathon",
"id": "marathon",
"displayName": "Marathon",
"appId": 3065800,
"keywordFilterMode": "none",
"keywords": [],
"clusterKeywords": [ "Hong Kong", "Sweden", "India", "Netherlands" ]
},
{
"gameMode": "THE FINALS",
"id": "the_finals",
"displayName": "THE FINALS",
"appId": 2073850,
"keywordFilterMode": "none",
"keywords": [],
"clusterKeywords": [ "Sweden", "India", "Washington" ]
}
]
1 change: 0 additions & 1 deletion ServerPickerX/ServerPickerX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<AvaloniaResource Include="Styles\**" />
<AvaloniaResource Include="Locales\**" />
</ItemGroup>

<ItemGroup>
<Reference Include="Interop.NetFwTypeLib">
<HintPath>libs\Interop.NetFwTypeLib.dll</HintPath>
Expand Down
150 changes: 0 additions & 150 deletions ServerPickerX/Services/Servers/CS2ServerDataService.cs

This file was deleted.

Loading
Loading