fix: Adds expansion specific mobile status version (#1145)

This commit is contained in:
Kamron Batman 2022-08-22 21:04:59 -07:00 committed by GitHub
parent 61f77df892
commit 2d95fb20a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 363 additions and 324 deletions

View file

@ -60,7 +60,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 3
},
{
"Name": "The Second Age",
@ -123,7 +124,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 3
},
{
"Name": "Renaissance",
@ -186,7 +188,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 3
},
{
"Name": "Third Dawn",
@ -249,7 +252,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 3
},
{
"Name": "Blackthorn's Revenge",
@ -312,7 +316,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 3
},
{
"Name": "Age of Shadows",
@ -375,7 +380,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 6
},
{
"Name": "Samurai Empire",
@ -438,7 +444,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 6
},
{
"Name": "Mondain's Legacy",
@ -501,7 +508,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 6
},
{
"Name": "Stygian Abyss",
@ -564,7 +572,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 6
},
{
"Name": "High Seas",
@ -627,7 +636,8 @@
"Shadowguard": false,
"TOL": false,
"EJ": false
}
},
"MobileStatusVersion": 6
},
{
"Name": "Time of Legends",
@ -690,7 +700,8 @@
"Shadowguard": true,
"TOL": true,
"EJ": false
}
},
"MobileStatusVersion": 6
},
{
"Name": "Endless Journey",
@ -753,6 +764,7 @@
"Shadowguard": true,
"TOL": true,
"EJ": true
}
},
"MobileStatusVersion": 6
}
]

View file

@ -232,11 +232,23 @@ namespace Server.Tests.Network
}
[Theory]
[InlineData(ProtocolChanges.Version70610)]
[InlineData(ProtocolChanges.Version400a)]
[InlineData(ProtocolChanges.Version502b)]
public void TestMobileStatusExtendedSelf(ProtocolChanges changes)
[InlineData(ProtocolChanges.Version70610, "7.0.61.0", ClientFlags.TerMur, Expansion.HS, 6)]
[InlineData(ProtocolChanges.Version400a, "4.0.0a", ClientFlags.Malas, Expansion.AOS, 4)]
[InlineData(ProtocolChanges.Version502b, "5.0.2b", ClientFlags.Malas, Expansion.ML, 5)]
public void TestMobileStatusExtendedSelf(
ProtocolChanges changes,
string version,
ClientFlags clientFlags,
Expansion expansion,
int mobileStatusVersion
)
{
var expansionInfo = ExpansionInfo.GetInfo(Core.Expansion);
var oldExpansion = Core.Expansion;
var oldVersion = expansionInfo.MobileStatusVersion;
Core.Expansion = expansion;
ExpansionInfo.GetInfo(Core.Expansion).MobileStatusVersion = mobileStatusVersion;
var m = new Mobile((Serial)0x1) { Name = "Random Mobile 1" };
m.DefaultMobileInit();
m.Str = 50;
@ -248,12 +260,16 @@ namespace Server.Tests.Network
var ns = PacketTestUtilities.CreateTestNetState();
ns.ProtocolChanges = changes;
ns.Version = new ClientVersion(version);
ns.Flags = clientFlags;
var expected = new MobileStatusExtended(m, ns).Compile();
ns.SendMobileStatus(m, m);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
Core.Expansion = oldExpansion;
expansionInfo.MobileStatusVersion = oldVersion;
}
[Theory]

View file

