I have uploaded both the server and client side code for the Multiplayer Nutmeg game mentioned in a previous post. Here is a short description on the steps to have your own copy up and running. Be warned that I have never written Actionscript code before and Java was a looong time ago so this is probably not the prettiest code you've seen.
In order to have a go yourself you must first download the Nutmeg tutorial files (second part) from .net Magazine (Issue 218) and get it to compile and run using FlashDevelop or similar IDE.
You also need to install Smartfoxserver 2 on your PC. Installation files are available for Windows, Linux and Mac.
- Download and extract the attached ZIP file (see end of this post)
- Add Network.as, RemoteUser.as and Users.as to the Flixel project.
- Next add the Smartfoxserver library, SFS2X_API_AS3.swc, to your project. This file you will have to copy from your Smartfox installation - **installdir**/Client/Flash/API.
- Replace PlayerState.as with the one from the ZIP
- Copy the sfs-config.xml file from ZIP into the bin directory of the project. Edit that file and replace www.spelagon.com with localhost or the name of the server with your Smartfoxserver instance.
You should now be able to compile the project and start the game. It will still not be multiplayer because you need to setup the zone, room and server extension as shown below.
- Create a new Java project using Eclipse or your favourite IDE. Add MoveHandler.java and Nutmeg.java as source files.
- Also be sure to reference the smartfoxserver libraries: sfs2x.jar, sfs2x-core.jar
- Build the Nutmeg.jar file and copy it into the smartfox installation directory **installdir**/SFS2X/extensions/Nutmeg. You have to create the Nutmeg directory.
- Next we have to add the Zone "Rune" in the Smartfox admin Tool. In the Zone extension tab add Nutmeg as name and com.nutmeg.sfsx2.Nutmeg as file.
- Create a room in the zone called "FirstRoom"
- Restart Smartfoxserver. This is needed to activate the new Zone.
If you have any problems compiling or installing the server extension there is a nice video tutorial on how to do it. It sure helped me =)
You should now be able to start the Nutmeg game and see it connect to your server. I haven't really explained any of the code here so if you have any questions feel free to ask!