2016-06-14 22:54:02 +01:00
|
|
|
|
using FFXIVClassic_Map_Server;
|
|
|
|
|
using FFXIVClassic.Common;
|
2016-06-08 22:29:04 +01:00
|
|
|
|
using FFXIVClassic_Map_Server.packets;
|
2016-01-20 23:18:10 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.Actors;
|
2016-04-02 17:56:01 -04:00
|
|
|
|
using FFXIVClassic_Map_Server.lua;
|
2015-10-13 19:15:44 -04:00
|
|
|
|
using FFXIVClassic_Map_Server.packets.send.actor;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Map_Server.dataobjects
|
|
|
|
|
{
|
2015-12-04 02:00:05 -05:00
|
|
|
|
class ConnectedPlayer
|
|
|
|
|
{
|
|
|
|
|
public uint actorID = 0;
|
2016-01-02 14:04:45 -05:00
|
|
|
|
Player playerActor;
|
|
|
|
|
public List<Actor> actorInstanceList = new List<Actor>();
|
2016-03-28 11:31:21 -04:00
|
|
|
|
|
|
|
|
|
public uint languageCode = 1;
|
|
|
|
|
|
2016-01-19 21:47:59 -05:00
|
|
|
|
private ClientConnection zoneConnection;
|
|
|
|
|
private ClientConnection chatConnection;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-03-06 17:55:42 -05:00
|
|
|
|
private uint lastPingPacket = Utils.UnixTimeStampUTC();
|
2016-02-07 13:05:54 -05:00
|
|
|
|
|
2016-03-06 17:55:42 -05:00
|
|
|
|
public string errorMessage = "";
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2015-12-04 02:00:05 -05:00
|
|
|
|
public ConnectedPlayer(uint actorId)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
this.actorID = actorId;
|
2016-01-19 21:47:59 -05:00
|
|
|
|
playerActor = new Player(this, actorId);
|
2016-01-10 01:19:46 -05:00
|
|
|
|
actorInstanceList.Add(playerActor);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void SetConnection(int type, ClientConnection conn)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-02-16 22:53:53 -05:00
|
|
|
|
conn.connType = type;
|
2016-01-19 21:47:59 -05:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case BasePacket.TYPE_ZONE:
|
|
|
|
|
zoneConnection = conn;
|
|
|
|
|
break;
|
|
|
|
|
case BasePacket.TYPE_CHAT:
|
|
|
|
|
chatConnection = conn;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
2016-01-19 21:47:59 -05:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public bool IsClientConnectionsReady()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-01-19 21:47:59 -05:00
|
|
|
|
return (zoneConnection != null && chatConnection != null);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void Disconnect()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
zoneConnection.Disconnect();
|
|
|
|
|
chatConnection.Disconnect();
|
2016-01-19 21:47:59 -05:00
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public bool IsDisconnected()
|
2016-03-06 17:55:42 -05:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
return (!zoneConnection.IsConnected() && !chatConnection.IsConnected());
|
2016-03-06 17:55:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void QueuePacket(BasePacket basePacket)
|
2016-01-02 14:04:45 -05:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
zoneConnection.QueuePacket(basePacket);
|
2016-01-02 14:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void QueuePacket(SubPacket subPacket, bool isAuthed, bool isEncrypted)
|
2016-01-02 14:04:45 -05:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
zoneConnection.QueuePacket(subPacket, isAuthed, isEncrypted);
|
2016-01-02 14:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public Player GetActor()
|
2015-10-06 00:39:18 -04:00
|
|
|
|
{
|
|
|
|
|
return playerActor;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void Ping()
|
2016-03-06 17:55:42 -05:00
|
|
|
|
{
|
|
|
|
|
lastPingPacket = Utils.UnixTimeStampUTC();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public bool CheckIfDCing()
|
2016-03-06 17:55:42 -05:00
|
|
|
|
{
|
|
|
|
|
uint currentTime = Utils.UnixTimeStampUTC();
|
|
|
|
|
if (currentTime - lastPingPacket >= 5000) //Show D/C flag
|
2016-06-14 21:29:10 +01:00
|
|
|
|
playerActor.SetDCFlag(true);
|
2016-03-06 17:55:42 -05:00
|
|
|
|
else if (currentTime - lastPingPacket >= 30000) //DCed
|
|
|
|
|
return true;
|
|
|
|
|
else
|
2016-06-14 21:29:10 +01:00
|
|
|
|
playerActor.SetDCFlag(false);
|
2016-03-06 17:55:42 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void UpdatePlayerActorPosition(float x, float y, float z, float rot, ushort moveState)
|
2016-01-25 01:10:43 -05:00
|
|
|
|
{
|
|
|
|
|
playerActor.oldPositionX = playerActor.positionX;
|
|
|
|
|
playerActor.oldPositionY = playerActor.positionY;
|
|
|
|
|
playerActor.oldPositionZ = playerActor.positionZ;
|
|
|
|
|
playerActor.oldRotation = playerActor.rotation;
|
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
playerActor.positionX = x;
|
|
|
|
|
playerActor.positionY = y;
|
|
|
|
|
playerActor.positionZ = z;
|
|
|
|
|
playerActor.rotation = rot;
|
|
|
|
|
playerActor.moveState = moveState;
|
2016-01-25 01:10:43 -05:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
GetActor().zone.UpdateActorPosition(GetActor());
|
2016-01-20 00:02:57 -05:00
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
2016-03-06 17:55:42 -05:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void UpdateInstance(List<Actor> list)
|
2015-10-13 19:15:44 -04:00
|
|
|
|
{
|
|
|
|
|
List<BasePacket> basePackets = new List<BasePacket>();
|
2016-06-14 22:54:02 +01:00
|
|
|
|
List<SubPacket> RemoveActorSubpackets = new List<SubPacket>();
|
2015-10-13 19:15:44 -04:00
|
|
|
|
List<SubPacket> posUpdateSubpackets = new List<SubPacket>();
|
2015-10-12 02:03:47 -04:00
|
|
|
|
|
2016-01-23 23:28:12 -05:00
|
|
|
|
//Remove missing actors
|
|
|
|
|
for (int i = 0; i < actorInstanceList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!list.Contains(actorInstanceList[i]))
|
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
GetActor().QueuePacket(RemoveActorPacket.BuildPacket(playerActor.actorId, actorInstanceList[i].actorId));
|
2016-01-23 23:28:12 -05:00
|
|
|
|
actorInstanceList.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Add new actors or move
|
2015-10-13 19:15:44 -04:00
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Actor actor = list[i];
|
|
|
|
|
|
2016-01-02 14:04:45 -05:00
|
|
|
|
if (actor.actorId == playerActor.actorId)
|
2015-10-13 19:15:44 -04:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (actorInstanceList.Contains(actor))
|
2015-10-13 22:58:21 -04:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
GetActor().QueuePacket(actor.CreatePositionUpdatePacket(playerActor.actorId));
|
2015-10-13 22:58:21 -04:00
|
|
|
|
}
|
2015-10-13 19:15:44 -04:00
|
|
|
|
else
|
2015-10-13 22:58:21 -04:00
|
|
|
|
{
|
2016-06-14 21:29:10 +01:00
|
|
|
|
GetActor().QueuePacket(actor.GetSpawnPackets(playerActor.actorId, 1));
|
|
|
|
|
GetActor().QueuePacket(actor.GetInitPackets(playerActor.actorId));
|
|
|
|
|
GetActor().QueuePacket(actor.GetSetEventStatusPackets(playerActor.actorId));
|
2015-10-13 22:58:21 -04:00
|
|
|
|
actorInstanceList.Add(actor);
|
2016-04-07 22:34:10 -04:00
|
|
|
|
|
|
|
|
|
if (actor is Npc)
|
|
|
|
|
{
|
2016-05-29 16:03:24 -04:00
|
|
|
|
((Npc)actor).DoOnActorSpawn(playerActor);
|
2016-04-07 22:34:10 -04:00
|
|
|
|
}
|
2015-10-13 22:58:21 -04:00
|
|
|
|
}
|
2015-10-13 19:15:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 02:03:47 -04:00
|
|
|
|
}
|
2016-01-02 14:04:45 -05:00
|
|
|
|
|
2016-02-07 13:05:54 -05:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void ClearInstance()
|
2016-02-07 13:05:54 -05:00
|
|
|
|
{
|
|
|
|
|
actorInstanceList.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|