mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-07-27 04:48:16 +02:00
Cleaned up a lot of the "ConnectedPlayer" objects, turning them into "Session" objects. A lot of duplicate lists were also removed.
This commit is contained in:
parent
06e7ea59f4
commit
cf38454c8f
7 changed files with 131 additions and 159 deletions
132
FFXIVClassic Map Server/dataobjects/Session.cs
Normal file
132
FFXIVClassic Map Server/dataobjects/Session.cs
Normal file
|
@ -0,0 +1,132 @@
|
|||
using FFXIVClassic_Map_Server;
|
||||
using FFXIVClassic.Common;
|
||||
|
||||
using FFXIVClassic_Map_Server.Actors;
|
||||
using FFXIVClassic_Map_Server.lua;
|
||||
using FFXIVClassic_Map_Server.packets.send.actor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFXIVClassic_Map_Server.dataobjects
|
||||
{
|
||||
class Session
|
||||
{
|
||||
public uint id = 0;
|
||||
Player playerActor;
|
||||
public List<Actor> actorInstanceList = new List<Actor>();
|
||||
public uint languageCode = 1;
|
||||
private uint lastPingPacket = Utils.UnixTimeStampUTC();
|
||||
|
||||
public string errorMessage = "";
|
||||
|
||||
public Session(uint sessionId)
|
||||
{
|
||||
this.id = sessionId;
|
||||
playerActor = new Player(this, sessionId);
|
||||
actorInstanceList.Add(playerActor);
|
||||
}
|
||||
|
||||
public void QueuePacket(BasePacket basePacket)
|
||||
{
|
||||
Server.GetWorldConnection().QueuePacket(basePacket);
|
||||
}
|
||||
|
||||
public void QueuePacket(SubPacket subPacket, bool isAuthed, bool isEncrypted)
|
||||
{
|
||||
Server.GetWorldConnection().QueuePacket(subPacket, isAuthed, isEncrypted);
|
||||
}
|
||||
|
||||
public Player GetActor()
|
||||
{
|
||||
return playerActor;
|
||||
}
|
||||
|
||||
public void Ping()
|
||||
{
|
||||
lastPingPacket = Utils.UnixTimeStampUTC();
|
||||
}
|
||||
|
||||
public bool CheckIfDCing()
|
||||
{
|
||||
uint currentTime = Utils.UnixTimeStampUTC();
|
||||
if (currentTime - lastPingPacket >= 5000) //Show D/C flag
|
||||
playerActor.SetDCFlag(true);
|
||||
else if (currentTime - lastPingPacket >= 30000) //DCed
|
||||
return true;
|
||||
else
|
||||
playerActor.SetDCFlag(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdatePlayerActorPosition(float x, float y, float z, float rot, ushort moveState)
|
||||
{
|
||||
playerActor.oldPositionX = playerActor.positionX;
|
||||
playerActor.oldPositionY = playerActor.positionY;
|
||||
playerActor.oldPositionZ = playerActor.positionZ;
|
||||
playerActor.oldRotation = playerActor.rotation;
|
||||
|
||||
playerActor.positionX = x;
|
||||
playerActor.positionY = y;
|
||||
playerActor.positionZ = z;
|
||||
playerActor.rotation = rot;
|
||||
playerActor.moveState = moveState;
|
||||
|
||||
GetActor().zone.UpdateActorPosition(GetActor());
|
||||
|
||||
}
|
||||
|
||||
public void UpdateInstance(List<Actor> list)
|
||||
{
|
||||
List<BasePacket> basePackets = new List<BasePacket>();
|
||||
List<SubPacket> RemoveActorSubpackets = new List<SubPacket>();
|
||||
List<SubPacket> posUpdateSubpackets = new List<SubPacket>();
|
||||
|
||||
//Remove missing actors
|
||||
for (int i = 0; i < actorInstanceList.Count; i++)
|
||||
{
|
||||
if (!list.Contains(actorInstanceList[i]))
|
||||
{
|
||||
GetActor().QueuePacket(RemoveActorPacket.BuildPacket(playerActor.actorId, actorInstanceList[i].actorId));
|
||||
actorInstanceList.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
//Add new actors or move
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
Actor actor = list[i];
|
||||
|
||||
if (actor.actorId == playerActor.actorId)
|
||||
continue;
|
||||
|
||||
if (actorInstanceList.Contains(actor))
|
||||
{
|
||||
GetActor().QueuePacket(actor.CreatePositionUpdatePacket(playerActor.actorId));
|
||||
}
|
||||
else
|
||||
{
|
||||
GetActor().QueuePacket(actor.GetSpawnPackets(playerActor.actorId, 1));
|
||||
GetActor().QueuePacket(actor.GetInitPackets(playerActor.actorId));
|
||||
GetActor().QueuePacket(actor.GetSetEventStatusPackets(playerActor.actorId));
|
||||
actorInstanceList.Add(actor);
|
||||
|
||||
if (actor is Npc)
|
||||
{
|
||||
((Npc)actor).DoOnActorSpawn(playerActor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ClearInstance()
|
||||
{
|
||||
actorInstanceList.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue