Page 1 of 1

User vs Player and Room vs Game

Posted: 26 Nov 2010, 21:28
by vandelpal
I have a question about storage my data associated with User and GameRoom.
1. How to set the context of the player?
Maybe using UserVariable:

Code: Select all

 ProfileVO profileVO = (ProfileVO) data.getVo();

        UserVariable variable = new SFSUserVariable("context", profileVO);

        try
        {
            user.setVariable(variable);
        }
        catch (SFSVariableException ex)
        {
            getExtension().trace(ExtensionLogLevel.ERROR, ex);
        }
or use

Code: Select all

private static ConcurrentHashMap <User, ProfileVO> profilesByUser = new ConcurrentHashMap <User, ProfileVO> ();
private static ConcurrentHashMap<Integer, ProfileVO> profilesById = new ConcurrentHashMap<Integer, ProfileVO>();
 
2. How much will a quick search for an "id" in the "context" in UserVariable ?

3. Rooms:
I have zone Extension, and rooms I create dynamically on server.

Code: Select all

SFSGameApi
 createGame(Zone zone, CreateSFSGameSettings settings, User owner) 
and then

Code: Select all

room.setExtension(ISFSExtension myExtension)
where myExtension - an instance of my class were logic, data and room event handlers in the room-game.
Everything is correct?

Posted: 27 Nov 2010, 07:22
by Lapo
1) UserVariables are recommended. They can be made "hidden" if you require them to be server-side only.
An alternative is to use the getProperty/setProperty which is server side only and based on a Map object.
2. How much will a quick search for an "id" in the "context" in UserVariable ?

Your question is not clear... how much what?
You mean performance? Absolutely negligible.


3) No that's wrong. You don't attach extensions manually.
In order to create a Room with an extension you pass the Extension parameters in the settings object. Double check the javadoc --> http://docs2x.smartfoxserver.com/api-do ... tings.html