using Mirror; using QSB.HUD; using QSB.Localization; using QSB.Menus; using QSB.Messaging; using QSB.Utility; namespace QSB.Player.Messages; /// /// always sent by host /// internal class PlayerKickMessage : QSBMessage { private uint PlayerId; public PlayerKickMessage(uint playerId, string reason) : base(reason) => PlayerId = playerId; public override void Serialize(NetworkWriter writer) { base.Serialize(writer); writer.Write(PlayerId); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); PlayerId = reader.Read(); } public override void OnReceiveRemote() { if (PlayerId != QSBPlayerManager.LocalPlayerId) { if (QSBPlayerManager.PlayerExists(PlayerId)) { MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name)}"); return; } MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId)}"); return; } MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.KickedFromServer, Data)}"); MenuManager.Instance.OnKicked(Data); NetworkClient.Disconnect(); } }