Documentation ¶
Overview ¶
Package proxy is a minetest reverse proxy for multiple servers. It also provides an API for plugins.
Index ¶
- Variables
- func AddServer(name string, s Server) bool
- func Banned(addr *net.UDPAddr) bool
- func BuildPlugin() error
- func ChatCmdExists(name string) bool
- func ChatCmds() map[string]ChatCmd
- func Clts() map[*ClientConn]struct{}
- func Colorize(text, color string) string
- func FallbackServers(server string) []string
- func LoadConfig() error
- func Path(path ...string) string
- func Players() map[string]struct{}
- func RegisterChatCmd(cmd ChatCmd) bool
- func RegisterInteractionHandler(handler InteractionHandler)
- func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]string) string) string
- func RmServer(name string) bool
- func Run()
- func Unban(id string) error
- func Uptime() time.Duration
- func Version() (string, error)
- type AuthBackend
- type AuthFiles
- func (a AuthFiles) Ban(addr, name string) error
- func (a AuthFiles) Banned(addr *net.UDPAddr) bool
- func (a AuthFiles) Exists(name string) bool
- func (a AuthFiles) Export() ([]User, error)
- func (a AuthFiles) ExportBans() ([]Ban, error)
- func (a AuthFiles) Import(in []User) error
- func (a AuthFiles) ImportBans(in []Ban) error
- func (a AuthFiles) LastSrv(name string) (string, error)
- func (a AuthFiles) Passwd(name string) (salt, verifier []byte, err error)
- func (a AuthFiles) SetLastSrv(name, srv string) error
- func (a AuthFiles) SetPasswd(name string, salt, verifier []byte) error
- func (a AuthFiles) Timestamp(name string) (time.Time, error)
- func (a AuthFiles) Unban(id string) error
- type AuthMTPostgreSQL
- func (a *AuthMTPostgreSQL) Ban(addr, name string) error
- func (a *AuthMTPostgreSQL) Banned(addr *net.UDPAddr) bool
- func (a *AuthMTPostgreSQL) Close() error
- func (a *AuthMTPostgreSQL) Exists(name string) bool
- func (a *AuthMTPostgreSQL) Export() ([]User, error)
- func (a *AuthMTPostgreSQL) ExportBans() ([]Ban, error)
- func (a *AuthMTPostgreSQL) Import(in []User) error
- func (a *AuthMTPostgreSQL) ImportBans(in []Ban) error
- func (a *AuthMTPostgreSQL) LastSrv(_ string) (string, error)
- func (a *AuthMTPostgreSQL) Passwd(name string) (salt, verifier []byte, err error)
- func (a *AuthMTPostgreSQL) SetLastSrv(_, _ string) error
- func (a *AuthMTPostgreSQL) SetPasswd(name string, salt, verifier []byte) error
- func (a *AuthMTPostgreSQL) Timestamp(name string) (time.Time, error)
- func (a *AuthMTPostgreSQL) Unban(id string) error
- type AuthMTSQLite3
- func (a *AuthMTSQLite3) Ban(addr, name string) error
- func (a *AuthMTSQLite3) Banned(addr *net.UDPAddr) bool
- func (a *AuthMTSQLite3) Close() error
- func (a *AuthMTSQLite3) Exists(name string) bool
- func (a *AuthMTSQLite3) Export() ([]User, error)
- func (a *AuthMTSQLite3) ExportBans() ([]Ban, error)
- func (a *AuthMTSQLite3) Import(in []User) error
- func (a *AuthMTSQLite3) ImportBans(in []Ban) error
- func (a *AuthMTSQLite3) LastSrv(_ string) (string, error)
- func (a *AuthMTSQLite3) Passwd(name string) (salt, verifier []byte, err error)
- func (a *AuthMTSQLite3) SetLastSrv(_, _ string) error
- func (a *AuthMTSQLite3) SetPasswd(name string, salt, verifier []byte) error
- func (a *AuthMTSQLite3) Timestamp(name string) (time.Time, error)
- func (a *AuthMTSQLite3) Unban(id string) error
- type Ban
- type ChatCmd
- type ClientConn
- func (cc *ClientConn) Ban() error
- func (cc *ClientConn) DoChatMsg(msg string)
- func (cc *ClientConn) HasPerms(want ...string) bool
- func (cc *ClientConn) Hop(serverName string) (err error)
- func (cc *ClientConn) HopGroup(groupName string) error
- func (cc *ClientConn) HopRaw(serverName string) error
- func (cc *ClientConn) Init() <-chan struct{}
- func (cc *ClientConn) Kick(reason string)
- func (cc *ClientConn) Log(dir string, v ...interface{})
- func (cc *ClientConn) Name() string
- func (cc *ClientConn) Perms() []string
- func (cc *ClientConn) SendChatMsg(msg ...string)
- func (cc *ClientConn) ServerName() string
- type Config
- func (cnf Config) DefaultServer() Server
- func (cnf Config) DefaultServerInfo() (string, Server)
- func (cnf Config) DefaultServerName() string
- func (cnf Config) Pools() map[string]map[string]Server
- func (cnf Config) RandomGroupServer(search string) (string, bool)
- func (cnf Config) ServerGroups() map[string]map[string]Server
- type Interaction
- type InteractionHandler
- type LogWriter
- type Server
- type ServerConn
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthBackendExists = errors.New("auth backend already set") ErrInvalidSRPHeader = errors.New("encoded password is not SRP") ErrLastSrvNotSupported = errors.New("auth backend does not support server information") )
var ( ErrNoServerConn = errors.New("no server connection") ErrNoSuchServer = errors.New("inexistent server") ErrNewMediaPool = errors.New("media pool unknown to client") )
var ChatCmdTimeout = 10 * time.Second
ChatCmdTimeout is the time needed until a user is warned about a chat command that's taking long to execute.
var ErrNoBuildInfo = errors.New("unable to retrieve proxy version: no build info")
Functions ¶
func AddServer ¶
AddServer dynamically configures a new Server at runtime. Servers added in this way are ephemeral and will be lost when the proxy shuts down. The server must be part of a media pool with at least one other member. At least one of the other members always needs to be reachable. WARNING: Reloading the config will not overwrite servers added using this function. The server definition from the configuration file will silently be ignored.
func BuildPlugin ¶
func BuildPlugin() error
func ChatCmdExists ¶
ChatCmdExists reports if a ChatCmd exists.
func Clts ¶
func Clts() map[*ClientConn]struct{}
Clts returns all ClientConns currently connected to the proxy.
func FallbackServers ¶
FallbackServers returns a slice of server names that a server can fall back to.
func LoadConfig ¶
func LoadConfig() error
LoadConfig attempts to parse the configuration file. It leaves the config unchanged if there is an error and returns the error.
func Path ¶
Path prepends the directory the executable is in to the given path. It follows symlinks to the executable.
func Players ¶
func Players() map[string]struct{}
Players returns the names of all players that are currently connected to the proxy.
func RegisterChatCmd ¶
RegisterChatCmd adds a new ChatCmd. It returns true on success and false if a command with the same name already exists.
func RegisterInteractionHandler ¶
func RegisterInteractionHandler(handler InteractionHandler)
RegisterInteractionHandler adds a new InteractionHandler.
func RmServer ¶
RmServer deletes a Server from the Config at runtime. Only servers added using AddServer can be deleted at runtime. Returns true on success or if the server doesn't exist.
func Run ¶
func Run()
Run initializes the proxy and starts the main listener loop. It blocks forever.
Types ¶
type AuthBackend ¶
type AuthBackend interface { Exists(name string) bool Passwd(name string) (salt, verifier []byte, err error) SetPasswd(name string, salt, verifier []byte) error LastSrv(name string) (string, error) SetLastSrv(name, srv string) error Timestamp(name string) (time.Time, error) Import(in []User) error Export() ([]User, error) Ban(addr, name string) error Unban(id string) error Banned(addr *net.UDPAddr) bool ImportBans(in []Ban) error ExportBans() ([]Ban, error) }
type AuthFiles ¶
type AuthFiles struct{}
func (AuthFiles) Banned ¶
Banned reports whether a network address is banned. Error cases count as banned.
func (AuthFiles) Exists ¶
Exists reports whether a user is registered. Error cases count as inexistent.
func (AuthFiles) ExportBans ¶
ExportBans returns data that can be processed by ImportBans or an error,
func (AuthFiles) ImportBans ¶
ImportBans deletes all ban entries and adds the passed entries.
func (AuthFiles) SetLastSrv ¶
SetLastSrv sets the last server a user was on.
func (AuthFiles) SetPasswd ¶
SetPasswd creates a password entry if necessary and sets the password of a user.
type AuthMTPostgreSQL ¶
type AuthMTPostgreSQL struct {
// contains filtered or unexported fields
}
A handle to a PostgreSQL authentication database. The upstream Minetest schema is used.
Table info:
Table "public.auth" Column | Type | Collation | Nullable | Default
------------+---------+-----------+----------+------------------------------------
id | integer | | not null | nextval('auth_id_seq'::regclass) name | text | | | password | text | | | last_login | integer | | not null | 0
Indexes:
"auth_pkey" PRIMARY KEY, btree (id) "auth_name_key" UNIQUE CONSTRAINT, btree (name)
Sequence info:
Sequence "public.auth_id_seq" Type | Start | Minimum | Maximum | Increment | Cycles? | Cache
---------+-------+---------+------------+-----------+---------+-------
integer | 1 | 1 | 2147483647 | 1 | no | 1
Owned by: public.auth.id
func NewAuthMTPostgreSQL ¶
func NewAuthMTPostgreSQL(conn string) (*AuthMTPostgreSQL, error)
NewAuthMTPostgreSQL opens the PostgreSQL authentication database at the specified connection string.
func (*AuthMTPostgreSQL) Ban ¶
func (a *AuthMTPostgreSQL) Ban(addr, name string) error
Ban adds a ban entry for a network address and an associated name.
func (*AuthMTPostgreSQL) Banned ¶
func (a *AuthMTPostgreSQL) Banned(addr *net.UDPAddr) bool
Banned reports whether a network address is banned. Error cases count as banned.
func (*AuthMTPostgreSQL) Close ¶
func (a *AuthMTPostgreSQL) Close() error
Close closes the underlying PostgreSQL database handle.
func (*AuthMTPostgreSQL) Exists ¶
func (a *AuthMTPostgreSQL) Exists(name string) bool
Exists reports whether a user is registered. Error cases count as inexistent.
func (*AuthMTPostgreSQL) Export ¶
func (a *AuthMTPostgreSQL) Export() ([]User, error)
Export returns data that can be processed by Import or an error.
func (*AuthMTPostgreSQL) ExportBans ¶
func (a *AuthMTPostgreSQL) ExportBans() ([]Ban, error)
ExportBans returns data that can be processed by ImportBans or an error.
func (*AuthMTPostgreSQL) Import ¶
func (a *AuthMTPostgreSQL) Import(in []User) error
Import adds the passed users.
func (*AuthMTPostgreSQL) ImportBans ¶
func (a *AuthMTPostgreSQL) ImportBans(in []Ban) error
ImportBans adds the passed entries.
func (*AuthMTPostgreSQL) LastSrv ¶
func (a *AuthMTPostgreSQL) LastSrv(_ string) (string, error)
LastSrv always returns an error since the Minetest database schema cannot store this information.
func (*AuthMTPostgreSQL) Passwd ¶
func (a *AuthMTPostgreSQL) Passwd(name string) (salt, verifier []byte, err error)
Passwd returns the SRP salt and verifier of a user or an error.
func (*AuthMTPostgreSQL) SetLastSrv ¶
func (a *AuthMTPostgreSQL) SetLastSrv(_, _ string) error
SetLastSrv is a no-op since the Minetest database schema cannot store this information.
func (*AuthMTPostgreSQL) SetPasswd ¶
func (a *AuthMTPostgreSQL) SetPasswd(name string, salt, verifier []byte) error
SetPasswd creates a password entry if necessary and sets the password of a user.
func (*AuthMTPostgreSQL) Timestamp ¶
func (a *AuthMTPostgreSQL) Timestamp(name string) (time.Time, error)
Timestamp returns the last time an authentication entry was accessed or an error.
func (*AuthMTPostgreSQL) Unban ¶
func (a *AuthMTPostgreSQL) Unban(id string) error
Unban deletes a ban entry. It accepts bot network addresses and player names.
type AuthMTSQLite3 ¶
type AuthMTSQLite3 struct {
// contains filtered or unexported fields
}
A handle to a SQLite3 authentication database. The upstream Minetest schema is used.
Table info:
0|id|INTEGER|0||1 1|name|VARCHAR(32)|0||0 2|password|VARCHAR(512)|0||0 3|last_login|INTEGER|0||0
func NewAuthMTSQLite3 ¶
func NewAuthMTSQLite3() (*AuthMTSQLite3, error)
NewAuthMTSQLite3 opens the SQLite3 authentication database at auth.sqlite.
func (*AuthMTSQLite3) Ban ¶
func (a *AuthMTSQLite3) Ban(addr, name string) error
Ban adds a ban entry for a network address and an associated name.
func (*AuthMTSQLite3) Banned ¶
func (a *AuthMTSQLite3) Banned(addr *net.UDPAddr) bool
Banned reports whether a network address is banned. Error cases count as banned.
func (*AuthMTSQLite3) Close ¶
func (a *AuthMTSQLite3) Close() error
Close closes the underlying SQLite3 database handle.
func (*AuthMTSQLite3) Exists ¶
func (a *AuthMTSQLite3) Exists(name string) bool
Exists reports whether a user is registered. Error cases count as inexistent.
func (*AuthMTSQLite3) Export ¶
func (a *AuthMTSQLite3) Export() ([]User, error)
Export returns data that can be processed by Import or an error.
func (*AuthMTSQLite3) ExportBans ¶
func (a *AuthMTSQLite3) ExportBans() ([]Ban, error)
ExportBans returns data that can be processed by ImportBans or an error.
func (*AuthMTSQLite3) Import ¶
func (a *AuthMTSQLite3) Import(in []User) error
Import adds the passed users.
func (*AuthMTSQLite3) ImportBans ¶
func (a *AuthMTSQLite3) ImportBans(in []Ban) error
ImportBans adds the passed entries.
func (*AuthMTSQLite3) LastSrv ¶
func (a *AuthMTSQLite3) LastSrv(_ string) (string, error)
LastSrv always returns an error since the Minetest database schema cannot store this information.
func (*AuthMTSQLite3) Passwd ¶
func (a *AuthMTSQLite3) Passwd(name string) (salt, verifier []byte, err error)
Passwd returns the SRP salt and verifier of a user or an error.
func (*AuthMTSQLite3) SetLastSrv ¶
func (a *AuthMTSQLite3) SetLastSrv(_, _ string) error
SetLastSrv is a no-op since the Minetest database schema cannot store this information.
func (*AuthMTSQLite3) SetPasswd ¶
func (a *AuthMTSQLite3) SetPasswd(name string, salt, verifier []byte) error
SetPasswd creates a password entry if necessary and sets the password of a user.
func (*AuthMTSQLite3) Timestamp ¶
func (a *AuthMTSQLite3) Timestamp(name string) (time.Time, error)
Timestamp returns the last time an authentication entry was accessed or an error.
func (*AuthMTSQLite3) Unban ¶
func (a *AuthMTSQLite3) Unban(id string) error
Unban deletes a ban entry. It accepts bot network addresses and player names.
type ChatCmd ¶
type ChatCmd struct { Name string Perm string Help string Usage string Handler func(*ClientConn, ...string) string }
A ChatCmd holds information on how to handle a chat command.
type ClientConn ¶
A ClientConn is a connection to a minetest client.
func Find ¶
func Find(name string) *ClientConn
Find returns the ClientConn that has the specified player name. If no ClientConn is found, nil is returned.
func (*ClientConn) Ban ¶
func (cc *ClientConn) Ban() error
Ban disconnects the ClientConn and prevents the underlying network address from connecting again.
func (*ClientConn) DoChatMsg ¶
func (cc *ClientConn) DoChatMsg(msg string)
DoChatMsg handles a chat message string as if it was sent by the ClientConn.
func (*ClientConn) HasPerms ¶
func (cc *ClientConn) HasPerms(want ...string) bool
HasPerms returns true if the ClientConn has all of the specified permissions. Otherwise it returns false. This method matches wildcards, but they may only be used at the end of a raw permission. Asterisks in other places will be treated as regular characters.
func (*ClientConn) Hop ¶
func (cc *ClientConn) Hop(serverName string) (err error)
Hop connects the ClientConn to the specified upstream server or the first working fallback server, saving the player's last server unless `ForceDefaultSrv` is enabled. If all attempts fail the client stays connected to the current server with the potential for inconsistent state. At the moment the ClientConn is NOT fixed if an error occurs so the player may have to reconnect.
func (*ClientConn) HopGroup ¶
func (cc *ClientConn) HopGroup(groupName string) error
HopGroup connects the ClientConn to the specified server group or the first working fallback server, saving the player's last server unless `ForceDefaultSrv` is enabled. See the documentation on `Server.Groups` in `doc/config.md` for details on how a specific game server is selected from the group name. If all attempts fail the client stays connected to the current server with the potential for inconsistent state. At the moment the ClientConn is NOT fixed if an error occurs so the player may have to reconnect.
func (*ClientConn) HopRaw ¶
func (cc *ClientConn) HopRaw(serverName string) error
HopRaw connects the ClientConn to the specified upstream server. At the moment the ClientConn is NOT fixed if an error occurs so the player may have to reconnect.
This method ignores fallback servers and doesn't save the player's last server. You may use the `Hop` wrapper for these purposes.
func (*ClientConn) Init ¶
func (cc *ClientConn) Init() <-chan struct{}
Init returns a channel that is closed when the ClientConn enters the csActive state.
func (*ClientConn) Kick ¶
func (cc *ClientConn) Kick(reason string)
Kick sends mt.ToCltKick with the specified custom reason and closes the ClientConn.
func (*ClientConn) Log ¶
func (cc *ClientConn) Log(dir string, v ...interface{})
Log logs an interaction with the ClientConn. dir indicates the direction of the interaction.
func (*ClientConn) Name ¶
func (cc *ClientConn) Name() string
Name returns the player name of the ClientConn.
func (*ClientConn) Perms ¶
func (cc *ClientConn) Perms() []string
Perms returns the raw permissions of the ClientConn.
func (*ClientConn) SendChatMsg ¶
func (cc *ClientConn) SendChatMsg(msg ...string)
SendChatMsg sends a chat message to the ClientConn.
func (*ClientConn) ServerName ¶
func (cc *ClientConn) ServerName() string
ServerName returns the name of the current upstream server of the ClientConn. It is empty if there is no upstream connection.
type Config ¶
type Config struct { NoPlugins bool NoAutoPlugins bool CmdPrefix string RequirePasswd bool SendInterval float32 UserLimit int AuthBackend string AuthPostgresConn string NoTelnet bool TelnetAddr string BindAddr string DefaultSrv string Servers map[string]Server ForceDefaultSrv bool KickOnNewPool bool FallbackServers []string CSMRF struct { NoCSMs bool ChatMsgs bool ItemDefs bool NodeDefs bool NoLimitMapRange bool PlayerList bool } MapRange uint32 DropCSMRF bool Groups map[string][]string UserGroups map[string]string List struct { Enable bool Addr string Interval int Name string Desc string URL string Creative bool Dmg bool PvP bool Game string FarNames bool Mods []string } }
A Config contains information from the configuration file that affects the way the proxy works.
func Conf ¶
func Conf() Config
Conf returns a copy of the Config used by the proxy. Any modifications will not affect the original Config.
func (Config) DefaultServer ¶
DefaultServer returns information about the default server. If no servers exist the returned struct will be uninitialized. This is a faster shortcut for Config.Servers[Config.DefaultServerName()]. You should thus only use this method or the DefaultServerInfo method.
func (Config) DefaultServerInfo ¶
DefaultServerInfo returns both the name of the default server and information about it. The return values are uninitialized if no servers exist.
func (Config) DefaultServerName ¶
DefaultServerName returns the name of the default server. If no servers exist it returns an empty string.
func (Config) RandomGroupServer ¶
RandomGroupServer returns the name of a random member of a server group or the input string if it is a valid, existent server name. It also returns a boolean indicating success. The returned string is blank if there is a failure, i.e. if the input string is neither a server nor a group.
type Interaction ¶
type Interaction uint8
const ( Dig Interaction = iota StopDigging Dug Place Use Activate AnyInteraction = 255 )
type InteractionHandler ¶
type InteractionHandler struct { Type Interaction Handler func(*ClientConn, *mt.ToSrvInteract) bool }
A InteractionHandler holds information on how to handle a Minetest Interaction.
type ServerConn ¶
A ServerConn is a connection to a minetest server.
func (*ServerConn) Init ¶
func (sc *ServerConn) Init() <-chan struct{}
Init returns a channel that is closed when the ServerConn enters the csActive state.
func (*ServerConn) Log ¶
func (sc *ServerConn) Log(dir string, v ...interface{})
Log logs an interaction with the ServerConn. dir indicates the direction of the interaction.
Source Files ¶
- activeobject.go
- auth.go
- auth_files.go
- auth_mtpostgresql.go
- auth_mtsqlite3.go
- chat.go
- client_conn.go
- config.go
- connect.go
- content.go
- formspec.go
- hop.go
- list.go
- listen.go
- log.go
- mediacache.go
- moderation.go
- perms.go
- players.go
- plugin.go
- plugin_chatcmd.go
- plugin_interact.go
- process.go
- proxy.go
- run.go
- server_conn.go
- uptime.go
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
mt-auth-convert
mt-auth-convert converts between authentication backends.
|
mt-auth-convert converts between authentication backends. |
mt-build-plugin
mt-build-plugin builds a plugin using the proxy version the tool was built for.
|
mt-build-plugin builds a plugin using the proxy version the tool was built for. |
mt-multiserver-proxy
mt-multiserver-proxy starts the reverse proxy.
|
mt-multiserver-proxy starts the reverse proxy. |