server

package
v0.0.0-...-a5a0d7e Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkWidth    = 16
	ChunkHeight   = 256
	SectionWidth  = ChunkWidth
	SectionHeight = 16
	ChunkSections = ChunkHeight / SectionHeight
	SectionVolume = SectionWidth * SectionHeight * SectionWidth

	MinBitsPerBlock    = 4
	MaxBitsPerBlock    = 8
	GlobalBitsPerBlock = 14
)

Variables

View Source
var (
	OnPacketReadEvent  = "onPacketRead"
	OnPacketWriteEvent = "onPacketWrite"
)
View Source
var (
	ErrServerRunning = errors.New("server already running")
	ErrServerStopped = errors.New("server already stopped")
)

Functions

This section is empty.

Types

type Chunk

type Chunk interface {
	GetX() int
	GetZ() int
	GetSection(y int) ChunkSection
	GetSections() [ChunkSections]ChunkSection
	SetBlock(x, y, z int, block string)
	GetBlock(x, y, z int) string
}

type ChunkSection

type ChunkSection interface {
	IsEmpty() bool
	GetPalette() SectionPalette
	SetBlock(x, y, z int, block string)
	GetBlock(x, y, z int) string
	GetBlocks() bytes.PackedArray
}

type CompressionConf

type CompressionConf struct {
	Threshold int
	Level     int
}

type Config

type Config struct {
	Host        string
	Port        int
	World       WorldConf
	Compression CompressionConf
}

type Connection

type Connection interface {
	RemoteAddr() net.Addr

	GetServer() Server
	SetUniqueID(uniqueID uuid.UUID)
	GetUniqueID() uuid.UUID
	SetUsername(username string)
	GetUsername() string
	SetProtocol(protocol protocol.Protocol)
	GetProtocol() protocol.Protocol
	SetState(state protocol.State)
	GetState() protocol.State
	UseCompression() bool

	GetCompressionThreshold() int
	SetCompressionLevel(level int)
	GetCompressionLevel() int

	Close() error
	DelayedClose(delay time.Duration) error

	ReadPacket() error
	WritePacket(packet protocol.Packet) error
	// contains filtered or unexported methods
}

type PacketEvent

type PacketEvent interface {
	GetConnection() Connection
	GetPlayer() Player
	GetPacket() protocol.Packet
	SetCancelled(cancelled bool)
	IsCancelled() bool
}

func NewPacketEvent

func NewPacketEvent(connection Connection, player Player, packet protocol.Packet) PacketEvent

type Player

type Player interface {
	GetServer() Server
	GetUniqueID() uuid.UUID
	GetUsername() string
	GetProtocol() protocol.Protocol
	GetState() protocol.State

	GetLatency() time.Duration

	IsKeepAlivePending() bool

	GetLastKeepAliveTime() time.Time

	GetLastKeepAliveID() int32
	SendPacket(packet protocol.Packet) error
	Kick(reason []chat.Component) error
	// contains filtered or unexported methods
}

type SectionPalette

type SectionPalette interface {
	GetOrAdd(block string) int
	GetIndex(block string) int
	GetBlock(index int) string
	GetBlocks() []string
	GetLength() int
	GetBitsPerBlock() int
}

type Server

type Server interface {
	Start() error
	Stop() error

	GetConfig() Config
	GetWorld() World

	GetPlayerCount() int
	GetPlayers() []Player
	GetPlayer(uniqueID uuid.UUID) Player
	ForEachPlayer(fn func(player Player) bool)

	FireEvent(event string, args ...interface{})
	On(event string, fn interface{}, priority ...eventbus.Priority) error
	OnAsync(event string, fn interface{}) error
	// contains filtered or unexported methods
}

func NewServer

func NewServer(config Config) Server

type World

type World interface {
	GetName() string
	GetDimension() protocol.Dimension
	GetChunk(x, z int) Chunk
	GetChunks() []Chunk
	SetBlock(x, y, z int, block string)
	GetBlock(x, y, z int) string
	SendChunks(player Player) error
}

func NewWorld

func NewWorld(name string, dimension protocol.Dimension) World

type WorldConf

type WorldConf struct {
	Schematic      string
	RenderDistance int
}

Jump to

Keyboard shortcuts

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