From 5af1f6dba68a3b09093a4cd7b63dcb0cb5d9114e Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Mon, 2 Jan 2017 11:47:14 -0500 Subject: [PATCH] Relation group work. --- .../FFXIVClassic Map Server.csproj | 2 + .../Send/Group/PartyInvitePacket.cs | 45 ++++++++++++++++ .../Send/Group/PartyInviteResultPacket.cs | 31 +++++++++++ .../DataObjects/Group/Party.cs | 2 +- .../DataObjects/Group/Relation.cs | 10 ++++ .../FFXIVClassic World Server.csproj | 2 + .../Receive/Group/PartyInvitePacket.cs | 39 ++++++++++++++ .../Receive/Group/PartyInviteResultPacket.cs | 32 +++++++++++ .../RelationGroupManager.cs | 54 ++++++++++++++++--- FFXIVClassic World Server/Server.cs | 15 ++++++ FFXIVClassic World Server/WorldMaster.cs | 18 +++---- 11 files changed, 234 insertions(+), 16 deletions(-) create mode 100644 FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInvitePacket.cs create mode 100644 FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInviteResultPacket.cs create mode 100644 FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInvitePacket.cs create mode 100644 FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInviteResultPacket.cs diff --git a/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj b/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj index 20947c99..9df052dc 100644 --- a/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj +++ b/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj @@ -286,6 +286,8 @@ + + diff --git a/FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInvitePacket.cs b/FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInvitePacket.cs new file mode 100644 index 00000000..8df14982 --- /dev/null +++ b/FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInvitePacket.cs @@ -0,0 +1,45 @@ +using FFXIVClassic.Common; +using FFXIVClassic_Map_Server.dataobjects; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FFXIVClassic_Map_Server.packets.WorldPackets.Send.Group +{ + class PartyInvitePacket + { + public const ushort OPCODE = 0x1022; + public const uint PACKET_SIZE = 0x48; + + public static SubPacket BuildPacket(Session session, string name) + { + byte[] data = new byte[PACKET_SIZE - 0x20]; + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + binWriter.Write((UInt16)0); + binWriter.Write(Encoding.ASCII.GetBytes(name), 0, Encoding.ASCII.GetByteCount(name) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(name)); + } + } + return new SubPacket(true, OPCODE, session.id, session.id, data); + } + + public static SubPacket BuildPacket(Session session, uint actorId) + { + byte[] data = new byte[PACKET_SIZE - 0x20]; + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + binWriter.Write((UInt16)1); + binWriter.Write((UInt32)actorId); + } + } + return new SubPacket(true, OPCODE, session.id, session.id, data); + } + } +} diff --git a/FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInviteResultPacket.cs b/FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInviteResultPacket.cs new file mode 100644 index 00000000..6fc17074 --- /dev/null +++ b/FFXIVClassic Map Server/packets/WorldPackets/Send/Group/PartyInviteResultPacket.cs @@ -0,0 +1,31 @@ +using FFXIVClassic.Common; +using FFXIVClassic_Map_Server.dataobjects; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FFXIVClassic_Map_Server.packets.WorldPackets.Send.Group +{ + class PartyInviteResultPacket + { + public const ushort OPCODE = 0x1023; + public const uint PACKET_SIZE = 0x28; + + public static SubPacket BuildPacket(Session session, uint result) + { + byte[] data = new byte[PACKET_SIZE - 0x20]; + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + binWriter.Write((UInt32)result); + } + } + return new SubPacket(true, OPCODE, session.id, session.id, data); + } + + } +} diff --git a/FFXIVClassic World Server/DataObjects/Group/Party.cs b/FFXIVClassic World Server/DataObjects/Group/Party.cs index 2447f1d6..1286d693 100644 --- a/FFXIVClassic World Server/DataObjects/Group/Party.cs +++ b/FFXIVClassic World Server/DataObjects/Group/Party.cs @@ -200,7 +200,7 @@ namespace FFXIVClassic_World_Server.DataObjects.Group public uint GetLeader() { - return (uint)((partyGroupWork._globalTemp.owner >> 32) & 0xFFFFFFFF); + return (uint)(((ulong)partyGroupWork._globalTemp.owner >> 32) & 0xFFFFFFFF); } public uint GetIdForName(string name) diff --git a/FFXIVClassic World Server/DataObjects/Group/Relation.cs b/FFXIVClassic World Server/DataObjects/Group/Relation.cs index 8c308e91..b256faf5 100644 --- a/FFXIVClassic World Server/DataObjects/Group/Relation.cs +++ b/FFXIVClassic World Server/DataObjects/Group/Relation.cs @@ -21,6 +21,16 @@ namespace FFXIVClassic_World_Server.DataObjects.Group work._globalTemp.variableCommand = command; } + public uint GetHost() + { + return (uint)(((ulong)work._globalTemp.host >> 32) & 0xFFFFFFFF); + } + + public uint GetOther() + { + return charaOther; + } + public override int GetMemberCount() { return 2; diff --git a/FFXIVClassic World Server/FFXIVClassic World Server.csproj b/FFXIVClassic World Server/FFXIVClassic World Server.csproj index 086a7145..5e6868d3 100644 --- a/FFXIVClassic World Server/FFXIVClassic World Server.csproj +++ b/FFXIVClassic World Server/FFXIVClassic World Server.csproj @@ -108,7 +108,9 @@ + + diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInvitePacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInvitePacket.cs new file mode 100644 index 00000000..796a1792 --- /dev/null +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInvitePacket.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group +{ + class PartyInvitePacket + { + public bool invalidPacket = false; + + public ushort command; + public string name; + public uint actorId; + + public PartyInvitePacket(byte[] data) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + command = binReader.ReadUInt16(); + + if (command == 0) + actorId = binReader.ReadUInt32(); + else + name = Encoding.ASCII.GetString(binReader.ReadBytes(0x20)).Trim(new[] { '\0' }); + } + catch (Exception) + { + invalidPacket = true; + } + } + } + } + } +} diff --git a/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInviteResultPacket.cs b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInviteResultPacket.cs new file mode 100644 index 00000000..f3fa8701 --- /dev/null +++ b/FFXIVClassic World Server/Packets/WorldPackets/Receive/Group/PartyInviteResultPacket.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group +{ + class PartyInviteResultPacket + { + public bool invalidPacket = false; + + public uint result; + + public PartyInviteResultPacket(byte[] data) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryReader binReader = new BinaryReader(mem)) + { + try + { + result = binReader.ReadUInt32(); + } + catch (Exception) + { + invalidPacket = true; + } + } + } + } + } +} diff --git a/FFXIVClassic World Server/RelationGroupManager.cs b/FFXIVClassic World Server/RelationGroupManager.cs index 7c211bce..c15f6bc1 100644 --- a/FFXIVClassic World Server/RelationGroupManager.cs +++ b/FFXIVClassic World Server/RelationGroupManager.cs @@ -9,7 +9,8 @@ namespace FFXIVClassic_World_Server private WorldManager mWorldManager; private Object mGroupLockReference; private Dictionary mCurrentWorldGroupsReference; - private Dictionary mRelationList = new Dictionary(); + private Dictionary mPartyRelationList = new Dictionary(); + private Dictionary mLinkshellRelationList = new Dictionary(); public RelationGroupManager(WorldManager worldManager, Object groupLock, Dictionary worldGroupList) { @@ -18,23 +19,64 @@ namespace FFXIVClassic_World_Server mCurrentWorldGroupsReference = worldGroupList; } - public Relation CreateRelationGroup(uint hostCharaId, uint otherCharaId, uint command) + public Relation CreatePartyRelationGroup(uint hostCharaId, uint otherCharaId) { lock (mGroupLockReference) { ulong groupIndex = mWorldManager.GetGroupIndex(); - Relation relation = new Relation(groupIndex, hostCharaId, otherCharaId, command); - mRelationList.Add(groupIndex, relation); + Relation relation = new Relation(groupIndex, hostCharaId, otherCharaId, 10001); + mPartyRelationList.Add(groupIndex, relation); mCurrentWorldGroupsReference.Add(groupIndex, relation); mWorldManager.IncrementGroupIndex(); return relation; } } + public Relation CreateLinkshellRelationGroup(uint hostCharaId, uint otherCharaId) + { + lock (mGroupLockReference) + { + ulong groupIndex = mWorldManager.GetGroupIndex(); + Relation relation = new Relation(groupIndex, hostCharaId, otherCharaId, 10002); + mLinkshellRelationList.Add(groupIndex, relation); + mCurrentWorldGroupsReference.Add(groupIndex, relation); + mWorldManager.IncrementGroupIndex(); + return relation; + } + } + + public Relation GetPartyRelationGroup(uint charaId) + { + lock (mGroupLockReference) + { + foreach (Relation relation in mPartyRelationList.Values) + { + if (relation.GetHost() == charaId || relation.GetOther() == charaId) + return relation; + } + return null; + } + } + + public Relation GetLinkshellRelationGroup(uint charaId) + { + lock (mGroupLockReference) + { + foreach (Relation relation in mLinkshellRelationList.Values) + { + if (relation.GetHost() == charaId || relation.GetOther() == charaId) + return relation; + } + return null; + } + } + public void DeleteRelationGroup(ulong groupId) { - if (mRelationList.ContainsKey(groupId)) - mRelationList.Remove(groupId); + if (mPartyRelationList.ContainsKey(groupId)) + mPartyRelationList.Remove(groupId); + if (mLinkshellRelationList.ContainsKey(groupId)) + mLinkshellRelationList.Remove(groupId); if (mCurrentWorldGroupsReference.ContainsKey(groupId)) mCurrentWorldGroupsReference.Remove(groupId); } diff --git a/FFXIVClassic World Server/Server.cs b/FFXIVClassic World Server/Server.cs index 0eeb92e2..d6221bb6 100644 --- a/FFXIVClassic World Server/Server.cs +++ b/FFXIVClassic World Server/Server.cs @@ -229,6 +229,21 @@ namespace FFXIVClassic_World_Server else leavePt.DisbandPlayerRequest(GetSession(subpacket.header.sourceId)); + break; + //Party Invite Request + case 0x1022: + PartyInvitePacket partyInvitePacket = new PartyInvitePacket(subpacket.data); + if (partyInvitePacket.command == 0) + mWorldManager.ProcessPartyInvite(GetSession(subpacket.header.sourceId), partyInvitePacket.actorId); + else if (partyInvitePacket.command == 1) + { + + } + break; + //Party Invite Result + case 0x1023: + PartyInviteResultPacket partyInviteResultPacket = new PartyInviteResultPacket(subpacket.data); + break; //Linkshell create request case 0x1025: diff --git a/FFXIVClassic World Server/WorldMaster.cs b/FFXIVClassic World Server/WorldMaster.cs index 66012213..9181d46d 100644 --- a/FFXIVClassic World Server/WorldMaster.cs +++ b/FFXIVClassic World Server/WorldMaster.cs @@ -212,13 +212,6 @@ namespace FFXIVClassic_World_Server //Send party, retainer, ls groups Party pt = mPartyManager.GetParty(session.sessionId); - - - if (session.sessionId == 156) - { - mPartyManager.AddToParty(pt.groupIndex, 0x6c); - mPartyManager.AddToParty(pt.groupIndex, 157); - } pt.SendGroupPackets(session); SendPartySync(pt); @@ -228,7 +221,8 @@ namespace FFXIVClassic_World_Server foreach (Linkshell ls in linkshells) ls.SendGroupPackets(session); - mRelationGroupManager.CreateRelationGroup(157, session.sessionId, 10001).SendGroupPackets(session); + mRelationGroupManager.CreatePartyRelationGroup(157, session.sessionId).SendGroupPackets(session); + } private void SendMotD(Session session) @@ -296,7 +290,12 @@ namespace FFXIVClassic_World_Server foreach (GroupMember member in group.BuildMemberList(0)) group.SendGroupPackets(mServer.GetSession(member.actorId)); } - } + } + + public void ProcessPartyInvite(Session request, uint invitee) + { + throw new NotImplementedException(); + } public void IncrementGroupIndex() { @@ -332,6 +331,7 @@ namespace FFXIVClassic_World_Server { return mLinkshellManager; } + } }