{ NEW } The Java Extensions CookBook

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

Moderators: Lapo, Bax

User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

{ NEW } The Java Extensions CookBook

Postby Lapo » 17 Feb 2009, 08:56

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
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Feb 2009, 08:06

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.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
mariana
Posts: 77
Joined: 26 Mar 2007, 11:15
Location: Buenos Aires, Argentina

AS3 and Server-Side extensions

Postby mariana » 17 Mar 2009, 06:25

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
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Mar 2009, 07:38

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)
Lapo

--

gotoAndPlay()

...addicted to flash games
duke
Posts: 31
Joined: 16 Apr 2009, 11:23

Postby duke » 16 Apr 2009, 11:44

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
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 16 Apr 2009, 12:58

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
Lapo

--

gotoAndPlay()

...addicted to flash games
AlecMcE
Posts: 11
Joined: 24 Nov 2008, 16:03

joinRoom recipe 1 error

Postby AlecMcE » 08 May 2009, 12:26

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.
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 May 2009, 11:13

Sorry which server side language are you referring to? Actionscript? Java?
Lapo

--

gotoAndPlay()

...addicted to flash games
jah2488
Posts: 19
Joined: 05 May 2009, 04:06
Contact:

Postby jah2488 » 22 May 2009, 02:59

does the new sfsPRO still not allow AS3 Server Side?
Sic Transit Gloria Mundi
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 22 May 2009, 06:40

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
Lapo

--

gotoAndPlay()

...addicted to flash games
jah2488
Posts: 19
Joined: 05 May 2009, 04:06
Contact:

Postby jah2488 » 22 May 2009, 16:15

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...
Sic Transit Gloria Mundi
Jipii
Posts: 72
Joined: 18 Aug 2008, 08:53
Location: Frankfurt, Germany

Postby Jipii » 03 Aug 2009, 13:12

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.
Thanks!
User avatar
Lapo
Site Admin
Posts: 21286
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 03 Aug 2009, 13:27

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.
Lapo

--

gotoAndPlay()

...addicted to flash games
darkxer878
Posts: 2
Joined: 19 Jul 2010, 17:46

Postby darkxer878 » 19 Jul 2010, 19:09

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.
d3m0nlogic
Posts: 32
Joined: 19 Aug 2010, 22:44
Location: Santa Monica
Contact:

To serve Man ... Its a cook book

Postby d3m0nlogic » 19 Aug 2010, 22:56

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:
Abyssus abyssum invocat,Ad hominem Ad Libitur..Non Conserva me ab animam inferno...liberate tutame ex inferis

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 2 guests