rcon

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package rcon provides RCON client for graceful Minecraft server shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect(ctx context.Context) error
	SendCommand(ctx context.Context, command string) (string, error)
	GracefulShutdown(ctx context.Context, warnings []string, warningInterval time.Duration) error
	Close() error
}

Client is an interface for RCON client operations.

type MockClient

type MockClient struct {

	// Call tracking
	ConnectCalled          bool
	SendCommandCalled      bool
	GracefulShutdownCalled bool
	CloseCalled            bool

	// Commands received via SendCommand
	SentCommands []string

	// Commands received (GracefulShutdown simulation)
	Commands []string

	// Warnings received during graceful shutdown
	Warnings []string

	// Behavior control
	ConnectError          error
	SendCommandError      error
	SendCommandErrors     map[string]error
	SendCommandResponses  map[string]string
	GracefulShutdownError error
	ConnectDelay          time.Duration
	ShutdownDelay         time.Duration
	// contains filtered or unexported fields
}

MockClient is a mock RCON client for testing.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock RCON client.

func (*MockClient) Close

func (m *MockClient) Close() error

Close simulates closing the RCON connection.

func (*MockClient) Connect

func (m *MockClient) Connect(ctx context.Context) error

Connect simulates connecting to the RCON server.

func (*MockClient) GetCommands

func (m *MockClient) GetCommands() []string

GetCommands returns a copy of recorded commands (thread-safe).

func (*MockClient) GetSentCommands

func (m *MockClient) GetSentCommands() []string

GetSentCommands returns a copy of commands sent via SendCommand (thread-safe).

func (*MockClient) GetWarnings

func (m *MockClient) GetWarnings() []string

GetWarnings returns a copy of recorded warnings (thread-safe).

func (*MockClient) GracefulShutdown

func (m *MockClient) GracefulShutdown(ctx context.Context, warnings []string, warningInterval time.Duration) error

GracefulShutdown simulates a graceful server shutdown with warnings.

func (*MockClient) Reset

func (m *MockClient) Reset()

Reset clears all tracking data for reuse.

func (*MockClient) SendCommand

func (m *MockClient) SendCommand(ctx context.Context, command string) (string, error)

SendCommand simulates sending a command to the server.

type RCONClient

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

RCONClient wraps gorcon/rcon for Minecraft server communication.

func NewRCONClient

func NewRCONClient(host string, port int, password string) (*RCONClient, error)

NewRCONClient creates a new RCON client. The client is not connected until Connect() is called.

func (*RCONClient) Close

func (c *RCONClient) Close() error

Close closes the RCON connection.

func (*RCONClient) Connect

func (c *RCONClient) Connect(ctx context.Context) error

Connect establishes connection to the RCON server.

func (*RCONClient) GracefulShutdown

func (c *RCONClient) GracefulShutdown(
	ctx context.Context,
	warnings []string,
	warningInterval time.Duration,
) error

GracefulShutdown performs a graceful shutdown of the Minecraft server. It sends warning messages to players before shutting down.

func (*RCONClient) IsConnected

func (c *RCONClient) IsConnected() bool

IsConnected returns true if the client is connected.

func (*RCONClient) SendCommand

func (c *RCONClient) SendCommand(ctx context.Context, command string) (string, error)

SendCommand sends a command to the server and returns the response.

Jump to

Keyboard shortcuts

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