How to update user ID?

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

User avatar
moccha
Posts: 50
Joined: 13 Feb 2014, 16:09

How to update user ID?

Postby moccha » 27 Aug 2015, 18:59

I started using the PrivateMessageRequest function client side and when I go to send a message I get the User ID from their name via "sfs.userManager.getUserByName(username).id". When I first get a users name for example "Charles", it tells me Charles ID is 18. When he logs out and logs back in, it still says his ID is 18 instead of the correct value, which would be 19. It then tries to send the PM to the user but fails because the ID is incorrect, but the client throws no errors. How do i properly update the clients ID with the matching current server ID?
User avatar
Lapo
Site Admin
Posts: 19679
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to update user ID?

Postby Lapo » 28 Aug 2015, 08:46

Are sender and recipient in the same Room when they're sending private messages?
It seems to me the problem depends on that.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
moccha
Posts: 50
Joined: 13 Feb 2014, 16:09

Re: How to update user ID?

Postby moccha » 29 Aug 2015, 18:55

Yes, they're definitely in the same room. I join the Lobby, then player 2 joins lobby. My client says their ID was "18". After player 2 logout and rejoin Lobby, it still says their ID is 18 but it should retrieve 19. It tries to send to "18" but nothing happens since this user does not exist, but my client never complains.
User avatar
Lapo
Site Admin
Posts: 19679
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to update user ID?

Postby Lapo » 30 Aug 2015, 19:35

Two things:
1- Can you tell me the version number of the AS3 API you're using
2- Instead of this code: sfs.userManager.getUserByName(username).id
can you use room.getUserByName("userName") instead and see if returns the right ID? I suspect it will.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 50
Joined: 13 Feb 2014, 16:09

Re: How to update user ID?

Postby moccha » 01 Sep 2015, 03:20

I'm using the latest version of the API for as3. (1.6.0)
Also, it does work when i change the code to a local room, however I obviously can't work with other users this way if they're in different rooms as you know. Do you have any ideas or solutions? thanks Lapo. :cry:
User avatar
Lapo
Site Admin
Posts: 19679
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to update user ID?

Postby Lapo » 01 Sep 2015, 14:55

moccha wrote:I'm using the latest version of the API for as3. (1.6.0)
Also, it does work when i change the code to a local room, however I obviously can't work with other users this way if they're in different rooms as you know. Do you have any ideas or solutions? thanks Lapo. :cry:

There is something not clear in your post.
You said the problem was in the "Lobby". Now you're saying that users are in different rooms.
Can you clarify the steps to reproduce this problem?

Also, the initial case you have described (2 users in the same room) is not reproducible:
Yes, they're definitely in the same room. I join the Lobby, then player 2 joins lobby. My client says their ID was "18". After player 2 logout and rejoin Lobby, it still says their ID is 18 but it should retrieve 19. It tries to send to "18" but nothing happens since this user does not exist, but my client never complains.


Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 50
Joined: 13 Feb 2014, 16:09

Re: How to update user ID?

Postby moccha » 01 Sep 2015, 17:28

Sorry for the confusion. I was only saying that "room.getUserByName("userName").id" forces users to be in the same room to send private messages. The code you suggested does work properly though when a user logs in and out.

Here's the scenario: Client1 is a Guest and Client2's name is "charles". Pressing a key in either client will trace the ID value for "charles" via this method:

Code: Select all

trace(sfs.userManager.getUserByName("charles").id)


Client1 (Guest) logs in and then Client2 (charles) logs in. Client1's trace produces an ID of 2 for "charles". Client2's trace also produces an ID of 2. Client2 logs out and then back in. Client1's trace still produces 2, while Client2's produces the correct number of 3. No matter what, Client1 keeps saying the ID is 2, even if Guest2 is logged out. Is there an update event I'm not receiving?
User avatar
Lapo
Site Admin
Posts: 19679
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to update user ID?

Postby Lapo » 01 Sep 2015, 19:04

moccha wrote:Sorry for the confusion. I was only saying that "room.getUserByName("userName").id" forces users to be in the same room to send private messages. The code you suggested does work properly though when a user logs in and out.

I understand what you are saying but there is a catch.
Two users cannot exchange private messages in separate Rooms if they haven't "met" before. What I mean is that if User A logs in and goes to Room 1 and User B logs in and goes to Room 2, the two clients never meet and therefore they don't have access to their respective IDs.

For this to work correctly they both must meet in a common room, let's a the "Lobby", at this point each client has seen the other User at least once and has the data necessary to send private messages even from separated Rooms.

Now we get to the scenario that you're talking about. User B disconnects, and then reconnects a bit later with a new ID, while User A still holds the old User ID, which no longer works

Here's the problem, but it's not an API issue. This is an application logic issue, because we must work with the limitation that the server will only update the people who are in the same Room with User B. If the server had to update everybody it would waste a ton of bandwidth and resources. Additionally such a global update would not interest most of the other people.

If this is the kind of logic you need for your application you don't need Private Messages, but rather you should use the Buddy List, which allows users to exchange state, variables and messages across without the need to be in the same Room. Actually the Buddy List doesn't require Rooms at all.

I hope this clarifies the problem.

For more on the BuddyList API see here: http://docs2x.smartfoxserver.com/Advanc ... y-list-api
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 50
Joined: 13 Feb 2014, 16:09

Re: How to update user ID?

Postby moccha » 01 Sep 2015, 19:11

Thanks Lapo, I'll instead use the buddy list for this type of communication. I appreciate your detailed response.

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 4 guests