Online Subsystem Steam

Online Subsystem Steam的概述,包括如何设置项目以在Valve的Steam平台上分发。

Windows
MacOS
Linux

Contributors:Valve

Online Subsystem Steam API 使您可以将虚幻引擎4(UE4)应用程序发布到Valve的Steam平台Steam 模块的主要目的是帮助您通过一组功能(如媒介和通栏广告)将应用程序分发给Steam用户。 此外,Steam模块实现多个由Online Subsystem公开的接口,支持Steamworks Software Development Kit(SDK)提供的大多数功能。

部分可用的Steam接口包括:

  • Matchmaking(Lobbies和GameServer API)

  • Leaderboards

  • Achievements

  • Voice

  • UserCloud

  • SharedCloud

  • External UI

请参考Online Subsystem Steam API参考以了解当前可用的Steam接口的更完整列表。

满足Valve的要求

Steam Subsystem需要通过Valve Steamworks进行额外设置。 请联系Valve并参考Steamworks SDK文档以确保您的应用程序满足Valve的要求,然后再尝试将Steam与UE4一起使用。

下载Steamworks

如果您的应用程序满足Valve的要求,请继续并下载最新版Steamworks SDK。 SDK需要解压并复制到/YourUnrealEnginePath/Engine/Source/ThirdParty/Steamworks/Steam[当前版本]/sdk

如果要更新项目的Steamworks SDK,请确保更新项目Steamworks路径中的[当前版本]
/YourUnrealEnginePath/Engine/Source/ThirdParty/Steamworks/Steam[当前版本]/sdk
您还需要更新Steamworks.build.cs,它位于项目目录中。
SteamworksCSFile.png
在本示例中,[当前版本]格式为v139

编译UE4

如果您从源代码编译虚幻引擎4,应采取以下步骤:

  1. 打开“OnlineSubsystemSteamPrivatePCH.h”(位于“..\..\Plugins\Online\OnlineSubsystemSteam\Source\Private\”中),在这里您会看到以下代码,这行代码定义Steamworks SDK的根目录位置:

    define STEAM_SDK_ROOT_PATH TEXT("Binaries/ThirdParty/Steamworks")

  2. 您需要将这一行修改为:

    define STEAM_SDK_VER TEXT("Steam[Current Version]")

设置Steamworks SDK

对预编译版本引擎使用Steam应只需要将部分动态链接库从Valve SDK复制到相应的文件夹。如果您想要根据源代码重新编译引擎,还需要将SDK放在合适的位置。现在,将相关的可重新分发文件从SDK istributable_bin/目录复制到以下位置:

部分64位库位于Steam客户端目录中(在编写本文时,Valve没有将所有库包含在SDK中)。

/YourUnrealEnginePath/Engine/Binaries/ThirdParty/Steamworks/Steam[Current Version]/Win64

  • steam_api64.dll

  • steamclient64.dll

  • tier0_s64.dll

  • vstdlib_s64.dll

/YourUnrealEnginePath/Engine/Binaries/ThirdParty/Steamworks/Steam[Current Version]/Win32

  • steam_api.dll

  • steamclient.dll

  • tier0_s.dll

  • vstdlib_s.dll

只有在显式链接不允许为专用服务器版本使用 "-force_steamclient_link" 标签时,才会需要 tier0_s.dllvstdlib_s.dll 文件。客户端版本永远不会需要这些文件。

在UE4 4.22及更早版本中: /YourUnrealEnginePath/EngineOrGameFolder/Binaries/Mac/YourGame.app/Contents/MacOS

  • libsteam_api.dylib (from /redistributable_bin/osx32 - the dynamic library (*.dylib) has both 32 and 64 bit support)

从UE4 4.23版本开始,Mac用户还必须运行以下命令: /YourUnrealEnginePath/Engine/Binaries/ThirdParty/Steamworks/Steam[Current Version]/Mac/

  • libsteam_api.dylib, generated by running the following command:

    install_name_tool -id @rpath/libsteam_api.dylib /redistributable_bin/osx32/libsteam_api.dylib

Linux用户必须随可执行文件一起链接并分发以下文件。

/YourUnrealEnginePath/Engine/Binaries/ThirdParty/Steamworks/Steam[Current Version]/i686-unknown-linux-gnu/libsteam_api.so

  • redistibutable_bin/linux32/libsteam_api.so

/YourUnrealEnginePath/Engine/Binaries/ThirdParty/Steamworks/Steam[Current Version]/x86_64-unknown-linux-gnu/libsteam_api.so

  • redistibutable_bin/linux64/libsteam_api.so

