1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-23 05:07:47 +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_Map_Server.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;
2015-10-15 17:04:04 -04:00
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)
{
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()
{
if (!socket.Connected)
return;
while (sendPacketQueue.Count > 0)
{
BasePacket packet = sendPacketQueue.Take();
2015-09-25 18:52:25 -04:00
byte[] packetBytes = packet.getPacketBytes();
2015-09-25 18:52:25 -04:00
try
{
socket.Send(packetBytes);
}
catch (Exception e)
{ Log.Error(String.Format("Weird case, socket was d/ced: {0}", e)); }
2015-09-25 18:52:25 -04:00
}
}
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);
}
2015-09-25 18:52:25 -04:00
public void disconnect()
{
if (socket.Connected)
socket.Disconnect(false);
2015-09-25 18:52:25 -04:00
}
}
}