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