Documentation ¶
Overview ¶
Package proxy contains Gate's Minecraft Java edition proxy implementation.
Index ¶
- Constants
- Variables
- func BroadcastMessage(sinks []MessageSink, msg component.Component)
- func BroadcastPluginMessage(sinks []message.ChannelMessageSink, identifier message.ChannelIdentifier, ...)
- func PlayersToSlice[R any](p Players) []R
- func RegisteredServerEqual(a, b RegisteredServer) bool
- func ServerInfoEqual(a, b ServerInfo) bool
- func WithMessageSender(id uuid.UUID) command.MessageOption
- func WithMessageType(t MessageType) command.MessageOption
- type ChannelRegistrar
- type CommandExecuteEvent
- func (c *CommandExecuteEvent) Allowed() bool
- func (c *CommandExecuteEvent) Command() string
- func (c *CommandExecuteEvent) Forward() bool
- func (c *CommandExecuteEvent) OriginalCommand() string
- func (c *CommandExecuteEvent) SetAllowed(allowed bool)
- func (c *CommandExecuteEvent) SetCommand(commandline string)
- func (c *CommandExecuteEvent) SetForward(forward bool)
- func (c *CommandExecuteEvent) Source() command.Source
- type ConnectionHandshakeEvent
- type ConnectionRequest
- type ConnectionResult
- type ConnectionStatus
- type DisconnectEvent
- type DisconnectPlayerKickResult
- type GameProfileProvider
- type GameProfileRequestEvent
- func (e *GameProfileRequestEvent) Conn() Inbound
- func (e *GameProfileRequestEvent) GameProfile() profile.GameProfile
- func (e *GameProfileRequestEvent) OnlineMode() bool
- func (e *GameProfileRequestEvent) Original() profile.GameProfile
- func (e *GameProfileRequestEvent) SetGameProfile(p profile.GameProfile)
- type HandshakeAddresser
- type Inbound
- type KickedFromServerEvent
- func (e *KickedFromServerEvent) KickedDuringServerConnect() bool
- func (e *KickedFromServerEvent) OriginalReason() component.Component
- func (e *KickedFromServerEvent) Player() Player
- func (e *KickedFromServerEvent) Result() ServerKickResult
- func (e *KickedFromServerEvent) Server() RegisteredServer
- func (e *KickedFromServerEvent) SetResult(result ServerKickResult)
- type LoginEvent
- type LoginPhaseConnection
- type LoginStatus
- type MessageConsumer
- type MessageSink
- type MessageType
- type NotifyKickResult
- type Options
- type PermissionsSetupEvent
- type PingEvent
- type Player
- type PlayerAvailableCommandsEvent
- type PlayerChannelRegisterEvent
- type PlayerChatEvent
- type PlayerChooseInitialServerEvent
- type PlayerModInfoEvent
- type PlayerResourcePackStatusEvent
- func (p *PlayerResourcePackStatusEvent) OverwriteKick() bool
- func (p *PlayerResourcePackStatusEvent) PackInfo() ResourcePackInfo
- func (p *PlayerResourcePackStatusEvent) Player() Player
- func (p *PlayerResourcePackStatusEvent) SetOverwriteKick(overwriteKick bool)
- func (p *PlayerResourcePackStatusEvent) Status() ResourcePackResponseStatus
- type PlayerSettingsChangedEvent
- type Players
- type Plugin
- type PluginMessageEvent
- func (p *PluginMessageEvent) Allowed() bool
- func (p *PluginMessageEvent) Data() []byte
- func (p *PluginMessageEvent) Identifier() message.ChannelIdentifier
- func (p *PluginMessageEvent) SetForward(forward bool)
- func (p *PluginMessageEvent) Source() message.ChannelMessageSource
- func (p *PluginMessageEvent) Target() message.ChannelMessageSink
- type PostLoginEvent
- type PreLoginEvent
- func (e *PreLoginEvent) Allow()
- func (e *PreLoginEvent) Conn() Inbound
- func (e *PreLoginEvent) Deny(reason component.Component)
- func (e *PreLoginEvent) ForceOfflineMode()
- func (e *PreLoginEvent) ForceOnlineMode()
- func (e *PreLoginEvent) Reason() component.Component
- func (e *PreLoginEvent) Result() PreLoginResult
- func (e *PreLoginEvent) Username() string
- type PreLoginResult
- type PreShutdownEvent
- type Proxy
- func (p *Proxy) ChannelRegistrar() *ChannelRegistrar
- func (p *Proxy) Command() *command.Manager
- func (p *Proxy) Config() config.Config
- func (p *Proxy) DisconnectAll(reason component.Component)
- func (p *Proxy) Event() event.Manager
- func (p *Proxy) HandleConn(raw net.Conn)
- func (p *Proxy) Player(id uuid.UUID) Player
- func (p *Proxy) PlayerByName(username string) Player
- func (p *Proxy) PlayerCount() int
- func (p *Proxy) Players() []Player
- func (p *Proxy) Register(info ServerInfo) (RegisteredServer, error)
- func (p *Proxy) Server(name string) RegisteredServer
- func (p *Proxy) Servers() []RegisteredServer
- func (p *Proxy) Shutdown(reason component.Component)
- func (p *Proxy) Start(ctx context.Context) error
- func (p *Proxy) Unregister(info ServerInfo) bool
- type ReadyEvent
- type RedirectPlayerKickResult
- type RegisteredServer
- type ResourcePackInfo
- type ResourcePackOrigin
- type ResourcePackResponseStatus
- type ServerConnectedEvent
- type ServerConnection
- type ServerDialer
- type ServerInfo
- type ServerKickResult
- type ServerLoginPluginMessageEvent
- type ServerLoginPluginMessageResult
- type ServerPostConnectEvent
- type ServerPreConnectEvent
- func (e *ServerPreConnectEvent) Allow(server RegisteredServer)
- func (e *ServerPreConnectEvent) Allowed() bool
- func (e *ServerPreConnectEvent) Deny()
- func (e *ServerPreConnectEvent) OriginalServer() RegisteredServer
- func (e *ServerPreConnectEvent) Player() Player
- func (e *ServerPreConnectEvent) Server() RegisteredServer
- type ServerRegistrar
- type ServerRegistry
- type ServerResourcePackSendEvent
- func (e *ServerResourcePackSendEvent) Allowed() bool
- func (e *ServerResourcePackSendEvent) ProvidedResourcePack() ResourcePackInfo
- func (e *ServerResourcePackSendEvent) ReceivedResourcePack() ResourcePackInfo
- func (e *ServerResourcePackSendEvent) ServerConnection() ServerConnection
- func (e *ServerResourcePackSendEvent) SetAllowed(allowed bool)
- func (e *ServerResourcePackSendEvent) SetProvidedResourcePack(pack ResourcePackInfo)
- type ShutdownEvent
- type TabCompleteEvent
Constants ¶
const ( // ChatMessageType is a standard chat message and // lets the chat message appear in the client's HUD. // These messages can be filtered out by the client's settings. ChatMessageType = packet.ChatMessageType // SystemMessageType is a system chat message. // e.g. client is willing to accept messages from commands, // but does not want general chat from other players. // It lets the chat message appear in the client's HUD and can't be dismissed. SystemMessageType = packet.SystemMessageType // GameInfoMessageType lets the chat message appear above the player's main HUD. // This text format doesn't support many component features, such as hover events. GameInfoMessageType = packet.GameInfoMessageType )
Chat message types.
Variables ¶
var ( ErrNoBackendConnection = errors.New("player has no backend server connection yet") ErrTooLongChatMessage = errors.New("server bound chat message can not exceed 256 characters") )
var ErrProxyAlreadyRun = errors.New("proxy was already run, create a new one")
ErrProxyAlreadyRun is returned by Proxy.Run if the proxy instance was already run.
var ErrServerAlreadyExists = errors.New("server already exists")
ErrServerAlreadyExists indicates that a server is already registered in ServerRegistrar.
var ErrServerOnlineMode = errors.New("backend server is online mode, but should be offline")
ErrServerOnlineMode indicates error in a ConnectionRequest when the backend server is in online mode.
var Plugins []Plugin
Plugins is used to register plugins with the proxy. The plugin's init hook is run after the proxy is initialized and before serving any connections.
If one init hook errors, the proxy cancels the boot and shuts down; will fire the ShutdownEvent so other plugins can gracefully de-initialize.
Functions ¶
func BroadcastMessage ¶ added in v0.19.1
func BroadcastMessage(sinks []MessageSink, msg component.Component)
BroadcastMessage broadcasts a message to all given sinks (e.g. Player).
func BroadcastPluginMessage ¶ added in v0.19.1
func BroadcastPluginMessage(sinks []message.ChannelMessageSink, identifier message.ChannelIdentifier, data []byte)
BroadcastPluginMessage sends the plugin message to all players on the server.
func PlayersToSlice ¶ added in v0.19.1
PlayersToSlice returns a slice of all players.
func RegisteredServerEqual ¶ added in v0.17.0
func RegisteredServerEqual(a, b RegisteredServer) bool
RegisteredServerEqual returns true if RegisteredServer a and b are equal. They are never equal if one of them is nil.
func ServerInfoEqual ¶ added in v0.17.0
func ServerInfoEqual(a, b ServerInfo) bool
ServerInfoEqual returns true if ServerInfo a and b are equal. They are never equal if one of them is nil.
func WithMessageSender ¶ added in v0.19.0
func WithMessageSender(id uuid.UUID) command.MessageOption
WithMessageSender modifies the sender identity of the chat message.
func WithMessageType ¶ added in v0.19.0
func WithMessageType(t MessageType) command.MessageOption
WithMessageType modifies chat message type.
Types ¶
type ChannelRegistrar ¶
type ChannelRegistrar struct {
// contains filtered or unexported fields
}
func NewChannelRegistrar ¶
func NewChannelRegistrar() *ChannelRegistrar
func (*ChannelRegistrar) ChannelsForProtocol ¶
func (r *ChannelRegistrar) ChannelsForProtocol(protocol proto.Protocol) sets.String
ChannelsForProtocol returns all the channel names to register depending on the Minecraft protocol version.
func (*ChannelRegistrar) FromID ¶
func (r *ChannelRegistrar) FromID(channel string) (message.ChannelIdentifier, bool)
func (*ChannelRegistrar) LegacyChannelIDs ¶
func (r *ChannelRegistrar) LegacyChannelIDs() sets.String
LegacyChannelIDs returns all legacy channel IDs.
func (*ChannelRegistrar) ModernChannelIDs ¶
func (r *ChannelRegistrar) ModernChannelIDs() sets.String
ModernChannelIDs returns all channel IDs (as strings) for use with Minecraft 1.13 and above.
type CommandExecuteEvent ¶
type CommandExecuteEvent struct {
// contains filtered or unexported fields
}
CommandExecuteEvent is fired when someone wants to execute a command.
func (*CommandExecuteEvent) Allowed ¶
func (c *CommandExecuteEvent) Allowed() bool
Allowed returns true when the command is allowed to be executed.
func (*CommandExecuteEvent) Command ¶
func (c *CommandExecuteEvent) Command() string
Command returns the whole commandline without the leading "/".
func (*CommandExecuteEvent) Forward ¶ added in v0.12.0
func (c *CommandExecuteEvent) Forward() bool
Forward returns true when the command should be forwarded to the server.
func (*CommandExecuteEvent) OriginalCommand ¶ added in v0.12.0
func (c *CommandExecuteEvent) OriginalCommand() string
OriginalCommand returns the original command if SetCommand has changed it.
func (*CommandExecuteEvent) SetAllowed ¶
func (c *CommandExecuteEvent) SetAllowed(allowed bool)
SetAllowed sets whether the command is allowed to be executed.
func (*CommandExecuteEvent) SetCommand ¶ added in v0.12.0
func (c *CommandExecuteEvent) SetCommand(commandline string)
SetCommand changes the command being executed without the leading "/".
func (*CommandExecuteEvent) SetForward ¶ added in v0.12.0
func (c *CommandExecuteEvent) SetForward(forward bool)
SetForward sets whether the command should be forwarded to the server.
func (*CommandExecuteEvent) Source ¶
func (c *CommandExecuteEvent) Source() command.Source
Source returns the command source that wants to run the command.
type ConnectionHandshakeEvent ¶
type ConnectionHandshakeEvent struct {
// contains filtered or unexported fields
}
ConnectionHandshakeEvent is fired when a handshake is established between a client and the proxy.
func (*ConnectionHandshakeEvent) Connection ¶
func (e *ConnectionHandshakeEvent) Connection() Inbound
Connection returns the inbound connection.
type ConnectionRequest ¶
type ConnectionRequest interface { // Server returns the server that this connection request is for. Server() RegisteredServer // Connect blocks, initiates the connection to the // remote Server and returns a result after the user has logged on // or an error when an error occurred (e.g. could not net.Dial the Server, ctx was canceled, etc.). // // The given Context can be used to cancel the connection initiation, but // has no effect if the connection was already established or canceled. // // No messages will be communicated to the client: // You are responsible for all error handling. Connect(ctx context.Context) (ConnectionResult, error) // ConnectWithIndication is the same as Connect, but the proxy's built-in // handling will be used to provide errors to the player and returns // true if the player was successfully connected. ConnectWithIndication(ctx context.Context) (successful bool) }
ConnectionRequest can send a connection request to another server on the proxy. A connection request is created using Player.CreateConnectionRequest(RegisteredServer).
type ConnectionResult ¶
type ConnectionResult interface { Status() ConnectionStatus // The connection result status. // Reason returns a reason for the failure to connect to the server. // It is nil if not provided. Reason() Component }
ConnectionResult is the result of a ConnectionRequest.
type ConnectionStatus ¶
type ConnectionStatus uint8
ConnectionStatus is the status for a ConnectionResult
const ( // SuccessConnectionStatus indicates that the player was successfully connected to the server. SuccessConnectionStatus ConnectionStatus = iota // AlreadyConnectedConnectionStatus indicates that the player is already connected to this server. AlreadyConnectedConnectionStatus // InProgressConnectionStatus indicates that a connection is already in progress. InProgressConnectionStatus // CanceledConnectionStatus indicates that a plugin has cancelled this connection. CanceledConnectionStatus // ServerDisconnectedConnectionStatus indicates that the server disconnected the player. // A reason MAY be provided in the ConnectionResult.Reason(). ServerDisconnectedConnectionStatus )
func (ConnectionStatus) AlreadyConnected ¶
func (r ConnectionStatus) AlreadyConnected() bool
AlreadyConnected id true if the player is already connected to this server.
func (ConnectionStatus) Canceled ¶
func (r ConnectionStatus) Canceled() bool
Canceled is true if a plugin has cancelled this connection.
func (ConnectionStatus) ConnectionInProgress ¶
func (r ConnectionStatus) ConnectionInProgress() bool
ConnectionInProgress is true if a connection is already in progress.
func (ConnectionStatus) ServerDisconnected ¶
func (r ConnectionStatus) ServerDisconnected() bool
ServerDisconnected is true if the server disconnected the player. A reason MAY be provided in the ConnectionResult.Reason().
func (ConnectionStatus) Successful ¶
func (r ConnectionStatus) Successful() bool
Successful is true if the player was successfully connected to the server.
type DisconnectEvent ¶
type DisconnectEvent struct {
// contains filtered or unexported fields
}
func (*DisconnectEvent) LoginStatus ¶
func (e *DisconnectEvent) LoginStatus() LoginStatus
func (*DisconnectEvent) Player ¶
func (e *DisconnectEvent) Player() Player
type DisconnectPlayerKickResult ¶
DisconnectPlayerKickResult is a ServerKickResult and tells the proxy to disconnect the player with the specified reason.
type GameProfileProvider ¶ added in v0.17.0
type GameProfileProvider interface {
GameProfile() (profile *profile.GameProfile)
}
GameProfileProvider provides the GameProfile for a player connection.
type GameProfileRequestEvent ¶
type GameProfileRequestEvent struct {
// contains filtered or unexported fields
}
GameProfileRequestEvent is fired after the PreLoginEvent in order to set up the game profile for the user. This can be used to configure a custom profile for a user, i.e. skin replacement.
func NewGameProfileRequestEvent ¶
func NewGameProfileRequestEvent( inbound Inbound, original profile.GameProfile, onlineMode bool, ) *GameProfileRequestEvent
func (*GameProfileRequestEvent) Conn ¶
func (e *GameProfileRequestEvent) Conn() Inbound
Conn returns the inbound connection that is connecting to the proxy.
func (*GameProfileRequestEvent) GameProfile ¶
func (e *GameProfileRequestEvent) GameProfile() profile.GameProfile
GameProfile returns the game profile that will be used to initialize the connection with. Should no profile be set, the original profile (given by the proxy) will be used.
func (*GameProfileRequestEvent) OnlineMode ¶
func (e *GameProfileRequestEvent) OnlineMode() bool
OnlineMode specifies whether the user connected in online/offline mode.
func (*GameProfileRequestEvent) Original ¶
func (e *GameProfileRequestEvent) Original() profile.GameProfile
Original returns the by the proxy created offline or online (Mojang authenticated) game profile.
func (*GameProfileRequestEvent) SetGameProfile ¶
func (e *GameProfileRequestEvent) SetGameProfile(p profile.GameProfile)
SetGameProfile sets the profile to use for this connection.
type HandshakeAddresser ¶ added in v0.17.0
type HandshakeAddresser interface {
HandshakeAddr(defaultPlayerVirtualHost string, player Player) (newPlayerVirtualHost string)
}
HandshakeAddresser provides the ServerAddress sent with the packet.Handshake when a player joins the server implementing this interface. A ServerInfo of a registered server or a RegisteredServer can implement this interface. If no ServerInfo or RegisteredServer implements this interface the ServerInfo.Addr the default ServerAddress is used or the BungeeCord forwarding scheme if the proxy is in cfg.LegacyForwardingMode.
type Inbound ¶
type Inbound interface { Protocol() proto.Protocol // The current protocol version the connection uses. VirtualHost() net.Addr // The hostname, the client sent us, to join the server, if applicable. RemoteAddr() net.Addr // The player's IP address. Active() bool // Whether the connection remains active. // Context returns the connection's context that can be used to know when the connection was closed. // (e.g. for canceling work in an event handler) Context() context.Context }
Inbound is an incoming connection to the proxy.
type KickedFromServerEvent ¶
type KickedFromServerEvent struct {
// contains filtered or unexported fields
}
Fired when a player is kicked from a server. You may either allow the proxy to kick the player (with an optional reason override) or redirect the player to a separate server. By default, the proxy will notify the user (if they are already connected to a server) or disconnect them (if they are not on a server and no other servers are available).
func (*KickedFromServerEvent) KickedDuringServerConnect ¶
func (e *KickedFromServerEvent) KickedDuringServerConnect() bool
KickedDuringServerConnect returns true if the player got kicked while connecting to another server.
func (*KickedFromServerEvent) OriginalReason ¶
func (e *KickedFromServerEvent) OriginalReason() component.Component
OriginalReason returns the reason the server kicked the player from the server. May return nil!
func (*KickedFromServerEvent) Player ¶
func (e *KickedFromServerEvent) Player() Player
Player returns the player that got kicked.
func (*KickedFromServerEvent) Result ¶
func (e *KickedFromServerEvent) Result() ServerKickResult
KickedDuringServerConnect returns current kick result. The proxy sets a default non-nil result but an event handler may has set it nil when handling the event.
func (*KickedFromServerEvent) Server ¶
func (e *KickedFromServerEvent) Server() RegisteredServer
Server returns the server the player got kicked from.
func (*KickedFromServerEvent) SetResult ¶
func (e *KickedFromServerEvent) SetResult(result ServerKickResult)
KickedDuringServerConnect sets the kick result.
type LoginEvent ¶
type LoginEvent struct {
// contains filtered or unexported fields
}
func (*LoginEvent) Allow ¶
func (e *LoginEvent) Allow()
func (*LoginEvent) Allowed ¶
func (e *LoginEvent) Allowed() bool
func (*LoginEvent) Deny ¶
func (e *LoginEvent) Deny(reason component.Component)
func (*LoginEvent) Player ¶
func (e *LoginEvent) Player() Player
func (*LoginEvent) Reason ¶
func (e *LoginEvent) Reason() component.Component
Is nil if Allowed() returns true
type LoginPhaseConnection ¶ added in v0.19.0
type LoginPhaseConnection interface { Inbound crypto.KeyIdentifiable SendLoginPluginMessage(identifier message.ChannelIdentifier, contents []byte, consumer MessageConsumer) error }
LoginPhaseConnection allows the server to communicate with a client logging into the proxy using login plugin messages.
type LoginStatus ¶
type LoginStatus uint8
const ( SuccessfulLoginStatus LoginStatus = iota ConflictingLoginStatus CanceledByUserLoginStatus CanceledByProxyLoginStatus CanceledByUserBeforeCompleteLoginStatus )
type MessageConsumer ¶ added in v0.19.0
type MessageSink ¶ added in v0.19.1
type MessageSink interface { // SendMessage sends a message component to the entity. SendMessage(msg component.Component, opts ...command.MessageOption) error }
MessageSink is a message sink.
type MessageType ¶ added in v0.13.0
type MessageType = packet.MessageType
MessageType is a chat message type.
type NotifyKickResult ¶
NotifyKickResult is ServerKickResult and notifies the player with the specified message but does nothing else. This is only a valid result to use if the player was trying to connect to a different server, otherwise it is treated like a DisconnectPlayerKickResult result.
type Options ¶
type Options struct { // Config requires configuration // validated by cfg.Validate. Config *config.Config // The event manager to use. // If none is set, no events are sent. EventMgr event.Manager // Authenticator to authenticate users in online mode. // If not set, creates a default one. Authenticator auth.Authenticator }
Options are the options for a new Java edition Proxy.
type PermissionsSetupEvent ¶
type PermissionsSetupEvent struct {
// contains filtered or unexported fields
}
PermissionsSetupEvent is fired once a permission.Subject's permissions are being initialized.
func (*PermissionsSetupEvent) Func ¶
func (p *PermissionsSetupEvent) Func() permission.Func
Func returns the permission.Func used for the subject.
func (*PermissionsSetupEvent) SetFunc ¶
func (p *PermissionsSetupEvent) SetFunc(fn permission.Func)
SetFunc sets the permission.Func usec for the subject. If fn is nil, the default Func fill be used.
func (*PermissionsSetupEvent) Subject ¶
func (p *PermissionsSetupEvent) Subject() permission.Subject
Subject returns the subject the permissions are setup for.
type PingEvent ¶
type PingEvent struct {
// contains filtered or unexported fields
}
PingEvent is fired when a request for server information is sent by a remote client, or when the server sends the MOTD and favicon to the client after a successful login. The proxy will wait on this event to finish firing before delivering the results to the remote client, but you are urged to handle this event as quickly as possible when handling this event due to the amount of ping packets a client can send.
func (*PingEvent) Connection ¶
Connection returns the inbound connection.
func (*PingEvent) Ping ¶
func (p *PingEvent) Ping() *ping.ServerPing
Ping returns the used ping. (pre-initialized by the proxy)
func (*PingEvent) SetPing ¶
func (p *PingEvent) SetPing(ping *ping.ServerPing)
SetPing sets the ping response to use.
type Player ¶
type Player interface { Inbound command.Source message.ChannelMessageSource message.ChannelMessageSink crypto.KeyIdentifiable ID() uuid.UUID // The Minecraft ID of the player. Username() string // The username of the player. // CurrentServer returns the current server connection of the player. CurrentServer() ServerConnection // May be nil, if there is no backend server connection! Ping() time.Duration // The player's ping or -1 if currently unknown. OnlineMode() bool // Whether the player was authenticated with Mojang's session servers. // CreateConnectionRequest creates a connection request to begin switching the backend server. CreateConnectionRequest(target RegisteredServer) ConnectionRequest GameProfile() profile.GameProfile // Returns the player's game profile. Settings() player.Settings // The player's client settings. Returns player.DefaultSettings if unknown. // Disconnect disconnects the player with a reason. // Once called, further interface calls to this player become undefined. Disconnect(reason component.Component) // SpoofChatInput sends chats input onto the player's current server as if // they typed it into the client chat box. SpoofChatInput(input string) error // SendResourcePack sends the specified resource pack from url to the user. // If at all possible, specify an 20-byte SHA-1 hash of the resource pack file. // To monitor the status of the sent resource pack, subscribe to PlayerResourcePackStatusEvent. SendResourcePack(info ResourcePackInfo) error // SendActionBar sends an action bar to the player. SendActionBar(msg component.Component) error TabList() tablist.TabList // Returns the player's tab list. }
Player is a connected Minecraft player.
type PlayerAvailableCommandsEvent ¶ added in v0.12.0
type PlayerAvailableCommandsEvent struct {
// contains filtered or unexported fields
}
PlayerAvailableCommandsEvent allows plugins to modify the packet indicating commands available on the server to a Minecraft 1.13+ client.
func (*PlayerAvailableCommandsEvent) Player ¶ added in v0.12.0
func (p *PlayerAvailableCommandsEvent) Player() Player
Player returns the player that is about to see the available commands.
func (*PlayerAvailableCommandsEvent) RootNode ¶ added in v0.12.0
func (p *PlayerAvailableCommandsEvent) RootNode() *brigodier.RootCommandNode
RootNode returns the available commands to the Player.
type PlayerChannelRegisterEvent ¶ added in v0.19.0
type PlayerChannelRegisterEvent struct {
// contains filtered or unexported fields
}
PlayerChannelRegisterEvent is fired when a client Player sends a plugin message through the register channel. The proxy will not wait on this event to finish firing.
func (*PlayerChannelRegisterEvent) Channels ¶ added in v0.19.0
func (e *PlayerChannelRegisterEvent) Channels() []message.ChannelIdentifier
func (*PlayerChannelRegisterEvent) Player ¶ added in v0.19.0
func (e *PlayerChannelRegisterEvent) Player() Player
type PlayerChatEvent ¶
type PlayerChatEvent struct {
// contains filtered or unexported fields
}
PlayerChatEvent is fired when a player sends a chat message. Note that messages with a leading "/" do not trigger this event, but instead CommandExecuteEvent.
func (*PlayerChatEvent) Allowed ¶
func (c *PlayerChatEvent) Allowed() bool
Allowed returns true when the chat message is allowed.
func (*PlayerChatEvent) Message ¶
func (c *PlayerChatEvent) Message() string
Message returns the message that will be sent by the player.
func (*PlayerChatEvent) Original ¶ added in v0.19.0
func (c *PlayerChatEvent) Original() string
Original returns the original message the player sent.
func (*PlayerChatEvent) Player ¶
func (c *PlayerChatEvent) Player() Player
Player returns the player that sent the message.
func (*PlayerChatEvent) SetAllowed ¶
func (c *PlayerChatEvent) SetAllowed(allowed bool)
SetAllowed sets whether the chat message is allowed.
func (*PlayerChatEvent) SetMessage ¶ added in v0.19.0
func (c *PlayerChatEvent) SetMessage(msg string)
SetMessage modifies the message of the player.
type PlayerChooseInitialServerEvent ¶
type PlayerChooseInitialServerEvent struct {
// contains filtered or unexported fields
}
PlayerChooseInitialServerEvent is fired when a player has finished the login process, and we need to choose the first server to connect to. The proxy will wait on this event to finish firing before initiating the connection but you should try to limit the work done in this event. Failures will be handled by KickedFromServerEvent as normal.
func (*PlayerChooseInitialServerEvent) InitialServer ¶
func (e *PlayerChooseInitialServerEvent) InitialServer() RegisteredServer
InitialServer returns the initial server or nil if no server is configured.
func (*PlayerChooseInitialServerEvent) Player ¶
func (e *PlayerChooseInitialServerEvent) Player() Player
Player returns the player to find the initial server for.
func (*PlayerChooseInitialServerEvent) SetInitialServer ¶
func (e *PlayerChooseInitialServerEvent) SetInitialServer(server RegisteredServer)
SetInitialServer sets the initial server for the player.
type PlayerModInfoEvent ¶
type PlayerModInfoEvent struct {
// contains filtered or unexported fields
}
PlayerModInfoEvent is fired when a Forge client sends its mods to the proxy while connecting to a server.
func (*PlayerModInfoEvent) ModInfo ¶
func (e *PlayerModInfoEvent) ModInfo() modinfo.ModInfo
ModInfo is the mod info received by the player.
func (*PlayerModInfoEvent) Player ¶
func (e *PlayerModInfoEvent) Player() Player
Player returns the player who sent the mod info.
type PlayerResourcePackStatusEvent ¶ added in v0.19.0
type PlayerResourcePackStatusEvent struct {
// contains filtered or unexported fields
}
PlayerResourcePackStatusEvent is fired when the status of a resource pack sent to the player by the server is changed. Depending on the result of this event (which the proxy will wait until completely fired), the player may be kicked from the server.
func (*PlayerResourcePackStatusEvent) OverwriteKick ¶ added in v0.19.0
func (p *PlayerResourcePackStatusEvent) OverwriteKick() bool
OverwriteKick returns whether to override the kick resulting from ResourcePackInfo.ShouldForce() being true.
func (*PlayerResourcePackStatusEvent) PackInfo ¶ added in v0.19.0
func (p *PlayerResourcePackStatusEvent) PackInfo() ResourcePackInfo
PackInfo returns the ResourcePackInfo this response is for.
func (*PlayerResourcePackStatusEvent) Player ¶ added in v0.19.0
func (p *PlayerResourcePackStatusEvent) Player() Player
Player returns the player affected by the change in resource pack status.
func (*PlayerResourcePackStatusEvent) SetOverwriteKick ¶ added in v0.19.0
func (p *PlayerResourcePackStatusEvent) SetOverwriteKick(overwriteKick bool)
SetOverwriteKick can set to true to prevent ResourcePackInfo.ShouldForce() from kicking the player. Overwriting this kick is only possible on versions older than 1.17, as the client or server will enforce this regardless. Cancelling the resulting kick-events will not prevent the player from disconnecting from the proxy.
func (*PlayerResourcePackStatusEvent) Status ¶ added in v0.19.0
func (p *PlayerResourcePackStatusEvent) Status() ResourcePackResponseStatus
Status returns the new status for the resource pack.
type PlayerSettingsChangedEvent ¶
type PlayerSettingsChangedEvent struct {
// contains filtered or unexported fields
}
func (*PlayerSettingsChangedEvent) Player ¶
func (s *PlayerSettingsChangedEvent) Player() Player
Player returns the player whose settings where updates/initialized.
func (*PlayerSettingsChangedEvent) Settings ¶
func (s *PlayerSettingsChangedEvent) Settings() player.Settings
Settings returns player's new settings.
type Players ¶
type Players interface { Len() int // Returns the size of the player list. Range(func(p Player) bool) // Loops through the players, breaks if func returns false. }
Players is a list of players safe for concurrent use.
type Plugin ¶
type Plugin struct { Name string // The name identifying the plugin. Init func(proxy *Proxy) error // The hook to initialize the plugin. }
Plugin provides the ability to extend Gate with external code.
Quick notes on Go's plugin system:
We don't support Go's plugin system as it is not a mature solution. They force your plugin implementation to be highly-coupled with Gate's build toolchain, the end-result would be very brittle, hard to maintain and the overhead would be much higher if the plugin author does not have any control over new versions of Gate.
Now with that made clear, here is how Gate can be customized!
Native Go:
You can use Gate as a framework and compile your code with it. ¶
- Create your own Go project/module and `go get -u go.minekube.com/gate`
- Within your main function
- Add your Plugin to the Plugins
- And call cmd/gate.Execute (blocking your main until shutdown).
- Subscribe to proxy.ShutdownEvent for de-initializing your plugin.
By running cmd/gate.Execute, Gate will do the whole rest.
- load the cfg (parse found file, flags and env vars)
- make and run the proxy.Proxy that will call the Plugins init hooks.
Script languages:
- Not yet supported.
type PluginMessageEvent ¶
type PluginMessageEvent struct {
// contains filtered or unexported fields
}
PluginMessageEvent is fired when a plugin message is sent to the proxy, either from a player or a server backend server.
func (*PluginMessageEvent) Allowed ¶
func (p *PluginMessageEvent) Allowed() bool
func (*PluginMessageEvent) Data ¶
func (p *PluginMessageEvent) Data() []byte
func (*PluginMessageEvent) Identifier ¶
func (p *PluginMessageEvent) Identifier() message.ChannelIdentifier
func (*PluginMessageEvent) SetForward ¶
func (p *PluginMessageEvent) SetForward(forward bool)
func (*PluginMessageEvent) Source ¶
func (p *PluginMessageEvent) Source() message.ChannelMessageSource
func (*PluginMessageEvent) Target ¶
func (p *PluginMessageEvent) Target() message.ChannelMessageSink
type PostLoginEvent ¶
type PostLoginEvent struct {
// contains filtered or unexported fields
}
func (*PostLoginEvent) Player ¶
func (e *PostLoginEvent) Player() Player
type PreLoginEvent ¶
type PreLoginEvent struct {
// contains filtered or unexported fields
}
func (*PreLoginEvent) Allow ¶
func (e *PreLoginEvent) Allow()
func (*PreLoginEvent) Conn ¶
func (e *PreLoginEvent) Conn() Inbound
func (*PreLoginEvent) Deny ¶
func (e *PreLoginEvent) Deny(reason component.Component)
func (*PreLoginEvent) ForceOfflineMode ¶
func (e *PreLoginEvent) ForceOfflineMode()
func (*PreLoginEvent) ForceOnlineMode ¶
func (e *PreLoginEvent) ForceOnlineMode()
func (*PreLoginEvent) Reason ¶
func (e *PreLoginEvent) Reason() component.Component
Reason returns the deny reason to disconnect the connection. May be nil!
func (*PreLoginEvent) Result ¶
func (e *PreLoginEvent) Result() PreLoginResult
func (*PreLoginEvent) Username ¶
func (e *PreLoginEvent) Username() string
type PreLoginResult ¶
type PreLoginResult uint8
const ( AllowedPreLogin PreLoginResult = iota DeniedPreLogin ForceOnlineModePreLogin ForceOfflineModePreLogin )
type PreShutdownEvent ¶
type PreShutdownEvent struct {
// contains filtered or unexported fields
}
PreShutdownEvent is fired before the proxy begins to shut down by stopping to accept new connections and disconnect all players.
func (*PreShutdownEvent) Reason ¶
func (s *PreShutdownEvent) Reason() component.Component
Reason returns the shutdown reason used to disconnect players with. May be nil!
func (*PreShutdownEvent) SetReason ¶
func (s *PreShutdownEvent) SetReason(reason component.Component)
SetReason sets the shutdown reason used to disconnect players with.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is Gate's Java edition Minecraft proxy.
func (*Proxy) ChannelRegistrar ¶
func (p *Proxy) ChannelRegistrar() *ChannelRegistrar
func (*Proxy) DisconnectAll ¶
DisconnectAll disconnects all current connected players in parallel and waits until all players have been disconnected.
func (*Proxy) HandleConn ¶ added in v0.17.0
HandleConn handles a just-accepted client connection that has not had any I/O performed on it yet.
func (*Proxy) Player ¶
Player returns the online player by their Minecraft id. Returns nil if the player was not found.
func (*Proxy) PlayerByName ¶
PlayerByName returns the online player by their Minecraft name (search is case-insensitive). Returns nil if the player was not found.
func (*Proxy) PlayerCount ¶
PlayerCount returns the number of players on the proxy.
func (*Proxy) Register ¶
func (p *Proxy) Register(info ServerInfo) (RegisteredServer, error)
Register - See ServerRegistrar
func (*Proxy) Server ¶
func (p *Proxy) Server(name string) RegisteredServer
Server gets a backend server registered with the proxy by name. Returns nil if not found.
func (*Proxy) Servers ¶
func (p *Proxy) Servers() []RegisteredServer
Servers gets all registered servers.
func (*Proxy) Shutdown ¶
Shutdown stops the Proxy and/or blocks until the Proxy has finished shutdown.
It first stops listening for new connections, disconnects all existing connections with the given reason (nil = blank reason) and waits for all event subscribers to finish.
func (*Proxy) Start ¶
Start runs the Java edition Proxy, blocks until the proxy is Shutdown or an error occurred while starting. The Proxy is already shutdown on method return. Another method of stopping the Proxy is to call Shutdown. A Proxy can only be run once or ErrProxyAlreadyRun is returned.
func (*Proxy) Unregister ¶
func (p *Proxy) Unregister(info ServerInfo) bool
Unregister unregisters the server exactly matching the given ServerInfo and returns true if found.
type ReadyEvent ¶
type ReadyEvent struct{}
ReadyEvent is fired once the proxy was successfully initialized and is ready to serve connections.
type RedirectPlayerKickResult ¶
type RedirectPlayerKickResult struct { Server RegisteredServer // The new server to redirect the kicked player to. Message component.Component // Optional message sent to the player after redirecting. }
RedirectPlayerKickResult is a ServerKickResult and tells the proxy to redirect the player to another server.
type RegisteredServer ¶
type RegisteredServer interface { ServerInfo() ServerInfo Players() Players // The players connected to the server on THIS proxy. }
RegisteredServer is a backend server that has been registered with the proxy.
type ResourcePackInfo ¶ added in v0.19.0
type ResourcePackInfo struct { // The download link the resource-pack can be found at. URL string // The SHA-1 hash of the provided resource pack. // // Note: It is recommended to always set this hash. // If this hash is not set/not present then the client will always download // the resource pack even if it may still be cached. By having this hash present, // the client will check first whether a resource pack by this hash is cached // before downloading. Hash []byte // Whether the acceptance of the resource-pack is enforced. // // Sets the resource-pack as required to play on the network. // This feature was introduced in 1.17. // Setting this to true has one of two effects: // If the client is on 1.17 or newer: // - The resource-pack prompt will display without a decline button // - Accept or disconnect are the only available options but players may still press escape. // - Forces the resource-pack offer prompt to display even if the player has // previously declined or disabled resource packs // - The player will be disconnected from the network if they close/skip the prompt. // If the client is on a version older than 1.17: // - If the player accepts the resource pack or has previously accepted a resource-pack // then nothing else will happen. // - If the player declines the resource pack or has previously declined a resource-pack // the player will be disconnected from the network ShouldForce bool // The optional message that is displayed on the resource-pack prompt. // This is only displayed if the client version is 1.17 or newer. Prompt component.Component Origin ResourcePackOrigin // The origin of the resource-pack. }
ResourcePackInfo is resource-pack options for Player.SendResourcePack.
type ResourcePackOrigin ¶ added in v0.19.0
type ResourcePackOrigin byte
ResourcePackOrigin represents the origin of the resource-pack.
const ( DownstreamServerResourcePackOrigin ResourcePackOrigin = iota PluginOnProxyResourcePackOrigin )
type ResourcePackResponseStatus ¶ added in v0.19.0
type ResourcePackResponseStatus = packet.ResourcePackResponseStatus
ResourcePackResponseStatus is the status for a resource pack.
const ( SuccessfulResourcePackResponseStatus ResourcePackResponseStatus = packet.SuccessfulResourcePackResponseStatus DeclinedResourcePackResponseStatus ResourcePackResponseStatus = packet.DeclinedResourcePackResponseStatus FailedDownloadResourcePackResponseStatus ResourcePackResponseStatus = packet.FailedDownloadResourcePackResponseStatus AcceptedResourcePackResponseStatus ResourcePackResponseStatus = packet.AcceptedResourcePackResponseStatus )
Possible statuses for a resource pack.
type ServerConnectedEvent ¶
type ServerConnectedEvent struct {
// contains filtered or unexported fields
}
ServerConnectedEvent is fired before the player completely transitions to the target server and the connection to the previous server has been de-established.
Use Server to get the target server since Player.CurrentServer is yet nil or listen for ServerPostConnectEvent instead.
func (*ServerConnectedEvent) Player ¶
func (s *ServerConnectedEvent) Player() Player
Player returns the associated player.
func (*ServerConnectedEvent) PreviousServer ¶
func (s *ServerConnectedEvent) PreviousServer() RegisteredServer
PreviousServer returns the server the player was previously connected to. May return nil if there was none!
func (*ServerConnectedEvent) Server ¶
func (s *ServerConnectedEvent) Server() RegisteredServer
Server returns the server the player connected to.
type ServerConnection ¶
type ServerConnection interface { message.ChannelMessageSink message.ChannelMessageSource Server() RegisteredServer // Returns the server that this connection is connected to. Player() Player // Returns the player that this connection is associated with. }
ServerConnection is a connection to a backend server from the proxy for a client.
type ServerDialer ¶ added in v0.17.0
ServerDialer provides the server connection for a joining player. A ServerInfo of a registered server or a RegisteredServer can implement this interface to provide custom connection establishment when a player wants to join a server. If no ServerInfo or RegisteredServer implements this interface the ServerInfo.Addr is used to dial the server using tcp.
type ServerInfo ¶
type ServerInfo interface { Name() string // Returns the server name. Addr() net.Addr // Returns the server address. }
ServerInfo is the info of a backend server.
func NewServerInfo ¶
func NewServerInfo(name string, addr net.Addr) ServerInfo
type ServerKickResult ¶
type ServerKickResult interface {
// contains filtered or unexported methods
}
ServerKickResult is the result of a KickedFromServerEvent and is implemented by
DisconnectPlayerKickResult ¶
RedirectPlayerKickResult ¶
NotifyKickResult
type ServerLoginPluginMessageEvent ¶ added in v0.19.0
type ServerLoginPluginMessageEvent struct {
// contains filtered or unexported fields
}
ServerLoginPluginMessageEvent is fired when a server sends a login plugin message to the proxy. Plugins have the opportunity to respond to the messages as needed. The proxy will wait on this event to finish. The server will be responsible for continuing the login process once the server is satisfied with any login plugin responses sent by proxy plugins (or messages indicating a lack of response).
func (*ServerLoginPluginMessageEvent) Contents ¶ added in v0.19.0
func (e *ServerLoginPluginMessageEvent) Contents() []byte
Contents returns the contents of the login plugin message sent by the server.
func (*ServerLoginPluginMessageEvent) Result ¶ added in v0.19.0
func (e *ServerLoginPluginMessageEvent) Result() *ServerLoginPluginMessageResult
func (*ServerLoginPluginMessageEvent) SequenceID ¶ added in v0.19.0
func (e *ServerLoginPluginMessageEvent) SequenceID() int
SequenceID returns the sequence id of the login plugin message sent by the server.
type ServerLoginPluginMessageResult ¶ added in v0.19.0
type ServerLoginPluginMessageResult struct {
Response []byte
}
func (*ServerLoginPluginMessageResult) Allowed ¶ added in v0.19.0
func (r *ServerLoginPluginMessageResult) Allowed() bool
func (*ServerLoginPluginMessageResult) Copy ¶ added in v0.19.0
func (r *ServerLoginPluginMessageResult) Copy() []byte
func (*ServerLoginPluginMessageResult) Reply ¶ added in v0.19.0
func (r *ServerLoginPluginMessageResult) Reply(response []byte) *ServerLoginPluginMessageResult
type ServerPostConnectEvent ¶
type ServerPostConnectEvent struct {
// contains filtered or unexported fields
}
ServerPostConnectEvent is fired after the player has connected to a server. The server the player is now connected to is available in Player().CurrentServer().
func (*ServerPostConnectEvent) Player ¶
func (s *ServerPostConnectEvent) Player() Player
Player returns the associated player.
func (*ServerPostConnectEvent) PreviousServer ¶
func (s *ServerPostConnectEvent) PreviousServer() RegisteredServer
PreviousServer returns the server the player was previously connected to. May return nil if there was none!
type ServerPreConnectEvent ¶
type ServerPreConnectEvent struct {
// contains filtered or unexported fields
}
ServerPreConnectEvent is fired before the player connects to a server.
func (*ServerPreConnectEvent) Allow ¶
func (e *ServerPreConnectEvent) Allow(server RegisteredServer)
Allow the player to connect to the specified server.
func (*ServerPreConnectEvent) Allowed ¶
func (e *ServerPreConnectEvent) Allowed() bool
Allowed returns true whether the connection is allowed.
func (*ServerPreConnectEvent) Deny ¶
func (e *ServerPreConnectEvent) Deny()
Deny will cancel the player to connect to another server.
func (*ServerPreConnectEvent) OriginalServer ¶
func (e *ServerPreConnectEvent) OriginalServer() RegisteredServer
OriginalServer returns the server that the player originally tried to connect to. To get the server the player will connect to, see the Server() of this event. To get the server the player is currently on when this event is fired, use Player.getCurrentServer().
func (*ServerPreConnectEvent) Player ¶
func (e *ServerPreConnectEvent) Player() Player
Player returns the player that tries to connect to another server.
func (*ServerPreConnectEvent) Server ¶
func (e *ServerPreConnectEvent) Server() RegisteredServer
Server returns the server the player will connect to OR nil if Allowed() returns false.
type ServerRegistrar ¶ added in v0.17.0
type ServerRegistrar interface { // Register registers a server with the proxy and returns it. // If the there is already a server with the same info // error ErrServerAlreadyExists is returned and the already registered server. Register(info ServerInfo) (RegisteredServer, error) // Unregister unregisters the server exactly matching the // given ServerInfo and returns true if found. Unregister(info ServerInfo) bool }
ServerRegistrar is used to register servers.
type ServerRegistry ¶ added in v0.17.0
type ServerRegistry interface { // Server gets a registered server by name or returns nil if not found. Server(name string) RegisteredServer ServerRegistrar }
ServerRegistry is used to retrieve registered servers that players can connect to.
type ServerResourcePackSendEvent ¶ added in v0.19.0
type ServerResourcePackSendEvent struct {
// contains filtered or unexported fields
}
ServerResourcePackSendEvent is fired when the downstream server tries to send a player a ResourcePack packet. The proxy will wait on this event to finish before forwarding the resource pack to the user. If this event is denied, it will retroactively send a DENIED status to the downstream server in response. If the downstream server has it set to "forced" it will forcefully disconnect the user.
func (*ServerResourcePackSendEvent) Allowed ¶ added in v0.19.0
func (e *ServerResourcePackSendEvent) Allowed() bool
Allowed indicated whether sending the resource pack to the client is allowed.
func (*ServerResourcePackSendEvent) ProvidedResourcePack ¶ added in v0.19.0
func (e *ServerResourcePackSendEvent) ProvidedResourcePack() ResourcePackInfo
ProvidedResourcePack returns the resource pack provided to the client if allowed.
func (*ServerResourcePackSendEvent) ReceivedResourcePack ¶ added in v0.19.0
func (e *ServerResourcePackSendEvent) ReceivedResourcePack() ResourcePackInfo
ReceivedResourcePack returns the resource pack send by the server.
func (*ServerResourcePackSendEvent) ServerConnection ¶ added in v0.19.0
func (e *ServerResourcePackSendEvent) ServerConnection() ServerConnection
ServerConnection returns the associated server connection.
func (*ServerResourcePackSendEvent) SetAllowed ¶ added in v0.19.0
func (e *ServerResourcePackSendEvent) SetAllowed(allowed bool)
SetAllowed allows or denies sending the resource pack to the client.
func (*ServerResourcePackSendEvent) SetProvidedResourcePack ¶ added in v0.19.0
func (e *ServerResourcePackSendEvent) SetProvidedResourcePack(pack ResourcePackInfo)
SetProvidedResourcePack sets the resource pack provided to the client if allowed.
type ShutdownEvent ¶
type ShutdownEvent struct{}
ShutdownEvent is fired by the proxy after the proxy has stopped accepting connections and PreShutdownEvent, but before the proxy process exits.
Subscribe to this event to gracefully stop any subtasks, such as plugin dependencies.
type TabCompleteEvent ¶ added in v0.12.0
type TabCompleteEvent struct {
// contains filtered or unexported fields
}
TabCompleteEvent is fired after a tab complete response is sent by the remote server, for clients on1.12.2 and below. You have the opportunity to modify the response sent to the remote player.
func (*TabCompleteEvent) PartialMessage ¶ added in v0.12.0
func (t *TabCompleteEvent) PartialMessage() string
PartialMessage returns the message being partially completed.
func (*TabCompleteEvent) Player ¶ added in v0.12.0
func (t *TabCompleteEvent) Player() Player
Player returns the player requesting the tab completion.
func (*TabCompleteEvent) SetSuggestions ¶ added in v0.12.0
func (t *TabCompleteEvent) SetSuggestions(s []string)
SetSuggestions sets the suggestions provided to the user.
func (*TabCompleteEvent) Suggestions ¶ added in v0.12.0
func (t *TabCompleteEvent) Suggestions() []string
Suggestions returns all the suggestions provided to the user, as a mutable list.
Source Files ¶
- builtin_cmd_glist.go
- builtin_cmd_server.go
- builtin_commands.go
- bungee.go
- doc.go
- events.go
- login_inbound.go
- player.go
- plugin.go
- proxy.go
- server.go
- session_backend_login.go
- session_backend_play.go
- session_backend_transition.go
- session_client_play.go
- session_handshake.go
- session_initial_connect.go
- session_initial_login.go
- session_status.go
- sesssion_auth.go
- switch.go