Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ both leave the runtime unloaded. A dedicated server passes `initializeClient = 0
only uses the game server functions.

* Client: game connection tickets (`InitiateGameConnection_DEPRECATED`), SteamID,
persona name, app subscription and voice (User023, Friends018, Apps009). Missing
interfaces make the corresponding calls return `SB_UNAVAILABLE`.
persona name, app subscription, current game language, low violence and voice
(User023, Friends018, Apps009). Missing interfaces make the corresponding calls return
`SB_UNAVAILABLE`.
* Game server (`SteamBridge_ServerInit`): GameServer015 logon, server rules and
heartbeats, ticket authentication (`SendUserConnectAndAuthenticate_DEPRECATED`),
bots and shared-socket master server packets. The interface version list matches
Expand Down Expand Up @@ -130,7 +131,8 @@ runtime for the target architecture beside the bridge, as host mode expects;
## Verification

CTest covers, on every supported platform, absent runtimes and host mode against a
fixture runtime: client initialization failure and retry, connection tickets, voice
fixture runtime: client initialization failure and retry, connection tickets, app
subscription, game language (including truncation and a missing language), low violence, voice
capture/decoding and non-OK voice results, client and game server event translation
and dispatcher separation, deferred shutdown from callbacks, game server setters and
authentication, packets, dedicated (server-only) sessions, and FakeIP ports: datagram
Expand Down
4 changes: 4 additions & 0 deletions include/SteamAPIBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ extern "C"
// Copies the persona name, truncated and NUL-terminated.
STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserGetPersonaName(char* name, uint32_t capacity);
STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserIsSubscribedApp(uint32_t appID, uint32_t* subscribed);
// Copies the running application's language ("english", "schinese", ...), truncated and
// NUL-terminated.
STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserGetCurrentGameLanguage(char* language, uint32_t capacity);
STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserIsLowViolence(uint32_t* lowViolence);

// Voice. Get and Decompress succeed only for Steam's k_EVoiceResultOK; any other
// voice result returns SB_FAILED with zero lengths.
Expand Down
18 changes: 18 additions & 0 deletions src/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ SteamBridgeStatus SteamBridge_UserIsSubscribedApp(uint32_t appID, uint32_t* subs
*subscribed = host.apps->BIsSubscribedApp(appID);
return SB_OK;
}
SteamBridgeStatus SteamBridge_UserGetCurrentGameLanguage(char* language, uint32_t capacity)
{
if (!language || !capacity) return SB_INVALID_ARGUMENT;
language[0] = 0;
if (!host.apps) return SB_UNAVAILABLE;
const char* current = host.apps->GetCurrentGameLanguage();
if (!current) return SB_FAILED;
CopyText(language, capacity, current);
return SB_OK;
}
SteamBridgeStatus SteamBridge_UserIsLowViolence(uint32_t* lowViolence)
{
if (!lowViolence) return SB_INVALID_ARGUMENT;
*lowViolence = 0;
if (!host.apps) return SB_UNAVAILABLE;
*lowViolence = host.apps->BIsLowViolence();
return SB_OK;
}

SteamBridgeStatus SteamBridge_VoiceStartRecording()
{
Expand Down
57 changes: 55 additions & 2 deletions tests/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using QueueFn = void(S_CALLTYPE*)(int, int, const void*, int);
using QueueFakeFn = void(S_CALLTYPE*)(int, uint32_t, uint16_t, int);
using SetFakeIPFn = void(S_CALLTYPE*)(int, uint32_t, uint16_t);
using EmitDebugFn = int(S_CALLTYPE*)(int, const char*);
using SetAppsFn = void(S_CALLTYPE*)(int, const char*, int);
namespace mock
{
SetIntFn failInit, voiceResult;
Expand All @@ -23,6 +24,7 @@ QueueFn queue;
QueueFakeFn queueFake;
SetFakeIPFn setFakeIP;
EmitDebugFn emitDebug;
SetAppsFn setApps;
} // namespace mock
using namespace mock;

Expand Down Expand Up @@ -79,6 +81,12 @@ void Unavailable(const char* missing)
assert(0 == size);
assert(SB_UNAVAILABLE == SteamBridge_ServerInit(0, 27015, 27015, SB_SERVER_MODE_SECURE, "1.0"));
assert(0 == SteamBridge_VoiceGetOptimalSampleRate());
char language[8] = "x";
assert(SB_UNAVAILABLE == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language)));
assert(0 == language[0]);
uint32_t lowViolence = 1;
assert(SB_UNAVAILABLE == SteamBridge_UserIsLowViolence(&lowViolence));
assert(0 == lowViolence);
SteamBridge_HostRunCallbacks();
SteamBridge_HostShutdown();
}
Expand Down Expand Up @@ -107,13 +115,20 @@ void Client(const char* mock)
uint64_t id{};
assert(SB_OK == SteamBridge_UserGetSteamID(&id));
assert(76561198000000001 == id);
// The fixture exposes no SteamFriends/SteamApps; those calls report unavailability.
// The fixture exposes no SteamFriends, nor SteamApps until Apps enables it; those calls
// report unavailability.
char name[4] = "x";
assert(SB_UNAVAILABLE == SteamBridge_UserGetPersonaName(name, sizeof(name)));
assert(0 == name[0]);
uint32_t subscribed = 1;
assert(SB_UNAVAILABLE == SteamBridge_UserIsSubscribedApp(70, &subscribed));
assert(0 == subscribed);
char language[8] = "x";
assert(SB_UNAVAILABLE == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language)));
assert(0 == language[0]);
uint32_t lowViolence = 1;
assert(SB_UNAVAILABLE == SteamBridge_UserIsLowViolence(&lowViolence));
assert(0 == lowViolence);

assert(SB_OK == SteamBridge_VoiceStartRecording());
uint32_t available{};
Expand Down Expand Up @@ -205,6 +220,42 @@ void Client(const char* mock)
assert(SB_UNAVAILABLE == SteamBridge_UserGetSteamID(&id));
SteamBridge_HostSetClientCallback(nullptr, nullptr);
}
void Apps(const char* mock)
{
setApps(1, "schinese", 1);
assert(SB_OK == SteamBridge_HostInit(mock, 1));
uint32_t subscribed{};
assert(SB_OK == SteamBridge_UserIsSubscribedApp(70, &subscribed));
assert(1 == subscribed);
assert(SB_OK == SteamBridge_UserIsSubscribedApp(10, &subscribed));
assert(0 == subscribed);
char language[16]{};
assert(SB_OK == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language)));
assert(!std::strcmp("schinese", language));
char truncated[4]{};
assert(SB_OK == SteamBridge_UserGetCurrentGameLanguage(truncated, sizeof(truncated)));
assert(!std::strcmp("sch", truncated));
assert(SB_INVALID_ARGUMENT == SteamBridge_UserGetCurrentGameLanguage(nullptr, sizeof(language)));
assert(SB_INVALID_ARGUMENT == SteamBridge_UserGetCurrentGameLanguage(language, 0));
uint32_t lowViolence{};
assert(SB_OK == SteamBridge_UserIsLowViolence(&lowViolence));
assert(1 == lowViolence);
assert(SB_INVALID_ARGUMENT == SteamBridge_UserIsLowViolence(nullptr));
SteamBridge_HostShutdown();

// SteamApps without a language fails the query and still answers the others.
setApps(1, nullptr, 0);
assert(SB_OK == SteamBridge_HostInit(mock, 1));
std::strcpy(language, "x");
assert(SB_FAILED == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language)));
assert(0 == language[0]);
lowViolence = 1;
assert(SB_OK == SteamBridge_UserIsLowViolence(&lowViolence));
assert(0 == lowViolence);
SteamBridge_HostShutdown();
setApps(0, nullptr, 0);
assert(!SteamBridge_HostIsActive());
}
void DedicatedServer(const char* mock)
{
int shutdowns = mock::stat(MOCK_HOST_SHUTDOWNS);
Expand Down Expand Up @@ -314,10 +365,12 @@ int main(int argc, char** argv)
mock::queueFake = platform::Resolve<QueueFakeFn>(module, "MockHostQueueFakeMessage");
mock::setFakeIP = platform::Resolve<SetFakeIPFn>(module, "MockHostSetFakeIP");
mock::emitDebug = platform::Resolve<EmitDebugFn>(module, "MockHostEmitDebug");
mock::setApps = platform::Resolve<SetAppsFn>(module, "MockHostSetApps");
assert(mock::failInit && mock::voiceResult && mock::stat && mock::forwarded && mock::queue);
assert(mock::queueFake && mock::setFakeIP && mock::emitDebug);
assert(mock::queueFake && mock::setFakeIP && mock::emitDebug && mock::setApps);
Unavailable(argv[2]);
Client(argv[1]);
Apps(argv[1]);
DedicatedServer(argv[1]);
platform::UnloadRuntime(module);
}
43 changes: 41 additions & 2 deletions tests/HostStubs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
// Empty implementations of every SteamUser023, SteamGameServer015, SteamNetworkingSockets013 and
// SteamNetworkingUtils004 method, generated from the Steamworks SDK v1.65 declarations. Mocks
// Empty implementations of every SteamUser023, SteamApps009, SteamGameServer015, SteamNetworkingSockets013
// and SteamNetworkingUtils004 method, generated from the Steamworks SDK v1.65 declarations. Mocks
// override the methods they exercise.
#include <steam/steam_api.h>
#include <steam/steam_gameserver.h>
Expand Down Expand Up @@ -42,6 +42,45 @@ class StubUser : public ISteamUser
SteamAPICall_t GetDurationControl() override { return {}; }
bool BSetDurationControlOnlineState(EDurationControlOnlineState eNewState) override { return {}; }
};
class StubApps : public ISteamApps
{
public:
bool BIsSubscribed() override { return {}; }
bool BIsLowViolence() override { return {}; }
bool BIsCybercafe() override { return {}; }
bool BIsVACBanned() override { return {}; }
const char* GetCurrentGameLanguage() override { return {}; }
const char* GetAvailableGameLanguages() override { return {}; }
bool BIsSubscribedApp(AppId_t appID) override { return {}; }
bool BIsDlcInstalled(AppId_t appID) override { return {}; }
uint32 GetEarliestPurchaseUnixTime(AppId_t nAppID) override { return {}; }
bool BIsSubscribedFromFreeWeekend() override { return {}; }
int GetDLCCount() override { return {}; }
bool BGetDLCDataByIndex(int iDLC, AppId_t* pAppID, bool* pbAvailable, char* pchName, int cchNameBufferSize) override { return {}; }
void InstallDLC(AppId_t nAppID) override {}
void UninstallDLC(AppId_t nAppID) override {}
void RequestAppProofOfPurchaseKey(AppId_t nAppID) override {}
bool GetCurrentBetaName(char* pchName, int cchNameBufferSize) override { return {}; }
bool MarkContentCorrupt(bool bMissingFilesOnly) override { return {}; }
uint32 GetInstalledDepots(AppId_t appID, DepotId_t* pvecDepots, uint32 cMaxDepots) override { return {}; }
uint32 GetAppInstallDir(AppId_t appID, char* pchFolder, uint32 cchFolderBufferSize) override { return {}; }
bool BIsAppInstalled(AppId_t appID) override { return {}; }
CSteamID GetAppOwner() override { return {}; }
const char* GetLaunchQueryParam(const char* pchKey) override { return {}; }
bool GetDlcDownloadProgress(AppId_t nAppID, uint64* punBytesDownloaded, uint64* punBytesTotal) override { return {}; }
int GetAppBuildId() override { return {}; }
void RequestAllProofOfPurchaseKeys() override {}
SteamAPICall_t GetFileDetails(const char* pszFileName) override { return {}; }
int GetLaunchCommandLine(char* pszCommandLine, int cubCommandLine) override { return {}; }
bool BIsSubscribedFromFamilySharing() override { return {}; }
bool BIsTimedTrial(uint32* punSecondsAllowed, uint32* punSecondsPlayed) override { return {}; }
bool SetDlcContext(AppId_t nAppID) override { return {}; }
int GetNumBetas(int* pnAvailable, int* pnPrivate) override { return {}; }
bool GetBetaInfo(int iBetaIndex, uint32* punFlags, uint32* punBuildID, char* pchBetaName, int cchBetaName, char* pchDescription, int cchDescription, uint32* punLastUpdated) override { return {}; }
bool SetActiveBeta(const char* pchBetaName) override { return {}; }
void SetGamePerformanceSetting(EGamePerformanceSetting setting) override {}
void SetGameRenderResolution(uint32 unWidth, uint32 unHeight) override {}
};
class StubGameServer : public ISteamGameServer
{
public:
Expand Down
22 changes: 21 additions & 1 deletion tests/MockHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ class User final : public StubUser
uint32 GetVoiceOptimalSampleRate() override { return 24000; }
} user;

// MockHostSetApps controls whether SteamApps exists and what it reports.
bool appsAvailable, appsHasLanguage, appsLowViolence;
char appsLanguage[32];
class Apps final : public StubApps
{
public:
bool BIsLowViolence() override { return appsLowViolence; }
const char* GetCurrentGameLanguage() override { return appsHasLanguage ? appsLanguage : nullptr; }
bool BIsSubscribedApp(AppId_t appID) override { return appID == 70; }
} apps;

class GameServer final : public StubGameServer
{
public:
Expand Down Expand Up @@ -227,6 +238,7 @@ extern "C"
S_API void* S_CALLTYPE SteamInternal_FindOrCreateUserInterface(HSteamUser steamUser, const char* version)
{
if (!std::strcmp(version, STEAMUSER_INTERFACE_VERSION)) return &user;
if (!std::strcmp(version, STEAMAPPS_INTERFACE_VERSION)) return appsAvailable ? &apps : nullptr;
if (!std::strcmp(version, STEAMNETWORKINGSOCKETS_INTERFACE_VERSION)) return steamUser == 1 ? &clientSockets : nullptr;
// The global utilities (user 0) exist once the client is initialized.
if (!std::strcmp(version, STEAMNETWORKINGUTILS_INTERFACE_VERSION)) return clientInitialized && !steamUser ? &utils : nullptr;
Expand Down Expand Up @@ -261,7 +273,15 @@ extern "C"
// Fixture control.
S_API void S_CALLTYPE MockHostSetFailInit(int value) { failInit = value; }
S_API void S_CALLTYPE MockHostSetVoiceResult(int value) { voiceResult = value; }
S_API int S_CALLTYPE MockHostStat(int which)
// Applies to the next client initialization. A NULL language makes SteamApps return NULL.
S_API void S_CALLTYPE MockHostSetApps(int available, const char* language, int lowViolence)
{
appsAvailable = available != 0;
appsHasLanguage = language != nullptr;
appsLowViolence = lowViolence != 0;
std::snprintf(appsLanguage, sizeof(appsLanguage), "%s", language ? language : "");
}
S_API int S_CALLTYPE MockHostStat(int which)
{
switch (which)
{
Expand Down
Loading