2020-08-09 07:17:00 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.TransformSync;
|
2020-08-08 11:23:23 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Events
|
|
|
|
|
{
|
2020-08-09 07:37:32 +00:00
|
|
|
|
class PlayerJoinEvent : QSBEvent<PlayerJoinMessage>
|
2020-08-08 11:23:23 +00:00
|
|
|
|
{
|
2020-08-09 07:17:00 +00:00
|
|
|
|
public override MessageType Type => MessageType.PlayerJoin;
|
2020-08-08 11:23:23 +00:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-09 07:37:32 +00:00
|
|
|
|
GlobalMessenger<string>.AddListener("QSBPlayerJoin", name => SendEvent(new PlayerJoinMessage { PlayerName = name }));
|
2020-08-08 11:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 07:37:32 +00:00
|
|
|
|
public override void OnReceive(uint sender, PlayerJoinMessage message)
|
2020-08-08 11:23:23 +00:00
|
|
|
|
{
|
|
|
|
|
var player = PlayerRegistry.CreatePlayer(sender);
|
2020-08-09 07:37:32 +00:00
|
|
|
|
player.Name = message.PlayerName;
|
2020-08-08 11:23:23 +00:00
|
|
|
|
player.IsReady = true;
|
|
|
|
|
DebugLog.ToAll($"{player.Name} joined!");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 07:37:32 +00:00
|
|
|
|
public override void OnReceiveLocal(PlayerJoinMessage message)
|
2020-08-08 11:23:23 +00:00
|
|
|
|
{
|
2020-08-08 12:27:49 +00:00
|
|
|
|
var player = PlayerRegistry.CreatePlayer(PlayerTransformSync.LocalInstance.netId.Value);
|
2020-08-09 07:37:32 +00:00
|
|
|
|
player.Name = message.PlayerName;
|
2020-08-08 12:27:49 +00:00
|
|
|
|
player.IsReady = true;
|
|
|
|
|
DebugLog.ToAll($"{player.Name} joined!");
|
2020-08-08 11:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|