sfs2x.client.requests
Class ExtensionRequest

java.lang.Object
  extended by sfs2x.client.requests.BaseRequest
      extended by 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
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, CreateRoom, CreateSFSGame, FindRooms, FindUsers, 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, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
 
Constructor Summary
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
 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
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 - If null, the specified command is sent to the current Zone server-side Extension; if not null, the command is sent to the server-side Extension attached to the passed Room.
useUDP - If true, 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)
See Also:
ExtensionRequest(String, ISFSObject, Room, boolean)

ExtensionRequest

public ExtensionRequest(java.lang.String extCmd,
                        com.smartfoxserver.v2.entities.data.ISFSObject params)
See Also:
ExtensionRequest(String, ISFSObject, Room, boolean)
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 *