smartfox buddies mechanism

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

smartfox buddies mechanism

Postby crosskid » 31 Jan 2013, 10:09

hello, now i'm dealing with buddies development in my current game
i'm having several questions regarding of this, as i've seen there not too many documentation about the smartfox buddies mechanism

1. if a user want to add a friend, is it using [AddBuddyRequest requestWithBuddyName:@"loggedUserName"]; ? is it must use the exact string name? i mean the name of the user that can be monitored in zone monitor of the admin panel?
2. after a user request a friend request, is it need to be confirmed by the other user? is there a way after request immediately become a friend?
3. by the default, where the buddies "database" stored? and what kind of information that can be stored into the "database", is it only "name", "blocked", and "temp" as i seen in admin panel?
4. where i can see an user buddies? is it in zone monitor on buddy properties tab?
5. from what i know, buddies mechanism must be initiated with something like [self.smartFox send:[InitBuddyListRequest request]];, is the previous information that stored in "database" will be taken based on "loggedUserName" which means the "loggedUserName" must be unique?

i think that's enough for the start, i'll apreciate if there is an iOS example code at least to befriend with one and others.
thanks
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: smartfox buddies mechanism

Postby Bax » 05 Feb 2013, 09:09

1) Yes, you have to send the exact username (case sensitive)
2) No, when adding a buddy, this is immediately added, without confirmation.
3) Buddy list informations are stored in the data folder of the server. It stores the usernames, state and the persistent buddy variables.
4) Yes.
5) Exactly.
Paolo Bax
The SmartFoxServer Team
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: smartfox buddies mechanism

Postby crosskid » 05 Feb 2013, 10:22

ah, thanks Bax. i'll post again when i'm having issues with the buddies things
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: smartfox buddies mechanism

Postby crosskid » 22 Feb 2013, 08:45

hello again Bax, now i'm working on smartfox buddies again
i have a question, let's say user A have user variables, then can user B (as a friend of user A) see A user variables? is it as buddyVariable?

i'm having trouble with it.
the workflow would be like this : first, client request his buddy list

Code: Select all

NSArray *buddy = [NSArray arrayWithArray:[[_smartFox buddyManager] buddyList]];


when i check buddy variable content, it was
[Buddy: playerName, id: 270]


then, i want access buddies user variable, but either of

Code: Select all

NSLog(@"buddies var %@", [[buddy objectAtIndex:0] getOnlineVariables]);

or

Code: Select all

NSLog(@"buddies var %@", [[buddy objectAtIndex:0] getOfflineVariables]);


return null result, where did i went wrong? thanks

EDIT

sorry, i found SFSBuddyVariable, now i set buddy variable like this

Code: Select all

SFSBuddyVariable *budVar = [SFSBuddyVariable variableWithName:@"blahblah" value:blahblah];
[_smartFox send:[SetBuddyVariablesRequest requestWithBuddyVariables:[NSArray arrayWithObjects:budVar, nil]]];


now on admin panel, i check the user, on buddy properties tab. i can clearly see the "blahblah" variable with offline properties marked cross
but still, the other user can't see the buddy variables with above code, getOnlineVariables
am i doing wrong on storing buddy list?
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: smartfox buddies mechanism

Postby A51Integrated » 22 Feb 2013, 15:30

Buddy variables and User variables are two separate things. User variables are attached to the user. If you have the user object, you can iterate through the User variables, see: http://docs2x.smartfoxserver.com/api-do ... iable.html

Buddy variables are attached to a buddy, see http://docs2x.smartfoxserver.com/api-do ... iable.html

Obviously a buddy is a user, so there is some overlap, but buddy variables can be persistant, meaning the can be stored and retrieved if the user is offline, where as User variables are only accessible when the User is logged in.

There are use cases for each.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: smartfox buddies mechanism

Postby crosskid » 22 Feb 2013, 18:22

yes, i've realize it different things.
so, actually how to get buddy list then access the buddies variables?

this code

Code: Select all

NSArray *buddy = [NSArray arrayWithArray:[[_smartFox buddyManager] buddyList]];

works fine, but then

Code: Select all

[[buddy objectAtIndex:0] getOnlineVariables]);
or

Code: Select all

[[buddy objectAtIndex:0] getOfflineVariables]);

give empty result. could you tell me where did i went wrong? thanks
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: smartfox buddies mechanism

Postby A51Integrated » 22 Feb 2013, 18:58

See the docs here: http://docs2x.smartfoxserver.com/api-do ... eVariables

It's very similar to retrieving User or Room variables. Use the buddy object and call the getOnlineVariables or getOfflineVariables method to retrieve an array. Then iterate through the returned array

Code: Select all

   NSArray *vars = [buddy getOnlineVariables];
   
   for (NSString *key in vars) {
      NSLog(@"%@", key);
   }


Or to first get the buddylist and then retrieve variables for each buddy:

Code: Select all

        NSArray *buddyList = [[client buddyManager] buddyList];
   
   for (SFSBuddy *buddy in buddyList) {
            NSArray *vars = [buddy getOfflineVariables];
       
            for (NSString *key in vars) {
                NSLog(@"%@", key);
            }
   }
