minecraft

package
v1.0.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLevelName = "world"

DefaultLevelName is the world directory Minecraft uses when server.properties does not override level-name.

View Source
const MaxDatapackBytes = 256 << 20 // 256 MiB

MaxDatapackBytes caps a downloaded datapack archive. Datapacks are small world-data bundles; anything enormous is a mistake or an attack.

View Source
const (
	SettingVelocitySecret = "velocity_forwarding_secret"
)

Variables

This section is empty.

Functions

func DetectModpackLoader

func DetectModpackLoader(candidates ...string) (models.ModLoader, bool)

Inspects candidate strings for modloader identification

func DownloadAllowsPrivate added in v1.0.39

func DownloadAllowsPrivate(indexerURL string) bool

DownloadAllowsPrivate reports whether downloads driven by an indexer at indexerURL may target private network addresses. A public indexer's responses must never point the panel at internal hosts (SSRF via tampered index data), while a self-hosted indexer on a private network is an operator's deliberate trust decision and keeps serving private downloads. Unresolvable indexer hosts fail closed to strict (public-only).

func DownloadDatapackArchiveFrom added in v1.0.39

func DownloadDatapackArchiveFrom(ctx context.Context, indexerURL, rawURL, destPath string) error

DownloadDatapackArchiveFrom streams a datapack to destPath with an SSRF-guarded client whose private-network allowance is scoped to the indexer that supplied the URL. It does not trust Content-Length.

func DownloadDatapackArchiveWithClient added in v1.0.39

func DownloadDatapackArchiveWithClient(client *http.Client, ctx context.Context, rawURL, destPath string) error

DownloadDatapackArchiveWithClient is DownloadDatapackArchive with an explicit client so tests can exercise the streaming and size logic without defeating the SSRF guard.

func FindMostRecentMinecraftVersion

func FindMostRecentMinecraftVersion(versions []string) string

func GamePackFormat added in v1.0.39

func GamePackFormat(mcVersion string) (float64, bool)

GamePackFormat reports the data pack format supported by a Minecraft release (e.g. "1.21.1" -> 48). Unknown versions (snapshots, future releases) report false.

func GenerateVelocitySecret

func GenerateVelocitySecret() (string, error)

GenerateVelocitySecret generates a cryptographically secure 32-byte (256-bit) secret

func GetAllConfigs

func GetAllConfigs(serverDataPath string, loader models.ModLoader) (map[string]any, error)

GetAllConfigs returns all configuration files for a server

func GetAllVersions

func GetAllVersions() []string

Returns all versions including snapshots

func GetDatapacksPath added in v1.0.39

func GetDatapacksPath(serverDataPath, levelName string) string

GetDatapacksPath returns the datapack directory for a server's world. Datapacks are world data, not mods, so they live under the world folder rather than a loader-specific mods directory.

func GetJavaVersion

func GetJavaVersion(mcVersion string) (string, error)

Fetches required Java version for a specific Minecraft version

func GetLatestSnapshot

func GetLatestSnapshot() string

Returns the latest snapshot version

func GetLatestVersion

func GetLatestVersion() string

Returns the latest Minecraft release version

func GetModsPath

func GetModsPath(serverDataPath string, loader models.ModLoader) string

GetModsPath returns the path where mods should be stored for a given server

func GetProtocolVersion

func GetProtocolVersion(mcVersion string) int

Get protocol version for a Minecraft version string

func GetTPSCommand

func GetTPSCommand(modLoader models.ModLoader) string

func GetVersionDate

func GetVersionDate(version string) (time.Time, error)

Returns the release date of a Minecraft version

func GetVersions

func GetVersions() []string

Returns a list of all Minecraft release versions

func IsClientOnly added in v1.0.39

func IsClientOnly(jarPath string) (bool, error)

IsClientOnly reports whether the jar targets the client exclusively. It returns false for unknown metadata; callers that must be strict should check InspectModSide directly.

func IsSnapshot

func IsSnapshot(version string) bool

Checks if a version is a snapshot

func IsValidDatapackFile added in v1.0.39

func IsValidDatapackFile(filename string) bool

IsValidDatapackFile reports whether a filename has a datapack archive extension. Datapacks are distributed as ZIP archives.

func IsValidModFile

func IsValidModFile(filename string, loader models.ModLoader) bool

IsValidModFile checks if a file is a valid mod file for the given loader

func IsValidVersion

func IsValidVersion(version string) bool

Checks if a given version string is a valid Minecraft version

func LoadYAMLConfig

func LoadYAMLConfig(serverDataPath string, configFile ConfigFile) (map[string]any, error)

LoadYAMLConfig loads a YAML configuration file

func MatchModLoader

func MatchModLoader(input string) (models.ModLoader, bool)

func NormalizeDatapackArchive added in v1.0.39

func NormalizeDatapackArchive(path string) (bool, error)

NormalizeDatapackArchive repairs a common real-world packaging mistake: the whole datapack is nested inside a single wrapper directory (pack.mcmeta sits at wrapper/pack.mcmeta instead of the archive root). Minecraft ignores such archives, so the installer re-packs them with the wrapper stripped. It reports whether the archive was rewritten. An archive that is already valid, or that cannot be repaired, is left untouched (an error is returned only for a structurally broken archive).

func PackFormatWarning added in v1.0.39

func PackFormatWarning(pack PackFormat, mcVersion string) string

PackFormatWarning judges a datapack's declared formats against a server's Minecraft version. Minecraft loads packs whose format is at or below the game's supported format (older packs get fixers) and marks packs built for NEWER formats as incompatible. The message is empty when the pack is fine or when either side is unknown — the panel never warns on guesses.

func ParsePlayerListFromOutput

func ParsePlayerListFromOutput(output string) (int, []string)

ParsePlayerListFromOutput parses player count and names from list command output.

func ParseTPSFromOutput

func ParseTPSFromOutput(output string) float64

ParseTPSFromOutput parses TPS value from various server command outputs.

func SaveServerProperties

func SaveServerProperties(serverDataPath string, properties ServerProperties) error

SaveServerProperties saves the server.properties file

func SaveYAMLConfig

func SaveYAMLConfig(serverDataPath string, configFile ConfigFile, config map[string]any) error

SaveYAMLConfig saves a YAML configuration file

func SyncVelocitySecretToDataPath

func SyncVelocitySecretToDataPath(dataPath string, secret string) (string, error)

SyncVelocitySecretToDataPath writes or updates the Velocity modern forwarding secret in paper-global.yml or paper.yml

func ValidateDatapackArchive added in v1.0.39

func ValidateDatapackArchive(path string) error

ValidateDatapackArchive checks that a file is a well-formed datapack: a ZIP archive containing a pack.mcmeta descriptor at its root. This is what separates a real datapack from an arbitrary zip a user might upload.

func ValidateDatapackFilename added in v1.0.39

func ValidateDatapackFilename(name string) error

ValidateDatapackFilename rejects path traversal and non-zip names.

Types

type ConfigFile

type ConfigFile string

ConfigFile represents a generic configuration file type

const (
	ConfigServerProperties ConfigFile = "server.properties"
	ConfigBukkit           ConfigFile = "bukkit.yml"
	ConfigSpigot           ConfigFile = "spigot.yml"
	ConfigPaper            ConfigFile = "paper.yml"
	ConfigPaperGlobal      ConfigFile = "config/paper-global.yml"
	ConfigPaperWorld       ConfigFile = "config/paper-world-defaults.yml"
)

func GetConfigFiles

func GetConfigFiles(loader models.ModLoader) []ConfigFile

GetConfigFiles returns the configuration files for a specific mod loader

type LatestVersions

type LatestVersions struct {
	Release  string `json:"release"`
	Snapshot string `json:"snapshot"`
}

type ModLoaderInfo

type ModLoaderInfo struct {
	Name              string
	DisplayName       string
	Description       string
	Category          string
	ModsDirectory     string
	ConfigDirectory   string
	SupportedVersions []string
	FileExtensions    []string
}

ModLoaderInfo contains information about a specific mod loader

func GetAllModLoaders

func GetAllModLoaders() []ModLoaderInfo

GetAllModLoaders returns information about all available mod loaders

func GetModLoaderInfo

func GetModLoaderInfo(loader models.ModLoader) ModLoaderInfo

GetModLoaderInfo returns information about a specific mod loader

type ModSide added in v1.0.39

type ModSide string

ModSide describes which Minecraft side a mod artifact targets.

const (
	// SideClient means the mod is client-only and will crash a dedicated server.
	SideClient ModSide = "client"
	// SideServer means the mod targets the server side only.
	SideServer ModSide = "server"
	// SideBoth means the mod runs on both sides (the Fabric default).
	SideBoth ModSide = "both"
	// SideUnknown means the metadata declares nothing reliable (e.g. Forge).
	SideUnknown ModSide = "unknown"
)

func InspectModSide added in v1.0.39

func InspectModSide(jarPath string) (ModSide, error)

InspectModSide reads a mod jar's metadata to determine whether it targets the client, the server, or both. Client-only mods crash dedicated servers at class load, so a panel must catch them before installing (ME-04).

Fabric and Quilt declare an explicit environment; Forge and NeoForge have no reliable equivalent, so those return SideUnknown rather than guessing.

type PackFormat added in v1.0.39

type PackFormat struct {
	Min float64
	Max float64
}

PackFormat is the pack-format range a datapack declares in pack.mcmeta. Formats since 1.21.9 carry minor parts (88.0, 94.1), so the range is floating point. A zero Min means the archive declared nothing usable.

func ReadPackFormat added in v1.0.39

func ReadPackFormat(archivePath string) (PackFormat, error)

ReadPackFormat parses the pack.mcmeta of a datapack archive. It understands all three historical shapes: legacy pack_format, pack_format as a range object with supported_formats, and the 1.21.9+ min_format/max_format pair. A zero value means the archive declared nothing the panel can judge.

func (PackFormat) Known added in v1.0.39

func (p PackFormat) Known() bool

Known reports whether the archive declared any format at all.

func (PackFormat) String added in v1.0.39

func (p PackFormat) String() string

String renders the declared range for display ("48", "88.0 - 94.1").

type ProtocolVersionEntry

type ProtocolVersionEntry struct {
	MinecraftVersion string `json:"minecraftVersion"`
	Version          int    `json:"version"`
	DataVersion      int    `json:"dataVersion"`
	UsesNetty        bool   `json:"usesNetty"`
	MajorVersion     string `json:"majorVersion"`
	ReleaseType      string `json:"releaseType"`
}

type SLPClient

type SLPClient struct {
	// contains filtered or unexported fields
}

Implements the Minecraft Server List Ping protocol

func NewSLPClient

func NewSLPClient(timeout time.Duration) *SLPClient

SLP client with timeout

func (*SLPClient) Ping

func (c *SLPClient) Ping(ctx context.Context, host string, port int, mcVersion string) (*SLPResult, error)

Server list ping to host and port

type SLPResult

type SLPResult struct {
	Version struct {
		Name     string `json:"name"`
		Protocol int    `json:"protocol"`
	} `json:"version"`
	Players struct {
		Max    int `json:"max"`
		Online int `json:"online"`
		Sample []struct {
			Name string `json:"name"`
			ID   string `json:"id"`
		} `json:"sample"`
	} `json:"players"`
	Description    json.RawMessage `json:"description"`
	Favicon        string          `json:"favicon,omitempty"`
	EnforcesSecure bool            `json:"enforcesSecureChat,omitempty"`
	LatencyMs      int64
	MOTD           string   // Parsed from Description
	PlayerNames    []string // Extracted player names
}

Parsed response from a server list ping

type ServerProperties

type ServerProperties map[string]string

ServerProperties represents the Minecraft server.properties file

func LoadServerProperties

func LoadServerProperties(serverDataPath string) (ServerProperties, error)

LoadServerProperties loads the server.properties file from a server's data directory

func (ServerProperties) GetBool

func (p ServerProperties) GetBool(key string, defaultValue bool) bool

func (ServerProperties) GetInt

func (p ServerProperties) GetInt(key string, defaultValue int) int

func (ServerProperties) GetString

func (p ServerProperties) GetString(key string, defaultValue string) string

func (ServerProperties) SetBool

func (p ServerProperties) SetBool(key string, value bool)

func (ServerProperties) SetInt

func (p ServerProperties) SetInt(key string, value int)

func (ServerProperties) SetString

func (p ServerProperties) SetString(key, value string)

type Version

type Version struct {
	ID              string    `json:"id"`
	Type            string    `json:"type"`
	URL             string    `json:"url"`
	Time            time.Time `json:"time"`
	ReleaseTime     time.Time `json:"releaseTime"`
	SHA1            string    `json:"sha1"`
	ComplianceLevel int       `json:"complianceLevel"`
}

A single Minecraft version entry

func GetVersionInfo

func GetVersionInfo(version string) (*Version, error)

Returns detailed information about a specific version

type VersionManifestV2

type VersionManifestV2 struct {
	Latest   LatestVersions `json:"latest"`
	Versions []Version      `json:"versions"`
}

type VersionMetadata

type VersionMetadata struct {
	JavaVersion struct {
		Component    string `json:"component"`
		MajorVersion int    `json:"majorVersion"`
	} `json:"javaVersion"`
}

Metadata for a specific version

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL