Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displays reported panic bunker status for listed servers #128

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions SS14.Launcher/Api/ServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public sealed record ServerStatus(
int PlayerCount,
[property: JsonPropertyName("soft_max_players")]
int SoftMaxPlayerCount,
[property: JsonPropertyName("panic_bunker")]
bool? PanicBunker,
[property: JsonPropertyName("tags")] string[]? Tags);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions SS14.Launcher/Models/ServerStatus/IServerStatusData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface IServerStatusData : INotifyPropertyChanged
int PlayerCount { get; set; }

int SoftMaxPlayerCount { get; set; }

bool? PanicBunker { get; set; }
}
7 changes: 7 additions & 0 deletions SS14.Launcher/Models/ServerStatus/ServerStatusCache.Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public sealed class ServerStatusData : ObservableObject, IServerStatusData
private TimeSpan? _ping;
private int _playerCount;
private int _softMaxPlayerCount;
private bool? _panicBunker;
private ServerStatusCode _status = ServerStatusCode.FetchingStatus;
private ServerStatusInfoCode _statusInfo = ServerStatusInfoCode.NotFetched;
private ServerInfoLink[]? _links;
Expand Down Expand Up @@ -77,6 +78,12 @@ public int SoftMaxPlayerCount
set => SetProperty(ref _softMaxPlayerCount, value);
}

public bool? PanicBunker
{
get => _panicBunker;
set => SetProperty(ref _panicBunker, value);
}

public ServerInfoLink[]? Links
{
get => _links;
Expand Down
1 change: 1 addition & 0 deletions SS14.Launcher/Models/ServerStatus/ServerStatusCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public static void ApplyStatus(ServerStatusData data, ServerApi.ServerStatus sta
data.Name = status.Name;
data.PlayerCount = status.PlayerCount;
data.SoftMaxPlayerCount = status.SoftMaxPlayerCount;
data.PanicBunker = status.PanicBunker;

var baseTags = status.Tags ?? Array.Empty<string>();
var inferredTags = ServerTagInfer.InferTags(status);
Expand Down
1 change: 1 addition & 0 deletions SS14.Launcher/Utility/ServerFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ public enum ServerFilterCategory : byte
EighteenPlus = 4,
PlayerCount = 5,
Hub = 6,
Bunker = 7,
}
38 changes: 38 additions & 0 deletions SS14.Launcher/ViewModels/MainWindowTabs/ServerEntryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,38 @@ public string ServerStatusString
}
}

public string BunkerIcon
{
get
{
switch (_cacheData.PanicBunker)
{
case true:
return "⏲️"; //TODO: replace this with a proper icon. This might be doable in 126? We'd rather not step on Visne's toes for now, so a system-dependant emoji will do.
case null:
return "?";
default:
return "";
}
}
}

public string BunkerText
{
get
{
switch (_cacheData.PanicBunker)
{
case true:
return "Panic Bunker Enabled";
case false:
return "Panic Bunker Disabled";
default:
return "Missing Panic Bunker Information";
}
}
}

public string Description
{
get
Expand Down Expand Up @@ -213,6 +245,12 @@ private void OnCacheDataOnPropertyChanged(object? _, PropertyChangedEventArgs ar
OnPropertyChanged(nameof(ServerStatusString));
break;

case nameof(IServerStatusData.PanicBunker):
OnPropertyChanged(nameof(ServerStatusString));
OnPropertyChanged(nameof(BunkerIcon));
OnPropertyChanged(nameof(BunkerText));
break;

case nameof(IServerStatusData.Status):
OnPropertyChanged(nameof(IsOnline));
OnPropertyChanged(nameof(ServerStatusString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public sealed partial class ServerListFiltersViewModel : ObservableObject
private readonly FilterListCollection _filtersRolePlay = new();
private readonly FilterListCollection _filtersEighteenPlus = new();
private readonly FilterListCollection _filtersHub = new();
private readonly FilterListCollection _filtersBunker = new();

public ObservableCollection<ServerFilterViewModel> FiltersLanguage => _filtersLanguage;
public ObservableCollection<ServerFilterViewModel> FiltersRegion => _filtersRegion;
public ObservableCollection<ServerFilterViewModel> FiltersRolePlay => _filtersRolePlay;
public ObservableCollection<ServerFilterViewModel> FiltersEighteenPlus => _filtersEighteenPlus;
public ObservableCollection<ServerFilterViewModel> FiltersHub => _filtersHub;
public ObservableCollection<ServerFilterViewModel> FiltersBunker => _filtersBunker;

public ServerFilterViewModel FilterPlayerCountHideEmpty { get; }
public ServerFilterViewModel FilterPlayerCountHideFull { get; }
Expand Down Expand Up @@ -73,6 +75,11 @@ public ServerListFiltersViewModel(DataManager dataManager, LocalizationManager l
_loc.GetString("filters-18-no"),
new ServerFilter(ServerFilterCategory.EighteenPlus, ServerFilter.DataFalse), this));

FiltersBunker.Add(new ServerFilterViewModel("Yes", "Yes",
new ServerFilter(ServerFilterCategory.Bunker, ServerFilter.DataTrue), this));
FiltersBunker.Add(new ServerFilterViewModel("No", "No",
new ServerFilter(ServerFilterCategory.Bunker, ServerFilter.DataFalse), this));

FilterPlayerCountHideEmpty = new ServerFilterViewModel(
_loc.GetString("filters-player-count-hide-empty-desc"),
_loc.GetString("filters-player-count-hide-empty"),
Expand Down Expand Up @@ -276,6 +283,21 @@ public void ApplyFilters(List<ServerStatusData> list)
eighteenPlus = false;
}

bool? panicBunker = null;
if (GetFilter(ServerFilterCategory.Bunker, ServerFilter.DataTrue))
{
panicBunker = true;
}

if (GetFilter(ServerFilterCategory.Bunker, ServerFilter.DataFalse))
{
// Having both
if (panicBunker == true)
panicBunker = null;
else
panicBunker = false;
}

for (var i = 0; i < list.Count; i++)
{
var server = list[i];
Expand All @@ -299,6 +321,12 @@ bool DoesServerMatch(ServerStatusData server)
return false;
}

if (panicBunker != null)
{
if (panicBunker != server.PanicBunker)
return false;
}

if (!CheckCategoryFilterSet(categorySetLanguage, server.Tags, Tags.TagLanguage, PrimaryLanguageTag))
return false;

Expand Down
8 changes: 8 additions & 0 deletions SS14.Launcher/Views/MainWindowTabs/ServerEntryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
MinWidth="80"
Margin="10, 0" />
<Rectangle DockPanel.Dock="Right" Classes="VerticalSeparator" />
<TextBlock DockPanel.Dock="Right" VerticalAlignment="Center"
TextAlignment="Center" Text="{Binding BunkerIcon}"
MinWidth="20" Margin="5, 0" ToolTip.ShowDelay="0">
<ToolTip.Tip>
<TextBlock Text="{Binding BunkerText}" />
</ToolTip.Tip>
</TextBlock>
<Rectangle DockPanel.Dock="Right" Classes="VerticalSeparator" />
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" TextTrimming="CharacterEllipsis"/>
</DockPanel>
</Expander.Header>
Expand Down
5 changes: 5 additions & 0 deletions SS14.Launcher/Views/MainWindowTabs/ServerListFiltersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<ItemsControl ItemsSource="{Binding FiltersEighteenPlus}"
ItemsPanel="{StaticResource PanelTemplate}" ItemTemplate="{StaticResource FilterTemplate}"/>
</DockPanel>
<DockPanel Classes="ServerFilterGroup">
<TextBlock MinWidth="150" DockPanel.Dock="Left" VerticalAlignment="Center" Classes="SubText" Text="Panic Bunker" />
<ItemsControl ItemsSource="{Binding FiltersBunker}"
ItemsPanel="{StaticResource PanelTemplate}" ItemTemplate="{StaticResource FilterTemplate}"/>
</DockPanel>

<DockPanel Classes="ServerFilterGroup">
<TextBlock MinWidth="150" DockPanel.Dock="Left" Classes="SubText" Text="{loc:Loc filters-title-hub}" />
Expand Down
11 changes: 11 additions & 0 deletions SS14.Launcher/Views/MainWindowTabs/ServerListTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
<Rectangle DockPanel.Dock="Right" Classes="VerticalSeparator"/>
<TextBlock DockPanel.Dock="Right" Text="{loc:Loc tab-servers-table-players}" Classes="SubText" TextAlignment="Center" MinWidth="80" Margin="10 0"/>
<Rectangle DockPanel.Dock="Right" Classes="VerticalSeparator" />
<TextBlock DockPanel.Dock="Right" Text="⏲️" Classes="SubText" TextAlignment="Center" MinWidth="20" Margin="5 0" ToolTip.ShowDelay="0">
<ToolTip.Tip>
<StackPanel>
<TextBlock TextAlignment="Left" Text="Panic bunker status. Servers with a panic bunker enabled" />
<TextBlock TextAlignment="Left" Text="are not accepting new players, and might have specific" />
<TextBlock TextAlignment="Left" Text="requirements to connect, such as a playtime prerequisite," />
<TextBlock TextAlignment="Left" Text="or a manual whitelist process." />
</StackPanel>
</ToolTip.Tip>
</TextBlock>
<Rectangle DockPanel.Dock="Right" Classes="VerticalSeparator" />
<TextBlock Text="{loc:Loc tab-servers-table-name}" Classes="SubText"/>
</DockPanel>

Expand Down
Loading