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

70 lines
1.9 KiB
C#
Raw Normal View History

2015-09-25 18:52:25 -04:00
using System;
using System.Net.Sockets;
using FFXIVClassic_Map_Server.packets;
using FFXIVClassic.Common;
2015-09-25 18:52:25 -04:00
using System.Collections.Concurrent;
using System.Net;
namespace FFXIVClassic_Map_Server
2015-09-25 18:52:25 -04:00
{
class ClientConnection
{
//Connection stuff
public Blowfish blowfish;
public Socket socket;
public byte[] buffer;
private BlockingCollection<BasePacket> SendPacketQueue = new BlockingCollection<BasePacket>(1000);
public int lastPartialSize = 0;
2015-09-25 18:52:25 -04:00
//Instance Stuff
public uint owner = 0;
public int connType = 0;
2015-09-25 18:52:25 -04:00
public void QueuePacket(BasePacket packet)
2015-09-25 18:52:25 -04:00
{
SendPacketQueue.Add(packet);
}
public void QueuePacket(SubPacket subpacket, bool isAuthed, bool isEncrypted)
{
SendPacketQueue.Add(BasePacket.CreatePacket(subpacket, isAuthed, isEncrypted));
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
{
BasePacket packet = SendPacketQueue.Take();
byte[] packetBytes = packet.GetPacketBytes();
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
}
}
}