2019-06-18 22:55:32 -04:00
|
|
|
|
/*
|
|
|
|
|
===========================================================================
|
|
|
|
|
Copyright (C) 2015-2019 Project Meteor Dev Team
|
|
|
|
|
|
|
|
|
|
This file is part of Project Meteor Server.
|
|
|
|
|
|
|
|
|
|
Project Meteor Server is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
Project Meteor Server is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
|
|
|
|
|
===========================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
using System.Net.Sockets;
|
2016-08-22 10:43:04 -04:00
|
|
|
|
|
2019-06-19 00:05:18 -04:00
|
|
|
|
using Meteor.Common;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Net;
|
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
|
|
|
|
{
|
2018-04-07 13:50:43 -04:00
|
|
|
|
if (SendPacketQueue.Count == SendPacketQueue.BoundedCapacity - 1)
|
2017-12-10 09:20:42 -06:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|