### Install MineStatSharp via .NET CLI Source: https://context7.com/traceld/minestat-sharp/llms.txt Adds the MineStatSharp NuGet package to your project using the .NET CLI. ```bash # .NET CLI dotnet add package TraceLd.MineStatSharp ``` -------------------------------- ### Install MineStatSharp via Package Manager Console Source: https://context7.com/traceld/minestat-sharp/llms.txt Installs the MineStatSharp NuGet package using the Package Manager Console in Visual Studio. ```powershell # Package Manager Console (Visual Studio) Install-Package TraceLd.MineStatSharp ``` -------------------------------- ### Get Server MotD Source: https://context7.com/traceld/minestat-sharp/llms.txt Retrieves the server's Message of the Day and demonstrates how to strip Minecraft color codes. ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("minecraft.dilley.me", 25565); if (ms.ServerUp) { // Strip Minecraft color/format codes (§ followed by a character) string cleanMotd = System.Text.RegularExpressions.Regex.Replace(ms.Motd, "§.", ""); Console.WriteLine($"MotD (raw): {ms.Motd}"); Console.WriteLine($"MotD (clean): {cleanMotd}"); // Expected output: // MotD (raw): §aWelcome §rto our server! // MotD (clean): Welcome to our server! } ``` -------------------------------- ### Get Player Counts and Calculate Fill Percentage Source: https://context7.com/traceld/minestat-sharp/llms.txt Retrieves current and maximum player counts, then calculates the server's fill percentage. Convert player counts to integers for arithmetic operations. ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("minecraft.dilley.me", 25565); if (ms.ServerUp) { int current = int.Parse(ms.CurrentPlayers); int max = int.Parse(ms.MaximumPlayers); double fillPercent = (double)current / max * 100; Console.WriteLine($"Players: {ms.CurrentPlayers}/{ms.MaximumPlayers} ({fillPercent:F1}% full)"); if (current >= max) { Console.WriteLine("Server is full!"); } // Expected output: // Players: 18/20 (90.0% full) // Server is full! } ``` -------------------------------- ### Check Minecraft Server Status Source: https://github.com/traceld/minestat-sharp/blob/master/docs/README.md Instantiate MineStat with the server address and port to check its status. This example demonstrates how to retrieve and display server information like version, player count, MOTD, and latency if the server is online. ```csharp MineStat ms = new MineStat("minecraft.dilley.me", 25565); Console.WriteLine("Minecraft server status of {0} on port {1}:", ms.Address, ms.Port); if(ms.ServerUp) { Console.WriteLine("Server is online running version {0} with {1} out of {2} players.", ms.Version, ms.CurrentPlayers, ms.MaximumPlayers); Console.WriteLine("Message of the day: {0}", ms.Motd); Console.WriteLine("Latency: {0}ms", ms.Latency); } else { Console.WriteLine("Server is offline!"); } ``` -------------------------------- ### Get Connection Latency Source: https://context7.com/traceld/minestat-sharp/llms.txt Measures and displays the round-trip time in milliseconds for establishing a TCP connection. This value is 0 if the connection fails. ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("minecraft.dilley.me", 25565); if (ms.ServerUp) { Console.WriteLine($"Latency: {ms.Latency}ms"); if (ms.Latency < 50) Console.WriteLine("Excellent connection."); else if (ms.Latency < 150) Console.WriteLine("Good connection."); else Console.WriteLine("High latency — players may experience lag."); // Expected output: // Latency: 42ms // Excellent connection. } ``` -------------------------------- ### Instantiate MineStat and Query Server Source: https://context7.com/traceld/minestat-sharp/llms.txt Demonstrates basic and custom timeout usage of the MineStat constructor. The constructor immediately queries the server upon instantiation. Check the ServerUp property to determine if the query was successful. ```csharp using TraceLd.MineStatSharp; // Basic usage with default 5-second timeout MineStat ms = new MineStat("minecraft.dilley.me", 25565); // Usage with a custom timeout (10 seconds) MineStat msCustomTimeout = new MineStat("minecraft.dilley.me", 25565, 10); Console.WriteLine("Minecraft server status of {0} on port {1}:", ms.Address, ms.Port); if (ms.ServerUp) { Console.WriteLine("Server is online running version {0} with {1} out of {2} players.", ms.Version, ms.CurrentPlayers, ms.MaximumPlayers); Console.WriteLine("Message of the day: {0}", ms.Motd); Console.WriteLine("Latency: {0}ms", ms.Latency); } else { Console.WriteLine("Server is offline!"); } // Expected output (server online): // Minecraft server status of minecraft.dilley.me on port 25565: // Server is online running version 1.20.1 with 3 out of 20 players. // Message of the day: Welcome to our Minecraft server! // Latency: 42ms // Expected output (server offline): // Minecraft server status of minecraft.dilley.me on port 25565: // Server is offline! ``` -------------------------------- ### Display Server Address and Port Source: https://context7.com/traceld/minestat-sharp/llms.txt The Address and Port properties store the server details passed to the constructor. These are always set, regardless of server reachability, and are useful for labeling output when checking multiple servers. ```csharp using TraceLd.MineStatSharp; string[] servers = { "hub.example.com", "survival.example.com", "creative.example.com" }; ushort port = 25565; foreach (var server in servers) { MineStat ms = new MineStat(server, port); string status = ms.ServerUp ? "ONLINE" : "OFFLINE"; Console.WriteLine($"[{status}] {ms.Address}:{ms.Port}"); } // Expected output: // [ONLINE] hub.example.com:25565 // [OFFLINE] survival.example.com:25565 // [ONLINE] creative.example.com:25565 ``` -------------------------------- ### Address and Port Properties Source: https://context7.com/traceld/minestat-sharp/llms.txt Address (string) and Port (ushort) store the hostname/IP and port number passed to the constructor. These are set unconditionally, regardless of whether the server is reachable, and can be used to label output when polling multiple servers. ```APIDOC ## Address and Port Properties `Address` (string) and `Port` (ushort) store the hostname/IP and port number passed to the constructor. These are set unconditionally, regardless of whether the server is reachable, and can be used to label output when polling multiple servers. ### Parameters None ### Request Example ```csharp using TraceLd.MineStatSharp; string[] servers = { "hub.example.com", "survival.example.com", "creative.example.com" }; ushort port = 25565; foreach (var server in servers) { MineStat ms = new MineStat(server, port); string status = ms.ServerUp ? "ONLINE" : "OFFLINE"; Console.WriteLine($"[{status}] {ms.Address}:{ms.Port}"); } ``` ### Response #### Success Response (200) - **Address** (string) - The hostname or IP address of the server. - **Port** (ushort) - The port number of the server. #### Response Example ```csharp // Example output: // [ONLINE] hub.example.com:25565 // [OFFLINE] survival.example.com:25565 // [ONLINE] creative.example.com:25565 ``` ``` -------------------------------- ### MineStat Constructor Source: https://context7.com/traceld/minestat-sharp/llms.txt Instantiates a MineStat object and immediately queries the given Minecraft server. The constructor opens a TCP connection to address:port, sends the legacy ping payload, parses the Unicode-encoded response, and populates all public properties. An optional timeout parameter (in seconds, default 5) controls the TCP receive timeout. If the server is unreachable or returns an unexpected response, ServerUp is set to false and all other data properties remain null. ```APIDOC ## MineStat Constructor Instantiates a `MineStat` object and immediately queries the given Minecraft server. The constructor opens a TCP connection to `address:port`, sends the legacy ping payload, parses the Unicode-encoded response, and populates all public properties. An optional `timeout` parameter (in seconds, default 5) controls the TCP receive timeout. If the server is unreachable or returns an unexpected response, `ServerUp` is set to `false` and all other data properties remain `null`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using TraceLd.MineStatSharp; // Basic usage with default 5-second timeout MineStat ms = new MineStat("minecraft.dilley.me", 25565); // Usage with a custom timeout (10 seconds) MineStat msCustomTimeout = new MineStat("minecraft.dilley.me", 25565, 10); Console.WriteLine("Minecraft server status of {0} on port {1}:", ms.Address, ms.Port); if (ms.ServerUp) { Console.WriteLine("Server is online running version {0} with {1} out of {2} players.", ms.Version, ms.CurrentPlayers, ms.MaximumPlayers); Console.WriteLine("Message of the day: {0}", ms.Motd); Console.WriteLine("Latency: {0}ms", ms.Latency); } else { Console.WriteLine("Server is offline!"); } ``` ### Response #### Success Response (Constructor completes without exception) Properties are populated based on server response. `ServerUp` will be true if successful. #### Response Example ```csharp // Server online example: // Minecraft server status of minecraft.dilley.me on port 25565: // Server is online running version 1.20.1 with 3 out of 20 players. // Message of the day: Welcome to our Minecraft server! // Latency: 42ms // Server offline example: // Minecraft server status of minecraft.dilley.me on port 25565: // Server is offline! ``` ``` -------------------------------- ### Version Property Source: https://context7.com/traceld/minestat-sharp/llms.txt A string property containing the Minecraft server version (e.g., "1.20.1"). Populated from the third field of the parsed server response. This value is null if ServerUp is false. ```APIDOC ## Version Property A `string` property containing the Minecraft server version (e.g., `"1.20.1"`). Populated from the third field of the parsed server response. This value is `null` if `ServerUp` is `false`. ### Parameters None ### Request Example ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("minecraft.dilley.me", 25565); if (ms.ServerUp) { Console.WriteLine($"Server version: {ms.Version}"); } ``` ### Response #### Success Response (200) - **Version** (string) - The version of the Minecraft server. Returns `null` if `ServerUp` is `false`. #### Response Example ```csharp // If server is online: // Server version: 1.20.1 // If server is offline: // (No output for version, as ms.ServerUp would be false) ``` ``` -------------------------------- ### Retrieve Minecraft Server Version Source: https://context7.com/traceld/minestat-sharp/llms.txt The Version property returns the Minecraft server version as a string. This value is null if the ServerUp property is false. ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("minecraft.dilley.me", 25565); if (ms.ServerUp) { Console.WriteLine($"Server version: {ms.Version}"); // Expected output: Server version: 1.20.1 } ``` -------------------------------- ### Check Server Status with ServerUp Property Source: https://context7.com/traceld/minestat-sharp/llms.txt Use the ServerUp boolean property to determine if the server responded successfully. Access other data properties only when ServerUp is true to avoid null reference exceptions. ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("play.example.com", 25565); if (ms.ServerUp) { // Safe to access all data properties Console.WriteLine($"Online: {ms.CurrentPlayers}/{ms.MaximumPlayers} players"); } else { // ServerUp is false — do not rely on Version, Motd, CurrentPlayers, etc. Console.WriteLine("Could not reach the server."); } ``` -------------------------------- ### Reference MineStatSharp in .csproj Source: https://context7.com/traceld/minestat-sharp/llms.txt Manually adds a reference to the MineStatSharp package within a .csproj file. ```xml ``` -------------------------------- ### Configure TCP Receive Timeout Source: https://context7.com/traceld/minestat-sharp/llms.txt Configures the TCP receive timeout in milliseconds. The value is multiplied by 1000 if provided in seconds at construction. Default is 5000ms. ```csharp using TraceLd.MineStatSharp; // Use a short timeout for fast polling in a monitoring dashboard MineStat msFast = new MineStat("minecraft.dilley.me", 25565, timeout: 2); Console.WriteLine($"Timeout configured: {msFast.Timeout}ms"); // 2000ms // Use a longer timeout for servers with high latency MineStat msSlow = new MineStat("far-away-server.example.com", 25565, timeout: 15); Console.WriteLine($"Timeout configured: {msSlow.Timeout}ms"); // 15000ms ``` -------------------------------- ### ServerUp Property Source: https://context7.com/traceld/minestat-sharp/llms.txt A boolean property indicating whether the server responded successfully to the ping. It is set to true only when the server returns a valid, parseable response with at least 6 fields. It is false if the TCP connection fails, times out, the response is empty, or the response contains fewer fields than expected. ```APIDOC ## ServerUp Property A `bool` property indicating whether the server responded successfully to the ping. It is set to `true` only when the server returns a valid, parseable response with at least 6 fields. It is `false` if the TCP connection fails, times out, the response is empty, or the response contains fewer fields than expected. ### Parameters None ### Request Example ```csharp using TraceLd.MineStatSharp; MineStat ms = new MineStat("play.example.com", 25565); if (ms.ServerUp) { // Safe to access all data properties Console.WriteLine($"Online: {ms.CurrentPlayers}/{ms.MaximumPlayers} players"); } else { // ServerUp is false — do not rely on Version, Motd, CurrentPlayers, etc. Console.WriteLine("Could not reach the server."); } ``` ### Response #### Success Response (200) - **ServerUp** (bool) - `true` if the server responded successfully, `false` otherwise. #### Response Example ```csharp // If server is online: // true // If server is offline or unreachable: // false ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.