quantum-space-buddies/QSB/Events/PlayerJoinEvent.cs
Mister_Nebula a07e1a9a44 cleanup
2020-08-09 13:48:55 +01:00

35 lines
1.1 KiB
C#

using QSB.Messaging;
using QSB.TransformSync;
using QSB.Utility;
namespace QSB.Events
{
class PlayerJoinEvent : QSBEvent<PlayerJoinMessage>
{
public override MessageType Type => MessageType.PlayerJoin;
public override void SetupListener()
{
GlobalMessenger<string>.AddListener("QSBPlayerJoin", name => SendEvent(
new PlayerJoinMessage {
SenderId = PlayerTransformSync.LocalInstance.netId.Value,
PlayerName = name
}));
}
public override void OnReceive(PlayerJoinMessage message)
{
var player = PlayerRegistry.CreatePlayer(message.SenderId);
player.Name = message.PlayerName;
DebugLog.ToAll($"{player.Name} joined!");
}
public override void OnReceiveLocal(PlayerJoinMessage message)
{
var player = PlayerRegistry.CreatePlayer(PlayerTransformSync.LocalInstance.netId.Value);
player.Name = message.PlayerName;
DebugLog.ToAll($"Connected to server as {player.Name}.");
}
}
}