Changed folder from Proxy to World. Did some nlog configing.

This commit is contained in:
Filip Maj 2016-08-28 14:25:37 -04:00
parent 364ab40b3f
commit bd26a71fef
21 changed files with 32 additions and 24 deletions

View file

@ -0,0 +1,67 @@
using System;
using System.Net.Sockets;
using System.Collections.Concurrent;
using System.Net;
using FFXIVClassic.Common;
using FFXIVClassic_World_Server.DataObjects;
namespace FFXIVClassic_World_Server
{
class ClientConnection
{
//Connection stuff
public Socket socket;
public byte[] buffer;
private BlockingCollection<BasePacket> SendPacketQueue = new BlockingCollection<BasePacket>(1000);
public int lastPartialSize = 0;
//Instance Stuff
public Session owner;
public void QueuePacket(BasePacket packet)
{
SendPacketQueue.Add(packet);
}
public void QueuePacket(SubPacket subpacket, bool isAuthed, bool isEncrypted)
{
SendPacketQueue.Add(BasePacket.CreatePacket(subpacket, isAuthed, isEncrypted));
}
public void FlushQueuedSendPackets()
{
if (!socket.Connected)
return;
while (SendPacketQueue.Count > 0)
{
BasePacket packet = SendPacketQueue.Take();
byte[] packetBytes = packet.GetPacketBytes();
try
{
socket.Send(packetBytes);
}
catch (Exception e)
{ Program.Log.Error("Weird case, socket was d/ced: {0}", e); }
}
}
public String GetAddress()
{
return String.Format("{0}:{1}", (socket.RemoteEndPoint as IPEndPoint).Address, (socket.RemoteEndPoint as IPEndPoint).Port);
}
public bool IsConnected()
{
return (socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0);
}
public void Disconnect()
{
if (socket.Connected)
socket.Disconnect(false);
}
}
}

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_World_Server.DataObjects
{
class Session
{
public enum Channel {ZONE, CHAT};
public readonly uint sessionId;
public readonly ClientConnection clientConnection;
public readonly Channel type;
public ZoneServer routing1, routing2;
public Session(uint sessionId, ClientConnection connection, Channel type)
{
this.sessionId = sessionId;
this.clientConnection = connection;
this.type = type;
connection.owner = this;
}
}
}

View file

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using FFXIVClassic.Common;
namespace FFXIVClassic_World_Server.DataObjects
{
class ZoneServer
{
public readonly string zoneServerIp;
public readonly int zoneServerPort;
public readonly int[] ownedZoneIds;
public bool isConnected = false;
public Socket zoneServerConnection;
public ZoneServer(string ip, int port)
{
zoneServerIp = ip;
zoneServerPort = port;
}
public void Connect()
{
Program.Log.Info("Connecting to zone server @ {0}:{1}", zoneServerIp, zoneServerPort);
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(zoneServerIp), zoneServerPort);
zoneServerConnection = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
zoneServerConnection.Connect(remoteEP);
isConnected = true;
}
catch (Exception e)
{ Program.Log.Error("Failed to connect"); return; }
}
public void SendPacket(SubPacket subpacket)
{
if (isConnected)
{
byte[] packetBytes = subpacket.GetBytes();
try
{
zoneServerConnection.Send(packetBytes);
}
catch (Exception e)
{ Program.Log.Error("Weird case, socket was d/ced: {0}", e); }
}
}
}
}