I am trying to create a custom login extension. Everything works fine. When I send wrong login parameters, the socket throw an error, but user login successfully. The client side doesnt receive any error. I see the error on the system logs. My codes and logs is here:
Client :
Code: Select all
public function login():void
{
addEventListener(SFSEvent.LOGIN, onLogin);
addEventListener(SFSEvent.LOGIN_ERROR, onLoginError);
send(new LoginRequest(username, password, zone));
}
private function onLoginError(event:SFSEvent):void
{
dispatchEvent(new Event(CustomEvent.LOGIN_ERROR));
}
private function onLogin(event:SFSEvent):void
{
dispatchEvent(new Event(CustomEvent.LOGIN_SUCCESS));
}
Server :
Code: Select all
package sfs2x.extensions.coolgames.poker.src;
import com.smartfoxserver.bitswarm.sessions.ISession;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.SFSArray;
import com.smartfoxserver.v2.exceptions.SFSErrorCode;
import com.smartfoxserver.v2.exceptions.SFSErrorData;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.exceptions.SFSLoginException;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;
public class Login {
Database database;
String username;
String password;
User user;
ISession session;
Room gameRoom;
public Login(ISFSEvent event, Game game) throws SFSException
{
username = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
password = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
user = (User)event.getParameter(SFSEventParam.USER);
session = (ISession)event.getParameter(SFSEventParam.SESSION);
gameRoom = game.getGameRoom();
SFSErrorData data;
database = new Database();
try {
SFSArray row = database.login(game, session, username, password);
if(row.size() == 0){
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
errData.addParameter(username);
throw new SFSLoginException(username +" is not allowed in this Zone!", errData);
}
if (password.equals(""))
{
data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
data.addParameter(username);
throw new SFSLoginException("You must enter a password.", data);
}
if (!username.equals("admin") && !password.equals("admin") &&
!game.getApi().checkSecurePassword(session, row.getSFSObject(0).getUtfString("user_password"), password))
{
data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
data.addParameter(username);
throw new SFSLoginException("Login failed for user: " + username, data);
}
game.trace("Login successfully!");
} catch (Exception e) {
game.trace(ExtensionLogLevel.WARN, " SQL Failed: " + e.toString());
}
}
}
logs :
03 May 2012 | 14:44:01,609 | WARN | pool-1-thread-2 | Extensions | {Game}: SQL Failed: com.smartfoxserver.v2.exceptions.SFSLoginException: asdfasdfwer is not allowed in this Zone!
03 May 2012 | 14:44:01,611 | INFO | pool-1-thread-2 | v2.api.SFSApi | Login in, { Zone: Game }, ( User Name: asdfasdfwer, Id: 1, Priv: 0, Sess: 192.168.110.1:54162 )