Skip to content

Commit

Permalink
Fix Server getting saved with ServerOverride's value which never shou…
Browse files Browse the repository at this point in the history
…ld've happened. EffectiveServer is a property that takes the override into account but does not get saved to YAML, as I intended it.

If in the next month someone has 'Server: localhost' in their config, it'll be reset because it may have been the oopsie.

But at least with the new mod option labels and warning it'll be noticable either way.
  • Loading branch information
RedFlames committed Aug 25, 2024
1 parent 2f40296 commit 41bae2a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
10 changes: 9 additions & 1 deletion CelesteNet.Client/CelesteNetClientModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public int FailedReconnectCount {
private set {
_FailedReconnectCount = value;

if (value >= FailedReconnectThreshold && Settings.Server != CelesteNetClientSettings.DefaultServer) {
if (value >= FailedReconnectThreshold && Settings.EffectiveServer != CelesteNetClientSettings.DefaultServer) {
Settings.ConnectDefaultVisible = true;
Settings.WantsToBeConnected = false;
}
Expand Down Expand Up @@ -187,6 +187,14 @@ public override void LoadSettings() {
if (string.IsNullOrWhiteSpace(Settings.Server) || Settings.Server == "celeste.0x0ade.ga" || Settings.Server == "celestenet.0x0ade.ga")
Settings.Server = CelesteNetClientSettings.DefaultServer;

// So I did an oopsie, with how the 'Server' property getter was for convenience returning the ServerOverride when it's set,
// but I had entirely forgotten that this actual getter value will be saved to the settings file... for some reason I didn't think of this
// and obviously didn't intend it this way.
// So uhm, for the next month only, reset people who have "Server: localhost" in their yaml? :catplush:
if (Settings.Server == "localhost" && DateTime.UtcNow.Month < 10 && DateTime.UtcNow.Year == 2024) {
Settings.Server = CelesteNetClientSettings.DefaultServer;
}

if (Settings.Emotes == null || Settings.Emotes.Length == 0) {
Settings.Emotes = new string[] {
"i:collectables/heartgem/0/spin",
Expand Down
43 changes: 23 additions & 20 deletions CelesteNet.Client/CelesteNetClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,27 @@ public bool ConnectDefaultVisible {
public TextMenu.OnOff ReceivePlayerAvatarsEntry { get; protected set; }

public const string DefaultServer = "celeste.0x0a.de";
#if DEBUG
[SettingSubHeader("modoptions_celestenetclient_subheading_general")]
#else
[SettingIgnore]
#endif
[SettingSubText("modoptions_celestenetclient_devonlyhint")]
public string Server {
get => ServerOverride.IsNullOrEmpty() ? _Server : ServerOverride;
set {
if (_Server == value)

[SettingIgnore, YamlIgnore]
public string EffectiveServer {
get => ServerOverride.IsNullOrEmpty() ? Server : ServerOverride;
private set {
if (Server == value)
return;

_Server = value;
Server = value;

UpdateServerInDialogs();
}
}
private string _Server = DefaultServer;

#if DEBUG
[SettingSubHeader("modoptions_celestenetclient_subheading_general")]
#else
[SettingIgnore]
#endif
[SettingSubText("modoptions_celestenetclient_devonlyhint")]
public string Server { get; set; } = DefaultServer;

// Any non-empty string will override Server property temporarily. (setting not saved)
// Currently only used for "connect locally" button (for Nucleus etc.)
Expand All @@ -135,16 +138,16 @@ public string ServerOverride {
// best way I can come up with to do this in various places, rather than a lot of erratic logic in Server & ServerOverride setters
public void UpdateServerInDialogs() {
if (ServerEntry != null)
ServerEntry.Label = "modoptions_celestenetclient_server".DialogClean().Replace("((server))", Server);
ServerEntry.Label = "modoptions_celestenetclient_server".DialogClean().Replace("((server))", EffectiveServer);

if (EnabledEntry != null)
EnabledEntry.Label = "modoptions_celestenetclient_connected".DialogClean().Replace("((server))", Server);
EnabledEntry.Label = "modoptions_celestenetclient_connected".DialogClean().Replace("((server))", EffectiveServer);

if (ConnectDefaultButton != null)
ConnectDefaultButton.Label = "modoptions_celestenetclient_connectdefault".DialogClean().Replace("((default))", DefaultServer);

if (ConnectDefaultButtonHint != null)
ConnectDefaultButtonHint.Title = "modoptions_celestenetclient_connectdefaulthint".DialogClean().Replace("((server))", Server);
ConnectDefaultButtonHint.Title = "modoptions_celestenetclient_connectdefaulthint".DialogClean().Replace("((server))", EffectiveServer);
}

private string _ServerOverride = "";
Expand Down Expand Up @@ -801,7 +804,7 @@ private float CalcUIScale(int uisize) {
[SettingIgnore, YamlIgnore]
public string Host {
get {
string server = Server?.ToLowerInvariant();
string server = EffectiveServer?.ToLowerInvariant();
int indexOfPort;
if (!string.IsNullOrEmpty(server) &&
(indexOfPort = server.LastIndexOf(':')) != -1 &&
Expand All @@ -814,7 +817,7 @@ public string Host {
[SettingIgnore, YamlIgnore]
public int Port {
get {
string server = Server;
string server = EffectiveServer;
int indexOfPort;
if (!string.IsNullOrEmpty(server) &&
(indexOfPort = server.LastIndexOf(':')) != -1 &&
Expand Down Expand Up @@ -861,15 +864,15 @@ public TextMenu.Button CreateMenuStringInput(TextMenu menu, string dialogLabel,

public void CreateConnectedEntry(TextMenu menu, bool inGame) {
menu.Add(
(EnabledEntry = new TextMenu.OnOff("modoptions_celestenetclient_connected".DialogClean().Replace("((server))", Server), Connected))
(EnabledEntry = new TextMenu.OnOff("modoptions_celestenetclient_connected".DialogClean().Replace("((server))", EffectiveServer), Connected))
.Change(v => Connected = v)
);
EnabledEntry.AddDescription(menu, "modoptions_celestenetclient_connectedhint".DialogClean());
}

public void CreateServerEntry(TextMenu menu, bool inGame) {
#if DEBUG
ServerEntry = CreateMenuStringInput(menu, "SERVER", s => s.Replace("((server))", Server), 30, () => Server, newVal => Server = newVal);
ServerEntry = CreateMenuStringInput(menu, "SERVER", s => s.Replace("((server))", EffectiveServer), 30, () => EffectiveServer, newVal => EffectiveServer = newVal);
ServerEntry.Disabled = inGame || Connected;
ServerEntry.AddDescription(menu, "modoptions_celestenetclient_devonlyhint".DialogClean());
#endif
Expand Down Expand Up @@ -1034,7 +1037,7 @@ public void CreateConnectDefaultButtonEntry(TextMenu menu, bool inGame) {
});

ConnectDefaultButtonHint = null;
ConnectDefaultButton.AddDescription(menu, "modoptions_celestenetclient_connectdefaulthint".DialogClean().Replace("((server))", Server));
ConnectDefaultButton.AddDescription(menu, "modoptions_celestenetclient_connectdefaulthint".DialogClean().Replace("((server))", EffectiveServer));

int descriptionIndex = menu.Items.IndexOf(ConnectDefaultButton) + 1;
if (descriptionIndex > 0 && descriptionIndex < menu.Items.Count && menu.Items[descriptionIndex] is TextMenuExt.EaseInSubHeaderExt desc)
Expand Down

0 comments on commit 41bae2a

Please sign in to comment.