-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add play disconnect packet, and it's handler
- Loading branch information
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Components/MineSharp.Protocol/Packets/Clientbound/Play/DisconnectPacket.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using MineSharp.ChatComponent; | ||
using MineSharp.Core.Common; | ||
using MineSharp.Data; | ||
using MineSharp.Data.Protocol; | ||
|
||
namespace MineSharp.Protocol.Packets.Clientbound.Play; | ||
#pragma warning disable CS1591 | ||
/// <summary> | ||
/// Disconnect packet for play | ||
/// </summary> | ||
public class DisconnectPacket : IPacket | ||
{ | ||
/// <inheritdoc /> | ||
public PacketType Type => PacketType.CB_Play_KickDisconnect; | ||
|
||
/// <summary> | ||
/// The reason for being disconnected | ||
/// </summary> | ||
public Chat Reason { get; set; } | ||
|
||
/// <summary> | ||
/// Create a new instance | ||
/// </summary> | ||
/// <param name="reason"></param> | ||
public DisconnectPacket(Chat reason) | ||
{ | ||
this.Reason = reason; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Write(PacketBuffer buffer, MinecraftData version) | ||
{ | ||
buffer.WriteString(this.Reason.Json); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public static IPacket Read(PacketBuffer buffer, MinecraftData version) | ||
{ | ||
string reason = buffer.ReadString(); | ||
return new DisconnectPacket(new Chat(reason, version)); | ||
} | ||
} | ||
#pragma warning restore CS1591 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters