[Cherbot-commit] SF.net SVN: cherbot:[124] trunk/src
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-11-30 19:54:13
|
Revision: 124
http://cherbot.svn.sourceforge.net/cherbot/?rev=124&view=rev
Author: christianhujer
Date: 2008-11-30 19:54:09 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Clarified and improved code about channels.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java
trunk/src/prj/net/sf/cherbot/connection/Channel.java
trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java
trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java
Modified: trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java 2008-01-19 18:33:12 UTC (rev 123)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractCFConnection.java 2008-11-30 19:54:09 UTC (rev 124)
@@ -17,8 +17,7 @@
import net.sf.japi.io.args.Option;
import net.sf.japi.io.args.OptionType;
-/**
- * Common base class for Connections that use Crossfire-style protocols such as Angelion or Daimonin and of course Crossfire itself.
+/** Common base class for Connections that use Crossfire-style protocols such as Angelion or Daimonin and of course Crossfire itself.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public abstract class AbstractCFConnection extends AbstractConnection {
Modified: trunk/src/prj/net/sf/cherbot/connection/Channel.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/Channel.java 2008-01-19 18:33:12 UTC (rev 123)
+++ trunk/src/prj/net/sf/cherbot/connection/Channel.java 2008-11-30 19:54:09 UTC (rev 124)
@@ -9,7 +9,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-/** A Channel uniquely identifies a protocol (type) / server / channel combination.
+/** A Channel uniquely identifies a protocol (type) / server / channel combination to which text messages can be sent.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public interface Channel {
Modified: trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java 2008-01-19 18:33:12 UTC (rev 123)
+++ trunk/src/prj/net/sf/cherbot/connection/IRCConnection.java 2008-11-30 19:54:09 UTC (rev 124)
@@ -53,7 +53,10 @@
/** The BufferedReader to read from. */
@Nullable private BufferedReader in;
- /** The channels of this connection. */
+ /** The channels of this connection.
+ * This is not necessarily all channels that the server has.
+ * It's just the channels that are somehow important to CherBot.
+ */
private Map<String, IRCChannel> channels = new HashMap<String, IRCChannel>();
/** Creates an IRCConnection. */
@@ -181,13 +184,8 @@
*/
@Patterns({"^:([^!]+)!([^ ]+) PRIVMSG ([^ ]+) :(.*)$"})
public void processPRIVMSG(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channelName, @NotNull final String message) {
- Channel channel = channels.get(channelName);
- if (channel == null) {
- // TODO: Create channel on demand.
- } else {
- // channel.send(message); // echo
- }
- System.out.println(channel);
+ final Channel channel = getOrCreateChannel(channelName);
+ // TODO:cher:Process message.
}
/** Joins an IRC channel.
@@ -200,12 +198,7 @@
assert out != null;
out.println("JOIN " + channelName);
out.flush();
- IRCChannel channel = channels.get(channelName);
- if (channels.get(channelName) == null) {
- channel = new IRCChannel(channelName);
- channels.put(channelName, channel);
- }
- return channel;
+ return getOrCreateChannel(channelName);
}
/** Sets the username to use for connecting to the IRC server.
@@ -243,6 +236,20 @@
this.nickPassword = nickPassword;
}
+ /** Gets a channel.
+ * If the channel did not already exist, it is created and stored.
+ * @param channelName Name of the channel to get or create.
+ * @return Channel
+ */
+ private Channel getOrCreateChannel(@NotNull final String channelName) {
+ IRCChannel channel = channels.get(channelName);
+ if (channel == null) {
+ channel = new IRCChannel(channelName);
+ channels.put(channelName, channel);
+ }
+ return channel;
+ }
+
/** Represents a Channel on IRC.
* This can be used for both, real channels (whith channel names starting with '#') and direct communication channels with nicks.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
Modified: trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java
===================================================================
--- trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java 2008-01-19 18:33:12 UTC (rev 123)
+++ trunk/src/tst/test/net/sf/cherbot/metaserver/MetaServerEntryTest.java 2008-11-30 19:54:09 UTC (rev 124)
@@ -43,4 +43,21 @@
Assert.assertEquals("unknown4 must be stored.", "04", testling.getUnknown4());
}
+ /** Tests that {@link MetaServerEntry#parse(String)} throws an exception if the supplied string is not a metaserver entry. */
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseException() {
+ MetaServerEntry.parse("192.168.0.1_177|localhost|20|0.9.7|My own Daimonin server.|02|03|04");
+ }
+
+ /** Tests that {@link MetaServerEntry#toString()} returns reasonable data. */
+ @Test
+ public void testToString() {
+ final MetaServerEntry testling = MetaServerEntry.parse("192.168.0.1|177|localhost|20|0.9.7|My own Daimonin server.|02|03|04");
+ final String string = testling.toString();
+ Assert.assertTrue(string.contains(testling.getHostname()));
+ Assert.assertTrue(string.contains(testling.getVersion()));
+ Assert.assertTrue(string.contains(Integer.toString(testling.getPlayerCount())));
+ Assert.assertTrue(string.contains(testling.getDescription()));
+ }
+
} // class MetaServerEntryTest
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|