Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onLogin playerSession.getPlayer() is null #7

Closed
nikolaykuz opened this issue Aug 22, 2012 · 8 comments
Closed

onLogin playerSession.getPlayer() is null #7

nikolaykuz opened this issue Aug 22, 2012 · 8 comments

Comments

@nikolaykuz
Copy link

public class ConnectGameRoom extends GameRoomSession {

    @Override
public void onLogin(PlayerSession playerSession)
{
    System.out.println(playerSession.getPlayer() == null);
    }

}

prints true. Why is it so?

@nikolaykuz
Copy link
Author

seems that in LoginHandler handleGameRoomJoin parameter player is not used at all.

@menacher
Copy link
Owner

This is known, meaning I have a TODO in code for this.
public static PlayerSession newPlayerSession(GameRoom gameRoom)
{
// TODO the player has to be set here after doing lookup.
return new PlayerSessionBuilder().parentGameRoom(gameRoom).build();
}
org.menacheri.jetserver.app.impl.Sessions class is used to create player sessions. This code is invoked by the GameRoomSession.getSessionInstance() method. You can override to lookup the player object when necessary.

@menacher
Copy link
Owner

If you have alternate suggestions on this, let me know. The reason "Player" object has lower precedence is that it will be hooked up from backend database based on the ref key, when someone uses jetserver. For the trivial example games I have done, it is un-necessary.

@nikolaykuz
Copy link
Author

That's a little confusing, in order to that I have to modify the internal code and build the project again to get new jar files.

public static PlayerSession newPlayerSession(GameRoom gameRoom)
should be changed to
public static PlayerSession newPlayerSession(GameRoom gameRoom, Player player)
and also calls to this function I guess. For now I just want to have initalized Player inside PlayerSession to be able to print userName.

@menacher
Copy link
Owner

Hmm, yes its little confusing. I will modify the signature of newPlayerSession to what you have mentioned. I don't think you would need to touch internal code.
You just need to override this method of the abstract class - GameRoomSession
@OverRide
public PlayerSession createPlayerSession()
{
PlayerSession playerSession = getSessionInstance();
return playerSession;
}
And inject your Player instance here. No need to use the static factory at all. But let me try to re-factor this part as you have said.

Given an option, at which point would you have the player looked up from database during the login process? Any suggestions.

@nikolaykuz
Copy link
Author

Okay, please let me know when I can download a new version of the code and jars.

@nikolaykuz
Copy link
Author

For now I am using a hack to distinguish different clients

public class ConnectGameRoom extends GameRoomSession {
@OverRide
public PlayerSession getSessionInstance()
{
String name = "PLAYER" + playerId;
String email = name + "@gmail.com";

    Player player = new DefaultPlayer(playerId, name, email);
    PlayerSession playerSession = new PlayerSessionBuilder().parentGameRoom(this).player(player).build();

    playerId++;

    return playerSession;
}

}

@menacher
Copy link
Owner

This works, but like you said not the best solution. Let me see if I can clean it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants