mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-07-25 20:08:20 +02:00
More work on the world server. Modified map server to communicate with it.
This commit is contained in:
parent
bd26a71fef
commit
6bffe69b21
16 changed files with 507 additions and 577 deletions
|
@ -18,15 +18,15 @@ namespace FFXIVClassic_World_Server
|
|||
|
||||
public static bool Load()
|
||||
{
|
||||
Program.Log.Info("Loading config.ini");
|
||||
Program.Log.Info("Loading world_config.ini");
|
||||
|
||||
if (!File.Exists("./config.ini"))
|
||||
if (!File.Exists("./world_config.ini"))
|
||||
{
|
||||
Program.Log.Error("FILE NOT FOUND!");
|
||||
return false;
|
||||
}
|
||||
|
||||
INIFile configIni = new INIFile("./config.ini");
|
||||
INIFile configIni = new INIFile("./world_config.ini");
|
||||
|
||||
ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1");
|
||||
ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54992");
|
||||
|
|
|
@ -16,6 +16,9 @@ namespace FFXIVClassic_World_Server.DataObjects
|
|||
public readonly int[] ownedZoneIds;
|
||||
public bool isConnected = false;
|
||||
public Socket zoneServerConnection;
|
||||
private ClientConnection conn;
|
||||
|
||||
private byte[] buffer = new byte[0xFFFF];
|
||||
|
||||
public ZoneServer(string ip, int port)
|
||||
{
|
||||
|
@ -34,6 +37,18 @@ namespace FFXIVClassic_World_Server.DataObjects
|
|||
{
|
||||
zoneServerConnection.Connect(remoteEP);
|
||||
isConnected = true;
|
||||
conn = new ClientConnection();
|
||||
conn.socket = zoneServerConnection;
|
||||
conn.buffer = new byte[0xFFFF];
|
||||
|
||||
try
|
||||
{
|
||||
zoneServerConnection.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), conn);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApplicationException("Error occured starting listeners, check inner exception", e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{ Program.Log.Error("Failed to connect"); return; }
|
||||
|
@ -54,5 +69,71 @@ namespace FFXIVClassic_World_Server.DataObjects
|
|||
}
|
||||
}
|
||||
|
||||
private void ReceiveCallback(IAsyncResult result)
|
||||
{
|
||||
ClientConnection conn = (ClientConnection)result.AsyncState;
|
||||
//Check if disconnected
|
||||
if ((conn.socket.Poll(1, SelectMode.SelectRead) && conn.socket.Available == 0))
|
||||
{
|
||||
conn = null;
|
||||
isConnected = false;
|
||||
Program.Log.Info("Zone server @ {0}:{1} disconnected!", zoneServerIp, zoneServerPort);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int bytesRead = conn.socket.EndReceive(result);
|
||||
|
||||
bytesRead += conn.lastPartialSize;
|
||||
|
||||
if (bytesRead >= 0)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
//Build packets until can no longer or out of data
|
||||
while (true)
|
||||
{
|
||||
SubPacket subpacket = SubPacket.CreatePacket(ref offset, conn.buffer, bytesRead);
|
||||
|
||||
//If can't build packet, break, else process another
|
||||
if (subpacket == null)
|
||||
break;
|
||||
else
|
||||
Server.GetServer().OnReceiveSubPacketFromZone(this, subpacket);
|
||||
}
|
||||
|
||||
//Not all bytes consumed, transfer leftover to beginning
|
||||
if (offset < bytesRead)
|
||||
Array.Copy(conn.buffer, offset, conn.buffer, 0, bytesRead - offset);
|
||||
|
||||
conn.lastPartialSize = bytesRead - offset;
|
||||
|
||||
//Build any queued subpackets into basepackets and send
|
||||
conn.FlushQueuedSendPackets();
|
||||
|
||||
if (offset < bytesRead)
|
||||
//Need offset since not all bytes consumed
|
||||
conn.socket.BeginReceive(conn.buffer, bytesRead - offset, conn.buffer.Length - (bytesRead - offset), SocketFlags.None, new AsyncCallback(ReceiveCallback), conn);
|
||||
else
|
||||
//All bytes consumed, full buffer available
|
||||
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
conn = null;
|
||||
isConnected = false;
|
||||
Program.Log.Info("Zone server @ {0}:{1} disconnected!", zoneServerIp, zoneServerPort);
|
||||
}
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
conn = null;
|
||||
isConnected = false;
|
||||
Program.Log.Info("Zone server @ {0}:{1} disconnected!", zoneServerIp, zoneServerPort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
<!-- add your logging rules here -->
|
||||
<logger name='*' minlevel='Trace' writeTo='file' />
|
||||
<logger name='FFXIVClassic_World_Server.Program' minlevel='Trace' writeTo='console' />
|
||||
<logger name='FFXIVClassic.Common.*' minlevel='Debug' writeTo='packets' />
|
||||
<!--
|
||||
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
|
||||
<logger name="*" minlevel="Debug" writeTo="f" />
|
||||
|
|
|
@ -75,6 +75,7 @@ namespace FFXIVClassic_World_Server
|
|||
{
|
||||
//Send to the correct zone server
|
||||
uint targetSession = subpacket.header.targetId;
|
||||
mServer.GetSession(targetSession).routing1 = Server.GetServer().GetWorldManager().mZoneServerList["127.0.0.1:1989"];
|
||||
|
||||
if (mServer.GetSession(targetSession).routing1 != null)
|
||||
mServer.GetSession(targetSession).routing1.SendPacket(subpacket);
|
||||
|
@ -85,7 +86,7 @@ namespace FFXIVClassic_World_Server
|
|||
else
|
||||
packet.DebugPrintPacket();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,14 +31,18 @@ namespace FFXIVClassic_World_Server.Packets.Send
|
|||
}
|
||||
|
||||
byte[] reply2Data = {
|
||||
0x66, 0x00, 0x00, 0x00, 0xC8, 0xD6, 0xAF, 0x2B, 0x38, 0x2B, 0x5F, 0x26, 0xB8, 0x8D, 0xF0, 0x2B,
|
||||
0x6c, 0x00, 0x00, 0x00, 0xC8, 0xD6, 0xAF, 0x2B, 0x38, 0x2B, 0x5F, 0x26, 0xB8, 0x8D, 0xF0, 0x2B,
|
||||
0xC8, 0xFD, 0x85, 0xFE, 0xA8, 0x7C, 0x5B, 0x09, 0x38, 0x2B, 0x5F, 0x26, 0xC8, 0xD6, 0xAF, 0x2B,
|
||||
0xB8, 0x8D, 0xF0, 0x2B, 0x88, 0xAF, 0x5E, 0x26
|
||||
};
|
||||
|
||||
data = reply2Data;
|
||||
/*
|
||||
0x6c, 0x00, 0x00, 0x00, 0xC8, 0xD6, 0xAF, 0x2B, 0x38, 0x2B, 0x5F, 0x26, 0xB8, 0x8D, 0xF0, 0x2B,
|
||||
0xC8, 0xFD, 0x85, 0xFE, 0xA8, 0x7C, 0x5B, 0x09, 0x38, 0x2B, 0x5F, 0x26, 0xC8, 0xD6, 0xAF, 0x2B,
|
||||
0xB8, 0x8D, 0xF0, 0x2B, 0x88, 0xAF, 0x5E, 0x26
|
||||
*/
|
||||
|
||||
return new SubPacket(false, OPCODE, 0, 0, data);
|
||||
return new SubPacket(false, OPCODE, 0, 0, reply2Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,55 +75,7 @@ namespace FFXIVClassic_World_Server
|
|||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#region Socket Handling
|
||||
private void AcceptCallback(IAsyncResult result)
|
||||
{
|
||||
ClientConnection conn = null;
|
||||
Socket socket = (System.Net.Sockets.Socket)result.AsyncState;
|
||||
|
||||
try
|
||||
{
|
||||
conn = new ClientConnection();
|
||||
conn.socket = socket.EndAccept(result);
|
||||
conn.buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
lock (mConnectionList)
|
||||
{
|
||||
mConnectionList.Add(conn);
|
||||
}
|
||||
|
||||
Program.Log.Info("Connection {0}:{1} has connected.", (conn.socket.RemoteEndPoint as IPEndPoint).Address, (conn.socket.RemoteEndPoint as IPEndPoint).Port);
|
||||
//Queue recieving of data from the connection
|
||||
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), conn);
|
||||
//Queue the accept of the next incomming connection
|
||||
mServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), mServerSocket);
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
if (conn != null)
|
||||
{
|
||||
|
||||
lock (mConnectionList)
|
||||
{
|
||||
mConnectionList.Remove(conn);
|
||||
}
|
||||
}
|
||||
mServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), mServerSocket);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (conn != null)
|
||||
{
|
||||
lock (mConnectionList)
|
||||
{
|
||||
mConnectionList.Remove(conn);
|
||||
}
|
||||
}
|
||||
mServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), mServerSocket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddSession(ClientConnection connection, Session.Channel type, uint id)
|
||||
{
|
||||
|
@ -182,6 +134,70 @@ namespace FFXIVClassic_World_Server
|
|||
return null;
|
||||
}
|
||||
|
||||
public void OnReceiveSubPacketFromZone(ZoneServer zoneServer, SubPacket subpacket)
|
||||
{
|
||||
uint sessionId = subpacket.header.targetId;
|
||||
|
||||
if (mZoneSessionList.ContainsKey(sessionId))
|
||||
{
|
||||
ClientConnection conn = mZoneSessionList[sessionId].clientConnection;
|
||||
conn.QueuePacket(subpacket, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
public WorldManager GetWorldManager()
|
||||
{
|
||||
return mWorldManager;
|
||||
}
|
||||
|
||||
#region Socket Handling
|
||||
private void AcceptCallback(IAsyncResult result)
|
||||
{
|
||||
ClientConnection conn = null;
|
||||
Socket socket = (System.Net.Sockets.Socket)result.AsyncState;
|
||||
|
||||
try
|
||||
{
|
||||
conn = new ClientConnection();
|
||||
conn.socket = socket.EndAccept(result);
|
||||
conn.buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
lock (mConnectionList)
|
||||
{
|
||||
mConnectionList.Add(conn);
|
||||
}
|
||||
|
||||
Program.Log.Info("Connection {0}:{1} has connected.", (conn.socket.RemoteEndPoint as IPEndPoint).Address, (conn.socket.RemoteEndPoint as IPEndPoint).Port);
|
||||
//Queue recieving of data from the connection
|
||||
conn.socket.BeginReceive(conn.buffer, 0, conn.buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), conn);
|
||||
//Queue the accept of the next incomming connection
|
||||
mServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), mServerSocket);
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
if (conn != null)
|
||||
{
|
||||
|
||||
lock (mConnectionList)
|
||||
{
|
||||
mConnectionList.Remove(conn);
|
||||
}
|
||||
}
|
||||
mServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), mServerSocket);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (conn != null)
|
||||
{
|
||||
lock (mConnectionList)
|
||||
{
|
||||
mConnectionList.Remove(conn);
|
||||
}
|
||||
}
|
||||
mServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), mServerSocket);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Receive Callback. Reads in incoming data, converting them to base packets. Base packets are sent to be parsed. If not enough data at the end to build a basepacket, move to the beginning and prepend.
|
||||
/// </summary>
|
||||
|
@ -214,7 +230,7 @@ namespace FFXIVClassic_World_Server
|
|||
//Build packets until can no longer or out of data
|
||||
while (true)
|
||||
{
|
||||
BasePacket basePacket = BuildPacket(ref offset, conn.buffer, bytesRead);
|
||||
BasePacket basePacket = BasePacket.CreatePacket(ref offset, conn.buffer, bytesRead);
|
||||
|
||||
//If can't build packet, break, else process another
|
||||
if (basePacket == null)
|
||||
|
@ -264,48 +280,7 @@ namespace FFXIVClassic_World_Server
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a packet from the incoming buffer + offset. If a packet can be built, it is returned else null.
|
||||
/// </summary>
|
||||
/// <param name="offset">Current offset in buffer.</param>
|
||||
/// <param name="buffer">Incoming buffer.</param>
|
||||
/// <returns>Returns either a BasePacket or null if not enough data.</returns>
|
||||
public BasePacket BuildPacket(ref int offset, byte[] buffer, int bytesRead)
|
||||
{
|
||||
BasePacket newPacket = null;
|
||||
|
||||
//Too small to even get length
|
||||
if (bytesRead <= offset)
|
||||
return null;
|
||||
|
||||
ushort packetSize = BitConverter.ToUInt16(buffer, offset);
|
||||
|
||||
//Too small to whole packet
|
||||
if (bytesRead < offset + packetSize)
|
||||
return null;
|
||||
|
||||
if (buffer.Length < offset + packetSize)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
newPacket = new BasePacket(buffer, ref offset);
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public WorldManager GetWorldManager()
|
||||
{
|
||||
return mWorldManager;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace FFXIVClassic_World_Server
|
|||
class WorldManager
|
||||
{
|
||||
private Server mServer;
|
||||
private Dictionary<string, ZoneServer> mZoneServerList;
|
||||
public Dictionary<string, ZoneServer> mZoneServerList;
|
||||
|
||||
public WorldManager(Server server)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue