eos

package
v0.4.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package eos is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.

Package eos binds Epic Online Services for desktop Epic Games Store builds (via purego with no cgo or hand-written C) and provides an injectable callback Driver contract for tests and non-desktop targets (where opening the native library returns ErrUnavailable).

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable is returned by New without a driver, by Open on non-desktop targets, and by the native driver when the EOS shared library cannot be loaded or initialized.
	ErrUnavailable = errors.New("eos: unavailable")
	// ErrClosed is reported for a request made after Close.
	ErrClosed = errors.New("eos: closed")
	// ErrUnauthenticated is reported by Login without valid credentials and by a request made before Login succeeds.
	ErrUnauthenticated = errors.New("eos: unauthenticated")
	// ErrInvalidConfig is returned by New or Open when a product, sandbox or deployment ID is empty or cx is nil.
	ErrInvalidConfig = errors.New("eos: invalid config")
	// ErrInvalidArgument is reported for an empty ID or an out-of-range argument.
	ErrInvalidArgument = errors.New("eos: invalid argument")
)

Functions

func ExchangeCodeFromArgs

func ExchangeCodeFromArgs(args []string) string

ExchangeCodeFromArgs returns the exchange code the Epic launcher passes as -AUTH_PASSWORD=<code> together with -AUTH_TYPE=exchangecode, or "" when args carry no exchange-code login. Pass os.Args[1:].

Types

type AuthCredentials

type AuthCredentials struct {
	// Type is AuthExchangeCode or AuthDeveloper, or empty when no supported auth type was found.
	Type AuthType
	// ID is the Developer Authentication Tool host:port (-AUTH_LOGIN) when Type is AuthDeveloper.
	ID string
	// Token is the exchange code or developer credential name (-AUTH_PASSWORD).
	Token string
}

AuthCredentials holds parsed command-line or explicit EOS authentication parameters.

func AuthFromArgs

func AuthFromArgs(args []string) AuthCredentials

AuthFromArgs parses Epic Games Launcher (-AUTH_TYPE=exchangecode -AUTH_PASSWORD=<code>) or Developer Authentication Tool (-AUTH_TYPE=developer -AUTH_LOGIN=<host:port> -AUTH_PASSWORD=<name>) flags from args, supporting both -FLAG=value and -FLAG value forms. Pass os.Args[1:].

type AuthDriver

type AuthDriver interface {
	LoginWithCredentials(creds AuthCredentials, done func(Player, error))
}

AuthDriver is an optional Driver extension implemented by the desktop purego driver and FakeDriver to support developer auth tool logins (AuthDeveloper) in addition to launcher exchange codes.

type AuthType

type AuthType string

AuthType selects how Platform.Login authenticates with Epic Online Services.

const (
	// AuthExchangeCode authenticates using the single-use exchange code passed by the Epic Games Launcher (-AUTH_TYPE=exchangecode -AUTH_PASSWORD=<code>).
	AuthExchangeCode AuthType = "exchangecode"
	// AuthDeveloper authenticates against a locally running EOS Developer Authentication Tool (-AUTH_TYPE=developer -AUTH_LOGIN=localhost:6547 -AUTH_PASSWORD=<credential>).
	AuthDeveloper AuthType = "developer"
)

type Config

