A lightweight wrapper around TcpClient to send and receive messages asynchronously to/from
Source RCON Protocol compatible servers (including Minecraft).
This is a very simple/dumb implementation and concurrently sending multiple messages is not supported,
as the send method returns the first received message after sending.
usingTeraa.Rcon;usingvarclient=newRconClient();awaitclient.ConnectAsync(host:"localhost",port:25575,cancellationToken:default);constintauthId=1;Messageresponse;response=awaitclient.SendAsync(id:authId,type:MessageType.Auth,body:"password",cancellationToken:default);switch(response){case{Id:authId,Type:MessageType.AuthResponse}:Console.WriteLine("Authenticated");break;case{Id:-1,Type:MessageType.AuthResponse}:Console.WriteLine("Auth failed (invalid password)");return;default:Console.WriteLine($"Unknown response: {response}");return;}Console.WriteLine("Type commands or Q to quit.");intid=authId+1;while(true){Console.Write("> ");string?input=Console.ReadLine();if(inputisnull or "q" or "Q")break;id++;response=awaitclient.SendAsync(id:id,type:MessageType.Command,body:input,cancellationToken:default);if(response.Id==id&&response.Type==MessageType.CommandResponse)Console.WriteLine(response.Body);elseConsole.WriteLine($"Unknown response: {response}");}