login issue
Posted: 18 Jul 2011, 08:11
Hi wondering if you could help with an issue we are having
When i login a user i get this message but not all the time:
[ WARNING ] > Room list was requested by a non logged user!
I'm wondering what could be causing this.
Should I put the forceLogin flag to true in the canLogin method?
here is the code i'm using for the login check
When i login a user i get this message but not all the time:
[ WARNING ] > Room list was requested by a non logged user!
I'm wondering what could be causing this.
Should I put the forceLogin flag to true in the canLogin method?
here is the code i'm using for the login check
Code: Select all
private void loginCheck(String nameKey, SocketChannel chan)
{
// convert nameKey to userID by reading key from database
boolean ok = true;
// Prepare a response object for the client
JSONObject res = new JSONObject();
//check if user is still playing a tournament
-- if user is still in a tournament set ok to false
if (ok)
{
try
{
User usr = null;
try{
usr = zone.getUserByName(nameID);
if(usr !=null)
{
xtHelper.logoutUser(usr, false);
}else{
//trace("not logged in");
}
}catch(Error e){ log("error getting user "+ nameID); }
// Attempt to login the user in the system
usr = xtHelper.canLogin(nameID, "", chan, ZONE_NAME, true);
if(usr != null )
{
res.put("cmd", CMD_LOG_OK);
}else{
//trace("setting ok to false");
ok = false;
}
}
// An exception occurred while logging the user in
catch (Exception le)
{
log("Could not login user: " + nameID);
try{
res.put("cmd", CMD_LOG_FAIL);
res.put("msg", le.getMessage());
}catch(Exception e){ trace("Failed to create response " + e.toString());}
}
}
// The user name is not among the valid ones
else
{
try
{
res.put("cmd", CMD_LOG_FAIL);
if(nameID == null)
{
res.put("msg", "User access error");
}else{
res.put("msg", "Already playing");
}
}catch(Exception e){log("ERROR - Failed to create response 2 "+ e.toString());}
}
// Prepare the list of recipients, in this case we only one.
LinkedList<SocketChannel> ll = new LinkedList<SocketChannel>();
ll.add(chan);
// Send login response
sendResponse(res, -1, null, ll);
// Send room list
if (ok)
xtHelper.sendRoomList(chan);
}