type Config struct {
	// ProductID is the Epic Developer Portal Product ID.
	ProductID string
	// SandboxID is the Epic Developer Portal Sandbox ID.
	SandboxID string
	// DeploymentID is the Epic Developer Portal Deployment ID.
	DeploymentID string
	// ExchangeCode is the launcher exchange code (-AUTH_PASSWORD with -AUTH_TYPE=exchangecode).
	ExchangeCode string
	// ClientID is the EOS Desktop Client Policy ClientId required by EOS_Platform_Create.
	ClientID string
	// ClientSecret is the EOS Desktop Client Policy ClientSecret required by EOS_Platform_Create.
	ClientSecret string
	// ProductName is passed to EOS_Initialize; defaults to ProductID when empty.
	ProductName string
	// ProductVersion is passed to EOS_Initialize; defaults to "1.0.0" when empty.
	ProductVersion string
	// EncryptionKey is an optional 64-hex-character key used by EOS storage and stats.
	EncryptionKey string
	// CacheDirectory is an optional writable directory path for EOS SDK caches.
	CacheDirectory string
	// LibraryPath overrides standard shared library discovery for the native EOS SDK binary.
	LibraryPath string
	// AuthType selects AuthExchangeCode (default) or AuthDeveloper for Platform.Login.
	AuthType AuthType
	// DevAuthHost is the EOS Developer Authentication Tool address (such as "localhost:6547") when AuthType is AuthDeveloper.
	DevAuthHost string
	// DevAuthCredential is the credential name registered in the Developer Authentication Tool when AuthType is AuthDeveloper.
	DevAuthCredential string
	// IsServer marks the EOS platform instance as a dedicated server (false for desktop game clients).
	IsServer bool
	// DisableOverlay disables the Epic Social Overlay (EOS_PF_DISABLE_OVERLAY) when true.
	DisableOverlay bool
}

Config identifies an Epic product and optional native SDK and login parameters. ExchangeCode is the code the Epic launcher passes with -AUTH_PASSWORD; ExchangeCodeFromArgs and WithArgs read launcher or developer auth flags from os.Args[1:].

func (Config) WithArgs

func (c Config) WithArgs(args []string) Config

WithArgs returns a copy of c populated with any Epic launcher exchange-code or developer auth tool flags found in args (typically os.Args[1:]).

type Driver

type Driver interface {
	Login(exchangeCode string, done func(Player, error))
	UnlockAchievement(id string, done func(error))
	ProgressAchievement(id string, percent float64, done func(error))
	SubmitScore(board string, score int64, done func(error))
	QueryLeaderboard(board string, friends bool, limit int, done func([]LeaderboardEntry, error))
	SetPresence(details, status string, done func(error))
	Tick()
	Close() error
}

Driver is the native boundary implemented by an EOS SDK adapter. Every operation is asynchronous, as in the EOS SDK: a method starts the request and returns, and the driver calls done exactly once when the request completes, normally from inside Tick, where the EOS SDK dispatches its callbacks, or at once when the request cannot start. Platform calls every method and Tick on the engine goroutine and posts each done result back to its scope, so a driver may also call done from another goroutine.

type FakeDriver

type FakeDriver struct {

	// Player returned by Login / LoginWithCredentials. Defaults to a non-empty test player when zero.
	Player Player

	// Optional errors injected for testing error paths.
	LoginErr       error
	UnlockErr      error
	ProgressErr    error
	IngestStatErr  error
	SubmitScoreErr error
	QueryErr       error
	PresenceErr    error
	// contains filtered or unexported fields
}

FakeDriver is an in-process pure-Go Driver implementing Driver, AuthDriver, StatsDriver and RichPresenceDriver for deterministic unit tests without loading the EOS SDK shared library.

Like the real EOS SDK, FakeDriver queues every operation's callback until Tick is called. All methods are safe for concurrent use.

func NewFakeDriver

func NewFakeDriver() *FakeDriver

NewFakeDriver returns a FakeDriver initialized with a default test player.

func (*FakeDriver) ClearPresence

func (f *FakeDriver) ClearPresence(done func(error))

ClearPresence implements RichPresenceDriver.

func (*FakeDriver) ClearPresenceCount

func (f *FakeDriver) ClearPresenceCount() int

ClearPresenceCount returns how many times ClearPresence was called.

func (*FakeDriver) Close

func (f *FakeDriver) Close() error

Close implements Driver.

func (*FakeDriver) CloseCount

func (f *FakeDriver) CloseCount() int

CloseCount returns how many times Close was called.

func (*FakeDriver) IngestStat

func (f *FakeDriver) IngestStat(stat string, amount int32, done func(error))

IngestStat implements StatsDriver.

