rcon

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 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
	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
	GracefulShutdownCalled bool
	CloseCalled            bool

	// Commands received
	Commands []string

	// Warnings received during graceful shutdown
	Warnings []string

	// Behavior control
	ConnectError          error
	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) 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.

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