ISteamGameServer

You can use this interface to connect to steam as a Game Server and run this library without having to run the steam client in the background.

You need to use luasteam a bit differently. Instead of using Steam.init() and the other callbacks, do it like this:

local Steam = require 'luasteam'

Steam.gameServer.init(0, gamePort, queryPort, Steam.gameServer.mode.NoAuthentication, "0.0.1")
-- ...
-- during the update loop
Steam.gameServer.runCallbacks()
-- ...
-- when game is closing
Steam.gameServer.shutdown()

In this mode, not all modules and functions are usable.

Useable modules:

  • ISteamNetworkingSockets

  • ISteamNetworkingUtils

List of Functions

List of Callbacks

Function Reference

gameServer.init()
Parameters:
  • unIP (int) – The IP address you are going to bind to. (This should be in host order, i.e 127.0.0.1 == 0x7f000001 == 2130706433). You can just use 0 to bind to all local IPv4 addresses.

  • steamPort (int) – The port clients are going to bind to. Important if you want to connect this server to a game master and show it in a server list.

  • queryPort (int) – The port for communicating with a game master server and exchange status information.

  • serverMode (int) –

    The server mode to use. Use constants from Steam.gameServer.mode.*

    • NoAuthentication Don’t authenticate user logins and don’t list on the server list.

    • Authentication Authenticate users, list on the server list, don’t run VAC on clients that connect.

    • AuthenticationAndSecure Authenticate users, list on the server list and VAC protect clients.

  • version (string) – The version of your game in the form x.x.x.x. This is used to show the version of the server in the server browser and to block outdated servers from connecting.

Returns:

(boolean) success

SteamWorks:

SteamGameServer_Init

Initiate the game server API and allow usage of ISteamNetworkingSockets and ISteamNetworkingUtils. Add some metadata about the type of server you’re running here. Most of this is only relevant if you’re planning to make use of Steam’s server browser feature.

Example:

local result = Steam.gameServer.init(0, gamePort, queryPort, Steam.gameServer.mode.Authentication, "0.0.0.1")
gameServer.shutdown()
Returns:

nothing

SteamWorks:

SteamGameServer_Shutdown

Don’t forget to call this when your game is closing or when you’re done using the interface.

Example:

Steam.gameServer.shutdown()
gameServer.runCallbacks()
Returns:

nothing

SteamWorks:

SteamGameServer_RunCallbacks

Run the steam callbacks. This is required to get any callbacks from the steam API. You need to call this regularly, e.g. in your main loop.

Example:

Steam.gameServer.runCallbacks()
gameServer.logOn()
Parameters:

token (string) – The login token for your server

Returns:

nothing

SteamWorks:

LogOn

Authenticate to steam with a login token. Generate a token through Steam.

Triggers the callbacks

  • networkingSockets.onSteamServersConnected()

  • networkingSockets.onSteamServersDisconnected()

  • networkingSockets.onSteamServerConnectFailure()

Example:

local accessToken = "abcdef123456" -- Access token generated through steam
Steam.gameServer.logOn(accessToken)
gameServer.logOnAnonymous()
Returns:

nothing

SteamWorks:

LogOnAnonymous

Log in into a generic, anonymous Steam account.

Triggers the callbacks

  • networkingSockets.onSteamServersConnected()

  • networkingSockets.onSteamServersDisconnected()

  • networkingSockets.onSteamServerConnectFailure()

Example:

Steam.gameServer.logOnAnonymous()
gameServer.logOff()
Returns:

nothing

SteamWorks:

LogOff

Begin process of logging the game server out of steam.

Triggers the callbacks

  • networkingSockets.onSteamServersConnected()

  • networkingSockets.onSteamServersDisconnected()

  • networkingSockets.onSteamServerConnectFailure()

Example:

Steam.gameServer.logOff()
gameServer.bLoggedOn()
Returns:

(boolean) true if logged on

SteamWorks:

BLoggedOn

Checks if the game server is logged on.

Example:

local loggedOn = Steam.gameServer.bLoggedOn()
gameServer.bSecure()
Returns:

(boolean) true if logged on

SteamWorks:

BSecure

Checks whether the game server is in “Secure” mode.

Example:

local secure = Steam.gameServer.bSecure()
gameServer.getSteamID()
Returns:

(uint64) The SteamID of the server.

SteamWorks:

GetSteamID

Gets the Steam ID of the game server.

Example:

local steam_id = Steam.gameServer.getSteamID()
gameServer.setDedicatedServer()
Parameters:

bDedicated (boolean) – Is this a dedicated server (true) or a listen server (false)?

Returns:

nothing

SteamWorks:

SetDedicatedServer

Sets the whether this is a dedicated server or a listen server. The default is listen server.

NOTE: This can only be set before calling networkingSockets.LogOn() or networkingSockets.LogOnAnonymous().

Example:

Steam.gameServer.setDedicatedServer(true)
gameServer.beginAuthSession()
Parameters:
  • authTicket (string) – The auth ticket in hexadeximal string representation

  • steamID (uint64) – The steam id of the user to verify an auth ticket for. Needs to be the same user that originally created the authTicket.

Returns:

nothing

SteamWorks:

BeginAuthSession

Use this to validate an auth ticket created with user.getAuthSessionTicket(). Read User Authentication and Ownership for more information.

Triggers the callback gameServer.onValidateAuthTicketResponse()

Example:

Steam.gameServer.beginAuthSession(authTicket, steamID)
gameServer.endAuthSession()
Parameters:

steamID (uint64) – The steam id of the user for which a verification is in progress.

Returns:

nothing

SteamWorks:

EndAuthSession

Cancel the auth session. Must be called for any calls to gameServer.beginAuthSession() when the connection is ended or before the server shutdown. Read User Authentication and Ownership for more information.

Example:

Steam.gameServer.endAuthSession()

Callbacks Reference

Warning

Remember callbacks are functions that you should override in order to receive the events, and not call directly.

Also, you must constantly call Steam.gameServer.runCallbacks() (preferably in your game loop) in order for your callbacks to be called.

gameServer.onValidateAuthTicketResponse()
Parameters:

data (table) –

A result table

  • data.steam_id (uint64) The steam id of the account requesting validation for the given game context

  • data.owner_steam_id (uint64) The steam id of the owner of the game for the given game context. E.g. for example when the game is played through family sharing, the owner_steam_id will differ.

  • data.response (string) A result string. OK if the validation was successful, otherwise an error string. See EAuthSessionResponse <https://partner.steamgames.com/doc/api/steam_api#EAuthSessionResponse>_ for details.

Returns:

nothing

SteamWorks:

ValidateAuthTicketResponse_t

Called when steam has validated an auth ticket on the steam server side. If OK, you know that’s a registered, verified steam account that owns a valid license for the app in question.

Example:

function Steam.gameServer.onValidateAuthTicketResponse(data)
    print("Auth ticket validated", data.steam_id, data.response)
end
gameServer.onSteamServersConnected()
Returns:

nothing

SteamWorks:

SteamServersConnected_t

Called when a connections to the Steam back-end has been established. This is in response to a call to networkingSockets.LogOn() or networkingSockets.LogOnAnonymous() or after loosing a connection.

This means the Steam client now has a working connection to the Steam servers.

Example:

function Steam.gameServer.onSteamServersConnected()
    print("SteamServersConnected")
end
gameServer.onSteamServersDisconnected(data)
Parameters:

data (table) –

A result table

  • data.result (string) An error message with the reason for the disconnect.

Returns:

nothing

SteamWorks:

SteamServersDisconnected_t

Called if the client has lost connection to the Steam servers.

Example:

function Steam.gameServer.onSteamServersDisconnected(data)
    print("onSteamServersDisconnected", data.result)
end
gameServer.onSteamServerConnectFailure(data)
Parameters:

data (table) –

A result table

  • data.result (string) An error message with the reason for the disconnect.

  • data.stillRetrying (boolean) True if another connection attempt will be made, False if we have given up.

Returns:

nothing

SteamWorks:

SteamServerConnectFailure_t

Called when a connection attempt has failed.

This will occur periodically if the Steam client is not connected, and has failed when retrying to establish a connection.

Example:

function Steam.gameServer.onSteamServerConnectFailure(data)
    print("onSteamServerConnectFailure", data.result, data.stillRetrying)
end