saving buddy vars on client side

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

saving buddy vars on client side

Postby sstark » 05 Jan 2009, 22:59

sfs 1.6.3

Config:

Code: Select all

<BuddyList active="true">
         <size>150</size>
         <mode>advanced</mode>
         <addBuddyPermission>true</addBuddyPermission>
         <mutualAddBuddy>true</mutualAddBuddy>
         <mutualRemoveBuddy>false</mutualRemoveBuddy>
         <offLineBuddyVariables>true</offLineBuddyVariables>
        </BuddyList>



when a user logs in, they set their own buddy var:

(I had to modify SmartFoxClient.as for this to work:
from : public function setBuddyVariables(varList:Array):void
to : public function setBuddyVariables(varList:*):void
because the documentation examples pass an Object, not an Array)

Code: Select all

        var b_v:Object = new Object()
        b_v["$user_id"] = String(myId)
        com.noname.Vars.sfs.setBuddyVariables(b_v)


this works! see trace:

Code: Select all

[Sending]: <msg t='sys'><body action='setBvars' r='-1'><vars><var n='$user_id'><![CDATA[3]]></var></vars></body></msg>


and I am trying to access those var's in my buddy list:

Code: Select all

for (var b:String in com.noname.Vars.sfs.buddyList)
{
          var buddy:Object = com.noname.Vars.sfs.buddyList[b]
          for (var v:String in com.noname.Vars.sfs.myBuddyVars)
          {
            trace("My User's Variable " + v + " --> " + com.noname.Vars.sfs.myBuddyVars[v])
          }
          for (var v2:String in buddy.variables)
          {
              trace("\tBuddyVariable: " + v2 + " --> " + buddy.variables[v2])
          }
}


This traces my own buddy variables, but there is no output for the variables from my buddies.
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 09 Jan 2009, 17:27

bump
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 15 Jan 2009, 18:38

I've moved back to an Array, still same problems. No change.

doesn't matter if it's offline var or a regular one.

Is there some kind of event or something I'm missing?
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 19 Jan 2009, 20:44

Ok, we have now purchased the 500 user license. It is my understanding that this comes with increased support. The email we received said, however, to still post support requests on the forum.

I really need this problem addressed. Please and thank you for any suggestions, guidance and help you can provide.
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 22 Jan 2009, 16:41

Thank you for the 1.6.5 update!


Defiantly have progress with this issue now... but still not quiiite there in my case

The API still is asking for an Array, however the code example and doc's use an Object for public function setBuddyVariables(varList:Array):void, so I just change it to public function setBuddyVariables(varList:Object):void.

I have two users, 'aaa' and 'sstark'. sstark see's aaa's buddy vars, however aaa does not see sstark's vars.

see traces:
note: $user_id is the user's id from the sql database
note 2: The information IS in the XML from the server, so I know we're very close here.


sstark:

Code: Select all

====================>initBuddyList
My User's Variable $user_id --> 23
B0
Buddy id: 13
Buddy name: aaa
Is buddy online: Yes
Is buddy blocked: No
BuddyVariable: $user_id --> 3
[Sending]: <msg t='xt'><body action='xtReq' r='3'><![CDATA[<dataObj><var n='name' t='s'>buddyEx</var><obj t='o' o='param'><obj t='a' o='bl'><var n='0' t='s'>aaa</var></obj><var n='user_id' t='n'>23</var></obj><var n='cmd' t='s'>cleanInvites</var></dataObj>]]></body></msg>
refreshing buddy list


aaa:

Code: Select all

====================>initBuddyList
My User's Variable $user_id --> 3
B0
Buddy id: 14
Buddy name: sstark
Is buddy online: Yes
Is buddy blocked: No
[Sending]: <msg t='xt'><body action='xtReq' r='3'><![CDATA[<dataObj><obj t='o' o='param'><obj t='a' o='bl'><var n='0' t='s'>sstark</var></obj><var n='user_id' t='n'>3</var></obj><var n='cmd' t='s'>cleanInvites</var><var n='name' t='s'>buddyEx</var></dataObj>]]></body></msg>
refreshing buddy list
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 28 Jan 2009, 08:05

