Add-Buddy-Event?

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

amenthes
Posts: 35
Joined: 22 Oct 2008, 11:55

Add-Buddy-Event?

Postby amenthes » 09 Apr 2009, 12:04

Hi Everyone,

Currently i have a bug/problem in my application: I use Offline-Buddy-Vars to store information about the appearance of a user.

I read this information in a custom buddylist persistor.

When I add a new buddy, this information-reading never happens. So things like the other one's gender are not available in the vars.

Is there something like an "addBuddy-Event" - i searched through the internalEventObject, but there seems to be nothing comparable.

Bottomline is: can i somehow know, extension-wise, that there is a new buddy? I could then add the appropriate vars from the server side.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Apr 2009, 13:12

Hi,
I am not following, sorry.

Have you create a custom java persistence class?
If so what does it do that is different from the default one?

When I add a new buddy, this information-reading never happens. So things like the other one's gender are not available in the vars.

This is where don't understand.
When you add a buddy to your list you will receive an event back to the client.
The persistence class, on the other hand, simply takes care of loading and saving the buddy list data when the server decides that it's the right time.

Can you better explain what the problem is exactly?
Lapo
--
gotoAndPlay()
...addicted to flash games
amenthes
Posts: 35
Joined: 22 Oct 2008, 11:55

Postby amenthes » 13 Apr 2009, 23:15

Have you create a custom java persistence class?
If so what does it do that is different from the default one?


Yes, the persistence class is for storing the buddy-information in our database.

I'll try to explain my problem a little better:

Application
In my application i have a users-table and a buddies-table. Users has information about the user's gender. Buddies just stores two user-ids (the mutual buddies' IDs). The client will display a buddylist that is styled slightly different depending on the other person's gender. This information is supposed to be in a offline-buddyvariable which i'd like to set on the server-side.

What's working
All of the above works the way it is intended - for all your buddies that are already on your list when you logon.

Problem
When i add a new buddy, his/her entry in the buddylist will appear incorrect. We traced this down to the buddyvars being empty. As mentioned above, i'd like to set them from the server-side. As far as i can tell, i have no means of doing this.

It seems to me that the server thinks "Ok he's a new buddy, so there won't be any stored offline buddy-vars i need to fetch". But in my case there are.

I hope i succeded in clarifying my problem. Thanks a lot for reading!
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 14 Apr 2009, 07:59

Thanks for providing more details.
I probably need to ask a few more questions:

We traced this down to the buddyvars being empty. As mentioned above, i'd like to set them from the server-side. As far as i can tell, i have no means of doing this.

Hmmm... setting buddy variables is definitely available from server side and you can set offline buddy variables by using the provided convention where the variable starts with a $ (dollar) character.
Are you doing this?

It seems to me that the server thinks "Ok he's a new buddy, so there won't be any stored offline buddy-vars i need to fetch". But in my case there are.

If the above is correct could you explain step-by-step how you create those variables and at which point you don't get the desired "effect"

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
amenthes
Posts: 35
Joined: 22 Oct 2008, 11:55

Postby amenthes » 14 Apr 2009, 11:19

Lapo wrote:
amenthes wrote:We traced this down to the buddyvars being empty. As mentioned above, i'd like to set them from the server-side. As far as i can tell, i have no means of doing this.

Hmmm... setting buddy variables is definitely available from server side and you can set offline buddy variables by using the provided convention where the variable starts with a $ (dollar) character.
Are you doing this?


Yes, i am aware of this. Currently I have this function in my buddy-persister. I could also put it somewhere else if i knew where.

Code: Select all

@Override
public Map<String, String> getOfflineVariables(String userName) {
   System.out.println("offl-buddy-vars for " + userName);
   Map<String,String> buddyVar = new HashMap<String,String>();

   // this is hardcoded to make the code-snipped easier.
   // Actually this is retrieved from a database.
   String spriteset = "male";   
   buddyVar.put("$spriteset", spriteset);
   return buddyVar;
}


I also have code that sets buddyvars via the BuddylistManager when other events happen. The problem is more of a "when?" not so much the "how do i?".

Lapo wrote:
It seems to me that the server thinks "Ok he's a new buddy, so there won't be any stored offline buddy-vars i need to fetch". But in my case there are.

If the above is correct could you explain step-by-step how you create those variables and at which point you don't get the desired "effect"


I can tell by looking at the output that this function will run several times when a user logs on. All the buddies he already has when logging in will have the correct $spriteset = "male".

I am then walking around in this world and add a new buddy. But this snippet of code will not be running (at least from what i can tell from the System.out.println or from the buddyvars). So that new buddy doesn't have the $spriteset-buddyvar. Thus the buddylist will be displayed incorrectly.

Basically what i need is a clean way to run server-sided code at the moment when a (mutual) buddy-request is successful. If there was an event i could wait for, i'd put code like the snippet above there and everything would be fine.

