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.