Page 1 of 2

{ NEW } The Java Extensions CookBook

Posted: 17 Feb 2009, 08:56
by Lapo
Hello everyone,
we have just added a new section in the documentation called the Java Extension CookBook. It is a collection of code examples for many different use cases diveded in different categories: login handling, room creation, room joining, json protocol, string protocol, request dispatching and a lot more.

There are currently over 30 recipes in the cookbook and we'll keep adding them with next updates.

Also we encourage anyone who has an interesting code recipe to post it here or send it to our email. We will be very pleased to grow the cookbook's recipe list with the your help.

Follow this link to consult the CookBook
You will also find it linked in the main documentation menu, chapter 6.x

Posted: 18 Feb 2009, 08:06
by Lapo
Small Update:
The chapter related to User Variables are referring to SmartFoxServer version 1.6.5.02 which is not out yet.
It's the next update coming in the next week and it will include a few enhancements on the User variables front.

AS3 and Server-Side extensions

Posted: 17 Mar 2009, 06:25
by mariana
I moved recently from AS2 to AS3 and am looking for examples, tutorials, etc, in server-side AS3 extensions, but I find none.....

am I right in assuming that from here onwards server-side extensions will always be JavaScript?

It IS true that they are VERY similar.

Thanks,

Mariana

Posted: 17 Mar 2009, 07:38
by Lapo
Server side AS3 is not supported. You can use Java instead which is very similar and performs hundreds of times better.

