Packet filtering for those who never finish the handshake
This also kicks those who never finish handshaking upon chat now. (To free up the resources a bit I guess?) Before a player finishes the connection handshake, the server will check if it's necessary to send them a packet - it checks against a list of necessary packets like: - ContinueConnecting (Send User Slot), - PlayerSpawnSelf (CompleteConnectionAndSpawn), - WorldInfo (Which the server does a further check if the player is at the appropriate state to be sent the world info) - Status - Disconnection - TileFrameSection & TileSendSection
This commit is contained in:
parent
b5d546a660
commit
52d1840003
2 changed files with 29 additions and 0 deletions
|
|
@ -2102,6 +2102,28 @@ namespace TShockAPI
|
||||||
SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time);
|
SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if an outgoing packet is necessary to send to a player before they have finished the connection handshake.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msgType">The packet type to check against the necessary list.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool NecessaryPacket(PacketTypes msgType)
|
||||||
|
{
|
||||||
|
List<PacketTypes> ConnectionPackets = new List<PacketTypes>()
|
||||||
|
{
|
||||||
|
PacketTypes.ContinueConnecting,
|
||||||
|
PacketTypes.WorldInfo,
|
||||||
|
PacketTypes.Status,
|
||||||
|
PacketTypes.Disconnect,
|
||||||
|
PacketTypes.TileFrameSection,
|
||||||
|
PacketTypes.TileSendSection,
|
||||||
|
PacketTypes.PlayerSpawnSelf
|
||||||
|
};
|
||||||
|
|
||||||
|
return ConnectionPackets.Contains(msgType);
|
||||||
|
}
|
||||||
|
|
||||||
//Todo: Separate this into a few functions. SendTo, SendToAll, etc
|
//Todo: Separate this into a few functions. SendTo, SendToAll, etc
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends data to the player.
|
/// Sends data to the player.
|
||||||
|
|
@ -2119,6 +2141,12 @@ namespace TShockAPI
|
||||||
if (RealPlayer && !ConnectionAlive)
|
if (RealPlayer && !ConnectionAlive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!NecessaryPacket(msgType) && !FinishedHandshake)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (msgType == PacketTypes.WorldInfo && State < 3) //If the player has requested the world data, their state will be 3.
|
||||||
|
return;
|
||||||
|
|
||||||
NetMessage.SendData((int)msgType, Index, -1, text == null ? null : NetworkText.FromLiteral(text), number, number2, number3, number4, number5);
|
NetMessage.SendData((int)msgType, Index, -1, text == null ? null : NetworkText.FromLiteral(text), number, number2, number3, number4, number5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1494,6 +1494,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
if (!tsplr.FinishedHandshake)
|
if (!tsplr.FinishedHandshake)
|
||||||
{
|
{
|
||||||
|
tsplr.Kick(GetString("Your client didn't finish the handshake."), true);
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue