Suggestions + fix last missed magic number

This commit is contained in:
ohayo 2025-02-05 09:33:36 +10:00
parent 72f529fcb1
commit 5a23073db5
4 changed files with 31 additions and 31 deletions

View file

@ -189,7 +189,7 @@ namespace TShockAPI.DB
if (!player.IsLoggedIn)
return false;
if (player.State < (int)ClientState.ClientSpawned)
if (player.State < (int)ConnectionState.Complete)
return false;
if (player.HasPermission(Permissions.bypassssc) && !fromCommand)

View file

@ -2628,8 +2628,8 @@ namespace TShockAPI
{
if (account.UUID == args.Player.UUID)
{
if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
args.Player.State = (int)ClientState.ClientSentPlayerInformation;
if (args.Player.State == (int)ConnectionState.AssigningPlayerSlot)
args.Player.State = (int)ConnectionState.AwaitingPlayerInfo;
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
@ -2688,8 +2688,8 @@ namespace TShockAPI
return true;
}
if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
args.Player.State = 2;
if (args.Player.State == (int)ConnectionState.AssigningPlayerSlot)
args.Player.State = (int)ConnectionState.AwaitingPlayerInfo;
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
return true;
@ -2728,7 +2728,7 @@ namespace TShockAPI
short numberOfDeathsPVP = args.Data.ReadInt16();
PlayerSpawnContext context = (PlayerSpawnContext)args.Data.ReadByte();
if (args.Player.State >= (int)ClientState.ClientRequestedWorldData && !args.Player.FinishedHandshake)
if (args.Player.State >= (int)ConnectionState.RequestingWorldData && !args.Player.FinishedHandshake)
args.Player.FinishedHandshake = true; //If the player has requested world data before sending spawn player, they should be at the obvious ClientRequestedWorldData state. Also only set this once to remove redundant updates.
if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context))
@ -3221,8 +3221,8 @@ namespace TShockAPI
args.Player.RequiresPassword = false;
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID);
if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
args.Player.State = (int)ClientState.ClientSentPlayerInformation;
if (args.Player.State == (int)ConnectionState.AssigningPlayerSlot)
args.Player.State = (int)ConnectionState.AwaitingPlayerInfo;
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
@ -3271,8 +3271,8 @@ namespace TShockAPI
{
args.Player.RequiresPassword = false;
if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
args.Player.State = (int)ClientState.ClientSentPlayerInformation;
if (args.Player.State == (int)ConnectionState.AssigningPlayerSlot)
args.Player.State = (int)ConnectionState.AwaitingPlayerInfo;
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
return true;

View file

@ -65,44 +65,44 @@ namespace TShockAPI
/// <summary>
/// An enum based on the current client's connection state to the server.
/// </summary>
public enum ClientState : int
public enum ConnectionState : int
{
/// <summary>
/// The server has accepted the client's connection but now requires a password from them before they can continue. (Only for password protected servers)
/// The server is password protected and the connection is pending until a password is sent by the client.
/// </summary>
RequiresPassword = -1,
AwaitingPassword = -1,
/// <summary>
/// The server has accepted the client's connection. In this state, they will send their current version string to the server.
/// The connection has been established, and the client must verify its version.
/// </summary>
ClientConnecting = 0,
AwaitingVersionCheck = 0,
/// <summary>
/// The server has accepted the client's password to connect and/or the server has verified the client's version string as being correct. In this state, the server will send them their user slot and in return, they must send their player information.
/// The server has accepted the client's password to connect and/or the server has verified the client's version string as being correct. The client is now being assigned a player slot.
/// </summary>
ClientReceivingPlayerSlot = 1,
AssigningPlayerSlot = 1,
/// <summary>
/// The client has sent their player information. In this state, they must request world data.
/// The player slot has been received by the client, and the server is now waiting for the player information.
/// </summary>
ClientSentPlayerInformation = 2,
AwaitingPlayerInfo = 2,
/// <summary>
/// The client has requested the world data.
/// Player information has been received, and the client is requesting world data.
/// </summary>
ClientRequestedWorldData = 3,
RequestingWorldData = 3,
/// <summary>
/// The client has received the world data.
/// The world data is being sent to the client.
/// </summary>
ClientReceivedWorldData = 4,
ReceivingWorldData = 4,
/// <summary>
/// The client has loaded the world data and map.
/// The world data has been received, and the client is now finalizing the load.
/// </summary>
ClientLoadedWorldData = 5,
FinalizingWorldLoad = 5,
/// <summary>
/// The client is requesting tile data.
/// </summary>
ClientRequestingTileData = 6,
RequestingTileData = 6,
/// <summary>
/// The client has sent a SpawnPlayer packet and has finished the connection process.
/// The connection process is complete (The player has spawned), and the client has fully joined the game.
/// </summary>
ClientSpawned = 10
Complete = 10
}
public class TSPlayer
@ -2186,7 +2186,7 @@ namespace TShockAPI
if (!NecessaryPacket(msgType) && !FinishedHandshake)
return;
if (msgType == PacketTypes.WorldInfo && State < (int)ClientState.ClientRequestedWorldData)
if (msgType == PacketTypes.WorldInfo && State < (int)ConnectionState.RequestingWorldData)
return;
NetMessage.SendData((int)msgType, Index, -1, text == null ? null : NetworkText.FromLiteral(text), number, number2, number3, number4, number5);

View file

@ -1440,7 +1440,7 @@ namespace TShockAPI
if (tsplr.ReceivedInfo)
{
if (!tsplr.SilentKickInProgress && tsplr.State >= (int)ClientState.ClientRequestedWorldData && tsplr.FinishedHandshake) //The player has left, do not broadcast any clients exploiting the behaviour of not spawning their player.
if (!tsplr.SilentKickInProgress && tsplr.State >= (int)ConnectionState.RequestingWorldData && tsplr.FinishedHandshake) //The player has left, do not broadcast any clients exploiting the behaviour of not spawning their player.
Utils.Broadcast(GetString("{0} has left.", tsplr.Name), Color.Yellow);
Log.Info(GetString("{0} disconnected.", tsplr.Name));
@ -1678,7 +1678,7 @@ namespace TShockAPI
return;
}
if ((player.State < (int)ClientState.ClientSpawned || player.Dead) && (int)type > 12 && (int)type != 16 && (int)type != 42 && (int)type != 50 &&
if ((player.State < (int)ConnectionState.Complete || player.Dead) && (int)type > 12 && (int)type != 16 && (int)type != 42 && (int)type != 50 &&
(int)type != 38 && (int)type != 21 && (int)type != 22 && type != PacketTypes.SyncLoadout)
{
e.Handled = true;