If you prefer to stay with Actionscript then you should use AS1 / Javascript (it's the same thing)

Posted: 16 Apr 2009, 11:44
by duke
I did a cut+paste on the login to DB recipe, but got quite a few errors! I'm pretty sure I included all the right classes. Moo_Login is my classname/filename :)

Code: Select all

Moo_Login.java:15: Moo_Login is not abstract and does not override abstract meth
od handleRequest(java.lang.String,java.lang.String[],it.gotoandplay.smartfoxserv
er.data.User,int) in it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

public class Moo_Login extends AbstractExtension
       ^
Moo_Login.java:24: cannot find symbol
symbol  : variable getOwnerZone
location: class Moo_Login
                currentZone = helper.getZone(this.getOwnerZone);
                                                 ^
Moo_Login.java:39: cannot find symbol
symbol  : variable ieo
location: class Moo_Login
                        String nick = ieo.getParam("nick");
                                      ^
Moo_Login.java:40: cannot find symbol
symbol  : variable ieo
location: class Moo_Login
                        String pass = ieo.getParam("pass");
                                      ^
Moo_Login.java:43: cannot find symbol
symbol  : variable ieo
location: class Moo_Login
                        SocketChannel chan = (SocketChannel)ieo.getObject("chan"
);
                                                            ^
Moo_Login.java:53: canLogin(java.lang.String,java.lang.String,java.nio.channels.
SocketChannel,java.lang.String) in it.gotoandplay.smartfoxserver.extensions.Exte
nsionHelper cannot be applied to (java.lang.String,java.lang.String,java.nio.cha
nnels.SocketChannel,it.gotoandplay.smartfoxserver.data.Zone)
                                        newUser = helper.canLogin(nick, pass, ch
an, currentZone);
                                                        ^
Moo_Login.java:55: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                        res.put("_cmd", "logOK");
                                        ^
Moo_Login.java:56: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                        res.put("id", String.valueOf(newUser.get
UserId()));
                                        ^
Moo_Login.java:57: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                        res.put("name", newUser.getName());
                                        ^
Moo_Login.java:67: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                        res.put("_cmd", "logKO");
                                        ^
Moo_Login.java:68: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                        res.put("err", le.getMessage());
                                        ^
Moo_Login.java:75: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                res.put("_cmd", "logKO");
                                ^
Moo_Login.java:76: cannot find symbol
symbol  : variable res
location: class Moo_Login
                                res.put("err", "Sorry, invalid credentials.");
                                ^
Moo_Login.java:81: warning: [unchecked] unchecked call to add(E) as a member of
the raw type java.util.LinkedList
                        ll.add(chan);
                              ^
Moo_Login.java:84: cannot find symbol
symbol  : variable res
location: class Moo_Login
                        sendResponse(res, -1, null, ll);
                                     ^
Moo_Login.java:98: cannot find symbol
symbol  : variable SmartFoxLib
location: class Moo_Login
                name = SmartFoxLib.escapeQuotes(name);
                       ^
Moo_Login.java:99: cannot find symbol
symbol  : variable SmartFoxLib
location: class Moo_Login
                pass = SmartFoxLib.escapeQuotes(pass);
                       ^
Moo_Login.java:107: cannot find symbol
symbol  : class ArrayList
location: class Moo_Login
                ArrayList queryRes = dbManager.executeQuery(sql);
                ^
17 errors
1 warning

Posted: 16 Apr 2009, 12:58
by Lapo
Make sure to have all necessary classes in the classpath when compiling, according to the SFS version in use.
Also using an IDE such as Eclipse or Netbeans will help quite a lot.

You can read about all these things and a lot more here:
http://www.smartfoxserver.com/docs/docP ... nsions.htm

joinRoom recipe 1 error

Posted: 08 May 2009, 12:26
by AlecMcE
There's a parameter missing in the helper.joinRoom command. The syntax demands a 'current room' integer variable, but this is not included in the example.

Posted: 09 May 2009, 11:13
by Lapo
Sorry which server side language are you referring to? Actionscript? Java?

Posted: 22 May 2009, 02:59
by jah2488
does the new sfsPRO still not allow AS3 Server Side?

Posted: 22 May 2009, 06:40
by Lapo
No, it is very unlikely we will ever support it.
If you need an OOP language for your server side code use Java, you will exploit the full potential of the JVM, including threading, synchronization etc...

Java and AS3 are very similar (actually AS3 is very much "inspired" by Java) but Java outperforms it by orders of magnitude.

If you know your OOP concepts the jump from AS3 to Java is minimal.
Take a look here:
http://www.infoq.com/articles/actionscript-java

Posted: 22 May 2009, 16:15
by jah2488
Thanks again for the info, I'd best get used to Java then :P

hrmm.. although I suppose I could use python, i do know more of that then Java, but then again Java/AS3 are very similar. Stupid decisions...

Posted: 03 Aug 2009, 13:12
by Jipii
So if I want to develop my new extensions with java, which java I have to learn? I see books about java 2, java 6, java 7 and some more.
I am developing other projects objectoriented in php, so I just have to extend my knowledge in some topics in java (java syntax, development enviroment and more). That's why I will first take a look into a book in combination with the java extension examples.

Posted: 03 Aug 2009, 13:27
by Lapo
Learn Java 5.
In other words any book dealing with Java 5 or higher is great. Java 6 didn't add anything new to the language, while Java 7 is not out yet.

Btw, if you are familiar with OOP in PHP (like PHP 5) you will find yourself pretty much at home because PHP "inherited" a lot from the Java OOP style.

Posted: 19 Jul 2010, 19:09
by darkxer878
Lapo wrote:Learn Java 5.
In other words any book dealing with Java 5 or higher is great. Java 6 didn't add anything new to the language, while Java 7 is not out yet.

Btw, if you are familiar with OOP in PHP (like PHP 5) you will find yourself pretty much at home because PHP "inherited" a lot from the Java OOP style.
Java appears to be very similar to C# also.

To serve Man ... Its a cook book

Posted: 19 Aug 2010, 22:56
by d3m0nlogic
I am posting hoping someone can help..
The cookbook recipes for uservariables does not work, nor is it casting correctly for HashMap.

for example.. declaring TYPE_NUMBER by itself throws and error.. and when corrected with UserVariables.TYPE_NUMBER throw an entirely different error.

there is a slew of errors .. is there any class examples that I can glean from ?

:shock: :shock: :shock: