1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-23 21:27:46 +00:00
project-meteor-server/FFXIVClassic Map Server/ZoneConnection.cs

68 lines
1.8 KiB
C#
Raw Normal View History

2015-09-25 18:52:25 -04:00
using System;
using System.Net.Sockets;
2016-08-22 10:43:04 -04:00
using FFXIVClassic.Common;
2015-09-25 18:52:25 -04:00
using System.Collections.Concurrent;
using System.Net;
using System.Collections.Generic;
2015-09-25 18:52:25 -04:00
namespace FFXIVClassic_Map_Server
2015-09-25 18:52:25 -04:00
{
class ZoneConnection
2015-09-25 18:52:25 -04:00
{
//Connection stuff
public Socket socket;
public byte[] buffer;
private BlockingCollection<SubPacket> SendPacketQueue = new BlockingCollection<SubPacket>(1000);
public int lastPartialSize = 0;
2015-09-25 18:52:25 -04:00
public void QueuePacket(BasePacket packet)
2015-09-25 18:52:25 -04:00
{
List<SubPacket> subPackets = packet.GetSubpackets();
foreach (SubPacket s in subPackets)
SendPacketQueue.Add(s);
}
public void QueuePacket(SubPacket subpacket, bool isAuthed, bool isEncrypted)
{
SendPacketQueue.Add(subpacket);
2015-09-25 18:52:25 -04:00
}
public void FlushQueuedSendPackets()
2015-09-25 18:52:25 -04:00
{
if (!socket.Connected)
return;
while (SendPacketQueue.Count > 0)
2015-09-25 18:52:25 -04:00
{
SubPacket packet = SendPacketQueue.Take();
byte[] packetBytes = packet.GetBytes();
2015-09-25 18:52:25 -04:00
try
{
socket.Send(packetBytes);
}
catch (Exception e)
{ Program.Log.Error("Weird case, socket was d/ced: {0}", e); }
2015-09-25 18:52:25 -04:00
}
}
public String GetAddress()
2015-09-25 18:52:25 -04:00
{
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()
2015-09-25 18:52:25 -04:00
{
if (socket.Connected)
socket.Disconnect(false);
2015-09-25 18:52:25 -04:00
}
}
}