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-08-26 13:38:58 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Net;
|
2019-06-19 00:05:18 -04:00
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
|
|
|
|
|
using Cyotek.Collections.Generic;
|
|
|
|
|
using Meteor.Common;
|
2015-08-26 13:38:58 -04:00
|
|
|
|
|
2019-06-19 00:05:18 -04:00
|
|
|
|
namespace Meteor.Lobby
|
2015-08-26 13:38:58 -04:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
2019-06-08 21:11:51 -07:00
|
|
|
|
if (SendPacketQueue.Count == SendPacketQueue.BoundedCapacity - 1)
|
|
|
|
|
FlushQueuedSendPackets();
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|