Im using Unity3D and SmartFoxServer to develop a multiplayer game.
I want that players can register (Im using sign up assistance from SmartFoxServer), so they can login an play. But also, that they can play as guest players.
I enabled this feature in the admin, but when I made a LoginRequest in the client, if the user doesn't exists (or the password is wrong) I'm logged in as Guest.
I need a command for registered users login and one for guest players login or a way to tell SmartFoxServer to difference between a registered user login, and a guest login. There is some built in solution?
Here's one way of doing it.
Implement a customhandler for the login event
//Inside your main extension
addEventHandler(SFSEventType.USER_LOGIN, UserLoginEventHandler.class);
public class UserLoginEventHandler extends BaseServerEventHandler{
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException {
String loginName = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
//send a blank username as login for guest, smartfox will create a guest user for you
if(loginName.isEmpty(''))
return
//Authenticate your registered user here
if(...isNot Authenticated..)
{
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
errData.addParameter(loginName);
// Fire a Login exception
throw new SFSLoginException("UserName/password not correct", errData);
}
}
}