fix: Adds CUO settings support and adds more robust 7.0.9 support (#945)

This commit is contained in:
Kamron Batman 2022-02-27 02:15:06 -08:00 committed by GitHub
parent 941452de4a
commit 5b7b99e0de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 958 additions and 773 deletions

View file

@ -1,41 +1,42 @@
using System;
using Server.Accounting;
using Server.Logging;
namespace Server.Misc
namespace Server.Misc;
public static class AccountPrompt
{
public static class AccountPrompt
private static readonly ILogger logger = LogFactory.GetLogger(typeof(AccountPrompt));
public static void Initialize()
{
public static void Initialize()
if (Accounts.Count == 0)
{
if (Accounts.Count == 0)
Console.WriteLine("This server has no accounts.");
Console.Write("Do you want to create the owner account now? (y/n): ");
var answer = Console.ReadLine();
if (answer is "y" or "Y")
{
Console.WriteLine("This server has no accounts.");
Console.Write("Do you want to create the owner account now? (y/n): ");
Console.WriteLine();
var answer = Console.ReadLine();
if (answer is "y" or "Y")
Console.Write("Username: ");
var username = Console.ReadLine();
Console.Write("Password: ");
var password = Console.ReadLine();
var a = new Account(username, password)
{
Console.WriteLine();
AccessLevel = AccessLevel.Owner
};
Console.Write("Username: ");
var username = Console.ReadLine();
Console.Write("Password: ");
var password = Console.ReadLine();
var a = new Account(username, password);
a.AccessLevel = AccessLevel.Owner;
Console.WriteLine("Account created.");
ServerAccess.AddProtectedAccount(a, true);
Console.WriteLine("Added {0} to the protected accounts list.", a.Username);
}
else
{
Console.WriteLine();
Console.WriteLine("Account not created.");
}
logger.Information("Owner account created: {0}", username);
ServerAccess.AddProtectedAccount(a, true);
}
else
{
logger.Warning("No owner account created.");
}
}
}

View file

@ -1,6 +1,4 @@
using System;
using System.Buffers.Binary;
using System.IO;
using Server.Buffers;
using Server.Gumps;
using Server.Logging;
@ -14,7 +12,6 @@ namespace Server.Misc
private static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientVerification));
private static bool _enable;
private static bool _detectClientRequirement;
private static InvalidClientResponse _invalidClientResponse;
private static string _versionExpression;
@ -33,11 +30,6 @@ namespace Server.Misc
MinRequired = ServerConfiguration.GetSetting("clientVerification.minRequired", (ClientVersion)null);
MaxRequired = ServerConfiguration.GetSetting("clientVerification.maxRequired", (ClientVersion)null);
if (MinRequired == null && MaxRequired == null)
{
_detectClientRequirement = ServerConfiguration.GetOrUpdateSetting("clientVerification.detectFromClientExe", true);
}
_enable = ServerConfiguration.GetOrUpdateSetting("clientVerification.enable", true);
_invalidClientResponse =
ServerConfiguration.GetOrUpdateSetting("clientVerification.invalidClientResponse", InvalidClientResponse.Kick);
@ -53,40 +45,9 @@ namespace Server.Misc
{
EventSink.ClientVersionReceived += EventSink_ClientVersionReceived;
if (_detectClientRequirement)
if (MinRequired == null && MaxRequired == null)
{
var path = Core.FindDataFile("client.exe", false);
if (File.Exists(path))
{
using FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
var buffer = GC.AllocateUninitializedArray<byte>((int)fs.Length, true);
fs.Read(buffer);
// VS_VERSION_INFO (unicode)
Span<byte> vsVersionInfo = stackalloc byte[]
{
0x56, 0x00, 0x53, 0x00, 0x5F, 0x00, 0x56, 0x00,
0x45, 0x00, 0x52, 0x00, 0x53, 0x00, 0x49, 0x00,
0x4F, 0x00, 0x4E, 0x00, 0x5F, 0x00, 0x49, 0x00,
0x4E, 0x00, 0x46, 0x00, 0x4F, 0x00
};
for (var i = 0; i < buffer.Length; i++)
{
if (vsVersionInfo.SequenceEqual(buffer.AsSpan(i, 30)))
{
var offset = i + 42; // 30 + 12
var minorPart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset));
var majorPart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset + 2));
var privatePart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset + 4));
var buildPart = BinaryPrimitives.ReadUInt16LittleEndian(buffer.AsSpan(offset + 6));
MinRequired = new ClientVersion(majorPart, minorPart, buildPart, privatePart);
break;
}
}
}
MinRequired = UOClient.ServerClientVersion;
}
if (MinRequired != null || MaxRequired != null)

View file

@ -56,8 +56,11 @@ public static class ServerAccess
}
ServerAccessConfiguration = JsonConfig.Deserialize<ServerAccessConfiguration>(path);
var protectedAccounts = string.Join(", ", ServerAccessConfiguration.ProtectedAccounts);
logger.Information("Protected accounts registered: {0}", protectedAccounts);
if (ServerAccessConfiguration.ProtectedAccounts.Count > 0)
{
var protectedAccounts = string.Join(", ", ServerAccessConfiguration.ProtectedAccounts);
logger.Information("Protected accounts registered: {0}", protectedAccounts);
}
}
public static void Initialize()