Skip to content

Commit

Permalink
new setting: Shines/Excluded
Browse files Browse the repository at this point in the history
To exclude specific shines to be synced to other clients.

Pre-initialized with shine 496 (Moon Shards in the Sand) that causes people to get stuck in front of the inverted pyramid.

This commit fixes issue #31
  • Loading branch information
Istador authored and Sanae6 committed Apr 27, 2024
1 parent 20ee74d commit 61e6fcf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
29 changes: 26 additions & 3 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async Task ClientSyncShineBag(Client client) {
try {
if ((bool?) client.Metadata["speedrun"] ?? false) return;
ConcurrentBag<int> clientBag = (ConcurrentBag<int>) (client.Metadata["shineSync"] ??= new ConcurrentBag<int>());
foreach (int shine in shineBag.Except(clientBag).ToArray()) {
foreach (int shine in shineBag.Except(clientBag).Except(Settings.Instance.Shines.Excluded).ToArray()) {
if (!client.Connected) return;
await client.Send(new ShinePacket {
ShineId = shine
Expand Down Expand Up @@ -196,6 +196,10 @@ void logError(Task x) {

case ShinePacket shinePacket: {
if (!Settings.Instance.Shines.Enabled) return false;
if (Settings.Instance.Shines.Excluded.Contains(shinePacket.ShineId)) {
c.Logger.Info($"Got moon {shinePacket.ShineId} (excluded)");
return false;
}
if (c.Metadata["loadedSave"] is false) break;
ConcurrentBag<int> playerBag = (ConcurrentBag<int>)c.Metadata["shineSync"]!;
shineBag.Add(shinePacket.ShineId);
Expand Down Expand Up @@ -558,12 +562,16 @@ await server.Broadcast(new TagPacket {
});

CommandHandler.RegisterCommand("shine", args => {
const string optionUsage = "Valid options: list, clear, sync, send, set";
const string optionUsage = "Valid options: list, clear, sync, send, set, include, exclude";
if (args.Length < 1)
return optionUsage;
switch (args[0]) {
case "list" when args.Length == 1:
return $"Shines: {string.Join(", ", shineBag)}";
return $"Shines: {string.Join(", ", shineBag)}" + (
Settings.Instance.Shines.Excluded.Count() > 0
? "\nExcluded Shines: " + string.Join(", ", Settings.Instance.Shines.Excluded)
: ""
);
case "clear" when args.Length == 1:
shineBag.Clear();
Task.Run(async () => {
Expand Down Expand Up @@ -600,6 +608,21 @@ await c.Send(new ShinePacket {

return optionUsage;
}
case "exclude" when args.Length == 2:
case "include" when args.Length == 2: {
if (int.TryParse(args[1], out int sid)) {
if (args[0] == "exclude") {
Settings.Instance.Shines.Excluded.Add(sid);
Settings.SaveSettings();
return $"Exclude shine {sid} from syncing.";
} else {
Settings.Instance.Shines.Excluded.Remove(sid);
Settings.SaveSettings();
return $"No longer exclude shine {sid} from syncing.";
}
}
return optionUsage;
}
default:
return optionUsage;
}
Expand Down
1 change: 1 addition & 0 deletions Server/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class DiscordTable {

public class ShineTable {
public bool Enabled { get; set; } = true;
public ISet<int> Excluded { get; set; } = new SortedSet<int> { 496 };
}

public class PersistShinesTable
Expand Down

0 comments on commit 61e6fcf

Please sign in to comment.