Remove magic number + Use suggestions by particles
Added a new ClientState enum based on code in Terraria.MessageBuffer.GetData & Terraria.Netplay.InnerClientLoop
This commit is contained in:
parent
ff9cb9f858
commit
ce04d9d173
5 changed files with 66 additions and 18 deletions
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,49 @@ namespace TShockAPI
|
|||
WriteToLogAndConsole
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An enum based on the current client's connection state to the server.
|
||||
/// </summary>
|
||||
public enum ClientState : 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)
|
||||
/// </summary>
|
||||
RequiresPassword = -1,
|
||||
/// <summary>
|
||||
/// The server has accepted the client's connection. In this state, they will send their current version string to the server.
|
||||
/// </summary>
|
||||
ClientConnecting = 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.
|
||||
/// </summary>
|
||||
ClientReceivingPlayerSlot = 1,
|
||||
/// <summary>
|
||||
/// The client has sent their player information. In this state, they must request world data.
|
||||
/// </summary>
|
||||
ClientSentPlayerInformation = 2,
|
||||
/// <summary>
|
||||
/// The client has requested the world data.
|
||||
/// </summary>
|
||||
ClientRequestedWorldData = 3,
|
||||
/// <summary>
|
||||
/// The client has received the world data.
|
||||
/// </summary>
|
||||
ClientReceivedWorldData = 4,
|
||||
/// <summary>
|
||||
/// The client has loaded the world data and map.
|
||||
/// </summary>
|
||||
ClientLoadedWorldData = 5,
|
||||
/// <summary>
|
||||
/// The client is requesting tile data.
|
||||
/// </summary>
|
||||
ClientRequestingTileData = 6,
|
||||
/// <summary>
|
||||
/// The client has sent a SpawnPlayer packet and has finished the connection process.
|
||||
/// </summary>
|
||||
ClientSpawned = 10
|
||||
}
|
||||
|
||||
public class TSPlayer
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -2105,7 +2148,7 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// The list of necessary packets to make sure gets through to the player upon connection (before they finish the handshake).
|
||||
/// </summary>
|
||||
private static readonly HashSet<PacketTypes> NecessaryPackets = new()
|
||||
private static readonly HashSet<PacketTypes> HandshakeNecessaryPackets = new()
|
||||
{
|
||||
PacketTypes.ContinueConnecting,
|
||||
PacketTypes.WorldInfo,
|
||||
|
|
@ -2121,7 +2164,7 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
/// <param name="msgType">The packet type to check against the necessary list.</param>
|
||||
/// <returns>Whether the packet is necessary for connection or not</returns>
|
||||
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
|
||||
/// <summary>
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue