Wednesday, October 8, 2008

Hello World Login with JAGS 1.4m

I've had this demo sitting around for months, thinking I'd had posted it.

This hello world template will help anyone learn how to convert their Actionscript 3 game into a multiplayer game using the JAGS 1.4m server. Physics don't complicate this example like the Tank game, so it's much easier.

The client shows how a login request might be handled, what messages are flowing, and how game names spaces and groups within your game space works.

Typical built in commands save you the grunt work of making a multiplayer game a reality. Not only do you get a nice foundation, but you can easily direct who the messages are going to (everyone in the game, just that players group, or to a single player):



Plus, I give you a simple class called YourCommands.as to extend your own game events and commands. Take a look at this simple Actionscript code:



You can put as much or as little logic into the Java server side. The java code demonstrates how you would pump the game messages through your java code, giving it a chance to alter what a player can do, what the message contains, who its going to, and of course affect your java game state.

The JAGS 1.4m server has a really cool way of checking for any (optional) java code you may have put on the backend. Just plop as many jagGames.java classes onto the JAGS server, and it will match your AS3 client with the right java resource.

That way, all you have to do is put stuff in the doAction method and you've got a complete server backend. Check out this jagsGame.java that is in the public_ftp.login.v1_1 folder:



All the code can be easily ran without installing anything, and then can be downloaded as full projects with source code when you want to get into it.

Just visit fireleg.com and look at the Login 1.1 links.

Thursday, April 24, 2008

Possible AI game

I can't release the details yet, but JagsM may be used for an AI game being developed by a university.

They are going to put together the single player version and I'll go back in and connect it for multiplayer.

This will be quite exciting. I'm sure I'm not giving away too many details if I mention that the game takes human input and creates a knowledge base.

Tank has primitive bullets

The tank demo now has bullets. So what, you can't aim them, and they only collide with the ground, but hey, they're bullets.

Yep, and I believe I even have code that introduces an example constraint on how to keep the tanks from ever leaning more than 45 degrees in APE.

Sorry the JagsM server was down for 27 days. My virtual host restored an old backup and which took my java process down, probably because I had messed around with my CentOS linux kernal and didn't know what I was doing.

It's back up now, better than ever.

Tuesday, February 12, 2008

TankAPE 1.1 Working!

Heck yeah! Multiplayer APE physics worlds unified via the JAGS 1.4m server.

Check out the TankAPE demo (link is on front page of fireleg.com).

I learned a whole lot about IExternalizable, and then I learned I didn't need to know squat about it. I rewrote the whole APE physics engine so you could serialize any particle across the net.

What I didn't realize was that the particles would be very large to send and they would cause weird problems upon receiving them (like APE would duplicate them upon creation because they do stuff with the engine).

Anyway, I then dropped back to plan B, and that worked way better. Plan B was to send just the x,y and velocity data per update, and only send updates when keystrokes happened.

This reduced the data size from 3000 bytes to about 100 bytes. And to think I was going to send 3000 bytes per tank 24 times per second! Ha! Now I send 100 byte packets when someone changes direction or every 2 seconds per tank just to keep everything synced up.

Have fun with it.

Monday, February 4, 2008

FAQ Running Java Server 1.4 and 1.4m

Here's an example email that I have been getting, so I just wanted to share a higher level recap of how you can run the client/server code.

On Sun, 3 Feb 2008 16:15:54 -0430, xxx xxxxxx wrote
> Hello,
>
> I have downloaded your client/server game at fireleg.com
> I know how to import the Flex project and run it. But I have no idea how to even start with the Java project. I am a newbie at Java. I have downloade NetBeans and I plan to start doing some serious work on it, specially because I need to create games like the want you have made freely available (superb thanks by the way).
>
> So how do I setup the Java project? Also if you can spare the time, what are all of those folders inside the server package? like
>
  • /build
  • /dist
  • /nbproject
  • /src
  • /test
  • /ultraedit32
and the build.xml and manifest.mf?
>
> Please can you explain all of these to me? How to setup the project in Java? and what are those listed items folders for?
>
> Thanks and appreciated.

Jorge,

Thanks for the compliments - that always fuels my release schedule!

I just finished writing a blog on installing the Java portion (the JAGS1.4m server), as several people have been asking.
See http://flexjavagames.blogspot.com/2008/02/jags-14m-source-available.html

Also, I've got the 1.4m server running on fireleg.com:82 (that's port 82 instead of port 81).

So, you can either
1) point to my running server for your tests.
2) double click the jar file mentioned in the blog (for a local test environment)
3) compile and install the server on your own local or public machine
4) point your actionscript to fireleg, and email me some java backend code.

I offer option #1 as the most convenient way for people to make their games live to the world, no charge.
Option #2 is the best for a quick test, especially for games that do almost everything on client-to-client.
Option #3 is great if you are going to do anything server-side.

Option #4 is already a reality, which is to compile a java class that implements IGame and I'll put it up on the fireleg server for you. This option will soon be available without my help, when I open up the right FTP server for everyone.

As far as your question about those wacky looking files, those are generated and maintained by Netbeans and will get written over each time you compile.

/src is what to look inside of to understand JAGS.
/build is where you'll see the complied classes - pretty much can ignore unless you need to copy them.
/dist is where you'll find the runnable jar file (you can double click it and start a local JAGS server)
Note: if you have taken the time to get the server compiling, you'll find starting/stopping from
Netbeans much better, as you will see the log output, can set breakpoints, etc.

Also, that code you have is JAGS 1.4, which is correct if you are going over the pong 1.4 demo.
I'll be getting some 1.4m actionscript client examples out soon as well - that java server is written a little cleaner, but still has many common features with JAGS 1.4.

-Travis

Friday, February 1, 2008

JAGS 1.4m Source Available

Easy binary way
If you just want to start testing my latest game server, the easiest way is to run a local copy. Download the executable jar and double click it.

(In Windows) all you will see is a javaw process running like so:


Ways to see the source


If you are just curious
Poke around the 1.4m server or the client code.

Easiest compilable source
These are the major releases, and will allow you to set breakpoints and follow along. If you are new to Java, pick this route before diving deeper.

Just download my zip files of the ready made projects at fireleg.com

Getting the latest source
If you are familiar with Java and want to keep up with the latest builds, I will show you how to download the source from the google repository into a working project.

Trust me, this setup isn't one of those configuration nightmares, it's just a couple of steps that I document very thoroughly so you can see exactly what I did. Expert users can breeze through this in minutes.

Install Subversion (SVN)
First, let's go get Subversion (aka svn). Download from this link on this page http://downloads.open.collab.net/collabnet-subversion.html



Just double click the download -- the installer does a really nice job of adding 'svn' to your command line.



Now you have two main options for getting the source. The first is to use an IDE like Netbeans 6.0 (or any other IDE) and pull a copy of the project visually. The other way is to just use 'svn' on the command line. I'll go over the svn command line way first, then get into the visual way.

Either way, the google repository page is here http://code.google.com/p/fireleg/source/checkout.

Mainly this page lets you know that the svn command to pull the whole trunk is:
svn checkout http://fireleg.googlecode.com/svn/trunk/

So, to use the command line svn do this:
Start -> Run -> cmd



Type a DOS prompt command ('cmd') like so:


Test that svn works by typing "svn --version" (without the quotes) like this:


From that command prompt, navigate using 'cd' (change directory) command to the main folder that will store the source code.

Then just type:
svn checkout http://fireleg.googlecode.com/svn/trunk/jags_server1.4m/ and it will download all the source code.

Netbeans 6.0 IDE

Once you have installed subversion, you can follow along this path to visually pull the project. You may want to restart Netbeans since you just installed subversion.

In Netbeans, go to the Versioning -> Subversion -> Checkout menu.


The first time you try this, Netbeans will ask where subversion is installed. Just browse to the folder you put subversion in. Mine looks like this (I shortened the install name and picked my own folder):


Now fill out what svn repository you want to pull from:


Leave the user / password blank so you can pull anonymously. This just means you won't be able to check code back in, but you can always mail me your code suggestions or ask to get write access from me (email travis_somerville2000 ~at~ yahoo.com).

Next, tell it what folders you want to check out. Browse and select just the jags_server1.4m folder like so:


Your screen should look like this (or something similar):


Now you should see a fully working project called "jags_server1.4m". I recommend making it your main project before hitting run, just so you know it's running the right project.

To make it the main project, right click the project like this:


We're so close! Just run the thing and your server is ready for Actionscript 3.0 games!

Hit the run button.

When you see the statement "listening on port 81" in the Netbeans Output window, you know it's ready.


Pat yourself on the back! Set breakpoints, go crazy.
The client code
From here, just get the Actionscript client going (listed above) and make contact with the server.

As mentioned above, the source for the client code is here .

In another post, I will detail how to talk to the server from the client's perspective. For now, I'd better go eat some dinner.

Wednesday, January 30, 2008

APE Google Blog

I'm always scrambling around for this link to the blog site of APE Physics engine.
http://groups.google.com/group/ape-general

