Marauroa Chat Tutorial/Server: Difference between revisions
Content deleted Content added
imported>Hendrik Brummermann splitted Marauroa Tutorial |
imported>Hendrik Brummermann added missing call to world.initialize() as reported by maxgmer |
||
| (36 intermediate revisions by 2 users not shown) | |||
Line 1:
{{Navigation for Marauroa Top|Using}}
{{Navigation for Marauroa Users}}
{{Marauroa Chat Tutorial}}
In order to create a Marauroa-based game server you must provide at least implementation of the marauroa.server.game.rp.IRPRuleProcessor interface and a class for zone management, i.e. marauroa.server.game.rp.RPWorld descendant. You can use the marauroa.server.game.rp.RPWorld itself, but it doesn't provide you with any RPZones, while you will almost certainly need at least one.
Line 15 ⟶ 18:
if (instance == null) {
instance = new World();
instance.initialize();
}
return instance;
}
@Override
public void onInit() {
super.onInit();
Line 35 ⟶ 40:
<!-- Please, see details here http://stendhal.game-host.org/wiki/index.php/Refactoring_Database_Access_in_Marauroa. -->
<source lang="java">
import java.sql.SQLException;
Line 68 ⟶ 72:
}
@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
onExit(
}
@Override
public synchronized boolean onExit(RPObject
world.remove(
return true;
}
@Override
public synchronized boolean onInit(RPObject
IRPZone zone = world.getRPZone(new IRPZone.ID("lobby"));
zone.add(
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) {
if (action.get("type").equals("chat")) {
RPObject
IRPZone zone = world.getRPZone(new IRPZone.ID(caster.getID().getZoneID()));
zone.assignRPObjectID(
zone.add(
}
}
@Override
public AccountResult createAccount(String username, String password, String email) {
TransactionPool transactionPool = TransactionPool.get();
Line 131 ⟶ 145:
}
@Override
public CharacterResult createCharacter(String username, String
TransactionPool transactionPool = TransactionPool.get();
DBTransaction trans = transactionPool.beginWork();
CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
try {
if (characterDAO.hasCharacter(trans, username,
return new CharacterResult(Result.
}
IRPZone zone = world.getRPZone(new IRPZone.ID("lobby"));
RPObject
zone.assignRPObjectID(
characterDAO.addCharacter(trans, username,
transactionPool.commit(trans);
return new CharacterResult(Result.OK_CREATED,
} catch (Exception e1) {
transactionPool.rollback(trans);
return new CharacterResult(Result.FAILED_EXCEPTION,
}
}
Line 167 ⟶ 182:
Functions for creating account and character should find out whether to create a new account/character or not. In our case we just always do it (not for duplicates of course). Result of this actions is instantly written to the database. Note that client can provide a template for the avatar object (an RPObject associated with the character). It is up to you how to use it while constructing the actual avatar object. We take what client provides, add a "nick" property (the same as character name) and use the resulting one as an avatar object.
So, we have two files, World.java and Rule.java, which contain the classes mentioned above.
<pre>
javac -cp marauroa.jar;log4j.jar;. *.java
</pre>
On Linux and MacOSX, you have to replace the ";" with ":".
<pre>
javac -cp marauroa.jar:log4j.jar:. *.java
</pre>
Line 203 ⟶ 222:
<pre>
java -cp marauroa.jar;h2.jar;log4j.jar;. marauroa.server.marauroad -c server.ini
</pre>
Again, on Linux and MacOSX, you have to replace the ";" with ":".
<pre>
java -cp marauroa.jar:h2.jar:log4j.jar:. marauroa.server.marauroad -c server.ini
</pre>
Of course, make sure that all the jars are in the current directory. Marauroa framework will parse server.ini file, find and load your classes World and Rule.
== Next Steps ==
In the next section of this tutorial, we will write the '''[[Marauroa Chat Tutorial/Text Client|client]]''' which will connect to our server.
[[Category:Marauroa]]
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Chat Tutorial|Tutorial]] | [[Marauroa Chat Tutorial/Server|Server]]}}
| |||