feat: Adds KR/EC client versions (No actual support yet). (#1506)

### Summary

- Adds KR/EC client versions to ClientVersion
- Adds distinction for enhanced versions in the page queue
- Adds KR Expansion flags
- Adds ProtocolChange enum support
- Adds missing Moongate checks for TerMur
- Adds better message for why a client version is not supported, and which ones are supported.
This commit is contained in:
Kamron Batman 2023-09-18 23:53:18 -07:00 • committed by GitHub
parent cee4d0fb15
commit 0bec97639f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 284 additions and 103 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Numerics;
using Server.Gumps;
using Server.Logging;
using Server.Mobiles;
@ -17,12 +18,17 @@ namespace Server.Misc
private static TimeSpan _ageLeniency;
private static TimeSpan _gameTimeLeniency;
private static string _allowedClientsMessage;
public static ClientType AllowedClientTypes { get; private set; }
public static bool AllowClassic => (AllowedClientTypes & ClientType.Classic) != 0;
public static bool AllowUOTD => (AllowedClientTypes & ClientType.UOTD) != 0;
public static bool AllowKR => (AllowedClientTypes & ClientType.KR) != 0;
public static bool AllowSA => (AllowedClientTypes & ClientType.SA) != 0;
public static ClientVersion MinRequired { get; private set; }
public static ClientVersion MaxRequired { get; private set; }
public static bool AllowRegular => true;
public static bool AllowUOTD => false;
public static TimeSpan KickDelay { get; private set; }
public static void Configure()
@ -39,6 +45,8 @@ namespace Server.Misc
TimeSpan.FromHours(25)
);
KickDelay = ServerConfiguration.GetOrUpdateSetting("clientVerification.kickDelay", TimeSpan.FromSeconds(20.0));
AllowedClientTypes = ServerConfiguration.GetSetting("clientVerification.allowedClientTypes", ClientType.Classic | ClientType.SA);
_allowedClientsMessage = GetAllowedClientsString(AllowedClientTypes);
}
public static void Initialize()
@ -81,6 +89,34 @@ namespace Server.Misc
return _versionExpression;
}
private static string GetAllowedClientsString(ClientType allowedClients)
{
// Get total number of allowed clients
var totalAllowedClients = BitOperations.PopCount((uint)allowedClients) - 1;
if (totalAllowedClients == 0)
{
return "There are no clients supported at this time.";
}
using var builder = ValueStringBuilder.Create();
builder.Append("Please connect with a ");
uint flags = 0;
var i = 0;
while (flags < (uint)allowedClients)
{
flags = 1u << i;
if (i > 0)
{
builder.Append(i == totalAllowedClients ? " or " : ", ");
}
builder.Append(((ClientType)flags).TypeName());
i++;
}
return builder.ToString();
}
private static void EventSink_ClientVersionReceived(NetState state, ClientVersion version)
{
var sb = ValueStringBuilder.Create();
@ -97,22 +133,23 @@ namespace Server.Misc
mobile.GameTime > _gameTimeLeniency;
bool shouldKick = false;
bool isKRClient = version.Type == ClientType.KR;
if (MinRequired != null && version < MinRequired)
if (!isKRClient && MinRequired != null && version < MinRequired)
{
sb.Append($"This server doesn't support clients older than {MinRequired}.");
shouldKick = strictRequirement;
}
else if (MaxRequired != null && version > MaxRequired)
else if (!isKRClient && MaxRequired != null && version > MaxRequired)
{
sb.Append($"This server doesn't support clients newer than {MaxRequired}.");
shouldKick = strictRequirement;
}
else if (!AllowRegular || !AllowUOTD)
else
{
if (!AllowRegular && version.Type == ClientType.Regular)
if (!AllowClassic && version.Type == ClientType.Classic)
{
sb.Append("This server does not allow regular clients to connect.");
sb.Append("This server does not allow classic clients to connect.");
shouldKick = true;
}
else if (!AllowUOTD && state.IsUOTDClient)
@ -120,21 +157,20 @@ namespace Server.Misc
sb.Append("This server does not allow UO:TD clients to connect.");
shouldKick = true;
}
else if (!AllowKR && version.Type == ClientType.KR)
{
sb.Append("This server does not allow UO:KR clients to connect.");
shouldKick = true;
}
else if (!AllowSA && version.Type == ClientType.SA)
{
sb.Append("This server does not allow UO:SA clients to connect.");
shouldKick = true;
}
if (sb.Length > 0)
{
if (AllowRegular && AllowUOTD)
{
sb.Append(" You can use regular or UO:TD clients.");
}
else if (AllowRegular)
{
sb.Append(" You can use regular clients.");
}
else if (AllowUOTD)
{
sb.Append(" You can use UO:TD clients.");
}
sb.Append(_allowedClientsMessage);
}
}