Chawol.MinecraftProtocol 1.0.1-alpha

This is a prerelease version of Chawol.MinecraftProtocol.
dotnet add package Chawol.MinecraftProtocol --version 1.0.1-alpha
NuGet\Install-Package Chawol.MinecraftProtocol -Version 1.0.1-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chawol.MinecraftProtocol" Version="1.0.1-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chawol.MinecraftProtocol --version 1.0.1-alpha
#r "nuget: Chawol.MinecraftProtocol, 1.0.1-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Chawol.MinecraftProtocol as a Cake Addin
#addin nuget:?package=Chawol.MinecraftProtocol&version=1.0.1-alpha&prerelease

// Install Chawol.MinecraftProtocol as a Cake Tool
#tool nuget:?package=Chawol.MinecraftProtocol&version=1.0.1-alpha&prerelease

Sample Code

Simple Console Chat Program
IPAddress ip;      // Server IP address
ushort port;       // Server port number
string playerName; // Player name (Replace with SessionToken if required for online mode login)

MinecraftClient client = await ClientBuilder.FromServerListPingAsync(ip, port);
ChatType[] chatTypes = null;

// Listen for received packets
client.PacketReceived += (m, args) =>
{
    if (!m.Joined)
        return;

    // Output chat messages received from the server to the console
    if (CompatibleReader.TryReadServerChatMessage(args.Packet, chatTypes, out var chatMessage))
    {
        Console.WriteLine(chatMessage);
    }
};

// Starting from 1.19, ChatType needs to be read from JoinGamePacket, otherwise some messages may not be displayed correctly.
if (Client.ProtocolVersion >= ProtocolVersions.V1_19)
{
    Client.PacketReceived += (m, args) =>
    {
        _ = JoinGamePacket.TryRead(args.Packet, out JoinGamePacket jgp) && jgp.TryGetChatTypes(out chatTypes);
    };
}

if (!Client.Connect()) // Connect to the server (TCP handshake)
    Console.WriteLine($"Failed to establish a connection with the server");
else if (!await Client.JoinAsync(playerName)) // Join the server (send login packet)
    Console.WriteLine($"Login failed");
else // Start listening for packets (PacketReceived event won't trigger if not listening)
    Client.StartListen(); 

while (Client.Joined)
{
    // Continuously listen for input from the command line and send it as a chat message to the server
    string Input = Console.ReadLine();
    await Client.GetPlayer()?.SendMessageAsync(Input);
}
Get SessionToken from Mojang Account
SessionToken session = await MojangAccount.AuthenticateAsync("email", "password");
Get SessionToken from Microsoft Account
MicrosoftOAuth2Token microsoftToken = await MicrosoftAccount.AuthenticateAsync("email", "password");
XboxLiveResponse xbl = await XboxLive.XBLAuthenticateAsync(microsoftToken);
XboxLiveResponse xsts = await XboxLive.GetXSTSAuthorizeAsync(xbl);
SessionToken session = await (await XboxLive.MinecraftAuthenticate(xsts)).AsSessionTokenAsync();

Supported version:1.7-1.18.2

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1-alpha 83 5/22/2023