Code: Select all
package Login;
import com.smartfoxserver.v2.components.login.LoginAssistantComponent;
import com.smartfoxserver.v2.extensions.SFSExtension;
/**
*
* @author User
*/
public class ZoneExtension extends SFSExtension {
private LoginAssistantComponent lac;
@Override
public void init()
{
lac = new LoginAssistantComponent(this);
lac.getConfig().loginTable = "users";
lac.getConfig().userNameField = "username";
lac.getConfig().passwordField = "password";
lac.getConfig().nickNameField = "email";
}
@Override
public void destroy()
{
super.destroy();
lac.destroy();
}
}
package SignUp;
import com.smartfoxserver.v2.components.signup.SignUpAssistantComponent;
import com.smartfoxserver.v2.extensions.SFSExtension;
/**
*
* @author User
*/
public class ZoneExtension extends SFSExtension {
private SignUpAssistantComponent suac;
@Override
public void init()
{
suac=new SignUpAssistantComponent();
addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX,suac);
}
}
Here is my client code:
Code: Select all
using UnityEngine;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities.Data;
using Sfs2X.Requests;
using Sfs2X.Entities;
public class SignUp : MonoBehaviour
{
public string Host = "127.0.0.1";
public int TcpPort = 9933;
public string Zone = "game";
public string UserName = "";
public string Password = "";
public string Email = "";
SmartFox sfs;
string CMD_Signup = "$SignUp.Submit";
public 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(Host, TcpPort);
}
public void OnConnection(BaseEvent evt)
{
if ((bool)evt.Params["success"])
{
Debug.Log("Succesfully Connected");
//login in to Zone
sfs.Send(new LoginRequest("", "", Zone));
}
else
{
Debug.Log("Connection failed");
}
}
public void OnLogin(BaseEvent evt)
{
User user = (User)evt.Params["user"];
Debug.Log("User: " + user.Name);
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 evt)
{
Debug.Log("Login error: (" + evt.Params["errorCode"] + "): " + evt.Params["errorMessage"]);
}
public void OnExtensionResponse(BaseEvent evt)
{
string cmd = (string)evt.Params["cmd"];
ISFSObject objIn = (SFSObject)evt.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");
}
}
}
public void Update()
{
if (sfs != null)
{
sfs.ProcessEvents();
}
}
public void OnApplicationQuit()
{
if (sfs.IsConnected)
{
sfs.Disconnect();
}
}
}