2015-08-26 13:38:58 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using FFXIVClassic_Lobby_Server.packets;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using FFXIVClassic_Lobby_Server.common;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.IO;
|
|
|
|
|
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);
|
|
|
|
|
public BlockingCollection<BasePacket> sendPacketQueue = new BlockingCollection<BasePacket>(100);
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void processIncoming(int bytesIn)
|
|
|
|
|
{
|
|
|
|
|
if (bytesIn == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
incomingStream.Put(buffer, 0, bytesIn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void queuePacket(BasePacket packet)
|
|
|
|
|
{
|
|
|
|
|
sendPacketQueue.Add(packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void flushQueuedSendPackets()
|
|
|
|
|
{
|
2015-08-27 10:19:00 -04:00
|
|
|
|
if (!socket.Connected)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-08-26 13:38:58 -04:00
|
|
|
|
while (sendPacketQueue.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
BasePacket packet = sendPacketQueue.Take();
|
|
|
|
|
byte[] packetBytes = packet.getPacketBytes();
|
|
|
|
|
byte[] buffer = new byte[0xffff];
|
|
|
|
|
Array.Copy(packetBytes, buffer, packetBytes.Length);
|
|
|
|
|
try {
|
|
|
|
|
socket.Send(packetBytes);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
2015-09-08 19:39:52 -04:00
|
|
|
|
{ Log.error(String.Format("Weird case, socket was d/ced: {0}", e)); }
|
2015-08-26 13:38:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAddress()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
public void disconnect()
|
|
|
|
|
{
|
|
|
|
|
socket.Disconnect(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|