I am using a java login extension along with the avatarchat example to login to the avatarchat with a username and password.
The login is working, but my avatar does not appear when it goes to the chat frame, and the exit + send buttons do nothing.
Here is the onextensionresponse code I have added to the actionscript.
Code: Select all
public function onExtensionResponse(evt:SFSEvent):void
{
var params:Object = evt.params.dataObj
var cmd:String = params._cmd
if (cmd == "logOK")
{
sfs.myUserId = params.id
sfs.myUserName = params.name
trace("login success")
}
else if (cmd == "logKO")
{
trace("authentication failed: " + params.err)
}
}
And here's my extension code (I am 99% sure the error is that I'm missing something in the client side).:
Code: Select all
boolean checkCredentials(String name, String pass)
{
boolean result = false;
// Escape quotes on passed data
name = SmartFoxLib.escapeQuotes(name);
pass = SmartFoxLib.escapeQuotes(pass);
String q = "'";
// SQL statement to execute
String sql = "SELECT name,login_key,mod_level,ip FROM users WHERE name = " + q + name + q;
// Execute the SQL statement
ArrayList queryRes = db.executeQuery(sql);
// If record was found exist...
if (queryRes != null && queryRes.size() > 0)
{
DataRow dr = (DataRow) queryRes.get(0);
System.out.println(dr);
String lk = dr.getItem("login_key");
if(lk.equals(pass))
{
result = true;
}
}
return result;
}
public void handleInternalEvent(InternalEventObject evt)
{
String evtName = evt.getEventName();
if(evtName.equals("loginRequest"))
{
boolean ok = false;
User newUser = null;
ActionscriptObject res = new ActionscriptObject();
String nick = evt.getParam("nick");
String pass = evt.getParam("pass");
SocketChannel chan = (SocketChannel) evt.getObject("chan");
ok = checkCredentials(nick, pass);
if (ok)
{
try
{
Zone z0n3 = helper.getZone(this.getOwnerZone());
String currentZone = z0n3.getName();
newUser = helper.canLogin(nick, pass, chan, currentZone);
//newUser = helper.canLogin(nick, pass, chan, currentZone);
res.put("_cmd", "logOK");
res.put("id", String.valueOf(newUser.getUserId()));
res.put("name", newUser.getName());
ok = true;
}
catch (LoginException le)
{
this.trace("Could not login user: " + nick);
res.put("_cmd", "logKO");
res.put("err", le.getMessage());
}
}
else
{
res.put("_cmd", "logKO");
res.put("err", "Sorry, invalid credentials.");
}
LinkedList ll = new LinkedList();
ll.add(chan);
sendResponse(res, -1, null, ll);
if (ok)
helper.sendRoomList(chan);
}
}
Like I said, I'm pretty sure the issue is that I'm missing something in the client side. Could someone help me with this?