Marauroa Chat Tutorial/Text Client: Difference between revisions
Content deleted Content added
imported>Hendrik Brummermann m header and footer |
imported>Fjacob Cleaned up java code to adhere to the java coding conventions, changed some variable names to be more explicit. |
||
| (25 intermediate revisions by 2 users not shown) | |||
Line 1:
{{Navigation for Marauroa Top|Using}}
{{Navigation for Marauroa Users}}
{{Marauroa Chat Tutorial}}
Line 9:
<source lang="java">
import java.util.Map;
import java.util.HashMap;
import java.util.
import java.
import marauroa.client.ClientFramework;
import marauroa.client.net.IPerceptionListener;
import marauroa.client.net.PerceptionHandler;
import marauroa.common.game.RPAction;
import marauroa.common.game.RPObject;
import marauroa.common.net.message.MessageS2CPerception;
import marauroa.common.net.message.TransferContent;
Line 26 ⟶ 23:
public class Client extends ClientFramework {
private PerceptionHandler handler;
private String[]
private
public static Client get() {
Line 40 ⟶ 37:
protected Client() {
super("log4j.properties");
handler = new PerceptionHandler(new PerceptionListener());
}
public String[]
return
}
public String popQuote() {
if (quotes.isEmpty()) {
return null;
}
}
public void
RPAction action;
action = new RPAction();
Line 65 ⟶ 60:
}
@Override
protected void onPerception(MessageS2CPerception message) {
try {
handler.apply(message,
} catch (java.lang.Exception e) {
// Something weird happened while applying perception
Line 73 ⟶ 69:
}
@Override
protected List<TransferContent> onTransferREQ(List<TransferContent> items) {
return items;
}
@Override
protected void onTransfer(List<TransferContent> items) {
}
@Override
protected void onAvailableCharacters(String[] characters) {
}
@Override
protected void onServerInfo(String[] info) {
for (String s : info) {
Line 90:
}
@Override
protected String getGameName() {
return "Chat";
}
@Override
protected String getVersionNumber() {
return "0.5";
}
@Override
protected void onPreviousLogins(List<String> previousLogins) {
}
class PerceptionListener implements IPerceptionListener {
@Override
public boolean onAdded(RPObject object) {
if (object.has("text")) {
Line 109 ⟶ 113:
}
@Override
public boolean onModifiedAdded(RPObject object, RPObject changes) {
return false;
}
@Override
public boolean onModifiedDeleted(RPObject object, RPObject changes) {
return false;
}
@Override
public boolean onDeleted(RPObject object) {
return false;
}
@Override
public boolean onMyRPObject(RPObject added, RPObject deleted) {
return false;
}
@Override
public void onSynced() {
}
@Override
public void onUnsynced() {
}
@Override
public void onException(Exception e,
e.printStackTrace();
System.exit(-1);
}
@Override
public boolean onClear() {
return false;
}
@Override
public void onPerceptionBegin(byte type, int timestamp) {
}
@Override
public void onPerceptionEnd(byte type, int timestamp) {
}
Line 161 ⟶ 175:
Marauroa frameword provides the main method for server, so that you don't need to care about execution loop. It is not true for server, so we will also need to implement the main module of our client. Here is a very easy solution
<source lang="java">
import marauroa.common.game.RPObject;
public class Test {
public static void main(String[] args) {
boolean
Client
try {
if (args.length == 3) {
}
if (
RPObject character = new RPObject();
}
} catch (Exception e) {
}
int i = 0;
while (
i++
if (i % 100 == 50) {
}
String s =
while (s != null) {
System.out.println(s);
s =
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
Line 224 ⟶ 233:
java -cp marauroa.jar;log4j.jar;. Test login password
</pre>
Again, on Linux & MacOSX, all ";" have to be replaced with ":".
Don't forget to replace login and password with the actual ones. To create a new account just add a third command-line parameter (that should be an email, but no validation at the moment).
Line 232 ⟶ 242:
>java -cp marauroa.jar;log4j.jar;. Test test1 test1
Cannot find log4j.properties in classpath. Using default properties.
*test1* : test50
*test1* : test150
*test1* : test250
...
</pre>
Note the message about log4j.properties: you can create that file in order to configure the Log4J usage inside the Marauroa framework.
== Next Steps ==
In the next section of this tutorial, we will write a '''[[Marauroa Chat Tutorial/Swing Client|Swing client]]''' with a graphical user interface.
[[Category:Marauroa]]
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Chat Tutorial|Tutorial]] | [[Marauroa Chat Tutorial/Text Client|Text Client]]}}
| |||