1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-22 04:37:47 +00:00
project-meteor-server/Map Server/dataobjects/ZoneConnection.cs

91 lines
3.1 KiB
C#
Raw Normal View History

/*
===========================================================================
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
using Meteor.Common;
2015-09-25 18:52:25 -04:00
using System.Collections.Concurrent;
using System.Net;
using FFXIVClassic_Map_Server.packets.WorldPackets.Send;
2015-09-25 18:52:25 -04:00
namespace FFXIVClassic_Map_Server.dataobjects
2015-09-25 18:52:25 -04:00
{
class ZoneConnection
2015-09-25 18:52:25 -04:00
{
//Connection stuff
public Socket socket;
public byte[] buffer;
private BlockingCollection<SubPacket> SendPacketQueue = new BlockingCollection<SubPacket>(1000);
public int lastPartialSize = 0;
2015-09-25 18:52:25 -04:00
public void QueuePacket(SubPacket subpacket)
{
2018-04-07 13:50:43 -04:00
if (SendPacketQueue.Count == SendPacketQueue.BoundedCapacity - 1)
2017-12-10 09:20:42 -06:00
FlushQueuedSendPackets();
SendPacketQueue.Add(subpacket);
2015-09-25 18:52:25 -04:00
}
public void FlushQueuedSendPackets()
2015-09-25 18:52:25 -04:00
{
if (socket == null || !socket.Connected)
2015-09-25 18:52:25 -04:00
return;
while (SendPacketQueue.Count > 0)
2015-09-25 18:52:25 -04:00
{
SubPacket packet = SendPacketQueue.Take();
byte[] packetBytes = packet.GetBytes();
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
}
}
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);
}
public bool IsConnected()
{
return (socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0);
}
public void Disconnect()
2015-09-25 18:52:25 -04:00
{
if (socket.Connected)
socket.Disconnect(false);
2015-09-25 18:52:25 -04: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();
QueuePacket(WorldRequestZoneChangePacket.BuildPacket(sessionId, destinationZoneId, spawnType, spawnX, spawnY, spawnZ, spawnRotation));
}
2015-09-25 18:52:25 -04:00
}
}