From dbaea65c197eade4881abe8512cfe77586db900c Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Mon, 19 Jun 2017 16:30:04 -0400 Subject: [PATCH] Fixed how login/zoning session start is handled. Should fix the bug where a player could not relogin into a server twice. --- FFXIVClassic Map Server/PacketProcessor.cs | 5 ++++- .../WorldPackets/Receive/SessionBeginPacket.cs | 16 +++++++++++++++- .../DataObjects/ZoneServer.cs | 4 ++-- FFXIVClassic World Server/PacketProcessor.cs | 2 +- .../WorldPackets/Send/SessionBeginPacket.cs | 13 ++++++++++++- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/FFXIVClassic Map Server/PacketProcessor.cs b/FFXIVClassic Map Server/PacketProcessor.cs index 783dfba0..d8a748c3 100644 --- a/FFXIVClassic Map Server/PacketProcessor.cs +++ b/FFXIVClassic Map Server/PacketProcessor.cs @@ -56,9 +56,12 @@ namespace FFXIVClassic_Map_Server //World Server - Session Begin case 0x1000: subpacket.DebugPrintSubPacket(); + + SessionBeginPacket beginSessionPacket = new SessionBeginPacket(subpacket.data); + session = mServer.AddSession(subpacket.header.targetId); - if (session.GetActor().destinationZone != 0) + if (beginSessionPacket.isLogin) Server.GetWorldManager().DoZoneIn(session.GetActor(), false, session.GetActor().destinationSpawnType); Program.Log.Info("{0} has been added to the session list.", session.GetActor().customDisplayName); diff --git a/FFXIVClassic Map Server/packets/WorldPackets/Receive/SessionBeginPacket.cs b/FFXIVClassic Map Server/packets/WorldPackets/Receive/SessionBeginPacket.cs index 3baf9b98..f970004e 100644 --- a/FFXIVClassic Map Server/packets/WorldPackets/Receive/SessionBeginPacket.cs +++ b/FFXIVClassic Map Server/packets/WorldPackets/Receive/SessionBeginPacket.cs @@ -9,11 +9,25 @@ namespace FFXIVClassic_Map_Server.packets.WorldPackets.Receive { class SessionBeginPacket { + public bool isLogin; public bool invalidPacket = false; public SessionBeginPacket(byte[] data) { - + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + isLogin = binReader.ReadByte() != 0; + } + catch (Exception) + { + invalidPacket = true; + } + } + } } } } diff --git a/FFXIVClassic World Server/DataObjects/ZoneServer.cs b/FFXIVClassic World Server/DataObjects/ZoneServer.cs index 2ed92de4..8b957bb0 100644 --- a/FFXIVClassic World Server/DataObjects/ZoneServer.cs +++ b/FFXIVClassic World Server/DataObjects/ZoneServer.cs @@ -150,9 +150,9 @@ namespace FFXIVClassic_World_Server.DataObjects } } - public void SendSessionStart(Session session) + public void SendSessionStart(Session session, bool isLogin = false) { - SendPacket(SessionBeginPacket.BuildPacket(session)); + SendPacket(SessionBeginPacket.BuildPacket(session, isLogin)); } public void SendSessionEnd(Session session) diff --git a/FFXIVClassic World Server/PacketProcessor.cs b/FFXIVClassic World Server/PacketProcessor.cs index 95e27eea..3049cdf5 100644 --- a/FFXIVClassic World Server/PacketProcessor.cs +++ b/FFXIVClassic World Server/PacketProcessor.cs @@ -56,7 +56,7 @@ namespace FFXIVClassic_World_Server mServer.AddSession(client, Session.Channel.ZONE, hello.sessionId); Session session = mServer.GetSession(hello.sessionId); session.routing1 = mServer.GetWorldManager().GetZoneServer(session.currentZoneId); - session.routing1.SendSessionStart(session); + session.routing1.SendSessionStart(session, true); } else if (packet.header.connectionType == BasePacket.TYPE_CHAT) mServer.AddSession(client, Session.Channel.CHAT, hello.sessionId); diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Send/SessionBeginPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Send/SessionBeginPacket.cs index 686aceeb..d77a1634 100644 --- a/FFXIVClassic World Server/Packets/WorldPackets/Send/SessionBeginPacket.cs +++ b/FFXIVClassic World Server/Packets/WorldPackets/Send/SessionBeginPacket.cs @@ -14,10 +14,21 @@ namespace FFXIVClassic_World_Server.Packets.WorldPackets.Send public const ushort OPCODE = 0x1000; public const uint PACKET_SIZE = 0x24; - public static SubPacket BuildPacket(Session session) + public static SubPacket BuildPacket(Session session, bool isLogin) { byte[] data = new byte[PACKET_SIZE - 0x20]; + if (isLogin) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + binWriter.Write((Byte)1); + } + } + } + return new SubPacket(true, OPCODE, 0, session.sessionId, data); } }