steamworks

package module
v0.0.0-...-72424b2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 10 Imported by: 0

README

Steamworks API wrapper for Go

GoDoc Go Report Card CodeFactor

Documentation

Overview

Package steamworks wraps the Steamworks API.

See the official API documentation on the Steam Partner website: <https://partner.steamgames.com/doc/api>

This package attempts to make API functions available in a more idiomatic Go style.

Index

Constants

View Source
const UseGameSocketShare = ^uint16(0)

UseGameSocketShare is a placeholder value for queryPort that means the game is responsible for sending and receiving UDP packets for the master server updater.

Variables

View Source
var (
	ErrSteamNotRunning = errors.New("steamworks: the Steam client is not running")
	ErrIPv4Only        = errors.New("steamworks: only IPv4 addresses are supported")
)

Errors that can be returned by InitClient or InitServer.

Functions

func InitClient

func InitClient(startCallbackGoroutine bool) error

InitClient initializes the Steamworks API for game clients.

See Initialization and Shutdown for additional information. <https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown>

If startCallbackGoroutine is true, RunCallbacks will automatically be called in a loop. Set startCallbackGoroutine to false if you plan to call RunCallbacks manually, e.g. if your callback code is not thread-safe.

Returns nil if all required interfaces have been acquired and are accessible.

A non-nil error indicates one of the following conditions:

  • The Steam client isn't running. A running Steam client is required to provide implementations of the various Steamworks interfaces.
  • The Steam client couldn't determine the App ID of game. If you're running your application from the executable or debugger directly then you must have a steam_appid.txt in your game directory next to the executable, with your app ID in it and nothing else. Steam will look for this file in the current working directory. If you are running your executable from a different directory you may need to relocate the steam_appid.txt file.
  • Your application is not running under the same OS user context as the Steam client, such as a different user or administration access level.
  • Ensure that you own a license for the App ID on the currently active Steam account. Your game must show up in your Steam library.
  • Your App ID is not completely set up, i.e. in Release State: Unavailable, or it's missing default packages.

func InitServer

func InitServer(ip net.IP, steamPort, gamePort, queryPort uint16, serverMode ServerMode, version string, startCallbackGoroutine bool) error

InitServer initializes the ISteamGameServer interface object, and sets server properties which may not be changed.

After calling this function, you should set any additional server parameters, and then call steamgameserver.LogOnAnonymous or steamgameserver.LogOn.

If you pass in UseGameSocketShare into queryPort, then the game server will use GameSocketShare mode, which means that the game is responsible for sending and receiving UDP packets for the master server updater.

func RestartAppIfNecessary

func RestartAppIfNecessary(ownAppID AppID) bool

RestartAppIfNecessary checks if your executable was launched through Steam and relaunches it through Steam if it wasn't started by Steam originally.

See Initialization and Shutdown for additional information. <https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown>

If this returns true then it starts the Steam client if required and launches your game again through it, and you should quit your process as soon as possible. This effectively runs `steam://run/<AppId>` so it may not relaunch the exact executable that called it, as it will always relaunch from the version installed in your Steam library folder.

If it returns false, then your game was launched by the Steam client and no action needs to be taken. One exception is if a steam_appid.txt file is present then this will return false regardless. This allows you to develop and test without launching your game through the Steam client. Make sure to remove the steam_appid.txt file when uploading the game to your Steam depot!

Example:

const appId = ...

func main() {
    if steamworks.RestartAppIfNecessary(appId) {
        return
    }

    if err := steamworks.InitClient(true); err != nil {
        handleFatalError(err)
    }
    defer steamworks.Shutdown()

    mainGameLoop()
}

func RunCallbacks

func RunCallbacks()

RunCallbacks dispatches callbacks and call results to all of the registered listeners.

It's best to call this at >10Hz, the more time between calls, the more potential latency between receiving events or results from the Steamworks API. Most games call this once per render-frame. All registered listener functions will be invoked during this call, in the caller's thread context.

RunCallbacks is safe to call from multiple goroutines simultaneously, but if you choose to do this, callback code could be executed on any goroutine. One alternative is to call RunCallbacks from the main thread only.

Calling this function is required if and only if InitClient or InitServer was called with startCallbackGoroutine set to false.

func Shutdown

func Shutdown()

Shutdown shuts down the Steamworks API, releases pointers and frees memory.

You should call this during process shutdown if possible.

This will not unhook the Steam Overlay from your game as there's no guarantee that your rendering API is done using it.

Types

type AccountInstance

type AccountInstance uint32

AccountInstance represents an instance of a Steam account.

const (
	InstanceDesktop AccountInstance = 1 << 0
	InstanceConsole AccountInstance = 1 << 1
	InstanceWeb     AccountInstance = 1 << 2

	// Special flags for Chat accounts - they go in the top 8 bits
	// of the steam ID's "instance", leaving 12 for the actual instances
	InstanceFlagClan     AccountInstance = 1 << 19
	InstanceFlagLobby    AccountInstance = 1 << 18
	InstanceFlagMMSLobby AccountInstance = 1 << 17
)

Constants for AccountInstance

type AccountType

type AccountType = internal.EAccountType

AccountType is a Steam account type.

Constants for AccountType

type AccountUniverse

type AccountUniverse = internal.EUniverse

AccountUniverse is a Steam universe.

Constants for AccountUniverse

type AppID

type AppID uint32

AppID is a numeric identifier for a Steam app.

