login doesnt work :(

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

login doesnt work :(

Postby Robbilie » 09 Oct 2010, 14:55

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 09 Oct 2010, 18:52

what error are you getting ? do you see anything in the extension or smartfox logs ? are you checking your login in a database ?
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 10 Oct 2010, 01:00

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 10 Oct 2010, 01:51

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.
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 11 Oct 2010, 09:23

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 12 Oct 2010, 01:30

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.
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 12 Oct 2010, 17:57

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 13 Oct 2010, 10:51

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.
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 13 Oct 2010, 18:30

Nope u sent me a txt file...

K have to check ur chat out in a week xD
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 13 Oct 2010, 18:34

sent it again :)
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 14 Oct 2010, 17:46

Receiver it ... Thanks;)

Where do u host the Server?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 14 Oct 2010, 20:17

server farm in the US.
Robbilie
Posts: 190
Joined: 04 Sep 2010, 19:48
Location: Ratingen, Germany
Contact:

Postby Robbilie » 15 Oct 2010, 17:37

24/7?
With Webserver/MySQL?

How much dies it cost?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 15 Oct 2010, 18:28

dedicated server so i can install all i need.
it's not cheap no :)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 16 Oct 2010, 05:51

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

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 22 guests