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 FFXIVClassic.Common;
|
2016-08-22 10:43:04 -04:00
|
|
|
|
|
2016-01-20 23:18:10 -05:00
|
|
|
|
using FFXIVClassic_Map_Server.Actors;
|
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.Collections.Generic;
|
2017-09-05 12:37:23 -04:00
|
|
|
|
using FFXIVClassic_Map_Server.actors.chara.npc;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Map_Server.dataobjects
|
|
|
|
|
{
|
2016-08-29 12:37:41 -04:00
|
|
|
|
class Session
|
2015-12-04 02:00:05 -05:00
|
|
|
|
{
|
2016-08-29 12:37:41 -04:00
|
|
|
|
public uint id = 0;
|
2016-01-02 14:04:45 -05:00
|
|
|
|
Player playerActor;
|
|
|
|
|
public List<Actor> actorInstanceList = new List<Actor>();
|
2016-08-29 12:37:41 -04:00
|
|
|
|
public uint languageCode = 1;
|
2016-03-06 17:55:42 -05:00
|
|
|
|
private uint lastPingPacket = Utils.UnixTimeStampUTC();
|
2016-02-07 13:05:54 -05:00
|
|
|
|
|
2016-12-03 13:23:32 -05:00
|
|
|
|
public bool isUpdatesLocked = true;
|
2016-12-03 12:19:59 -05:00
|
|
|
|
|
2016-03-06 17:55:42 -05:00
|
|
|
|
public string errorMessage = "";
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-08-29 12:37:41 -04:00
|
|
|
|
public Session(uint sessionId)
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-08-29 12:37:41 -04:00
|
|
|
|
this.id = sessionId;
|
|
|
|
|
playerActor = new Player(this, sessionId);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 21:08:30 -04:00
|
|
|
|
public void QueuePacket(List<SubPacket> packets)
|
2016-01-02 14:04:45 -05:00
|
|
|
|
{
|
2017-06-27 21:08:30 -04:00
|
|
|
|
foreach (SubPacket s in packets)
|
|
|
|
|
QueuePacket(s);
|
2016-01-02 14:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 13:52:47 -04:00
|
|
|
|
public void QueuePacket(SubPacket subPacket)
|
2016-08-22 10:43:04 -04:00
|
|
|
|
{
|
2017-06-27 13:52:47 -04:00
|
|
|
|
subPacket.SetTargetId(id);
|
2017-06-27 21:08:30 -04:00
|
|
|
|
Server.GetWorldConnection().QueuePacket(subPacket);
|
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-06-24 20:52:30 +01:00
|
|
|
|
{
|
2016-12-03 12:19:59 -05:00
|
|
|
|
if (isUpdatesLocked)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-30 02:38:55 +01:00
|
|
|
|
if (playerActor.positionX == x && playerActor.positionY == y && playerActor.positionZ == z && playerActor.rotation == rot)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-08-16 17:25:32 +01:00
|
|
|
|
/*
|
2016-01-25 01:10:43 -05:00
|
|
|
|
playerActor.oldPositionX = playerActor.positionX;
|
|
|
|
|
playerActor.oldPositionY = playerActor.positionY;
|
|
|
|
|
playerActor.oldPositionZ = playerActor.positionZ;
|
|
|
|
|
playerActor.oldRotation = playerActor.rotation;
|
2017-08-16 17:25:32 +01:00
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
playerActor.positionX = x;
|
|
|
|
|
playerActor.positionY = y;
|
|
|
|
|
playerActor.positionZ = z;
|
2017-08-16 17:25:32 +01:00
|
|
|
|
*/
|
2015-09-25 18:52:25 -04:00
|
|
|
|
playerActor.rotation = rot;
|
|
|
|
|
playerActor.moveState = moveState;
|
2016-01-25 01:10:43 -05:00
|
|
|
|
|
2017-08-31 05:56:43 +01:00
|
|
|
|
//GetActor().GetZone().UpdateActorPosition(GetActor());
|
2017-06-30 02:38:55 +01:00
|
|
|
|
playerActor.QueuePositionUpdate(new Vector3(x,y,z));
|
2016-06-17 23:17:24 -04:00
|
|
|
|
}
|
2017-06-30 02:38:55 +01:00
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public void UpdateInstance(List<Actor> list)
|
2016-06-17 23:17:24 -04:00
|
|
|
|
{
|
2016-12-03 12:19:59 -05:00
|
|
|
|
if (isUpdatesLocked)
|
|
|
|
|
return;
|
|
|
|
|
|
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++)
|
|
|
|
|
{
|
2017-09-05 12:37:23 -04:00
|
|
|
|
//Retainer Instance
|
|
|
|
|
if (actorInstanceList[i] is Retainer && playerActor.currentSpawnedRetainer == null)
|
|
|
|
|
{
|
|
|
|
|
QueuePacket(RemoveActorPacket.BuildPacket(actorInstanceList[i].actorId));
|
|
|
|
|
actorInstanceList.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
else if (!list.Contains(actorInstanceList[i]) && !(actorInstanceList[i] is Retainer))
|
2016-01-23 23:28:12 -05:00
|
|
|
|
{
|
2017-06-27 21:40:49 -04:00
|
|
|
|
QueuePacket(RemoveActorPacket.BuildPacket(actorInstanceList[i].actorId));
|
2016-06-17 23:17:24 -04:00
|
|
|
|
actorInstanceList.RemoveAt(i);
|
2019-05-04 20:13:29 -04:00
|
|
|
|
}
|
2016-01-23 23:28:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-05 12:37:23 -04:00
|
|
|
|
//Retainer Instance
|
|
|
|
|
if (playerActor.currentSpawnedRetainer != null && !playerActor.sentRetainerSpawn)
|
|
|
|
|
{
|
|
|
|
|
Actor actor = playerActor.currentSpawnedRetainer;
|
|
|
|
|
QueuePacket(actor.GetSpawnPackets(playerActor, 1));
|
|
|
|
|
QueuePacket(actor.GetInitPackets());
|
|
|
|
|
QueuePacket(actor.GetSetEventStatusPackets());
|
|
|
|
|
actorInstanceList.Add(actor);
|
2017-09-09 14:11:35 -04:00
|
|
|
|
((Npc)actor).DoOnActorSpawn(playerActor);
|
2017-09-05 12:37:23 -04:00
|
|
|
|
playerActor.sentRetainerSpawn = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-23 23:28:12 -05:00
|
|
|
|
//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-09-24 14:17:31 -04:00
|
|
|
|
|
2015-10-13 22:58:21 -04:00
|
|
|
|
}
|
2015-10-13 19:15:44 -04:00
|
|
|
|
else
|
2017-06-27 21:30:32 -04:00
|
|
|
|
{
|
2018-04-18 16:06:41 -05:00
|
|
|
|
QueuePacket(actor.GetSpawnPackets(playerActor, 1));
|
2017-06-27 16:55:14 -04:00
|
|
|
|
|
2017-06-27 21:30:32 -04:00
|
|
|
|
QueuePacket(actor.GetInitPackets());
|
|
|
|
|
QueuePacket(actor.GetSetEventStatusPackets());
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 12:19:59 -05:00
|
|
|
|
|
|
|
|
|
public void LockUpdates(bool f)
|
|
|
|
|
{
|
|
|
|
|
isUpdatesLocked = f;
|
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|