I run a simple testing code (which I paste at the bottom), and I noticed it was failing.
I think this shouldn't be happening, as it doesn't make any sense to me to have multiple logs within the same session; even the SFSApi class returns only one user in the method getUserBySession, so I think this could be an issue.
I solved this using a custom login that doesn't allow multiple logins for a session, but I would anyways like to know if there is a way to do this using a config file or something like that, or, in case this is a n issue, if it could be solved in future releases.
Testing code:
Code: Select all
@Test
public void singleConnectionShouldNotAllowMultipleUsers() throws InterruptedException {
totalLogs = 0;
totalFails = 0;
smartFox = new SmartFox(true);
smartFox.connect("localhost", 9933);
smartFox.addEventListener(SFSEvent.CONNECTION, new IEventListener() {
public void dispatch(BaseEvent evt) throws SFSException {
Map params = evt.getArguments();
if ((Boolean) params.get("success")) {
System.out.println("Connection established");
ISFSObject sendingParams = new SFSObject();
sendingParams.putInt("g", 7);
smartFox.send(new LoginRequest("", "", "My Lobby", sendingParams));
smartFox.send(new LoginRequest("", "", "My Lobby", sendingParams));
} else {
fail("Connection failed, ensure server is running on localhost, 9933");
}
}
});
smartFox.addEventListener(SFSEvent.LOGIN, new IEventListener() {
public void dispatch(BaseEvent evt) throws SFSException {
User user = (User) evt.getArguments().get("user");
System.out.println("Login successful " + user.getName());
totalLogs++;
}
});
smartFox.addEventListener(SFSEvent.LOGIN_ERROR, new IEventListener() {
public void dispatch(BaseEvent evt) throws SFSException {
System.out.println("Login failure: " + evt.getArguments().get("errorMessage"));
totalFails++;
}
});
Thread.sleep(2000);
assertEquals(1, totalLogs);
}