2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Messaging;
|
2020-11-03 22:29:23 +00:00
|
|
|
|
using QSB.SectorSync;
|
2020-08-22 20:21:13 +01:00
|
|
|
|
using QSB.Utility;
|
2020-08-15 14:22:56 +01:00
|
|
|
|
using System.Linq;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2020-11-03 21:33:48 +00:00
|
|
|
|
namespace QSB.Player.Events
|
2020-08-10 14:40:06 +01:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.PlayerStatesRequest;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler() => SendEvent(CreateMessage());
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private PlayerMessage CreateMessage() => new PlayerMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId
|
|
|
|
|
};
|
2020-08-10 18:17:54 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void OnServerReceive(PlayerMessage message)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"[S] Get state request from {message.FromId}");
|
|
|
|
|
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
|
|
|
|
|
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
|
|
|
|
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-10 14:40:06 +01:00
|
|
|
|
}
|