Page 1 of 1

Not getting extension response from SUAC

Posted: 27 Nov 2016, 22:34
by Ludopathic
Hi guys, I am getting my data to the server but I am not receiving confirmation that the sign up was successful (or not) - this is my code currently. I am not getting any console output passed the Connection case.

Code: Select all

package LoginRegistration;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.exceptions.SFSException;

import sfs2x.client.SmartFox;
import sfs2x.client.core.BaseEvent;
import sfs2x.client.core.IEventListener;
import sfs2x.client.core.SFSEvent;
import sfs2x.client.requests.ExtensionRequest;
import sfs2x.client.requests.LoginRequest;

public class RegistrationSender implements IEventListener {
   
   public String ServerIP = "myserverip";
   public int ServerPort = 9933;
   public String ZoneName = "Signup";
   //public String UserName = "";
   public String UserName = Screens.Register.getUsernameTF().getText();
   public String Password = Screens.Register.getPasswordTF().getText();
   public String Email = Screens.Register.getEmailTF().getText();
   public String name = Screens.Register.getNameTextField().getText();
   public static String SignUpErrorString;
   
   SmartFox sfs;
   String CMD_SIGNUP = "$SignUp.Submit";
   
   public void Start(){
      
      sfs = new SmartFox();
      sfs.addEventListener(SFSEvent.CONNECTION, this);
      sfs.addEventListener(SFSEvent.LOGIN, this);
      sfs.addEventListener(SFSEvent.LOGIN_ERROR, this);
      sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, this);
      
      sfs.connect(ServerIP, ServerPort);
      
   }
      @Override
      public void dispatch(BaseEvent event) throws SFSException {
         
         switch(event.getType()){
         
         case SFSEvent.CONNECTION:
            
            if (event.getArguments().get("success").equals(true)){
               
               System.out.println("Connection Success");
               sfs.send(new LoginRequest("","", ZoneName));
            } else{
               System.out.println("Connection error");
            }
            break;
            
         case SFSEvent.LOGIN:
            ISFSObject objOut = new SFSObject();
            objOut.putUtfString("username", UserName);
            objOut.putUtfString("password", Password);
            objOut.putUtfString("email", Email);
            objOut.putUtfString("name", name);
            
            sfs.send(new ExtensionRequest(CMD_SIGNUP, objOut));
            break;
            
         case SFSEvent.LOGIN_ERROR:
            System.out.println("Login Error");
         
            break;
            
         case SFSEvent.EXTENSION_RESPONSE:
            String cmd = (String) event.getArguments().get("cmd");
            ISFSObject objIn = (ISFSObject) event.getArguments().get("params");
            
            if (cmd == CMD_SIGNUP){
               
               if (objIn.containsKey("errorMessage")){
                  
                  System.out.println("Signup Error" + objIn.getUtfString("errorMessage"));
                  SignUpErrorString = objIn.getUtfString("errorMessage");
               }
               else if (objIn.containsKey("success")){
                  
                  System.out.println("Signup Successful");
                  SignUpErrorString = ("Signup Was Successful");
               }
               
            }
            
            
         }
         
      }
   }

Re: Not getting extension response from SUAC

Posted: 28 Nov 2016, 08:49
by Lapo
Hi,
you should check the server side logs for errors if you're not getting any replies.

Let us know.

Re: Not getting extension response from SUAC

Posted: 28 Nov 2016, 13:07
by Ludopathic
Thats the problem, server logs show no errors :/ Is there something I should have added to my zone extension code to get a response? I assumed that the response I was trying to get was built into the SUAC.

My extension code -

Code: Select all

package SignupExtExtension;

import java.util.Arrays;

import com.smartfoxserver.v2.components.signup.ISignUpAssistantPlugin;
import com.smartfoxserver.v2.components.signup.SignUpAssistantComponent;
import com.smartfoxserver.v2.components.signup.SignUpConfiguration;
import com.smartfoxserver.v2.components.signup.SignUpValidationException;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class ZoneExtension extends SFSExtension {
   
   private SignUpAssistantComponent suac;

   @Override
   public void init() {
      
      suac = new SignUpAssistantComponent();
      
      suac.getConfig().extraFields = Arrays.asList("name");
      
      addRequestHandler (SignUpAssistantComponent.COMMAND_PREFIX, suac);
   
   
      
      
       // Add a pre-process plugin for custom validation
       suac.getConfig().preProcessPlugin = new ISignUpAssistantPlugin(){

         @Override
         public void execute(User user, ISFSObject params, SignUpConfiguration config) throws SignUpValidationException {
            // TODO Auto-generated method stub
            
            @SuppressWarnings("unused")
            String name = params.getUtfString("name");
            
            
            
         }
          
          
       };
      
      
   
      
   }
   
   @Override
   public void destroy(){
      
      super.destroy();
   }

}

Re: Not getting extension response from SUAC

Posted: 28 Nov 2016, 16:51
by Lapo
The Signup component replies to your requests but if an unexpected exception interrupts a request, such as a database error, the client won't receive the details.

In your code the configuration of the Signup component seems incomplete. Where's the table name and all the other fields necessary to the transaction?

This is an example from our doc:

Code: Select all

@Override
public void init()
{
    suac = new SignUpAssistantComponent();
     
    suac.getConfig().signUpTable = "signup";
    suac.getConfig().userNameField = "user_name";
    suac.getConfig().passwordField = "user_pword";
    suac.getConfig().emailField = "user_email";
    suac.getConfig().checkForDuplicateEmails = false;
     
    addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
}

which is a very minimal setup. Make sure to check the documentation:
http://docs2x.smartfoxserver.com/Develo ... ant-basics

Cheers

Re: Not getting extension response from SUAC

Posted: 28 Nov 2016, 18:39
by Ludopathic
I was unaware that they needed to be specified, in your documentation it says that the SUAC has default fields, therefore I added one extra field that was not in the default configuration and left it at that. I will try to do it manually and see what happens.

Re: Not getting extension response from SUAC

Posted: 29 Nov 2016, 08:43
by Lapo
Well, at the very least the name of the table from where to get the data must be specified... ;)

cheers