Skip to content

Latest commit

 

History

History
303 lines (204 loc) · 7.8 KB

friends.md

File metadata and controls

303 lines (204 loc) · 7.8 KB

Friends

Friends APIs give you the ability to access friends list data and general information about users.

var greenworks = require('./greenworks');

if (greenworks.init()) {
  greenworks.on('persona-state-change',
                function(steam_id, persona_change_flag) {
    if (persona_change_flag == greenworks.PersonaChange.Name)
      console.log("Change to new name: " + steam_id.getPersonaName());
  });

  greenworks.on('game-connected-friend-chat-message',
                function(steam_id, message_id) {
    var info = greenworks.getFriendMessage(steam_id.getRawSteamID(), message_id,
                                           2048);
    if (info.chatEntryType == greenworks.ChatEntryType.ChatMsg) {
      var message = info.message;
      console.log("Receive a message from " + steam_id.getPersonaName() + ": " +
                  message);
      greenworks.replyToFriendMessage(steam_id.getRawSteamID(),
                                      "Hello, I received your message.");
    }
  });

  // Listen to messages from friends.
  greenworks.setListenForFriendsMessage(true);

  // Get the number of regular friends.
  console.log(greenworks.getFriendCount(greenworks.FriendFlags.Immediate));
  var friends = greenworks.getFriends(greenworks.FriendFlags.Immediate);
  for (var i = 0; i < friends.length; ++i) {
    console.log(friends[i].getPersonaName());
    greenworks.requestUserInformation(friends[i].getRawSteamID(), true);
  }
}

Objects

greenworks.FriendFlags

Represents Steam SDK EFriendFlags, for enumerating friends list, or quickly checking a the relationship between users.

  • None
  • Blocked
  • FriendshipRequested
  • Immediate
  • ClanMember
  • OnGameServer
  • RequestingFriendship
  • RequestingInfo
  • Ignored
  • IgnoredFriend
  • ChatMember
  • All

greenworks.FriendRelationship

Represents Steam SDK EFriendRelationship (set of relationships to other users).

  • None
  • Blocked
  • RequestRecipient
  • Friend
  • RequestInitiator
  • Ignored
  • IgnoredFriend

greenworks.PersonaChange

Represents Steam SDK EPersonaChange, which is used in persona-state-change event.

It describes what the client has learned has changed recently, so on startup you'll see a name, avatar & relationship change for every friend.

  • Name
  • Status
  • ComeOnline
  • GoneOffline
  • GamePlayed
  • GameServer
  • Avator
  • JoinedSource
  • LeftSource
  • RelationshipChanged
  • NameFirstSet
  • FacebookInfo
  • NickName
  • SteamLevel

greenworks.AccountType

Represents Steam SDK EAccountType (Steam account types).

  • Invalid
  • Individual
  • Multiseat
  • GameServer
  • AnonymousGameServer
  • Pending
  • ContentServer
  • Clan
  • Chat
  • ConsoleUser
  • AnonymousUser

greenworks.ChatEntryType

Represents Steam SDK EChatEntryType (previously was only friend-to-friend message types).

  • Invalid
  • ChatMsg
  • Typing
  • InviteGame
  • Emote
  • LeftConversation
  • Entered
  • WasKicked
  • WasBanned
  • Disconnected
  • HistoricalChat
  • LinkBlocked

SteamID

An object represents CSteamID.

The SteamID object has following methods:

  • SteamID.isAnonymous()

Returns whether it is an anonymous account.

  • SteamID.isAnonymousGameServer()

Returns whether it is an anonymous game server account id.

  • SteamID.isAnonymousGameServerLogin()

Returns whether it is an anonymous game server login that will be filled in.

  • SteamID.isAnonymousUser()

Returns whether it is an anonymous user account (used to create an account or reset a password).

  • SteamID.isChatAccount()

Returns whether it is a chat account id.

  • SteamID.isClanAccount()

Returns whether it is a clan account id.

  • SteamID.isConsoleUserAccount()

