Here is what I have on the server side. This was straight from a tutorial, but I took the time to understand it, hopefully it will help you with your Java extension and understanding how that reacts with the client:
Code: Select all
@Override
public void handleInternalEvent(InternalEventObject ieo) {
// TODO Auto-generated method stub
String eventName = ieo.getEventName();
trace("Event Fired: " + eventName);
if (eventName.equals("loginRequest"))
{
boolean ok = false;
User newUser = null;
// Prepare a response object for the client
ActionscriptObject response = new ActionscriptObject();
// Get the user nickname and password
String user = ieo.getParam("nick");
String pass = ieo.getParam("pass");
SocketChannel chan = (SocketChannel) ieo.getObject("chan");
// validate the user name
if (validNames.contains(user))
{
ok = true;
}
if (ok)
{
try
{
// Attempt to login the user to the system
newUser = helper.canLogin(user, pass, chan, currentZone.getName());
response.put("_cmd", "logOK");
response.put("id", String.valueOf(newUser.getUserId()));
response.put("name", newUser.getName());
trace("Logged in user.");
ok = true;
}
catch (LoginException le)
{
this.trace("Could not login user: " + user);
response.put("_cmd", "logKO");
response.put("err", le.getMessage());
}
}
// The user name is not among the valid ones
else
{
response.put("_cmd", "logKO");
response.put("err", "Sorry, your user name was not accepted.");
trace("Failed");
}
// Prepare the list of recipients, in this case we only one.
LinkedList ll = new LinkedList();
ll.add(chan);
// Send login response
sendResponse(response, -1, null, ll);
// Send room list
if (ok)
helper.sendRoomList(chan);
}
The most important thing I think to look at is here:
response.put("_cmd", "logOK");
response.put("id", String.valueOf(newUser.getUserId()));
response.put("name", newUser.getName());
trace("Logged in user.");
ok = true;
You can see the server is stuffing that "logOK" message along with the ID, and the name of the logged in user, and sending it as an SFSObject to the client. The client then uses the code in my previous post to pull out those parameters and use them.
Hope this helps.