JAGs 1.4m coming soon!

Eureka! I've done a lot since last post.

I'm close to releasing an alpha JAGS 1.4m.
The 'm' stands for multi game. This means one JAGs server will search an FTP directory, load up all those java games and connect the client to the correct backend game space.

For instance, I can set up an FTP folder and you will be able to upload your java game right along with mine.

This will be fantastic for testing, as I can have my own games going and so can you -- even ones that need java resources on the backend.

And if your game doesn't need backend java resources, JAGs 1.4m will still give you a virtual game space based on your whatever you want to call it in your Actionscript call.

Of course, groups are still supported within your game space. This allows you to further refine who everyone is playing with.

I've also improved the Actionscript client library. Now, it's much cleaner and uses events heavily. This means much lighter integration with any game you want to write = easier in general.

---------

The example I will release soon brings me to my final exciting bit of news: multiplayer physics APE.

Yes, that's right. I successfully sent complete APE "WheelParticle"s across the server from one Actionscript client to another! Yeah.

In this video, you can see two windows running some APE physics. The top window, when refreshed sends its wheel particles to the bottom window. The only way the bottom window gets the WheelParticle is through JAGS.

I hit refresh two times, and you can see where it made a couple of sets of wheels and sent them over the wire.



I'll have to post the code and write up how to make use of the IExternalizable interface so you can go crazy with sending any object you want over the net too.

Just need to sleep a little right now...

Thursday, January 10, 2008

Setting up Java Game Server 1.4

Couple of main points.

Project is ready to be opened in Netbeans 5.5.

Go to Trace.java class and take comments off of this one section.

