Sign Up

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Swonson
Posts: 8
Joined: 15 Nov 2016, 07:30

Sign Up

Postby Swonson » 06 Dec 2016, 18:10

Hey Guys,

i tried to realise the following SignUp tutorial for unity: http://docs2x.smartfoxserver.com/Develo ... ant-basics
Unfortunetaly i went in an error, which i dont understand.

Code: Select all

com.smartfoxserver.v2.exceptions.SFSExtensionException: Extension Request refused. Sender is not a User: { Id: 3, Type: DEFAULT, Logged: No, IP: XXX.XXX.XXX.XXX:XXXXX }
   com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:93)
   com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   java.lang.Thread.run(Thread.java:745)


I inserted the following server-side code to my extension:

Code: Select all

private SignUpAssistantComponent suac;
   
@Override
public void init()
{
suac = new SignUpAssistantComponent();
        suac.getConfig().signUpTable = "playesdata";
        suac.getConfig().usernameField = "playername";
        suac.getConfig().passwordField = "playerpasswort";
        suac.getConfig().emailField = "email";
        suac.getConfig().checkForDuplicateEmails = false;
        addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
}


and the following to my unity project:

Code: Select all

Debug.Log("connected");
string CMD_SUBMIT = "$SignUp.Submit";

SFSObject sfso = new SFSObject();
sfso.PutUtfString("playername", "NAMEHERE");
sfso.PutUtfString("playerpasswort", "PWHERE");
sfso.PutUtfString("email", "EMAIL@ADRESSE.COM");

sfs.Send(new ExtensionRequest(CMD_SUBMIT, sfso));

This code will execude if the connection was successfully established. With zone etc.

This code for server-response:

Code: Select all

        private void OnExtensionResponse(BaseEvent evt)
        {
            Debug.Log("test");
             string cmd = (string)evt.Params["cmd"];
             SFSObject dataObject = (SFSObject)evt.Params["params"];

            if (cmd == "$SignUp.Submit")
            {
                if (dataObject.GetBool("success"))
                    Debug.Log("Success, thanks for registering");
                else
                    Debug.Log("SignUp Error:" + (string)evt.Params["errorMessage"]);
            }
            else
            {
                Debug.Log("test");
                Debug.Log("SignUp Error:" + (string)evt.Params["errorMessage"]);
            }

        }


I dont understand, whats wrong.
I hope you can help me.

Have a nice eve!
Best regards swonson
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sign Up

Postby Lapo » 06 Dec 2016, 18:17

Hi,
the error is due to the fact the the user is not logged in.

You should setup a Zone for users that need to register. They can login as guest (empty name, empty password) and then send their Extension requests.

When the process is done you can log the user out of the registration zone and log him into the actual game.

Makes sense?

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Swonson
Posts: 8
Joined: 15 Nov 2016, 07:30

Re: Sign Up

Postby Swonson » 06 Dec 2016, 18:28

Hi,

thanks for you fast reply.

Yes it makes sense, but my current zone allows guest user.
so where is the diffrent to a new zone where i allow guest users too?

thanks for your help.

ciao
swonson
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sign Up

Postby Lapo » 07 Dec 2016, 09:33

For testing you can do it without a second Zone, if you so desire.
In any case the error you have posted here indicates that your client code is sending requests prior to having logged in or, alternatively, after a LOGIN_ERROR. In either case a client is not allowed to send requests if he's not successfully logged in.

Make sure to double check your client code for those two states.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Swonson
Posts: 8
Joined: 15 Nov 2016, 07:30

Re: Sign Up

Postby Swonson » 08 Dec 2016, 16:39

HI,

i dont get it.
I created a new Zone and the error is still here.

Could you please my check code?

Client:

Code: Select all

        void Start()
        {
            // Set connection parameters
            ConfigData cfg = new ConfigData();
            cfg.Host = Host;
            cfg.Port = TcpPort;
            cfg.Zone = Zone;

            // Initialize SFS2X client and add listeners
            sfs = new SmartFox();


            // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
            sfs.ThreadSafeMode = true;
           
            sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
            sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
            sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
           

            // Connect to SFS2X
            sfs.Connect(cfg);
        }


Code: Select all

        private void OnConnection(BaseEvent evt)
        {
            if ((bool)evt.Params["success"])
            {
                // Save reference to SmartFox instance; it will be used in the other scenes
                SmartFoxConnection.Connection = sfs;
                Debug.Log("connected");

                // The SignUp extension command
               
                string CMD_SUBMIT = "$SignUp.Submit";

                SFSObject sfso = new SFSObject();
                sfso.PutUtfString("playername", "swonson");
                sfso.PutUtfString("playerpasswort", "123456");
                sfso.PutUtfString("email", "xxx@xxx.org");

                sfs.Send(new ExtensionRequest(CMD_SUBMIT, sfso));

            }
            else
            {
                // Remove SFS2X listeners and re-enable interface
                reset();

                // Show error message
                ServerOutput.text = "Connection failed; is the server running at all?";
            }
        }


Server:

Code: Select all

package xxxxx;

import com.smartfoxserver.v2.components.signup.SignUpAssistantComponent;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class xxxxx extends SFSExtension  {
   

    private SignUpAssistantComponent suac;
   
   @Override
   public void init()
   {
      trace(" xxxxx:   ############################### init ");
       suac = new SignUpAssistantComponent();
        
       suac.getConfig().signUpTable = "xxxx";
       suac.getConfig().usernameField = "xxxx";
       suac.getConfig().passwordField = "xxxx";
       suac.getConfig().emailField = "email";
       suac.getConfig().checkForDuplicateEmails = false;
        
       addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
      
      trace(" xxxxx:   ############################### end init ");
   }
}


Error:

Code: Select all

com.smartfoxserver.v2.exceptions.SFSExtensionException: Extension Request refused. Sender is not a User: { Id: 7, Type: DEFAULT, Logged: No, IP: xxxxxxxxxxxx:60182 }
   com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:93)
   com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   java.lang.Thread.run(Thread.java:745)


Zomne Settings
Image


I hope you can help me.
Thanks for your time.


Best regards
swonson
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sign Up

Postby Lapo » 08 Dec 2016, 18:04

In your code you're sending the Extension request for sign up in the CONNECTION event.

As I said this is the source of the error, because at this point you have just started a connection but you are NOT logged in any specific Zone. The server doesn't even know which Extension to talk to.

So after the CONNECTION event send a login request and on success call the Extension

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Swonson
Posts: 8
Joined: 15 Nov 2016, 07:30

Re: Sign Up

Postby Swonson » 08 Dec 2016, 19:22

Hi Lapo,

you are right. of course...

I thought i must signup BEFORE i can login.

Thanks for your fast help!
Have a nice eve and if we dont talk again :wink: nice xmas.

Best regards
Swonson
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sign Up

Postby Lapo » 09 Dec 2016, 08:56

Happy Xmas to you too :)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 38 guests