Initial commit: RegionIO Minecraft server core (26.1.2/protocol 775)
Vanilla-faithful overworld generator (final_density + multi-noise biomes), full connection lifecycle (status/login/configuration/play), chunk streaming, creative block editing, and the protocol/nbt/registry infrastructure.
This commit is contained in:
commit
a7bb9496ae
146 changed files with 217621 additions and 0 deletions
21
internal/server/profile.go
Normal file
21
internal/server/profile.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
)
|
||||
|
||||
// Profile is an authenticated (or, in offline mode, derived) player identity.
|
||||
type Profile struct {
|
||||
UUID [16]byte
|
||||
Name string
|
||||
}
|
||||
|
||||
// OfflineUUID derives the stable offline-mode UUID for a username, matching
|
||||
// vanilla's java.util.UUID.nameUUIDFromBytes("OfflinePlayer:" + name): an
|
||||
// MD5-based (version 3) UUID with the IETF variant bits set.
|
||||
func OfflineUUID(name string) [16]byte {
|
||||
sum := md5.Sum([]byte("OfflinePlayer:" + name))
|
||||
sum[6] = (sum[6] & 0x0f) | 0x30 // version 3
|
||||
sum[8] = (sum[8] & 0x3f) | 0x80 // IETF variant
|
||||
return sum
|
||||
}
|
||||
98
internal/server/server.go
Normal file
98
internal/server/server.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
// Package server holds the RegionIO core: configuration, shared state, and the
|
||||
// data shown to clients (status, MOTD).
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"regionio/internal/protocol"
|
||||
"regionio/internal/world"
|
||||
)
|
||||
|
||||
// Config holds operator-tunable settings for a RegionIO instance.
|
||||
type Config struct {
|
||||
Host string
|
||||
Port int
|
||||
MOTD string
|
||||
MaxPlayers int
|
||||
// CompressionThreshold is the minimum uncompressed packet size (bytes) that
|
||||
// triggers zlib compression. Negative disables compression entirely.
|
||||
CompressionThreshold int
|
||||
// WorldSeed seeds terrain generation.
|
||||
WorldSeed int64
|
||||
}
|
||||
|
||||
// DefaultConfig returns sensible defaults matching vanilla expectations.
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
Host: "0.0.0.0",
|
||||
Port: 25565,
|
||||
MOTD: "RegionIO — a Minecraft server in Go",
|
||||
MaxPlayers: 20,
|
||||
CompressionThreshold: 256,
|
||||
// WorldSeed defaults to 0 for backward compatibility; operators override
|
||||
// it via the REGIONIO_SEED env var or the -seed flag.
|
||||
WorldSeed: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// Server is the top-level core shared across all connections.
|
||||
type Server struct {
|
||||
cfg Config
|
||||
chunks *world.Cache
|
||||
}
|
||||
|
||||
// New constructs a Server from cfg.
|
||||
func New(cfg Config) *Server {
|
||||
return &Server{
|
||||
cfg: cfg,
|
||||
chunks: world.NewCache(int32(cfg.CompressionThreshold), world.NewVanillaGenerator(cfg.WorldSeed)),
|
||||
}
|
||||
}
|
||||
|
||||
// Config returns the active configuration.
|
||||
func (s *Server) Config() Config { return s.cfg }
|
||||
|
||||
// Chunks returns the shared chunk cache.
|
||||
func (s *Server) Chunks() *world.Cache { return s.chunks }
|
||||
|
||||
// statusResponse mirrors the JSON shape the client expects for the server-list
|
||||
// ping. Field names and nesting are part of the protocol contract.
|
||||
type statusResponse struct {
|
||||
Version statusVersion `json:"version"`
|
||||
Players statusPlayers `json:"players"`
|
||||
Description statusText `json:"description"`
|
||||
// EnforcesSecureChat is read by the client; false keeps unsigned chat working.
|
||||
EnforcesSecureChat bool `json:"enforcesSecureChat"`
|
||||
}
|
||||
|
||||
type statusVersion struct {
|
||||
Name string `json:"name"`
|
||||
Protocol int `json:"protocol"`
|
||||
}
|
||||
|
||||
type statusPlayers struct {
|
||||
Max int `json:"max"`
|
||||
Online int `json:"online"`
|
||||
}
|
||||
|
||||
type statusText struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// StatusJSON returns the marshaled status response for the server-list ping.
|
||||
func (s *Server) StatusJSON(onlinePlayers int) ([]byte, error) {
|
||||
resp := statusResponse{
|
||||
Version: statusVersion{
|
||||
Name: protocol.GameVersion,
|
||||
Protocol: protocol.ProtocolVersion,
|
||||
},
|
||||
Players: statusPlayers{
|
||||
Max: s.cfg.MaxPlayers,
|
||||
Online: onlinePlayers,
|
||||
},
|
||||
Description: statusText{Text: s.cfg.MOTD},
|
||||
EnforcesSecureChat: false,
|
||||
}
|
||||
return json.Marshal(resp)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue