OnExtensionResponse Question with Unity and XML
Posted: 07 Aug 2009, 17:03
Hello All:
I don't have a clue what I am doing. Here is my issue:
This runs and get the data from the database. It's all good and I have tested it, and the traces are showing the correct data.
Then the OnExtensionResponse gets fired.
All I want to do is get the value of "remoteUserID". Is there a way to dump the entire SFSObject in a Debug so I can see what's going on?
But otherwise, I think everything else is working. I know if I do a responseData.GetString("_cmd") I will get back "getData". But I cannot seem to get the value of "remoteUserID" back.
What am I overlooking? Thanks for any and all help!
I don't have a clue what I am doing. Here is my issue:
Code: Select all
function handleRequest(cmd, params, user, fromRoom)
{
// Add your code here
trace("handleRequest")
trace("params1:"+params[0])
trace("params2:"+params["remoteUserName"])
if (cmd == "getData")
{
trace("handleRequest inside")
// create a SQL statement
var sql = "SELECT remoteUserID FROM characterData where name = '"+params["remoteUserName"]+"'"
// execute query on DB
// queryRes is a ResultSet object
var queryRes = dbase.executeQuery(sql)
// prepare the response object
var response = {}
response._cmd = "getData"
// Here we create an array for storing the database data
response.db = []
if (queryRes != null)
{
// Cycle through all records in the ResultSet
for (var i = 0; i < queryRes.size(); i++)
{
// Get a record
var tempRow = queryRes.get(i)
// This object will hold the record data that we'll send to the client
var item = {}
// From the record object we can get each field value
item.remoteUserID = tempRow.getItem("remoteUserID")
trace("item.remoteUserID: "+item.remoteUserID)
response.db.push( item )
}
}
else
trace("DB Query failed")
_server.sendResponse(response, -1, null, [user])
}
}
This runs and get the data from the database. It's all good and I have tested it, and the traces are showing the correct data.
Then the OnExtensionResponse gets fired.
Code: Select all
public void OnExtensionResponse(object data, string type)
{
Debug.Log("NetworkController : OnExtensionResponse");
Debug.Log("Type: "+type);
// Handle XML responses
if (type == SmartFoxClient.XTMSG_TYPE_XML)
{
SFSObject responseData = (SFSObject)data;
Debug.Log("Testing Return Data: "+responseData.GetString("_cmd"));
switch (responseData.GetString("item"))
{
case "getData":
Debug.Log("I hit 1");
break;
case "remoteUserID":
Debug.Log("I hit 2");
break;
}
// TODO: check command and perform required actions
}
// Handle RAW responses
else if (type == SmartFoxClient.XTMSG_TYPE_STR)
{
string responseData = (string)data;
// TODO: check command and perform required actions
}
}
All I want to do is get the value of "remoteUserID". Is there a way to dump the entire SFSObject in a Debug so I can see what's going on?
But otherwise, I think everything else is working. I know if I do a responseData.GetString("_cmd") I will get back "getData". But I cannot seem to get the value of "remoteUserID" back.
What am I overlooking? Thanks for any and all help!