Class SFSGameApi

java.lang.Object
com.smartfoxserver.api.SFSGameApi
All Implemented Interfaces:
ISFSGameApi

public class SFSGameApi extends Object implements ISFSGameApi
Provides specialized methods for advanced game functionalities such as:
  • Match making
  • Creation of private/invitation-only games
  • Invitations
  • Quick joining games matching specific parameters
  • Etc...
  • Field Details

    • sfs

      protected SmartFoxServer sfs
    • sfsApi

      protected ISFSApi sfsApi
    • log

      protected final org.slf4j.Logger log
    • responseApi

      protected final com.smartfoxserver.api.response.ISFSGameResponseApi responseApi
  • Constructor Details

    • SFSGameApi

      public SFSGameApi()
    • SFSGameApi

      public SFSGameApi(SmartFoxServer sfs)
  • Method Details

    • setSFS

      public void setSFS(SmartFoxServer sfs)
      Description copied from interface: ISFSGameApi
      Private
      Specified by:
      setSFS in interface ISFSGameApi
    • getResponseAPI

      public com.smartfoxserver.api.response.ISFSGameResponseApi getResponseAPI()
      Specified by:
      getResponseAPI in interface ISFSGameApi
    • createGame

      public Room createGame(Zone zone, CreateSFSGameSettings settings, User owner) throws SFSCreateRoomException
      Create an SFSGame Room and automatically update the clients and trigger a server event
      Specified by:
      createGame in interface ISFSGameApi
      Parameters:
      zone - the Zone
      settings - the SFSGame settings
      owner - the owner of the game (null == The Server)
      Returns:
      the Room
      Throws:
      SFSCreateRoomException
      See Also:
    • createGame

      public Room createGame(Zone zone, CreateSFSGameSettings settings, User owner, boolean fireClientEvent, boolean fireServerEvent) throws SFSCreateRoomException
      Create an SFSGame Room.
      Specified by:
      createGame in interface ISFSGameApi
      Parameters:
      zone - the Zone
      settings - the SFSGame settings
      owner - the game owner (null == The Server)
      fireClientEvent - if true an update will be sent to the clients (recommended)
      fireServerEvent - if true a server side event will be fired
      Returns:
      the Room
      Throws:
      SFSCreateRoomException
      See Also:
    • quickJoinGame

      public Room quickJoinGame(User player, MatchExpression expression, Zone zone, String groupId) throws SFSJoinRoomException
      Quick join a User in an SFSGame.

      The method will:

      1. match the provided MatchExpression in the scope (Zone/Group) to find a list of possible Rooms that the Player can join.
      2. match the User properties with the SFSGame ones (if any)
      The first Room that matches is joined, otherwise an error is returned.
      If the User is already joined in an another Room, the Room will not be left automatically.
      If you want the User to leave the previous Room use the overloaded version ISFSGameApi.quickJoinGame(User, MatchExpression, Zone, String, Room)
      Specified by:
      quickJoinGame in interface ISFSGameApi
      Parameters:
      player - the User who wants to join a game
      expression - a MatchExpression with the Room search criteria
      zone - the Zone where to search the Rooms
      groupId - if non-null this will restrict the match to the Rooms in that group
      Returns:
      the Room that was joined
      Throws:
      SFSJoinRoomException
      See Also:
    • quickJoinGame

      public Room quickJoinGame(User player, MatchExpression expression, Zone zone, String groupId, Room roomToLeave) throws SFSJoinRoomException
      Quick join a User in an SFSGame.

      The API will:

      1. match the provided MatchExpression in the scope (Zone/Group) to find a list of possible Rooms that the Player can join.
      2. match the User properties with the SFSGame ones (if any)
      The first Room that matches the criteria is joined, otherwise an error is returned.
      Specified by:
      quickJoinGame in interface ISFSGameApi
      Parameters:
      player - the User who wants to join a game
      expression - a MatchExpression with the Room search criteria
      zone - the Zone where to search the Rooms
      groupId - is non-null this will restrict the match to the Rooms in that group
      roomToLeave - the Room to leave after having successfully joined a Game.
      Returns:
      the Room that was joined
      Throws:
      SFSJoinRoomException
      See Also:
    • quickJoinGame

      public Room quickJoinGame(User player, MatchExpression expression, Collection<Room> searchableRooms, Room roomToLeave) throws SFSJoinRoomException
      Quick join a User in an SFSGame.

      The method will:

      1. match the provided MatchExpression in the scope (Zone/Group) to find a list of possible Rooms that the Player can join.
      2. match the User properties with the SFSGame ones (if any)
      The first Room that matches the criteria is joined, otherwise an error is returned.
      Specified by:
      quickJoinGame in interface ISFSGameApi
      Parameters:
      player - the User who wants to join a game
      expression - a MatchExpression with the Room search criteria
      searchableRooms - a List of Rooms to search
      roomToLeave - the Room to leave after having successfully joined a Game
      Returns:
      the Room that was joined
      Throws:
      SFSJoinRoomException
      See Also:
    • sendInvitation

      public void sendInvitation(Invitation invitation, InvitationCallback callBackHandler)
      Send an Invitation to a User.
      An Invitation can be sent for various purposes such as for joining a room/game, adding a friend to the Buddy List etc...
      Specified by:
      sendInvitation in interface ISFSGameApi
      Parameters:
      invitation - the Invitation
      callBackHandler - the Invitation callback handler
      See Also:
    • sendInvitation

      public void sendInvitation(User inviter, List<User> invitees, int expirySeconds, InvitationCallback callBackHandler, ISFSObject params)
      Send an Invitation to a User.
      An Invitation can be sent for various purposes such as for joining a room/game, adding a friend to the Buddy List etc...
      Specified by:
      sendInvitation in interface ISFSGameApi
      Parameters:
      inviter - the Inviter
      invitees - the Invitee
      expirySeconds - the amount of time allowed for the Invitee to accept or refuse the invitation
      callBackHandler - the Invitation callback handler
      params - custom Invitation parameters
      See Also:
    • replyToInvitation

      public void replyToInvitation(User invitedUser, int invitationId, InvitationResponse reply, ISFSObject params, boolean fireClientEvent)
      Handle the Invitation reply of a User
      Specified by:
      replyToInvitation in interface ISFSGameApi
      Parameters:
      invitedUser - the invited User
      invitationId - the id of the invitation
      reply - the reply
      params - optional parameters
      fireClientEvent - will fire a client event in case of failure
    • sendJoinRoomInvitation

      public void sendJoinRoomInvitation(Room target, User inviter, List<User> invitees, int expirySeconds)
      Invites Users / Players in an existing Room. No custom parameters used. Assumes that asSpect = false, and leaveLastJoinedRoom = false.
      Specified by:
      sendJoinRoomInvitation in interface ISFSGameApi
      Parameters:
      target - the Room where people accepting the invitation will be joined in
      inviter - the sender of the invitation. Null can be passed to specify that the invitation is on behalf of the server itself
      invitees - a list of people invited in the Room
      expirySeconds - the amount of seconds allowed to reply to the invitation
    • sendJoinRoomInvitation

      public void sendJoinRoomInvitation(Room target, User inviter, List<User> invitees, int expirySeconds, boolean asSpect, boolean leaveLastJoinedRoom)
      Invites Users / Players in an existing Room. No custom parameters used.
      Specified by:
      sendJoinRoomInvitation in interface ISFSGameApi
      Parameters:
      target - the Room where people accepting the invitation will be joined in
      inviter - the sender of the invitation. Null can be passed to specify that the invitation is on behalf of the server itself
      invitees - a list of people invited in the Room
      expirySeconds - the amount of seconds allowed to reply to the invitation
      asSpect - if true the provided list of people will be joined as spectators (where applicable, i.e. Game Rooms)
      leaveLastJoinedRoom - if true the users joining the target Room will leave the previously joined Room
    • sendJoinRoomInvitation

      public void sendJoinRoomInvitation(Room target, User inviter, List<User> invitees, int expirySeconds, boolean asSpect, boolean leaveLastJoinedRoom, ISFSObject params)
      Invites Users / Players in an existing Room.
      Specified by:
      sendJoinRoomInvitation in interface ISFSGameApi
      Parameters:
      target - the Room where people accepting the invitation will be joined in
      inviter - the sender of the invitation. Null can be passed to specify that the invitation is on behalf of the server itself
      invitees - a list of people invited in the Room
      expirySeconds - the amount of seconds allowed to reply to the invitation
      asSpect - if true the provided list of people will be joined as spectators (where applicable, i.e. Game Rooms)
      leaveLastJoinedRoom - if true the users joining the target Room will leave the previously joined Room
      params - an optional SFSObject with custom data that is sent to the invitees