quantum-space-buddies/QSB/Player/Messages/PlayerKickMessage.cs

50 lines
1.1 KiB
C#
Raw Normal View History

using Mirror;
using QSB.Localization;
using QSB.Menus;
2021-12-22 16:44:03 -08:00
using QSB.Messaging;
using QSB.Utility;
2022-03-02 19:46:33 -08:00
namespace QSB.Player.Messages;
/// <summary>
/// always sent by host
/// </summary>
2022-03-18 02:58:01 -07:00
internal class PlayerKickMessage : QSBMessage<string>
2021-12-22 16:44:03 -08:00
{
2022-03-02 19:46:33 -08:00
private uint PlayerId;
2022-03-18 02:58:01 -07:00
public PlayerKickMessage(uint playerId, string reason) : base(reason) =>
2022-03-02 19:46:33 -08:00
PlayerId = playerId;
2021-12-22 17:13:54 -08:00
2022-03-02 19:46:33 -08:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(PlayerId);
}
2021-12-22 17:13:54 -08:00
2022-03-02 19:46:33 -08:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
PlayerId = reader.Read<uint>();
}
2021-12-22 17:13:54 -08:00
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote()
{
if (PlayerId != QSBPlayerManager.LocalPlayerId)
2021-12-22 16:44:03 -08:00
{
2022-03-02 19:46:33 -08:00
if (QSBPlayerManager.PlayerExists(PlayerId))
2021-12-22 16:44:03 -08:00
{
DebugLog.ToAll(string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name));
2021-12-22 16:44:03 -08:00
return;
}
DebugLog.ToAll(string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId));
2022-03-02 19:46:33 -08:00
return;
2021-12-22 16:44:03 -08:00
}
2022-03-02 19:46:33 -08:00
DebugLog.ToAll(string.Format(QSBLocalization.Current.KickedFromServer, Data));
2022-03-02 19:46:33 -08:00
MenuManager.Instance.OnKicked(Data);
2022-08-26 20:47:47 +01:00
NetworkClient.Disconnect();
2021-12-22 16:44:03 -08:00
}
}