diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs
index f630165f..f4d00f71 100644
--- a/TShockAPI/Commands.cs
+++ b/TShockAPI/Commands.cs
@@ -2530,7 +2530,7 @@ namespace TShockAPI
{
foreach (TSPlayer ply in TShock.Players.Where(p => p != null && p.Active && p.TPlayer.name.ToLower().Equals(args.Parameters[0].ToLower())))
{
- //this will always tell the client that they have not done the quest today. * Update: We have a definition for Packet 74, why are you sending it as a cast to PacketTypes?
+ //this will always tell the client that they have not done the quest today.
ply.SendData(PacketTypes.AnglerQuest, "");
}
args.Player.SendSuccessMessage(GetString("Removed {0} players from the angler quest completion list for today.", result));
diff --git a/TShockAPI/DB/CharacterManager.cs b/TShockAPI/DB/CharacterManager.cs
index 5a5e13a6..32ac924d 100644
--- a/TShockAPI/DB/CharacterManager.cs
+++ b/TShockAPI/DB/CharacterManager.cs
@@ -189,7 +189,7 @@ namespace TShockAPI.DB
if (!player.IsLoggedIn)
return false;
- if (player.State < 10)
+ if (player.State < (int)ClientState.ClientSpawned)
return false;
if (player.HasPermission(Permissions.bypassssc) && !fromCommand)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index c0faf964..043b12a4 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -2618,7 +2618,7 @@ namespace TShockAPI
private static bool HandleConnecting(GetDataHandlerArgs args)
{
- var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name);//
+ var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name);
args.Player.DataWhenJoined = new PlayerData(args.Player);
args.Player.DataWhenJoined.CopyCharacter(args.Player);
args.Player.PlayerData = new PlayerData(args.Player);
@@ -2628,8 +2628,9 @@ namespace TShockAPI
{
if (account.UUID == args.Player.UUID)
{
- if (args.Player.State == 1)
- args.Player.State = 2;
+ if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
+ args.Player.State = (int)ClientState.ClientSentPlayerInformation;
+
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
var group = TShock.Groups.GetGroupByName(account.Group);
@@ -2687,8 +2688,9 @@ namespace TShockAPI
return true;
}
- if (args.Player.State == 1)
+ if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
args.Player.State = 2;
+
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
return true;
}
@@ -2726,8 +2728,8 @@ namespace TShockAPI
short numberOfDeathsPVP = args.Data.ReadInt16();
PlayerSpawnContext context = (PlayerSpawnContext)args.Data.ReadByte();
- if (args.Player.State >= 3 && !args.Player.FinishedHandshake)
- args.Player.FinishedHandshake = true; //If the player has requested world data before sending spawn player, this should be equal to or greater than 3, otherwise it'll usually be 1. Also only set this once to remove redundant updates.
+ if (args.Player.State >= (int)ClientState.ClientRequestedWorldData && !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))
return true;
@@ -3219,8 +3221,9 @@ namespace TShockAPI
args.Player.RequiresPassword = false;
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID);
- if (args.Player.State == 1)
- args.Player.State = 2;
+ if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
+ args.Player.State = (int)ClientState.ClientSentPlayerInformation;
+
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
var group = TShock.Groups.GetGroupByName(account.Group);
@@ -3267,8 +3270,10 @@ namespace TShockAPI
if (TShock.Config.Settings.ServerPassword == password)
{
args.Player.RequiresPassword = false;
- if (args.Player.State == 1)
- args.Player.State = 2;
+
+ if (args.Player.State == (int)ClientState.ClientReceivingPlayerSlot)
+ args.Player.State = (int)ClientState.ClientSentPlayerInformation;
+
NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index);
return true;
}
diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs
index 6569ef01..aeadd408 100644
--- a/TShockAPI/TSPlayer.cs
+++ b/TShockAPI/TSPlayer.cs
@@ -62,6 +62,49 @@ namespace TShockAPI
WriteToLogAndConsole
}
+ ///
+ /// An enum based on the current client's connection state to the server.
+ ///
+ public enum ClientState : int
+ {
+ ///
+ /// The server has accepted the client's connection but now requires a password from them before they can continue. (Only for password protected servers)
+ ///
+ RequiresPassword = -1,
+ ///
+ /// The server has accepted the client's connection. In this state, they will send their current version string to the server.
+ ///
+ ClientConnecting = 0,
+ ///
+ /// 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.
+ ///
+ ClientReceivingPlayerSlot = 1,
+ ///
+ /// The client has sent their player information. In this state, they must request world data.
+ ///
+ ClientSentPlayerInformation = 2,
+ ///
+ /// The client has requested the world data.
+ ///
+ ClientRequestedWorldData = 3,
+ ///
+ /// The client has received the world data.
+ ///
+ ClientReceivedWorldData = 4,
+ ///
+ /// The client has loaded the world data and map.
+ ///
+ ClientLoadedWorldData = 5,
+ ///
+ /// The client is requesting tile data.
+ ///
+ ClientRequestingTileData = 6,
+ ///
+ /// The client has sent a SpawnPlayer packet and has finished the connection process.
+ ///
+ ClientSpawned = 10
+ }
+
public class TSPlayer
{
///
@@ -2105,7 +2148,7 @@ namespace TShockAPI
///
/// The list of necessary packets to make sure gets through to the player upon connection (before they finish the handshake).
///
- private static readonly HashSet NecessaryPackets = new()
+ private static readonly HashSet HandshakeNecessaryPackets = new()
{
PacketTypes.ContinueConnecting,
PacketTypes.WorldInfo,
@@ -2121,7 +2164,7 @@ namespace TShockAPI
///
/// The packet type to check against the necessary list.
/// Whether the packet is necessary for connection or not
- private bool NecessaryPacket(PacketTypes msgType) => NecessaryPackets.Contains(msgType);
+ private bool NecessaryPacket(PacketTypes msgType) => HandshakeNecessaryPackets.Contains(msgType);
//Todo: Separate this into a few functions. SendTo, SendToAll, etc
///
@@ -2143,7 +2186,7 @@ namespace TShockAPI
if (!NecessaryPacket(msgType) && !FinishedHandshake)
return;
- if (msgType == PacketTypes.WorldInfo && State < 3) //If the player has requested the world data, their state will be 3.
+ if (msgType == PacketTypes.WorldInfo && State < (int)ClientState.ClientRequestedWorldData)
return;
NetMessage.SendData((int)msgType, Index, -1, text == null ? null : NetworkText.FromLiteral(text), number, number2, number3, number4, number5);
diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs
index 64f23ec3..6c1b251c 100644
--- a/TShockAPI/TShock.cs
+++ b/TShockAPI/TShock.cs
@@ -1440,7 +1440,7 @@ namespace TShockAPI
if (tsplr.ReceivedInfo)
{
- if (!tsplr.SilentKickInProgress && tsplr.State >= 3 && 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)ClientState.ClientRequestedWorldData && 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));
@@ -1494,7 +1494,7 @@ namespace TShockAPI
if (!tsplr.FinishedHandshake)
{
- tsplr.Kick(GetString("Your client didn't finish the handshake."), true);
+ tsplr.Kick(GetString("Your didn't send the right connection information."), true);
args.Handled = true;
return;
}
@@ -1678,7 +1678,7 @@ namespace TShockAPI
return;
}
- if ((player.State < 10 || player.Dead) && (int)type > 12 && (int)type != 16 && (int)type != 42 && (int)type != 50 &&
+ if ((player.State < (int)ClientState.ClientSpawned || 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;