Package com.smartfoxserver.v2.api
Class SFSGameApi
- java.lang.Object
-
- com.smartfoxserver.v2.api.SFSGameApi
-
- All Implemented Interfaces:
ISFSGameApi
public class SFSGameApi extends java.lang.Object implements ISFSGameApi
Provides specialized API calls for advanced game functionalities: player matching, game invitations/challenges, quick games etc...
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
log
protected com.smartfoxserver.v2.api.response.ISFSGameResponseApi
responseApi
protected SmartFoxServer
sfs
protected ISFSApi
sfsApi
-
Constructor Summary
Constructors Constructor Description SFSGameApi()
SFSGameApi(SmartFoxServer sfs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Room
createGame(Zone zone, CreateSFSGameSettings settings, User owner)
Create an SFSGame Room and automatically update the clients and fire a server eventRoom
createGame(Zone zone, CreateSFSGameSettings settings, User owner, boolean fireClientEvent, boolean fireServerEvent)
Create an SFSGame Room.com.smartfoxserver.v2.api.response.ISFSGameResponseApi
getResponseAPI()
Room
quickJoinGame(User player, MatchExpression expression, Zone zone, java.lang.String groupId)
Quick join a User in an SFSGame.Room
quickJoinGame(User player, MatchExpression expression, Zone zone, java.lang.String groupId, Room roomToLeave)
Quick join a User in an SFSGame.Room
quickJoinGame(User player, MatchExpression expression, java.util.Collection<Room> searchableRooms, Room roomToLeave)
Quick join a User in an SFSGame.void
replyToInvitation(User invitedUser, int invitationId, InvitationResponse reply, ISFSObject params, boolean fireClientEvent)
Handle the Invitation reply of a Uservoid
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...void
sendInvitation(User inviter, java.util.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...void
sendJoinRoomInvitation(Room target, User inviter, java.util.List<User> invitees, int expirySeconds)
Invites Users / Players in an existing Room.void
sendJoinRoomInvitation(Room target, User inviter, java.util.List<User> invitees, int expirySeconds, boolean asSpect, boolean leaveLastJoinedRoom)
Invites Users / Players in an existing Room.void
sendJoinRoomInvitation(Room target, User inviter, java.util.List<User> invitees, int expirySeconds, boolean asSpect, boolean leaveLastJoinedRoom, ISFSObject params)
Invites Users / Players in an existing Room.void
setSFS(SmartFoxServer sfs)
Private
-
-
-
Field Detail
-
sfs
protected SmartFoxServer sfs
-
sfsApi
protected ISFSApi sfsApi
-
log
protected final org.slf4j.Logger log
-
responseApi
protected final com.smartfoxserver.v2.api.response.ISFSGameResponseApi responseApi
-
-
Constructor Detail
-
SFSGameApi
public SFSGameApi()
-
SFSGameApi
public SFSGameApi(SmartFoxServer sfs)
-
-
Method Detail
-
setSFS
public void setSFS(SmartFoxServer sfs)
Description copied from interface:ISFSGameApi
Private- Specified by:
setSFS
in interfaceISFSGameApi
-
getResponseAPI
public com.smartfoxserver.v2.api.response.ISFSGameResponseApi getResponseAPI()
- Specified by:
getResponseAPI
in interfaceISFSGameApi
-
createGame
public Room createGame(Zone zone, CreateSFSGameSettings settings, User owner) throws SFSCreateRoomException
Create an SFSGame Room and automatically update the clients and fire a server event- Specified by:
createGame
in interfaceISFSGameApi
- Parameters:
zone
- the Zonesettings
- the SFSGame settingsowner
- the owner of the game (null == The Server)- Returns:
- the Room
- Throws:
SFSCreateGameException
SFSCreateRoomException
- See Also:
SFSGame
,CreateSFSGameSettings
-
createGame
public Room createGame(Zone zone, CreateSFSGameSettings settings, User owner, boolean fireClientEvent, boolean fireServerEvent) throws SFSCreateRoomException
Create an SFSGame Room.- Specified by:
createGame
in interfaceISFSGameApi
- Parameters:
zone
- the Zonesettings
- the SFSGame settingsowner
- 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:
SFSCreateGameException
SFSCreateRoomException
- See Also:
SFSGame
,CreateSFSGameSettings
-
quickJoinGame
public Room quickJoinGame(User player, MatchExpression expression, Zone zone, java.lang.String groupId) throws SFSJoinRoomException
Quick join a User in an SFSGame.The API will:
- match the provided MatchExpression in the scope (Zone/Group) to find a list of possible Rooms that the Player can join.
- match the User properties with the SFSGame ones (if any)
If the User is already joined in an another Room he will not automatically leave that Room.
If you want the User to leave the previous Room use the overloaded versionISFSGameApi.quickJoinGame(User, MatchExpression, Zone, String, Room)
- Specified by:
quickJoinGame
in interfaceISFSGameApi
- Parameters:
player
- the User who wants to join a gameexpression
- a MatchExpression with the Room search criteriazone
- the Zone where to search the RoomsgroupId
- is non-null this will restrict the match to the Rooms in that group- Returns:
- the Room that was joined
- Throws:
SFSJoinRoomException
- See Also:
SFSGame
,MatchExpression
-
quickJoinGame
public Room quickJoinGame(User player, MatchExpression expression, Zone zone, java.lang.String groupId, Room roomToLeave) throws SFSJoinRoomException
Quick join a User in an SFSGame.The API will:
- match the provided MatchExpression in the scope (Zone/Group) to find a list of possible Rooms that the Player can join.
- match the User properties with the SFSGame ones (if any)
- Specified by:
quickJoinGame
in interfaceISFSGameApi
- Parameters:
player
- the User who wants to join a gameexpression
- a MatchExpression with the Room search criteriazone
- the Zone where to search the RoomsgroupId
- is non-null this will restrict the match to the Rooms in that grouproomToLeave
- the Room to leave after having successfully joined a Game.- Returns:
- the Room that was joined
- Throws:
SFSJoinRoomException
- See Also:
SFSGame
,MatchExpression
-
quickJoinGame
public Room quickJoinGame(User player, MatchExpression expression, java.util.Collection<Room> searchableRooms, Room roomToLeave) throws SFSJoinRoomException
Quick join a User in an SFSGame.The API will:
- match the provided MatchExpression in the scope (Zone/Group) to find a list of possible Rooms that the Player can join.
- match the User properties with the SFSGame ones (if any)
- Specified by:
quickJoinGame
in interfaceISFSGameApi
- Parameters:
player
- the User who wants to join a gameexpression
- a MatchExpression with the Room search criteriasearchableRooms
- a List of Rooms to searchroomToLeave
- the Room to leave after having successfully joined a Game.- Returns:
- the Room that was joined
- Throws:
SFSJoinRoomException
- See Also:
SFSGame
,MatchExpression
-
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 interfaceISFSGameApi
- Parameters:
invitation
- the InvitationcallBackHandler
- the Invitation callback handler- See Also:
SFSInvitation
,InvitationCallback
-
sendInvitation
public void sendInvitation(User inviter, java.util.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 interfaceISFSGameApi
- Parameters:
inviter
- the Inviterinvitees
- the InviteeexpirySeconds
- the amount of time allowed for the Invitee to accept or refuse the invitationcallBackHandler
- the Invitation callback handlerparams
- custom Invitation parameters- See Also:
SFSInvitation
,InvitationCallback
-
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 interfaceISFSGameApi
- Parameters:
invitedUser
- the invited UserinvitationId
- the id of the invitationreply
- the replyparams
- optional parametersfireClientEvent
- will fire a client event in case of failure
-
sendJoinRoomInvitation
public void sendJoinRoomInvitation(Room target, User inviter, java.util.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 interfaceISFSGameApi
- Parameters:
target
- the Room where people accepting the invitation will be joined ininviter
- the sender of the invitation. Null can be passed to specify that the invitation is on behalf of the server itselfinvitees
- a list of people invited in the RoomexpirySeconds
- the amount of seconds allowed to reply to the invitation
-
sendJoinRoomInvitation
public void sendJoinRoomInvitation(Room target, User inviter, java.util.List<User> invitees, int expirySeconds, boolean asSpect, boolean leaveLastJoinedRoom)
Invites Users / Players in an existing Room. No custom parameters used.- Specified by:
sendJoinRoomInvitation
in interfaceISFSGameApi
- Parameters:
target
- the Room where people accepting the invitation will be joined ininviter
- the sender of the invitation. Null can be passed to specify that the invitation is on behalf of the server itselfinvitees
- a list of people invited in the RoomexpirySeconds
- the amount of seconds allowed to reply to the invitationasSpect
- 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, java.util.List<User> invitees, int expirySeconds, boolean asSpect, boolean leaveLastJoinedRoom, ISFSObject params)
Invites Users / Players in an existing Room.- Specified by:
sendJoinRoomInvitation
in interfaceISFSGameApi
- Parameters:
target
- the Room where people accepting the invitation will be joined ininviter
- the sender of the invitation. Null can be passed to specify that the invitation is on behalf of the server itselfinvitees
- a list of people invited in the RoomexpirySeconds
- the amount of seconds allowed to reply to the invitationasSpect
- 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 Roomparams
- an optional SFSObject with custom data that is sent to the invitees
-
-