forked from Impostor/Impostor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use actual disconnect message in ClientBase#DisconnectAsync
- Loading branch information
Showing
5 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using Impostor.Api.Innersloth; | ||
|
||
namespace Impostor.Api.Net.Messages.S2C | ||
{ | ||
public class MessageDisconnect | ||
{ | ||
public static void Serialize(IMessageWriter writer, bool hasReason, DisconnectReason? reason, string? message) | ||
{ | ||
writer.Write(hasReason); | ||
|
||
if (hasReason) | ||
{ | ||
if (reason == null) | ||
{ | ||
throw new ArgumentNullException(nameof(reason)); | ||
} | ||
|
||
writer.StartMessage(0); | ||
writer.Write((byte)reason); | ||
|
||
if (reason == DisconnectReason.Custom) | ||
{ | ||
if (message == null) | ||
{ | ||
throw new ArgumentNullException(nameof(message)); | ||
} | ||
|
||
writer.Write(message); | ||
} | ||
|
||
writer.EndMessage(); | ||
} | ||
} | ||
|
||
public static void Deserialize(IMessageReader reader, out bool hasReason, out DisconnectReason? reason, out string? message) | ||
{ | ||
hasReason = reader.ReadBoolean(); | ||
|
||
if (hasReason) | ||
{ | ||
var inner = reader.ReadMessage(); | ||
reason = (DisconnectReason)inner.ReadByte(); | ||
message = reason == DisconnectReason.Custom ? inner.ReadString() : null; | ||
} | ||
else | ||
{ | ||
reason = null; | ||
message = null; | ||
} | ||
} | ||
} | ||
} |
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
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