Chat Tutorial in NetBeans/Server: Difference between revisions
Content deleted Content added
imported>SimonSmall Some corrections |
imported>Hendrik Brummermann →World.java: added missing call to world.initialize() as reported by maxgmer |
||
| (38 intermediate revisions by 2 users not shown) | |||
Line 1:
= Introduction =
= NetBeans Project (server) =
Start the NetBeans IDE. Close all open projects.
Click '''New Project''', choose '''Java''' and '''Java Class Library'''. Click '''Next''', then give the '''Project Name''' as '''server'''. Change the '''Project Location''' to '''DEVPATH\DevChat''' (DEVPATH, see above); the '''Project Folder''' is shown as '''DEVPATH\DevChat\server''' with DEVPATH being your chosen location. Click '''Finish'''.
The empty Project is created in NetBeans. Under the Files tab you will see the directory structure it has also generated; check this using your file explorer.
Create a new directory named '''libs''' (i.e. DEVPATH\libs) so that it can be used by the rest of the Chat code.
Right click the Libraries branch of the server Project tree, and select Add Project. Make sure you browse to the correct file location and select the marauroa project that you created earlier. This will include your marauroa library that you built.▼
== Configuration choices ==
There are a few choices to be made about the configuration of our server. They are covered below, so make sure that you are reading the correct instructions.
* This example is using the h2 database to store data. This uses a single file for storing the data, and does not need login credentials. You need to decide where the database file will be stored. This configuration is referred to as an embedded h2 database. It is further restricted by being single user access, meaning the server becomes that single user and you cannot access the database when the server is running.
* MySQL can also be used but this is covered in the [[Chat Tutorial in NetBeans/MySQL]] page; you may need this if there is more to be stored in the database, or if you want a different security model. This will allow the database to be examined when the server is running.
* The server and client code can be written and linked to the Marauroa engine as a jar file or as a NetBeans project if you have the source code. This choice affects the actions you must take.
== Adding the Marauroa library ==
Choose the correct way depending on if you are using the marauroa.jar file, of have created a marauroa project from the source code.
=== Using the Jar file ===
Find the marauror.jar file from the download, and copy it to the '''libs''' directory (created above). Right click the '''Libraries''' branch of the server Project tree, and select '''Add Jar/Folder'''. Browse to the the '''libs''' directory for this project and select the '''marauroa.jar''' file. This will include the marauroa library with no view of the source code.
=== Using the marauroa project ===
▲Right click the '''Libraries''' branch of the server Project tree, and select '''Add Project'''. Make sure you browse to the correct file location and select the marauroa project that you created earlier. This will include your marauroa library that you built, and you can see the source code.
== World.java ==
Right-click on the '''default package''' branch and add a new Java Class. Give the
<source lang="Java">
/*
*▼
*/
package server;
Line 36 ⟶ 53:
public class World extends RPWorld {
private static World instance;
public static World get() {
if (instance == null) {
instance = new World();
instance.initialize()
}
return instance;
}
public void onInit() {
super.onInit();
Line 54 ⟶ 72:
== Rule.java ==
Right-click on the
<source lang="Java">
/*
*
*/
package server;
Line 80 ⟶ 97:
public class Rule implements IRPRuleProcessor {
private static Rule instance;
private World world = World.get();
Line 91 ⟶ 108:
return instance;
}
@Override
public void setContext(RPServerManager rpman) {
manager = rpman;
}
@Override
public boolean checkGameVersion(String game, String version) {
return game.equals("Chat");
}
@Override
public synchronized void onTimeout(RPObject object) {
onExit(object);
}
@Override
public synchronized boolean onExit(RPObject object) {
Line 112 ⟶ 129:
return true;
}
@Override
public synchronized boolean onInit(RPObject object) {
Line 119 ⟶ 136:
return true;
}
@Override
public synchronized void beginTurn() {
}
@Override
public boolean onActionAdd(RPObject caster, RPAction action, List<RPAction> actionList) {
return true;
}
@Override
public synchronized void endTurn() {
}
@Override
public void execute(RPObject caster, RPAction action) {
Line 163 ⟶ 180:
}
}
@Override
public CharacterResult createCharacter(String username, String character, RPObject template) {
Line 191 ⟶ 208:
== Building ==
If there are no errors in the package, select '''Run''',
= Server Configuration =
When the server is started it will read a set of configuration values from the configuration file '''server.ini'''. The first thing we will create are the encryption keys.
== GenerateKeys.java ==▼
=== Using the Jar file ===
▲== GenerateKeys.java ==
Without the source code access to this program is limited using NetBeans. The easiest way is to run the program using a terminal window. Open a command / terminal window in the DEVPATH directory. Type the following lines (for a Windows system):
<pre>
java -classpath libs\marauroa.jar marauroa.tools.GenerateKeys
</pre>
For a UNIX / Linux system, use / instead of \ after the libs.
As the program runs in the window, accept the suggested value of 512 (i.e. just press Return). This creates the keys and writes them to the screen. Copy the lines into the server.ini file (see below).
=== Using the marauroa project ===
<pre>
run:
# How long should the key be? [512]:
# Using key of 512 bits.
Line 222 ⟶ 249:
</pre>
where there are two long lines of numbers (shown above as 12345...). You need to copy those three number lines, and the comment line above them, for the '''server.ini''' file (see below).
== server.ini ==
In the server Project tree, right click on
Copy the following code into the server.ini window (note that the code below includes the Keys lines; don't copy them). Paste the four lines from the output of GenerateKeys into this file.
<pre>
Line 239 ⟶ 266:
turn_length=300
statistics_filename=server_stats.xml
log4j_url=
# World and RP configuration
Line 265 ⟶ 292:
This is using the h2 database. Configuration of others is possible.
The line starting '''jdbc_url=jdbc:h2:Chat''' gives the location and name of the database. This creates a database named Chat in the current (i.e. server) directory. See here [http://www.h2database.com/html/features.html#database_url] for the technical details.
=== TCP Port ===
The port is given as 5555; the client will try to connect to this port so it should not be changed (unless you change the port in the client; work this one out yourself).
=== Game classes ===
The lines '''world=''' and '''ruleprocessor=''' specify the classes to be used for these features. If you chose different class names above, use those names (and package) here.
=== Game Information ===
Line 279 ⟶ 310:
Although you don't have to provide a Log configuration file, you can if you wish.
Create another empty file, as you did with the '''server.ini''' file, with a name of
<pre>
# Set root
log4j.rootLogger=INFO, Console, File
# Paste all
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%
# Paste all log entries to a daily log file
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=log/server.log
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%
# Set priority to warning messages and above, disabling debug and info messages
log4j.logger.marauroa.server.game.RPServerManager=WARN
</pre>
Line 301 ⟶ 333:
= Completion =
You have created the two class files and compiled them into a java library, and created the server and logfile configuration files. The next step is to create the client files then follow the deployment instructions for preparing and testing your game.
[[Category:NetBeans]]
| |||