Documentation
¶
Overview ¶
Package rcon provides RCON client for graceful Minecraft server shutdown.
Index ¶
- type Client
- type MockClient
- func (m *MockClient) Close() error
- func (m *MockClient) Connect(ctx context.Context) error
- func (m *MockClient) GetCommands() []string
- func (m *MockClient) GetSentCommands() []string
- func (m *MockClient) GetWarnings() []string
- func (m *MockClient) GracefulShutdown(ctx context.Context, warnings []string, warningInterval time.Duration) error
- func (m *MockClient) Reset()
- func (m *MockClient) SendCommand(ctx context.Context, command string) (string, error)
- type RCONClient
- func (c *RCONClient) Close() error
- func (c *RCONClient) Connect(ctx context.Context) error
- func (c *RCONClient) GracefulShutdown(ctx context.Context, warnings []string, warningInterval time.Duration) error
- func (c *RCONClient) IsConnected() bool
- func (c *RCONClient) SendCommand(ctx context.Context, command string) (string, error)
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 (*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) SendCommand ¶
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) 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 ¶
SendCommand sends a command to the server and returns the response.