A51 Integrated

http://a51integrated.com / +1 416-703-2300
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: smartfox buddies mechanism

Postby crosskid » 26 Feb 2013, 02:05

thanks for the reply, i found something confusing with above code

my code is look like this

Code: Select all

 NSArray *buddyList = [[_smartFox buddyManager] buddyList];
    for (SFSBuddy *buddy in buddyList) {
        NSArray *vars = [buddy getOnlineVariables];
        for (NSString *key in vars) {
            NSLog(@"%@", key);
        }
       
        NSArray *vars2 = [buddy getOfflineVariables];
        for (NSString *key in vars2) {
            NSLog(@"%@", key);
        }
       
        NSLog(@"%@ \n%@",vars, vars2);
    }
    NSLog(@"STAAAHP %d", [[buddyList objectAtIndex:0] containsVariable:@"$facebookId"]);
    NSLog(@"STAAAHP %@", [[[buddyList objectAtIndex:0] getVariable:@"$facebookId"] getStringValue]);
    NSLog(@"STAAAHP %@", [[[buddyList objectAtIndex:1] getVariable:@"$facebookId"] getStringValue]);
    NSLog(@"STAAAHP %@", [[[buddyList objectAtIndex:2] getVariable:@"$facebookId"] getStringValue]);
    NSLog(@"STAAAHP");


the part where i got confused is in the loop using getOfflineVariables & getOnlineVariables it's not log anything, but when i try to get the variable directly using getVariable it's catch the variable right in the spot

from the above code, the log is :

Code: Select all

2013-02-26 08:41:08.901 big2[23484:1c403] (
)
(
)
2013-02-26 08:41:08.901 big2[23484:1c403] (
)
(
)
2013-02-26 08:41:08.902 big2[23484:1c403] (
)
(
)
2013-02-26 08:41:08.902 big2[23484:1c403] STAAAHP 1
2013-02-26 08:41:08.902 big2[23484:1c403] STAAAHP 1205862493
2013-02-26 08:41:08.902 big2[23484:1c403] STAAAHP 1527465771
2013-02-26 08:41:08.902 big2[23484:1c403] STAAAHP (null)
2013-02-26 08:41:08.903 big2[23484:1c403] STAAAHP


one more question, if A befriend with B but B not befriended yet with A, is it true A can't see B buddy variables yet?
as you can see in above log, the part of

Code: Select all

NSLog(@"STAAAHP %@", [[[buddyList objectAtIndex:2] getVariable:@"$facebookId"] getStringValue]);
return null
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: smartfox buddies mechanism

Postby A51Integrated » 26 Feb 2013, 16:27

Make sure your data types are correct for your NSLog statements.

Yes, in your scenario, A would not get B's updates.
A51 Integrated

http://a51integrated.com / +1 416-703-2300
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: smartfox buddies mechanism

Postby crosskid » 27 Feb 2013, 09:20

ah, i see.

so far my buddies mechanism is when a player want to befriended with another player, he send request to server side extension and server side extension make both of them as a friend
now i got another problem

lets use A & B thing again :D
after A add B as a friend, i see on admin panel A already friend with B, and B already friend with A too
but, when i check using

Code: Select all

if ([[_smartFox buddyManager] containsBuddy:@"B"]) {
   //do something
}

right away, it never come to true unless i logout and login again

i suspect there is something i must do to "save" current buddy list
i see on another thread (not iOS) there is some kind of "saveList" method, is it possible in iOS?
or, i suspect i must re-init the "InitBuddyListRequest" again, how to do this? or something like "refresh" the buddyManager
thanks
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: smartfox buddies mechanism

Postby A51Integrated » 27 Feb 2013, 15:06

Try to only retrieve the entire BuddyList once - it can grow rather large. Once retrieved, store it locally on the client and listen for events to update your local copy. By retrieving the entire buddy list for each call, you're wasting a lot of bandwidth and using unnecessary resources.
A51 Integrated

http://a51integrated.com / +1 416-703-2300
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: smartfox buddies mechanism

Postby crosskid » 28 Feb 2013, 05:22

so you say it's better to call it only once, then store to a variable something like

Code: Select all

NSArray *buddyList = [[client buddyManager] buddyList];


then A add a buddy, making request to server side extension, then both A and B become a friend
from here if A want to check B is already friend with B or not, you suggest i manipulated the local variable instead of request fresh buddy list?
by manipulated the local variable i mean when A make request to server side extension, then server side extension send some data, when A received the response, add B in the local variable (in this case is NSArray *buddyList). is it right?

still, i dont know why call

Code: Select all

if ([[_smartFox buddyManager] containsBuddy:@"B"]) {
   //do something
}

not returning true value when "B" is already added
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: smartfox buddies mechanism

Postby A51Integrated » 01 Mar 2013, 15:41

This may be cause by the way you're adding buddies from an extension as apposed to the traditional method. Make certain that you are replicating the exact SFS series of events when adding a buddy on the back end.
A51 Integrated

http://a51integrated.com / +1 416-703-2300

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 29 guests