Login problem in Java extension

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
wildart
Posts: 2
Joined: 13 Jun 2007, 04:23

Login problem in Java extension

Post by wildart »

Hi,
I've never wrote java extension before. Everything was written in actionscript. Then I started to port my extension to java and I got error when I try to do custom login.

Here is the code:

Code: Select all

if (ieo.getEventName() == "loginRequest") {
    // Check login name
   String nick = ieo.getParam("nick");
   String pass = ieo.getParam("pass");
   SocketChannel chan = (SocketChannel) ieo.getObject("chan");

   JSONObject oResponse = new JSONObject();
			
   // User object
   User newUser = null;

   // Retrive user params from db (web service)
   DataRow userParams = dbLoginRequest(nick, pass);
   try {
        // PROBLEM IS HERE
	newUser = extHelper.canLogin(nick, pass, chan, currZone.getName());

	newUser.setVariable("uid", userParams.getItem("user_id"), UserVariable.TYPE_NUMBER); 
	oResponse.put("_cmd", "logOK");
	oResponse.put("id", String.valueOf(newUser.getUserId()));
	oResponse.put("user", userParams);
    } catch (LoginException le) {
	this.trace(le.getMessage());
	oResponse.put("_cmd", "logKO");
	oResponse.put("err", "Could not login user: " + nick);
	isError = true;
	}
}
After call of "canLogin" server troughs this exception.

Code: Select all

java.lang.NullPointerException
        at cpi.extPlayground.handleInternalEvent(extPlayground.java:171)
        at it.gotoandplay.smartfoxserver.controllers.MessageHandler.dispatchEvent(MessageHandler.java:141)
        at it.gotoandplay.smartfoxserver.controllers.SystemHandler.handleLoginRequest(SystemHandler.java:406)
        at it.gotoandplay.smartfoxserver.controllers.SystemHandler.processEvent(SystemHandler.java:174)
        at it.gotoandplay.smartfoxserver.controllers.SystemHandler.run(SystemHandler.java:122)
        at java.lang.Thread.run(Thread.java:613)
BTW, I am running server version 1.5.9
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I don't know how that block of code ever gets a chance to be executed...
because this:

Code: Select all

if (ieo.getEventName() == "loginRequest")
is wrong.

The right version is:

Code: Select all

if (ieo.getEventName().equals("loginRequest"))
if you compare two object in java you always use the equals() method. The == sign is used for comparing two references.

Sorry for the digression... anyways if you're new to Java it's highly recommended to look for a couple of tutorials on the basics of the language to avoid common pitfalls.

About your problem, if you get a NullPointer error at the line that you indicated then probably extHelper is null. Double check!
Lapo
--
gotoAndPlay()
...addicted to flash games
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Post by patso »

OFFTOPIC:

It's very likely that java 7 will support String in switch statement (http://blogs.sun.com/dannycoward/resour ... ue_JUG.pdf).

Also language level XML.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

It's very likely that java 7 will support String in switch statement
It was about time! :)
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply