please help with my login password

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

Moderators: Lapo, Bax

kano
Posts: 71
Joined: 04 Dec 2010, 00:44
Location: Asturias

please help with my login password

Postby kano » 08 Dec 2010, 02:52

hi.im trying to do my login password.i have mysql and smartfox running.smartfox dont send error, say sever ready.the only think is in my extension.when smartfox is running say myloginextension.as:initing dbextension, but in other zones with other extension say initialized, not initing.is this ok??
when i run my game, all is ok, unity dont send error, smarfox dont send error and conect with my sql database, but the login and password dont work.if you write anithink in the login and password you can go to the game scene.the login and password dont work, but i dont see errors.
ok, my extension is:

Code: Select all

var dbase



/*
* Initializion point:
*
* this function is called as soon as the extension
* is loaded in the server.
*
* You can add here all the initialization code
*
*/
function init()
{
   trace("Initing dbExtension")

   // get a reference to the database manager object
   // This will let you interact the database configure for this zone
   dbase = _server.getDatabaseManager()

}


/*
* This method is called by the server when an extension
* is being removed / destroyed.
*
* Always make sure to release resources like setInterval(s)
* open files etc in this method.
*
* In this case we delete the reference to the databaseManager
*/
function destroy()
{
   // Release the reference to the dbase manager
   delete dbase
}



function handleRequest(cmd, params, user, fromRoom)
{

}











function handleInternalEvent(evt)
{
       
   var nick = evt["nick"]
   var pass = evt["pass"]
   var chan = evt["chan"]
   
   // create a SQL statement
   var sql = "SELECT * FROM mydatabase WHERE nombre='"+nick+"' AND password='"+pass+"'"

   

   // prepare the response object
   var response = new Object()

   // execute query on DB
   // queryRes is a ResultSet object
   var queryRes = dbase.executeQuery(sql)
 
   if (queryRes == null)   {
      response.err = "User not recognized"
      response._cmd = "logKO"
      _server.sendResponse(response, -1, null, chan)
   }

   if (queryRes != null) {
   
      var obj = _server.loginUser(nick, pass, chan)
      if (obj.success == false) {
         response.err = obj.error
      } else if (obj.success == true) {
         response.err = "";
         if (response.err == "") {
            //var response = new Object()
            user = _server.getUserByChannel(chan);
            response._cmd = "logOK"
            response.name = user.getName();
            response.id = user.getUserId();
         }
         else
         {               
            response._cmd = "logKO"
            response.name = nick
         }
         _server.sendResponse(response, -1, null, [user])
      }
   }
}



