From d94fcdfa766d49c65c0280727adfd896e1f988f7 Mon Sep 17 00:00:00 2001 From: Longfeng Qin Date: Mon, 16 Sep 2024 15:30:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E6=9C=AA?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=95=B0=E6=8D=AE=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/Client.cs | 10 ++-- Server/Packets/Handlers/03-00-MapTransfer.cs | 20 ++++++++ Server/Packets/Handlers/03-03-InitialLoad.cs | 9 +++- Server/Packets/Handlers/03-06-UNK.cs | 19 +++++++ .../Packets/Handlers/04-14-ObjectInteract.cs | 8 +-- Server/Packets/Handlers/07-00-ChatHandler.cs | 46 ++++++++++++++++- Server/Packets/Handlers/0B-09-UNK.cs | 18 +++---- Server/Packets/Handlers/0E-19-UNK.cs | 18 +++---- Server/Packets/Handlers/11-04-StartGame.cs | 4 +- Server/Packets/Handlers/11-0B-KeyExchange.cs | 2 +- .../03-04-LoadingScreenTransitionPacket.cs | 11 +++++ .../PSOPackets/03-08-ServerHelloPacket.cs | 49 +++++++++++++++++++ Server/Server.csproj | 4 ++ 13 files changed, 185 insertions(+), 33 deletions(-) create mode 100644 Server/Packets/Handlers/03-00-MapTransfer.cs create mode 100644 Server/Packets/Handlers/03-06-UNK.cs create mode 100644 Server/Packets/PSOPackets/03-04-LoadingScreenTransitionPacket.cs create mode 100644 Server/Packets/PSOPackets/03-08-ServerHelloPacket.cs diff --git a/Server/Client.cs b/Server/Client.cs index c94fe13..955cd24 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -6,6 +6,7 @@ using PSO2SERVER.Models; using PSO2SERVER.Network; using PSO2SERVER.Packets; using PSO2SERVER.Packets.Handlers; +using PSO2SERVER.Packets.PSOPackets; using PSO2SERVER.Zone; namespace PSO2SERVER @@ -34,12 +35,7 @@ namespace PSO2SERVER InputArc4 = null; OutputArc4 = null; - var welcome = new PacketWriter(); - welcome.Write((ushort)3); - welcome.Write((ushort)201); - welcome.Write((ushort)0); - welcome.Write((ushort)0); - SendPacket(0x03, 0x08, 0, welcome.ToArray()); + SendPacket(new ServerHelloPacket()); } public bool IsClosed { get; private set; } @@ -65,7 +61,7 @@ namespace PSO2SERVER return; } - Logger.Write("[接收] 接收到 {0} 字节", size); + //Logger.Write("[接收] 接收到 {0} 字节", size); Array.Copy(data, 0, _readBuffer, _readBufferSize, size); diff --git a/Server/Packets/Handlers/03-00-MapTransfer.cs b/Server/Packets/Handlers/03-00-MapTransfer.cs new file mode 100644 index 0000000..cc3e19c --- /dev/null +++ b/Server/Packets/Handlers/03-00-MapTransfer.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PSO2SERVER.Packets.Handlers +{ + + //[PacketHandlerAttr(0x03, 0x00)] + //class MapTransfer : PacketHandler + //{ + // /// (0x03, 0x00) Map Transfer. + // public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) + // { + // //var info = string.Format("[接收] 接收到的数据 (hex): "); + // //Logger.WriteHex(info, data); + // } + //} +} diff --git a/Server/Packets/Handlers/03-03-InitialLoad.cs b/Server/Packets/Handlers/03-03-InitialLoad.cs index 839efe3..ecd1017 100644 --- a/Server/Packets/Handlers/03-03-InitialLoad.cs +++ b/Server/Packets/Handlers/03-03-InitialLoad.cs @@ -9,6 +9,13 @@ namespace PSO2SERVER.Packets.Handlers [PacketHandlerAttr(0x03, 0x03)] public class InitialLoad : PacketHandler { + /// (0x03, 0x03) Initial Load (?). + /// + /// (C -> S) Sent when the client loads for the first time in the session. + /// + /// Response to: [`Packet::LoadingScreenTransition`] (?). + /// + /// Respond with: lobby map setup. // Ninji note: 3-3 may not be the correct place to do this // Once we have better state tracking, we should make sure that // 3-3 only does anything at the points where the client is supposed @@ -26,7 +33,7 @@ namespace PSO2SERVER.Packets.Handlers // Set Player ID var setPlayerId = new PacketWriter(); setPlayerId.WritePlayerHeader((uint)context.User.PlayerId); - context.SendPacket(6, 0, 0, setPlayerId.ToArray()); + context.SendPacket(0x06, 0x00, 0, setPlayerId.ToArray()); // Spawn Player new CharacterSpawn().HandlePacket(context, flags, data, position, size); diff --git a/Server/Packets/Handlers/03-06-UNK.cs b/Server/Packets/Handlers/03-06-UNK.cs new file mode 100644 index 0000000..5706ce1 --- /dev/null +++ b/Server/Packets/Handlers/03-06-UNK.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PSO2SERVER.Packets.Handlers +{ + + //[PacketHandlerAttr(0x03, 0x06)] + //class _0B_06_UNK : PacketHandler + //{ + // public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) + // { + // //var info = string.Format("[接收] 接收到的数据 (hex): "); + // //Logger.WriteHex(info, data); + // } + //} +} diff --git a/Server/Packets/Handlers/04-14-ObjectInteract.cs b/Server/Packets/Handlers/04-14-ObjectInteract.cs index dc7f341..35aca05 100644 --- a/Server/Packets/Handlers/04-14-ObjectInteract.cs +++ b/Server/Packets/Handlers/04-14-ObjectInteract.cs @@ -28,9 +28,11 @@ namespace PSO2SERVER.Packets.Handlers } else if(srcObject.EntityType == EntityType.Player) { - srcObj = new PSOObject(); - srcObj.Header = srcObject; - srcObj.Name = "Player"; + srcObj = new PSOObject + { + Header = srcObject, + Name = "Player" + }; } else { diff --git a/Server/Packets/Handlers/07-00-ChatHandler.cs b/Server/Packets/Handlers/07-00-ChatHandler.cs index e951cf8..d59e304 100644 --- a/Server/Packets/Handlers/07-00-ChatHandler.cs +++ b/Server/Packets/Handlers/07-00-ChatHandler.cs @@ -1,11 +1,34 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using System.Linq; namespace PSO2SERVER.Packets.Handlers { + [PacketHandlerAttr(0x07, 0x00)] public class ChatHandler : PacketHandler { + //public uint Unk1 { get; set; } + //public uint Unk2 { get; set; } + //public uint Unk3 { get; set; } + //public byte[] VerId { get; set; } = new byte[0x20]; + //public List Interfaces { get; set; } = new List(); + //public byte[] Unk4 { get; set; } = new byte[0x90]; + //public byte[] Unk5 { get; set; } = new byte[0x10]; + //public Language TextLang { get; set; } + //public Language VoiceLang { get; set; } + //public Language TextLang2 { get; set; } + //public Language LangLang { get; set; } + //public string Language { get; set; } = new string(' ', 0x10); + //public uint Unk6 { get; set; } + //public uint Unk7 { get; set; } + //public uint Magic1 { get; set; } + //public byte[] Unk8 { get; set; } = new byte[0x20]; + //public byte[] Unk9 { get; set; } = new byte[0x44]; + //public string Username { get; set; } = new string(' ', 0x40); + //public string Password { get; set; } = new string(' ', 0x40); + //public uint Unk10 { get; set; } + //public string Unk11 { get; set; } #region implemented abstract members of PacketHandler public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) @@ -67,4 +90,25 @@ namespace PSO2SERVER.Packets.Handlers #endregion } + public enum MessageChannel : byte + { + // Map channel. + Map = 0, + + // Party channel. + Party = 1, + + // Alliance channel. + Alliance = 2, + + // Whisper channel. + Whisper = 3, + + // Group channel. + Group = 4, + + // Undefined channel. + Undefined = 0xFF + } + } \ No newline at end of file diff --git a/Server/Packets/Handlers/0B-09-UNK.cs b/Server/Packets/Handlers/0B-09-UNK.cs index dfd1aa6..dd976ff 100644 --- a/Server/Packets/Handlers/0B-09-UNK.cs +++ b/Server/Packets/Handlers/0B-09-UNK.cs @@ -4,13 +4,13 @@ using PSO2SERVER.Packets.PSOPackets; namespace PSO2SERVER.Packets.Handlers { - [PacketHandlerAttr(0x0B, 0x09)] - class _0B_09_UNK : PacketHandler - { - public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) - { - var info = string.Format("[接收] 接收到的数据 (hex): "); - Logger.WriteHex(info, data); - } - } + //[PacketHandlerAttr(0x0B, 0x09)] + //class _0B_09_UNK : PacketHandler + //{ + // public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) + // { + // //var info = string.Format("[接收] 接收到的数据 (hex): "); + // //Logger.WriteHex(info, data); + // } + //} } diff --git a/Server/Packets/Handlers/0E-19-UNK.cs b/Server/Packets/Handlers/0E-19-UNK.cs index b7ebe09..365682c 100644 --- a/Server/Packets/Handlers/0E-19-UNK.cs +++ b/Server/Packets/Handlers/0E-19-UNK.cs @@ -4,13 +4,13 @@ using PSO2SERVER.Packets.PSOPackets; namespace PSO2SERVER.Packets.Handlers { - [PacketHandlerAttr(0x0E, 0x19)] - class _0E_19_UNK : PacketHandler - { - public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) - { - var info = string.Format("[接收] 接收到的数据 (hex): "); - Logger.WriteHex(info, data); - } - } +// [PacketHandlerAttr(0x0E, 0x19)] +// class _0E_19_UNK : PacketHandler +// { +// public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size) +// { +// //var info = string.Format("[接收] 接收到的数据 (hex): "); +// //Logger.WriteHex(info, data); +// } +// } } diff --git a/Server/Packets/Handlers/11-04-StartGame.cs b/Server/Packets/Handlers/11-04-StartGame.cs index b234dd0..a83cf2a 100644 --- a/Server/Packets/Handlers/11-04-StartGame.cs +++ b/Server/Packets/Handlers/11-04-StartGame.cs @@ -5,7 +5,7 @@ using System.Linq; namespace PSO2SERVER.Packets.Handlers { - [PacketHandlerAttr(0x11, 0x4)] + [PacketHandlerAttr(0x11, 0x04)] public class StartGame : PacketHandler { #region implemented abstract members of PacketHandler @@ -46,7 +46,7 @@ namespace PSO2SERVER.Packets.Handlers PartyManager.Instance.CreateNewParty(context); // Transition to the loading screen - context.SendPacket(new NoPayloadPacket(0x3, 0x4)); + context.SendPacket(new NoPayloadPacket(0x03, 0x04)); // TODO Set area, Set character, possibly more. See PolarisLegacy for more. } diff --git a/Server/Packets/Handlers/11-0B-KeyExchange.cs b/Server/Packets/Handlers/11-0B-KeyExchange.cs index 03d95e5..a61772f 100644 --- a/Server/Packets/Handlers/11-0B-KeyExchange.cs +++ b/Server/Packets/Handlers/11-0B-KeyExchange.cs @@ -78,7 +78,7 @@ namespace PSO2SERVER.Packets.Handlers var decryptedToken = new byte[16]; tempDecryptor.TransformBlock(decryptedBlob, 0, 0x10, decryptedToken, 0); - context.SendPacket(0x11, 0xC, 0, decryptedToken); + context.SendPacket(0x11, 0x0C, 0, decryptedToken); } #endregion diff --git a/Server/Packets/PSOPackets/03-04-LoadingScreenTransitionPacket.cs b/Server/Packets/PSOPackets/03-04-LoadingScreenTransitionPacket.cs new file mode 100644 index 0000000..b58653b --- /dev/null +++ b/Server/Packets/PSOPackets/03-04-LoadingScreenTransitionPacket.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace PSO2SERVER.Packets.PSOPackets +{ + class LoadingScreenTransitionPacket + { + } +} diff --git a/Server/Packets/PSOPackets/03-08-ServerHelloPacket.cs b/Server/Packets/PSOPackets/03-08-ServerHelloPacket.cs new file mode 100644 index 0000000..67b766b --- /dev/null +++ b/Server/Packets/PSOPackets/03-08-ServerHelloPacket.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using PSO2SERVER.Models; + +namespace PSO2SERVER.Packets.PSOPackets +{ + class ServerHelloPacket : Packet + { + + /// + /// Unknown. Seems to be always 0x03. + /// + public ushort Unk1 { get; set; } + + /// + /// Block Id. + /// + public ushort BlockId { get; set; } + + public uint Unk2 { get; set; } + + public ServerHelloPacket() + { + Unk1 = 0x03; // Initialize Unk1 with default value + } + + public override byte[] Build() + { + + //var welcome = new PacketWriter(); + //welcome.Write((ushort)3); + //welcome.Write((ushort)201); + //welcome.Write((ushort)0); + //welcome.Write((ushort)0); + + PacketWriter writer = new PacketWriter(); + writer.Write(Unk1); + writer.Seek(4, SeekOrigin.Current); // Skip 4 bytes + writer.Write(BlockId); + writer.Write(Unk2); + return writer.ToArray(); + } + + public override PacketHeader GetHeader() + { + return new PacketHeader(0x03, 0x08, PacketFlags.None); + } + } +} diff --git a/Server/Server.csproj b/Server/Server.csproj index c36e01d..b3c9f3b 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -170,6 +170,8 @@ + + @@ -194,6 +196,7 @@ + @@ -207,6 +210,7 @@ +