1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-20 11:47:48 +00:00
project-meteor-server/FFXIVClassic World Server/PacketProcessor.cs

167 lines
7.6 KiB
C#
Raw Normal View History

2016-08-23 16:57:24 -04:00
using FFXIVClassic.Common;
2016-08-24 14:18:37 -04:00
using FFXIVClassic_World_Server.DataObjects;
using FFXIVClassic_World_Server.Packets.Receive;
using FFXIVClassic_World_Server.Packets.Receive.Subpackets;
using FFXIVClassic_World_Server.Packets.Send;
2016-08-23 16:57:24 -04:00
using FFXIVClassic_World_Server.Packets.Send.Login;
using FFXIVClassic_World_Server.Packets.WorldPackets.Receive;
using FFXIVClassic_World_Server.Packets.WorldPackets.Send;
2016-08-23 16:57:24 -04:00
using System;
using System.Collections.Generic;
using System.IO;
namespace FFXIVClassic_World_Server
{
class PacketProcessor
{
/*
Session Creation:
Get 0x1 from server
Send 0x7
Send 0x2
Zone Change:
Send 0x7
Get 0x8 - Wait??
Send 0x2
*/
Server mServer;
public PacketProcessor(Server server)
{
mServer = server;
}
public void ProcessPacket(ClientConnection client, BasePacket packet)
{
if (packet.header.isCompressed == 0x01)
BasePacket.DecompressPacket(ref packet);
2016-08-23 16:57:24 -04:00
List<SubPacket> subPackets = packet.GetSubpackets();
foreach (SubPacket subpacket in subPackets)
{
//Initial Connect Packet, Create session
if (subpacket.header.type == 0x01)
{
2016-08-24 14:18:37 -04:00
HelloPacket hello = new HelloPacket(packet.data);
2016-08-23 16:57:24 -04:00
if (packet.header.connectionType == BasePacket.TYPE_ZONE)
{
2016-08-24 14:18:37 -04:00
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);
}
2016-08-23 16:57:24 -04:00
else if (packet.header.connectionType == BasePacket.TYPE_CHAT)
mServer.AddSession(client, Session.Channel.CHAT, hello.sessionId);
client.QueuePacket(_0x7Packet.BuildPacket(0x0E016EE5), true, false);
client.QueuePacket(_0x2Packet.BuildPacket(hello.sessionId), true, false);
2016-08-23 16:57:24 -04:00
}
//Ping from World Server
else if (subpacket.header.type == 0x07)
{
SubPacket init = _0x8PingPacket.BuildPacket(client.owner.sessionId);
2016-08-23 16:57:24 -04:00
client.QueuePacket(BasePacket.CreatePacket(init, true, false));
}
//Zoning Related
else if (subpacket.header.type == 0x08)
{
//Response, client's current [actorID][time]
//BasePacket init = Login0x7ResponsePacket.BuildPacket(BitConverter.ToUInt32(packet.data, 0x10), Utils.UnixTimeStampUTC(), 0x07);
//client.QueuePacket(init);
packet.DebugPrintPacket();
}
//Game Message
else if (subpacket.header.type == 0x03)
{
2016-08-23 16:57:24 -04:00
//Send to the correct zone server
uint targetSession = subpacket.header.targetId;
InterceptProcess(mServer.GetSession(targetSession), subpacket);
2016-08-23 16:57:24 -04:00
if (mServer.GetSession(targetSession).routing1 != null)
mServer.GetSession(targetSession).routing1.SendPacket(subpacket);
if (mServer.GetSession(targetSession).routing2 != null)
mServer.GetSession(targetSession).routing2.SendPacket(subpacket);
}
//World Server Type
else if (subpacket.header.type >= 0x1000)
{
uint targetSession = subpacket.header.targetId;
Session session = mServer.GetSession(targetSession);
switch (subpacket.header.type)
{
//Session Begin Confirm
case 0x1000:
SessionBeginConfirmPacket beginConfirmPacket = new SessionBeginConfirmPacket(packet.data);
if (beginConfirmPacket.invalidPacket || beginConfirmPacket.errorCode == 0)
Program.Log.Error("Session {0} had a error beginning session.", beginConfirmPacket.sessionId);
break;
//Session End Confirm
case 0x1001:
SessionEndConfirmPacket endConfirmPacket = new SessionEndConfirmPacket(packet.data);
if (!endConfirmPacket.invalidPacket && endConfirmPacket.errorCode != 0)
{
//Check destination, if != 0, update route and start new session
if (endConfirmPacket.destinationZone != 0)
{
2016-12-13 15:02:28 -05:00
session.currentZoneId = endConfirmPacket.destinationZone;
session.routing1 = Server.GetServer().GetWorldManager().GetZoneServer(endConfirmPacket.destinationZone);
session.routing1.SendSessionStart(session);
}
else
{
mServer.RemoveSession(Session.Channel.ZONE, endConfirmPacket.sessionId);
mServer.RemoveSession(Session.Channel.CHAT, endConfirmPacket.sessionId);
}
}
else
Program.Log.Error("Session {0} had an error ending session.", endConfirmPacket.sessionId);
2016-12-13 15:02:28 -05:00
break;
//Zone Change Request
case 0x1002:
WorldRequestZoneChangePacket zoneChangePacket = new WorldRequestZoneChangePacket(packet.data);
if (!zoneChangePacket.invalidPacket)
{
mServer.GetWorldManager().DoZoneServerChange(session, zoneChangePacket.destinationZoneId, "", zoneChangePacket.destinationSpawnType, zoneChangePacket.destinationX, zoneChangePacket.destinationY, zoneChangePacket.destinationZ, zoneChangePacket.destinationRot);
}
break;
}
}
2016-08-23 16:57:24 -04:00
else
packet.DebugPrintPacket();
}
}
2016-08-23 16:57:24 -04:00
public void InterceptProcess(Session session, SubPacket subpacket)
{
switch (subpacket.gameMessage.opcode)
{
case 0x6:
mServer.GetWorldManager().DoLogin(session);
break;
//Special case for groups. If it's a world group, send values, else send to zone server
case 0x133:
GroupCreatedPacket groupCreatedPacket = new GroupCreatedPacket(subpacket.data);
if (!mServer.GetWorldManager().SendGroupInit(session, groupCreatedPacket.groupId))
session.clientConnection.QueuePacket(subpacket, true, false);
break;
}
}
2016-08-23 16:57:24 -04:00
}
}