Chapter 1 – Getting Started

Creating New Players with J2EE

 

Now that you have downloaded the J2SD 1.4 and J2EE 1.3, you are ready to begin the game.  Every game needs players, so we will begin by designing a EJB backend and a web frontend for players to create new characters.

 

The Web Interface

 

When you start up the mud successfully, you should see the following welcome screen on http://localhost/mud.

 

 

The “Create a Character” link is a JSP page that will create a Being entity depending on what you enter.

The Create JSP

The create JSP retrieves parameters from the request and uses those parameters to populate the database.  The first line of the JSP imports the necessary Java files into the generated JSP code.

 

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

<%@ page import="com.owlmountain.mud.GameException,com.owlmountain.mud.ejb.*,javax.servlet.http.*,java.util.*" session="true"%>

 

The form values are retrieved from the request.

 

<%

    String name = request.getParameter( "name" );

    String password = request.getParameter( "password" );

    String confirm = request.getParameter( "confirm" );

    String sex = request.getParameter( "sex" );

    String shortDescription = request.getParameter( "shortdescription" );

    String longDescription = request.getParameter( "longdescription" );

    String race = request.getParameter( "race" );

    String profession = request.getParameter( "profession" );

 

In J2EE, it is considered good practice to access all EntityBeans through a SessionBean.  This is commonly called a session façade.  Using a session façade creates a frame for the transactional context.

 

    String createResult =  "INVALID PARAMETER";

    boolean error = false;

    if ( password.equals( confirm ) ) {

        try {

            PlayerSessionHome home = new EJBFactory().lookupPlayerSessionHome();

            PlayerSession facade =

                new EJBFactory().lookupPlayerSessionHome().create();

            createResult = facade.createCharacter( name, password, sex,

                        shortDescription, longDescription, race,

                        profession );

 

        }

        catch ( GameException e ) {

            error = true;

            createResult = e.getMessage();

        }

        catch ( Exception e ) {

            error = true;

            e.printStackTrace();

        }

    }

 

%>

 

Checking your Results

When you successfully create a character, the database should contain the data you entered through the form.

 

 

Running the Mud Server

The Mud server runs as a stand-alone process, listening to a designated socket using the new Socket I/O in Java.

 

export JAVA_HOME=D:/java/jdk1.4

export PATH="//D/java/jdk1.4/bin:$PATH"

export CLASSPATH="D:/owlmountain/mud/build/mud-ejb.jar;D:/owlmountain/software/log4j/dist/lib/log4j.jar"

export CLASSPATH="$CLASSPATH;D:/orion/orion/orion.jar;D:/orion/orion/ejb.jar;D:/orion/orion/jndi.jar"

export CLASSPATH="$CLASSPATH;D:/orion/orion/jta.jar"

java -version

java com.owlmountain.mud.server.Main

 

The mud server should be restarted whenever the EJB server is restarted.  It runs a separate PlayerSession for each player, and runs its own scheduled events through the ServerSession.