func GetAppID

func GetAppID() AppID

GetAppID returns the App ID of the current process.

func (AppID) GameID

func (id AppID) GameID() GameID

GameID returns the base GameID for this AppID.

type GameID

type GameID uint64

GameID identifies a game in Steam.

func NewModID

func NewModID(app AppID, path string) GameID

NewModID returns a GameID for a modification of a Steam app with the given base directory path.

func NewShortcutID

func NewShortcutID(exePath, appName string) GameID

NewShortcutID returns a GameID for a shortcut.

func (GameID) AppID

func (id GameID) AppID() AppID

AppID returns the AppID for this GameID.

func (GameID) Type

func (id GameID) Type() GameIDType

Type returns the type of this GameID.

type GameIDType

type GameIDType = internal.EGameIDType

GameIDType is the type of a GameID.

const (
	// TypeApp is a Steam app.
	TypeApp GameIDType = internal.EGameIDType_App
	// TypeGameMod is a modification of a Steam app.
	TypeGameMod GameIDType = internal.EGameIDType_GameMod
	// TypeShortcut is a shortcut to a non-Steam game.
	TypeShortcut GameIDType = internal.EGameIDType_Shortcut
)

type Registration

type Registration interface {
	// Unregister unregisters the callback. It is unsafe to call Unregister
	// multiple times on the same Registration.
	Unregister()
}

Registration is an opaque type that represents a registered callback.

type ServerMode

type ServerMode = internal.EServerMode

ServerMode is the authentication mode for a Steam game server.

const (
	// NoAuthentication doesn't authenticate user logins and doesn't list the
	// server on the master server list.
	NoAuthentication ServerMode = internal.EServerMode_NoAuthentication
	// Authentication authenticates users and lists the server on the master
	// server list but doesn't run VAC on clients that connect.
	Authentication ServerMode = internal.EServerMode_Authentication
	// AuthenticationAndSecure authenticates users, lists the server on the
	// master server list, and VAC protects clients.
	AuthenticationAndSecure ServerMode = internal.EServerMode_AuthenticationAndSecure
)

type SteamID

type SteamID uint64

SteamID is a 64-bit ID representing an object within the Steam "multiverse".

const (
	// SteamIDNil is a generic invalid SteamID.
	SteamIDNil SteamID = 0

	// SteamIDOutofDateGS is a SteamID that comes from a user game connection to an out-of-date game server that hasn't implemented the protocol to provide its SteamID.
	SteamIDOutofDateGS SteamID = SteamID(0) | SteamID(AccountTypeInvalid)<<52 | SteamID(UniverseInvalid)<<56
	// SteamIDLanModeGS is a SteamID that comes from a user game connection to an sv_lan game server.
	SteamIDLanModeGS SteamID = SteamID(0) | SteamID(AccountTypeInvalid)<<52 | SteamID(UniversePublic)<<56
	// SteamIDNotInitYetGS is a SteamID that can come from a user game connection to a game server that has just booted but hasn't yet even initialized its Steam3 component and started logging on.
	SteamIDNotInitYetGS SteamID = SteamID(1) | SteamID(AccountTypeInvalid)<<52 | SteamID(UniverseInvalid)<<56
	// SteamIDNonSteamGS is a SteamID that can come from a user game connection to a GS that isn't using the steam authentication system but still wants to support the "Join Game" option in the friends list.
	SteamIDNonSteamGS SteamID = SteamID(2) | SteamID(AccountTypeInvalid)<<52 | SteamID(UniverseInvalid)<<56
)

func GetSteamID

func GetSteamID() SteamID

GetSteamID returns the Steam ID associated with the current user or game server.

func (SteamID) AccountID

func (id SteamID) AccountID() uint32

AccountID extracts the account ID from this SteamID.

func (SteamID) Instance

func (id SteamID) Instance() AccountInstance

Instance extracts the account instance from this SteamID.

The meaning of the account instance is different for each account type.

func (SteamID) IsValid

func (id SteamID) IsValid() bool

IsValid returns true if the SteamID has a valid format. It does not check whether the target of the ID exists.

func (SteamID) Steam2String

func (id SteamID) Steam2String() string

Steam2String returns the Steam2 string representation of this ID.

If the account type is AccountTypeInvalid or AccountTypeIndividual

func (SteamID) String

func (id SteamID) String() string

func (SteamID) Type

func (id SteamID) Type() AccountType

Type extracts the account type from this SteamID.

The most common account type you will interact with is AccountTypeIndividual.

func (SteamID) Universe

func (id SteamID) Universe() AccountUniverse

Universe extracts the universe from this SteamID.

It is safe to assume the universe is UniversePublic in any valid SteamID. Other universes are only used within Valve's internal network.

Directories

Path Synopsis
Package internal wraps the Steamworks API.
Package internal wraps the Steamworks API.
Package steamauth wraps Steam's user authentication API.
Package steamauth wraps Steam's user authentication API.
Package steamcontroller wraps Steam's controller input API.
Package steamcontroller wraps Steam's controller input API.
Package steamnet wraps Steam's peer-to-peer networking API.
Package steamnet wraps Steam's peer-to-peer networking API.
Package steamutils wraps miscellaneous Steam utility functions.
Package steamutils wraps miscellaneous Steam utility functions.
Package steamvoice wraps Steam's voice chat API.
Package steamvoice wraps Steam's voice chat API.

Jump to

Keyboard shortcuts

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