2020-08-22 18:08:25 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-09 12:19:51 +01:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Events
|
|
|
|
|
{
|
2020-08-10 18:17:54 +02:00
|
|
|
|
public class PlayerLeaveEvent : QSBEvent<PlayerLeaveMessage>
|
2020-08-09 12:19:51 +01:00
|
|
|
|
{
|
2020-08-22 18:08:25 +01:00
|
|
|
|
public override EventType Type => EventType.PlayerLeave;
|
2020-08-09 12:19:51 +01:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-15 21:52:43 +02:00
|
|
|
|
GlobalMessenger<uint, uint[]>.AddListener(EventNames.QSBPlayerLeave, Handler);
|
2020-08-09 12:19:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 20:32:58 +01:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
2020-08-15 21:52:43 +02:00
|
|
|
|
GlobalMessenger<uint, uint[]>.RemoveListener(EventNames.QSBPlayerLeave, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 22:37:27 +02:00
|
|
|
|
private void Handler(uint playerId, uint[] netIds) => SendEvent(CreateMessage(playerId, netIds));
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2020-08-18 22:37:27 +02:00
|
|
|
|
private PlayerLeaveMessage CreateMessage(uint playerId, uint[] netIds) => new PlayerLeaveMessage
|
2020-08-10 18:17:54 +02:00
|
|
|
|
{
|
2020-08-18 22:37:27 +02:00
|
|
|
|
AboutId = playerId,
|
|
|
|
|
NetIds = netIds
|
2020-08-10 18:17:54 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 14:40:06 +01:00
|
|
|
|
public override void OnReceiveRemote(PlayerLeaveMessage message)
|
2020-08-09 12:19:51 +01:00
|
|
|
|
{
|
2020-08-17 16:51:56 +01:00
|
|
|
|
var playerName = PlayerRegistry.GetPlayer(message.AboutId).Name;
|
2020-08-22 18:08:25 +01:00
|
|
|
|
DebugLog.ToAll($"{playerName} disconnected.", MessageType.Info);
|
2020-08-23 12:43:08 +01:00
|
|
|
|
PlayerRegistry.GetPlayer(message.AboutId).HudMarker?.Remove();
|
2020-08-17 16:51:56 +01:00
|
|
|
|
PlayerRegistry.RemovePlayer(message.AboutId);
|
2020-08-18 22:37:27 +02:00
|
|
|
|
message.NetIds.ToList().ForEach(netId => QSBNetworkManager.Instance.CleanupNetworkBehaviour(netId));
|
2020-08-09 12:19:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|