Sign up

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Kor
Posts: 3
Joined: 29 Jan 2020, 16:53

Sign up

Postby Kor » 29 Jan 2020, 17:54

Hi, Can you help me with signup code? I have postgress database with the table users and one column nickname which is primary key. I made extension code and activate the database. Wrote the client code with the zone BasicExamples. But in Log of smartfox there was an signup error when i wanna import some user in database. For example when i write in the script kermit.I just login as a guest and can't import the nickname kermit to the database.The nickname is empty in database
Here is the server code:

Code: Select all

import com.smartfoxserver.v2.components.login.LoginAssistantComponent;
import com.smartfoxserver.v2.components.signup.SignUpAssistantComponent;
import com.smartfoxserver.v2.components.signup.SignUpConfiguration;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;
public class SignUpTestExtension extends SFSExtension
{
   private SignUpAssistantComponent suac;
   private LoginAssistantComponent lac;
   
   @Override
   public void init()
   {
      initSignUpAssistant();
      initLoginAssistant();
   }
   
   @Override
   public void destroy()
   {
       super.destroy();
       lac.destroy();
   }
   
   private void initSignUpAssistant()
   {
      suac = new SignUpAssistantComponent();
      suac.getConfig().signUpTable = "users";      
      addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
   }
   
   private void initLoginAssistant()
   {
      lac = new LoginAssistantComponent(this);      
      lac.getConfig().loginTable = "users";      
      };
   }
}
 

And the client code:

Code: Select all

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities.Data;

public class SignUp : MonoBehaviour {
       
        public string ServerIP = "127.0.0.1";
        public int ServerPort = 9933;
        public string ZoneName = "BasicExamples";
        public string UserName = "";
        SmartFox sfs;
        string CMD_Signup = "$SignUp.Submit";
       
        void Start()
        {
                sfs = new SmartFox();
                sfs.ThreadSafeMode = true;
               
                sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
                sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
                sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
                sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
               
                sfs.Connect(ServerIP, ServerPort);
        }
       
        void OnConnection(BaseEvent e)
        {
                if ((bool)e.Params["success"])
                {
                        Debug.Log("Successfully Connected!");
                        sfs.Send(new LoginRequest("", "", ZoneName));
                } else {
                        Debug.Log("Connection Failed!");
                }
        }
       
        void OnLogin(BaseEvent e)
        {
                Debug.Log("Logged In: " + e.Params["user"]);
               
                ISFSObject objOut = new SFSObject();
                objOut.PutUtfString("nickname", UserName);
               
                sfs.Send(new ExtensionRequest(CMD_Signup, objOut));
        }
       
        void OnLoginError(BaseEvent e)
        {
                Debug.Log("Login error: (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
        }
       
        void OnExtensionResponse(BaseEvent e)
        {
                string cmd = (string)e.Params["cmd"];
                ISFSObject objIn = (SFSObject)e.Params["params"];
               
                if (cmd == CMD_Signup)
                {
                        if (objIn.ContainsKey("errorMessage"))
                        {
                                Debug.Log("Signup Error: " + objIn.GetUtfString("errorMessage"));
                        }
                        else if (objIn.ContainsKey("success"))
                        {
                                Debug.Log("Signup Successful");
                        }
                }
        }
       
        void FixedUpdate()
        {
                sfs.ProcessEvents();
        }
       
        void OnApplicationQuit()
        {
                if (sfs.IsConnected)
                        sfs.Disconnect();
        }
}
User avatar
Lapo
Site Admin
Posts: 21952
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sign up

Postby Lapo » 10 Feb 2020, 16:14

Sorry for the delay in responding, this was posted under the SFS1.x forum so I didn't notice it for a while. I've now moved it under SFS2X.

What is exactly the error you're getting from server side?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 43 guests