Steam应用ID

所有使用Steam Online Subsystem的游戏都必须有有效的应用程序ID,因为如果Steamworks API不知道您应用程序的Steam应用ID,就无法初始化。 在初始化Steam之前,UE4将生成steam_appid.txt(在正常关闭引擎时,UE4会删除这个文件)。 需要注意的是,steam_appid.txt必须位于应用程序可执行文件所在的目录,因为Steam将在当前工作目录寻找这个文本文件。 此外,该文件不应包含在任何Steam映像中。

如果您打开steam_appid.txt,将会看到 SteamDevAppId 条目,这个字段向Steam暗示应用程序ID。 这样就无需使用Steam客户端(尽管它必须运行)启动游戏。

如果想要测试应用程序,可以使用 SteamDevAppId 480,这是所有开发者共享的测试应用ID。 虽然您可以使用之前提到的测试应用ID来测试大都数Steam接口,但应用程序需要有Steam应用ID才能发布。

发布构建版

在发布构建版时,引擎会检查以确保登录用户正确订阅了游戏,如果引擎测试返回false,则会关闭(这是帮助保护游戏的一种方式)。 此外,使用Steam DRM(请参阅Steamworks SDK)应进一步保护游戏不被篡改。

配置应用程序设置

如果您使用 虚幻项目浏览器 创建新项目,那么DefaultEngine.ini中应该没有 Online Subsystem 设置;但如果您要修改我们的某个样本项目,则 Online Subsystem 设置可能已经存在。

现在,您已经为应用程序设置了Steamworks SDK(同时设置Steam应用ID),便已准备好了配置应用程序设置以使用Online Subsystem Steam。

步骤

  1. 打开项目的DefaultEngine.ini文件,并添加以下设置:

    [/Script/Engine.GameEngine] +NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

    NetDriverDefinitions 描述了可供UE4使用的网络驱动器,并添加了以下属性:

    • DefName 是该网络驱动器定义的唯一名称。

    • DriverClassName 是主网络驱动器的类名称。

    • DriverClassNameFallBack 是退却网络驱动器的类名(如果主网络驱动器类初始化失败)。

  2. 为了告诉UE4使用Online Subsystem Steam,添加以下设置:

    [OnlineSubsystem] DefaultPlatformService=Steam

  3. 现在,您已经告诉UE4,您希望应用程序使用Steam Online Subsystem,接下来需要添加以下设置来配置 OnlineSubsystemSteam 模块:

    [OnlineSubsystemSteam] bEnabled=true SteamDevAppId=480

  4. 最后,需要为应用程序连接在网络驱动器中指定Steam类:

    [/Script/OnlineSubsystemSteam.SteamNetDriver] NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"

最终结果

在本简短指南结束后,您的应用程序DefaultEngine.ini文件应类似于以下设置块。如果你想查看其他项目是如何设置的并使用Online Subsystem,请参考我们的样本项目库。

完成的设置

DefaultEngine.ini

