{ NEW } The Java Extensions CookBook

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

Moderators: Bax, Lapo, rjgtav

Postby Lapo » 20 Aug 2010, 06:24

There are 4 examples in the UserVariables chapter.
Which one is not working for you? And what is exactly the error that you get?
Which server version do you use?

FYI imports are omitted from the code. This is why the TYPE_NUMBER etc... dont' work for you. Use an import static to use them.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16221
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby d3m0nlogic » 20 Aug 2010, 08:11

:shock:
:shock:
:shock:
Wow... that was cool that you replied quick.

Ok. so none of them work...

not really sure about how to add import static?

but here is my code:
int fb_id = 1234;
Map<String, UserVariable> vars = new HashMap<String, UserVariable>();
vars.put("fb_id", new UserVariable(String.valueOf(fb_id), UserVariable.TYPE_NUMBER));
// Set Variables
_helper.setUserVariables(_user, vars, true);
UserVariable _retval = _user.getVariable("fb_id");

If there is one thing that does stick out for me... is that MAP isn't the type that method setUserVariables is looking for, it's looking for a HashMap not Map.






:twisted: :twisted: :twisted:
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
d3m0nlogic
 
Posts: 32
Joined: 19 Aug 2010, 22:44
Location: Santa Monica

Postby Lapo » 20 Aug 2010, 10:18

Static imports:
http://www.deitel.com/articles/java_tut ... index.html

If there is one thing that does stick out for me... is that MAP isn't the type that method setUserVariables is looking for, it's looking for a HashMap not Map.

Ok, anything else that is not working?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16221
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby d3m0nlogic » 20 Aug 2010, 17:23

:D :D :D

Thank you for your response back...
I did change Map to HashMap ... but it doesn't work ... when I use the tester client to connect to room and it triggers a JOIN event, the trace dies around that code...so it possible its throwing an error in java and not to sfs..

I am gonna see if I can investigate in the logs if it is throwing an error.

The other thing is ... this may be a silly question... which class are you recommending to import as a static class, UserVariable?

...UPDATE:
I am using SFS 1.6.6 with the update 1.6.9 patch.

so this is the code:
User _user = (User) evt.getObject("user");
trace("_user Name:" + _user.getName());
int fb_id = 1234;
trace("created a uservariable");
HashMap<String, UserVariable> vars = new HashMap<String, UserVariable>();
trace("hashmap instance");
vars.put("fb_id", new UserVariable(String.valueOf(fb_id), UserVariable.TYPE_NUMBER));
trace("put");
_helper.setUserVariables(_user, vars, true);
trace("end of block");
int currentId = _user.getVariable("score").getIntValue();
trace("test this::" + currentId);


