Tutorials/helloworldJsServer

= JavaScript API Tutorial - Server =

In a rush?
If you are in a rush, you can just get the finished gar-file here, which you should place under game/deploy in your Firebase installation. You can also download the finished project here, which contains the source code for what we will do below.

Want to do it properly?
We are keeping the server side of things brief, because we want to focus on the client in this tutorial. You should be able to have the server up in about 10 minutes. Just follow the steps below. If you want more details on the server side of things, you might find this interesting.

1. Install Maven (if you haven't done so) and run: mvn archetype:generate \ -DarchetypeGroupId=com.cubeia.firebase.tools \ -DarchetypeArtifactId=firebase-game-archetype \ -DarchetypeVersion=1.8.0 \ -DarchetypeRepository=http://m2.cubeia.com/nexus/content/groups/public \ -DgameId=1 \ -DgroupId=net.test \ -DartifactId=helloWorldGame \ -Dversion=1.0-SNAPSHOT \ -Dpackage=net.test As the above command pre-populates all data we need, all you've got to do is to hit 'enter' when it asks you if it is correct. Note the "gameId=1" as we're going to use it later.

2. Step into the newly created helloWorldGame directory.

3. Edit  and change the handle(GameData…) method to: @Override public void handle(GameDataAction action, Table table) { /*        * The action contains game data as a byte buffer, * we'll transform it to an array, and then to a string. */       byte[] arr = action.getData.array; String message = new String(arr);

/*        * Create a new action to send the message to all players. * in this case we could actually just re-send the incoming * action as they will be identical, but for clarity, we'll        * create a new action here. */       int tableId = table.getId; int playerId = action.getPlayerId; GameDataAction outAction = new GameDataAction(playerId, tableId); outAction.setData(ByteBuffer.wrap(message.getBytes));

/*        * Now send the action to all players at the table. */       table.getNotifier.notifyAllPlayers(outAction); } If you did it in a Java IDE you probably got all imports right from the start. However, if you used a text editor you also need a few import statement, as so:

package net.test;

import java.nio.ByteBuffer;

import com.cubeia.firebase.api.action.GameDataAction; import com.cubeia.firebase.api.action.GameObjectAction; import com.cubeia.firebase.api.game.GameProcessor; import com.cubeia.firebase.api.game.table.Table;

public class Processor implements GameProcessor {

[...]

4. Still in the same directory, start the server by running. The output should end like this: Name: Client MServer IFace: /0.0.0.0:4123

INFO SystemLogImpl - System [Java HotSpot(TM) 64-Bit Server VM 20.4-b02-402; Mac OS X Mac OS X (x86_64)] INFO SystemLogImpl - Server started [Tue Mar 06 10:10:14 EST 2012] INFO SystemLogImpl - Firebase Server Platform [version: 1.7.0-CE] This means your game is now compiled and you've sucessfully started a Firebase server with it deployed!

6. Now, move on to creating the HTML5 client.