func (*FakeDriver) LastAuth

func (f *FakeDriver) LastAuth() AuthCredentials

LastAuth returns the most recent credentials passed to Login or LoginWithCredentials.

func (*FakeDriver) LeaderboardQueries

func (f *FakeDriver) LeaderboardQueries() []LeaderboardQuery

LeaderboardQueries returns a copy of QueryLeaderboard calls.

func (*FakeDriver) Login

func (f *FakeDriver) Login(exchangeCode string, done func(Player, error))

Login implements Driver for exchange-code authentication.

func (*FakeDriver) LoginCalls

func (f *FakeDriver) LoginCalls() int

LoginCalls returns the number of login attempts received.

func (*FakeDriver) LoginWithCredentials

func (f *FakeDriver) LoginWithCredentials(creds AuthCredentials, done func(Player, error))

LoginWithCredentials implements AuthDriver for both exchange-code and developer auth tool logins.

func (*FakeDriver) PendingCount

func (f *FakeDriver) PendingCount() int

PendingCount returns the number of queued callbacks awaiting Tick.

func (*FakeDriver) Presences

func (f *FakeDriver) Presences() []PresenceUpdate

Presences returns a copy of all presence updates published to the driver.

func (*FakeDriver) ProgressAchievement

func (f *FakeDriver) ProgressAchievement(id string, percent float64, done func(error))

ProgressAchievement implements Driver.

func (*FakeDriver) ProgressReports

func (f *FakeDriver) ProgressReports() []ProgressReport

ProgressReports returns a copy of ProgressAchievement calls.

func (*FakeDriver) QueryLeaderboard

func (f *FakeDriver) QueryLeaderboard(board string, friends bool, limit int, done func([]LeaderboardEntry, error))

QueryLeaderboard implements Driver.

func (*FakeDriver) ScoreSubmissions

func (f *FakeDriver) ScoreSubmissions() []ScoreSubmission

ScoreSubmissions returns a copy of SubmitScore calls.

func (*FakeDriver) SeedLeaderboard

func (f *FakeDriver) SeedLeaderboard(board string, friends bool, entries []LeaderboardEntry)

SeedLeaderboard seeds global or friends leaderboard entries returned by QueryLeaderboard.

func (*FakeDriver) SeedLeaderboardDefinition

func (f *FakeDriver) SeedLeaderboardDefinition(boardID, statName string)

SeedLeaderboardDefinition links leaderboard boardID to backing EOS stat name so SubmitScore(statName, score) updates boardID automatically.

func (*FakeDriver) SetPresence

func (f *FakeDriver) SetPresence(details, status string, done func(error))

SetPresence implements Driver.

func (*FakeDriver) SetRichPresence

func (f *FakeDriver) SetRichPresence(update PresenceUpdate, done func(error))

SetRichPresence implements RichPresenceDriver.

func (*FakeDriver) StatIngests

func (f *FakeDriver) StatIngests() []StatIngest

StatIngests returns a copy of IngestStat calls.

func (*FakeDriver) StatTotal

func (f *FakeDriver) StatTotal(stat string) int32

StatTotal returns the cumulative ingested value for stat.

func (*FakeDriver) SubmitScore

func (f *FakeDriver) SubmitScore(board string, score int64, done func(error))

SubmitScore implements Driver, recording the submission and updating matching global and friends leaderboard rows when SubmitScoreErr is nil.

func (*FakeDriver) Tick

func (f *FakeDriver) Tick()

Tick implements Driver, dispatching all callbacks queued before Tick began.

func (*FakeDriver) TickCount

func (f *FakeDriver) TickCount() int

TickCount returns how many times Tick was called.

func (*FakeDriver) UnlockAchievement

func (f *FakeDriver) UnlockAchievement(id string, done func(error))

UnlockAchievement implements Driver.

func (*FakeDriver) Unlocks

func (f *FakeDriver) Unlocks() []string

Unlocks returns a copy of achievement IDs passed to UnlockAchievement.

