feat: Customize expansion and set maps on first boot (#1425)
This commit is contained in:
parent
3ffe049e08
commit
a9a2a89908
45 changed files with 700 additions and 269 deletions
|
|
@ -7,7 +7,9 @@ using System.Buffers;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Server.Buffers;
|
||||
using Server.Buffers;
|
||||
|
||||
namespace Server.Text;
|
||||
|
||||
public ref struct ValueStringBuilder
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Buffers;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public struct ArrayEnumerator<T> : IEnumerator<T>
|
|||
|
||||
if ((uint)_index < (uint)localList.Length)
|
||||
{
|
||||
_current = _array[_index++];
|
||||
_current = localList[_index++];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
118
Projects/Server/Configuration/ExpansionConfigurationPrompts.cs
Normal file
118
Projects/Server/Configuration/ExpansionConfigurationPrompts.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
using Server.Maps;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public static class ExpansionConfigurationPrompts
|
||||
{
|
||||
internal static Expansion GetExpansion()
|
||||
{
|
||||
Console.WriteLine("Please choose an expansion by typing the number or short name:");
|
||||
var expansions = ExpansionInfo.Table;
|
||||
|
||||
for (var i = 0; i < expansions.Length; i++)
|
||||
{
|
||||
var info = expansions[i];
|
||||
Console.WriteLine(" - {0,2}: {1} ({2})", i, ((Expansion)info.Id).ToString(), info.Name);
|
||||
}
|
||||
|
||||
var maxExpansion = (Expansion)expansions[^1].Id;
|
||||
var maxExpansionName = maxExpansion.ToString();
|
||||
|
||||
do
|
||||
{
|
||||
Console.Write("[enter for {0}]> ", maxExpansionName);
|
||||
var input = Console.ReadLine();
|
||||
Expansion expansion;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
expansion = maxExpansion;
|
||||
}
|
||||
else if (int.TryParse(input, NumberStyles.Integer, null, out var number) &&
|
||||
number >= 0 && number < expansions.Length)
|
||||
{
|
||||
expansion = (Expansion)number;
|
||||
}
|
||||
else if (!Enum.TryParse(input, out expansion))
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.Write(input);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(" is an invalid expansion option.");
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.Write("Expansion set to ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.Write(ExpansionInfo.GetInfo(expansion).Name);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(".");
|
||||
return expansion;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
internal static void OutputSelectedMaps(Expansion expansion, MapSelectionFlags selectedMaps)
|
||||
{
|
||||
Console.WriteLine("Selected maps:");
|
||||
|
||||
var i = 0;
|
||||
foreach (var flag in MapSelection.EnumFromExpansion(expansion))
|
||||
{
|
||||
Console.WriteLine($"{i + 1}. {flag} [{(selectedMaps.Includes(flag) ? "*" : "")}]");
|
||||
i++;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"[1-{i} and enter to toggle, or enter to finish]");
|
||||
}
|
||||
|
||||
internal static MapSelectionFlags GetSelectedMaps(Expansion expansion)
|
||||
{
|
||||
var expansionMaps = ExpansionInfo.GetInfo(expansion).MapSelectionFlags;
|
||||
var selectedMaps = expansionMaps;
|
||||
|
||||
string lastInput;
|
||||
do
|
||||
{
|
||||
OutputSelectedMaps(expansion, selectedMaps);
|
||||
lastInput = Console.ReadLine()?.TrimEnd();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lastInput))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!int.TryParse(lastInput, out var selectedNumber))
|
||||
{
|
||||
Console.WriteLine("You need to choose a number, or press ENTER on its own to accept");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectedNumber is < 1 or > 31)
|
||||
{
|
||||
Console.WriteLine("That number was not an option. Please try again...");
|
||||
continue;
|
||||
}
|
||||
|
||||
var selectedFlag = (MapSelectionFlags)(1 << (selectedNumber - 1));
|
||||
|
||||
if (!expansionMaps.Includes(selectedFlag))
|
||||
{
|
||||
Console.WriteLine("That number was not an option. Please try again...");
|
||||
continue;
|
||||
}
|
||||
|
||||
selectedMaps.Toggle(selectedFlag);
|
||||
} while (lastInput != "");
|
||||
|
||||
Console.WriteLine("These maps will be populated and moongates will not lead to other maps: ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.WriteLine(selectedMaps.ToCommaDelimitedString());
|
||||
Utility.PopColor();
|
||||
Console.WriteLine($"To change the selected maps, modify {ExpansionInfo.ExpansionConfigurationPath}.");
|
||||
|
||||
return selectedMaps;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,56 +28,57 @@ public static class ServerConfiguration
|
|||
|
||||
private const string _relPath = "Configuration/modernuo.json";
|
||||
private static readonly string m_FilePath = Path.Join(Core.BaseDirectory, _relPath);
|
||||
private static ServerSettings m_Settings;
|
||||
|
||||
private static ServerSettings _settings;
|
||||
private static bool m_Mocked;
|
||||
|
||||
public static List<string> AssemblyDirectories => m_Settings.AssemblyDirectories;
|
||||
public static List<string> AssemblyDirectories => _settings.AssemblyDirectories;
|
||||
|
||||
public static HashSet<string> DataDirectories => m_Settings.DataDirectories;
|
||||
public static HashSet<string> DataDirectories => _settings.DataDirectories;
|
||||
|
||||
public static List<IPEndPoint> Listeners => m_Settings.Listeners;
|
||||
public static List<IPEndPoint> Listeners => _settings.Listeners;
|
||||
|
||||
public static string ConfigurationFilePath => _relPath;
|
||||
|
||||
public static ClientVersion GetSetting(string key, ClientVersion defaultValue) =>
|
||||
m_Settings.Settings.TryGetValue(key, out var value) ? new ClientVersion(value) : defaultValue;
|
||||
_settings.Settings.TryGetValue(key, out var value) ? new ClientVersion(value) : defaultValue;
|
||||
|
||||
public static string GetSetting(string key, string defaultValue) =>
|
||||
m_Settings.Settings.TryGetValue(key, out var value) ? value : defaultValue;
|
||||
_settings.Settings.TryGetValue(key, out var value) ? value : defaultValue;
|
||||
|
||||
public static int GetSetting(string key, int defaultValue)
|
||||
{
|
||||
m_Settings.Settings.TryGetValue(key, out var strValue);
|
||||
_settings.Settings.TryGetValue(key, out var strValue);
|
||||
return int.TryParse(strValue, out var value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
public static long GetSetting(string key, long defaultValue)
|
||||
{
|
||||
m_Settings.Settings.TryGetValue(key, out var strValue);
|
||||
_settings.Settings.TryGetValue(key, out var strValue);
|
||||
return long.TryParse(strValue, out var value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
public static bool GetSetting(string key, bool defaultValue)
|
||||
{
|
||||
m_Settings.Settings.TryGetValue(key, out var strValue);
|
||||
_settings.Settings.TryGetValue(key, out var strValue);
|
||||
return bool.TryParse(strValue, out var value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
public static T GetSetting<T>(string key, T defaultValue) where T : struct, Enum
|
||||
{
|
||||
m_Settings.Settings.TryGetValue(key, out var strValue);
|
||||
_settings.Settings.TryGetValue(key, out var strValue);
|
||||
return Enum.TryParse(strValue, out T value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
public static double GetSetting(string key, double defaultValue)
|
||||
{
|
||||
m_Settings.Settings.TryGetValue(key, out var strValue);
|
||||
_settings.Settings.TryGetValue(key, out var strValue);
|
||||
return double.TryParse(strValue, out var value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
public static T? GetSetting<T>(string key) where T : struct, Enum
|
||||
{
|
||||
if (!m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (!_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -87,7 +88,7 @@ public static class ServerConfiguration
|
|||
|
||||
public static string GetOrUpdateSetting(string key, string defaultValue)
|
||||
{
|
||||
if (m_Settings.Settings.TryGetValue(key, out var value))
|
||||
if (_settings.Settings.TryGetValue(key, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
|
@ -100,7 +101,7 @@ public static class ServerConfiguration
|
|||
{
|
||||
int value;
|
||||
|
||||
if (m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = int.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
|
|
@ -116,7 +117,7 @@ public static class ServerConfiguration
|
|||
{
|
||||
long value;
|
||||
|
||||
if (m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = long.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
|
|
@ -132,7 +133,7 @@ public static class ServerConfiguration
|
|||
{
|
||||
bool value;
|
||||
|
||||
if (m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = bool.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
|
|
@ -148,7 +149,7 @@ public static class ServerConfiguration
|
|||
{
|
||||
TimeSpan value;
|
||||
|
||||
if (m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = TimeSpan.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
|
|
@ -164,7 +165,7 @@ public static class ServerConfiguration
|
|||
{
|
||||
T value;
|
||||
|
||||
if (m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = Enum.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
|
|
@ -180,7 +181,7 @@ public static class ServerConfiguration
|
|||
{
|
||||
double value;
|
||||
|
||||
if (m_Settings.Settings.TryGetValue(key, out var strValue))
|
||||
if (_settings.Settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = double.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
|
|
@ -207,7 +208,7 @@ public static class ServerConfiguration
|
|||
|
||||
public static void SetSetting(string key, string value)
|
||||
{
|
||||
m_Settings.Settings[key] = value;
|
||||
_settings.Settings[key] = value;
|
||||
Save();
|
||||
}
|
||||
|
||||
|
|
@ -220,9 +221,9 @@ public static class ServerConfiguration
|
|||
if (File.Exists(m_FilePath))
|
||||
{
|
||||
logger.Information("Reading server configuration from {Path}...", _relPath);
|
||||
m_Settings = JsonConfig.Deserialize<ServerSettings>(m_FilePath);
|
||||
_settings = JsonConfig.Deserialize<ServerSettings>(m_FilePath);
|
||||
|
||||
if (m_Settings == null)
|
||||
if (_settings == null)
|
||||
{
|
||||
logger.Error("Reading server configuration failed");
|
||||
throw new FileNotFoundException($"Failed to deserialize {m_FilePath}.");
|
||||
|
|
@ -233,7 +234,7 @@ public static class ServerConfiguration
|
|||
else
|
||||
{
|
||||
updated = true;
|
||||
m_Settings = new ServerSettings();
|
||||
_settings = new ServerSettings();
|
||||
}
|
||||
|
||||
if (mocked)
|
||||
|
|
@ -241,12 +242,12 @@ public static class ServerConfiguration
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_Settings.DataDirectories.Count == 0)
|
||||
if (_settings.DataDirectories.Count == 0)
|
||||
{
|
||||
updated = true;
|
||||
foreach (var directory in ServerConfigurationPrompts.GetDataDirectories())
|
||||
{
|
||||
m_Settings.DataDirectories.Add(directory);
|
||||
_settings.DataDirectories.Add(directory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -258,19 +259,27 @@ public static class ServerConfiguration
|
|||
DataDirectories.Add(cuoClientFiles);
|
||||
}
|
||||
|
||||
if (m_Settings.Listeners.Count == 0)
|
||||
if (_settings.Listeners.Count == 0)
|
||||
{
|
||||
updated = true;
|
||||
m_Settings.Listeners.AddRange(ServerConfigurationPrompts.GetListeners());
|
||||
_settings.Listeners.AddRange(ServerConfigurationPrompts.GetListeners());
|
||||
}
|
||||
|
||||
if (m_Settings.Expansion == null)
|
||||
// We have a known, current expansion, so we can deserialize it from Configuration
|
||||
if (!ExpansionInfo.LoadConfiguration(out var currentExpansion))
|
||||
{
|
||||
m_Settings.Expansion = GetSetting<Expansion>("currentExpansion") ?? ServerConfigurationPrompts.GetExpansion();
|
||||
currentExpansion = (_settings.Data.Remove("expansion", out var el)
|
||||
? el.ToObject<Expansion?>(JsonConfig.DefaultOptions)
|
||||
: null) ?? ExpansionConfigurationPrompts.GetExpansion();
|
||||
|
||||
// We've updated the selected expansion, so choose the maps we want from it, then store and save our selection
|
||||
var selectedMaps = ExpansionConfigurationPrompts.GetSelectedMaps(currentExpansion);
|
||||
ExpansionInfo.StoreMapSelection(selectedMaps, currentExpansion);
|
||||
|
||||
updated = true;
|
||||
}
|
||||
|
||||
Core.Expansion = m_Settings.Expansion.Value;
|
||||
Core.Expansion = currentExpansion;
|
||||
|
||||
if (updated)
|
||||
{
|
||||
|
|
@ -279,6 +288,14 @@ public static class ServerConfiguration
|
|||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.WriteLine($"{_relPath}.");
|
||||
Utility.PopColor();
|
||||
|
||||
// Either the expansion.json file has never existed, or it's been deleted, so create it now
|
||||
ExpansionInfo.SaveConfiguration();
|
||||
|
||||
Console.Write("Expansion configuration saved to ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.WriteLine($"{ExpansionInfo.ExpansionConfigurationPath}.");
|
||||
Utility.PopColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -289,6 +306,6 @@ public static class ServerConfiguration
|
|||
return;
|
||||
}
|
||||
|
||||
JsonConfig.Serialize(m_FilePath, m_Settings);
|
||||
JsonConfig.Serialize(m_FilePath, _settings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
|
|
@ -83,53 +82,6 @@ public static class ServerConfigurationPrompts
|
|||
} while (true);
|
||||
}
|
||||
|
||||
internal static Expansion GetExpansion()
|
||||
{
|
||||
Console.WriteLine("Please choose an expansion by typing the number or short name:");
|
||||
var expansions = ExpansionInfo.Table;
|
||||
|
||||
for (int i = 0; i < expansions.Length; i++)
|
||||
{
|
||||
var info = expansions[i];
|
||||
Console.WriteLine(" - {0,2}: {1} ({2})", i, ((Expansion)info.ID).ToString(), info.Name);
|
||||
}
|
||||
|
||||
var maxExpansion = (Expansion)expansions[^1].ID;
|
||||
var maxExpansionName = maxExpansion.ToString();
|
||||
|
||||
do
|
||||
{
|
||||
Console.Write("[enter for {0}]> ", maxExpansionName);
|
||||
var input = Console.ReadLine();
|
||||
Expansion expansion;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
expansion = maxExpansion;
|
||||
}
|
||||
else if (int.TryParse(input, NumberStyles.Integer, null, out var number) &&
|
||||
number >= 0 && number < expansions.Length)
|
||||
{
|
||||
expansion = (Expansion)number;
|
||||
}
|
||||
else if (!Enum.TryParse(input, out expansion))
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Red);
|
||||
Console.Write(input);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(" is an invalid expansion option.");
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.Write("Expansion set to ");
|
||||
Utility.PushColor(ConsoleColor.Green);
|
||||
Console.Write(ExpansionInfo.GetInfo(expansion).Name);
|
||||
Utility.PopColor();
|
||||
Console.WriteLine(".");
|
||||
return expansion;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
internal static List<string> GetDataDirectories()
|
||||
{
|
||||
Console.WriteLine("Please enter the absolute path to your ClassicUO or Ultima Online data:");
|
||||
|
|
@ -214,7 +166,6 @@ public static class ServerConfigurationPrompts
|
|||
Utility.PopColor();
|
||||
Console.WriteLine(".");
|
||||
} while (true);
|
||||
|
||||
return ips;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server;
|
||||
|
|
@ -30,9 +31,10 @@ public class ServerSettings
|
|||
[JsonPropertyName("listeners")]
|
||||
public List<IPEndPoint> Listeners { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("expansion")]
|
||||
public Expansion? Expansion { get; set; }
|
||||
|
||||
[JsonPropertyName("settings")]
|
||||
public SortedDictionary<string, string> Settings { get; set; } = new();
|
||||
|
||||
// For backward compatibility
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement> Data { get; set; } = new();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
using Server.Json;
|
||||
using Server.Maps;
|
||||
|
||||
namespace Server;
|
||||
|
||||
|
|
@ -158,7 +158,10 @@ public enum HousingFlags
|
|||
|
||||
public class ExpansionInfo
|
||||
{
|
||||
public const string ExpansionConfigurationPath = "Configuration/expansion.json";
|
||||
|
||||
public static bool ForceOldAnimations { get; private set; }
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
ForceOldAnimations = ServerConfiguration.GetSetting("expansion.forceOldAnimations", false);
|
||||
|
|
@ -188,46 +191,44 @@ public class ExpansionInfo
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void StoreMapSelection(MapSelectionFlags mapSelectionFlags, Expansion expansion)
|
||||
{
|
||||
int expansionIndex = (int)expansion;
|
||||
Table[expansionIndex].MapSelectionFlags = mapSelectionFlags;
|
||||
}
|
||||
|
||||
public static void SaveConfiguration()
|
||||
{
|
||||
var pathToExpansionFile = Path.Combine(Core.BaseDirectory, ExpansionConfigurationPath);
|
||||
JsonConfig.Serialize(pathToExpansionFile, GetInfo(Core.Expansion));
|
||||
}
|
||||
|
||||
public static bool LoadConfiguration(out Expansion expansion)
|
||||
{
|
||||
var pathToExpansionFile = Path.Combine(Core.BaseDirectory, ExpansionConfigurationPath);
|
||||
|
||||
ExpansionInfo expansionConfig = JsonConfig.Deserialize<ExpansionInfo>(pathToExpansionFile);
|
||||
if (expansionConfig == null)
|
||||
{
|
||||
expansion = Expansion.None;
|
||||
return false;
|
||||
}
|
||||
|
||||
int currentExpansionIndex = expansionConfig.Id;
|
||||
Table[currentExpansionIndex] = expansionConfig;
|
||||
expansion = (Expansion)currentExpansionIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
static ExpansionInfo()
|
||||
{
|
||||
var path = Path.Combine(Core.BaseDirectory, "Data/expansion.json");
|
||||
var path = Path.Combine(Core.BaseDirectory, "Data/expansions.json");
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException($"Expansion file '{path}' could not be found.");
|
||||
}
|
||||
|
||||
var expansions = JsonConfig.Deserialize<List<ExpansionConfig>>(path);
|
||||
|
||||
Table = new ExpansionInfo[expansions.Count];
|
||||
|
||||
for (var i = 0; i < expansions.Count; i++)
|
||||
{
|
||||
var expansion = expansions[i];
|
||||
if (expansion.ClientVersion != null)
|
||||
{
|
||||
Table[i] = new ExpansionInfo(
|
||||
i,
|
||||
expansion.Name,
|
||||
expansion.ClientVersion,
|
||||
expansion.FeatureFlags,
|
||||
expansion.CharacterListFlags,
|
||||
expansion.HousingFlags,
|
||||
expansion.MobileStatusVersion
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Table[i] = new ExpansionInfo(
|
||||
i,
|
||||
expansion.Name,
|
||||
expansion.ClientFlags ?? ClientFlags.None,
|
||||
expansion.FeatureFlags,
|
||||
expansion.CharacterListFlags,
|
||||
expansion.HousingFlags,
|
||||
expansion.MobileStatusVersion
|
||||
);
|
||||
}
|
||||
}
|
||||
Table = JsonConfig.Deserialize<ExpansionInfo[]>(path);
|
||||
}
|
||||
|
||||
public ExpansionInfo(
|
||||
|
|
@ -237,8 +238,9 @@ public class ExpansionInfo
|
|||
FeatureFlags supportedFeatures,
|
||||
CharacterListFlags charListFlags,
|
||||
HousingFlags customHousingFlag,
|
||||
int mobileStatusVersion
|
||||
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag, mobileStatusVersion) =>
|
||||
int mobileStatusVersion,
|
||||
MapSelectionFlags mapSelectionFlags
|
||||
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag, mobileStatusVersion, mapSelectionFlags) =>
|
||||
ClientFlags = clientFlags;
|
||||
|
||||
public ExpansionInfo(
|
||||
|
|
@ -248,41 +250,54 @@ public class ExpansionInfo
|
|||
FeatureFlags supportedFeatures,
|
||||
CharacterListFlags charListFlags,
|
||||
HousingFlags customHousingFlag,
|
||||
int mobileStatusVersion
|
||||
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag, mobileStatusVersion) =>
|
||||
int mobileStatusVersion,
|
||||
MapSelectionFlags mapSelectionFlags
|
||||
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag, mobileStatusVersion, mapSelectionFlags) =>
|
||||
RequiredClient = requiredClient;
|
||||
|
||||
private ExpansionInfo(
|
||||
[JsonConstructor]
|
||||
public ExpansionInfo(
|
||||
int id,
|
||||
string name,
|
||||
FeatureFlags supportedFeatures,
|
||||
CharacterListFlags charListFlags,
|
||||
HousingFlags customHousingFlag,
|
||||
int mobileStatusVersion
|
||||
CharacterListFlags characterListFlags,
|
||||
HousingFlags housingFlags,
|
||||
int mobileStatusVersion,
|
||||
MapSelectionFlags mapSelectionFlags
|
||||
)
|
||||
{
|
||||
ID = id;
|
||||
Id = id;
|
||||
Name = name;
|
||||
|
||||
SupportedFeatures = supportedFeatures;
|
||||
CharacterListFlags = charListFlags;
|
||||
CustomHousingFlag = customHousingFlag;
|
||||
CharacterListFlags = characterListFlags;
|
||||
HousingFlags = housingFlags;
|
||||
MobileStatusVersion = mobileStatusVersion;
|
||||
MapSelectionFlags = mapSelectionFlags;
|
||||
}
|
||||
|
||||
public static ExpansionInfo CoreExpansion => GetInfo(Core.Expansion);
|
||||
|
||||
public static ExpansionInfo[] Table { get; }
|
||||
|
||||
public int ID { get; }
|
||||
public int Id { get; }
|
||||
public string Name { get; set; }
|
||||
public ClientFlags ClientFlags { get; set; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<FeatureFlags>))]
|
||||
public FeatureFlags SupportedFeatures { get; set; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<CharacterListFlags>))]
|
||||
public CharacterListFlags CharacterListFlags { get; set; }
|
||||
public ClientVersion RequiredClient { get; set; }
|
||||
public HousingFlags CustomHousingFlag { get; set; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<HousingFlags>))]
|
||||
public HousingFlags HousingFlags { get; set; }
|
||||
public int MobileStatusVersion { get; set; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<MapSelectionFlags>))]
|
||||
public MapSelectionFlags MapSelectionFlags { get; set; }
|
||||
|
||||
public static ExpansionInfo GetInfo(Expansion ex) => GetInfo((int)ex);
|
||||
|
||||
public static ExpansionInfo GetInfo(int ex)
|
||||
|
|
@ -299,23 +314,3 @@ public class ExpansionInfo
|
|||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public record ExpansionConfig
|
||||
{
|
||||
public string Name { get; init; }
|
||||
|
||||
public ClientVersion? ClientVersion { get; init; }
|
||||
|
||||
public ClientFlags? ClientFlags { get; init; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<FeatureFlags>))]
|
||||
public FeatureFlags FeatureFlags { get; init; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<CharacterListFlags>))]
|
||||
public CharacterListFlags CharacterListFlags { get; init; }
|
||||
|
||||
[JsonConverter(typeof(FlagsConverter<HousingFlags>))]
|
||||
public HousingFlags HousingFlags { get; init; }
|
||||
|
||||
public int MobileStatusVersion { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,28 +17,27 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class TextDefinitionConverter : JsonConverter<TextDefinition>
|
||||
{
|
||||
public override TextDefinition Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.String => TextDefinition.Of(reader.GetString()),
|
||||
JsonTokenType.Number => TextDefinition.Of(reader.GetInt32()),
|
||||
_ => throw new JsonException("TextDefinition value must be an integer or string")
|
||||
};
|
||||
namespace Server.Json;
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TextDefinition value, JsonSerializerOptions options)
|
||||
public class TextDefinitionConverter : JsonConverter<TextDefinition>
|
||||
{
|
||||
public override TextDefinition Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
if (value.Number > 0)
|
||||
{
|
||||
writer.WriteNumberValue(value.Number);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStringValue(value.String);
|
||||
}
|
||||
JsonTokenType.String => TextDefinition.Of(reader.GetString()),
|
||||
JsonTokenType.Number => TextDefinition.Of(reader.GetInt32()),
|
||||
_ => throw new JsonException("TextDefinition value must be an integer or string")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TextDefinition value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value.Number > 0)
|
||||
{
|
||||
writer.WriteNumberValue(value.Number);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStringValue(value.String);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class TextDefinitionConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(TextDefinition);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new TextDefinitionConverter();
|
||||
}
|
||||
}
|
||||
public class TextDefinitionConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(TextDefinition);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new TextDefinitionConverter();
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ using System;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using Server.Buffers;
|
||||
using Server.Text;
|
||||
using Server.Collections;
|
||||
|
||||
namespace Server;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ using System.Text;
|
|||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Server.Buffers;
|
||||
using Server.Json;
|
||||
using Server.Logging;
|
||||
using Server.Network;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server;
|
||||
|
||||
|
|
@ -227,7 +227,6 @@ public static class Core
|
|||
public static int ScriptMobiles => _mobileCount;
|
||||
|
||||
public static Expansion Expansion { get; set; }
|
||||
|
||||
public static bool T2A => Expansion >= Expansion.T2A;
|
||||
|
||||
public static bool UOR => Expansion >= Expansion.UOR;
|
||||
|
|
|
|||
|
|
@ -320,7 +320,6 @@ public sealed class Map : IComparable<Map>, ISpanFormattable, ISpanParsable<Map>
|
|||
public const int SectorActiveRange = 2;
|
||||
|
||||
private static ILogger logger = LogFactory.GetLogger(typeof(Map));
|
||||
|
||||
private readonly int m_FileIndex;
|
||||
private readonly Sector[][] m_Sectors;
|
||||
private readonly int m_SectorsHeight;
|
||||
|
|
|
|||
113
Projects/Server/Maps/MapSelection.cs
Normal file
113
Projects/Server/Maps/MapSelection.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Maps;
|
||||
|
||||
[Flags]
|
||||
public enum MapSelectionFlags
|
||||
{
|
||||
Felucca = 0x00000001,
|
||||
Trammel = 0x00000002,
|
||||
Ilshenar = 0x00000004,
|
||||
Malas = 0x00000008,
|
||||
Tokuno = 0x00000010,
|
||||
TerMur = 0x00000020
|
||||
}
|
||||
|
||||
public static class MapSelection
|
||||
{
|
||||
public static MapSelectionFlags[] MapSelectionValues { get; } = Enum.GetValues<MapSelectionFlags>();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool Includes(this MapSelectionFlags flags, MapSelectionFlags flag) => (flags & flag) == flag;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Toggle(this ref MapSelectionFlags flags, MapSelectionFlags flag)
|
||||
{
|
||||
flags ^= flag;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Enable(this ref MapSelectionFlags flags, MapSelectionFlags flag)
|
||||
{
|
||||
flags |= flag;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Disable(this ref MapSelectionFlags flags, MapSelectionFlags flag)
|
||||
{
|
||||
flags &= ~flag;
|
||||
}
|
||||
|
||||
public static string ToCommaDelimitedString(this MapSelectionFlags flags)
|
||||
{
|
||||
using var builder = ValueStringBuilder.Create();
|
||||
|
||||
foreach (var flag in flags.GetEnumerable())
|
||||
{
|
||||
builder.Append(builder.Length > 0 ? $", {flag}" : $"{flag}");
|
||||
}
|
||||
|
||||
return builder.Length == 0 ? "None" : builder.ToString();
|
||||
}
|
||||
|
||||
public static MapSelectionFlags ToSelectionFlag(this Map map) => (MapSelectionFlags)(1 << map.MapID);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MapSelectionEnumerable GetEnumerable(this MapSelectionFlags flags) => new(flags);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MapSelectionEnumerable EnumFromExpansion(Expansion expansion) => ExpansionInfo.GetInfo(expansion).MapSelectionFlags.GetEnumerable();
|
||||
|
||||
public class MapSelectionEnumerable
|
||||
{
|
||||
private readonly MapSelectionFlags _flags;
|
||||
|
||||
public MapSelectionEnumerable(MapSelectionFlags flags) => _flags = flags;
|
||||
|
||||
public MapSelectionEnumerator GetEnumerator() => new(MapSelectionValues, _flags);
|
||||
}
|
||||
|
||||
public ref struct MapSelectionEnumerator
|
||||
{
|
||||
private readonly MapSelectionFlags[] _allMaps;
|
||||
private readonly MapSelectionFlags _mapSelections;
|
||||
private int _index;
|
||||
private MapSelectionFlags _current;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal MapSelectionEnumerator(MapSelectionFlags[] allMaps, MapSelectionFlags mapSelections)
|
||||
{
|
||||
_allMaps = allMaps;
|
||||
_mapSelections = mapSelections;
|
||||
_index = 0;
|
||||
_current = default;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool MoveNext()
|
||||
{
|
||||
MapSelectionFlags[] localList = _allMaps;
|
||||
|
||||
while ((uint)_index < (uint)localList.Length)
|
||||
{
|
||||
_current = localList[_index++];
|
||||
|
||||
if ((_mapSelections & _current) == _current)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public MapSelectionFlags Current
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Accounting;
|
||||
using Server.Buffers;
|
||||
using Server.ContextMenus;
|
||||
using Server.Guilds;
|
||||
using Server.Gumps;
|
||||
|
|
@ -14,6 +13,7 @@ using Server.Mobiles;
|
|||
using Server.Network;
|
||||
using Server.Prompts;
|
||||
using Server.Targeting;
|
||||
using Server.Text;
|
||||
using Server.Utilities;
|
||||
using CalcMoves = Server.Movement.Movement;
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public partial class NetState
|
|||
}
|
||||
|
||||
public bool SupportsExpansion(ExpansionInfo info, bool checkCoreExpansion = true) =>
|
||||
info != null && (!checkCoreExpansion || (int)Core.Expansion >= info.ID) && ExpansionInfo.ID >= info.ID;
|
||||
info != null && (!checkCoreExpansion || (int)Core.Expansion >= info.Id) && ExpansionInfo.Id >= info.Id;
|
||||
|
||||
public bool SupportsExpansion(Expansion ex, bool checkCoreExpansion = true) =>
|
||||
SupportsExpansion(ExpansionInfo.GetInfo(ex), checkCoreExpansion);
|
||||
|
|
|
|||
|
|
@ -463,7 +463,7 @@ public static class OutgoingMobilePackets
|
|||
else
|
||||
{
|
||||
var maxVersion = ExpansionInfo.CoreExpansion.MobileStatusVersion;
|
||||
var nsExpansion = (Expansion)ns.ExpansionInfo.ID;
|
||||
var nsExpansion = (Expansion)ns.ExpansionInfo.Id;
|
||||
|
||||
if (maxVersion >= 6 && nsExpansion >= Expansion.HS && ns.ExtendedStatus)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
using Server.Json;
|
||||
using Server.Logging;
|
||||
|
|
|
|||
|
|
@ -860,7 +860,7 @@ public class Skills
|
|||
|
||||
while ((uint)_index < (uint)localList.Length)
|
||||
{
|
||||
_current = _skills[_index++];
|
||||
_current = localList[_index++];
|
||||
if (_current != null)
|
||||
{
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using Server.Buffers;
|
||||
|
||||
namespace Server.Text;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue