egg

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package egg reads Pterodactyl and Pelican egg files, the game server definitions that most existing panels share, into one internal format.

Index

Constants

View Source
const FeatureEULA = "eula"

FeatureEULA marks games, Minecraft's, that will not start until the player has accepted a license by writing eula=true to eula.txt.

View Source
const MaxConfigFile = 4 << 20

MaxConfigFile is the largest config file ApplyFile is meant for. The caller enforces it when it reads the file.

Variables

View Source
var Catalog = []Entry{
	{
		ID: "minecraft-vanilla", Name: "Vanilla", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "java/vanilla/egg-vanilla-minecraft.yaml",

		MemoryMB: 2 << 10,
		DiskMB:   5 << 10,
	},
	{
		ID: "minecraft-paper", Name: "Paper", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "java/paper/egg-paper.yaml",
	},
	{
		ID: "minecraft-purpur", Name: "Purpur", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "java/purpur/egg-purpur.yaml",

		MemoryMB: 2 << 10,
		DiskMB:   5 << 10,
	},
	{
		ID: "minecraft-fabric", Name: "Fabric", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "java/fabric/egg-fabric.yaml",

		MemoryMB: 2 << 10,
		DiskMB:   5 << 10,
	},
	{
		ID: "minecraft-forge", Name: "Forge", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "java/forge/egg-forge-minecraft.yaml",

		MemoryMB: 4 << 10,
		DiskMB:   10 << 10,
	},
	{
		ID: "minecraft-neoforge", Name: "NeoForge", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "java/neoforge/egg-neo-forge.json",

		MemoryMB: 4 << 10,
		DiskMB:   10 << 10,
	},
	{
		ID: "minecraft-velocity", Name: "Velocity", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "proxy/java/velocity/egg-velocity.json",

		MemoryMB: 512,
		DiskMB:   1 << 10,
	},
	{
		ID: "minecraft-bedrock", Name: "Bedrock", Game: "Minecraft",
		Repo:   "pelican-eggs/minecraft",
		Commit: minecraftCommit,
		Path:   "bedrock/bedrock/egg-vanilla-bedrock.json",

		MemoryMB: 1 << 10,
		DiskMB:   2 << 10,
	},
	{
		ID: "7-days-to-die", Name: "7 Days to Die", Game: "7 Days to Die",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "7_days_to_die/egg-7-days-to-die.json",

		MemoryMB: 8 << 10,
		DiskMB:   20 << 10,
		Ports:    4,
		Block:    4,
	},
	{
		ID: "ark-survival-ascended", Name: "ARK: Survival Ascended", Game: "ARK: Survival Ascended",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "ark_survival_ascended/egg-a-r-k--survival-ascended.json",

		MemoryMB: 16 << 10,
		DiskMB:   40 << 10,
	},
	{
		ID: "counter-strike-2", Name: "Counter-Strike 2", Game: "Counter-Strike 2",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "counter_strike/counter_strike_2/egg-counter--strike2.yaml",

		MemoryMB: 4 << 10,
		DiskMB:   50 << 10,
		Ports:    2,
	},
	{
		ID: "enshrouded", Name: "Enshrouded", Game: "Enshrouded",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "enshrouded/egg-enshrouded.json",

		MemoryMB: 12 << 10,
		DiskMB:   10 << 10,
		Ports:    2,
	},
	{
		ID: "garrys-mod", Name: "Garry's Mod", Game: "Garry's Mod",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "gmod/egg-garrys-mod.yaml",

		MemoryMB: 2 << 10,
		DiskMB:   10 << 10,
	},
	{
		ID: "palworld", Name: "Palworld", Game: "Palworld",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "palworld/egg-palworld.yaml",
	},
	{
		ID: "project-zomboid", Name: "Project Zomboid", Game: "Project Zomboid",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "project_zomboid/egg-project-zomboid.json",

		MemoryMB: 4 << 10,
		DiskMB:   10 << 10,
		Ports:    2,
	},
	{
		ID: "rust", Name: "Rust", Game: "Rust",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "rust/vanilla/egg-rust.yaml",

		MemoryMB: 8 << 10,
		DiskMB:   30 << 10,
		Ports:    4,
	},
	{
		ID: "satisfactory", Name: "Satisfactory", Game: "Satisfactory",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "satisfactory/egg-satisfactory.json",

		MemoryMB: 12 << 10,
		DiskMB:   25 << 10,
		Ports:    2,
	},
	{
		ID: "sons-of-the-forest", Name: "Sons of the Forest", Game: "Sons of the Forest",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "sonsoftheforest/egg-sons-of-the-forest.json",

		MemoryMB: 8 << 10,
		DiskMB:   10 << 10,
		Ports:    3,
	},
	{
		ID: "squad", Name: "Squad", Game: "Squad",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "squad/egg-squad.json",

		MemoryMB: 8 << 10,
		DiskMB:   25 << 10,
		Ports:    3,
	},
	{
		ID: "v-rising", Name: "V Rising", Game: "V Rising",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "v_rising/v_rising_vanilla/egg-v-rising.json",

		MemoryMB: 8 << 10,
		DiskMB:   10 << 10,
		Ports:    2,
	},
	{
		ID: "valheim", Name: "Valheim", Game: "Valheim",
		Repo:   "pelican-eggs/games-steamcmd",
		Commit: steamCommit,
		Path:   "valheim/valheim_vanilla/egg-valheim.json",

		MemoryMB: 4 << 10,
		DiskMB:   5 << 10,
		Ports:    3,
		Block:    3,
	},

	{
		ID: "nodejs", Kind: KindRuntime, Name: "Node.js", Game: "Node.js",
		Repo:   "pelican-eggs/generic",
		Commit: genericCommit,
		Path:   "nodejs/egg-nodejs-generic.yaml",
	},
	{
		ID: "python", Kind: KindRuntime, Name: "Python", Game: "Python",
		Repo:   "pelican-eggs/generic",
		Commit: genericCommit,
		Path:   "python/egg-python-generic.json",
	},
	{
		ID: "bun", Kind: KindRuntime, Name: "Bun", Game: "Bun",
		Repo:   "pelican-eggs/generic",
		Commit: genericCommit,
		Path:   "bun/egg-bun.json",
	},
	{
		ID: "deno", Kind: KindRuntime, Name: "Deno", Game: "Deno",
		Repo:   "pelican-eggs/generic",
		Commit: genericCommit,
		Path:   "deno/egg-deno-generic.json",
	},

	{
		ID: "java", Kind: KindRuntime, Name: "Java", Game: "Java",
		Repo:   "pelican-eggs/generic",
		Commit: genericCommit,
		Path:   "java/egg-generic-java.json",

		MemoryMB: 1024,
	},
}
View Source
var RawBase = "https://raw.githubusercontent.com"

RawBase is where catalog files are downloaded from. Tests point it at a local server.

View Source
var RuntimeVars = []string{
	"SERVER_MEMORY", "SERVER_IP", "SERVER_PORT", "TZ", "STARTUP",
	"P_SERVER_LOCATION", "P_SERVER_UUID",
}

RuntimeVars are the environment variables the runtime has to set for every server, whatever the egg declares. Startup commands and install scripts use them freely, for example -Xmx{{SERVER_MEMORY}}M.

Functions

func ApplyFile

func ApplyFile(parser string, content []byte, replaces []Replace, expand func(string) string) (out []byte, skipped []string, err error)

ApplyFile makes the changes an egg asks for in one config file and returns the new content. The parser is one of properties, file, yaml, json, ini and xml. Values go through expand first, so they may hold placeholders; expand may be nil.

A file that cannot be read as its format is an error. A key that cannot be set, such as a path that runs through a plain value, is left alone and named in skipped, so the rest of the file still gets its changes.

func Expand

func Expand(s string, vars map[string]string, port int) string

Expand fills in {{...}} placeholders. Eggs name the same value in several ways, from {{VAR}} to the long server.build.env.VAR and the server.allocations.* paths newer Pelican eggs use; all are understood. A placeholder that cannot be resolved is left as written.

func HasValue added in v0.7.5

func HasValue(s string, vars map[string]string, port int) bool

HasValue reports whether s refers to at least one placeholder that resolves to a non-empty value. A string with no placeholders, or only empty ones, has none.

func KnownParser added in v0.7.2

func KnownParser(parser string) bool

KnownParser reports whether ApplyFile can edit files with the parser.

Types

type Command

type Command struct {
	Label string
	Line  string
}

type ConfigFile

type ConfigFile struct {
	Path   string
	Parser string // properties, file, yaml, json, ini or xml
	Find   []Replace
}

ConfigFile is a file the panel edits before each start.

type Done

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

