### C++ Steam API Initialization and Shutdown Source: https://luasteam.readthedocs.io/en/stable/getting_started Provides the standard C++ code for initializing and shutting down the Steam API. This serves as a reference for the equivalent operations in Luasteam. ```cpp #include SteamAPI_Init(); // ... // when game is closing SteamAPI_Shudown() ``` -------------------------------- ### Initialize and Shutdown Luasteam Source: https://luasteam.readthedocs.io/en/stable/getting_started Demonstrates how to initialize and shut down the Luasteam library, mirroring the basic Steam API initialization process. Ensure Steam is running and a 'steam_appid.txt' file is present for development. ```lua local Steam = require 'luasteam' Steam.init() -- ... -- when game is closing Steam.shutdown() ``` -------------------------------- ### C++ SteamWorks API GameOverlayActivated Callback Source: https://luasteam.readthedocs.io/en/stable/getting_started Shows the C++ implementation for handling the `GameOverlayActivated_t` callback using the `STEAM_CALLBACK` macro. This is the original implementation that Luasteam simplifies. ```cpp class Listener { STEAM_CALLBACK(Listener, OnGameOverlayActivated, GameOverlayActivated_t); }; void Listener::OnGameOverlayActivated(GameOverlayActivated_t* data) { if (data->m_bActive) printf("Steam overlay now active\n"); else printf("Steam overlay now inactive\n"); } ``` -------------------------------- ### C++ SteamWorks API Leaderboard Find CallResult Source: https://luasteam.readthedocs.io/en/stable/getting_started Presents the C++ code for handling leaderboard finding results using `CCallResult`. This involves setting up a callback function and associating it with a `SteamAPICall_t`. ```cpp class Listener { public: void FindTestLeaderboard(const char *name); private: void OnLeaderboardFindResult(LeaderboardFindResult_t *data, bool err); CCallResult leaderboardFindResult; }; void Listener::OnLeaderboardFindResult(LeaderboardFindResult_t *data, bool err ) { if (err || data->m_bLeaderboardFound == 0) printf("Leaderboard not found!\n"); else printf("Leaderboard found!\n"); } // Make the request void Listener::FindTestLeaderboard() { SteamAPICall_t call = SteamUserStats()->FindLeaderboard("test"); leaderboardFindResult.Set(call, this, &Listener::OnLeaderboardFindResult); } ``` -------------------------------- ### Map C++ SteamFriends ActivateGameOverlay to Lua Source: https://luasteam.readthedocs.io/en/stable/getting_started Shows the direct mapping of the C++ SteamFriends API function `ActivateGameOverlay` to its Lua equivalent in Luasteam. This function is used to open the Steam overlay to a specific section, like achievements. ```lua Steam.friends.activateGameOverlay("achievements") ``` -------------------------------- ### Handle 64-bit Integers with LuaSteamworks Source: https://luasteam.readthedocs.io/en/stable/getting_started Demonstrates how to obtain a 64-bit SteamID, convert it to a string, and then parse it back into a 64-bit integer using LuaSteamworks. This snippet highlights the use of `tostring` for conversion and `Steam.extra.parseUint64` for parsing, along with an assertion to verify equality between the original and parsed IDs. ```lua local original = Steam.user.getSteamID() local str = tostring(original) print("Your id is " .. str) local id = Steam.extra.parseUint64(str) -- equality works, even though they are different userdata instances assert(id == original) ``` -------------------------------- ### Handle Leaderboard Find Result CallResult in Lua Source: https://luasteam.readthedocs.io/en/stable/getting_started Demonstrates how Luasteam simplifies handling Steam API call results, specifically for finding a leaderboard. Instead of registering a callback, a function is passed as the last argument, receiving data and an error status. ```lua Steam.userStats.findLeaderboard("test", function(data, err) if err or not data.leaderboardFound then print("Leaderboard not found!") else print("Leaderboard found!") end end) ``` -------------------------------- ### Handle GameOverlayActivated Callback in Lua Source: https://luasteam.readthedocs.io/en/stable/getting_started Illustrates how to handle the `GameOverlayActivated_t` callback in Luasteam by defining a function named `onGameOverlayActivated` within the `friends` module. This replaces the C++ class-based callback mechanism. ```lua function Steam.friends.onGameOverlayActivated(data) if data.active then print("Steam overlay now active") else print("Steam overlay now inactive") end end ``` -------------------------------- ### Get Item Install Information - Lua Source: https://luasteam.readthedocs.io/en/stable/UGC Retrieves information about the installed content of a workshop item, including its size in bytes, the absolute path to its content folder, and the last update time. Returns false if the item is not installed, has no content, or if the folder size is zero. Calling this function marks the item as 'used' by the current player. ```lua local success, sizeOnDisk, folder, lastUpdated = Steam.UGC.getItemInstallInfo(id) ``` -------------------------------- ### Start and Submit Steamworks UGC Item Update Source: https://luasteam.readthedocs.io/en/stable/UGC Initiates the process to update an existing workshop item and submits the changes. It starts by getting an update handle, then allows setting content, title, description, and preview image before finally submitting the update with a revision description and a callback for the result. This process is essential for modifying published UGC. ```lua local function populateItem(id) local handle = Steam.UGC.startItemUpdate(Steam.utils.getAppID(), id) Steam.UGC.setItemContent(handle, rootFolder) Steam.UGC.setItemTitle(handle, "My Item") Steam.UGC.setItemDescription(handle, "A Workshop item") Steam.UGC.setItemPreview(handle, rootFolder .. '/preview.png') Steam.UGC.submitItemUpdate(handle, "First Revision", function(data, err) if err or data.result ~= 1 then print('Update failed') else print('Update successfull') end end) end ``` -------------------------------- ### UGC.subscribeItem Source: https://luasteam.readthedocs.io/en/stable/UGC Subscribes to a workshop item. The item will be downloaded and installed as soon as possible. ```APIDOC ## UGC.subscribeItem ### Description Subscribe to a workshop item. It will be downloaded and installed as soon as possible. ### Method `UGC.subscribeItem(_itemId_ , _callback_) ### Parameters #### Path Parameters - **itemId** (_uint64_) - Required - The workshop item to subscribe to. - **callback** (_function_) - Required - Called asynchronously when this function returns. See below. ### Response #### Success Response (200) - **result** (number) - The result of the operation. See EResult. - **publishedFileId** (uint64) - The workshop item that the user subscribed to. ### Request Example ```lua -- Note: itemID is uint64, not a standard Lua number! Steam.UGC.subscribeItem(itemID, function(data, err) if not err and data.result == 1 then print('Successfully subscribed to ' .. itemID .. '!') end end) ``` ``` -------------------------------- ### Initialize and Run Game Server with luasteam Source: https://luasteam.readthedocs.io/en/stable/game_server Demonstrates how to initialize a game server connection using luasteam's ISteamGameServer interface. This setup is for running a game server without the Steam client. It requires specifying ports, authentication mode, and version. ```lua 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() ``` -------------------------------- ### Begin Authentication Session - Lua Source: https://luasteam.readthedocs.io/en/stable/game_server Starts an authentication session to verify a user's Steam authentication ticket. This is part of the process for validating players connecting to the server. ```lua Steam.gameServer.beginAuthSession(authTicket, steamID) ``` -------------------------------- ### SteamWorks Networking Sockets Initialization and Authentication Source: https://luasteam.readthedocs.io/en/stable/networking_sockets Functions to initialize authentication and get its current status. ```APIDOC ## networkingSockets.initAuthentication() ### Description Indicate our desire to be ready to participate in authenticated communications. ### Method POST ### Endpoint /networkingSockets/initAuthentication ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (int) - The possible values are same as `data.status` in `networkingSockets.onAuthenticationStatus()` #### Response Example ```json { "status": 1 } ``` ## networkingSockets.getAuthenticationStatus() ### Description Get the current status of authentication. ### Method GET ### Endpoint /networkingSockets/getAuthenticationStatus ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **status** (int) - The possible values are same as `data.status` in `networkingSockets.onAuthenticationStatus()` - **msg** (string) - A human-readable message for the current status #### Response Example ```json { "status": 2, "msg": "Authenticated" } ``` ``` -------------------------------- ### Get Launch Command Line Parameters (Lua) Source: https://luasteam.readthedocs.io/en/stable/apps Retrieves the launch command line parameters passed to the game. Useful for parsing connect strings for game invites. Note: Currently has a hardcoded limit of 1024 characters in luasteam. ```lua local params = Steam.apps.getLaunchCommandLine() local connect_string = tryParseConnectString(params) if connect_string then initiateJoinGame(connect_string) end ``` -------------------------------- ### Subscribe to UGC Item in Lua Source: https://luasteam.readthedocs.io/en/stable/UGC Subscribes the user to a specific workshop item, initiating its download and installation. It requires the item's unique ID (uint64) and a callback function. The callback is triggered asynchronously with subscription results and potential errors. ```lua -- Note: itemID is uint64, not a standard Lua number! Steam.UGC.subscribeItem(itemID, function(data, err) -- itemID: uint64 if not err and data.result == 1 then print('Successfully subscribed to ' .. itemID .. '!') end end) ``` -------------------------------- ### Get Subscribed Items List - Lua Source: https://luasteam.readthedocs.io/en/stable/UGC Fetches an array of PublishedFileIds (uint64) representing all items the current user is subscribed to. Returns an empty table if called from a game server. The example demonstrates iterating through subscribed items to check their installation status and retrieve installation details. ```lua for _, id in ipairs(Steam.UGC.getSubscribedItems()) do local flag = Steam.UGC.getItemState(id) if flag.installed then print('Subscribed item is installed!') local success, sizeOnDisk, folder = Steam.UGC.getItemInstallInfo(id) print('Install location: ' .. folder) print('Install size: ' .. sizeOnDisk) elseif flag.downloading then print('Subscribed item is downloading!') else print('Subscribed item is doing something') end end ``` -------------------------------- ### gameServer.init() Source: https://luasteam.readthedocs.io/en/stable/game_server Initializes the game server API, allowing for network binding and setting server properties for Steam's server browser. ```APIDOC ## POST /gameServer/init ### Description Initializes the game server API. This function binds the server to specified IP and ports, sets the server mode, and provides version information. It's crucial for connecting to the Steam master server and appearing in server lists. ### Method POST ### Endpoint /gameServer/init ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **unIP** (int) - Required - The IP address to bind to. Use `0` to bind to all local IPv4 addresses. - **steamPort** (int) - Required - The port clients will use to connect. - **queryPort** (int) - Required - The port for communicating with a game master server. - **serverMode** (int) - Required - The server mode. Use constants from `Steam.gameServer.mode.*` (e.g., `NoAuthentication`, `Authentication`, `AuthenticationAndSecure`). - **version** (string) - Required - The version of your game in the format 'x.x.x.x'. ### Request Example ```json { "unIP": 0, "steamPort": 27015, "queryPort": 27016, "serverMode": 2, "version": "1.0.0.0" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates whether the initialization was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### ISteamInput Function Reference Source: https://luasteam.readthedocs.io/en/stable/input This section provides a reference for all functions available within the ISteamInput interface, including initialization, action set management, input data retrieval, and controller manipulation. ```APIDOC ## ISteamInput Function Reference ### Description This reference details the functions available for managing controller input using the ISteamInput interface. ### Method Various (primarily procedural calls within a Lua environment) ### Endpoint N/A (Local library functions) ### Parameters #### input.init() ##### Description Initializes the ISteamInput interface. ##### Method `input.init()` #### input.shutdown() ##### Description Shuts down the ISteamInput interface. ##### Method `input.shutdown()` #### input.activateActionSet(controllerHandle, actionSetHandle) ##### Description Activates the specified action set for the given controller. ##### Method `input.activateActionSet(controllerHandle, actionSetHandle)` #### input.activateActionSetLayer(controllerHandle, actionSetLayerHandle) ##### Description Activates an action set layer for the specified controller. ##### Method `input.activateActionSetLayer(controllerHandle, actionSetLayerHandle)` #### input.deactivateActionSetLayer(controllerHandle, actionSetLayerHandle) ##### Description Deactivates an action set layer for the specified controller. ##### Method `input.deactivateActionSetLayer(controllerHandle, actionSetLayerHandle)` #### input.deactivateAllActionSetLayers(controllerHandle) ##### Description Deactivates all active action set layers for the specified controller. ##### Method `input.deactivateAllActionSetLayers(controllerHandle)` #### input.getActiveActionSetLayers(controllerHandle) ##### Description Retrieves a list of currently active action set layers for the specified controller. ##### Method `input.getActiveActionSetLayers(controllerHandle)` #### input.getActionSetHandle(actionSetName) ##### Description Gets the handle for an action set by its name. ##### Method `input.getActionSetHandle(actionSetName)` #### input.getAnalogActionData(controllerHandle, actionHandle) ##### Description Retrieves the data for a specified analog action on a controller. ##### Method `input.getAnalogActionData(controllerHandle, actionHandle)` #### input.getAnalogActionHandle(actionName) ##### Description Gets the handle for an analog action by its name. ##### Method `input.getAnalogActionHandle(actionName)` #### input.getAnalogActionOrigins(controllerHandle, actionHandle) ##### Description Retrieves the origins for a specified analog action on a controller. ##### Method `input.getAnalogActionOrigins(controllerHandle, actionHandle)` #### input.getConnectedControllers() ##### Description Gets a bitmask of currently connected controllers. ##### Method `input.getConnectedControllers()` #### input.getControllerForGamepadIndex(index) ##### Description Gets the controller handle for a given gamepad index. ##### Method `input.getControllerForGamepadIndex(index)` #### input.getCurrentActionSet(controllerHandle) ##### Description Gets the handle of the current action set for the specified controller. ##### Method `input.getCurrentActionSet(controllerHandle)` #### input.getDigitalActionData(controllerHandle, actionHandle) ##### Description Retrieves the data for a specified digital action on a controller. ##### Method `input.getDigitalActionData(controllerHandle, actionHandle)` #### input.getDigitalActionHandle(actionName) ##### Description Gets the handle for a digital action by its name. ##### Method `input.getDigitalActionHandle(actionName)` #### input.getDigitalActionOrigins(controllerHandle, actionHandle) ##### Description Retrieves the origins for a specified digital action on a controller. ##### Method `input.getDigitalActionOrigins(controllerHandle, actionHandle)` #### input.getGlyphForActionOrigin_Legacy(eOrigin, eActionSetType) ##### Description Gets the glyph for a specific action origin (legacy). ##### Method `input.getGlyphForActionOrigin_Legacy(eOrigin, eActionSetType)` #### input.getInputTypeForHandle(inputHandle) ##### Description Gets the input type for a given input handle. ##### Method `input.getInputTypeForHandle(inputHandle)` #### input.getMotionData(controllerHandle, actionHandle) ##### Description Retrieves motion data for a specified action on a controller. ##### Method `input.getMotionData(controllerHandle, actionHandle)` #### input.getStringForActionOrigin(origin) ##### Description Gets a string representation of an action origin. ##### Method `input.getStringForActionOrigin(origin)` #### input.runFrame() ##### Description Runs a frame of input processing. ##### Method `input.runFrame()` #### input.setLEDColor(controllerHandle, r, g, b) ##### Description Sets the LED color for the specified controller. ##### Method `input.setLEDColor(controllerHandle, r, g, b)` #### input.showBindingPanel(controllerHandle) ##### Description Shows the binding panel for the specified controller. ##### Method `input.showBindingPanel(controllerHandle)` #### input.stopAnalogActionMomentum(controllerHandle, actionHandle) ##### Description Stops analog action momentum for the specified controller and action. ##### Method `input.stopAnalogActionMomentum(controllerHandle, actionHandle)` #### input.legacy_triggerHapticPulse(controllerHandle, unk1, unk2) ##### Description Triggers a haptic pulse on the controller (legacy method). ##### Method `input.legacy_triggerHapticPulse(controllerHandle, unk1, unk2)` #### input.legacy_triggerRepeatedHapticPulse(controllerHandle, unk1, unk2, unk3) ##### Description Triggers a repeated haptic pulse on the controller (legacy method). ##### Method `input.legacy_triggerRepeatedHapticPulse(controllerHandle, unk1, unk2, unk3)` #### input.triggerVibration(controllerHandle, leftSpeed, rightSpeed) ##### Description Triggers vibration on the specified controller. ##### Method `input.triggerVibration(controllerHandle, leftSpeed, rightSpeed)` #### input.getActionOriginFromXboxOrigin(controllerType, xboxOrigin) ##### Description Converts an Xbox origin to a local input origin. ##### Method `input.getActionOriginFromXboxOrigin(controllerType, xboxOrigin)` #### input.translateActionOrigin(controllerHandle, origin) ##### Description Translates an action origin for the specified controller. ##### Method `input.translateActionOrigin(controllerHandle, origin)` #### input.getDeviceBindingRevision(controllerHandle, actionOrigin) ##### Description Gets the binding revision for a device on the controller. ##### Method `input.getDeviceBindingRevision(controllerHandle, actionOrigin)` #### input.getRemotePlaySessionID(controllerHandle) ##### Description Gets the Remote Play session ID for the specified controller. ##### Method `input.getRemotePlaySessionID(controllerHandle)` ### Request Example ```json { "example": "No specific request body for procedural calls, refer to function parameters." } ``` ### Response #### Success Response (200) - **result** (any) - The result of the function call, type depends on the function. #### Response Example ```json { "example": "Varies based on the function called. For example, getConnectedControllers() might return a number representing connected controllers." } ``` ``` -------------------------------- ### Rich Presence Localization Example - VDF Source: https://luasteam.readthedocs.io/en/stable/friends An example VDF file demonstrating localization for Rich Presence tokens. This setup allows for managing custom display text associated with specific rich presence keys. ```vdf "lang" { "english" { "tokens" { "#StatusFull" "%text%" } } } ``` -------------------------------- ### Input API Source: https://luasteam.readthedocs.io/en/stable/genindex Functions for handling controller input and configuration. ```APIDOC ## Input API ### Description Manages controller input, including activating action sets, retrieving input data, and configuring controller LEDs and haptics. ### Method Various (GET, POST, PUT) ### Endpoints - `/input/activateActionSet` - `/input/activateActionSetLayer` - `/input/deactivateActionSetLayer` - `/input/deactivateAllActionSetLayers` - `/input/getActionOriginFromXboxOrigin` - `/input/getActionSetHandle` - `/input/getActiveActionSetLayers` - `/input/getAnalogActionData` - `/input/getAnalogActionHandle` - `/input/getAnalogActionOrigins` - `/input/getConnectedControllers` - `/input/getControllerForGamepadIndex` - `/input/getCurrentActionSet` - `/input/getDeviceBindingRevision` - `/input/getDigitalActionData` - `/input/getDigitalActionHandle` - `/input/getDigitalActionOrigins` - `/input/getGamepadIndexForController` - `/input/getGlyphForActionOrigin_Legacy` - `/input/getInputTypeForHandle` - `/input/getMotionData` - `/input/getRemotePlaySessionID` - `/input/getStringForActionOrigin` - `/input/init` - `/input/legacy_triggerHapticPulse` - `/input/legacy_triggerRepeatedHapticPulse` - `/input/runFrame` - `/input/setLEDColor` - `/input/showBindingPanel` - `/input/shutdown` - `/input/stopAnalogActionMomentum` - `/input/translateActionOrigin` - `/input/triggerVibration` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - `actionSetHandle` (handle) - Handle to an action set. - `actionOrigin` (origin) - Origin of an action. - `player` (integer) - Player index. - `color` (array) - RGB color values [R, G, B]. - `intensity` (float) - Vibration intensity. - `duration` (float) - Vibration duration. ### Request Example ```json { "actionSetHandle": "handle_to_gameplay_set", "player": 0 } ``` ### Response #### Success Response (200) - `data` (object) - Input data for the requested action. - `connectedControllers` (integer) - Number of connected controllers. - `bindingRevision` (integer) - The device binding revision. #### Response Example ```json { "data": { "value": 0.5, "bActive": true } } ``` ``` -------------------------------- ### Initialize Relay Network Access - Lua Source: https://luasteam.readthedocs.io/en/stable/networking_utils Initializes the relay network for features like P2P connections. Call this proactively or to force a retry. Initialization is typically completed within seconds. Dedicated servers in known data centers do not need this unless using P2P. ```lua Steam.networkingUtils.initRelayNetworkAccess() ``` -------------------------------- ### input.init() and input.shutdown() Source: https://luasteam.readthedocs.io/en/stable/input Initialize and shut down the ISteamInput interface. init() must be called before using other input functions, and shutdown() must be called when ending usage. ```APIDOC ## input.init() ### Description Must be called when starting use of the ISteamInput interface. ### Method Not applicable (Lua function) ### Parameters #### Path Parameters - **explicitlyCallRunFrame** (boolean) - If true, you will need to manually call input.runFrame() each frame, otherwise Steam Input will call it automatically when Steam.runCallbacks() is called. ### Response #### Success Response (true) - Returns (boolean) Always returns true. ### SteamWorks Equivalent Init --- ## input.shutdown() ### Description Must be called when ending use of the ISteamInput interface. ### Method Not applicable (Lua function) ### Parameters None ### Response #### Success Response (true) - Returns (boolean) Always returns true. ### SteamWorks Equivalent Shutdown ``` -------------------------------- ### Get Item State - Lua Source: https://luasteam.readthedocs.io/en/stable/UGC Retrieves the current state flags for a given workshop item. Flags indicate subscription status, installation status, download progress, and whether the item is a legacy item. Returns nil if the item is not tracked on the client. ```lua local itemState = Steam.UGC.getItemState(publishedFileId) ``` -------------------------------- ### Check DLC Installation (Lua) Source: https://luasteam.readthedocs.io/en/stable/apps Checks if the user owns and has installed a specific DLC. Requires the App ID of the DLC as a number. Returns a boolean: true if owned and installed, false otherwise. ```lua if Steam.apps.isDlcInstalled(12345) then -- Unlock game content end ``` -------------------------------- ### Get Digital Action Data Source: https://luasteam.readthedocs.io/en/stable/input Gets the current state of a digital action for a given controller and action handle. ```APIDOC ## GET /input/getDigitalActionData ### Description Gets the current state of a digital action for a given controller and action handle. ### Method GET ### Endpoint /input/getDigitalActionData ### Parameters #### Query Parameters - **inputHandle** (uint64) - Required - The handle of the controller you want to query. Obtained from `input.getConnectedControllers()`. - **digitalActionHandle** (uint64) - Required - The handle of the digital action you want to query. This can be obtained from `input.getDigitalActionHandle()`. ### Response #### Success Response (200) - **actionData** (table) - The current state (InputDigitalActionData, see InputDigitalActionData_t) of the supplied digital game action. ``` -------------------------------- ### Handle New URL Launch Parameters (Lua) Source: https://luasteam.readthedocs.io/en/stable/apps Callback function that is invoked when a steam://run/// URL is navigated to while the game is running. Use apps.getLaunchCommandLine() to retrieve the parameters. ```lua -- This is a callback, implementation details would be within an event handler. -- Example structure: -- Steam.apps.onNewUrlLaunchParameters(function() -- local params = Steam.apps.getLaunchCommandLine() -- -- Process parameters -- end) ``` -------------------------------- ### Get Controller For Gamepad Index Source: https://luasteam.readthedocs.io/en/stable/input Gets the controller handle associated with a specific gamepad index. This is useful when the controller is emulating a gamepad. ```APIDOC ## GET /input/getControllerForGamepadIndex ### Description Gets the controller handle associated with a specific gamepad index. This is useful when the controller is emulating a gamepad. ### Method GET ### Endpoint /input/getControllerForGamepadIndex ### Parameters #### Query Parameters - **index** (uint64) - Required - The gamepad index to query. ### Response #### Success Response (200) - **inputHandle** (uint64) - The handle of the associated controller. ``` -------------------------------- ### LuaSteam Sockets Server Example Source: https://luasteam.readthedocs.io/en/stable/networking_sockets This Lua code sets up a basic server using Steam networking sockets. It listens on a specified IP address and port for incoming connections, accepts them, and sends a welcome message. The server also handles connection status changes, including disconnections. It continuously processes callbacks and receives messages from connected clients. ```lua local Steam = require 'luasteam' local connections = {} local server = nil Steam.init() Steam.networkingSockets.initAuthentication() function Steam.networkingSockets.onConnectionChanged(data) print ('Connection changed', data.connection, data.state, data.state_old, data.endReason, data.debug) if data.state == "Connecting" then Steam.networkingSockets.acceptConnection(data.connection) end if data.state == "Connected" then connections[data.connection] = true Steam.networkingSockets.sendMessageToConnection(data.connection, "Hello client! This is the server! Welcome!", Steam.networkingSockets.flags.Send_Reliable) end if data.state == "ClosedByPeer" or data.state == "ProblemDetectedLocally" then print(data.connection, data.state, data.endReason, data.debug) Steam.networkingSockets.closeConnection(data.connection) connections[data.connection] = nil end end function Steam.networkingSockets.onAuthenticationStatus(data) if data.status == 100 and not connection then server = Steam.networkingSockets.createListenSocketIP("[::]:55556") print("Listening on port 55556") end end local run = true while run do Steam.runCallbacks() for conn,_ in pairs(connections) do local n, messages = Steam.networkingSockets.receiveMessagesOnConnection(conn) if n > 0 then for j,m in ipairs(messages) do print("received message", j, m, "from connection", conn, type(j)) run = false end end end end for conn,_ in pairs(connections) do Steam.networkingSockets.closeConnection(conn) end Steam.shutdown() ``` -------------------------------- ### Get Glyph For Action Origin (Legacy) Source: https://luasteam.readthedocs.io/en/stable/input Gets a local path to an art asset for an on-screen glyph corresponding to a specific action origin. This is a legacy function. ```APIDOC ## GET /input/getGlyphForActionOrigin_Legacy ### Description Gets a local path to an art asset for an on-screen glyph corresponding to a specific action origin. This is a legacy function. ### Method GET ### Endpoint /input/getGlyphForActionOrigin_Legacy ### Parameters #### Query Parameters - **origin** (string) - Required - The action origin (e.g., LeftStick_Click, X, B). See EInputActionOrigin for reference. ### Response #### Success Response (200) - **glyphPath** (string) - A local path to art for on-screen glyph for a particular origin. ``` -------------------------------- ### Application API Source: https://luasteam.readthedocs.io/en/stable/genindex Functions related to the current game application and its launch parameters. ```APIDOC ## Application API ### Description Provides functions to interact with the current game application, such as retrieving language settings, command-line arguments, and DLC installation status. ### Method Various (primarily GET-like operations) ### Endpoints - `/apps/getCurrentGameLanguage` - `/apps/getLaunchCommandLine` - `/apps/isDlcInstalled` - `/apps/onNewUrlLaunchParameters` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - `language` (string) - The current game language. - `commandLine` (string) - The game's launch command line. - `isInstalled` (boolean) - Whether the DLC is installed. #### Response Example ```json { "language": "english" } ``` ``` -------------------------------- ### Initialize Network Connection with Config Options - Lua Source: https://luasteam.readthedocs.io/en/stable/networking_sockets This Lua code snippet demonstrates how to initialize a network connection using a table of configuration options. It highlights parameters like Unencrypted, IP_AllowWithoutAuth, and NagleTime. Ensure correct integer values are used for each option. ```lua local connection_config = { Unencrypted = 2, IP_AllowWithoutAuth = 1, NagleTime = 0 } -- Assume SteamNetworking is available and has a function like InitializeConnection -- SteamNetworking.InitializeConnection(connection_config) ``` -------------------------------- ### Get Motion Data Source: https://luasteam.readthedocs.io/en/stable/input Retrieves raw motion data for a specified controller. ```APIDOC ## GET /input/getMotionData ### Description Retrieves raw motion data for a specified controller. ### Method GET ### Endpoint /input/getMotionData ### Parameters #### Query Parameters - **inputHandle** (uint64) - Required - The handle of the controller you want to get motion data for. Obtained from `input.getConnectedControllers()`. ### Response #### Success Response (200) - **motionData** (table) - A table (see InputMotionData_t) filled with raw motion data for the specified controller. ``` -------------------------------- ### gameServer.beginAuthSession() Source: https://luasteam.readthedocs.io/en/stable/game_server Begins the authentication process for a user session, typically used to verify a user's entitlement or presence. ```APIDOC ## POST /gameServer/beginAuthSession ### Description Initiates the authentication process for a specific user session. This is often used to verify if a user has the necessary entitlements to join the game or server. ### Method POST ### Endpoint /gameServer/beginAuthSession ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **authTicket** (string) - Required - The authentication ticket for the user, provided as a hexadecimal string. - **steamID** (uint64) - Required - The Steam ID of the user whose auth ticket is being verified. This should be the same user who generated the ticket. ### Request Example ```json { "authTicket": "0x1234567890ABCDEF", "steamID": "76561197960265728" } ``` ### Response #### Success Response (200) No specific fields are returned on success. The result of the authentication will be delivered via callbacks. #### Response Example ```json {} ``` ``` -------------------------------- ### GET /userStats/getLeaderboardSortMethod Source: https://luasteam.readthedocs.io/en/stable/user_stats Retrieves the sort method (Ascending/Descending) of a leaderboard. ```APIDOC ## GET /userStats/getLeaderboardSortMethod ### Description Returns the sort order (Ascending or Descending) of the specified leaderboard handle. ### Method GET ### Endpoint `/userStats/getLeaderboardSortMethod` ### Parameters #### Query Parameters - **steamLeaderboard** (uint64) - Required - A leaderboard handle obtained from `userStats.findLeaderboard()` or `userStats.findOrCreateLeaderboard()`. ### Request Example ```javascript let handle = /* ... get leaderboard handle ... */; let sortMethod = Steam.userStats.getLeaderboardSortMethod(handle); console.log('Sort method:', sortMethod); ``` ### Response #### Success Response (200) - **(string?)** - The sort method of the leaderboard, either 'Ascending' or 'Descending'. Returns `nil` if the leaderboard handle is invalid. ``` -------------------------------- ### Log On to Steam - Lua Source: https://luasteam.readthedocs.io/en/stable/game_server Authenticates the game server with Steam using a provided access token. Successful authentication triggers callbacks for connection status. This is required for servers that need to be listed or authenticated by Steam. ```lua local accessToken = "abcdef123456" -- Access token generated through steam Steam.gameServer.logOn(accessToken) ``` -------------------------------- ### GET /userStats/getLeaderboardEntryCount Source: https://luasteam.readthedocs.io/en/stable/user_stats Retrieves the total number of entries in a leaderboard. ```APIDOC ## GET /userStats/getLeaderboardEntryCount ### Description Returns the total number of entries currently in the specified leaderboard. ### Method GET ### Endpoint `/userStats/getLeaderboardEntryCount` ### Parameters #### Query Parameters - **steamLeaderboard** (uint64) - Required - A leaderboard handle obtained from `userStats.findLeaderboard()` or `userStats.findOrCreateLeaderboard()`. ### Request Example ```javascript let handle = /* ... get leaderboard handle ... */; let entryCount = Steam.userStats.getLeaderboardEntryCount(handle); console.log('Number of entries:', entryCount); ``` ### Response #### Success Response (200) - **(number)** - The number of entries in the leaderboard. Returns 0 if the leaderboard handle is invalid. ``` -------------------------------- ### GET /userStats/getLeaderboardName Source: https://luasteam.readthedocs.io/en/stable/user_stats Retrieves the name of a given leaderboard handle. ```APIDOC ## GET /userStats/getLeaderboardName ### Description Returns the name associated with a leaderboard handle. ### Method GET ### Endpoint `/userStats/getLeaderboardName` ### Parameters #### Query Parameters - **steamLeaderboard** (uint64) - Required - A leaderboard handle obtained from `userStats.findLeaderboard()` or `userStats.findOrCreateLeaderboard()`. ### Request Example ```javascript let handle = /* ... get leaderboard handle ... */; let name = Steam.userStats.getLeaderboardName(handle); console.log('Leaderboard name:', name); ``` ### Response #### Success Response (200) - **(string)** - The name of the leaderboard. Returns an empty string if the leaderboard handle is invalid. ``` -------------------------------- ### LuaSteam Sockets Client Example Source: https://luasteam.readthedocs.io/en/stable/networking_sockets This Lua code implements a basic client for the Steam networking sockets. It initializes the library, establishes a connection to a specified IP address and port, sends messages, and receives responses. Ensure the server is running before executing the client. It handles connection status changes and message reception. ```lua local Steam = require 'luasteam' local connection = nil Steam.init() Steam.networkingSockets.initAuthentication() function Steam.networkingSockets.onConnectionChanged(data) print ('Connection changed', data.connection, data.state, data.state_old, data.endReason, data.debug) end function Steam.networkingSockets.onAuthenticationStatus(data) if data.status == 100 and not connection then connection = Steam.networkingSockets.connectByIPAddress("127.0.0.1:55556") end end local run = true local counter = 0 local msg_rec = false while run do Steam.runCallbacks() if connection then local n, messages = Steam.networkingSockets.receiveMessagesOnConnection(connection) if n > 0 then for j,m in ipairs(messages) do print("received message", j, m, "from connection", connection, type(j)) Steam.networkingSockets.sendMessageToConnection(connection, "Hello server! This is the client! Thank you!", Steam.networkingSockets.flags.Send_Reliable) msg_rec = true end end end if msg_rec then counter = counter + 1 if counter > 10000 then -- you might have to increase this if the client shuts down faster than the message can be sent run = false end end end if connection then Steam.networkingSockets.closeConnection(connection) end Steam.shutdown() ``` -------------------------------- ### Get Digital Action Handle Source: https://luasteam.readthedocs.io/en/stable/input Retrieves the handle for a digital action based on its string identifier. ```APIDOC ## GET /input/getDigitalActionHandle ### Description Retrieves the handle for a digital action based on its string identifier. ### Method GET ### Endpoint /input/getDigitalActionHandle ### Parameters #### Query Parameters - **actionName** (string) - Required - The string identifier of the digital action defined in the game’s VDF file. ### Response #### Success Response (200) - **actionHandle** (uint64) - The handle (InputDigitalActionHandle, ie uint64) of the specified digital action. ``` -------------------------------- ### Get Current Action Set Source: https://luasteam.readthedocs.io/en/stable/input Retrieves the handle of the currently active action set for a specified controller. ```APIDOC ## GET /input/getCurrentActionSet ### Description Retrieves the handle of the currently active action set for a specified controller. ### Method GET ### Endpoint /input/getCurrentActionSet ### Parameters #### Query Parameters - **inputHandle** (uint64) - Required - The handle of the controller you want to query. Obtained from `input.getConnectedControllers()`. ### Response #### Success Response (200) - **actionSetHandle** (uint64) - The InputActionSetHandle (uint64) handle of the action set activated for the specified controller. ``` -------------------------------- ### Initialize Game Server - Lua Source: https://luasteam.readthedocs.io/en/stable/game_server Initializes the game server API, allowing for network socket operations and utility functions. It requires specifying IP address, ports, server mode, and game version. This function is crucial for connecting to the Steam master server and enabling server browser features. ```lua local result = Steam.gameServer.init(0, gamePort, queryPort, Steam.gameServer.mode.Authentication, "0.0.0.1") ``` -------------------------------- ### gameServer.logOn() Source: https://luasteam.readthedocs.io/en/stable/game_server Authenticates the game server with Steam using a provided authentication token. ```APIDOC ## POST /gameServer/logOn ### Description Authenticates the game server to the Steam network using a provided authentication token. This enables features like server listing and secure connections. Triggers callbacks related to connection status. ### Method POST ### Endpoint /gameServer/logOn ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **token** (string) - Required - The authentication token for your server, generated through Steam. ### Request Example ```json { "token": "abcdef123456" } ``` ### Response #### Success Response (200) No specific fields are returned on success. #### Response Example ```json {} ``` ``` -------------------------------- ### SteamWorks Connection Management Source: https://luasteam.readthedocs.io/en/stable/networking_sockets Functions for getting connection information, creating, destroying, and setting poll groups for connections. ```APIDOC ## networkingSockets.getConnectionInfo(connection) ### Description Get basic information about the status of a connection. ### Method GET ### Endpoint /networkingSockets/getConnectionInfo/{connection} ### Parameters #### Path Parameters - **connection** (int) - The connection to get info about ### Request Example ```json {} ``` ### Response #### Success Response (200) - **code** (int) - See the return values of `networkingSockets.connectByIPAddress()` for code meanings. - **info** (string) - Connection detail string #### Response Example ```json { "code": 0, "info": "Connection active" } ``` ## networkingSockets.createPollGroup() ### Description Create a new poll group. You can use this to receive messages from multiple connections at once. You need to delete this if you don’t need it anymore with `networkingSockets.destroyPollGroup()`. ### Method POST ### Endpoint /networkingSockets/createPollGroup ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **pollGroup** (int) - id of the poll group #### Response Example ```json { "pollGroup": 123 } ``` ## networkingSockets.destroyPollGroup(pollGroup) ### Description Destroy a poll group. Do this before you shut down. ### Method DELETE ### Endpoint /networkingSockets/destroyPollGroup/{pollGroup} ### Parameters #### Path Parameters - **pollGroup** (int) - The poll group to destroy ### Request Example ```json {} ``` ### Response #### Success Response (200) - **success** (boolean) - `true` if it was successful #### Response Example ```json { "success": true } ``` ## networkingSockets.setConnectionPollGroup(connection, pollGroup) ### Description Assign a connection to a poll group. After that, you can poll this connection's messages through the poll group with `networkingSockets.receiveMessagesOnPollGroup()`. ### Method PUT ### Endpoint /networkingSockets/setConnectionPollGroup ### Parameters #### Request Body - **connection** (int) - The connection to add to the poll group - **pollGroup** (int) - The poll group ### Request Example ```json { "connection": 456, "pollGroup": 123 } ``` ### Response #### Success Response (200) - **success** (boolean) - `true` if it was successful #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Input API - Show Binding Panel Source: https://luasteam.readthedocs.io/en/stable/input Displays the controller binding panel for a specified controller handle. This allows users to configure controller inputs. ```APIDOC ## POST /input/showBindingPanel ### Description Displays the controller binding panel for a specified controller. ### Method POST ### Endpoint `/input/showBindingPanel` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **inputHandle** (uint64) - Required - The handle of the controller for which to display the binding panel. Obtained from `input.getConnectedControllers()`. ### Request Example ```json { "inputHandle": 1234567890 } ``` ### Response #### Success Response (200) - **success** (boolean) - true if the binding panel was successfully shown, false otherwise. #### Response Example ```json { "success": true } ``` #### Error Response - **error** (string) - Details about the error if the panel could not be shown (e.g., overlay disabled, not in Big Picture Mode). ``` -------------------------------- ### Utils API Source: https://luasteam.readthedocs.io/en/stable/genindex Utility functions for application information. ```APIDOC ## Utils API ### Description Provides utility functions, such as retrieving the current application ID. ### Method GET ### Endpoints - `/utils/getAppID` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - `appID` (integer) - The current application ID. #### Response Example ```json { "appID": 123450 } ``` ``` -------------------------------- ### GET /userStats/getLeaderboardDisplayType Source: https://luasteam.readthedocs.io/en/stable/user_stats Retrieves the display type (Numeric, TimeSeconds, TimeMilliSeconds) of a leaderboard. ```APIDOC ## GET /userStats/getLeaderboardDisplayType ### Description Returns the display type of the leaderboard handle, indicating how scores are represented (e.g., numeric, time in seconds, time in milliseconds). ### Method GET ### Endpoint `/userStats/getLeaderboardDisplayType` ### Parameters #### Query Parameters - **steamLeaderboard** (uint64) - Required - A leaderboard handle obtained from `userStats.findLeaderboard()` or `userStats.findOrCreateLeaderboard()`. ### Request Example ```javascript let handle = /* ... get leaderboard handle ... */; let displayType = Steam.userStats.getLeaderboardDisplayType(handle); console.log('Display type:', displayType); ``` ### Response #### Success Response (200) - **(string?)** - The display type of the leaderboard, one of 'Numeric', 'TimeSeconds', or 'TimeMilliSeconds'. Returns `nil` if the leaderboard handle is invalid. ``` -------------------------------- ### Get Gamepad Index For Controller Source: https://luasteam.readthedocs.io/en/stable/input Retrieves the gamepad index associated with a controller handle, if the controller is emulating a gamepad. ```APIDOC ## GET /input/getGamepadIndexForController ### Description Retrieves the gamepad index associated with a controller handle, if the controller is emulating a gamepad. ### Method GET ### Endpoint /input/getGamepadIndexForController ### Parameters #### Query Parameters - **inputHandle** (uint64) - Required - The handle of the controller you want to get a gamepad index for. Obtained from `input.getConnectedControllers()`. ### Response #### Success Response (200) - **gamepadIndex** (uint64) - The associated gamepad index for the specified controller, if emulating a gamepad. ```