Package sfs2x.client.requests.buddylist
Class SetBuddyVariablesRequest
- java.lang.Object
-
- sfs2x.client.requests.BaseRequest
-
- sfs2x.client.requests.buddylist.SetBuddyVariablesRequest
-
- All Implemented Interfaces:
sfs2x.client.requests.IRequest
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".
Example
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()); } } else { 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 (); vars.add(songTitle); vars.add(songAuthor); vars.add(mood); sfs.send(new SetBuddyVariablesRequest(vars)); }
-
-
Field Summary
Fields Modifier and Type Field Description 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, 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 SetBuddyVariablesRequest(java.util.List<BuddyVariable> buddyVariables)
Creates a new SetBuddyVariablesRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
-
Field Detail
-
KEY_BUDDY_NAME
public static final java.lang.String KEY_BUDDY_NAME
* API internal usage only *- See Also:
- Constant Field Values
-
KEY_BUDDY_VARS
public static final java.lang.String KEY_BUDDY_VARS
* API internal usage only *- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SetBuddyVariablesRequest
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.- Parameters:
buddyVariables
- A list of BuddyVariable objects representing the Buddy Variables to be set.- See Also:
SmartFox.send(sfs2x.client.requests.IRequest)
,BuddyVariable
-
-