public final class Trace {

public Trace() {
}

public static void out(String s) {
System.out.println(s);
}


In my production code I had the System.out.println(s); commented out.

Next, realize that once you fire the program off inside Netbeans (or from command line), you have to use Windows Task manager to stop it.

It's not like a regular java program where you can push stop. You'll find it floating around as a 6-8Meg java process in the task manager.

JAGS runs on port 81, so I you try to fire two of them off, or don't notice the other one still running, you'll get a startup message saying address already in use.

Here's a successful startup:


Here's what happens to me all the time when I try and run two of them (bad thing):
java.net.BindException: Address already in use: JVM_Bind



Once you've got your server running, and you've modified your Actionscript Client to point to your localhost, fire that Flex program off.

You should see messages talking about starting connections like this:

LISTENING on PORT 81
CONN # 0 :127.0.0.1
CONNECTION STARTED: 0
# Conns:1


And this...

--------------------
SECURITY POLICY SENT
--------------------
IN conn_0c: 1199952686796>no id0.17506256978958845>!server>Hello.
MESSAGE:
TIME: 1199952686843
FROM: no id0.17506256978958845
TO: !server
Action Verb: Hello.

COMMAND not found.Hello.
IN conn_0c: 1199952686859>no id0.17506256978958845>!server>!whats_my_name
MESSAGE:
TIME: 1199952686859
FROM: no id0.17506256978958845
TO: !server
Action Verb: !whats_my_name

OUT: !your_id:conn_0c

IN conn_0c: 1199952686859>no id0.17506256978958845>!server>!auto_match:2
MESSAGE:
TIME: 1199952686859
FROM: no id0.17506256978958845
TO: !server
Action Verb: !auto_match:2

:conn_0c looking for up to 2 total players.
OUT: !name_group:group_0g

OUT: !you_host:conn_0c

NEW GAME: group_0g


Now the arbitrary commands in the Actionscript Client project will start to make a little more sense.

Good luck! I've got to get some sleep...

Wednesday, January 9, 2008

JAGS Google Code Site

Just wanted to keep an easy link back to the google code site.

Go here to download code or see the code project page.
Project page
Download page

My site fireleg.com/jags.html also works, but I think I'll be switching over to the google code to post any new code.

Configuring the Actionscript Client

Once your Flex project is working, you may want to know how to change the most important things in the code.

Look at the Config.as file.

package GameKit
{
public final class Config
{
public static var URL:String = "fireleg.com";
//public static var URL:String = "localhost";
public static var port:uint = 81;

public static var framesPerSecond:int = 24;

// Zero means we synchronize the world every frame.
// 1,2,3 means we count 1,2,3 frames before synching.
// This keeps your world looking smooth while the network
// can chill out a little bit.
public static var dampenNetSyncBy:int = 0;


If you are going to run the Java server on your own machine, then switch out my "fireleg.com" address with your test environment, probably "localhost".

I chose port 81 since it's one of those ports that almost everyone's firewall will allow through, but does not interfere with web servers.

The frames per second can be adjusted as needed for your game's performance.

And finally, you may not want to send a game message for every frame. Your game may be able to do just fine with only sending a particle update every nth frame.

For instance, a checkers game might only need a refresh 4 times per second. If you have framesPerSecond=16, you would set dampenNetSyncBy=4 to achieve your goal.

Now look at MXMLPong.mxml
mx:application mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationcomplete="onAppComplete();"

This applicationcomplete event is different than many Actionscript examples you'll see. It actually waits until everything is created and avoids some serious errors. Be sure you use that exact function to launch your games framework.

Inside this function, we start the main game loop. Which is the heartbeat of the entire game:
private function onAppComplete():void
{
var framesPerSecond:int = GameKit.Config.framesPerSecond;
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;

game = new GameLoop(framesPerSecond, this);
This causes us to dive down into the GameLoop.as:

The MXMLPong file created the GameLoop object, which you can see is hungry for a sprite to display the game in.

 // sprite is the main container to display the game in
public function GameLoop(framesPerSecond:uint, sprite:Sprite) {
var refreshMillis:uint = 1000/framesPerSecond;


This function then calls the init function, which has one very important line of code:

gameTimer = new Timer(refreshMillis,0);
gameTimer.addEventListener(TimerEvent.TIMER, myLoop);


This kicks off the whole game at whatever frames per second you specified earlier, and will constantly call the myLoop() function.

Looking at myLoop(), you will see a whole checklist of things it tries to do again and again.

For instance, the first thing it does is check that a connection with the game server is made.

public function myLoop(timer:TimerEvent):void {
// this is that warmup time from the message sent above
if (!gameServer.connected || gameServer.msgCount < 1) {
trace("waiting for connection or first response...");
return;
}


You may think it's strange to keep "return"ing out of this function, but don't worry, it will be called many times until a connection is made.

Read through the rest of this function and you'll be on your way to understanding some of the code.

World.as contains the collision stuff.

Particle.as determines how the physical universe works in your game.

Commands.as is where you have to add how the network will pack/unpack the objects. It's a little ugly looking and you may just want to skip down to this part of the code:
 if (command != null && command.length > 1) {
if (command[0] == "place") { ...


Even then, my method requires hard-coded parsing of each element. I'm sure you may be able to improve this part of the code, but it's a very basic approach.

NetSynchronizer.as isn't used. I was probably thinking of making a generic way to avoid all the ugly parsing in commands.as. Ideally, there is probably a simple Flex way to package up any object.

The thing is, I want to be able to send a package with a header plus that AMF or whatever object. Obviously I just need a little more knowledge here so I can make use of the full Actionscript power.

NetworkConnection.as is super important. It takes care of the arbitrary protocol that I invented to speak with the Java server.

You will see all kinds of strange commands in there to join a group, send a message to your group or to everyone. This class is worth reading carefully once you're feeling good about the project.

You can see what's being sent back and forth by binding to these variables.

[Bindable] public var lastMessageIn:String; // from Server
[Bindable] public var lastMessageOut:String; // To Server


You may have noticed in the MXMLPong.mxml I put some text objects at the bottom of the screen to show you what is being said through NetworkConnection.as.

For those of you new to binding in Actionscript 3.0, just put something like this on your page:

<mx:Text x="315" y="482" text="{game.gameServer.lastMessageOut}" id="last_sent">
<mx:Text x="315" y="482" text="{game.gameServer.lastMessageIn}" id="last_in">

Creating the Flex Project

After unpacking the jags_client1.4.rar into normal folders, open up Flex 2.0 IDE.
Go File > Import > Existing Projects into Workspace.


Browse to the top level folder like so.


Right click > Run Application on MXMLPong.mxml to start the game.
Do this twice (so you have someone to play against).


You should see a game screen something like this.
If so, you've loaded the Actionscript 3.0 Pong client!


Tuesday, January 8, 2008

fireleg.com game server

I just want to get project JAGS (java actionscript game server) on people's radar.

This is a working game server that can teach you the basics of Flash/Flex security, dealing with multiple threads, sending messages from one Actionscript 3.0 program to another through sockets, etc.

The great thing is that you can start using it right away with no java configuration and no flex data services configuration. That's because I pay for a java server that is always up 24/7 and it's available for client to server requests.

For now, I'll just post the Actionscript 3.0 game code, and the java server code here.

To play the pong game browse to fireleg.com and play the pong demo.

Learn what you can from the code, enjoy. Feel free to email me at travis@fireleg.com.