1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-22 12:47:46 +00:00

More session handling code added.

This commit is contained in:
Filip Maj 2016-08-24 14:18:37 -04:00
parent a1ca960543
commit 4aae16e458
4 changed files with 109 additions and 56 deletions

View file

@ -1,4 +1,6 @@
using FFXIVClassic.Common;
using FFXIVClassic_World_Server.DataObjects;
using FFXIVClassic_World_Server.Packets.Receive;
using FFXIVClassic_World_Server.Packets.Send.Login;
using System;
using System.Collections.Generic;
@ -43,6 +45,8 @@ namespace FFXIVClassic_World_Server
//Initial Connect Packet, Create session
if (subpacket.header.type == 0x01)
{
#region Hardcoded replies
packet.DebugPrintPacket();
byte[] reply1Data = {
0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -70,33 +74,14 @@ namespace FFXIVClassic_World_Server
binReader.Write((UInt32)Utils.UnixTimeStampUTC());
}
}
#endregion
//Read in Actor Id that owns this connection
uint actorID = 0;
using (MemoryStream mem = new MemoryStream(packet.data))
{
using (BinaryReader binReader = new BinaryReader(mem))
{
try
{
byte[] readIn = new byte[12];
binReader.BaseStream.Seek(0x14, SeekOrigin.Begin);
binReader.Read(readIn, 0, 12);
actorID = UInt32.Parse(Encoding.ASCII.GetString(readIn));
}
catch (Exception)
{ }
}
}
mServer.AddSession(actorID);
HelloPacket hello = new HelloPacket(packet.data);
if (packet.header.connectionType == BasePacket.TYPE_ZONE)
Program.Log.Info("Got {0} connection for ActorID {1} @ {2}.", "zone", actorID, client.GetAddress());
mServer.AddSession(client, Session.Channel.ZONE, hello.sessionId);
else if (packet.header.connectionType == BasePacket.TYPE_CHAT)
Program.Log.Info("Got {0} connection for ActorID {1} @ {2}.", "chat", actorID, client.GetAddress());
break;
mServer.AddSession(client, Session.Channel.CHAT, hello.sessionId);
}
//Ping from World Server
else if (subpacket.header.type == 0x07)

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_World_Server.Packets.Receive
{
class HelloPacket
{
public bool invalidPacket = false;
public uint sessionId;
public HelloPacket(byte[] data)
{
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryReader binReader = new BinaryReader(mem))
{
try
{
byte[] readIn = new byte[12];
binReader.BaseStream.Seek(0x14, SeekOrigin.Begin);
binReader.Read(readIn, 0, 12);
sessionId = UInt32.Parse(Encoding.ASCII.GetString(readIn));
}
catch (Exception)
{
invalidPacket = true;
}
}
}
}
}
}

View file

@ -6,9 +6,12 @@ namespace FFXIVClassic_World_Server.Packets.Send.Login
{
class Login0x7ResponsePacket
{
public const ushort OPCODE = 0x0008;
public const uint PACKET_SIZE = 0x18;
public static SubPacket BuildPacket(uint actorID)
{
byte[] data = new byte[0x18];
byte[] data = new byte[PACKET_SIZE];
using (MemoryStream mem = new MemoryStream(data))
{
@ -17,15 +20,14 @@ namespace FFXIVClassic_World_Server.Packets.Send.Login
try
{
binWriter.Write((UInt32)actorID);
binWriter.Write((UInt32)type);
binWriter.Write((UInt32)Utils.UnixTimeStampUTC());
}
catch (Exception)
{
}
{}
}
}
return BasePacket.CreatePacket(data, false, false);
return new SubPacket(false, OPCODE, 0, 0, data);
}
}
}

View file

@ -18,7 +18,8 @@ namespace FFXIVClassic_World_Server
private Socket mServerSocket;
WorldManager worldManager;
WorldManager mWorldManager;
PacketProcessor mPacketProcessor;
private List<ClientConnection> mConnectionList = new List<ClientConnection>();
private Dictionary<uint, Session> mZoneSessionList = new Dictionary<uint, Session>();
@ -36,9 +37,10 @@ namespace FFXIVClassic_World_Server
public bool StartServer()
{
worldManager = new WorldManager(this);
worldManager.LoadZoneServerList();
worldManager.ConnectToZoneServers();
mPacketProcessor = new PacketProcessor(this);
mWorldManager = new WorldManager(this);
mWorldManager.LoadZoneServerList();
mWorldManager.ConnectToZoneServers();
IPEndPoint serverEndPoint = new System.Net.IPEndPoint(IPAddress.Parse(ConfigConstants.OPTIONS_BINDIP), int.Parse(ConfigConstants.OPTIONS_PORT));
@ -123,33 +125,61 @@ namespace FFXIVClassic_World_Server
}
}
public void AddSession(uint id)
public void AddSession(ClientConnection connection, Session.Channel type, uint id)
{
throw new NotImplementedException();
}
Session session = new Session(id, connection, type);
public void RemoveSession(uint id)
{
if (mChatSessionList.ContainsKey(id)) {
mChatSessionList[id].clientSocket.Disconnect();
mConnectionList.Remove(mChatSessionList[id].clientSocket);
mChatSessionList.Remove(id);
}
if (mZoneSessionList.ContainsKey(id))
switch (type)
{
mZoneSessionList[id].clientSocket.Disconnect();
mConnectionList.Remove(mZoneSessionList[id].clientSocket);
mZoneSessionList.Remove(id);
case Session.Channel.ZONE:
if (!mZoneSessionList.ContainsKey(id))
mZoneSessionList.Add(id, session);
break;
case Session.Channel.CHAT:
if (!mChatSessionList.ContainsKey(id))
mChatSessionList.Add(id, session);
break;
}
}
public Session GetSession(uint targetSession)
public void RemoveSession(Session.Channel type, uint id)
{
if (mZoneSessionList.ContainsKey(targetSession))
return mZoneSessionList[targetSession];
else
return null;
switch (type)
{
case Session.Channel.ZONE:
if (mZoneSessionList.ContainsKey(id))
{
mZoneSessionList[id].clientSocket.Disconnect();
mConnectionList.Remove(mZoneSessionList[id].clientSocket);
mZoneSessionList.Remove(id);
}
break;
case Session.Channel.CHAT:
if (mChatSessionList.ContainsKey(id))
{
mChatSessionList[id].clientSocket.Disconnect();
mConnectionList.Remove(mChatSessionList[id].clientSocket);
mChatSessionList.Remove(id);
}
break;
}
}
public Session GetSession(uint targetSession, Session.Channel type = Session.Channel.ZONE)
{
switch (type)
{
case Session.Channel.ZONE:
if (mZoneSessionList.ContainsKey(targetSession))
return mZoneSessionList[targetSession];
break;
case Session.Channel.CHAT:
if (mChatSessionList.ContainsKey(targetSession))
return mChatSessionList[targetSession];
break;
}
return null;
}
/// <summary>
@ -191,7 +221,7 @@ namespace FFXIVClassic_World_Server
break;
else
{
//mProcessor.ProcessPacket(conn, basePacket);
mPacketProcessor.ProcessPacket(conn, basePacket);
}
}
@ -274,7 +304,7 @@ namespace FFXIVClassic_World_Server
public WorldManager GetWorldManager()
{
return worldManager;
return mWorldManager;
}
}