Skip to content

Commit 756b156

Browse files
committed
feat(steam): add friends API
1 parent bdf1cb3 commit 756b156

8 files changed

Lines changed: 376 additions & 12 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The build uses the pluginConfig file to generate everything else.
3636
The main files you may want to look at would be instance.js
3737

3838
## Examples Files
39+
- [discord](./examples/discord.c3p)
40+
</br>
3941
- [example](./examples/example.c3p)
4042
</br>
4143
- [steam](./examples/steam.c3p)
@@ -267,6 +269,12 @@ When Download type is Around the user, the offsets are the amount of entries aro
267269
| Get workshop items with metadata | Gets multiple workshop items with their metadata, state, install info, and download info | Item IDs *(string)* <br>Tag *(string)* <br> |
268270
| Get workshop items with metadata | Gets multiple workshop items with their metadata, state, install info, and download info | Item IDs *(string)* <br> |
269271
| Get workshop items with metadata | Gets multiple workshop items with their metadata, state, install info, and download info | Item IDs *(string)* <br>Tag *(string)* <br> |
272+
| Get friends | Get an array of friends matching the provided flags. | Flags *(combo)* <br>Output *(object)* <br>Tag *(string)* <br> |
273+
| Get friends | Get an array of friends matching the provided flags. | Flags *(combo)* <br>Output *(object)* <br> |
274+
| Get friends | Get an array of friends matching the provided flags. | Flags *(combo)* <br>Output *(object)* <br>Tag *(string)* <br> |
275+
| Get friend name | Get the persona name of a friend. | Steam ID *(string)* <br>Tag *(string)* <br> |
276+
| Get friend name | Get the persona name of a friend. | Steam ID *(string)* <br> |
277+
| Get friend name | Get the persona name of a friend. | Steam ID *(string)* <br>Tag *(string)* <br> |
270278

271279

272280
---
@@ -477,6 +485,14 @@ When Download type is Around the user, the offsets are the amount of entries aro
477485
| On any "GetCurrentGameLanguage" success | Trigger when any of the "GetCurrentGameLanguage" are executed with success. | |
478486
| On "GetCurrentGameLanguage" error | Trigger when the "GetCurrentGameLanguage" failed to execute. | Tag *(string)* <br> |
479487
| On any "GetCurrentGameLanguage" error | Trigger when any of the "GetCurrentGameLanguage" failed to execute. | |
488+
| On "GetFriends" success | Trigger when the "GetFriends" is executed with success. | Tag *(string)* <br> |
489+
| On any "GetFriends" success | Trigger when any of the "GetFriends" are executed with success. | |
490+
| On "GetFriends" error | Trigger when the "GetFriends" failed to execute. | Tag *(string)* <br> |
491+
| On any "GetFriends" error | Trigger when any of the "GetFriends" failed to execute. | |
492+
| On "GetFriendName" success | Trigger when the "GetFriendName" is executed with success. | Tag *(string)* <br> |
493+
| On any "GetFriendName" success | Trigger when any of the "GetFriendName" are executed with success. | |
494+
| On "GetFriendName" error | Trigger when the "GetFriendName" failed to execute. | Tag *(string)* <br> |
495+
| On any "GetFriendName" error | Trigger when any of the "GetFriendName" failed to execute. | |
480496
| On overlay activated | Triggered when the Steam overlay is activated. | |
481497
| On overlay deactivated | Triggered when the Steam overlay is deactivated. | |
482498
| On "TriggerScreenshot" success | Trigger when the "TriggerScreenshot" is executed with success. | Tag *(string)* <br> |
@@ -729,6 +745,10 @@ When Download type is Around the user, the offsets are the amount of entries aro
729745
| WorkshopItemTimestamp | Get the install timestamp of a workshop item | number | Item ID *(string)* <br> |
730746
| WorkshopItemDownloadCurrent | Get the current download progress of a workshop item | number | Item ID *(string)* <br> |
731747
| WorkshopItemDownloadTotal | Get the total download progress of a workshop item | number | Item ID *(string)* <br> |
748+
| GetFriendsError | The error of the "GetFriends last call" | string | |
749+
| GetFriendsResult | The result of the "GetFriends last call" | string | |
750+
| GetFriendNameError | The error of the "GetFriendName last call" | string | |
751+
| GetFriendNameResult | The result of the "GetFriendName last call" | string | |
732752
| ArgumentAt | Get the argument at the given index. | string | Index *(number)* <br> |
733753
| ArgumentCount | Get the number of arguments. | number | |
734754
| AppFolderURL | Return the URL of the folder of the current app. | string | |
@@ -774,6 +794,14 @@ When Download type is Around the user, the offsets are the amount of entries aro
774794
| SteamIpCountry | Get the Steam IP country. | string | |
775795
| SteamIsRunningOnSteamDeck | Return true if the app is running on a Steam Deck. | number | |
776796
| SteamAppId | Get the currently used Steam App ID. | number | |
797+
| SteamIsOffline | Return 1 if the provided steam state is Offline (0). | number | State *(number)* <br> |
798+
| SteamIsOnline | Return 1 if the provided steam state is Online (1). | number | State *(number)* <br> |
799+
| SteamIsBusy | Return 1 if the provided steam state is Busy (2). | number | State *(number)* <br> |
800+
| SteamIsAway | Return 1 if the provided steam state is Away (3). | number | State *(number)* <br> |
801+
| SteamIsSnooze | Return 1 if the provided steam state is Snooze (4). | number | State *(number)* <br> |
802+
| SteamIsLookingToTrade | Return 1 if the provided steam state is Looking to Trade (5). | number | State *(number)* <br> |
803+
| SteamIsLookingToPlay | Return 1 if the provided steam state is Looking to Play (6). | number | State *(number)* <br> |
804+
| SteamIsInvisible | Return 1 if the provided steam state is Invisible (7). | number | State *(number)* <br> |
777805

778806
## Paths
779807
**ProjectFilesFolder**: Direct path to your games's content

examples/discord.c3p

164 KB
Binary file not shown.

examples/example.c3p

-5.37 KB
Binary file not shown.

examples/steam.c3p

5.42 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"electron": "35.0.3",
3737
"esbuild": "0.25.10",
3838
"lefthook": "1.11.3",
39-
"steamworks.js": "0.4.0",
4039
"typescript": "5.8.2"
4140
}
4241
}

pnpm-lock.yaml

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/instance.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ const defaultSteamId = {
223223
steamId64: '',
224224
}
225225

226+
const friendFlagsMap = [
227+
0x00, // none
228+
0x01, // blocked
229+
0x02, // friendshipRequested
230+
0x04, // immediate
231+
0x08, // clanMember
232+
0x10, // onGameServer
233+
0x80, // requestingFriendship
234+
0x100, // requestingInfo
235+
0xFFFF, // all
236+
];
237+
226238
// Simple path utility for POSIX-style path operations
227239
const posixPath = {
228240
dirname: (/** @type {string} */ path) => {
@@ -418,6 +430,19 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
418430
/** @type {string} */
419431
_GetCurrentGameLanguageResultValue = ''
420432

433+
/** @type {any[]} */
434+
_friendsList = []
435+
436+
/** @type {string} */
437+
_GetFriendsErrorValue = ''
438+
/** @type {string} */
439+
_GetFriendsResultValue = ''
440+
441+
/** @type {string} */
442+
_GetFriendNameErrorValue = ''
443+
/** @type {string} */
444+
_GetFriendNameResultValue = ''
445+
421446
/**
422447
* Description
423448
* @param {ISDKInstanceBase_} inst
@@ -2329,6 +2354,86 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
23292354
}
23302355
}, this.unsupportedEngine)
23312356

2357+
_GetFriends = this.wrap(super._GetFriends, async (
2358+
/** @type {number} */ flagsIdx,
2359+
/** @type {IObjectType<IJSONInstance>} */ jsonObject,
2360+
/** @type {Tag} */ tag
2361+
) => {
2362+
try {
2363+
const flags = friendFlagsMap[flagsIdx] ?? 0x00;
2364+
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').SteamRaw<'friends', 'getFriends'>, 'input'>} */
2365+
const order = {
2366+
url: '/steam/raw',
2367+
body: {
2368+
namespace: 'friends',
2369+
method: 'getFriends',
2370+
args: [flags],
2371+
},
2372+
};
2373+
const answer = await this.ws?.sendAndWaitForResponse(order);
2374+
if (answer?.body.success === false) {
2375+
throw new Error('Failed')
2376+
}
2377+
this._friendsList = answer?.body.data ?? []
2378+
this._GetFriendsResultValue = JSON.stringify(this._friendsList)
2379+
this._GetFriendsErrorValue = ''
2380+
2381+
const jsonInstance = jsonObject.getFirstInstance()
2382+
jsonInstance?.setJsonDataCopy(answer?.body.data ?? [])
2383+
2384+
await this.trigger(tag, [
2385+
C3.Plugins.pipelabv2.Cnds.OnGetFriendsSuccess,
2386+
C3.Plugins.pipelabv2.Cnds.OnAnyGetFriendsSuccess
2387+
])
2388+
} catch (e) {
2389+
if (e instanceof Error) {
2390+
this._GetFriendsErrorValue = e.message
2391+
this._friendsList = []
2392+
await this.trigger(tag, [
2393+
C3.Plugins.pipelabv2.Cnds.OnGetFriendsError,
2394+
C3.Plugins.pipelabv2.Cnds.OnAnyGetFriendsError
2395+
])
2396+
}
2397+
}
2398+
}, this.unsupportedEngine)
2399+
2400+
_GetFriendName = this.wrap(super._GetFriendName, async (
2401+
/** @type {string} */ steamId64,
2402+
/** @type {Tag} */ tag
2403+
) => {
2404+
try {
2405+
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').SteamRaw<'friends', 'getFriendName'>, 'input'>} */
2406+
const order = {
2407+
url: '/steam/raw',
2408+
body: {
2409+
namespace: 'friends',
2410+
method: 'getFriendName',
2411+
args: [steamId64],
2412+
},
2413+
};
2414+
const answer = await this.ws?.sendAndWaitForResponse(order);
2415+
if (answer?.body.success === false) {
2416+
throw new Error('Failed')
2417+
}
2418+
this._GetFriendNameResultValue = answer?.body.data ?? ''
2419+
this._GetFriendNameErrorValue = ''
2420+
2421+
await this.trigger(tag, [
2422+
C3.Plugins.pipelabv2.Cnds.OnGetFriendNameSuccess,
2423+
C3.Plugins.pipelabv2.Cnds.OnAnyGetFriendNameSuccess
2424+
])
2425+
} catch (e) {
2426+
if (e instanceof Error) {
2427+
this._GetFriendNameErrorValue = e.message
2428+
this._GetFriendNameResultValue = ''
2429+
await this.trigger(tag, [
2430+
C3.Plugins.pipelabv2.Cnds.OnGetFriendNameError,
2431+
C3.Plugins.pipelabv2.Cnds.OnAnyGetFriendNameError
2432+
])
2433+
}
2434+
}
2435+
}, this.unsupportedEngine)
2436+
23322437
// Steam Screenshots
23332438
_TriggerScreenshot = this.wrap(super._TriggerScreenshot, async (
23342439
/** @type {Tag} */ tag
@@ -3736,6 +3841,16 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
37363841
_OnCheckDLCIsInstalledError = this.wrap(super._OnCheckDLCIsInstalledError, (/** @type {Tag} */ tag) => this._currentTag === tag)
37373842
_OnAnyCheckDLCIsInstalledError = this.wrap(super._OnAnyCheckDLCIsInstalledError, () => true)
37383843

3844+
_OnGetFriendsSuccess = this.wrap(super._OnGetFriendsSuccess, (/** @type {Tag} */ tag) => this._currentTag === tag)
3845+
_OnAnyGetFriendsSuccess = this.wrap(super._OnAnyGetFriendsSuccess, () => true)
3846+
_OnGetFriendsError = this.wrap(super._OnGetFriendsError, (/** @type {Tag} */ tag) => this._currentTag === tag)
3847+
_OnAnyGetFriendsError = this.wrap(super._OnAnyGetFriendsError, () => true)
3848+
3849+
_OnGetFriendNameSuccess = this.wrap(super._OnGetFriendNameSuccess, (/** @type {Tag} */ tag) => this._currentTag === tag)
3850+
_OnAnyGetFriendNameSuccess = this.wrap(super._OnAnyGetFriendNameSuccess, () => true)
3851+
_OnGetFriendNameError = this.wrap(super._OnGetFriendNameError, (/** @type {Tag} */ tag) => this._currentTag === tag)
3852+
_OnAnyGetFriendNameError = this.wrap(super._OnAnyGetFriendNameError, () => true)
3853+
37393854
_OnCreateWorkshopItemSuccess = this.wrap(super._OnCreateWorkshopItemSuccess, (/** @type {Tag} */ tag) => this._currentTag === tag)
37403855
_OnAnyCreateWorkshopItemSuccess = this.wrap(super._OnAnyCreateWorkshopItemSuccess, () => true)
37413856
_OnCreateWorkshopItemError = this.wrap(super._OnCreateWorkshopItemError, (/** @type {Tag} */ tag) => this._currentTag === tag)
@@ -3999,6 +4114,38 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
39994114
return this._steam_AppId
40004115
})
40014116

