2015-09-25 18:52:25 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Sockets;
|
2016-08-22 10:43:04 -04:00
|
|
|
|
|
2016-06-12 20:12:59 +01:00
|
|
|
|
using FFXIVClassic.Common;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Net;
|
2016-08-29 09:03:48 -04:00
|
|
|
|
using System.Collections.Generic;
|
2016-12-03 12:19:59 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.packets.WorldPackets.Send;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-08-29 12:40:47 -04:00
|
|
|
|
namespace FFXIVClassic_Map_Server.dataobjects
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-08-29 08:17:14 -04:00
|
|
|
|
class ZoneConnection
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
//Connection stuff
|
|
|
|
|
public Socket socket;
|
2016-02-16 22:53:53 -05:00
|
|
|
|
public byte[] buffer;
|
2016-08-29 08:17:14 -04:00
|
|
|
|
private BlockingCollection<SubPacket> SendPacketQueue = new BlockingCollection<SubPacket>(1000);
|
2016-02-16 22:53:53 -05:00
|
|
|
|
public int lastPartialSize = 0;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2017-06-27 21:08:30 -04:00
|
|
|
|
public void QueuePacket(SubPacket subpacket)
|
2015-12-29 01:20:46 -05:00
|
|
|
|
{
|
2017-12-10 09:20:42 -06:00
|
|
|
|
if(SendPacketQueue.Count == 1000)
|
|
|
|
|
FlushQueuedSendPackets();
|
|
|
|
|
|
2016-08-29 08:17:14 -04:00
|
|
|
|
SendPacketQueue.Add(subpacket);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void FlushQueuedSendPackets()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2017-12-08 00:58:39 -06:00
|
|
|
|
if (socket == null || !socket.Connected)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
return;
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
while (SendPacketQueue.Count > 0)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-08-29 08:17:14 -04:00
|
|
|
|
SubPacket packet = SendPacketQueue.Take();
|
2015-11-27 00:42:35 -05:00
|
|
|
|
|
2016-08-29 08:17:14 -04:00
|
|
|
|
byte[] packetBytes = packet.GetBytes();
|
2016-04-14 08:30:34 -04:00
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
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-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01: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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public bool IsConnected()
|
2016-03-06 17:55:42 -05:00
|
|
|
|
{
|
|
|
|
|
return (socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void Disconnect()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2015-10-13 19:15:44 -04:00
|
|
|
|
if (socket.Connected)
|
|
|
|
|
socket.Disconnect(false);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
2016-12-03 12:19:59 -05:00
|
|
|
|
|
|
|
|
|
public void RequestZoneChange(uint sessionId, uint destinationZoneId, byte spawnType, float spawnX, float spawnY, float spawnZ, float spawnRotation)
|
|
|
|
|
{
|
|
|
|
|
WorldRequestZoneChangePacket.BuildPacket(sessionId, destinationZoneId, spawnType, spawnX, spawnY, spawnZ, spawnRotation).DebugPrintSubPacket();
|
2017-06-27 21:08:30 -04:00
|
|
|
|
QueuePacket(WorldRequestZoneChangePacket.BuildPacket(sessionId, destinationZoneId, spawnType, spawnX, spawnY, spawnZ, spawnRotation));
|
2016-12-03 12:19:59 -05:00
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|