示例#1
0
    /// <summary>
    /// Generates a server status from the specified <paramref name="server"/>.
    /// </summary>
    public ServerStatus(Server server, bool anonymous = false)
    {
        ArgumentNullException.ThrowIfNull(server);

        Version = ServerVersion.Of(server);
        if (!anonymous)
        {
            Players = new ServerPlayers(server);
        }
        Description = new ServerDescription(server);
        var faviconFile = "favicon.png";

        if (File.Exists(faviconFile))
        {
            byte[] imageData    = File.ReadAllBytes(@"favicon.png");
            bool   isValidImage = imageData.Length >= PngHeader.Length && PngHeader.SequenceEqual(imageData.AsSpan(0, PngHeader.Length));
            if (isValidImage)
            {
                string b64 = Convert.ToBase64String(imageData);
                Favicon = $"data:image/png;base64,{b64}";
            }
            else
            {
                server.Logger.LogError("The favicon.png is invalid! Skipping it.");
                Favicon = b64obsidian;
            }
        }
        else
        {
            Favicon = b64obsidian; // TOOD: add proper image
        }
    }