mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 03:40:46 +00:00
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using OWML.Common;
|
|
using QSB.Messaging;
|
|
using QSB.Utility;
|
|
|
|
namespace QSB.Events
|
|
{
|
|
public class PlayerJoinEvent : QSBEvent<PlayerJoinMessage>
|
|
{
|
|
public override EventType Type => EventType.PlayerJoin;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger<string>.AddListener(EventNames.QSBPlayerJoin, Handler);
|
|
}
|
|
|
|
public override void CloseListener()
|
|
{
|
|
GlobalMessenger<string>.RemoveListener(EventNames.QSBPlayerJoin, Handler);
|
|
}
|
|
|
|
private void Handler(string name) => SendEvent(CreateMessage(name));
|
|
|
|
private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
PlayerName = name
|
|
};
|
|
|
|
public override void OnReceiveRemote(PlayerJoinMessage message)
|
|
{
|
|
var player = PlayerRegistry.GetPlayer(message.AboutId);
|
|
player.Name = message.PlayerName;
|
|
var text = $"{player.Name} joined!";
|
|
DebugLog.ToAll(text, MessageType.Info);
|
|
}
|
|
|
|
public override void OnReceiveLocal(PlayerJoinMessage message)
|
|
{
|
|
var player = PlayerRegistry.GetPlayer(PlayerRegistry.LocalPlayerId);
|
|
player.Name = message.PlayerName;
|
|
var text = $"Connected to server as {player.Name}.";
|
|
DebugLog.ToAll(text, MessageType.Info);
|
|
}
|
|
}
|
|
}
|