Marauroa Chat Tutorial: Difference between revisions
Content deleted Content added
imported>Kymara →TODO: use template for todo not just the word todo |
imported>Terin |
||
Line 37:
Implementing IRPRuleProcessor will require more code, as we must implement all the methods of the interface. We will start with the following stub
<!-- Updated due to refactoring database access in Marauroa. -->
<!-- Please, see details here http://stendhal.game-host.org/wiki/index.php/Refactoring_Database_Access_in_Marauroa. -->
<pre>
import java.util.List;
Line 48 ⟶ 50:
import marauroa.common.game.RPObject;
import marauroa.common.game.Result;
import marauroa.server.game.db.
import marauroa.server.game.db.
import marauroa.server.game.db.
import marauroa.server.db.TransactionPool;
import marauroa.server.db.DBTransaction;
import marauroa.server.game.rp.IRPRuleProcessor;
import marauroa.server.game.rp.RPServerManager;
Line 115 ⟶ 119:
public AccountResult createAccount(String username, String password, String email) {
TransactionPool transactionPool = TransactionPool.get();
AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);
try {
▲ if (database.hasPlayer(trans, username)) {
return new AccountResult(Result.FAILED_PLAYER_EXISTS, username);
}
return new AccountResult(Result.OK_CREATED, username);
} catch (SQLException e1) {
▲ trans.rollback();
return new AccountResult(Result.FAILED_EXCEPTION, username);
}
Line 137:
public CharacterResult createCharacter(String username, String character, RPObject template) {
TransactionPool transactionPool = TransactionPool.get();
CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
try {
▲ if (database.hasCharacter(trans, username, character)) {
return new CharacterResult(Result.FAILED_PLAYER_EXISTS, character, template);
}
Line 149 ⟶ 148:
object.put("nick", character);
zone.assignRPObjectID(object);
return new CharacterResult(Result.OK_CREATED, character, object);
} catch (Exception e1) {
▲ trans.rollback();
return new CharacterResult(Result.FAILED_EXCEPTION, character, template);
}
Line 175 ⟶ 171:
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.
=== Deployment ===
So, we have two files, World.java and Rule.java, which contain the classes mentioned above.
| |||