@ -19,10 +19,10 @@ using System.IO;
using System.Text.Json.Serialization;
using Server.Json;
namespace Server
namespace Server;
public enum Expansion
{
public enum Expansion
{
None,
T2A,
UOR,
@ -35,11 +35,11 @@ namespace Server
HS,
TOL,
EJ
}
}
[Flags]
public enum ClientFlags
{
[Flags]
public enum ClientFlags
{
None = 0x00000000,
Felucca = 0x00000001,
Trammel = 0x00000002,
@ -50,11 +50,11 @@ namespace Server
Unk1 = 0x00000040,
Unk2 = 0x00000080,
UOTD = 0x00000100
}
}
[Flags]
public enum FeatureFlags
{
[Flags]
public enum FeatureFlags
{
None = 0x00000000,
T2A = 0x00000001,
UOR = 0x00000002, // In later clients, the T2A/UOR flags are negative feature flags to disable body replacement of Pre-AOS graphics.
@ -93,11 +93,11 @@ namespace Server
ExpansionHS = ExpansionSA | HS,
ExpansionTOL = ExpansionHS | TOL | Jungle | Shadowguard,
ExpansionEJ = ExpansionTOL | EJ
}
}
[Flags]
public enum CharacterListFlags
{
[Flags]
public enum CharacterListFlags
{
None = 0x00000000,
Unk1 = 0x00000001,
OverwriteConfigButton = 0x00000002,
@ -128,11 +128,11 @@ namespace Server
ExpansionHS = ExpansionSA,
ExpansionTOL = ExpansionHS,
ExpansionEJ = ExpansionTOL
}
}
[Flags]
public enum HousingFlags
{
[Flags]
public enum HousingFlags
{
None = 0x0,
AOS = 0x10,
SE = 0x40,
@ -154,10 +154,10 @@ namespace Server
HousingHS = HousingSA | HS,
HousingTOL = HousingHS | TOL | Jungle | Shadowguard,
HousingEJ = HousingTOL | EJ
}
}
public class ExpansionInfo
{
public class ExpansionInfo
{
public static bool ForceOldAnimations { get; private set; }
public static void Configure()
{
@ -206,7 +206,8 @@ namespace Server
expansion.ClientVersion,
expansion.FeatureFlags,
expansion.CharacterListFlags,
expansion.HousingFlags
expansion.HousingFlags,
expansion.MobileStatusVersion
);
}
else
@ -217,7 +218,8 @@ namespace Server
expansion.ClientFlags ?? ClientFlags.None,
expansion.FeatureFlags,
expansion.CharacterListFlags,
expansion.HousingFlags
expansion.HousingFlags,
expansion.MobileStatusVersion
);
}
}
@ -229,8 +231,10 @@ namespace Server
ClientFlags clientFlags,
FeatureFlags supportedFeatures,
CharacterListFlags charListFlags,
HousingFlags customHousingFlag
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag) => ClientFlags = clientFlags;
HousingFlags customHousingFlag,
int mobileStatusVersion
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag, mobileStatusVersion) =>
ClientFlags = clientFlags;
public ExpansionInfo(
int id,
@ -238,15 +242,18 @@ namespace Server
ClientVersion requiredClient,
FeatureFlags supportedFeatures,
CharacterListFlags charListFlags,
HousingFlags customHousingFlag
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag) => RequiredClient = requiredClient;
HousingFlags customHousingFlag,
int mobileStatusVersion
) : this(id, name, supportedFeatures, charListFlags, customHousingFlag, mobileStatusVersion) =>
RequiredClient = requiredClient;
private ExpansionInfo(
int id,
string name,
FeatureFlags supportedFeatures,
CharacterListFlags charListFlags,
HousingFlags customHousingFlag
HousingFlags customHousingFlag,
int mobileStatusVersion
)
{
ID = id;
@ -255,6 +262,7 @@ namespace Server
SupportedFeatures = supportedFeatures;
CharacterListFlags = charListFlags;
CustomHousingFlag = customHousingFlag;
MobileStatusVersion = mobileStatusVersion;
}
public static ExpansionInfo CoreExpansion => GetInfo(Core.Expansion);
@ -263,12 +271,12 @@ namespace Server
public int ID { get; }
public string Name { get; set; }
public ClientFlags ClientFlags { get; set; }
public FeatureFlags SupportedFeatures { get; set; }
public CharacterListFlags CharacterListFlags { get; set; }
public ClientVersion RequiredClient { get; set; }
public HousingFlags CustomHousingFlag { get; set; }
public int MobileStatusVersion { get; set; }
public static ExpansionInfo GetInfo(Expansion ex) => GetInfo((int)ex);
@ -285,10 +293,10 @@ namespace Server
}
public override string ToString() => Name;
}
}
public record ExpansionConfig
{
public record ExpansionConfig
{
public string Name { get; init; }
public ClientVersion? ClientVersion { get; init; }
@ -303,5 +311,6 @@ namespace Server
[JsonConverter(typeof(FlagsConverter<HousingFlags>))]
public HousingFlags HousingFlags { get; init; }
}
public int MobileStatusVersion { get; set; }
}

View file

@ -39,13 +39,6 @@ public static class OutgoingMobilePackets
public const int MobileStatusMLLength = 91;
public const int MobileStatusHSLength = 121;
public static bool ExtendedStatus { get; private set; } = true;
public static void Configure()
{
ExtendedStatus = ServerConfiguration.GetSetting("client.showExtendedStatus", true);
}
public static void CreateBondedStatus(Span<byte> buffer, Serial serial, bool bonded)
{
if (buffer[0] != 0)
@ -467,17 +460,22 @@ public static class OutgoingMobilePackets
version = 0;
length = MobileStatusCompactLength;
}
else if (ExtendedStatus && ns.ExtendedStatus)
else
{
var maxVersion = ExpansionInfo.CoreExpansion.MobileStatusVersion;
var nsExpansion = (Expansion)ns.ExpansionInfo.ID;
if (maxVersion >= 6 && nsExpansion >= Expansion.HS && ns.ExtendedStatus)
{
version = 6;
length = MobileStatusHSLength;
}
else if (Core.ML && ns.SupportsExpansion(Expansion.ML))
else if (maxVersion >= 5 && nsExpansion >= Expansion.ML)
{
version = 5;
length = MobileStatusMLLength;
}
else if (Core.AOS)
else if (maxVersion >= 4 && nsExpansion >= Expansion.AOS)
{
version = 4;
length = MobileStatusAOSLength;
@ -487,6 +485,7 @@ public static class OutgoingMobilePackets
version = 3;
length = MobileStatusLength;
}
}
Span<byte> buffer = stackalloc byte[length];
CreateMobileStatus(buffer, beheld, version, beheld.CanBeRenamedBy(beholder));
@ -563,6 +562,8 @@ public static class OutgoingMobilePackets
if (version >= 6)
{
// TODO: Once the new statuses are added, the length should be capped by expansion.
// This will allow newer clients to see AOS stats, but not newer ones.
for (var i = 0; i < 15; ++i)
{
writer.Write((short)beheld.GetAOSStatus(i));

View file

@ -4,6 +4,7 @@ public static class AssistantProtocol
{
private static PacketHandler[] _handlers;
[CallPriority(10)]
public static void Configure()
{
_handlers = ProtocolExtensions<AssistantsProtocolInfo>.Register(new AssistantsProtocolInfo());