player kicking: use string reason

This commit is contained in:
JohnCorby 2022-03-18 02:58:01 -07:00
parent 1cbd355151
commit 8bedbfe3f4
4 changed files with 8 additions and 29 deletions

View File

@ -1,7 +1,6 @@
using EpicTransport;
using Mirror;
using QSB.Messaging;
using QSB.Player;
using QSB.Player.TransformSync;
using QSB.SaveSync.Messages;
using QSB.Utility;
@ -384,20 +383,10 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
() => new RequestGameStateMessage().Send());
}
public void OnKicked(KickReason reason)
public void OnKicked(string reason)
{
_intentionalDisconnect = true;
var text = reason switch
{
KickReason.QSBVersionNotMatching => "Server refused connection as QSB version does not match.",
KickReason.GameVersionNotMatching => "Server refused connection as Outer Wilds version does not match.",
KickReason.DLCNotMatching => "Server refused connection as DLC installation state does not match.",
KickReason.InEye => "Server refused connection as game has progressed too far.",
KickReason.None => "Kicked from server. No reason given.",
_ => $"Kicked from server. KickReason:{reason}",
};
PopupOK += () =>
{
if (QSBSceneManager.IsInUniverse)
@ -406,7 +395,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
}
};
OpenInfoPopup(text, "OK");
OpenInfoPopup($"Server refused connection.\r\n{reason}", "OK");
SetButtonActive(DisconnectButton, false);
SetButtonActive(ConnectButton, true);

View File

@ -1,10 +0,0 @@
namespace QSB.Player;
public enum KickReason
{
None,
QSBVersionNotMatching,
GameVersionNotMatching,
DLCNotMatching,
InEye
}

View File

@ -46,28 +46,28 @@ public class PlayerJoinMessage : QSBMessage
if (QSBVersion != QSBCore.QSBVersion)
{
DebugLog.ToConsole($"Error - Client {PlayerName} connecting with wrong QSB version. (Client:{QSBVersion}, Server:{QSBCore.QSBVersion})", MessageType.Error);
new PlayerKickMessage(From, KickReason.QSBVersionNotMatching).Send();
new PlayerKickMessage(From, $"QSB version does not match. (Client:{QSBVersion}, Server:{QSBCore.QSBVersion})").Send();
return;
}
if (GameVersion != QSBCore.GameVersion)
{
DebugLog.ToConsole($"Error - Client {PlayerName} connecting with wrong game version. (Client:{GameVersion}, Server:{QSBCore.GameVersion})", MessageType.Error);
new PlayerKickMessage(From, KickReason.GameVersionNotMatching).Send();
new PlayerKickMessage(From, $"Outer Wilds version does not match. (Client:{GameVersion}, Server:{QSBCore.GameVersion})").Send();
return;
}
if (DlcInstalled != QSBCore.DLCInstalled)
{
DebugLog.ToConsole($"Error - Client {PlayerName} connecting with wrong DLC installation state. (Client:{DlcInstalled}, Server:{QSBCore.DLCInstalled})", MessageType.Error);
new PlayerKickMessage(From, KickReason.DLCNotMatching).Send();
new PlayerKickMessage(From, $"DLC installation state does not match. (Client:{DlcInstalled}, Server:{QSBCore.DLCInstalled})").Send();
return;
}
if (QSBPlayerManager.PlayerList.Any(x => x.EyeState >= EyeState.Observatory))
{
DebugLog.ToConsole($"Error - Client {PlayerName} connecting too late into eye scene.", MessageType.Error);
new PlayerKickMessage(From, KickReason.InEye).Send();
new PlayerKickMessage(From, "Game has progressed too far.").Send();
return;
}
}

View File

@ -8,11 +8,11 @@ namespace QSB.Player.Messages;
/// <summary>
/// always sent by host
/// </summary>
internal class PlayerKickMessage : QSBMessage<KickReason>
internal class PlayerKickMessage : QSBMessage<string>
{
private uint PlayerId;
public PlayerKickMessage(uint playerId, KickReason reason) : base(reason) =>
public PlayerKickMessage(uint playerId, string reason) : base(reason) =>
PlayerId = playerId;
public override void Serialize(NetworkWriter writer)