SFSUser

Represents a client logged in SmartFoxServer.


The SmartFoxServer client is not aware of all the clients (Users) connected to the server, but only of those that are in the same Rooms joined by the current client; this reduces the traffic between the client and the server considerably. In order to interact with other Users, the client should join other Rooms or use the Buddy List System.

The list of Users in each Room joined by the client is updated continuously by the server.

Members

(readonly) aoiEntryPoint :Vec3D

Entry point of the User in the Area of Interest of the current User.

The returned coordinates are those that the User had when thier presence in the Area of Interest of the current User was last notified by a SFSEvent.PROXIMITY_LIST_UPDATE event. This field is populated if the User joined a Room of type MMORoom only, and if the MMORoom is configured to receive such data from the server.

Type:

(readonly) id :number

Identifier of the User.

The id is unique and it is generated by the server when the User logs in.

Type:
  • number

(readonly) isAdmin :boolean

Indicates whether the User logged in as an administrator.

Administrator Users have this property set to the UserPrivileges.ADMINISTRATOR value.

Type:
  • boolean

(readonly) isGuest :boolean

Indicates whether the User logged in as a guest.

Guest Users have this property set to the UserPrivileges.GUEST value.

Type:
  • boolean

(readonly) isItMe :boolean

Indicates whether the SFSUser object represents the current client.
Type:
  • boolean

(readonly) isModerator :boolean

Indicates whether the User logged in as a moderator.

Moderator Users have this property set to the UserPrivileges.MODERATOR value.

Type:
  • boolean

(readonly) isPlayer :boolean

Indicates whether the User is a Player (the Player id is greater than 0) in the last joined Room.

Non-Game Rooms always return false

.

If the User is inside multiple Game Rooms at the same time, use the SFSUser#isPlayerInRoom method instead.

Type:
  • boolean

(readonly) isSpectator :boolean

Indicates whether the User is a Spectator (the Player id is lower than 0) in the last joined Room.

Non-Game Rooms always return false

.

If the User is inside multiple Game Rooms at the same time, use the SFSUser#isPlayerInRoom method instead.

Type:
  • boolean

(readonly) isStandardUser :boolean

Indicates whether the User logged in as a standard User.

Standard Users have this property set to the UserPrivileges.STANDARD value.

Type:
  • boolean

(readonly) name :string

Name of the User.

Two Users in the same Zone cannot have the same name.

Type:
  • string

(readonly) playerId :number

Identifier of the User as Player in a Game Room.

This property differs from SFSUser#id property and it is used to indicate which Player number is assigned to a User inside a Game Room. For example, in a Game Room for 5 players, the first client joining it will have its Player id equal to 1, the second will have it equal to 2 and so forth. When a User leaves the Room, the Player slot is freed up and the next User joining the Room will take it.

This property applies to Game Rooms only; in standard Rooms it is always 0. Also, in Game Rooms a Player id value lower than 0 indicates that the User is a Spectator.

If the User is inside multiple Game Rooms at the same time, a different Player id value will be assigned to it in each Room. In this case this property returns the value corresponding to the last joined Room; in order to obtain the value for a specific Room, use the SFSRoom#getPlayerId method.

Type:
  • number

(readonly) privilegeId :number

Number to identify the privilege level of the User.
Type:
  • number

(readonly) userManager :SFSUserManager

Reference to the User Manager which manages the User.

Methods

containsVariable(varName) → {boolean}

Indicates whether the User has the specified User Variable set.
Parameters:
NameTypeDescription
varNamestringThe name of the User Variable whose existance must be checked.
Returns:
true if a User Variable with the passed name is found.
Type: 
boolean

getPlayerId(room) → {number}

Player id of the User in the passed Room.

See the SFSRoom#playerId property description for more information.

Parameters:
NameTypeDescription
roomSFSRoomThe object representing the Room to get the Player id from.
Returns:
The Player id of the User in the passed Room.
Type: 
number

getVariable(varName) → {SFSUserVariable}

Retrieves a User Variable by its name.
Parameters:
NameTypeDescription
varNamestringThe name of the User Variable to be retrieved.
Returns:
The object representing the User Variable, or null if no User Variable with the passed name belongs to the User.
Type: 
SFSUserVariable

getVariables() → {Array.<SFSUserVariable>}

Returns all User Variables belonging to the User.
Returns:
A list of objects representing the User Variables.
Type: 
Array.<SFSUserVariable>

isJoinedInRoom(room) → {boolean}

Indicates whether the User joined the passed Room.
Parameters:
NameTypeDescription
roomSFSRoomThe object representing the Room where to check the User presence.
Returns:
true if the User is inside the passed Room.
Type: 
boolean

isPlayerInRoom(room) → {boolean}

Indicates whether the User is a Player (the Player id is greater than 0) in the passed Room.

Non-Game Rooms always return false.

If a User can join one Game Room at a time only, use the SFSUser#isPlayer property.

Parameters:
NameTypeDescription
roomSFSRoomThe object representing the Room where to check if the User is a Player.
Returns:
true if the User is a Player in the passed Room.
Type: 
boolean

isSpectatorInRoom(room) → {boolean}

Indicates whether the User is a Spectator (the Player id is lower than 0) in the passed Room.

Non-Game Rooms always return false.

If a User can join one Game Room at a time only, use the SFSUser#isSpectator property.

Parameters:
NameTypeDescription
roomSFSRoomThe object representing the Room where to check if the User is a Spectator.
Returns:
true if the User is a Spectator in the passed Room.
Type: 
boolean

toString() → {string}

Returns a string containing the User id, name and a flag indicating if the this object represents the current client.
Returns:
The string representation of the SFSUser object.
Type: 
string