When the user logs in to smartfox I would have to store userId and user object in memory.
The reason for this is I will have to send a custom smartfox event to a particular userId at any point based on my game logic.
I believe, Storing the entire user object would be heavy.
I am looking for ways to not store this entire user object
So I was thinking is there a way to get this user object from their id?
Or is there any other way to send a custom event to a user without storing the user object?
NOTE: Client is not aware of this situation so client won't be calling any event.
This event which will be sent is independently sent to a user so there is no chance of client calling any event before I send this event
Is there any way to get a user object from their id
Re: Is there any way to get a user object from their id
Hi,
I am not sure what you mean by "user object". SmartFoxServer already represent every connected user with a class called SFSUser (which implements a User interface), which represents the player and all its properties (id, variables, settings, session data etc...) and these objects are already available in memory as long as the user's session is active.
You can obtain a User object from its ID, user name or session object. Here're a few examples you can use in your Extension code:
Hope it helps
I am not sure what you mean by "user object". SmartFoxServer already represent every connected user with a class called SFSUser (which implements a User interface), which represents the player and all its properties (id, variables, settings, session data etc...) and these objects are already available in memory as long as the user's session is active.
You can obtain a User object from its ID, user name or session object. Here're a few examples you can use in your Extension code:
Code: Select all
public void test()
{
Zone zone = getParentZone();
User user = zone.getUserById(userId);
User user = zone.getUserByName(userName);
User user = zone.getUserBySession(userSession);
}
Hope it helps
Re: Is there any way to get a user object from their id
By user object I meant SFSUser object.
Thanks for the code. These should work but just to confirm
Consider I am an user with username "abc".
So using the above line can I get the user object with username "user2" and send "user2" and custom smartfox event
Code: Select all
zone.getUserByName(userName)
Thanks for the code. These should work but just to confirm
Consider I am an user with username "abc".
So using the above line can I get the user object with username "user2" and send "user2" and custom smartfox event
Re: Is there any way to get a user object from their id
Yes, that's correct.
All connected users can be found via one of those method calls.
Cheers
All connected users can be found via one of those method calls.
Cheers
Re: Is there any way to get a user object from their id
The names in smartfox login will be unique if custom Login is set to false.
But if we set customLogin to true, does this unique name check is still done by smartfox?
EDIT: It still does this check. How do I disable this? I would like to allow users with same name login
But if we set customLogin to true, does this unique name check is still done by smartfox?
EDIT: It still does this check. How do I disable this? I would like to allow users with same name login
Re: Is there any way to get a user object from their id
Devops wrote:The names in smartfox login will be unique if custom Login is set to false.
The names are always unique, regardless of the custom Login setting.
But if we set customLogin to true, does this unique name check is still done by smartfox?
Yes
EDIT: It still does this check. How do I disable this? I would like to allow users with same name login
In SFS2X user names must not have duplicates.
If the same user tries to login twice there can be two possible outcomes:
1) If the Zone's forceLogout options is set to true, the previous User session will be shut down and the User will be allowed to login and create a new Session.
2) If the Zone's forceLogout options is set to false, the new login attempt will be denied.
Cheers
Who is online
Users browsing this forum: No registered users and 100 guests