2022-01-13 23:38:45 -08:00
|
|
|
|
using Mirror;
|
2022-06-29 15:00:44 -07:00
|
|
|
|
using QSB.Localization;
|
2022-01-13 23:38:45 -08:00
|
|
|
|
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
|
|
|
|
{
|
2022-06-08 14:00:37 -07:00
|
|
|
|
DebugLog.ToAll(string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name));
|
2021-12-22 16:44:03 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 14:00:37 -07:00
|
|
|
|
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
|
|
|
|
|
2022-06-08 14:00:37 -07: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
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|