I have no idea how to make this any clearer. I could offer a beta slot once we are in beta ;-)

Cheers!
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Apr 2009, 07:55

Yes, i am aware of this. Currently I have this function in my buddy-persister. I could also put it somewhere else if i knew where.

This makes sense.
The getOfflineVariables method is called when the client sends the loadBuddyList request, so any values returned in that method will affect the variables that the client will receive for that user in his buddy list.

In other words your client should receive the offline buddy variables correctly in response to a LoadBuddyList request.

I can tell by looking at the output that this function will run several times when a user logs on.

Yes, it runs once for every buddy in the user buddy list.
That's because for each buddy we look for his offline variables, makes sense for you?

I am then walking around in this world and add a new buddy. But this snippet of code will not be running

It definitely should!
In fact this works correctly in our example applications.
I would suggest to track the debug of the SmartFoxClient API which is printed out in the Output Window (F2 key) of the Flash IDE.
Right after having sent an addBuddy request you should get the relative server response which sends you all the details about the added buddy, including his/her online (if he's connected) and offline variables.

This will also fire the onBuddyList event on the client.
Lapo

--

gotoAndPlay()

...addicted to flash games
amenthes
Posts: 35
Joined: 22 Oct 2008, 11:55

Postby amenthes » 15 Apr 2009, 13:35

Lapo wrote:Yes, it runs once for every buddy in the user buddy list.
That's because for each buddy we look for his offline variables, makes sense for you?


Yes, that's perfectly alright.

Lapo wrote:
I am then walking around in this world and add a new buddy. But this snippet of code will not be running


It definitely should!


It will run the next time i login, but not at the moment when the buddy-request is succesful. To illustrate that i attached a snippet from my Logfile, shortened the timestamp and jvm-stuff to make it more readable:

The server has been started just before this test.
User1 is Test, he has never been logging in (brand new user)
User2 is amenthes, he has some buddies already (nina and pixel).

Code: Select all

INFO 16:03:15| 16:03:15.788 - [ INFO ] > Server is up and running!
INFO 16:03:37| [ DBLogin ]: User demo4 logged in with ID 0
INFO 16:03:37| Getting offline-vars for amenthes
INFO 16:04:20| Getting offline-vars for demo4
INFO 16:04:20| [ DBLogin ]: User demo1 logged in with ID 1
INFO 16:07:29| [ DBLogin ]: User demo8 logged in with ID 2
INFO 16:08:49| [ DBLogin ]: User Test logged in with ID 3
INFO 16:08:56| 16:08:56.148 - [ INFO ] > Disconneting idle user: demo4
INFO 16:09:36| 16:09:36.156 - [ INFO ] > Disconneting idle user: demo1
INFO 16:10:03| [ DBLogin ]: User amenthes logged in with ID 4
INFO 16:10:03| Getting offline-vars for nina
INFO 16:10:03| Getting offline-vars for pixel
INFO 16:10:26| 16:10:26.285 - [ INFO ] > Asking buddy permission. Sender: Test, Target:it.gotoandplay.smartfoxserver.data.User@1eafe13


This buddy-request has been accepted, but there is no "Getting offline-vars for Test".

Lapo wrote:In other words your client should receive the offline buddy variables correctly in response to a LoadBuddyList request.


I'll receive a onBuddyList-event once the request is successful and it doesn't have the desired offline-vars. Even if i call loadBuddyList(), no offline-vars will be loaded.

Once i log back in, the offlineVars will be loaded, but not right after the request.

I am really stuck on this one. :(
amenthes
Posts: 35
Joined: 22 Oct 2008, 11:55

Postby amenthes » 15 Apr 2009, 13:51

I noticed that SFS does only call get getOfflineVariables once per userName. Is there any criterium from which SFS determines that he won't have to load for some userNames? Maybe i have some caching problem or something like that?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Apr 2009, 07:06

This buddy-request has been accepted, but there is no "Getting offline-vars for Test".


If you simply take a look at the AdvanceBuddyList example provided with SmartFoxServer you will notice that when you add a buddy to your list you always receive all his variables.

You can test in 2 different ways:

1) With the addBuddyPermission==false
User AA adds User BB (who is offline)
User AA receives User BB's offline variables

2) With the addBuddyPermission==true
User AA adds User BB (who is online)
User AA receives User BB's regular variables and offline variables (after User BB approval of the request)

I'll receive a onBuddyList-event once the request is successful and it doesn't have the desired offline-vars. Even if i call loadBuddyList(), no offline-vars will be loaded.

Then the problem is somewhere else, maybe a mix of issues with your code and the configurations parameters. Unfortunately I can't say.

One last thing. I test on SFS version 1.6.4 which is not the latest version.
In case you are running an older version, you might want to upgrade and see if the problem persists.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 24 guests