@@ -5,10 +5,34 @@ pub mod friends {
55 use napi:: bindgen_prelude:: BigInt ;
66 use steamworks:: SteamId ;
77
8+ #[ napi]
9+ pub enum PersonaState {
10+ Offline = 0 ,
11+ Online = 1 ,
12+ Busy = 2 ,
13+ Away = 3 ,
14+ Snooze = 4 ,
15+ LookingToTrade = 5 ,
16+ LookingToPlay = 6 ,
17+ Invisible = 7 ,
18+ }
19+
20+ #[ napi( object) ]
21+ pub struct FriendGameInfo {
22+ pub game_id : BigInt ,
23+ pub game_ip : String ,
24+ pub game_port : u32 ,
25+ pub query_port : u32 ,
26+ pub lobby_id : BigInt ,
27+ }
28+
829 #[ napi( object) ]
930 pub struct Friend {
1031 pub steam_id : BigInt ,
1132 pub name : String ,
33+ pub nickname : Option < String > ,
34+ pub state : PersonaState ,
35+ pub game_played : Option < FriendGameInfo > ,
1236 }
1337
1438 #[ napi]
@@ -27,17 +51,12 @@ pub mod friends {
2751 /// Get an array of friends matching the provided flags.
2852 ///
2953 /// @param flags - The flags to filter friends by.
30- /// @returns An array of friend objects containing steamId and name .
54+ /// @returns An array of friend objects containing steamId, name, nickname, state and gamePlayed .
3155 ///
3256 /// @example
3357 /// ```js
3458 /// const friends = client.friends.getFriends(client.friends.FriendFlags.Immediate)
3559 /// console.log(friends)
36- /// // Output:
37- /// // [
38- /// // { steamId: 76561197985341433n, name: 'XXX' },
39- /// // { steamId: 76561198034399293n, name: 'YYY' },
40- /// // ]
4160 /// ```
4261 #[ napi]
4362 pub fn get_friends ( flags : i32 ) -> Vec < Friend > {
@@ -50,11 +69,28 @@ pub mod friends {
5069 . map ( |f| Friend {
5170 steam_id : BigInt :: from ( f. id ( ) . raw ( ) ) ,
5271 name : f. name ( ) ,
72+ nickname : f. nick_name ( ) ,
73+ state : match f. state ( ) {
74+ steamworks:: FriendState :: Offline => PersonaState :: Offline ,
75+ steamworks:: FriendState :: Online => PersonaState :: Online ,
76+ steamworks:: FriendState :: Busy => PersonaState :: Busy ,
77+ steamworks:: FriendState :: Away => PersonaState :: Away ,
78+ steamworks:: FriendState :: Snooze => PersonaState :: Snooze ,
79+ steamworks:: FriendState :: LookingToTrade => PersonaState :: LookingToTrade ,
80+ steamworks:: FriendState :: LookingToPlay => PersonaState :: LookingToPlay ,
81+ } ,
82+ game_played : f. game_played ( ) . map ( |g| FriendGameInfo {
83+ game_id : BigInt :: from ( g. game . raw ( ) ) ,
84+ game_ip : g. game_address . to_string ( ) ,
85+ game_port : g. game_port as u32 ,
86+ query_port : g. query_port as u32 ,
87+ lobby_id : BigInt :: from ( g. lobby . raw ( ) ) ,
88+ } ) ,
5389 } )
5490 . collect ( )
5591 }
5692
57- /// Get the persona name of a friend.
93+ /// Get the name of a friend.
5894 ///
5995 /// @param steam_id64 - The Steam ID of the friend.
6096 /// @returns The name of the friend.
0 commit comments