We provide a fully working example with SmartFoxServer PRO which shows how to work with the Buddy List 2.0, including buddy variables, offline buddy variables, black lists etc...

You find it in the Examples/AS3/ folder

I would highly recommend to take a look at the code there and compare it with what you are doing.
Additionally there is no need to change the API source code, which might in turn create more problems.
Lapo
--
gotoAndPlay()
...addicted to flash games
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 28 Jan 2009, 16:16

Lapo,

I have looked at the example, and have tried to use it. Actually I have copied it directly.

Also, the class does need to be changed because the example in the package and in the docs pass the wrong variable type in the parameters.

Keep in mind I use Flex, not Flash, so I need all variable types to be accurate.

User Variables just do not propagate. :(
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 28 Jan 2009, 16:35

Sorry but I am really not following.

1) The example works perfectly and variables are updated correctly, so both users A and B should be able to see their respective vars

2) There's no problem with the setBuddyVariables in the SmartFoxClient class.You are required to pass an associative array.

This code, is perfectly legal and Flex 3 won't complain

Code: Select all

var anArray:Array = []
anArray["one"] = "test... one"
anArray["two"] = "test... two"

sfs.setBuddyVariables(anArray)


In Actionscript Arrays and Objects are pretty much ambiguous and they can be exchanged, although they differ slightly on the method one call on them.
Lapo

--

gotoAndPlay()

...addicted to flash games
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 28 Jan 2009, 20:24

you're right, just that the doc's and comments pass an Object not an Array:

Code: Select all

 * @example   The following example shows how to set three variables containing the user's status, the current audio track the user listening to and the user's rank. The last one is an offline variable.
       *          <code>
       *          var bVars:Object = new Object()
       *          bVars["status"] = "away"
       *          bVars["track"] = "One Of These Days"
       *          bVars["$rank"] = "guru"
       *          
       *          smartFox.setBuddyVariables(bVars)
       *          </code>


I'm going to start over from scratch, as one time it did save... just once though.

There isn't anything extension wise I need, is there?

UPDATE:

so I deleted the datastore, re-added the friends and re-did the code (as array, putting everything back to normal).

User 'aaa''s variable saves, but 'sstark''s does not save. See traces above to show this.

code:

(in sfs's extension response )

Code: Select all

/** start persistant buddy vars **/        
          
        var b_v:Array = []
        b_v["$user_id"] = String(myVars.myId)
        com.noname.Vars.sfs.setBuddyVariables(b_v)
       
        /** end persistant buddy vars **/


(in my show buddy list code)

Code: Select all

//trace my own buddy vars for testing
        for (var v:String in com.noname.Vars.sfs.myBuddyVars)
        {
          trace("My User's Variable " + v + " --> " + com.noname.Vars.sfs.myBuddyVars[v])
          //This is now needed for basic chat filter
        }
for (var b:String in com.noname.Vars.sfs.buddyList)
        {
          var buddy:Object = com.noname.Vars.sfs.buddyList[b]
           
          // Trace all Buddy Variables
          for (var v2:String in buddy.variables)
          {
              trace("\tBuddyVariable: " + v2 + " --> " + buddy.variables[v2])
          }
}


UPDATE 2:

Deleted the datastore again, re-added the friendships and 'aaa' is saving vars and 'sstark' is not. This shows that my code is right, but there's a problem with the variables saving.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 30 Jan 2009, 15:49

If you are trying to access your own buddy variables you should do it by using the smartfox.myBuddyVars.

http://www.smartfoxserver.com/docs/docP ... yBuddyVars
Lapo

--

gotoAndPlay()

...addicted to flash games
sstark
Posts: 77
Joined: 21 Nov 2008, 16:06

Postby sstark » 30 Jan 2009, 16:39

Lapo wrote:If you are trying to access your own buddy variables you should do it by using the smartfox.myBuddyVars.

http://www.smartfoxserver.com/docs/docP ... yBuddyVars


As you can see, I am doing that. They trace. They don't save on every user.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 61 guests