Problem with SmartFoxServer 2X - LoginAssistantComponent

Hi everyone,

I have recently moved from PhotonServer to SmartFoxServer 2X as the basic networking solution behind my game. One of the basic reassons is SmartFoxServer offers a login assistant component. This Login Assistant component is a helper class that assists in creating a database-driven login system, without the hassle of writing the database access code.

I was able to do all steps server side up to configuring the component in my client. I have the server running, the DB, I can connect to it, but I really don’t know how to handle the last part, which is to “Instantiate the component in the init() method of my Extension”.

Basically, I have no clue what it means… I’m pretty new to coding and unfortunately I have been using unityscript mostly. I can read C#, but when it gets to including external libraries I get a little confused.

You can access the Sfs2X LoginAssistantComponent documentation here:

I included the SmartFox2.dll in my Plugins folder, and have the following code working properly letting me connect and disconnect from my server.

#pragma strict

import System;
import System.Collections.Generic;
import Sfs2X;
import Sfs2X.Core;
import Sfs2X.Logging;

var serverName = "insertmyserveriphere";
var serverPort = 9933;
var smartFox = new SmartFox(true);

function OnGUI() {
	GUI.Box (Rect (20, 20, Screen.width - 40 , 25), "GAME NAME");
	GUI.Box (Rect (20, 50, Screen.width - 40 , Screen.height - 90), "Connection Screen");
	if (!smartFox.IsConnected) {
		if(GUI.Button(Rect(40, 165, Screen.width - 80, 20), "Connect")) {
			smartFox.Connect(serverName, serverPort);
	else if (smartFox.IsConnected) {
		if(GUI.Button(Rect(40, 165, Screen.width - 80, 20), "Disconnect")) {

My problem occurs when I add the following code in order to declare a LoginAssistantComponent() variable. I get an Unknown identifier: ‘LoginAssistantComponent’. error.

function Test() {
	var lac = new LoginAssistantComponent();

I know there is something else I have to do, but I have no clue what… Do I have to add another DLL in my project? do I have to “Include.Whatever” something else on top of my script? Do I have to wrap everything in something like

public class ScriptName extends Something.MonoBehaviour{
//code goes here

By the way… Anyone can explain to me what these include lines up top are used for exactly? And why in some other times you have to use “public class ScriptName extends Photon.MonoBehaviour” like I had to when using PhotonNetwork?

Thanks for the help :slight_smile:

lac = new LoginAssistantComponent();

it’s Server Code Extension for using Custom Login SmartFox (java).

in the unity you just call when you using LoginAssist Server Extension:


    void Awake() {
    		Application.runInBackground = true;
    		if (Application.isWebPlayer || Application.isEditor) {
    			if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500)) {
    				Debug.LogError("Security Exception. Policy file load failed!");
    		if (SmartFoxConnection.IsInitialized)
    			smartFox = SmartFoxConnection.Connection;
    		} else {
    		smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection);
    		smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
    		smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin);
            smartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
    		smartFox.Connect(serverName, serverPort);
    public void OnLoginError(BaseEvent evt)
    Debug.Log("Error Login !!!");

	public void OnLogin(BaseEvent evt) {
		bool success = true;
		if (evt.Params.Contains("success") && !(bool)evt.Params["success"]) {
			loginErrorMessage = (string)evt.Params["errorMessage"];
			Debug.Log("Login error: "+loginErrorMessage);
		} else {
			loginErrorMessage = "";

(Login from Database)

smartFox.Send(new LoginRequest(username, password, zone));


smartFox.Send(new LoginRequest(username,"", zone));


Don’t forget add library sfs2x.jar and sfs2x-core.jar

import com.smartfoxserver.v2.components.login.LoginAssistantComponent;
import com.smartfoxserver.v2.components.login.LoginData;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class YourServerName extends SFSExtension {

	public LoginAssistantComponent lac;
    public void init(){
		lac = new LoginAssistantComponent(this);
        lac.getConfig().loginTable = "tableUser";
        lac.getConfig().userNameField = "Username";
        lac.getConfig().passwordField = "Password";

Then Build Extension and place (.jar) in /SmartFoxServer_2X/SFS2X/extensions/YourExtensionFolderName

Setting Zone Extension with your .jar extension

if you activate the custom login on the server SmartFox, then he will use the login username from database. But if not, then automatically defined as a guest.