Extension isnt called

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Extension isnt called

Postby genar » 18 Oct 2017, 20:41

Hey there !

Im currently working on an custom login/register extension.

Code: Select all

import com.smartfoxserver.v2.components.login.LoginAssistantComponent;
import com.smartfoxserver.v2.components.signup.SignUpAssistantComponent;
import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class SignUpExtension
  extends SFSExtension
{
  private SignUpAssistantComponent suac;
  private LoginAssistantComponent lac;
 
  public void init()
  {
    addRequestHandler("register", UserRegistrationHandler.class);
   
    addEventHandler(SFSEventType.USER_LOGIN, LoginEventHandler.class);
  }
 
  public void destroy()
  {
    super.destroy();
  }
}


public class LoginEventHandler
  extends BaseServerEventHandler
{
  public void handleServerEvent(ISFSEvent event)
    throws SFSException
  {
    String userName = (String)event.getParameter(SFSEventParam.LOGIN_NAME);
    String cryptedPass = (String)event.getParameter(SFSEventParam.LOGIN_PASSWORD);
    ISession session = (ISession)event.getParameter(SFSEventParam.SESSION);
   
    IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
    try
    {
      Connection connection = dbManager.getConnection();
     
      PreparedStatement stmt = connection.prepareStatement("SELECT Username, Password FROM players where Username='" + userName + "'");
     
      ResultSet res = stmt.executeQuery();
      if (!res.first())
      {
        SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
       
        errData.addParameter(userName);
       
        throw new SFSLoginException("<LoginEventHandler : Bad user name: " + userName, errData);
      }
      String dbPword = res.getString("Password");
      if (!getApi().checkSecurePassword(session, dbPword, cryptedPass))
      {
        SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
       
        data.addParameter(userName);
       
        throw new SFSLoginException("<LoginEventHandler : Login failed for user: " + userName, data);
      }
    }
    catch (SQLException e)
    {
      SFSErrorData errData = new SFSErrorData(SFSErrorCode.GENERIC_ERROR);
     
      errData.addParameter("<LoginEventHandler : SQL Error: " + e.getMessage());
     
      throw new SFSLoginException("<LoginEventHandler : A SQL Error occurred: " + e.getMessage(), errData);
    }
    Connection connection;
  }
}


public class UserRegistrationHandler
  extends BaseClientRequestHandler
{
  public void handleClientRequest(User user, ISFSObject params)
  {
    String name = params.getUtfString("Username");
    String password = params.getUtfString("Password");
    String email = params.getUtfString("Email");
   
    IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
   
    String sql = "INSERT into login(Username, Password, Email) values ('" + name + "','" + password + "','" + email + "')";
    try
    {
      dbManager.executeUpdate(sql);
    }
    catch (SQLException e)
    {
      ISFSObject error = new SFSObject();
     
      error.putUtfString("error", "MySQL updation failed");
     
      send("register", error, user);
    }
    ISFSObject success = new SFSObject();
   
    success.putUtfString("success", "User successfully registered");
   
    send("register", success, user);
  }
}



And normally those methods should be called by my unity script :

Code: Select all

private void LoginHandler() {

        if (task == "register")
        {

            sfs.Send(new LoginRequest("", "", "Registration"));

            Debug.Log("<Server : Registration Executet>");

        }
        else if (task == "login")
        {
            sfs.Send(new LoginRequest(UserName, Password, "ParallelOriginWorld"));

            Debug.Log("<Server : Login Executet>");

        }

    }


    private void OnLogin(BaseEvent e)
    {

        if (task == "register")
        {

            ISFSObject isfsobject = new SFSObject();
            isfsobject.PutUtfString("Username", UserName);
            isfsobject.PutUtfString("Password", Password);
            isfsobject.PutUtfString("Email", Email);

            sfs.Send(new ExtensionRequest("register", isfsobject));

        }
        else if (task == "login")
        {

            Debug.Log("<Server : Login Sucessfull>");

        }

    }



But this isnt the case. Any ideas why the extension methods arent called and why theres no callbacks ?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extension isnt called

Postby Lapo » 19 Oct 2017, 09:51

Hi,
did you activate the "custom login" flag in your zone config?

If you prefer you can also do it via code in the init() method of your Extension like so:

Code: Select all

public void init()
{
   getParentZone().setCustomLogin(true);
}

This way login calls will be passed to your Extension.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
genar
Posts: 137
Joined: 13 Jul 2017, 11:49

Re: Extension isnt called

Postby genar » 19 Oct 2017, 14:16

Lapo wrote:Hi,
did you activate the "custom login" flag in your zone config?

If you prefer you can also do it via code in the init() method of your Extension like so:

Code: Select all

public void init()
{
   getParentZone().setCustomLogin(true);
}

This way login calls will be passed to your Extension.

Cheers



I added the line to my extension and replaced the old jar file. Still dont work. Yes custom login is enabled... Also i call trace(); in the init method, which isnt executed. I dont see any logs of it. No errors or warnings in the logs aswell...

Somehow i just see, even if the player is connected... he isnt in an zone somehow... how can this happen ? The zone monitor shows no players in the different zones...

PictureOfSettings.PNG
(70.46 KiB) Not downloaded yet

PictureOfZoneExtension.PNG
(32.5 KiB) Not downloaded yet




--- EDIT : Solved it ! There were some problems with the zone/rooms :) ---

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 25 guests