Merge branch 'proxy_server' into develop

# Conflicts:
#	FFXIVClassic Common Class Lib/packages.config
This commit is contained in:
Filip Maj 2016-12-03 14:03:13 -05:00
commit 3864bf6d85
195 changed files with 5926 additions and 1601 deletions

View file

@ -1,6 +1,6 @@
using FFXIVClassic_Map_Server;
using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.packets;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
@ -12,66 +12,33 @@ using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.dataobjects
{
class ConnectedPlayer
class Session
{
public uint actorID = 0;
public uint id = 0;
Player playerActor;
public List<Actor> actorInstanceList = new List<Actor>();
public uint languageCode = 1;
private ClientConnection zoneConnection;
private ClientConnection chatConnection;
public uint languageCode = 1;
private uint lastPingPacket = Utils.UnixTimeStampUTC();
public bool isUpdatesLocked = true;
public string errorMessage = "";
public ConnectedPlayer(uint actorId)
public Session(uint sessionId)
{
this.actorID = actorId;
playerActor = new Player(this, actorId);
this.id = sessionId;
playerActor = new Player(this, sessionId);
actorInstanceList.Add(playerActor);
}
public void SetConnection(int type, ClientConnection conn)
{
conn.connType = type;
switch (type)
{
case BasePacket.TYPE_ZONE:
zoneConnection = conn;
break;
case BasePacket.TYPE_CHAT:
chatConnection = conn;
break;
}
}
public bool IsClientConnectionsReady()
{
return (zoneConnection != null && chatConnection != null);
}
public void Disconnect()
{
zoneConnection.Disconnect();
chatConnection.Disconnect();
}
public bool IsDisconnected()
{
return (!zoneConnection.IsConnected() && !chatConnection.IsConnected());
}
public void QueuePacket(BasePacket basePacket)
{
zoneConnection.QueuePacket(basePacket);
Server.GetWorldConnection().QueuePacket(basePacket);
}
public void QueuePacket(SubPacket subPacket, bool isAuthed, bool isEncrypted)
{
zoneConnection.QueuePacket(subPacket, isAuthed, isEncrypted);
{
Server.GetWorldConnection().QueuePacket(subPacket, isAuthed, isEncrypted);
}
public Player GetActor()
@ -98,6 +65,9 @@ namespace FFXIVClassic_Map_Server.dataobjects
public void UpdatePlayerActorPosition(float x, float y, float z, float rot, ushort moveState)
{
if (isUpdatesLocked)
return;
playerActor.oldPositionX = playerActor.positionX;
playerActor.oldPositionY = playerActor.positionY;
playerActor.oldPositionZ = playerActor.positionZ;
@ -115,6 +85,9 @@ namespace FFXIVClassic_Map_Server.dataobjects
public void UpdateInstance(List<Actor> list)
{
if (isUpdatesLocked)
return;
List<BasePacket> basePackets = new List<BasePacket>();
List<SubPacket> RemoveActorSubpackets = new List<SubPacket>();
List<SubPacket> posUpdateSubpackets = new List<SubPacket>();
@ -139,6 +112,10 @@ namespace FFXIVClassic_Map_Server.dataobjects
if (actorInstanceList.Contains(actor))
{
//Don't send for static characters (npcs)
if (actor is Character && ((Character)actor).isStatic)
continue;
GetActor().QueuePacket(actor.CreatePositionUpdatePacket(playerActor.actorId));
}
else
@ -163,5 +140,10 @@ namespace FFXIVClassic_Map_Server.dataobjects
actorInstanceList.Clear();
}
public void LockUpdates(bool f)
{
isUpdatesLocked = f;
}
}
}

View file

@ -0,0 +1,74 @@
using System;
using System.Net.Sockets;
using FFXIVClassic.Common;
using System.Collections.Concurrent;
using System.Net;
using System.Collections.Generic;
using FFXIVClassic_Map_Server.packets.WorldPackets.Send;
namespace FFXIVClassic_Map_Server.dataobjects
{
class ZoneConnection
{
//Connection stuff
public Socket socket;
public byte[] buffer;
private BlockingCollection<SubPacket> SendPacketQueue = new BlockingCollection<SubPacket>(1000);
public int lastPartialSize = 0;
public void QueuePacket(BasePacket packet)
{
List<SubPacket> subPackets = packet.GetSubpackets();
foreach (SubPacket s in subPackets)
SendPacketQueue.Add(s);
}
public void QueuePacket(SubPacket subpacket, bool isAuthed, bool isEncrypted)
{
SendPacketQueue.Add(subpacket);
}
public void FlushQueuedSendPackets()
{
if (!socket.Connected)
return;
while (SendPacketQueue.Count > 0)
{
SubPacket packet = SendPacketQueue.Take();
byte[] packetBytes = packet.GetBytes();
try
{
socket.Send(packetBytes);
}
catch (Exception e)
{ Program.Log.Error("Weird case, socket was d/ced: {0}", e); }
}
}
public String GetAddress()
{
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()
{
if (socket.Connected)
socket.Disconnect(false);
}
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), true, false);
}
}
}