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
52 changes: 43 additions & 9 deletions Knossos.NET/Models/GlobalSettings.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

using System.Text.Json;
using Avalonia.Threading;
using IniParser;
using Knossos.NET.Classes;
using Knossos.NET.ViewModels;
using System;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using Knossos.NET.Classes;
using IniParser;
using Avalonia.Threading;
using Knossos.NET.ViewModels;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using Knossos.NET.Views;

namespace Knossos.NET.Models
{
Expand Down Expand Up @@ -88,6 +87,37 @@ public AutoUpdateFsoBuilds(bool stable = false, bool rc = false, bool nightly =
}
}

public struct StandaloneServerSettings
{

public StandaloneServerSettings(MultiCfg multiCfg, string id, string version, int buildType) : this()
{
this.extraOptions = multiCfg.Others;
this.banList = multiCfg.Ban;
this.pxoChannel = multiCfg.PXOChannel;
this.usePxo = multiCfg.UsePXO;
this.noVoice = multiCfg.NoVoice;
this.port = multiCfg.Port;
this.name = multiCfg.Name;
this.password = multiCfg.Password;
this.buildType = buildType;
this.modId = id;
this.modVersion = version;
}

public List<string> extraOptions { get; set; }
public List<string> banList { get; set; }
public string? pxoChannel { get; set; }
public bool usePxo { get; set; }
public bool noVoice { get; set; }
public int port { get; set; }
public string? name { get; set; }
public string? password { get; set; }
public int buildType { get; set; }
public string modId { get; set; }
public string modVersion { get; set; }
}

/* Knossos Settings */
[JsonPropertyName("base_path")]
public string? basePath { get; set; } = null;
Expand Down Expand Up @@ -139,6 +169,9 @@ public bool closeToTray {
[JsonPropertyName("ignored_launcher_updates")]
public List<string> ignoredLauncherUpdates { get; set; } = new List<string>();

[JsonPropertyName("standalone_server_settings")]
public StandaloneServerSettings? standaloneServerSettings { get; set;} = null;

/*
* Settings that can wait to be saved at app close so we dont have to call save() all the time
* use JsonIgnore, private and '_' for the actual variable name
Expand Down Expand Up @@ -699,6 +732,7 @@ public void Load()
}
MainWindowViewModel.Instance?.InstalledModsView?.ResetFilters();
}
standaloneServerSettings = tempSettings.standaloneServerSettings;
ReadFS2IniValues();
Log.Add(Log.LogSeverity.Information, "GlobalSettings.Load()", "Global settings have been loaded");

Expand Down
5 changes: 4 additions & 1 deletion Knossos.NET/Models/MultiCfg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class MultiCfg
/// Data is saved in {modfolder}\data\multi.cfg
/// </summary>
/// <param name="mod"></param>
public void LoadData(Mod mod)
/// Returns true/false if successfull
public bool LoadData(Mod mod)
{
UsePXO = false;
NoVoice = false;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void LoadData(Mod mod)
Others.Add(line.ToLower());
}
}
return true;
}
else
{
Expand All @@ -101,6 +103,7 @@ public void LoadData(Mod mod)
{
Log.Add(Log.LogSeverity.Error, "MultiCfg.LoadData()", ex);
}
return false;
}

/// <summary>
Expand Down
33 changes: 31 additions & 2 deletions Knossos.NET/ViewModels/Windows/ServerCreatorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Knossos.NET.Classes;
using Knossos.NET.Models;
using Knossos.NET.Views;
using System;
Expand Down Expand Up @@ -66,6 +67,22 @@ internal int ModIndex
[ObservableProperty]
public int buildType = 0;

public ServerCreatorViewModel()
{
//load last selected mod
if (Knossos.globalSettings.standaloneServerSettings != null)
{
var selectedMod = listOfMods.FirstOrDefault(x => x.id == Knossos.globalSettings.standaloneServerSettings.Value.modId
&& x.version == Knossos.globalSettings.standaloneServerSettings.Value.modVersion);
if (selectedMod != null)
{
var index = listOfMods.IndexOf(selectedMod);
if(index >= 0)
ModIndex = index;
}
}
}

/// <summary>
/// Load multi.cfg file for the currently selected mod in the list
/// </summary>
Expand All @@ -78,9 +95,19 @@ internal void LoadCFG()
PxoChannel = "#Eleh";
try
{
if (ModIndex >= 0)
if (Knossos.globalSettings.standaloneServerSettings != null)
{
BanList = string.Join(Environment.NewLine, Knossos.globalSettings.standaloneServerSettings.Value.banList);
ExtraOptions = string.Join(Environment.NewLine, Knossos.globalSettings.standaloneServerSettings.Value.extraOptions);
Name = Knossos.globalSettings.standaloneServerSettings.Value.name;
Password = Knossos.globalSettings.standaloneServerSettings.Value.password;
UsePxo = Knossos.globalSettings.standaloneServerSettings.Value.usePxo;
NoVoice = Knossos.globalSettings.standaloneServerSettings.Value.noVoice;
Port = Knossos.globalSettings.standaloneServerSettings.Value.port;
PxoChannel = Knossos.globalSettings.standaloneServerSettings.Value.pxoChannel ?? "#Eleh";
}
if (ModIndex >= 0 && Cfg.LoadData(ListOfMods[ModIndex]))
{
Cfg.LoadData(ListOfMods[ModIndex]);
UsePxo = Cfg.UsePXO;
Name = Cfg.Name;
Password = Cfg.Password;
Expand Down Expand Up @@ -134,6 +161,8 @@ internal void SaveCFG()
Cfg.Others = ExtraOptions.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries).ToList();
}
Cfg.SaveData(ListOfMods[ModIndex]);
Knossos.globalSettings.standaloneServerSettings = new GlobalSettings.StandaloneServerSettings(Cfg, ListOfMods[ModIndex].id, ListOfMods[ModIndex].version, BuildType);
Knossos.globalSettings.Save();
}
}
catch (Exception ex)
Expand Down