Returns whether it is a faked up Steam ID for a PSN friend account.

  • SteamID.isContentServerAccount()

Returns whether it is a content server account id.

  • SteamID.isGameServerAccount()

Returns whether it is a game server account id (either persistent or anonymous).

  • SteamID.isIndividualAccount()

Returns whether it is an individual user account id.

  • SteamID.isPersistentGameServerAccount()

Returns whether it is a persistent (not anonymous) game server account id.

  • SteamID.isLobby()

Returns whether it is a chat account id.

  • SteamID.getAccountID()

Returns an Integer represents account identifier.

  • SteamID.getRawSteamID()

Returns a String represents the SteamID (converts CSteamID to its 64-bit representation).

  • SteamID.getAccountType()

Returns a field of greenworks.AccountType.

  • SteamID.isValid()

Returns whether it is a valid account.

  • SteamID.getStaticAccountKey()

Returns a String represents 64-bit static account key.

It converts the static parts of a steam ID to a 64-bit representation. For multiseat accounts, all instances of that account will have the same static account key, so they can be grouped together by the static account key.

  • SteamID.getPersonaName()

Returns a String represents the name.

  • SteamID.getNickname()

Returns a String represents the nickname which the current user has set for the specified player. Empty if the no nickname has been set for that player.

  • SteamID.getRelationship()

Returns a `` represents a relationship to a user.

  • SteamID.getSteamLevel()

Returns an Integer represents steam level.

Methods

greenworks.getFriendsAccount(friend_flag)

  • friend_flag greenworks.FriendFlags

Returns an Integer represents the number of friends.

greenworks.getFriends(friend_flag)

  • friend_flag greenworks.FriendFlags

Returns an array of SteamID objects, each SteamID represents a friend.

greenworks.requestUserInformation(raw_steam_id, require_name_only)

  • raw_steam_id String: a 64-bits steam ID (SteamID.getRawSteamID()).
  • require_name_only Boolean: whether get name only.

Requests information about a user (persona name & avatar). Returns true, it means that data is being requested, and a persona-state-changed event will be emitted when it's retrieved; if returns false, it means that we already have all the details about that user, and functions can be called immediately.

If require_name_only is true, then the avatar of a user isn't downloaded (it's a lot slower to download avatars and churns the local cache, so if you don't need avatars, don't request them).

greenworks.getSmallFriendAvatar(raw_steam_id)

  • raw_steam_id String: a 64-bits steam ID (SteamID.getRawSteamID()).

Gets the small (32x32) avatar. Returns an integer handle which is used in getImageRGBA(); returns 0 if none set.

greenworks.getMediumFriendAvatar(raw_steam_id)

  • raw_steam_id String: a 64-bits steam ID (SteamID.getRawSteamID()).

Gets the medium (64*64) avatar. Returns an integer handle which is used in getImageRGBA(); returns 0 if none set.

greenworks.getLargeFriendAvatar(raw_steam_id)

  • raw_steam_id String: a 64-bits steam ID (SteamID.getRawSteamID()).

Gets the large (128*128) avatar. Returns an integer handle which is used in getImageRGBA(); returns 0 if none set; returns -1 if this image has yet to be loaded, in this case you should wait for avatar-image-loaded event.

greenworks.setListenForFriendsMessage(intecept_enabled)

  • intercept_enabled Boolean

Listen for friends message event (game-connected-friend-chat-message). Return a Boolean indicates whether the listener is set successfully.

greenworks.replyToFriendMessage(raw_steam_id, message)

  • raw_steam_id String: a 64-bits steam ID.
  • message String: a message being sent to a friend.

Send a message to a friend. Returns a Boolean indicates whether the message is sent successfully.

greenworks.getFriendMessage(raw_steam_id, message_id, maximum_message_size)

  • raw_steam_id String: a 64-bits steam ID.
  • message_id Integer
  • maximum_message_size Integer

Returns a String represents a message from a friend.