through the adminpanel.. it dies at _helper.setUserVariables(...


Thanks..

Thomas. :? :? :? :? :? :? :?
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
d3m0nlogic
 
Posts: 32
Joined: 19 Aug 2010, 22:44
Location: Santa Monica

Postby Lapo » 24 Aug 2010, 07:50

Thank you for your response back...
I did change Map to HashMap ... but it doesn't work ... when I use the tester client to connect to room and it triggers a JOIN event, the trace dies around that code...so it possible its throwing an error in java and not to sfs..

There is no difference. An exception will be logged anyways.
Did you check your logs?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16221
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby d3m0nlogic » 26 Aug 2010, 02:32

Yep checked the logs.. and there was zippo. nothing.


But I figured out to use instead the single entry approach to the variables.
It works and doesn't cause it to crash.....:)


Unfortunately it probably does not broadcast it back to the user.
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
d3m0nlogic
 
Posts: 32
Joined: 19 Aug 2010, 22:44
Location: Santa Monica

on to something...

Postby d3m0nlogic » 29 Aug 2010, 18:40

I just realized that it is very possible that there is a missed step from the tutorials and the reason why that line won't work. Something is either going undefined or hasn't been correctly instantiated. I am gonna test that out later this afternoon.. and get back with results.

BTW.. is there possibly an issue from the download version of the application and licensing? In other words... you guys give us a patched library that unlocks stuff once we pay the license fee?

I figured I asked... since it wouldn't hurt.. and its better than chasing my tail on stuff. :roll: :roll: :D

Best Regards,
Thomas
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
d3m0nlogic
 
Posts: 32
Joined: 19 Aug 2010, 22:44
Location: Santa Monica

Postby Lapo » 30 Aug 2010, 05:34

BTW.. is there possibly an issue from the download version of the application and licensing? In other words... you guys give us a patched library that unlocks stuff once we pay the license fee?

If you are running a demo license and buy a commercial one we'll send a license file. This will unlock the max number of concurrent users but no other features are locked.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16221
Joined: 21 Mar 2005, 09:50
Location: Italy

License

Postby d3m0nlogic » 30 Aug 2010, 15:58

Great. Thanks for the tip on that. I will let my team know.

And yes we are testing it out for purchase.
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
d3m0nlogic
 
Posts: 32
Joined: 19 Aug 2010, 22:44
Location: Santa Monica

Some errors in examples

Postby mst » 24 Jan 2011, 03:13

Hello
I am learning about Java Extensions, and I think that there are some errors in 6.x Java Extensions CookBook.
For example:

on page: http://www.smartfoxserver.com/docs/docP ... _Login.htm


Recipe #2
there is sample code:

ExtensionHelper helper;

Zone currentZone;
DbManager dbManager;

public void init()
{
helper = ExtensionHelper.instance();
currentZone = helper.getZone(this.getOwnerZone);
dbManager = currentZone.dbManager;
}

public void handleInternalEvent(InternalEventObject evt)
{
if (evt.getEventName().equals(InternalEventObject.EVENT_LOGIN))
{
boolean ok = false;
User newUser = null;

// Prepare a response object for the client
ActionscriptObject response = new ActionscriptObject();

// get the user nickname and password
String nick = ieo.getParam("nick");
String pass = ieo.getParam("pass");

// get the user socket channel
SocketChannel chan = (SocketChannel) ieo.getObject("chan");

// validate user name
ok = checkCredentials(nick, pass);

if (ok)
{
try
{
// Attempt to login the user in the system
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;
}

// An exception occurred while logging the user in
catch (LoginException le)
{
this.trace("Could not login user: " + nick);

res.put("_cmd", "logKO");
res.put("err", le.getMessage());
}
}

// Invalid credentials
else
{
res.put("_cmd", "logKO");
res.put("err", "Sorry, invalid credentials.");
}

// Prepare the list of recipients, in this case we only one.
LinkedList ll = new LinkedList();
ll.add(chan);

// Send login response
sendResponse(res, -1, null, ll);

// Send room list
if (ok)
helper.sendRoomList(chan);
}
}

// Here we execute the check on the database
boolean checkCredentials(String name, String pass)
{
boolean result = false;

// Escape quotes on passed data
name = SmartFoxLib.escapeQuotes(name);
pass = SmartFoxLib.escapeQuotes(pass);

// SQL statement to execute
String sql = "SELECT id,name,pass FROM registered_users WHERE" +
"name='" + name "'" +
"AND pass='" + pass + "'";

// Execute the SQL statement
ArrayList queryRes = dbManager.executeQuery(sql);

// If record was found exist...
if (queryRes != null && queryRes.size() > 0)
{
result = true;
}

return result;
}


// ----------------------------------------------------------------------------------------------------------
I think that there are errors in this code (use of evt or ieo? No def for res, is it response? And currentZone is a Zone type, but in helper.canLogin method we need String type) and it should be something like that:

ExtensionHelper helper;
Zone currentZone;
DbManager dbManager;
public void init()
{
helper = ExtensionHelper.instance();
currentZone = helper.getZone(this.getOwnerZone);
dbManager = currentZone.dbManager;
}

public void handleInternalEvent(InternalEventObject ieo)
{
if (ieo.getEventName().equals(InternalEventObject.EVENT_LOGIN))
{
boolean ok = false;
User newUser = null;

// Prepare a response object for the client
ActionscriptObject res = new ActionscriptObject();

// get the user nickname and password
String nick = ieo.getParam("nick");
String pass = ieo.getParam("pass");

// get the user socket channel
SocketChannel chan = (SocketChannel) ieo.getObject("chan");

// validate user name
ok = checkCredentials(nick, pass);

if (ok)
{
try
{
// Attempt to login the user in the system
newUser = helper.canLogin(nick, pass, chan, currentZone.getName());

res.put("_cmd", "logOK");
res.put("id", String.valueOf(newUser.getUserId()));
res.put("name", newUser.getName());

ok = true;
}

// An exception occurred while logging the user in
catch (LoginException le)
{
this.trace("Could not login user: " + nick);

res.put("_cmd", "logKO");
res.put("err", le.getMessage());
}
}

// Invalid credentials
else
{
res.put("_cmd", "logKO");
res.put("err", "Sorry, invalid credentials.");
}

// Prepare the list of recipients, in this case we only one.
LinkedList ll = new LinkedList();
ll.add(chan);

// Send login response
sendResponse(res, -1, null, ll);

// Send room list
if (ok)
helper.sendRoomList(chan);
}
}

// Here we execute the check on the database
boolean checkCredentials(String name, String pass)
{
boolean result = false;

// Escape quotes on passed data
name = SmartFoxLib.escapeQuotes(name);
pass = SmartFoxLib.escapeQuotes(pass);

// SQL statement to execute
String sql = "SELECT id,name,pass FROM registered_users WHERE" +
"name='" + name "'" +
"AND pass='" + pass + "'";

// Execute the SQL statement
ArrayList queryRes = dbManager.executeQuery(sql);

// If record was found exist...
if (queryRes != null && queryRes.size() > 0)
{
result = true;
}

return result;
}



Am I right with my corrections?
mst
 
Posts: 1
Joined: 24 Jan 2011, 02:29
Location: Poland

Postby Lapo » 26 Jan 2011, 18:05

Sorry for being late with this. The unformatted code doens't help :(
(Next time use the Code button to format code)
I will take a look asap and get back to you. Thanks for your patience
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16221
Joined: 21 Mar 2005, 09:50
Location: Italy

handleRequest is not called by smartfox

Postby abuwz » 24 May 2011, 11:13

Hi there,

I'm trying to send an xt message to a server side extension written in java.

From the server logs it seems that the extension is loaded successfully:

INFO | jvm 1 | 2011/05/24 15:11:37 | 15:11:37.662 - [ INFO ] > Zone Extension [ dmg ] created, for zone:demoZone
INFO | jvm 1 | 2011/05/24 15:11:37 | [ demominigame.DmgExtension ]: Demo Mini Game Extension Init.

Internal events are also received:
INFO | jvm 1 | 2011/05/24 15:11:37 | 15:11:37.686 - [ INFO ] > Server is up and running!
INFO | jvm 1 | 2011/05/24 15:11:37 | [ demominigame.DmgExtension ]: DMG - handleInternalEvent: serverReady

On the client side, whici is AC3, the code performs login to the demoZone successfully. Then it calls sendXtMessage("dmg", "testRequest", ....)

This request doesn't seem to reach my extension, because none of the handleRequest methods from my DmgExtension class are called.

Is there anything I need to configure in order to receive the handleRequest events?

Thanks
abuwz
 
Posts: 1
Joined: 24 May 2011, 08:50

Postby Lapo » 24 May 2011, 11:26

You must be logged in a Zone before you can interact with an Extension.
Other than that there's not much more to say. Unless you are overlooking simple stuff such as the name of the command (case sensitive).
I'd suggest to double check
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16221
Joined: 21 Mar 2005, 09:50
Location: Italy

Previous

Return to Server Side Extension Development

Who is online

Users browsing this forum: No registered users and 1 guest