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:
parent
a1ca960543
commit
4aae16e458
4 changed files with 109 additions and 56 deletions
|
@ -1,4 +1,6 @@
|
||||||
using FFXIVClassic.Common;
|
using FFXIVClassic.Common;
|
||||||
|
using FFXIVClassic_World_Server.DataObjects;
|
||||||
|
using FFXIVClassic_World_Server.Packets.Receive;
|
||||||
using FFXIVClassic_World_Server.Packets.Send.Login;
|
using FFXIVClassic_World_Server.Packets.Send.Login;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -43,6 +45,8 @@ namespace FFXIVClassic_World_Server
|
||||||
//Initial Connect Packet, Create session
|
//Initial Connect Packet, Create session
|
||||||
if (subpacket.header.type == 0x01)
|
if (subpacket.header.type == 0x01)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#region Hardcoded replies
|
||||||
packet.DebugPrintPacket();
|
packet.DebugPrintPacket();
|
||||||
byte[] reply1Data = {
|
byte[] reply1Data = {
|
||||||
0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
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());
|
binReader.Write((UInt32)Utils.UnixTimeStampUTC());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
//Read in Actor Id that owns this connection
|
HelloPacket hello = new HelloPacket(packet.data);
|
||||||
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);
|
|
||||||
|
|
||||||
if (packet.header.connectionType == BasePacket.TYPE_ZONE)
|
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)
|
else if (packet.header.connectionType == BasePacket.TYPE_CHAT)
|
||||||
Program.Log.Info("Got {0} connection for ActorID {1} @ {2}.", "chat", actorID, client.GetAddress());
|
mServer.AddSession(client, Session.Channel.CHAT, hello.sessionId);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
//Ping from World Server
|
//Ping from World Server
|
||||||
else if (subpacket.header.type == 0x07)
|
else if (subpacket.header.type == 0x07)
|
||||||
|
|
36
FFXIVClassic Proxy Server/Packets/Receive/HelloPacket.cs
Normal file
36
FFXIVClassic Proxy Server/Packets/Receive/HelloPacket.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,12 @@ namespace FFXIVClassic_World_Server.Packets.Send.Login
|
||||||
{
|
{
|
||||||
class Login0x7ResponsePacket
|
class Login0x7ResponsePacket
|
||||||
{
|
{
|
||||||
|
public const ushort OPCODE = 0x0008;
|
||||||
|
public const uint PACKET_SIZE = 0x18;
|
||||||
|
|
||||||
public static SubPacket BuildPacket(uint actorID)
|
public static SubPacket BuildPacket(uint actorID)
|
||||||
{
|
{
|
||||||
byte[] data = new byte[0x18];
|
byte[] data = new byte[PACKET_SIZE];
|
||||||
|
|
||||||
using (MemoryStream mem = new MemoryStream(data))
|
using (MemoryStream mem = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
|
@ -17,15 +20,14 @@ namespace FFXIVClassic_World_Server.Packets.Send.Login
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
binWriter.Write((UInt32)actorID);
|
binWriter.Write((UInt32)actorID);
|
||||||
binWriter.Write((UInt32)type);
|
binWriter.Write((UInt32)Utils.UnixTimeStampUTC());
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BasePacket.CreatePacket(data, false, false);
|
return new SubPacket(false, OPCODE, 0, 0, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ namespace FFXIVClassic_World_Server
|
||||||
|
|
||||||
private Socket mServerSocket;
|
private Socket mServerSocket;
|
||||||
|
|
||||||
WorldManager worldManager;
|
WorldManager mWorldManager;
|
||||||
|
PacketProcessor mPacketProcessor;
|
||||||
|
|
||||||
private List<ClientConnection> mConnectionList = new List<ClientConnection>();
|
private List<ClientConnection> mConnectionList = new List<ClientConnection>();
|
||||||
private Dictionary<uint, Session> mZoneSessionList = new Dictionary<uint, Session>();
|
private Dictionary<uint, Session> mZoneSessionList = new Dictionary<uint, Session>();
|
||||||
|
@ -36,9 +37,10 @@ namespace FFXIVClassic_World_Server
|
||||||
|
|
||||||
public bool StartServer()
|
public bool StartServer()
|
||||||
{
|
{
|
||||||
worldManager = new WorldManager(this);
|
mPacketProcessor = new PacketProcessor(this);
|
||||||
worldManager.LoadZoneServerList();
|
mWorldManager = new WorldManager(this);
|
||||||
worldManager.ConnectToZoneServers();
|
mWorldManager.LoadZoneServerList();
|
||||||
|
mWorldManager.ConnectToZoneServers();
|
||||||
|
|
||||||
IPEndPoint serverEndPoint = new System.Net.IPEndPoint(IPAddress.Parse(ConfigConstants.OPTIONS_BINDIP), int.Parse(ConfigConstants.OPTIONS_PORT));
|
IPEndPoint serverEndPoint = new System.Net.IPEndPoint(IPAddress.Parse(ConfigConstants.OPTIONS_BINDIP), int.Parse(ConfigConstants.OPTIONS_PORT));
|
||||||
|
|
||||||
|
@ -123,32 +125,60 @@ 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);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
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 void RemoveSession(uint id)
|
public void RemoveSession(Session.Channel type, uint id)
|
||||||
{
|
{
|
||||||
if (mChatSessionList.ContainsKey(id)) {
|
switch (type)
|
||||||
mChatSessionList[id].clientSocket.Disconnect();
|
{
|
||||||
mConnectionList.Remove(mChatSessionList[id].clientSocket);
|
case Session.Channel.ZONE:
|
||||||
mChatSessionList.Remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mZoneSessionList.ContainsKey(id))
|
if (mZoneSessionList.ContainsKey(id))
|
||||||
{
|
{
|
||||||
mZoneSessionList[id].clientSocket.Disconnect();
|
mZoneSessionList[id].clientSocket.Disconnect();
|
||||||
mConnectionList.Remove(mZoneSessionList[id].clientSocket);
|
mConnectionList.Remove(mZoneSessionList[id].clientSocket);
|
||||||
mZoneSessionList.Remove(id);
|
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)
|
public Session GetSession(uint targetSession, Session.Channel type = Session.Channel.ZONE)
|
||||||
{
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case Session.Channel.ZONE:
|
||||||
if (mZoneSessionList.ContainsKey(targetSession))
|
if (mZoneSessionList.ContainsKey(targetSession))
|
||||||
return mZoneSessionList[targetSession];
|
return mZoneSessionList[targetSession];
|
||||||
else
|
break;
|
||||||
|
case Session.Channel.CHAT:
|
||||||
|
if (mChatSessionList.ContainsKey(targetSession))
|
||||||
|
return mChatSessionList[targetSession];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +221,7 @@ namespace FFXIVClassic_World_Server
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//mProcessor.ProcessPacket(conn, basePacket);
|
mPacketProcessor.ProcessPacket(conn, basePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -274,7 +304,7 @@ namespace FFXIVClassic_World_Server
|
||||||
|
|
||||||
public WorldManager GetWorldManager()
|
public WorldManager GetWorldManager()
|
||||||
{
|
{
|
||||||
return worldManager;
|
return mWorldManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue