Package sfs2x.client.requests
Class ExtensionRequest
- java.lang.Object
-
- sfs2x.client.requests.BaseRequest
-
- sfs2x.client.requests.ExtensionRequest
-
- All Implemented Interfaces:
sfs2x.client.requests.IRequest
public class ExtensionRequest extends BaseRequest
Sends a command to the server-side Extension attached to the Zone or to a Room.This request is used to send custom commands from the client to a server-side Extension, be it a Zone-level or Room-level Extension. Viceversa, the extensionResponse event is used by the server to send Extension commands/responses to the client.
Read the SmartFoxServer 2X documentation about server-side Extension for more informations.
The ExtensionRequest request can be sent using the UDP protocol too, provided it is available (see the SmartFox.udpAvailable property): this allows sending fast stream of packets to the server in real-time type games, typically for position/transformation updates, etc.
Example
The following example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the extensionResponse listener (the same command name is used in both the request and the response):private void someMethod() { sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { if (evt.getArguments().get("cmd") == "add") { ISFSObject responseParams = (SFSObject)evt.getArguments().get("params"); // We expect an int parameter called "sum" System.out.println("The sum is: " + responseParams.getInt("sum")); } } }); // Send two integers to the Zone extension and get their sum in return ISFSObject params = new SFSObject(); params.putInt("n1", 26); params.putInt("n2", 16); sfs.send(new ExtensionRequest("add", params)); }
- See Also:
SFSEvent.EXTENSION_RESPONSE
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_CMD
* API internal usage only *static java.lang.String
KEY_PARAMS
* API internal usage only *static java.lang.String
KEY_ROOM
* API internal usage only *-
Fields inherited from class sfs2x.client.requests.BaseRequest
AddBuddy, AdminMessage, AutoJoin, BanUser, BlockBuddy, CallExtension, ChangeRoomCapacity, ChangeRoomName, ChangeRoomPassword, ClusterInviteUsers, ClusterJoinOrCreate, CreateRoom, CreateSFSGame, FindRooms, FindUsers, GameServerConnectionRequired, GenericMessage, GetRoomList, GoOnline, Handshake, InitBuddyList, InvitationReply, InviteUser, JoinRoom, JoinRoomInvite, KEY_ERROR_CODE, KEY_ERROR_PARAMS, KickUser, LeaveRoom, Login, Logout, ManualDisconnection, ModeratorMessage, ObjectMessage, PingPong, PlayerToSpectator, PrivateMessage, PublicMessage, QuickJoinGame, QuickJoinOrCreateRoom, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
-
-
Constructor Summary
Constructors Constructor Description ExtensionRequest(java.lang.String extCmd, com.smartfoxserver.v2.entities.data.ISFSObject params)
ExtensionRequest(java.lang.String extCmd, com.smartfoxserver.v2.entities.data.ISFSObject params, Room room)
ExtensionRequest(java.lang.String extCmd, com.smartfoxserver.v2.entities.data.ISFSObject params, Room room, boolean useUDP)
Creates a new ExtensionRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(ISmartFox sfs)
* API internal usage only *boolean
getUseUDP()
* API internal usage only *void
validate(ISmartFox sfs)
* API internal usage only *-
Methods inherited from class sfs2x.client.requests.BaseRequest
getId, getMessage, getTargetController, isEncrypted, setEncrypted, setId, setTargetController
-
-
-
-
Field Detail
-
KEY_CMD
public static final java.lang.String KEY_CMD
* API internal usage only *- See Also:
- Constant Field Values
-
KEY_PARAMS
public static final java.lang.String KEY_PARAMS
* API internal usage only *- See Also:
- Constant Field Values
-
KEY_ROOM
public static final java.lang.String KEY_ROOM
* API internal usage only *- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExtensionRequest
public ExtensionRequest(java.lang.String extCmd, com.smartfoxserver.v2.entities.data.ISFSObject params, Room room, boolean useUDP)
Creates a new ExtensionRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.- Parameters:
extCmd
- The name of the command which identifies an action that should be executed by the server-side Extension.params
- An instance of SFSObject containing custom data to be sent to the Extension. Can be null if no data needs to be sent.room
- Ifnull
, the specified command is sent to the current Zone server-side Extension; if notnull
, the command is sent to the server-side Extension attached to the passed Room.useUDP
- Iftrue
, the UDP protocol is used to send the request to the server (check the SmartFox.udpAvailable property for more informations).- See Also:
SmartFox.send(sfs2x.client.requests.IRequest)
,SFSObject
-
ExtensionRequest
public ExtensionRequest(java.lang.String extCmd, com.smartfoxserver.v2.entities.data.ISFSObject params, Room room)
-
ExtensionRequest
public ExtensionRequest(java.lang.String extCmd, com.smartfoxserver.v2.entities.data.ISFSObject params)
-
-
Method Detail
-
getUseUDP
public boolean getUseUDP()
* API internal usage only *
-
validate
public void validate(ISmartFox sfs) throws sfs2x.client.exceptions.SFSValidationException
* API internal usage only *- Throws:
sfs2x.client.exceptions.SFSValidationException
-
execute
public void execute(ISmartFox sfs)
* API internal usage only *
-
-