From 47e16a03fee081a1f93b02de0343ce6b4bfb742b Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:57:10 -0700 Subject: [PATCH] feat: Moves network related events to UOContent using code generation (#1945) ### Summary - Moves `CharacterCreated` event to UOContent using code generated event _CharacterCreatedEvent_. - Moves `TargetByResourceMacro` event to UOContent using code generated event _TargetByResourceMacro_. - Moves `GameLogin` event to UOContent using code generated event _GameLoginEvent_. - Moves `ServerList` event to UOContent using code generated event _ServerListEvent_. - Streamlines ProfessionInfo > [!IMPORTANT] > **Developer Note** > Custom scripts that use any of these event sinks will need to be updated to use the new code generated events. --- .../Server/Events/CharacterCreatedEvent.cs | 93 ------------------- Projects/Server/Events/EventSink.cs | 5 - Projects/Server/Events/GameLoginEvent.cs | 48 ---------- Projects/Server/Events/ServerListEvent.cs | 59 ------------ Projects/Server/Mobiles/Mobile.cs | 2 +- .../UOContent/Accounting/AccountHandler.cs | 6 +- .../CharacterCreatedEvent.cs | 46 +++++++++ .../Character Creation}/CharacterCreation.cs | 86 ++++++++--------- Projects/UOContent/Misc/ProfessionInfo.cs | 51 +++++----- Projects/UOContent/Misc/ServerList.cs | 6 +- Projects/UOContent/Network/GameServer.cs | 29 ++++++ Projects/UOContent/Network/GatewayServer.cs | 36 +++++++ .../Network/Packets/IncomingAccountPackets.cs | 39 ++++---- .../Packets/IncomingExtendedCommandPackets.cs | 10 +- 14 files changed, 207 insertions(+), 309 deletions(-) delete mode 100644 Projects/Server/Events/CharacterCreatedEvent.cs delete mode 100644 Projects/Server/Events/GameLoginEvent.cs delete mode 100644 Projects/Server/Events/ServerListEvent.cs create mode 100644 Projects/UOContent/Engines/Character Creation/CharacterCreatedEvent.cs rename Projects/UOContent/{Misc => Engines/Character Creation}/CharacterCreation.cs (93%) create mode 100644 Projects/UOContent/Network/GameServer.cs create mode 100644 Projects/UOContent/Network/GatewayServer.cs diff --git a/Projects/Server/Events/CharacterCreatedEvent.cs b/Projects/Server/Events/CharacterCreatedEvent.cs deleted file mode 100644 index 59dd626a6..000000000 --- a/Projects/Server/Events/CharacterCreatedEvent.cs +++ /dev/null @@ -1,93 +0,0 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: CharacterCreatedEvent.cs * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using Server.Accounting; -using Server.Network; - -namespace Server; - -public class CharacterCreatedEventArgs -{ - public CharacterCreatedEventArgs( - NetState state, IAccount a, string name, bool female, int hue, StatNameValue[] stats, CityInfo city, - SkillNameValue[] skills, int shirtHue, int pantsHue, int hairID, int hairHue, int beardID, int beardHue, - int profession, Race race - ) - { - State = state; - Account = a; - Name = name; - Female = female; - Hue = hue; - Stats = stats; - City = city; - Skills = skills; - ShirtHue = shirtHue; - PantsHue = pantsHue; - HairID = hairID; - HairHue = hairHue; - BeardID = beardID; - BeardHue = beardHue; - Profession = profession; - Race = race; - } - - public NetState State { get; } - - public IAccount Account { get; } - - public Mobile Mobile { get; set; } - - public string Name { get; } - - public bool Female { get; } - - public int Hue { get; } - - public StatNameValue[] Stats { get; } - - public CityInfo City { get; } - - public SkillNameValue[] Skills { get; } - - public int ShirtHue { get; } - - public int PantsHue { get; } - - public int HairID { get; } - - public int HairHue { get; } - - public int BeardID { get; } - - public int BeardHue { get; } - - public int Profession { get; set; } - - public Race Race { get; } -} - -public readonly record struct SkillNameValue(SkillName Name, int Value); -public readonly record struct StatNameValue(StatType Name, int Value); - -public static partial class EventSink -{ - public static event Action CharacterCreated; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void InvokeCharacterCreated(CharacterCreatedEventArgs e) => CharacterCreated?.Invoke(e); -} diff --git a/Projects/Server/Events/EventSink.cs b/Projects/Server/Events/EventSink.cs index b112cb72d..6a72185f4 100644 --- a/Projects/Server/Events/EventSink.cs +++ b/Projects/Server/Events/EventSink.cs @@ -41,9 +41,4 @@ public static partial class EventSink public static event Action ServerStarted; public static void InvokeServerStarted() => ServerStarted?.Invoke(); - - public static event Action TargetByResourceMacro; - - public static void InvokeTargetByResourceMacro(Mobile m, Item item, short resourceType) => - TargetByResourceMacro?.Invoke(m, item, resourceType); } diff --git a/Projects/Server/Events/GameLoginEvent.cs b/Projects/Server/Events/GameLoginEvent.cs deleted file mode 100644 index 5d05f180a..000000000 --- a/Projects/Server/Events/GameLoginEvent.cs +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: GameLoginEvent.cs * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -using System; -using System.Runtime.CompilerServices; -using Server.Network; - -namespace Server; - -public class GameLoginEventArgs -{ - public GameLoginEventArgs(NetState state, string un, string pw) - { - State = state; - Username = un; - Password = pw; - } - - public NetState State { get; } - - public string Username { get; } - - public string Password { get; } - - public bool Accepted { get; set; } - - public CityInfo[] CityInfo { get; set; } -} - -public static partial class EventSink -{ - public static event Action GameLogin; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void InvokeGameLogin(GameLoginEventArgs e) => GameLogin?.Invoke(e); -} diff --git a/Projects/Server/Events/ServerListEvent.cs b/Projects/Server/Events/ServerListEvent.cs deleted file mode 100644 index ce1c88ed1..000000000 --- a/Projects/Server/Events/ServerListEvent.cs +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: ServerListEvent.cs * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Net; -using System.Runtime.CompilerServices; -using Server.Accounting; -using Server.Network; - -namespace Server; - -public class ServerListEventArgs -{ - public ServerListEventArgs(NetState state, IAccount account) - { - State = state; - Account = account; - Servers = new List(); - } - - public NetState State { get; } - - public IAccount Account { get; } - - public bool Rejected { get; set; } - - public List Servers { get; } - - public void AddServer(string name, IPEndPoint address) - { - AddServer(name, 0, TimeZoneInfo.Local, address); - } - - public void AddServer(string name, int fullPercent, TimeZoneInfo tz, IPEndPoint address) - { - Servers.Add(new ServerInfo(name, fullPercent, tz, address)); - } -} - -public static partial class EventSink -{ - public static event Action ServerList; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void InvokeServerList(ServerListEventArgs e) => ServerList?.Invoke(e); -} diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index 122c44b10..8b5fe2a64 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -59,7 +59,7 @@ public class DamageEntry } [Flags] -public enum StatType +public enum StatType : byte { Str = 1, Dex = 2, diff --git a/Projects/UOContent/Accounting/AccountHandler.cs b/Projects/UOContent/Accounting/AccountHandler.cs index 12f9a9647..fce134355 100644 --- a/Projects/UOContent/Accounting/AccountHandler.cs +++ b/Projects/UOContent/Accounting/AccountHandler.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Net; +using ModernUO.CodeGeneratedEvents; using Server.Accounting; +using Server.Engines.CharacterCreation; using Server.Engines.Help; using Server.Logging; using Server.Network; @@ -65,7 +67,6 @@ public static class AccountHandler public static void Initialize() { EventSink.AccountLogin += EventSink_AccountLogin; - EventSink.GameLogin += EventSink_GameLogin; } [Usage("Password ")] @@ -348,7 +349,8 @@ public static class AccountHandler } } - public static void EventSink_GameLogin(GameLoginEventArgs e) + [OnEvent(nameof(GameServer.GameServerLoginEvent))] + public static void OnGameServerLogin(GameServer.GameLoginEventArgs e) { var un = e.Username; var pw = e.Password; diff --git a/Projects/UOContent/Engines/Character Creation/CharacterCreatedEvent.cs b/Projects/UOContent/Engines/Character Creation/CharacterCreatedEvent.cs new file mode 100644 index 000000000..4fddbf9b7 --- /dev/null +++ b/Projects/UOContent/Engines/Character Creation/CharacterCreatedEvent.cs @@ -0,0 +1,46 @@ +using Server.Accounting; +using Server.Network; + +namespace Server.Engines.CharacterCreation; + +public class CharacterCreatedEventArgs( + NetState state, IAccount a, string name, bool female, + int hue, byte[] stats, CityInfo city, (SkillName, byte)[] skills, + int shirtHue, int pantsHue, int hairId, int hairHue, + int beardId, int beardHue, int profession, Race race +) +{ + public NetState State { get; } = state; + + public IAccount Account { get; } = a; + + public Mobile Mobile { get; set; } + + public string Name { get; } = name; + + public bool Female { get; } = female; + + public int Hue { get; } = hue; + + public byte[] Stats { get; } = stats; + + public CityInfo City { get; } = city; + + public (SkillName, byte)[] Skills { get; } = skills; + + public int ShirtHue { get; } = shirtHue; + + public int PantsHue { get; } = pantsHue; + + public int HairID { get; } = hairId; + + public int HairHue { get; } = hairHue; + + public int BeardID { get; } = beardId; + + public int BeardHue { get; } = beardHue; + + public int Profession { get; set; } = profession; + + public Race Race { get; } = race; +} diff --git a/Projects/UOContent/Misc/CharacterCreation.cs b/Projects/UOContent/Engines/Character Creation/CharacterCreation.cs similarity index 93% rename from Projects/UOContent/Misc/CharacterCreation.cs rename to Projects/UOContent/Engines/Character Creation/CharacterCreation.cs index b171431e6..b743b9da7 100644 --- a/Projects/UOContent/Misc/CharacterCreation.cs +++ b/Projects/UOContent/Engines/Character Creation/CharacterCreation.cs @@ -1,16 +1,18 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using ModernUO.CodeGeneratedEvents; using Server.Accounting; using Server.Items; using Server.Logging; using Server.Maps; +using Server.Misc; using Server.Mobiles; using Server.Network; -namespace Server.Misc; +namespace Server.Engines.CharacterCreation; -public static class CharacterCreation +public static partial class CharacterCreation { private static readonly ILogger logger = LogFactory.GetLogger(typeof(CharacterCreation)); @@ -78,45 +80,45 @@ public static class CharacterCreation public static readonly CityInfo[] OldHavenStartingCities = [ - new CityInfo("Haven", "The Bountiful Harvest Inn", 3677, 2625, 0, Map.Trammel), - new CityInfo("Britain", "Sweet Dreams Inn", 1075074, 1496, 1628, 10, Map.Trammel), - new CityInfo("Magincia", "The Great Horns Tavern", 1075077, 3734, 2222, 20, Map.Trammel), + new("Haven", "The Bountiful Harvest Inn", 3677, 2625, 0, Map.Trammel), + new("Britain", "Sweet Dreams Inn", 1075074, 1496, 1628, 10, Map.Trammel), + new("Magincia", "The Great Horns Tavern", 1075077, 3734, 2222, 20, Map.Trammel), ]; public static readonly CityInfo[] FeluccaStartingCities = [ - new CityInfo("Yew", "The Empath Abbey", 1075072, 633, 858, 0, Map.Felucca), - new CityInfo("Minoc", "The Barnacle", 1075073, 2476, 413, 15, Map.Felucca), - new CityInfo("Britain", "Sweet Dreams Inn", 1075074, 1496, 1628, 10, Map.Felucca), - new CityInfo("Moonglow", "The Scholars Inn", 1075075, 4408, 1168, 0, Map.Felucca), - new CityInfo("Trinsic", "The Traveler's Inn", 1075076, 1845, 2745, 0, Map.Felucca), - new CityInfo("Magincia", "The Great Horns Tavern", 1075077, 3734, 2222, 20, Map.Felucca), - new CityInfo("Jhelom", "The Mercenary Inn", 1075078, 1374, 3826, 0, Map.Felucca), - new CityInfo("Skara Brae", "The Falconer's Inn", 1075079, 618, 2234, 0, Map.Felucca), - new CityInfo("Vesper", "The Ironwood Inn", 1075080, 2771, 976, 0, Map.Felucca) + new("Yew", "The Empath Abbey", 1075072, 633, 858, 0, Map.Felucca), + new("Minoc", "The Barnacle", 1075073, 2476, 413, 15, Map.Felucca), + new("Britain", "Sweet Dreams Inn", 1075074, 1496, 1628, 10, Map.Felucca), + new("Moonglow", "The Scholars Inn", 1075075, 4408, 1168, 0, Map.Felucca), + new("Trinsic", "The Traveler's Inn", 1075076, 1845, 2745, 0, Map.Felucca), + new("Magincia", "The Great Horns Tavern", 1075077, 3734, 2222, 20, Map.Felucca), + new("Jhelom", "The Mercenary Inn", 1075078, 1374, 3826, 0, Map.Felucca), + new("Skara Brae", "The Falconer's Inn", 1075079, 618, 2234, 0, Map.Felucca), + new("Vesper", "The Ironwood Inn", 1075080, 2771, 976, 0, Map.Felucca) ]; public static readonly CityInfo[] TrammelStartingCities = [ - new CityInfo("Yew", "The Empath Abbey", 1075072, 633, 858, 0, Map.Trammel), - new CityInfo("Minoc", "The Barnacle", 1075073, 2476, 413, 15, Map.Trammel), - new CityInfo("Moonglow", "The Scholars Inn", 1075075, 4408, 1168, 0, Map.Trammel), - new CityInfo("Trinsic", "The Traveler's Inn", 1075076, 1845, 2745, 0, Map.Trammel), - new CityInfo("Jhelom", "The Mercenary Inn", 1075078, 1374, 3826, 0, Map.Trammel), - new CityInfo("Skara Brae", "The Falconer's Inn", 1075079, 618, 2234, 0, Map.Trammel), - new CityInfo("Vesper", "The Ironwood Inn", 1075080, 2771, 976, 0, Map.Trammel), + new("Yew", "The Empath Abbey", 1075072, 633, 858, 0, Map.Trammel), + new("Minoc", "The Barnacle", 1075073, 2476, 413, 15, Map.Trammel), + new("Moonglow", "The Scholars Inn", 1075075, 4408, 1168, 0, Map.Trammel), + new("Trinsic", "The Traveler's Inn", 1075076, 1845, 2745, 0, Map.Trammel), + new("Jhelom", "The Mercenary Inn", 1075078, 1374, 3826, 0, Map.Trammel), + new("Skara Brae", "The Falconer's Inn", 1075079, 618, 2234, 0, Map.Trammel), + new("Vesper", "The Ironwood Inn", 1075080, 2771, 976, 0, Map.Trammel), ]; public static readonly CityInfo[] NewHavenStartingCities = [ - new CityInfo("New Haven", "The Bountiful Harvest Inn", 1150168, 3503, 2574, 14, Map.Trammel), - new CityInfo("Britain", "The Wayfarer's Inn", 1075074, 1602, 1591, 20, Map.Trammel) + new("New Haven", "The Bountiful Harvest Inn", 1150168, 3503, 2574, 14, Map.Trammel), + new("Britain", "The Wayfarer's Inn", 1075074, 1602, 1591, 20, Map.Trammel) // Magincia removed because it burned down. ]; public static readonly CityInfo[] StartingCitiesSA = [ - new CityInfo("Royal City", "Royal City Inn", 1150169, 738, 3486, -19, Map.TerMur) + new("Royal City", "Royal City Inn", 1150169, 738, 3486, -19, Map.TerMur) ]; private static CityInfo[] _availableStartingCities; @@ -155,11 +157,8 @@ public static class CharacterCreation return []; } - public static void Initialize() - { - // Register our event handler - EventSink.CharacterCreated += EventSink_CharacterCreated; - } + [GeneratedEvent(nameof(CharacterCreatedEvent))] + public static partial void CharacterCreatedEvent(CharacterCreatedEventArgs e); private static void AddBackpack(this Mobile m) { @@ -197,7 +196,8 @@ public static class CharacterCreation return null; } - private static void EventSink_CharacterCreated(CharacterCreatedEventArgs args) + [OnEvent(nameof(CharacterCreatedEvent))] + private static void OnCharacterCreated(CharacterCreatedEventArgs args) { if (!ProfessionInfo.GetProfession(args.Profession, out var profession)) { @@ -396,24 +396,13 @@ public static class CharacterCreation return args.City; } - private static void SetStats(Mobile m, NetState state, StatNameValue[] stats) + private static void SetStats(Mobile m, NetState state, byte[] stats) { var maxStats = state.NewCharacterCreation ? 90 : 80; - var str = 0; - var dex = 0; - var intel = 0; - - for (var i = 0; i < stats.Length; i++) - { - var (statType, value) = stats[i]; - switch (statType) - { - case StatType.Str: str = value; break; - case StatType.Dex: dex = value; break; - case StatType.Int: intel = value; break; - } - } + var str = stats[0]; + var dex = stats[1]; + var intel = stats[2]; if (str is < 10 or > 60 || dex is < 10 or > 60 || intel is < 10 or > 60 || str + dex + intel != maxStats) { @@ -437,7 +426,7 @@ public static class CharacterCreation m.Name = name; } - private static bool ValidateSkills(int raceFlag, SkillNameValue[] skills) + private static bool ValidateSkills(int raceFlag, (SkillName, byte)[] skills) { var total = 0; @@ -445,7 +434,7 @@ public static class CharacterCreation { var (name, value) = skills[i]; - if (value is < 0 or > 50 || !_allowedStartingSkills.Contains(name)) + if (value > 50 || !_allowedStartingSkills.Contains(name)) { return false; } @@ -473,6 +462,7 @@ public static class CharacterCreation for (var j = i + 1; j < skills.Length; ++j) { var (nameCheck, valueCheck) = skills[j]; + if (valueCheck > 0 && nameCheck == name) { return false; @@ -483,7 +473,7 @@ public static class CharacterCreation return total is 100 or 120; } - private static void SetSkills(Mobile m, SkillNameValue[] skills) + private static void SetSkills(Mobile m, (SkillName, byte)[] skills) { if (!ValidateSkills(m.Race.RaceFlag, skills)) { diff --git a/Projects/UOContent/Misc/ProfessionInfo.cs b/Projects/UOContent/Misc/ProfessionInfo.cs index 105927e20..ff644230e 100644 --- a/Projects/UOContent/Misc/ProfessionInfo.cs +++ b/Projects/UOContent/Misc/ProfessionInfo.cs @@ -49,8 +49,6 @@ public class ProfessionInfo static ProfessionInfo() { - List profs = []; - var file = Core.FindDataFile("prof.txt", false); if (!File.Exists(file)) { @@ -58,10 +56,11 @@ public class ProfessionInfo file = Path.Combine(ExpansionInfo.GetEraFolder(parent), "prof.txt"); } - var maxProf = 0; - if (File.Exists(file)) { + var maxProf = 0; + List profs = []; + using var s = File.OpenText(file); while (!s.EndOfStream) @@ -82,7 +81,6 @@ public class ProfessionInfo var prof = new ProfessionInfo(); - var statIndex = 0; var totalStats = 0; var skillIndex = 0; var totalSkill = 0; @@ -161,8 +159,8 @@ public class ProfessionInfo break; } - var skillValue = Utility.ToInt32(cols[2]); - prof.Skills[skillIndex++] = new SkillNameValue(skillName, skillValue); + var skillValue = byte.Parse(cols[2]); + prof.Skills[skillIndex++] = (skillName, skillValue); totalSkill += skillValue; } break; @@ -173,39 +171,44 @@ public class ProfessionInfo break; } - var statValue = Utility.ToInt32(cols[2]); - prof.Stats[statIndex++] = new StatNameValue(stat, statValue); + var statValue = byte.Parse(cols[2]); + prof.Stats[(int)stat >> 1] = statValue; totalStats += statValue; } break; } } } + + _professions = new ProfessionInfo[maxProf + 1]; + + foreach (var p in profs) + { + _professions[p.ID] = p; + } + + profs.Clear(); + profs.TrimExcess(); + } + else + { + _professions = new ProfessionInfo[1]; } - _professions = new ProfessionInfo[maxProf + 1]; _professions[0] = new ProfessionInfo { Name = "Advanced Skills" }; - - foreach (var p in profs) - { - _professions[p.ID] = p; - } - - profs.Clear(); - profs.TrimExcess(); } - private SkillNameValue[] _skills; + private (SkillName, byte)[] _skills; private ProfessionInfo() { Name = string.Empty; - _skills = new SkillNameValue[4]; - Stats = new StatNameValue[3]; + _skills = new (SkillName, byte)[4]; + Stats = new byte[3]; } public int ID { get; private set; } @@ -214,8 +217,8 @@ public class ProfessionInfo public int DescID { get; private set; } public bool TopLevel { get; private set; } public int GumpID { get; private set; } - public SkillNameValue[] Skills => _skills; - public StatNameValue[] Stats { get; } + public (SkillName, byte)[] Skills => _skills; + public byte[] Stats { get; } public void FixSkills() { @@ -223,7 +226,7 @@ public class ProfessionInfo while (index >= 0) { var skill = _skills[index]; - if (skill is not { Name: SkillName.Alchemy, Value: 0 }) + if (skill is not (SkillName.Alchemy, 0)) { break; } diff --git a/Projects/UOContent/Misc/ServerList.cs b/Projects/UOContent/Misc/ServerList.cs index e208f7c9b..3a9c39cf8 100644 --- a/Projects/UOContent/Misc/ServerList.cs +++ b/Projects/UOContent/Misc/ServerList.cs @@ -3,6 +3,7 @@ using System.Net; using System.Net.Http; using System.Net.NetworkInformation; using System.Net.Sockets; +using ModernUO.CodeGeneratedEvents; using Server.Logging; using Server.Network; @@ -60,11 +61,10 @@ namespace Server.Misc { Resolve(Address, out _publicAddress); } - - EventSink.ServerList += EventSink_ServerList; } - private static void EventSink_ServerList(ServerListEventArgs e) + [OnEvent(nameof(GatewayServer.ServerListEvent))] + public static void OnServerListEvent(GatewayServer.ServerListEventArgs e) { try { diff --git a/Projects/UOContent/Network/GameServer.cs b/Projects/UOContent/Network/GameServer.cs new file mode 100644 index 000000000..9fc170d69 --- /dev/null +++ b/Projects/UOContent/Network/GameServer.cs @@ -0,0 +1,29 @@ +using ModernUO.CodeGeneratedEvents; + +namespace Server.Network; + +public static partial class GameServer +{ + public class GameLoginEventArgs + { + public GameLoginEventArgs(NetState state, string un, string pw) + { + State = state; + Username = un; + Password = pw; + } + + public NetState State { get; } + + public string Username { get; } + + public string Password { get; } + + public bool Accepted { get; set; } + + public CityInfo[] CityInfo { get; set; } + } + + [GeneratedEvent(nameof(GameServerLoginEvent))] + public static partial void GameServerLoginEvent(GameLoginEventArgs e); +} diff --git a/Projects/UOContent/Network/GatewayServer.cs b/Projects/UOContent/Network/GatewayServer.cs new file mode 100644 index 000000000..6c9c143a3 --- /dev/null +++ b/Projects/UOContent/Network/GatewayServer.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Net; +using ModernUO.CodeGeneratedEvents; +using Server.Accounting; + +namespace Server.Network; + +public static partial class GatewayServer +{ + public class ServerListEventArgs + { + public ServerListEventArgs(NetState state, IAccount account) + { + State = state; + Account = account; + Servers = []; + } + + public NetState State { get; } + + public IAccount Account { get; } + + public bool Rejected { get; set; } + + public List Servers { get; } + + public void AddServer(string name, IPEndPoint address) => AddServer(name, 0, TimeZoneInfo.Local, address); + + public void AddServer(string name, int fullPercent, TimeZoneInfo tz, IPEndPoint address) => + Servers.Add(new ServerInfo(name, fullPercent, tz, address)); + } + + [GeneratedEvent(nameof(ServerListEvent))] + public static partial void ServerListEvent(ServerListEventArgs e); +} diff --git a/Projects/UOContent/Network/Packets/IncomingAccountPackets.cs b/Projects/UOContent/Network/Packets/IncomingAccountPackets.cs index eb8a89e83..655a2d64d 100644 --- a/Projects/UOContent/Network/Packets/IncomingAccountPackets.cs +++ b/Projects/UOContent/Network/Packets/IncomingAccountPackets.cs @@ -20,6 +20,7 @@ using System.IO; using Server.Accounting; using Server.Assistants; using Server.Commands; +using Server.Engines.CharacterCreation; using Server.Engines.ConPVP; using Server.Engines.Doom; using Server.Engines.PartySystem; @@ -33,7 +34,6 @@ using Server.Mobiles; using Server.Regions; using Server.Spells.Ninjitsu; using Server.Spells.Spellweaving; -using CV = Server.ClientVersion; namespace Server.Network; @@ -88,20 +88,17 @@ public static class IncomingAccountPackets var genderRace = reader.ReadByte(); - var stats = new StatNameValue[] - { - new(StatType.Str, reader.ReadByte()), - new(StatType.Dex, reader.ReadByte()), - new(StatType.Int, reader.ReadByte()) - }; + // Strength, Dex, Intelligence + byte[] stats = [reader.ReadByte(), reader.ReadByte(), reader.ReadByte()]; + + var skills = new (SkillName, byte)[state.NewCharacterCreation ? 4 : 3]; + skills[0] = ((SkillName)reader.ReadByte(), reader.ReadByte()); + skills[1] = ((SkillName)reader.ReadByte(), reader.ReadByte()); + skills[2] = ((SkillName)reader.ReadByte(), reader.ReadByte()); - var skills = new SkillNameValue[state.NewCharacterCreation ? 4 : 3]; - skills[0] = new SkillNameValue((SkillName)reader.ReadByte(), reader.ReadByte()); - skills[1] = new SkillNameValue((SkillName)reader.ReadByte(), reader.ReadByte()); - skills[2] = new SkillNameValue((SkillName)reader.ReadByte(), reader.ReadByte()); if (state.NewCharacterCreation) { - skills[3] = new SkillNameValue((SkillName)reader.ReadByte(), reader.ReadByte()); + skills[3] = ((SkillName)reader.ReadByte(), reader.ReadByte()); } int hue = reader.ReadUInt16(); @@ -183,7 +180,7 @@ public static class IncomingAccountPackets state.BlockAllPackets = true; - EventSink.InvokeCharacterCreated(args); + CharacterCreation.CharacterCreatedEvent(args); var m = args.Mobile; @@ -208,13 +205,9 @@ public static class IncomingAccountPackets AccountHandler.DeleteRequest(state, index); } - public static void AccountID(NetState state, SpanReader reader) - { - } - public static void ClientVersion(NetState state, SpanReader reader) { - var version = state.Version = new CV(reader.ReadAscii()); + var version = state.Version = new ClientVersion(reader.ReadAscii()); ClientVerification.ClientVersionReceived(state, version); } @@ -224,7 +217,7 @@ public static class IncomingAccountPackets reader.ReadUInt16(); int type = reader.ReadUInt16(); - var version = state.Version = new CV(reader.ReadAscii()); + var version = state.Version = new ClientVersion(reader.ReadAscii()); ClientVerification.ClientVersionReceived(state, version); } @@ -420,9 +413,9 @@ public static class IncomingAccountPackets var username = reader.ReadAscii(30); var password = reader.ReadAscii(30); - var e = new GameLoginEventArgs(state, username, password); + var e = new GameServer.GameLoginEventArgs(state, username, password); - EventSink.InvokeGameLogin(e); + GameServer.GameServerLoginEvent(e); if (e.Accepted) { @@ -501,9 +494,9 @@ public static class IncomingAccountPackets if (accountLoginEventArgs.Accepted) { - var serverListEventArgs = new ServerListEventArgs(state, state.Account); + var serverListEventArgs = new GatewayServer.ServerListEventArgs(state, state.Account); - EventSink.InvokeServerList(serverListEventArgs); + GatewayServer.ServerListEvent(serverListEventArgs); if (serverListEventArgs.Rejected) { diff --git a/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs b/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs index 00216857c..c593a56a2 100644 --- a/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs +++ b/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * + * Copyright 2019-2024 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IncomingExtendedCommandPackets.cs * * * @@ -15,12 +15,13 @@ using System.Buffers; using System.Runtime.CompilerServices; +using ModernUO.CodeGeneratedEvents; using Server.Items; using Server.Mobiles; namespace Server.Network; -public static class IncomingExtendedCommandPackets +public static partial class IncomingExtendedCommandPackets { private static readonly PacketHandler[] _extendedHandlers = new PacketHandler[0x100]; @@ -432,13 +433,16 @@ public static class IncomingExtendedCommandPackets PlayerMobile.TargetedSkillUse(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), skillId); } + [GeneratedEvent("TargetByResourceMacro")] + public static partial void InvokeTargetByResourceMacro(Mobile m, Item item, short resourceType); + public static void TargetByResourceMacro(NetState state, SpanReader reader) { var serial = (Serial)reader.ReadUInt32(); if (serial.IsItem) { - EventSink.InvokeTargetByResourceMacro(state.Mobile, World.FindItem(serial), reader.ReadInt16()); + InvokeTargetByResourceMacro(state.Mobile, World.FindItem(serial), reader.ReadInt16()); } } }