Class SetBuddyVariablesRequest

  extended by sfs2x.client.requests.BaseRequest
      extended by sfs2x.client.requests.buddylist.SetBuddyVariablesRequest
All Implemented Interfaces:

public class SetBuddyVariablesRequest
extends BaseRequest

Sets one or more Buddy Variables for the current user.

This operation updates the Buddy object representing the user in all the buddies lists in which the user was added as a buddy. If the operation is successful, a buddyVariablesUpdate event is dispatched to all the owners of those buddies lists and to the user who updated his variables too.

NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description) and the current user state in the system is "online".

The following example sets some Buddy Variables for the current user, one of which is persistent; the example also handles changes made by the user or by his buddies:

 private void someMethod() {
     sfs.addEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, new IEventListener() {
         public void dispatch(BaseEvent evt) throws SFSException {
             // As the update event is dispatched to me too,
             // I have to check if I am the one who changed his Buddy Variables
             boolean isItMe = (Boolean) evt.getArguments().get("isItMe");
             if (isItMe) {
                 System.out.println("I've updated the following Buddy Variables:");
                 for (String bVarName : (List) evt.getArguments().get("changedVars")) {
                     System.out.println(bVarName + "-->" + sfs.getBuddyManager().getMyVariable(bVarName).getValue());
                 String buddyName = ((Buddy) evt.getArguments().get("buddy")).getName();
                 System.out.println("My buddy " + buddyName + " updated the following Buddy Variables:");
                 for (String bVarName : (List) evt.getArguments().get("changedVars")) {
                     System.out.println(bVarName + "-->" + sfs.getBuddyManager().getBuddyByName(buddyName).getVariable(bVarName).getValue());
     // Create two Buddy Variables containing the title and artist of the song I'm listening to
     BuddyVariable songTitle = new SFSBuddyVariable("songTitle", "Ascension");
     BuddyVariable songAuthor = new SFSBuddyVariable("songAuthor", "Mike Oldfield");
     // Create a persistent Buddy Variable containing my mood message
     BuddyVariable mood = new SFSBuddyVariable(SFSBuddyVariable.OFFLINE_PREFIX + "mood", "I Need SmartFoxServer 2X desperately!");
     // Set my Buddy Variables
     List vars = new ArrayList();
     sfs.send(new SetBuddyVariablesRequest(vars));

See Also:
BuddyVariable, SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, InitBuddyListRequest

Field Summary
static java.lang.String KEY_BUDDY_NAME
          * API internal usage only *
static java.lang.String KEY_BUDDY_VARS
          * 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
SetBuddyVariablesRequest(java.util.List<BuddyVariable> buddyVariables)
          Creates a new SetBuddyVariablesRequest instance.
Method Summary
 void execute(ISmartFox sfs)
          * 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


public static final java.lang.String KEY_BUDDY_NAME
* API internal usage only *

See Also:
Constant Field Values


public static final java.lang.String KEY_BUDDY_VARS
* API internal usage only *

See Also:
Constant Field Values
Constructor Detail


public SetBuddyVariablesRequest(java.util.List<BuddyVariable> buddyVariables)
Creates a new SetBuddyVariablesRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

buddyVariables - A list of BuddyVariable objects representing the Buddy Variables to be set.
See Also:
SmartFox.send(sfs2x.client.requests.IRequest), BuddyVariable
Method Detail


public void validate(ISmartFox sfs)
              throws sfs2x.client.exceptions.SFSValidationException
* API internal usage only *



public void execute(ISmartFox sfs)
* API internal usage only *