Documentation
¶
Index ¶
Constants ¶
const ( JoinabilityInviteOnly = "invite_only" JoinabilityJoinableByFriends = "joinable_by_friends" )
const ( BroadcastSettingInviteOnly int32 = iota + 1 BroadcastSettingFriendsOnly BroadcastSettingFriendsOfFriends )
const ( TransportLayerRakNet int32 = iota TransportLayerNetherNet )
const ( ConnectionTypeWebSocketsWebRTCSignaling uint32 = 3 ConnectionTypeUPNP uint32 = 6 )
const (
WorldTypeCreative = "Creative"
)
Variables ¶
This section is empty.
Functions ¶
func NetherNetID ¶
Types ¶
type Announcer ¶
type Announcer interface {
// Announce sends the given Status to an external service for reporting.
// The [context.Context] may be used to control the deadline and cancellation
// of announcement. An error may be returned, if the Status could not be announced.
Announce(ctx context.Context, status Status) error
Close() error
}
Announcer announces the Status of a Listener to an external service. Implementations of Announcer should define how to report the status using the provided Announce method.
Example implementations might include XBLAnnouncer, which uses the Multiplayer Session Directory (MPSD) of Xbox Live for announcing the Status.
type Connection ¶
type ListenConfig ¶
type ListenConfig struct {
// Announcer announces the Status of Listener. It is called from [Listener.ServerStatus] to report the status
// to external services like Xbox Live and LAN discovery. If nil, the Wrap method will panic.
Announcer Announcer
// StatusProvider provides the Status for announcing using the Announcer. It will be called by [Listener.ServerStatus]
// at some intervals. If nil, a default StatusProvider reporting DefaultStatus will be set.
StatusProvider StatusProvider
// DisableServerStatusOverride indicates that fields of the Status provided by the StatusProvider should be modified
// to sync with the [minecraft.ServerStatus] reported from [minecraft.Listener]. It includes fields like [Status.MemberCount],
// [Status.MaxMemberCount], [Status.WorldName], and [Status.HostName].
DisableServerStatusOverride bool // TODO: Find a good name
// Log is used for logging messages at various log levels. If nil, the default [slog.Logger]
// will be set from [slog.Default].
Log *slog.Logger
}
ListenConfig holds the configuration for wrapping a minecraft.NetworkListener with additional functionality. It provides the ability to announce server status and custom the behavior of status reporting.
func (ListenConfig) Wrap ¶
func (conf ListenConfig) Wrap(n minecraft.NetworkListener) *Listener
Wrap wraps the minecraft.NetworkListener with additional functionality provided by Listener. It returns a new Listener that hijacks the minecraft.ServerStatus of the underlying listener and announces it using the Announcer and the Status provided by the StatusProvider.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener wraps a minecraft.NetworkListener, allowing it to announce minecraft.ServerStatus using an Announcer. It can be created using ListenConfig.Wrap.
func (*Listener) Accept ¶
Accept waits for and returns the next net.Conn to the underlying minecraft.NetworkListener. An error may be returned if the Listener has been closed.
func (*Listener) Addr ¶
Addr returns the net.Addr of the underlying minecraft.NetworkListener.
func (*Listener) Close ¶
Close closes the Listener. Any blocking methods will be canceled through its internal context.
func (*Listener) ID ¶
ID returns the unique ID of the underlying minecraft.NetworkListener.
func (*Listener) PongData ¶
PongData updates the pong data on the underlying minecraft.NetworkListener.
func (*Listener) ServerStatus ¶
func (l *Listener) ServerStatus(server minecraft.ServerStatus)
ServerStatus reports the minecraft.ServerStatus to the Announcer with a Status provided by the StatusProvider. If [ListenConfig.DisableServerStatusOverride] is false, the fields of the Status will be modified to sync with the minecraft.ServerStatus. This includes updating member counts, world names, host names, and connections based on the address type of the minecraft.NetworkListener.
type Status ¶
type Status struct {
Joinability string `json:"Joinability,omitempty"`
HostName string `json:"hostName,omitempty"`
OwnerID string `json:"ownerId,omitempty"`
RakNetGUID string `json:"rakNetGUID"`
Version string `json:"version"`
LevelID string `json:"levelId"`
WorldName string `json:"worldName"`
WorldType string `json:"worldType"`
Protocol int32 `json:"protocol"`
MemberCount int `json:"MemberCount"`
MaxMemberCount int `json:"MaxMemberCount"`
BroadcastSetting int32 `json:"BroadcastSetting"`
LanGame bool `json:"LanGame"`
IsEditorWorld bool `json:"isEditorWorld"`
TransportLayer int32 `json:"TransportLayer"`
OnlineCrossPlatformGame bool `json:"OnlineCrossPlatformGame"`
CrossPlayDisabled bool `json:"CrossPlayDisabled"`
TitleID int64 `json:"TitleId"`
SupportedConnections []Connection `json:"SupportedConnections"`
}
func DefaultStatus ¶
func DefaultStatus() Status
type StatusProvider ¶
type StatusProvider interface {
RoomStatus() Status
}
func NewStatusProvider ¶
func NewStatusProvider(status Status) StatusProvider
type XBLAnnouncer ¶
type XBLAnnouncer struct {
// TokenSource provides the [xsapi.Token] required to publish a session when the Session is nil.
TokenSource xsapi.TokenSource
// SessionReference specifies the internal ID of the session being published when the Session is nil.
SessionReference mpsd.SessionReference
// PublishConfig specifies custom configuration for publishing a session when the Session is nil.
PublishConfig mpsd.PublishConfig
// Session is the session where the Status will be committed. If nil, a [mpsd.Session] will be published
// using the PublishConfig.
Session *mpsd.Session
// Mutex ensures atomic read/write access to the fields.
sync.Mutex
// contains filtered or unexported fields
}
XBLAnnouncer announces a Status through the Multiplayer Session Directory (MPSD) of Xbox Live.
func (*XBLAnnouncer) Announce ¶
func (a *XBLAnnouncer) Announce(ctx context.Context, status Status) error
Announce commits or publishes a mpsd.Session with the given Status. The status will be encoded as custom properties of the session description. The context.Context may be used to control the deadline or cancellation of announcement.
If the Status has not changed since the last announcement, the method will return immediately.
func (*XBLAnnouncer) Close ¶
func (a *XBLAnnouncer) Close() (err error)