Page 1 of 2

login doesnt work :(

Posted: 09 Oct 2010, 14:55
by Robbilie
hey guys i tried to make a login in unity with password and a smartfoxextension (the pro example login extension)

i cant get it to work :(

here is my code:

Code: Select all


using UnityEngine;

using System;

using System.Collections;

using SmartFoxClientAPI;

using SmartFoxClientAPI.Data;

using SmartFoxClientAPI.Util;



public class LoginGUI : MonoBehaviour {

   private SmartFoxClient smartFox;

   private bool shuttingDown = false;



   public string serverIP = "127.0.0.1";

   public int serverPort = 3000;

   public string zone = "simpleChat";

   public bool debug = true;

   

   public string log;

   

   public GUISkin gSkin;



   private string nick = "";

   private string pword = "";

   private string loginErrorMessage = "";





   

   

   

   

   

   /************

     * Unity callback methods

     ************/



   void OnApplicationQuit() {

      shuttingDown = true;

   }
   
   void FixedUpdate() {
      smartFox.ProcessEventQueue();
   }



   void Awake() {

      

      

      

      Application.runInBackground = true;



      if ( SmartFox.IsInitialized() ) {

         smartFox = SmartFox.Connection;

      } else {

         try {

            smartFox = new SmartFoxClient(debug);
            smartFox.runInQueueMode=true;
         } catch ( Exception e ) {

            loginErrorMessage = e.ToString();

         }

      }



      // Register callback delegate

      SFSEvent.onConnection += OnConnection;

      SFSEvent.onConnectionLost += OnConnectionLost;

      SFSEvent.onLogin += OnLogin;

      SFSEvent.onRoomListUpdate += OnRoomList;

      SFSEvent.onDebugMessage += OnDebugMessage;

      //SFSEvent.onExtensionResponse += OnExtensionResponse;

      SFSEvent.onExtensionResponse += OnExtensionResponse;

        SFSEvent.onExtensionResponse -= OnExtensionResponse;



      smartFox.Connect(serverIP, serverPort);

   }



      

   

   void OnGUI() {

      

      GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, new Vector3 (Screen.width / 600.0f, Screen.height / 400.0f, 1f));



      GUI.skin = gSkin;
   
      //GUI.Label(new Rect(2, -2, 680, 70), "", "SFSLogo");   

      

      GUI.Box(new Rect (125,50,400,300), "Login");



      if ( smartFox.IsConnected() ) {

         // Login



         GUI.Label(new Rect(180, 117, 65, 100), "Username: ");

         nick = GUI.TextField(new Rect(250, 117, 150, 20), nick, 25);

         

         GUI.Label(new Rect(180, 145, 150, 20), "Password: ");

         pword = GUI.PasswordField(new Rect(250, 145, 150, 20), pword, "*"[0], 25);



         

         GUI.Label(new Rect(10, 218, 400, 100), loginErrorMessage);



         if ( GUI.Button(new Rect(300, 230, 100, 20), "Login")  || (Event.current.type == EventType.keyDown && Event.current.character == '\n')) {

            smartFox.Login(zone, nick, pword);

         

            

         }



      } else {

         GUI.Label(new Rect(10, 150, 400, 100), "Waiting for connection");

         GUI.Label(new Rect(10, 218, 400, 100), loginErrorMessage);

      }

   }

   

   /************

    * Helper methods

    ************/



   private void UnregisterSFSSceneCallbacks() {

      // This should be called when switching scenes, so callbacks from the backend do not trigger code in this scene

      SFSEvent.onConnection -= OnConnection;

      SFSEvent.onConnectionLost -= OnConnectionLost;

      SFSEvent.onLogin -= OnLogin;

      SFSEvent.onRoomListUpdate -= OnRoomList;

      SFSEvent.onDebugMessage -= OnDebugMessage;

        SFSEvent.onExtensionResponse -= OnExtensionResponse;

      

      SFSEvent.onExtensionResponse += OnExtensionResponse;

   }



   /************

    * Callbacks from the SFS API

    ************/



   void OnConnection(bool success, string error) {

      if ( success ) {

         SmartFox.Connection = smartFox;

      } else {

         loginErrorMessage = error;

      }

   }



   void OnConnectionLost() {

      loginErrorMessage = "Connection lost / no connection to server";

   }



   public void OnDebugMessage(string message) {

      Debug.Log("[SFS DEBUG] " + message);

   }



   

   

   

   

   public void OnExtensionResponse(object data, string type) {

      

      

      

      

      if (type == SmartFoxClient.XTMSG_TYPE_XML)



      {



         SFSObject responseData = (SFSObject)data;



         if(responseData.GetString("_cmd") == null)



         {



            loginErrorMessage = "Invalid login";



         }



         switch ( responseData.GetString("_cmd") )

 

          {

 

            case "logOK":

 

               OnLogin(true, responseData.GetString("name"), responseData.GetString("err"));



               



               break;

 

            case "logKO":

 

               loginErrorMessage = "Invalid username or password!";



               break;

 

          }

 

      }



}

   

   

   

   

   public void OnLogin(bool success, string name, string error) {

      if ( success ) {

         // Lets wait for the room list



      } else {

         // Login failed - lets display the error message sent to us

         loginErrorMessage = error;

      }

   }



   void OnRoomList(Hashtable roomList) {

      // When room list is updated we are ready to move on to the lobby

      UnregisterSFSSceneCallbacks();

      Application.LoadLevel("lobby");

   }

}



can anyone help me???

thanks
Robert

Posted: 09 Oct 2010, 18:52
by appels
what error are you getting ? do you see anything in the extension or smartfox logs ? are you checking your login in a database ?

Posted: 10 Oct 2010, 01:00
by Robbilie
i dont get errors

In the debug i get logOK when the login is riht and logKO when its wrong

But unity doesnt use the respnse so it doesnt login

Posted: 10 Oct 2010, 01:51
by appels
are you logging in the user in the extension ? Since you send the user info to the extension, you need to log it in yourself : _server.loginUser(nick, pass, chan);
And don't forget that you have to retrieve the roomlist manualy or you won't be able to join any room.
And you can remove both the Onlogin callbacks, you trigger them yourself from the extension response.

Posted: 11 Oct 2010, 09:23
by Robbilie
Heu?
How can i do that?
So i have to pur the Login Part in the extension?how?
And what to do or where with the roomlist?

Pls help.

Robert

Posted: 12 Oct 2010, 01:30
by appels
In the docs (http://www.smartfoxserver.com/docs/), section SFS Pro tutorials, Login extension. If you compare the extension to yours and what i gave you as login string you should be able to find it. It's in the section 'The server side'. The extension is just underneath.
Look for '_server.loginUser(nick, pass, chan);' -> thats the extension login string. Thats how you log in the user via the extension.
The roomlist can be called from the client side or you can have the server push the list once your login has succeeded.
And one last thing you need to do on the client side is set the smartfox.myUserName and myUserId variables... but thats something you should know if you read the docs. I have my setup running now :)
http://www.edje.net/AniLand/ if you want to test it out.
Just click connect and login ( no username needed, smartfox will assign one).
If you open 2 clients, you will see that if you change the avatar outfit and click save, it sends it to the other avatars.

Posted: 12 Oct 2010, 17:57
by Robbilie
So my problem was that i Logged in on extension and Client xD

Can u send me the file again?

I have to check Ur demo out Next daYs Causen im Not at Home....

Is it a roleplaygame?

If Yes Gould Be Nixe to learn how that Works ;)

Rohert

Posted: 13 Oct 2010, 10:51
by appels
Robbilie wrote:Can u send me the file again?

i never sent you a file

No, I just made a 3D chat for now with outfit sync over smartfox. I will add more later.

Posted: 13 Oct 2010, 18:30
by Robbilie
Nope u sent me a txt file...

K have to check ur chat out in a week xD

Posted: 13 Oct 2010, 18:34
by appels
sent it again :)

Posted: 14 Oct 2010, 17:46
by Robbilie
Receiver it ... Thanks;)

Where do u host the Server?

Posted: 14 Oct 2010, 20:17
by appels
server farm in the US.

Posted: 15 Oct 2010, 17:37
by Robbilie
24/7?
With Webserver/MySQL?

How much dies it cost?

Posted: 15 Oct 2010, 18:28
by appels
dedicated server so i can install all i need.
it's not cheap no :)

Posted: 16 Oct 2010, 05:51
by ThomasLund
I myself use these guys

www.hetzner.de

Great deal, good support, lots of bandwidth (dedicated server).

Alternatively one should look into a slice in the sky - EC2 or similar. Pay as you go, but can quickly be expensive also