2020-08-22 18:08:25 +01:00
|
|
|
|
using OWML.Common;
|
2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-08-08 12:23:23 +01:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
|
2020-11-03 21:33:48 +00:00
|
|
|
|
namespace QSB.Player.Events
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-08-10 18:17:54 +02:00
|
|
|
|
public class PlayerJoinEvent : QSBEvent<PlayerJoinMessage>
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-08-22 18:08:25 +01:00
|
|
|
|
public override EventType Type => EventType.PlayerJoin;
|
2020-08-08 12:23:23 +01:00
|
|
|
|
|
2020-10-22 16:46:01 +01:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<string>.AddListener(EventNames.QSBPlayerJoin, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2020-10-22 16:46:01 +01:00
|
|
|
|
public override void CloseListener() => GlobalMessenger<string>.RemoveListener(EventNames.QSBPlayerJoin, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2020-08-17 16:51:56 +01:00
|
|
|
|
private void Handler(string name) => SendEvent(CreateMessage(name));
|
2020-08-08 12:23:23 +01:00
|
|
|
|
|
2020-08-10 18:17:54 +02:00
|
|
|
|
private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage
|
|
|
|
|
{
|
2020-08-17 19:13:11 +02:00
|
|
|
|
AboutId = LocalPlayerId,
|
2020-08-10 18:17:54 +02:00
|
|
|
|
PlayerName = name
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 14:40:06 +01:00
|
|
|
|
public override void OnReceiveRemote(PlayerJoinMessage message)
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-11-03 21:18:40 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
2020-08-09 09:37:32 +02:00
|
|
|
|
player.Name = message.PlayerName;
|
2020-09-03 17:09:38 +01:00
|
|
|
|
DebugLog.ToHud($"{player.Name} joined!");
|
|
|
|
|
DebugLog.DebugWrite($"{player.Name} joined as id {player.PlayerId}", MessageType.Info);
|
2020-08-08 12:23:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 09:37:32 +02:00
|
|
|
|
public override void OnReceiveLocal(PlayerJoinMessage message)
|
2020-08-08 12:23:23 +01:00
|
|
|
|
{
|
2020-11-03 21:18:40 +00:00
|
|
|
|
var player = QSBPlayerManager.GetPlayer(QSBPlayerManager.LocalPlayerId);
|
2020-08-09 09:37:32 +02:00
|
|
|
|
player.Name = message.PlayerName;
|
2020-08-09 14:26:33 +01:00
|
|
|
|
var text = $"Connected to server as {player.Name}.";
|
2020-08-22 18:08:25 +01:00
|
|
|
|
DebugLog.ToAll(text, MessageType.Info);
|
2020-08-08 12:23:23 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|