Tuesday, September 28, 2010

Multiplayer Online Gaming - Actionscript and Red Dwarf Server: Part 1

Hello and welcome to my multi part tutorial on how the basics of creating multiplayer Actionscript(Flash) games. The advent of casual gaming has really seen this type of game taking off, and more and more there is demand for simple but powerful solutions to creating online multiplayer games rapidly without sacrificing quality or scalability.  I think that Flash in conjunction with Red Dwarf Server(RDS) is an excellent solution to this need.  The open source nature of RDS also makes it much easier to get started with for programmers of all levels.


First, before we begin let me state that this is not intended to be a beginner level Actionscript or Java tutorial, and if you are not reasonably comfortable with the basics of these languages then you should probably start there instead.


The tools we will use for this are:
- FlashDevelop - http://www.flashdevelop.org
- Darkstar-as3 - http://code.google.com/p/darkstar-as3/
- Eclipse IDE for Java Developers - http://www.eclipse.org/
- Red Dwarf Server (ver 0.10.1) - sgs-server-dist-0.10.1.zip
- Red Dwarf Client (ver 0.10.1) - sgs-c-client-dist-0.10.1.zip
- Fat Jar Eclipse Plug-In - http://fjep.sourceforge.net/
- RDS Server Tutorial - RedDwarf ServerApp Tutorial
- RDS Client Tutorial - RedDwarf Client Tutorial


Setup
Start by downloading Eclipse, Red Dwarf Server and the the RDS Tutorial document.  The RDS tutorial is an open office format document, so you may also need to install that.


Extract Eclipse to c:\projects\eclipse, and red dwarf server and client to c:\projects\rds


Follow the install instructions for Fat Jar Eclipse Plug in, its very easy.


Now the easy part of my tutorial.. RTFM!  Read the Red Dwarf Server App Tutorial.  Ok, ok, I am not actually going to be so lazy as to just tell you to RTFM, but I am also not going to rewrite the excellent tutorials RDS has set up either.  What I will do here is summarize some tips for each tutorial that should help you along.  Once we get near the end of the tutorials we will be ready to start working with Flash as well.  Also, the document is slightly out of date, so hopefully I can help you catch the issues.  The RDS download also contains the source for the tutorials which should work just fine.  The source for these tutorials is in: sgs-server-dist-0.10.1\tutorial\src\com\sun\sgs\tutorial\server


So go ahead and get started by reading the first section of the tutorial.  Nothing much for me to add here, this is the basics of RDS and you will need to learn it to get anywhere with this technology.


Once you get to Lesson One:Hello World! you should have a good basic understanding of RDS.  Lets get started with the first lesson.  Navigate to c:\projects\eclipse and start eclipse.exe.  The first thing you will need to do is set a workspace.  Go ahead and set up a new workspace anywhere you like, I am going to use C:\projects\ws for the tutorial


Next, select the icon on the right side to "Go to the workbench"


Next lets set up a project for this tutorial.  
Name it "tutorial1" and select Next:


Now we need to add the RDS server library.  Choose the Libraries tab, and select "Add External Jars".  We need to add sgs-server-api-0.10.1.jar, which should be located in C:\projects\rds\sgs-server-dist-0.10.1\lib







Lets go ahead and add the class file.  As I said before, the BEST place to get the source for these tutorials is not the tutorial document but rather the RDS download.  So head into the RDS folder and open up the file located at:
C:\projects\rds\sgs-server-dist-0.10.1\tutorial\src\com\sun\sgs\tutorial\server\lesson1
 Open this in notepad or something convenient, we will just copy and paste the class into Eclipse.  In Eclipse, create a new class for the tutorial by the name of HelloWorld.  Put it in the package name com.sun.sgs.tutorial.server.lesson1


Copy and paste the code in.  I recommend you read it thoroughly, but since this is covered in the document I wont discuss the specifics.


Next we are going to set up a few items that I found to be helpful but are not covered in the tutorial document.  Finally I am giving you something useful!


Create a new folder called META-INF in your src folder.  Add a new file called "app.properties" to this folder.  Finally, add these lines to the file:


 com.sun.sgs.app.name = HelloWorld  
 com.sun.sgs.app.listener = com.sun.sgs.tutorial.server.lesson1.HelloWorld  
 com.sun.sgs.impl.transport.tcp.listen.port=1139


Next, use Fat Jar to package up the project, its available from the right click menu off the project folder:





Next we are going to make a simple batch file for launching our projects.  Add another file to the project root called "launch_clean.bat".  Eclipse doesnt know how to edit batch files, but thats ok. Just use the text editor:




Here is the contents of the batch file:
 ECHO Y | del C:\projects\rds\sgs-server-dist-0.10.1\data\dsdb\*.*  
 java -jar C:\projects\rds\sgs-server-dist-0.10.1\bin\sgs-boot.jar  


This batch will delete the RDS database each time you run it.  Of course this isnt something you want to do in production, but its fine for development.


The final step can be done in a couple of ways.  Either copy the fat jar into the C:\projects\rds\sgs-server-dist-0.10.1\deploy directory, or you can edit the sgs-boot.properties file and redirect RDS to your project folder to find the project.  The latter is how I generally managed the tutorials, but either should work.


If you are editing the sgs-boot.properties, all you need to do is set this property:
SGS_DEPLOY = C:/projects/ws/tutorial1


The final step is to launch hello world, do this by right clicking on the launch_clean.bat and selecting Open With -> System Editor


This will also set the default editor back to System, so you can just double click the bat to launch after this.  If everything went correctly you should see a DOS prompt something like this:






Whoo hoo!  We are on the road now!


Well, this concludes Part 1 of my tutorial.  Up next I will do a quick overview of the remaining tutorials leading up to the client tutorial where we get started connecting a Flash client.


Ready for more?  Click here for part 2

3 comments:

  1. I get Missing required property com.sun.sgs.app.name

    I also posted in RedDwarf forums. following your example and
    copying code from the downloaded tutorial folder.

    I set the sgs-boot.properties as
    SGS_DEPLOY = ${SGS_HOME}/../sServices
    since my Eclipse project is one up and over in ../sServices relative to RedDwarf
    ex:
    ..../someFolder/sServices // eclipse project
    ..../someFolder/sServices/src // java source in eclipse project
    ..../someFolder/sServices/src/META-INF
    ..../someFolder/sgs-server // the unziped download with /bin, etc.

    Is that right?
    I get error "Missing required property com.sun.sgs.app.name" on start up.

    My other settings are
    app.properties: (I renamed hello world to Run in root package)
    com.sun.sgs.app.name=Run1
    com.sun.sgs.app.root=../sServices
    com.sun.sgs.impl.transport.tcp.listen.port=1139
    com.sun.sgs.app.listener=Run

    and run.sh (run.sh is in the root of the eclipse project)
    rm -f ../sgs-server/data/dsdb/*.*
    java -jar ../sgs-server/bin/sgs-boot.jar

    I get no joy. Hint?
    thx,
    Vic

    ReplyDelete
  2. Fixed:
    cd bin
    jar cf sServices.jar *
    cd ..
    rm -f ../sgs-server/data/dsdb/*.*
    java -jar ../sgs-server/bin/sgs-boot.jar ../sgs-server/conf/sgs-boot.properties

    ReplyDelete
  3. Are you looking for some online games crypto to play online ANYTIME? These days, almost everyone has access to the Internet and there are a lot of free online games that many of us are playing in our spare time.  https://www.prweb.com/releases/2018/06/prweb15581872.htm

    ReplyDelete