4117+
_SteamIsOffline = this.exprs(super._SteamIsOffline, (state) => {
4118+
return state === 0 ? 1 : 0
4119+
})
4120+
4121+
_SteamIsOnline = this.exprs(super._SteamIsOnline, (state) => {
4122+
return state === 1 ? 1 : 0
4123+
})
4124+
4125+
_SteamIsBusy = this.exprs(super._SteamIsBusy, (state) => {
4126+
return state === 2 ? 1 : 0
4127+
})
4128+
4129+
_SteamIsAway = this.exprs(super._SteamIsAway, (state) => {
4130+
return state === 3 ? 1 : 0
4131+
})
4132+
4133+
_SteamIsSnooze = this.exprs(super._SteamIsSnooze, (state) => {
4134+
return state === 4 ? 1 : 0
4135+
})
4136+
4137+
_SteamIsLookingToTrade = this.exprs(super._SteamIsLookingToTrade, (state) => {
4138+
return state === 5 ? 1 : 0
4139+
})
4140+
4141+
_SteamIsLookingToPlay = this.exprs(super._SteamIsLookingToPlay, (state) => {
4142+
return state === 6 ? 1 : 0
4143+
})
4144+
4145+
_SteamIsInvisible = this.exprs(super._SteamIsInvisible, (state) => {
4146+
return state === 7 ? 1 : 0
4147+
})
4148+
40024149
_IsOverlayActive = this.wrap(super._IsOverlayActive, () => {
40034150
return this._lastOverlayState ? 1 : 0
40044151
})
@@ -4347,6 +4494,19 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
43474494
return this._CheckDLCIsInstalledResultValue ?? 0
43484495
})
43494496

4497+
_GetFriendsError = this.exprs(super._GetFriendsError, () => {
4498+
return this._GetFriendsErrorValue
4499+
})
4500+
_GetFriendsResult = this.exprs(super._GetFriendsResult, () => {
4501+
return this._GetFriendsResultValue
4502+
})
4503+
_GetFriendNameError = this.exprs(super._GetFriendNameError, () => {
4504+
return this._GetFriendNameErrorValue
4505+
})
4506+
_GetFriendNameResult = this.exprs(super._GetFriendNameResult, () => {
4507+
return this._GetFriendNameResultValue
4508+
})
4509+
43504510
// Workshop expressions
43514511
_CreateWorkshopItemError = this.exprs(super._CreateWorkshopItemError, () => {
43524512
return this._CreateWorkshopItemErrorValue

0 commit comments

Comments
 (0)