SetBuddyVariablesRequest Class |
Namespace: Sfs2X.Requests.Buddylist
public class SetBuddyVariablesRequest : BaseRequest
The SetBuddyVariablesRequest type exposes the following members.
Name | Description | |
---|---|---|
SetBuddyVariablesRequest |
Creates a new SetBuddyVariablesRequest instance.
|
void SomeMethod() { // Add event listener for BuddyVariables sfs.AddEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, OnBuddyVarsUpdate); // 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<BuddyVariable> myVars = new List<BuddyVariable>(); myVars.Add(songTitle); myVars.Add(songAuthor); myVars.Add(mood); sfs.Send(new SetBuddyVariablesRequest(myVars)); } void OnBuddyVarsUpdate(BaseEvent evt) { // As the update event is dispatched to me too, // I have to check if I am the one who changed his Buddy Variables Buddy buddy = (Buddy)evt.Params["buddy"]); bool isItMe = (bool)evt.Params["isItMe"]; List<string> changedVars = (List<string>)evt.Params["changedVars"]; if (isItMe) { Console.WriteLine("I've updated the following Buddy Variables:"); // .Net / Unity System.Diagnostics.Debug.WriteLine("I've updated the following Buddy Variables:"); // UWP for (int i = 0; i < changedVars.Count; i++) { string bVarName = changedVars[i]; Console.WriteLine(bVarName + ": " + sfs.BuddyManager.GetMyVariable(bVarName).Value()); // .Net / Unity System.Diagnostics.Debug.WriteLine(bVarName + ": " + sfs.BuddyManager.GetMyVariable(bVarName).Value()); // UWP } } else { string buddyName = buddy.Name; Console.WriteLine("My buddy " + buddyName + " updated the following Buddy Variables:"); // .Net / Unity System.Diagnostics.Debug.WriteLine("My buddy " + buddyName + " updated the following Buddy Variables:"); // UWP for (int i = 0; i < changedVars.Count; i++) { var bVarName:String = changedVars[i]; Console.WriteLine(bVarName + ": " + sfs.BuddyManager.GetBuddyByName(buddyName).GetVariable(bVarName).Value()); // .Net / Unity System.Diagnostics.Debug.WriteLine(bVarName + ": " + sfs.BuddyManager.GetBuddyByName(buddyName).GetVariable(bVarName).Value()); // UWP } } }