diff --git a/FFXIVClassic World Server/DataObjects/Session.cs b/FFXIVClassic World Server/DataObjects/Session.cs index 4bebf269..5a0085b9 100644 --- a/FFXIVClassic World Server/DataObjects/Session.cs +++ b/FFXIVClassic World Server/DataObjects/Session.cs @@ -12,6 +12,10 @@ namespace FFXIVClassic_World_Server.DataObjects public enum Channel {ZONE, CHAT}; public readonly uint sessionId; + + public string characterName; + public uint currentZoneId; + public readonly ClientConnection clientConnection; public readonly Channel type; public ZoneServer routing1, routing2; @@ -22,7 +26,8 @@ namespace FFXIVClassic_World_Server.DataObjects this.clientConnection = connection; this.type = type; connection.owner = this; + Database.LoadZoneSessionInfo(this); } - + } } diff --git a/FFXIVClassic World Server/Database.cs b/FFXIVClassic World Server/Database.cs index dc835a18..e9f48004 100644 --- a/FFXIVClassic World Server/Database.cs +++ b/FFXIVClassic World Server/Database.cs @@ -1,9 +1,6 @@ using MySql.Data.MySqlClient; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using FFXIVClassic_World_Server.DataObjects; using FFXIVClassic_World_Server.DataObjects.Group; @@ -11,6 +8,48 @@ namespace FFXIVClassic_World_Server { class Database { + public static bool LoadZoneSessionInfo(Session session) + { + string characterName; + uint currentZone = 0; + uint destinationZone = 0; + bool readIn = false; + + using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) + { + try + { + conn.Open(); + MySqlCommand cmd = new MySqlCommand("SELECT name, currentZoneId, destinationZoneId FROM characters WHERE id = @charaId", conn); + cmd.Parameters.AddWithValue("@charaId", session.sessionId); + using (MySqlDataReader Reader = cmd.ExecuteReader()) + { + while (Reader.Read()) + { + characterName = Reader.GetString("name"); + currentZone = Reader.GetUInt32("currentZoneId"); + destinationZone = Reader.GetUInt32("destinationZoneId"); + + session.characterName = characterName; + session.currentZoneId = currentZone; + + readIn = true; + } + } + } + catch (MySqlException e) + { + Program.Log.Error(e.ToString()); + } + finally + { + conn.Dispose(); + } + } + + return readIn; + } + public static uint GetCurrentZoneForSession(uint charId) { uint currentZone = 0; @@ -50,7 +89,7 @@ namespace FFXIVClassic_World_Server { return 0; } - } + } public static Dictionary GetRetainers(uint charaId) { diff --git a/FFXIVClassic World Server/FFXIVClassic World Server.csproj b/FFXIVClassic World Server/FFXIVClassic World Server.csproj index e1609081..3b738158 100644 --- a/FFXIVClassic World Server/FFXIVClassic World Server.csproj +++ b/FFXIVClassic World Server/FFXIVClassic World Server.csproj @@ -82,8 +82,11 @@ - - + + + + + diff --git a/FFXIVClassic World Server/LinkshellManager.cs b/FFXIVClassic World Server/LinkshellManager.cs index 84e263ab..174f6f54 100644 --- a/FFXIVClassic World Server/LinkshellManager.cs +++ b/FFXIVClassic World Server/LinkshellManager.cs @@ -50,7 +50,7 @@ namespace FFXIVClassic_World_Server } //Creates a new linkshell and adds it to the list - public bool DeleteLinkshell(uint groupInstanceId) + public bool DeleteLinkshell(ulong groupInstanceId) { if (mCurrentWorldGroupsReference.ContainsKey(groupInstanceId)) { diff --git a/FFXIVClassic World Server/PacketProcessor.cs b/FFXIVClassic World Server/PacketProcessor.cs index 34793e38..0df0beb0 100644 --- a/FFXIVClassic World Server/PacketProcessor.cs +++ b/FFXIVClassic World Server/PacketProcessor.cs @@ -110,6 +110,7 @@ namespace FFXIVClassic_World_Server //Check destination, if != 0, update route and start new session if (endConfirmPacket.destinationZone != 0) { + session.currentZoneId = endConfirmPacket.destinationZone; session.routing1 = Server.GetServer().GetWorldManager().GetZoneServer(endConfirmPacket.destinationZone); session.routing1.SendSessionStart(session); } @@ -122,7 +123,7 @@ namespace FFXIVClassic_World_Server else Program.Log.Error("Session {0} had an error ending session.", endConfirmPacket.sessionId); - break; + break; //Zone Change Request case 0x1002: WorldRequestZoneChangePacket zoneChangePacket = new WorldRequestZoneChangePacket(packet.data); diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/CreateLinkshellPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/CreateLinkshellPacket.cs new file mode 100644 index 00000000..aa952d1a --- /dev/null +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/CreateLinkshellPacket.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group +{ + class CreateLinkshellPacket + { + public bool invalidPacket = false; + + public string name; + public ushort crestid; + public uint master; + + public CreateLinkshellPacket(byte[] data) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + name = Encoding.ASCII.GetString(binReader.ReadBytes(0x20)).Trim(new[] { '\0' }); + crestid = binReader.ReadUInt16(); + master = binReader.ReadUInt32(); + } + catch (Exception) + { + invalidPacket = true; + } + } + } + } + } +} diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/CreateRelationPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/CreateRelationPacket.cs new file mode 100644 index 00000000..eb573b5b --- /dev/null +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/CreateRelationPacket.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group +{ + class CreateRelationPacket + { + public bool invalidPacket = false; + + public uint host; + public uint guest; + public uint command; + + public CreateRelationPacket(byte[] data) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + host = binReader.ReadUInt32(); + guest = binReader.ReadUInt32(); + command = binReader.ReadUInt32(); + } + catch (Exception) + { + invalidPacket = true; + } + } + } + } + } +} diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GroupControlGetDeletePacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/DeleteGroupPacket.cs similarity index 65% rename from FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GroupControlGetDeletePacket.cs rename to FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/DeleteGroupPacket.cs index 9090d39d..9400b018 100644 --- a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GroupControlGetDeletePacket.cs +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/DeleteGroupPacket.cs @@ -3,16 +3,12 @@ using System.IO; namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group { - class GroupControlGetDeletePacket + class DeleteGroupPacket { - public const byte GROUP_CONTROL_GET = 0; - public const byte GROUP_CONTROL_DELETE = 1; - - public bool invalidPacket = false; - public uint controlCode; + public bool invalidPacket = false; public ulong groupId; - public GroupControlGetDeletePacket(byte[] data) + public DeleteGroupPacket(byte[] data) { using (MemoryStream mem = new MemoryStream(data)) { @@ -20,7 +16,6 @@ namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group { try { - controlCode = binReader.ReadUInt32(); groupId = binReader.ReadUInt64(); } catch (Exception) diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GetGroupPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GetGroupPacket.cs new file mode 100644 index 00000000..5276bfac --- /dev/null +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GetGroupPacket.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; + +namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group +{ + class GetGroupPacket + { + public bool invalidPacket = false; + public ulong groupId; + + public GetGroupPacket(byte[] data) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + groupId = binReader.ReadUInt64(); + } + catch (Exception) + { + invalidPacket = true; + } + } + } + } + } +} diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GroupControlCreateModifyPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GroupControlCreateModifyPacket.cs deleted file mode 100644 index 502fef6f..00000000 --- a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/GroupControlCreateModifyPacket.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.IO; - -namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group -{ - class GroupControlCreateModifyPacket - { - public const byte GROUP_CONTROL_CREATE = 0; - public const byte GROUP_CONTROL_MODIFY = 1; - - public const byte GROUP_PARTY = 0; - public const byte GROUP_RETAINER = 1; - public const byte GROUP_LINKSHELL = 2; - public const byte GROUP_RELATION = 3; - - public bool invalidPacket = false; - public byte controlCode; - public ulong groupId; - public byte groupType; - - public GroupControlCreateModifyPacket(byte[] data) - { - using (MemoryStream mem = new MemoryStream(data)) - { - using (BinaryReader binReader = new BinaryReader(mem)) - { - try - { - controlCode = binReader.ReadByte(); - groupType = binReader.ReadByte(); - groupId = binReader.ReadUInt64(); - - //Work value data - } - catch (Exception) - { - invalidPacket = true; - } - } - } - } - } -} diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/ModifyLinkshellPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/ModifyLinkshellPacket.cs new file mode 100644 index 00000000..7fd5f3ca --- /dev/null +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/ModifyLinkshellPacket.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; +using System.Text; + +namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group +{ + class ModifyLinkshellPacket + { + public bool invalidPacket = false; + + public ushort argCode; + public string name; + public ushort crestid; + public uint master; + + public ModifyLinkshellPacket(byte[] data) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + argCode = binReader.ReadUInt16(); + + switch (argCode) + { + case 0: + name = Encoding.ASCII.GetString(binReader.ReadBytes(0x20)).Trim(new[] { '\0' }); + break; + case 1: + crestid = binReader.ReadUInt16(); + break; + case 2: + master = binReader.ReadUInt32(); + break; + } + } + catch (Exception) + { + invalidPacket = true; + } + } + } + } + } +} diff --git a/FFXIVClassic World Server/Server.cs b/FFXIVClassic World Server/Server.cs index 883403f7..41ce633d 100644 --- a/FFXIVClassic World Server/Server.cs +++ b/FFXIVClassic World Server/Server.cs @@ -204,60 +204,25 @@ namespace FFXIVClassic_World_Server } break; - //Group Control Create or Modify + //Group get data request case 0x1020: - GroupControlCreateModifyPacket gCreateModifyPacket = new GroupControlCreateModifyPacket(subpacket.data); - - if (gCreateModifyPacket.controlCode == GroupControlCreateModifyPacket.GROUP_CONTROL_CREATE) - { - ulong groupId; - switch (gCreateModifyPacket.groupType) - { - case GroupControlCreateModifyPacket.GROUP_PARTY: - //mPartyManager.CreateParty(); - break; - case GroupControlCreateModifyPacket.GROUP_RETAINER: - //mPartyManager.CreateParty(); - break; - case GroupControlCreateModifyPacket.GROUP_LINKSHELL: - //mPartyManager.CreateParty(); - break; - case GroupControlCreateModifyPacket.GROUP_RELATION: - //mPartyManager.CreateParty(); - break; - } - } - else if (gCreateModifyPacket.controlCode == GroupControlCreateModifyPacket.GROUP_CONTROL_MODIFY) - { - switch (gCreateModifyPacket.groupType) - { - case GroupControlCreateModifyPacket.GROUP_PARTY: - //mPartyManager.CreateParty(); - break; - case GroupControlCreateModifyPacket.GROUP_RETAINER: - //mPartyManager.CreateParty(); - break; - case GroupControlCreateModifyPacket.GROUP_LINKSHELL: - //mPartyManager.CreateParty(); - break; - case GroupControlCreateModifyPacket.GROUP_RELATION: - //mPartyManager.CreateParty(); - break; - } - } - + GetGroupPacket getGroupPacket = new GetGroupPacket(subpacket.data); + SendGroupData(session, getGroupPacket.groupId); break; - //Group Control Get or Delete + //Group delete request case 0x1021: - GroupControlGetDeletePacket gGetDeletePacket = new GroupControlGetDeletePacket(subpacket.data); - if (gGetDeletePacket.controlCode == GroupControlGetDeletePacket.GROUP_CONTROL_GET) - { - - } - else if (gGetDeletePacket.controlCode == GroupControlGetDeletePacket.GROUP_CONTROL_DELETE) - { - - } + DeleteGroupPacket deleteGroupPacket = new DeleteGroupPacket(subpacket.data); + DeleteGroup(deleteGroupPacket.groupId); + break; + //Linkshell create request + case 0x1023: + CreateLinkshellPacket createLinkshellpacket = new CreateLinkshellPacket(subpacket.data); + mLinkshellManager.CreateLinkshell(createLinkshellpacket.name, createLinkshellpacket.crestid, createLinkshellpacket.master); + break; + //Linkshell modify request + case 0x1024: + ModifyLinkshellPacket modifyLinkshellpacket = new ModifyLinkshellPacket(subpacket.data); + mLinkshellManager.ModifyLinkshell(); break; //Group Add/Remove Member case 0x1022: @@ -265,8 +230,7 @@ namespace FFXIVClassic_World_Server break; } } - - if (mZoneSessionList.ContainsKey(sessionId)) + else if (mZoneSessionList.ContainsKey(sessionId)) { ClientConnection conn = mZoneSessionList[sessionId].clientConnection; conn.QueuePacket(subpacket, true, false); @@ -410,7 +374,58 @@ namespace FFXIVClassic_World_Server } } - #endregion + #endregion + + private void SendGroupData(Session session, ulong groupId) + { + if (mCurrentWorldGroups.ContainsKey(groupId)) + { + Group group = mCurrentWorldGroups[groupId]; + + } + } + + private void SendGroupDataToAllMembers(ulong groupId) + { + if (mCurrentWorldGroups.ContainsKey(groupId)) + { + Group group = mCurrentWorldGroups[groupId]; + + } + } + + public void GetGroup(Group group) + { + if (group is Party) + { + + } + else if (group is RetainerGroup) + { + + } + else if (group is Linkshell) + { + + } + else if (group is Relation) + { + + } + } + + public void DeleteGroup(ulong id) + { + if (!mCurrentWorldGroups.ContainsKey(id)) + return; + Group group = mCurrentWorldGroups[id]; + if (group is Party) + mPartyManager.DeleteParty(group.groupIndex); + else if (group is Linkshell) + mLinkshellManager.DeleteLinkshell(group.groupIndex); + else if (group is Relation) + mRelationGroupManager.DeleteRelationGroup(group.groupIndex); + } public void IncrementGroupIndex() { diff --git a/FFXIVClassic World Server/WorldMaster.cs b/FFXIVClassic World Server/WorldMaster.cs index b7c1d0bb..7d88bf31 100644 --- a/FFXIVClassic World Server/WorldMaster.cs +++ b/FFXIVClassic World Server/WorldMaster.cs @@ -173,6 +173,12 @@ namespace FFXIVClassic_World_Server if (zs == null) return; + session.currentZoneId = destinationZoneId; + + //Intrazone change, just update the id + if (zs.Equals(session.routing1)) + return; + if (zs.isConnected) session.routing1.SendSessionEnd(session, destinationZoneId, destinationPrivateArea, spawnType, spawnX, spawnY, spawnZ, spawnRotation); else if (zs.Connect()) @@ -184,7 +190,7 @@ namespace FFXIVClassic_World_Server //Login Zone In public void DoLogin(Session session) { - session.routing1 = GetZoneServer(Database.GetCurrentZoneForSession(session.sessionId)); + session.routing1 = GetZoneServer(session.currentZoneId); session.routing1.SendSessionStart(session); }