type LeaderboardEntry

type LeaderboardEntry struct {
	Rank    int
	UserID  string
	Display string
	Score   int64
}

LeaderboardEntry is one row returned by QueryLeaderboard.

type LeaderboardQuery

type LeaderboardQuery struct {
	Board   string
	Friends bool
	Limit   int
}

LeaderboardQuery records one QueryLeaderboard call performed on FakeDriver.

type OpenOption

type OpenOption func(*openOptions)

OpenOption configures Open.

func WithDriver

func WithDriver(driver Driver) OpenOption

WithDriver injects a custom or fake Driver into Open instead of loading the native EOS shared library.

type Platform

type Platform struct {
	// contains filtered or unexported fields
}

Platform owns one EOS connection and its driver. Its methods are safe only on the engine goroutine, matching sound and game services. Every done callback runs on the engine goroutine under the scope given to New or Open, never inside the call that started the request; results that arrive after Close or after the scope is disposed are dropped.

func Current

func Current() *Platform

Current returns the currently open shared Platform created by Open, or nil if none is open or it has been closed.

func New

func New(cx *core.Scope, cfg Config, driver Driver) (*Platform, error)

New creates a platform around an injected driver and closes it when cx is disposed. Native adapters should return ErrUnavailable when the EOS shared library cannot be loaded; a nil driver yields ErrUnavailable.

Example

New connects the app to Epic Online Services through a driver, which dispatches its results from Tick on the engine goroutine. The example is compiled but not run: a real driver needs the EOS SDK and a running app.

package main

import (
	"fmt"

	"github.com/nsgo-dev/game/pkg/online/eos"
	"github.com/nsgo-dev/nsgo/core"
)

func main() {
	var (
		cx     *core.Scope
		driver eos.Driver
	)
	platform, err := eos.New(cx, eos.Config{
		ProductID:    "product",
		SandboxID:    "sandbox",
		DeploymentID: "deployment",
	}, driver)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer platform.Close()
	platform.Login(func(player eos.Player, err error) {
		if err == nil {
			fmt.Println("signed in as", player.DisplayName)
		}
	})
}

func Open

func Open(cx *core.Scope, cfg Config, opts ...OpenOption) (*Platform, error)

Open creates and registers a shared EOS Platform bound to cx, ticking it automatically on every display frame on the engine goroutine and shutting it down when cx is disposed.

Without WithDriver, Open loads the desktop EOS shared library via purego (EOSSDK-Win64-Shipping.dll, libEOSSDK-Linux-Shipping.so, or libEOSSDK-Mac-Shipping.dylib) and returns ErrUnavailable on non-desktop targets or when the library cannot be loaded. Packages such as achievements, leaderboard and presence discover the open platform through Current.

func (*Platform) ClearPresence

func (p *Platform) ClearPresence(done func(error))

ClearPresence clears the local player's EOS rich presence and join info. Drivers that do not implement RichPresenceDriver fall back to Driver.SetPresence("", ""). done may be nil.

func (*Platform) Close

func (p *Platform) Close() error

Close shuts down the native driver, clears Current if p was opened with Open, notifies OnClose handlers, and signs the player out. It is idempotent.

func (*Platform) Closed

func (p *Platform) Closed() bool

Closed reports whether p has been closed.

func (*Platform) IngestStat

func (p *Platform) IngestStat(stat string, amount int32, done func(error))

IngestStat ingests an integer stat amount through EOS Stats (EOS_Stats_IngestStat), used by stat-backed achievements and leaderboards. Returns ErrUnavailable if the driver does not implement StatsDriver. done may be nil.

func (*Platform) Login

func (p *Platform) Login(done func(Player, error))

Login authenticates with the configured exchange code or developer auth tool credentials. On success Player and SignedIn report the account; on failure they report signed out. done may be nil.

func (*Platform) OnClose

func (p *Platform) OnClose(fn func()) func()

OnClose registers fn to run when Close shuts down p and returns an unregister function. If p is already closed, fn is not invoked and a no-op unregister function is returned.

