Issue with Viewing Persistent Buddy Variables on Client Side
Posted: 26 Aug 2024, 13:26
Hello everyone,
I'm encountering a problem with viewing a persistent Buddy variable on the client side in SmartFoxServer. I’ve written a server-side function to save the last login time of a user when they disconnect, using a Buddy variable named $lastlogin. Here is the server-side function I’m using:
The issue is that, on the client side, when I retrieve the buddy list, I cannot see the $lastlogin variable whether the user is online or offline. Here is the code I use to get the buddy list:
Even though the variable is correctly set on the server side (as confirmed by the trace), I cannot see it on the client side, regardless of whether the user is online or offline.
I'm encountering a problem with viewing a persistent Buddy variable on the client side in SmartFoxServer. I’ve written a server-side function to save the last login time of a user when they disconnect, using a Buddy variable named $lastlogin. Here is the server-side function I’m using:
Code: Select all
function onUserDisconnect(event) {
trace("onUserDisconnect");
var user = event.getParameter(SFSEventParam.USER);
var timeuscita = new Date().toISOString();
var lastlogin = new SFSBuddyVariable("$lastlogin", timeuscita, VariableType.STRING);
getBuddyApi().setBuddyVariables(user, [lastlogin], true, true);
}The issue is that, on the client side, when I retrieve the buddy list, I cannot see the $lastlogin variable whether the user is online or offline. Here is the code I use to get the buddy list:
Code: Select all
var buddies = sfs.buddyManager.getBuddyList();
console.log("SFS2X BUDDY_LIST_INIT buddies", buddies);
for (var i = 0; i < buddies.length; i++) {
var buddy = buddies[i];
var lastLogin = buddy.getVariable("$lastlogin");
if (lastLogin != null) {
console.log("Buddy:", buddy.name, "Last Login:", lastLogin.value);
} else {
console.log("Buddy:", buddy.name, "Last Login: not available");
}
}Even though the variable is correctly set on the server side (as confirmed by the trace), I cannot see it on the client side, regardless of whether the user is online or offline.