Done reports whether a console line means the server has started. A done string matches when the line contains it; one that starts with "regex:" is a regular expression the line is searched with. Lines that cannot be compiled never match.

func (*Done) Empty

func (d *Done) Empty() bool

Empty reports whether the egg names no line, so nothing tells when the server is up.

func (*Done) Match

func (d *Done) Match(line string) bool

Match reports whether the line means the server is up.

type Egg

type Egg struct {
	Version     string // meta.version of the file it came from
	Name        string
	Author      string
	Description string
	Features    []string
	Images      []Image // the first one is the default
	// Startup is the default command; StartupCommands has every named
	// variant in file order, and Startup is the first of them.
	Startup         string
	StartupCommands []Command
	// Stop is the raw value: a console command, or "^" plus a signal.
	Stop      string
	Done      []string // console lines that mean the server has started
	Files     []ConfigFile
	Install   Install
	Variables []Variable
}

Egg is one game server definition.

func Fetch

func Fetch(ctx context.Context, client *http.Client, e Entry) (*Egg, []byte, error)

Fetch downloads a catalog entry and returns it parsed, along with the file as downloaded so it can be stored unchanged.

func FetchURL

func FetchURL(ctx context.Context, client *http.Client, address string) (*Egg, []byte, error)

FetchURL downloads an egg from any https address. Without a client of its own it only connects to public addresses.

func Parse

func Parse(data []byte) (*Egg, error)

Parse reads an egg in any supported format. The format is told apart by its first character and then by meta.version.

func (*Egg) DoneMatcher

func (e *Egg) DoneMatcher() *Done

DoneMatcher prepares the egg's done lines.

func (*Egg) HasFeature

func (e *Egg) HasFeature(name string) bool

HasFeature reports whether the egg lists the feature, such as "eula".

func (*Egg) StopSignal

func (e *Egg) StopSignal() (name string, ok bool)

StopSignal reports whether Stop is a signal rather than a console command. Eggs write it as "^C" for SIGINT or "^" plus a signal name; some write the caret twice, and mean the same.

type Entry

type Entry struct {
	ID string
	// Kind tells the eggs of games from the generic ones that run a
	// program of the user's own. The two are offered in different places.
	Kind   Kind
	Name   string
	Game   string
	Repo   string // owner/name on GitHub
	Commit string // full SHA
	Path   string

	// What a game needs when the egg does not say, offered as the defaults
	// of a new server: memory and disk in MB, and how many ports it takes.
	// Zero means the general defaults.
	MemoryMB int64
	DiskMB   int64
	Ports    int
	// Block is how many ports in a row, from the game port, the game itself
	// opens without an egg variable to say where (Valheim's query port is
	// always the game port plus one). They are part of Ports. Zero or one
	// means the game port stands alone.
	Block int
}

Entry is one egg in the curated list. The list is not embedded in the binary: it names files in the pelican-eggs repositories (MIT) at a fixed commit, and the commits move with Zelie releases.

func Lookup

func Lookup(id string) (Entry, bool)

Lookup returns the catalog entry with the given id.

func OfKind

func OfKind(k Kind) []Entry

OfKind lists the catalog entries of one kind, in catalog order.

type Image

type Image struct {
	Label string
	Ref   string
}

type Install

type Install struct {
	Image      string
	Entrypoint string
	Script     string
}

type Kind

type Kind string

Kind is what an egg is for.

const (
	// KindGame is the zero value: a game server.
	KindGame Kind = ""
	// KindRuntime is a generic egg that runs files the user brings, such
	// as a Node.js or Python program.
	KindRuntime Kind = "runtime"
)

type Replace

type Replace struct {
	Key     string
	Value   string
	IfValue string
	Add     bool
}

Replace sets Key to Value. Value may hold placeholders. When IfValue is set the key is only changed if it currently holds that value; eggs write that as a nested object under the key. Add asks the "file" parser to append the line when no line starts with Key; the other parsers add missing keys on their own.

type Variable

type Variable struct {
	Name         string
	Description  string
	Env          string
	Default      string
	UserViewable bool
	UserEditable bool
	Rules        []string
}

func (Variable) Check

func (v Variable) Check(value string) error

Check tests a value against the variable's rules. The rules are the Laravel ones eggs use; a rule Check does not know is ignored, so an egg with an exotic rule stays usable. Like Laravel, an empty value passes everything except "required".

Jump to

Keyboard shortcuts

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