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