[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
DefaultPlatformService=Steam

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"

Servers and Lobbies

Steam supports peer-to-peer matchmaking (for both dedicated and listen server games) through lobbies, and provides the ability to run dedicated servers. Lobbies give users the ability to learn information about game servers, and are usually used to convey game-specific information about listen server games, such as what map or mode is being played. Users can also see the number of other users connected to a lobby without joining, through the matchmaking system. Dedicated servers are separate binaries from lobbies, as their task is to run and host the server-side portion of the game. For more information about Steam's features, implementation, or developer interface, please refer to the partner documentation on the Steam site.

Lobby Details

Lobbies are essentially chat rooms that exist as peer-to-peer instances on Steam's backend service. Unlike servers, no information about a lobby is available before joining, such as ping times or current number of other users. They are typically used for listen servers. To set up a lobby, set the bUsesPresence flag to true.

Server Details

To set up a server instance, make sure the bUsesPresence flag is false. Dedicated servers require the following three macros, and all three must match the values from Steam's dedicated server tool page, found on the partner panel. The Steam network will not show the dedicated server if these values do not match:

UE4 Macro

Steam Name

Description

UE4_PROJECT_STEAMPRODUCTNAME

STEAMPRODUCTNAME

Valve recommends that this be a build ID, although it is typical to use your AppID (as a string), or a light product name without any extra symbols.

Changing this field, such as when updating your build ID, will cause Steam to ignore all active servers with the old name for matchmaking purposes, and will require you to modify your tool information in the partner backend.

UE4_PROJECT_STEAMGAMEDIR

STEAMGAMEDIR

This is usually the folder name of your game, and cannot contain spaces or symbols. It is not required for this to be a folder name at all, as long as it is a name without spaces or symbols.

UE4_PROJECT_STEAMGAMEDESC

STEAMGAMEDESC

Valve recommends that you set this as the full name of your product.

UE4_PROJECT_STEAMSHIPPINGID

N/A

To launch outside of Steam in UE4 version 4.22 and higher, this macro must contain the product's Steam ID.

In UE4 version 4.22, you can specify these values in your game's Target.cs file. You can also write the Steam ID into a build by defining UE4_PROJECT_STEAMSHIPPINGID. All build configurations require this, and you cannot launch outside of Steam without it.

For versions before 4.22, edit OnlineSessionAsyncServerSteam.cpp so that it contains your game's values.

For information about distributing a dedicated server build, please refer to Steam's partner documentation.

Steam在线验证

Steam使用一种特殊的验证系统,用于控制对平台提供的部分独特服务器相关功能的访问,如广告服务器和玩家计数、检索禁令列表和做出反应(发行商和Valve反作弊禁令)和执行许可证检查。 虚幻引擎4允许通过FOnlineAuthSteam类与这个功能连接。 应用程序设置为使用Steam Online Subsystem后,就可以启用 SteamAuth 包处理程序组件来利用这些功能。

启用SteamAuth

要启用SteamAuth,并将以下内容添加到“DefaultEngine.ini”或者针对每一个打算支持Steam在线验证的平台,添加到特定于平台的引擎.ini文件(如“WindowsEngine.ini”、“LinuxEngine.ini”或“MacEngine.ini”):

[PacketHandlerComponents]
+Components=OnlineSubsystemSteam.SteamAuthComponentModuleInterface

启用后,就可以使用Steam Online Subsystem接口(SteamOSS)功能GetAuthInterface来访问SteamAuth功能。

启用SteamAuth将会使应用程序对所有加入的玩家运行验证程序(针对Steam服务)。默认情况下,SteamAuth将没有通过这项检查的玩家踢出游戏,但这个行为可以被覆盖。

SteamAuth委托

SteamAuth系统中有两个开发者可能希望覆盖的委托:OverrideFailureDelegateOnAuthenticationResultDelegate

当玩家尝试加入服务器而没有通过Steam验证时,或者玩家在会话期间失去了Steam验证,通过玩家的FUniqueNetId调用OverrideFailureDelegate。 默认情况下,SteamAuth会将玩家踢出游戏。 但是,如果该委托受到约束,则默认行为将被暂停,因此开发者必须在仍需要这个行为时手动将玩家踢出。

OnAuthenticationResultDelegate处理来自Steam验证服务的响应,提供玩家的FUniqueNetId和一个指示验证尝试是否成功的布尔值。

附加提示

Using IPNetDriver

By default, UE4's Steam OSS uses Steam Networking as the default socket subsystem. In 4.22, you can disable this behavior by setting OnlineSubsystemSteam.bUseSteamNetworking to false. To do this, add the following to "DefaultEngine.ini", or to the platform-specific engine .ini file (such as "WindowsEngine.ini", "LinuxEngine.ini", or "MacEngine.ini") for each platform you support:

[OnlineSubsystemSteam]
bUseSteamNetworking=false

In versions prior to 4.22, modify SocketSubsystemSteam.cpp where the RegisterSocketSubsystem function is called and change the bool parameter to be false. You will also need to change the netdrivers in your project configuration files.

模块设置

确保将虚幻引擎Steam模块作为项目的一部分包含进去(请参阅UnrealBuildTool目标哦文件以获取更多帮助)。 具体而言,在mygame.build.cs的构造函数中添加以下行应足以确保随着游戏构建Steam模块。

DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");

Steam Overlay on Mac

Steam Overlay on Mac要求通过Steam客户端启动游戏。为此,需要先使用Steam“游戏”菜单中的“将非Steam游戏添加到我的库”选项来将游戏添加到库。

欢迎来到全新虚幻引擎4文档站!

我们正在努力开发新功能,包括反馈系统,以便您能对我们的工作作出评价。但它目前还未正式上线。如果您对此页面有任何意见与在使用中遭遇任何问题,请前往文档反馈论坛告知我们。

新系统上线运行后,我们会及时通知您的。

发表反馈意见