Main Menu  

   

Login Form  

   

(012) Signup Assistant Component

Details
ZoneExtension.java
package SignupExt;

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

public class ZoneExtension extends SFSExtension{

	private SignUpAssistandComponent suac;

	@Override
	public void init()
	{
		suac = new SignUpAssistantComponent();
		addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
	}

	@Override
	public void destroy()
	{
		super.destroy();
	}
}
Signup.cs
using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities.Data;

public class Login : MonoBehaviour {

	public string ServerIP = "127.0.0.1";
	public int ServerPort = 9933;
	public string ZoneName = "Signup";
	public string UserName = "";
	public string Password = "";
	public string Email = "";

	SmartFox sfs;
	string CMD_Signup = "$SignUp.Submit";

	void Start()
	{
		sfs = new SmartFox();
		sfs.ThreadSageMode = 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("username", Username);
		objOut.PutUtfString("password", Password);
		objOut.PutUtfString("email", Email);

		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();
    }
}
   
© 2004-2015 Genesis Rage