2015-08-26 13:38:58 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Sockets;
|
2016-06-12 20:12:59 +01:00
|
|
|
|
using FFXIVClassic.Common;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using Cyotek.Collections.Generic;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Lobby_Server
|
|
|
|
|
{
|
|
|
|
|
class ClientConnection
|
|
|
|
|
{
|
|
|
|
|
//Connection stuff
|
|
|
|
|
public Blowfish blowfish;
|
|
|
|
|
public Socket socket;
|
|
|
|
|
public byte[] buffer = new byte[0xffff];
|
|
|
|
|
public CircularBuffer<byte> incomingStream = new CircularBuffer<byte>(1024);
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public BlockingCollection<BasePacket> SendPacketQueue = new BlockingCollection<BasePacket>(100);
|
2016-02-16 23:35:21 -05:00
|
|
|
|
public int lastPartialSize = 0;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
|
|
|
|
|
//Instance Stuff
|
2015-08-27 10:19:00 -04:00
|
|
|
|
public uint currentUserId = 0;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
public uint currentAccount;
|
2015-09-13 18:21:28 -04:00
|
|
|
|
public string currentSessionToken;
|
2015-09-09 00:08:46 -04:00
|
|
|
|
|
|
|
|
|
//Chara Creation
|
|
|
|
|
public string newCharaName;
|
|
|
|
|
public uint newCharaPid;
|
|
|
|
|
public uint newCharaCid;
|
|
|
|
|
public ushort newCharaSlot;
|
|
|
|
|
public ushort newCharaWorldId;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void ProcessIncoming(int bytesIn)
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
|
|
|
|
if (bytesIn == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
incomingStream.Put(buffer, 0, bytesIn);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void QueuePacket(BasePacket packet)
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
SendPacketQueue.Add(packet);
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void FlushQueuedSendPackets()
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
2015-08-27 10:19:00 -04:00
|
|
|
|
if (!socket.Connected)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
while (SendPacketQueue.Count > 0)
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
BasePacket packet = SendPacketQueue.Take();
|
|
|
|
|
byte[] packetBytes = packet.GetPacketBytes();
|
2015-08-26 13:38:58 -04:00
|
|
|
|
byte[] buffer = new byte[0xffff];
|
|
|
|
|
Array.Copy(packetBytes, buffer, packetBytes.Length);
|
|
|
|
|
try {
|
|
|
|
|
socket.Send(packetBytes);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
2019-05-04 20:53:08 -04:00
|
|
|
|
{ Program.Log.Error(e, "Weird case, socket was d/ced: {0}"); }
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public String GetAddress()
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
|
|
|
|
return String.Format("{0}:{1}", (socket.RemoteEndPoint as IPEndPoint).Address, (socket.RemoteEndPoint as IPEndPoint).Port);
|
2015-08-27 10:19:00 -04:00
|
|
|
|
}
|
2015-08-26 13:38:58 -04:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void Disconnect()
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
2016-03-30 20:16:59 -04:00
|
|
|
|
socket.Shutdown(SocketShutdown.Both);
|
2015-08-26 13:38:58 -04:00
|
|
|
|
socket.Disconnect(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|