and my loguingui is:

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;

   private string serverIP = "127.0.0.1";
   private string serverPort = "3000";
   public string zone = "simpleChat";
   public bool debug = true;

   public GUISkin gSkin;

   private string nick = "";
   private string pass = "";
   private string loginErrorMessage = "";

   /************
     * Unity callback methods
     ************/

   void OnApplicationQuit() {
      shuttingDown = true;
   }

   private bool connectionAttempt = false;

   
   //
   
   
   
   //
   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;
      
      
      

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

   void OnGUI() {

      GUI.skin = gSkin;
      GUI.Label(new Rect(2, -2, 680, 70), "", "SFSLogo");   
      //connectionAttempt = true;
   //smartFox.Connect(serverIP, Convert.ToInt32(serverPort));

      if (!connectionAttempt) {
         GUI.Label(new Rect(10, 116, 100, 100), "IP: ");
         serverIP = GUI.TextField(new Rect(100, 116, 200, 20), serverIP, 25);
         
         GUI.Label(new Rect(10, 136, 100, 100), "Port: ");
         serverPort = GUI.TextField(new Rect(100, 136, 200, 20), serverPort, 25);
         
         if (GUI.Button(new Rect(100, 166, 100, 24), "Connect")  || (Event.current.type == EventType.keyDown && Event.current.character == '\n')) {
            connectionAttempt = true;
            smartFox.Connect(serverIP, Convert.ToInt32(serverPort));
         }
      
      }
      else if (smartFox.IsConnected()) {
         // Login
         GUI.Label(new Rect(10, 116, 100, 100), "Username: ");
         nick = GUI.TextField(new Rect(100, 116, 200, 20), nick, 25);
         
         
         
         GUI.Label(new Rect(10, 146, 100, 100), "Password ");
         pass = GUI.TextField(new Rect(100, 146, 200, 20), pass, 25);
         
         

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

         if ( GUI.Button(new Rect(100, 186, 100, 24), "Login")  || (Event.current.type == EventType.keyDown && Event.current.character == '\n')) {
            smartFox.Login(zone, nick, pass);
         }

      } else {
         GUI.Label(new Rect(10, 150, 100, 100), "Waiting for connection");
         GUI.Label(new Rect(10, 218, 100, 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)
   {
      // Handle XML responses
       if (type == SmartFoxClient.XTMSG_TYPE_XML)
       {
          print("XML Response Handler");
              SFSObject responseData = (SFSObject)data;
           // TODO: check command and perform required actions

         print("Response Data: " + responseData.GetString("_cmd"));
         switch ( responseData.GetString("_cmd") )
         {
            case "logOK":
               OnLogin(true, responseData.GetString("name"), responseData.GetString("err"));
               break;
            case "logKO":
               OnLogin(false, responseData.GetString("name"), responseData.GetString("err"));
               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 island
      UnregisterSFSSceneCallbacks();
      Application.LoadLevel("Room_1");
   }
}




what i need to fix it.please help.
thanks.....and sorry for my bad english.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 08 Dec 2010, 03:48

Code: Select all

   public void OnLogin(bool success, string name, string error) {
      if ( success ) {
         // Lets wait for the room list

      }


» The server side

NOTE:
When using a non-custom login, the client will handle the login response via the onLogin event handler. Behind the scenes the client API will assign the SmartFoxClient myUserName and myUserId properties.

When using a custom login the response is sent back to the client via the extension and it is handled in the onExtensionResponse handler. Also the myUserName and myUserId properties ARE NOT populated auto-magically, so you will need to do it manually, if you need them.

When using a custom login always make sure to call to request the room list to the server via the getRoomList() request.

just read the docs..
kano
Posts: 71
Joined: 04 Dec 2010, 00:44
Location: Asturias

Postby kano » 09 Dec 2010, 06:51

thanks for answers appels.im a 3d modeler and is very hard for me to do that.i have some cuestions about that.
i see my onextensionresponse is for handle xml, and i dont want this , my extension conect (or will conect) with mysql.how can i use onextensionresponse with mysql?.i supose is via extension.but how handle it in my logingui.?
And other cuestion is where i need to put myusername and myuserid properties ,in the extension?

im using to response.name = user.getName();
response.id = user.getUserId();
but i supose i need to tell what name and what id have the user.
im working with my login passwor for a month and im mad with that.

thanks for any answer.
and sorry for my english again
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 09 Dec 2010, 07:53

the xml is the message type smartfox uses to send the response back to the client, it has nothing to do with mysql. You can talk to mysql from the extension and then validate your login request.
the extension response is the data you send back to the client, this can be anything you want, if you validate your received login data with the data from the mysql query, you can send a true or false value through a response object and you can catch that in the OnExtensionResonse handler on the client side.

where i need to put myusername and myuserid properties

since you get the validation data back in the OnExtensionResponse handler you can do it there.

but i supose i need to tell what name and what id have the user.

The user will send a username, use that.
Smartfox will assign an id :
response.id = user.getUserId(); <- this is good.
response.name = user.getName(); <- this isn't good.
you need to grab the name that was sent by the user.
var nick=evt["nick"];

response.name = nick;
kano
Posts: 71
Joined: 04 Dec 2010, 00:44
Location: Asturias

Postby kano » 09 Dec 2010, 09:06

thanks again appels.then, if i understand i just need to change
response.name = user.getName(); for
response.name = nick;
im using response.id = user.getUserId();
and var nick=evt["nick"];

then my extension is ok?
my error is in onextensionresponse?


sorry for to much questions.
thanks.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 09 Dec 2010, 09:44

then my extension is ok?

yes
my error is in onextensionresponse?

i don't know
kano
Posts: 71
Joined: 04 Dec 2010, 00:44
Location: Asturias

Postby kano » 09 Dec 2010, 10:09

thanks for your fast answer appels.then i need to work with my logingui and maybe with the onextensionresponse.thanks a lot, now i know where i need to see.if i can help you with 3d models, just say me.
thanks again.
kano
Posts: 71
Joined: 04 Dec 2010, 00:44
Location: Asturias

Postby kano » 09 Dec 2010, 15:18

hi again.now my problem is other.when i write my login and password, say "user not recognized" and in the unity console first say logko and after that say lokok, but the user is nor recognized.After that , if i try to use other username or password (in the same screen) the unity console just say logko.why ?

(user not recognized is in game screen , not in smartfox console)

thanks.
kano
Posts: 71
Joined: 04 Dec 2010, 00:44
Location: Asturias

Postby kano » 23 Dec 2010, 00:59

the login password now works.
thanks to appels.

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 2 guests