Developing TicToe HTML5/Preparing the Server

Revision as of 18:19, 3 January 2012 by imported>Hendrik Brummermann

Now it is time to get a basic (empty) server up and running.

server.ini

Marauroa is configured using a server.ini file. It tells the framework, how it can access its database and contains further information about the game. For now, just copy and paste the following code and save it as server.ini in your project root folder.

# Configure database using the serverless H2 engine
database_adapter=marauroa.server.db.adapter.H2DatabaseAdapter
jdbc_url=jdbc:h2:~/tictoe/database/h2db;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE
jdbc_class=org.h2.Driver

# TCP port for traditional clients
tcp_port=32170

# Web port
http_port=8080

# The length of the server game loop in milliseconds
turn_length=300

# Name of our game
server_typeGame=tictoe
server_name=TicToe

HTML5 just use https for secure communications and that is handled by the webserver. But for traditional clients, Marauroa has to do the encryption. Therefore we need to generate a key pair with the command: marauroa.tools.GenerateKeys. It will ask for the key length and then output 3 lines that we append to the server.ini.

# Encryption key
n = 900370704947823124855781868486098993883139326458426419821694524929194085970977109550540519463413920574303896162026330535842004647058075091756193089826466644581
e = 15
d = 120049427326376416647437582464813199184418576861123522642892603323892544796130273271757994671295519024634180073146730306761515863656819847545998907329992154007

Important: Do not use these example keys but create your own pair.

Starting the server

Make sure that marauroa.jar, and its dependencies are on the classpath. Then execute the class marauroa.server.net.web.WebSocketServer.

If all goes well, you will be greeted by some status message. The last one will be:

INFO  [main      ] marauroad                (123 ) - marauroa is up and running... (startup time: 3.1 s)

Testing client/server communication

To test the setup, we open a web browser at http://localhost:8080/index.html.

This will just result in a green screen, but we can manually connect to the server by using the Firebug console:

  • marauroa.clientFramework.connect(null, null);
    • connected
  • marauroa.clientFramework.createAccount("testuser", "password", "test@example.com");
    • Account "testuser" created successfully.
  • marauroa.clientFramework.login("testuser", "password");
    • Previous Logins []
    • ServerInfo ["tictoe", "TicToe"]
    • onAvailableCharacterDetails: Object {}
    • Character "testuser" created successfully.
    • onAvailableCharacterDetails: Object { testuser={...}}

These three commands will connect to the server, create a new account "testuser" and login. There is a default handler for the onAvailableCharacterDetails event, that will automatically create a character, if the account does not have any.