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.
{ NEW } The Java Extensions CookBook
-
- Posts: 32
- Joined: 19 Aug 2010, 22:44
- Location: Santa Monica
- Contact:
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.
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
Static imports:
http://www.deitel.com/articles/java_tut ... index.html
Ok, anything else that is not working?
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?
-
- Posts: 32
- Joined: 19 Aug 2010, 22:44
- Location: Santa Monica
- Contact:
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
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?
-
- Posts: 32
- Joined: 19 Aug 2010, 22:44
- Location: Santa Monica
- Contact:
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.
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
-
- Posts: 32
- Joined: 19 Aug 2010, 22:44
- Location: Santa Monica
- Contact:
on to something...
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.
Best Regards,
Thomas
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.
Best Regards,
Thomas
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis
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.
-
- Posts: 32
- Joined: 19 Aug 2010, 22:44
- Location: Santa Monica
- Contact:
License
Great. Thanks for the tip on that. I will let my team know.
And yes we are testing it out for purchase.
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
Some errors in examples
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?
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?
handleRequest is not called by smartfox
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
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
Return to “Server Side Extension Development”
Who is online
Users browsing this forum: No registered users and 50 guests