Marauroa Chat Tutorial: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Terin
imported>Kymara
add syntax highlighting. it is teh awesome
Line 10: Line 10:


We will start with the following implementation of the RPWorld
We will start with the following implementation of the RPWorld
<source lang="java">
<pre>
import marauroa.server.game.rp.RPWorld;
import marauroa.server.game.rp.RPWorld;
import marauroa.server.game.rp.MarauroaRPZone;
import marauroa.server.game.rp.MarauroaRPZone;
Line 30: Line 30:
}
}
}
}
</pre>
</source>


Don't forget to always implement the static get method which is used by Marauroa framework to retrieve an instance of your class.
Don't forget to always implement the static get method which is used by Marauroa framework to retrieve an instance of your class.
Line 39: Line 39:
<!-- Updated due to refactoring database access in Marauroa. -->
<!-- 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. -->
<!-- Please, see details here http://stendhal.game-host.org/wiki/index.php/Refactoring_Database_Access_in_Marauroa. -->
<source lang="java">
<pre>
import java.util.List;
import java.util.List;
import java.sql.SQLException;
import java.sql.SQLException;
Line 158: Line 158:
}
}
}
}
</pre>
</source>


We again implement the static get() method which is used by Marauroa to retrieve the RuleProcessor instance.
We again implement the static get() method which is used by Marauroa to retrieve the RuleProcessor instance.
Line 202: Line 202:
=== Code ===
=== Code ===
In order to create a client using Marauroa frameword you should extend the marauroa.client.ClientFramework class with your logic. Here is the source code for the chat client
In order to create a client using Marauroa frameword you should extend the marauroa.client.ClientFramework class with your logic. Here is the source code for the chat client
<source lang="java">
<pre>
import java.util.Map;
import java.util.Map;
import java.util.List;
import java.util.List;
Line 342: Line 342:
}
}
}
}
</pre>
</source>


This is mostly a boilerplate code. We claim that we are "Chat" client, version "0.5" As you remember, our server will accept any "Chat" client, without version restrictions.
This is mostly a boilerplate code. We claim that we are "Chat" client, version "0.5" As you remember, our server will accept any "Chat" client, without version restrictions.
Line 355: Line 355:


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
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">
<pre>
import java.io.IOException;
import java.io.IOException;
import java.lang.Thread;
import java.lang.Thread;
Line 401: Line 401:
}
}
}
}
</pre>
</source>


Our main method does a couple of things. First of all, we create a new account if three command-line arguments are provided (login, password, email). Otherwise we just login with login and password specified.
Our main method does a couple of things. First of all, we create a new account if three command-line arguments are provided (login, password, email). Otherwise we just login with login and password specified.
Line 437: Line 437:
=== Code ===
=== Code ===
The design of our Client class allows us to easily use it in something more complex then Test class above. Here is the example of a simple Swing application that uses Client as a communication tool
The design of our Client class allows us to easily use it in something more complex then Test class above. Here is the example of a simple Swing application that uses Client as a communication tool
<source lang="java">
<pre>
import javax.swing.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.*;
Line 552: Line 552:
}
}
}
}
</pre>
</source>


To create the layout of the elements NetBeans was used, but we concentrate just on the source code here.
To create the layout of the elements NetBeans was used, but we concentrate just on the source code here.
Line 561: Line 561:


The only thing left for the Swing client now is a main method. Here is the source code
The only thing left for the Swing client now is a main method. Here is the source code
<source lang="java">
<pre>
final class Chat {
final class Chat {
private Chat() {}
private Chat() {}
Line 569: Line 569:
}
}
}
}
</pre>
</source>
=== Deployment ===
=== Deployment ===
You still use the same command for compilation
You still use the same command for compilation