func (*Platform) Player

func (p *Platform) Player() Player

Player returns the authenticated player, or zero while signed out. It is a reactive read.

func (*Platform) ProgressAchievement

func (p *Platform) ProgressAchievement(id string, percent float64, done func(error))

ProgressAchievement reports achievement progress in [0,100]; other values yield ErrInvalidArgument. done may be nil.

func (*Platform) QueryLeaderboard

func (p *Platform) QueryLeaderboard(board string, friends bool, limit int, done func([]LeaderboardEntry, error))

QueryLeaderboard loads up to limit global or friends rows from an EOS leaderboard; limit must be positive. done must not be nil.

func (*Platform) SetPresence

func (p *Platform) SetPresence(details, status string, done func(error))

SetPresence publishes rich presence details and status. done may be nil.

func (*Platform) SetRichPresence

func (p *Platform) SetRichPresence(update PresenceUpdate, done func(error))

SetRichPresence publishes EOS rich text, join info, and optional custom presence data. Drivers that do not implement RichPresenceDriver fall back to Driver.SetPresence(update.RichText, update.JoinInfo). done may be nil.

func (*Platform) SignedIn

func (p *Platform) SignedIn() bool

SignedIn reports whether Login succeeded.

func (*Platform) SubmitScore

func (p *Platform) SubmitScore(board string, score int64, done func(error))

SubmitScore submits a score to a named EOS leaderboard (via its backing stat). done may be nil.

func (*Platform) Tick

func (p *Platform) Tick()

Tick pumps the native EOS callback queue once. Call it every step of the fixed game loop (Open also ticks on each display frame).

func (*Platform) UnlockAchievement

func (p *Platform) UnlockAchievement(id string, done func(error))

UnlockAchievement reports an achievement ID to EOS. done may be nil.

type Player

type Player struct {
	// ProductUserID is the EOS Connect ProductUserId used by Achievements, Stats and Leaderboards.
	ProductUserID string
	// DisplayName is the player's Epic account display name when available.
	DisplayName string
	// EpicAccountID is the Epic Account Services EpicAccountId used by Presence and Friends.
	EpicAccountID string
}

Player is the local Epic account returned by Login.

type PresenceUpdate

type PresenceUpdate struct {
	// RichText is the human-readable status text shown in the Epic Games Launcher friends list (at most 255 UTF-8 bytes).
	RichText string
	// JoinInfo is the opaque session join token passed to friends joining via the Epic overlay (at most 255 UTF-8 bytes).
	JoinInfo string
	// Data holds optional custom key-value presence records.
	Data map[string]string
}

PresenceUpdate describes a rich presence update published to Epic Online Services.

func (PresenceUpdate) Clone

func (u PresenceUpdate) Clone() PresenceUpdate

Clone returns a deep copy of u with an independent Data map.

type ProgressReport

type ProgressReport struct {
	ID      string
	Percent float64
}

ProgressReport records one ProgressAchievement call performed on FakeDriver.

type RichPresenceDriver

type RichPresenceDriver interface {
	SetRichPresence(update PresenceUpdate, done func(error))
	ClearPresence(done func(error))
}

RichPresenceDriver is an optional Driver extension implemented by the desktop purego driver and FakeDriver to publish rich text, join info, and custom presence data, and to clear presence.

type ScoreSubmission

type ScoreSubmission struct {
	Board string
	Score int64
}

ScoreSubmission records one SubmitScore call performed on FakeDriver.

type StatIngest

type StatIngest struct {
	Stat   string
	Amount int32
}

StatIngest records one EOS Stats ingestion performed on FakeDriver.

type StatsDriver

type StatsDriver interface {
	IngestStat(stat string, amount int32, done func(error))
}

StatsDriver is an optional Driver extension implemented by the desktop purego driver and FakeDriver to ingest EOS stats directly (EOS_Stats_IngestStat) for stepped achievements and stat-backed leaderboards.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL