cherbot-commit Mailing List for CherBot (Page 2)
Status: Alpha
Brought to you by:
christianhujer
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(39) |
Nov
(1) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
(67) |
Jul
(6) |
Aug
|
Sep
(2) |
Oct
(1) |
Nov
|
Dec
|
| 2008 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(6) |
Dec
(19) |
| 2009 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
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.
|
|
From: <chr...@us...> - 2008-01-19 18:33:21
|
Revision: 123
http://cherbot.svn.sourceforge.net/cherbot/?rev=123&view=rev
Author: christianhujer
Date: 2008-01-19 10:33:12 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
Updated FAQ about Derby.
Modified Paths:
--------------
trunk/FAQ
Modified: trunk/FAQ
===================================================================
--- trunk/FAQ 2008-01-01 18:10:47 UTC (rev 122)
+++ trunk/FAQ 2008-01-19 18:33:12 UTC (rev 123)
@@ -10,3 +10,4 @@
Q: When I try to run CherBot I get java.sql.SQLException: No suitable driver found for jdbc:derby:cherbotdb;create=true
A: You need to have derby.jar on your class path. Try this:
java -cp CherBot.jar:$JAVA_HOME/db/lib/derby.jar net.sf.cherbot.CherBot
+You may have to replace the path to derby.jar to something else on your system if Derby has been installed outside of JAVA_HOME.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-01-01 18:10:49
|
Revision: 122
http://cherbot.svn.sourceforge.net/cherbot/?rev=122&view=rev
Author: christianhujer
Date: 2008-01-01 10:10:47 -0800 (Tue, 01 Jan 2008)
Log Message:
-----------
Added TODO about metaserver support.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/metaserver/package-info.java
Modified: trunk/src/prj/net/sf/cherbot/metaserver/package-info.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/metaserver/package-info.java 2008-01-01 18:07:20 UTC (rev 121)
+++ trunk/src/prj/net/sf/cherbot/metaserver/package-info.java 2008-01-01 18:10:47 UTC (rev 122)
@@ -4,7 +4,9 @@
* See file COPYING in the root directory of this project.
*/
-/** The package net.sf.cherbot.metaserver contains metaserver access.
+/** The package net.sf.cherbot.metaserver contains a framework for metaserver access.
+ * Currently, it supports the Daimonin metaserver.
+ * @todo change to a framework, add support for Crossfire metaserver.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
package net.sf.cherbot.metaserver;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-01-01 18:07:28
|
Revision: 121
http://cherbot.svn.sourceforge.net/cherbot/?rev=121&view=rev
Author: christianhujer
Date: 2008-01-01 10:07:20 -0800 (Tue, 01 Jan 2008)
Log Message:
-----------
Updated IntelliJ IDEA project files.
Modified Paths:
--------------
trunk/cherbot.iml
trunk/cherbot.ipr
Modified: trunk/cherbot.iml
===================================================================
--- trunk/cherbot.iml 2007-10-12 19:06:05 UTC (rev 120)
+++ trunk/cherbot.iml 2008-01-01 18:07:20 UTC (rev 121)
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
- <component name="DependecySynchronizer" />
- <component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" packagePrefix="test" />
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Modified: trunk/cherbot.ipr
===================================================================
--- trunk/cherbot.ipr 2007-10-12 19:06:05 UTC (rev 120)
+++ trunk/cherbot.ipr 2008-01-01 18:07:20 UTC (rev 121)
@@ -6,7 +6,6 @@
<component name="BuildJarProjectSettings">
<option name="BUILD_JARS_ON_MAKE" value="false" />
</component>
- <component name="ClearCase" />
<component name="CodeStyleProjectProfileManger">
<option name="PROJECT_PROFILE" />
<option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
@@ -85,11 +84,12 @@
</wildcardResourcePatterns>
</component>
<component name="CppTools.Loader" warnedAboutFileOutOfSourceRoot="true" />
- <component name="DataSourceManagerImpl" />
<component name="DependenciesAnalyzeManager">
<option name="myForwardDirection" value="false" />
</component>
- <component name="DependencyValidationManager" />
+ <component name="DependencyValidationManager">
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
+ </component>
<component name="EclipseCompilerSettings">
<option name="DEBUGGING_INFO" value="true" />
<option name="GENERATE_NO_WARNINGS" value="true" />
@@ -112,7 +112,6 @@
<option name="OPEN_IN_BROWSER" value="false" />
<option name="OUTPUT_DIRECTORY" />
</component>
- <component name="GUI Designer component loader factory" />
<component name="IdProvider" IDEtalkID="ED349DBC49AC650043B9D99F1B6300AE" />
<component name="InspectionProjectProfileManager">
<option name="PROJECT_PROFILE" value="Project Default" />
@@ -122,24 +121,6 @@
<profile version="1.0" is_locked="false">
<option name="myName" value="Project Default" />
<option name="myLocal" value="false" />
- <used_levels>
- <error>
- <option name="myName" value="ERROR" />
- <option name="myVal" value="400" />
- </error>
- <warning>
- <option name="myName" value="WARNING" />
- <option name="myVal" value="300" />
- </warning>
- <information>
- <option name="myName" value="INFO" />
- <option name="myVal" value="200" />
- </information>
- <server>
- <option name="myName" value="SERVER PROBLEM" />
- <option name="myVal" value="100" />
- </server>
- </used_levels>
<inspection_tool class="InstanceofChain" level="WARNING" enabled="true" />
<inspection_tool class="ClassReferencesSubclass" level="WARNING" enabled="true" />
<inspection_tool class="DeclareCollectionAsInterface" level="WARNING" enabled="true">
@@ -153,7 +134,9 @@
<inspection_tool class="MagicNumber" level="WARNING" enabled="true">
<option name="m_ignoreInHashCode" value="true" />
</inspection_tool>
- <inspection_tool class="OverlyStrongTypeCast" level="WARNING" enabled="true" />
+ <inspection_tool class="OverlyStrongTypeCast" level="WARNING" enabled="true">
+ <option name="ignoreInMatchingInstanceof" value="false" />
+ </inspection_tool>
<inspection_tool class="MethodOnlyUsedFromInnerClass" level="WARNING" enabled="true">
<option name="ignoreMethodsAccessedFromAnonymousClass" value="false" />
</inspection_tool>
@@ -239,7 +222,6 @@
<option name="m_ignorePrimitives" value="false" />
</inspection_tool>
<inspection_tool class="NonFinalStaticVariableUsedInClassInitialization" level="WARNING" enabled="true" />
- <inspection_tool class="OverriddenMethodCallInConstructor" level="WARNING" enabled="true" />
<inspection_tool class="StaticVariableInitialization" level="WARNING" enabled="true">
<option name="m_ignorePrimitives" value="false" />
</inspection_tool>
@@ -255,7 +237,9 @@
<option name="m_minLength" value="12" />
<option name="m_maxLength" value="64" />
</inspection_tool>
- <inspection_tool class="TestCaseWithNoTestMethods" level="WARNING" enabled="true" />
+ <inspection_tool class="TestCaseWithNoTestMethods" level="WARNING" enabled="true">
+ <option name="ignoreSupers" value="false" />
+ </inspection_tool>
<inspection_tool class="JUnitTestClassNamingConvention" level="WARNING" enabled="true">
<option name="m_regex" value="[A-Z][A-Za-z\d]*Test" />
<option name="m_minLength" value="8" />
@@ -296,6 +280,8 @@
</inspection_tool>
<inspection_tool class="MethodWithMultipleLoops" level="WARNING" enabled="true" />
<inspection_tool class="MultipleReturnPointsPerMethod" level="WARNING" enabled="true">
+ <option name="ignoreGuardClauses" value="false" />
+ <option name="ignoreEqualsMethod" value="false" />
<option name="m_limit" value="1" />
</inspection_tool>
<inspection_tool class="ThrownExceptionsPerMethod" level="WARNING" enabled="true">
@@ -391,7 +377,7 @@
<option name="m_ignoreOverridesOfLibraryMethods" value="false" />
</inspection_tool>
<inspection_tool class="QuestionableName" level="WARNING" enabled="true">
- <option name="nameCheckString" value="foo,bar,baz" />
+ <option name="nameString" value="aa,abc,bad,bar,bar2,baz,baz1,baz2,baz3,bb,blah,bogus,bool,cc,dd,defau1t,dummy,dummy2,ee,fa1se,ff,foo,foo1,foo2,foo3,foobar,four,fred,fred1,fred2,gg,hh,hello,hello1,hello2,hello3,ii,nu11,one,silly,silly2,string,two,that,then,three,whi1e,var" />
</inspection_tool>
<inspection_tool class="StandardVariableNames" level="WARNING" enabled="true" />
<inspection_tool class="StaticMethodNamingConvention" level="WARNING" enabled="true">
@@ -447,7 +433,7 @@
<inspection_tool class="NonSerializableWithSerializationMethods" level="WARNING" enabled="true" />
<inspection_tool class="NonSerializableWithSerialVersionUIDField" level="WARNING" enabled="true" />
<inspection_tool class="NonSerializableFieldInSerializableClass" level="WARNING" enabled="true">
- <option name="ignoreSerializableDueToInheritance" value="true" />
+ <option name="superClassString" value="java.awt.Component" />
</inspection_tool>
<inspection_tool class="NonSerializableObjectBoundToHttpSession" level="WARNING" enabled="true" />
<inspection_tool class="NonSerializableObjectPassedToObjectStream" level="WARNING" enabled="true" />
@@ -455,16 +441,16 @@
<inspection_tool class="ReadResolveAndWriteReplaceProtected" level="WARNING" enabled="true" />
<inspection_tool class="SerializableWithUnconstructableAncestor" level="WARNING" enabled="true" />
<inspection_tool class="SerializableHasSerializationMethods" level="WARNING" enabled="true">
- <option name="m_ignoreSerializableDueToInheritance" value="true" />
+ <option name="superClassString" value="java.awt.Component" />
</inspection_tool>
<inspection_tool class="SerializableHasSerialVersionUIDField" level="WARNING" enabled="true">
- <option name="m_ignoreSerializableDueToInheritance" value="true" />
+ <option name="superClassString" value="java.awt.Component" />
</inspection_tool>
<inspection_tool class="SerializableInnerClassHasSerialVersionUIDField" level="WARNING" enabled="true">
- <option name="m_ignoreSerializableDueToInheritance" value="true" />
+ <option name="superClassString" value="java.awt.Component" />
</inspection_tool>
<inspection_tool class="SerializableInnerClassWithNonSerializableOuterClass" level="WARNING" enabled="true">
- <option name="m_ignoreSerializableDueToInheritance" value="true" />
+ <option name="superClassString" value="java.awt.Component" />
</inspection_tool>
<inspection_tool class="SerialPersistentFieldsWithWrongSignature" level="WARNING" enabled="true" />
<inspection_tool class="SerialVersionUIDNotStaticFinal" level="WARNING" enabled="true" />
@@ -600,7 +586,9 @@
</inspection_tool>
<inspection_tool class="LabeledStatement" level="WARNING" enabled="true" />
<inspection_tool class="NestedSwitchStatement" level="WARNING" enabled="true" />
- <inspection_tool class="LoopConditionNotUpdatedInsideLoop" level="WARNING" enabled="true" />
+ <inspection_tool class="LoopConditionNotUpdatedInsideLoop" level="WARNING" enabled="true">
+ <option name="ignoreIterators" value="false" />
+ </inspection_tool>
<inspection_tool class="SwitchStatementWithConfusingDeclaration" level="WARNING" enabled="true" />
<inspection_tool class="OverlyComplexBooleanExpression" level="WARNING" enabled="true">
<option name="m_limit" value="3" />
@@ -700,6 +688,7 @@
<inspection_tool class="UnusedProperty" level="WARNING" enabled="true" />
</profile>
</profiles>
+ <list size="0" />
</component>
<component name="JavacSettings">
<option name="DEBUGGING_INFO" value="true" />
@@ -739,7 +728,6 @@
<option name="FILTER_INFO" value="true" />
<option name="CUSTOM_FILTER" />
</component>
- <component name="Monitor.Log4jWindowPlugin" />
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
@@ -861,6 +849,7 @@
</item>
</group>
</component>
+ <component name="ProjectFileVersion" converted="true" />
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/cherbot.iml" filepath="$PROJECT_DIR$/cherbot.iml" />
@@ -869,7 +858,6 @@
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/ideaclasses" />
</component>
- <component name="ProjectRunConfigurationManager" />
<component name="ResourceManagerContainer">
<option name="myResourceBundles">
<value>
@@ -884,12 +872,10 @@
<option name="GENERATE_IIOP_STUBS" value="false" />
<option name="ADDITIONAL_OPTIONS_STRING" value="" />
</component>
- <component name="StarteamVcsAdapter" />
- <component name="SvnBranchConfigurationManager" />
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="svn" />
</component>
- <component name="VssVcs" />
+ <component name="WebServicesPlugin" addRequiredLibraries="true" />
<component name="com.intellij.jsf.UserDefinedFacesConfigs">
<option name="USER_DEFINED_CONFIGS">
<value>
@@ -1119,6 +1105,5 @@
<SOURCES />
</library>
</component>
- <component name="uidesigner-configuration" />
</project>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-10-12 19:06:09
|
Revision: 120
http://cherbot.svn.sourceforge.net/cherbot/?rev=120&view=rev
Author: christianhujer
Date: 2007-10-12 12:06:05 -0700 (Fri, 12 Oct 2007)
Log Message:
-----------
Fixed bug: properties files unavailable after compilation.
Modified Paths:
--------------
trunk/build.xml
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2007-09-23 22:14:04 UTC (rev 119)
+++ trunk/build.xml 2007-10-12 19:06:05 UTC (rev 120)
@@ -43,6 +43,11 @@
<compilerarg line="-Xmaxerrs 400"/>
<compilerarg line="-Xmaxwarns 4000"/>
</javac>
+ <copy todir="classes">
+ <fileset dir="src">
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
</target>
<target
@@ -115,11 +120,6 @@
description = "creates a jar archive containing the CherBot"
depends = "compile"
>
- <copy todir="classes">
- <fileset dir="src">
- <include name="**/*.properties"/>
- </fileset>
- </copy>
<jar destfile="CherBot.jar">
<manifest>
<attribute name="Main-Class" value="net.sf.cherbot.CherBot" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-09-23 22:14:07
|
Revision: 119
http://cherbot.svn.sourceforge.net/cherbot/?rev=119&view=rev
Author: christianhujer
Date: 2007-09-23 15:14:04 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
Restructured src to new common/ rules.
Added Paths:
-----------
trunk/src/prj/
trunk/src/prj/net/
trunk/src/prj/net/sf/
trunk/src/tst/
trunk/src/tst/test/
trunk/src/tst/test/net/
Removed Paths:
-------------
trunk/src/net/
trunk/src/prj/net/sf/
trunk/src/test/
trunk/src/tst/test/net/
Copied: trunk/src/prj/net (from rev 117, trunk/src/net)
Copied: trunk/src/prj/net/sf (from rev 118, trunk/src/net/sf)
Copied: trunk/src/tst/test (from rev 117, trunk/src/test)
Copied: trunk/src/tst/test/net (from rev 118, trunk/src/test/net)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-09-23 22:12:15
|
Revision: 118
http://cherbot.svn.sourceforge.net/cherbot/?rev=118&view=rev
Author: christianhujer
Date: 2007-09-23 15:11:48 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
Added Factoid Module.
Added Paths:
-----------
trunk/src/net/sf/cherbot/FactoidModule.java
Added: trunk/src/net/sf/cherbot/FactoidModule.java
===================================================================
--- trunk/src/net/sf/cherbot/FactoidModule.java (rev 0)
+++ trunk/src/net/sf/cherbot/FactoidModule.java 2007-09-23 22:11:48 UTC (rev 118)
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import net.sf.cherbot.connection.Channel;
+
+/** A Module for managing factoids.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class FactoidModule implements PersistentModule {
+
+ /** The factoids. */
+ private final Map<String, String> factoids = new HashMap<String, String>();
+
+ /** {@inheritDoc} */
+ public void load(@NotNull final Connection con) throws SQLException {
+ }
+
+ /** {@inheritDoc} */
+ public void save(@NotNull final Connection con) throws SQLException {
+ }
+
+ /** {@inheritDoc} */
+ public void parseMessage(@NotNull final Channel channel, @NotNull final String msg) {
+ if (msg.startsWith("?")) {
+ final String factoid = msg.substring(1);
+ final String explanation = getExplanation(factoid);
+ if (explanation == null) {
+ channel.send("I have no information on " + factoid);
+ } else {
+ channel.send(explanation);
+ }
+ } else if (msg.startsWith("!")) {
+ final Pattern pattern = Pattern.compile("! *(.+?) *= *(.*)$");
+ final Matcher matcher = pattern.matcher(msg);
+ if (matcher.matches()) {
+ final String factoid = matcher.group(1);
+ final String explanation = matcher.group(2);
+ setExplanation(factoid, explanation);
+ }
+ }
+ }
+
+ /** Returns an explanation for a factoid or <code>null</code> if no explanation was found.
+ * @param factoid Factoid to get explanation for.
+ * @return explanation.
+ */
+ @Nullable public String getExplanation(@NotNull final String factoid) {
+ return factoids.get(factoid);
+ }
+
+ /** Sets an explanation for a factoid.
+ * @param factoid Factoid to set explanation for.
+ * @param explanation Explanation for the factoid.
+ */
+ public void setExplanation(@NotNull final String factoid, @NotNull final String explanation) {
+ factoids.put(factoid, explanation);
+ }
+
+} // class FactoidModule
Property changes on: trunk/src/net/sf/cherbot/FactoidModule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-07-07 12:38:56
|
Revision: 117
http://svn.sourceforge.net/cherbot/?rev=117&view=rev
Author: christianhujer
Date: 2007-07-07 05:38:54 -0700 (Sat, 07 Jul 2007)
Log Message:
-----------
Added automatic setting of id in case of new records.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/Server.java
trunk/src/net/sf/cherbot/ServerModule.java
Modified: trunk/src/net/sf/cherbot/Server.java
===================================================================
--- trunk/src/net/sf/cherbot/Server.java 2007-07-07 12:07:45 UTC (rev 116)
+++ trunk/src/net/sf/cherbot/Server.java 2007-07-07 12:38:54 UTC (rev 117)
@@ -41,6 +41,13 @@
this.protocol = protocol;
}
+ /** Sets the id of this server.
+ * @param id The id of this server.
+ */
+ public void setId(final int id) {
+ this.id = id;
+ }
+
/** Returns the id of this server.
* @return The id of this server.
*/
@@ -92,7 +99,7 @@
/** {@inheritDoc} */
@NotNull @Override public String toString() {
- return protocol + "://" + hostname + ":" + port + "/";
+ return protocol + "://" + hostname + ":" + port + "/ " + id;
}
} // class Server
Modified: trunk/src/net/sf/cherbot/ServerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/ServerModule.java 2007-07-07 12:07:45 UTC (rev 116)
+++ trunk/src/net/sf/cherbot/ServerModule.java 2007-07-07 12:38:54 UTC (rev 117)
@@ -45,19 +45,28 @@
final PreparedStatement lookup = con.prepareStatement("SELECT id FROM Server WHERE id = ?");
final PreparedStatement update = con.prepareStatement("UPDATE Server SET host = ?, port = ?, protocol = ? WHERE id = ?");
final PreparedStatement insert = con.prepareStatement("INSERT INTO Server (host, port, protocol) VALUES (?, ?, ?)");
+ final PreparedStatement getId = con.prepareStatement("VALUES IDENTITY_VAL_LOCAL()");
for (final Server server : servers) {
+ final boolean newRecord;
lookup.setInt(1, server.getId());
final PreparedStatement stmt;
- if (lookup.executeQuery().next()) {
+ newRecord = !lookup.executeQuery().next();
+ if (newRecord) {
+ stmt = insert;
+ } else {
stmt = update;
update.setInt(4, server.getId());
- } else {
- stmt = insert;
}
stmt.setString(1, server.getHostname());
stmt.setInt(2, server.getPort());
stmt.setString(3, server.getProtocol());
stmt.executeUpdate();
+ if (newRecord) {
+ final ResultSet rs = getId.executeQuery();
+ rs.next();
+ server.setId(rs.getInt(1));
+ rs.close();
+ }
}
lookup.close();
update.close();
@@ -85,7 +94,7 @@
/** Returns a list of servers.
* @return a list of servers
*/
- public List<Server> getServers() {
+ @NotNull public List<Server> getServers() {
return Collections.unmodifiableList(servers);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-07-07 12:07:48
|
Revision: 116
http://svn.sourceforge.net/cherbot/?rev=116&view=rev
Author: christianhujer
Date: 2007-07-07 05:07:45 -0700 (Sat, 07 Jul 2007)
Log Message:
-----------
Implemented rudimentary configurator. Servers can now be added or listed.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/Configurator.java
trunk/src/net/sf/cherbot/Server.java
trunk/src/net/sf/cherbot/ServerModule.java
Modified: trunk/src/net/sf/cherbot/Configurator.java
===================================================================
--- trunk/src/net/sf/cherbot/Configurator.java 2007-07-07 12:07:08 UTC (rev 115)
+++ trunk/src/net/sf/cherbot/Configurator.java 2007-07-07 12:07:45 UTC (rev 116)
@@ -6,18 +6,105 @@
package net.sf.cherbot;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.List;
+import net.sf.japi.io.args.ArgParser;
import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.Option;
import org.jetbrains.annotations.NotNull;
-import java.util.List;
-/** The Configurator creates or modifies the initial server database for CherBot.
+/** The Configurator creates or modifies the server database for CherBot.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public class Configurator extends BasicCommand {
+ /** The default database URL. */
+ @NotNull private static final String DEFAULT_DATABASE_URL = "jdbc:derby:cherbotdb;create=true";
+
+ /** The database URL. */
+ @NotNull private String databaseURL = DEFAULT_DATABASE_URL;
+
+ /** The JDBC connection for data persistence. */
+ @NotNull private Connection connection;
+
+ /** The server module. */
+ @NotNull private ServerModule serverModule = new ServerModule();
+
+ /** The command mode. */
+ @NotNull private CommandMode commandMode = CommandMode.LIST;
+
+ /** Main program.
+ * @param args Command line arguments (try --help)
+ */
+ public static void main(@NotNull final String... args) {
+ ArgParser.simpleParseAndRun(new Configurator(), args);
+ }
+
/** {@inheritDoc} */
public int run(@NotNull final List<String> args) throws Exception {
+ initConnection();
+ serverModule.load(connection);
+ switch (commandMode) {
+ case LIST:
+ for (final Server server : serverModule.getServers()) {
+ System.out.println(server);
+ }
+ break;
+ case ADD:
+ final Server server = new Server(0, args.get(0), Integer.parseInt(args.get(1)), args.get(2));
+ serverModule.add(server);
+ serverModule.save(connection);
+ System.out.println("Successfully added " + server);
+ break;
+ }
return 0;
}
+ /** Initializes the connection.
+ * @throws SQLException in case of SQL problems.
+ */
+ private void initConnection() throws SQLException {
+ synchronized (this) {
+ if (connection == null) {
+ connection = DriverManager.getConnection(databaseURL);
+ }
+ }
+ }
+
+ /** Lists the current server database. */
+ @Option({"l", "list"})
+ public void list() {
+ commandMode = CommandMode.LIST;
+ }
+
+ /** Adds the specified server spec. */
+ @Option({"a", "add"})
+ public void add() {
+ commandMode = CommandMode.ADD;
+ }
+
+ /** Returns the database URL.
+ * @return The database URL.
+ */
+ @NotNull public String getDatabaseURL() {
+ return databaseURL;
+ }
+
+ /** Sets the database URL.
+ * @param databaseURL The database URL.
+ */
+ @Option({"databaseURL"})
+ public void setDatabaseURL(@NotNull final String databaseURL) {
+ this.databaseURL = databaseURL;
+ }
+
+ /** Enumeration of supported command modes.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+ private enum CommandMode {
+ ADD, LIST
+ }
+
} // class Configurator
Modified: trunk/src/net/sf/cherbot/Server.java
===================================================================
--- trunk/src/net/sf/cherbot/Server.java 2007-07-07 12:07:08 UTC (rev 115)
+++ trunk/src/net/sf/cherbot/Server.java 2007-07-07 12:07:45 UTC (rev 116)
@@ -25,15 +25,20 @@
/** The port of this server. */
private int port;
+ /** The protocol of this server. */
+ @NotNull private String protocol;
+
/** Create a Server.
* @param id Id of this server.
* @param hostname Hostname of this server.
* @param port Port of this server.
+ * @param protocol Protocol of this server.
*/
- public Server(final int id, @NotNull final String hostname, final int port) {
+ public Server(final int id, @NotNull final String hostname, final int port, @NotNull final String protocol) {
this.id = id;
this.hostname = hostname;
this.port = port;
+ this.protocol = protocol;
}
/** Returns the id of this server.
@@ -71,4 +76,23 @@
this.port = port;
}
+ /** Returns the protocol of this server.
+ * @return The protocol of this server.
+ */
+ @NotNull public String getProtocol() {
+ return protocol;
+ }
+
+ /** Sets the protocol of this server.
+ * @param protocol The protocol of this server.
+ */
+ public void setProtocol(@NotNull final String protocol) {
+ this.protocol = protocol;
+ }
+
+ /** {@inheritDoc} */
+ @NotNull @Override public String toString() {
+ return protocol + "://" + hostname + ":" + port + "/";
+ }
+
} // class Server
Modified: trunk/src/net/sf/cherbot/ServerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/ServerModule.java 2007-07-07 12:07:08 UTC (rev 115)
+++ trunk/src/net/sf/cherbot/ServerModule.java 2007-07-07 12:07:45 UTC (rev 116)
@@ -13,6 +13,7 @@
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
+import java.util.Collections;
import net.sf.cherbot.connection.Channel;
/** Module for managing servers.
@@ -25,13 +26,15 @@
/** {@inheritDoc} */
public void load(@NotNull final Connection con) throws SQLException {
- final PreparedStatement stmt = con.prepareStatement("SELECT id, serverId, name FROM Player");
+ createTables(con);
+ final PreparedStatement stmt = con.prepareStatement("SELECT id, host, port, protocol FROM Server");
final ResultSet result = stmt.executeQuery();
while (result.next()) {
final int id = result.getInt(1);
final String host = result.getString(2);
final int port = result.getInt(3);
- servers.add(new Server(id, host, port));
+ final String protocol = result.getString(4);
+ servers.add(new Server(id, host, port, protocol));
}
stmt.close();
}
@@ -40,21 +43,21 @@
public void save(@NotNull final Connection con) throws SQLException {
createTables(con);
final PreparedStatement lookup = con.prepareStatement("SELECT id FROM Server WHERE id = ?");
- final PreparedStatement update = con.prepareStatement("UPDATE Server SET host = ?, port = ? WHERE id = ?");
- final PreparedStatement insert = con.prepareStatement("INSERT INTO Server (id, host, port) VALUES (?, ?, ?)");
+ final PreparedStatement update = con.prepareStatement("UPDATE Server SET host = ?, port = ?, protocol = ? WHERE id = ?");
+ final PreparedStatement insert = con.prepareStatement("INSERT INTO Server (host, port, protocol) VALUES (?, ?, ?)");
for (final Server server : servers) {
lookup.setInt(1, server.getId());
+ final PreparedStatement stmt;
if (lookup.executeQuery().next()) {
- update.setString(1, server.getHostname());
- update.setInt(2, server.getPort());
- update.setInt(3, server.getId());
- update.executeUpdate();
+ stmt = update;
+ update.setInt(4, server.getId());
} else {
- insert.setInt(1, server.getId());
- insert.setString(2, server.getHostname());
- insert.setInt(3, server.getPort());
- insert.executeUpdate();
+ stmt = insert;
}
+ stmt.setString(1, server.getHostname());
+ stmt.setInt(2, server.getPort());
+ stmt.setString(3, server.getProtocol());
+ stmt.executeUpdate();
}
lookup.close();
update.close();
@@ -67,11 +70,11 @@
*/
private void createTables(@NotNull final Connection con) throws SQLException {
try {
- final PreparedStatement stmt = con.prepareStatement("CREATE TABLE Server (id INT, host VARCHAR(64), port INT");
+ final PreparedStatement stmt = con.prepareStatement("CREATE TABLE Server (id INT NOT NULL GENERATED ALWAYS AS IDENTITY, host VARCHAR(64), port INT, protocol VARCHAR(64))");
stmt.execute();
stmt.close();
} catch (final SQLException ignore) {
- System.err.println(ignore);
+ // System.err.println(ignore);
}
}
@@ -79,4 +82,18 @@
public void parseMessage(@NotNull final Channel channel, @NotNull final String msg) {
}
+ /** Returns a list of servers.
+ * @return a list of servers
+ */
+ public List<Server> getServers() {
+ return Collections.unmodifiableList(servers);
+ }
+
+ /** Adds a server.
+ * @param server Server to add.
+ */
+ public void add(@NotNull final Server server) {
+ servers.add(server);
+ }
+
} // class ServerModule
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-07-07 12:07:11
|
Revision: 115
http://svn.sourceforge.net/cherbot/?rev=115&view=rev
Author: christianhujer
Date: 2007-07-07 05:07:08 -0700 (Sat, 07 Jul 2007)
Log Message:
-----------
Fixed bogus format.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/connection/CrossfireConnection.java
Modified: trunk/src/net/sf/cherbot/connection/CrossfireConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/connection/CrossfireConnection.java 2007-07-07 11:14:56 UTC (rev 114)
+++ trunk/src/net/sf/cherbot/connection/CrossfireConnection.java 2007-07-07 12:07:08 UTC (rev 115)
@@ -17,12 +17,12 @@
*/
public class CrossfireConnection extends AbstractCFConnection {
- /** Default server host. */
- //@NotNull public static final String DEFAULT_CROSSFIRE_HOST = "crossfire.metalforge.net";
- @NotNull public static final String DEFAULT_CROSSFIRE_HOST = "127.0.0.1";
+ /** Default server host. */
+ //@NotNull public static final String DEFAULT_CROSSFIRE_HOST = "crossfire.metalforge.net";
+ @NotNull public static final String DEFAULT_CROSSFIRE_HOST = "127.0.0.1";
- /** Default server port. */
- public static final int DEFAULT_CROSSFIRE_PORT = 13327;
+ /** Default server port. */
+ public static final int DEFAULT_CROSSFIRE_PORT = 13327;
/** Creates a CrossfireConnection. */
public CrossfireConnection() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-07-07 11:14:59
|
Revision: 114
http://svn.sourceforge.net/cherbot/?rev=114&view=rev
Author: christianhujer
Date: 2007-07-07 04:14:56 -0700 (Sat, 07 Jul 2007)
Log Message:
-----------
Updated wrong copyright / author.
Modified Paths:
--------------
trunk/src/doc/commands.xslt
Modified: trunk/src/doc/commands.xslt
===================================================================
--- trunk/src/doc/commands.xslt 2007-07-01 17:36:38 UTC (rev 113)
+++ trunk/src/doc/commands.xslt 2007-07-07 11:14:56 UTC (rev 114)
@@ -19,8 +19,8 @@
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>Cherbot commands</title>
- <meta name="Copyright" content="© 2003 ITCQIS GmbH. All rights reserved." />
- <meta name="Author" content="ITCQIS GmbH, $Author: chris $" />
+ <meta name="Copyright" content="© 2003-2007 Christian Hujer. All rights reserved." />
+ <meta name="Author" content="Christian Hujer, $Author: chris $" />
<meta scheme="CVS" name="Id" content="$Id: commands.xslt,v 1.2 2005/08/29 15:46:27 chris Exp $" />
<meta scheme="CVS" name="Source" content="$Source: /home/rpgroot/CherBot/src/doc/commands.xslt,v $" />
<meta scheme="CVS" name="State" content="$State: Exp $" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-07-01 17:36:40
|
Revision: 113
http://svn.sourceforge.net/cherbot/?rev=113&view=rev
Author: christianhujer
Date: 2007-07-01 10:36:38 -0700 (Sun, 01 Jul 2007)
Log Message:
-----------
Moved connection related stuff into a separate package.
Removed Paths:
-------------
trunk/src/net/sf/cherbot/AbstractCFConnection.java
trunk/src/net/sf/cherbot/AbstractChannel.java
trunk/src/net/sf/cherbot/AbstractConnection.java
trunk/src/net/sf/cherbot/Channel.java
trunk/src/net/sf/cherbot/CrossfireConnection.java
trunk/src/net/sf/cherbot/DaimoninConnection.java
trunk/src/net/sf/cherbot/IRCConnection.java
Deleted: trunk/src/net/sf/cherbot/AbstractCFConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractCFConnection.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/AbstractCFConnection.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,141 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.BufferedOutputStream;
-import java.net.Socket;
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.NotNull;
-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.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public abstract class AbstractCFConnection extends AbstractConnection {
-
- /** The username to authenticate with. */
- @NotNull private String username;
-
- /** The password to authenticate with. */
- @NotNull private String password;
-
- /** The PrintStream to write to. */
- @Nullable private OutputStream out;
-
- /** The BufferedReader to read from. */
- @Nullable private InputStream in;
-
- /** Creates an AbstractCFConnection. */
- protected AbstractCFConnection() {
- }
-
- /** Reads and discards a single message.
- * @throws IOException In case of I/O problems.
- */
- protected void readToNull() throws IOException {
- receivePacket();
- }
-
- /** Reads the next data packet.
- * @throws IOException In case of I/O problems.
- * @return The data of the next data packet.
- */
- @NotNull protected byte[] receivePacket() throws IOException {
- final InputStream in = this.in;
- assert in != null;
- final int h1 = in.read();
- final int length = h1 != -1 && (h1 & 0x80) == 0x80 ? h1 << 16 | in.read() << 8 | in.read() : h1 << 8 | in.read();
- if (length == -1) {
- throw new EOFException();
- }
- final byte[] data = new byte[length];
- for (int read = 0; read < length;) {
- final int bytesRead = in.read(data, read, length - read);
- if (bytesRead == -1) {
- throw new EOFException();
- }
- read += bytesRead;
- }
- return data;
- }
-
- /** Sends a simple text message.
- * @param msg Message to send
- * @throws IOException In case of I/O problems.
- */
- protected void textMsg(@NotNull final String msg) throws IOException {
- final OutputStream out = this.out;
- assert out != null;
- final byte[] data = msg.getBytes("utf-8");
- out.write(0xFF & data.length >> 8);
- out.write(0xFF & data.length);
- out.write(data);
- out.flush();
- }
-
- /** {@inheritDoc} */
- public void close() throws IOException {
- try {
- super.close();
- } finally {
- in = null;
- out = null;
- }
- }
-
- /** {@inheritDoc} */
- @Override public void setSocket(@NotNull final Socket socket) throws IOException {
- super.setSocket(socket);
- out = new BufferedOutputStream(socket.getOutputStream());
- in = socket.getInputStream();
- }
-
- /** Sets the username for connecting to this CF-Style server.
- * @param username Username for connecting to this CF-Style server.
- */
- @Option(type = OptionType.REQUIRED, value = {"username"})
- public void setUsername(@NotNull final String username) {
- this.username = username;
- }
-
- /** Sets the password for connecting to this CF-Style server.
- * @param password Password for connecting to this CF-Style server.
- */
- @Option(type = OptionType.REQUIRED, value = {"password"})
- public void setPassword(@NotNull final String password) {
- this.password = password;
- }
-
- /** {@inheritDoc} */
- // Overridden because for CF-Style servers the host is optional.
- @Option({"host"})
- public void setHost(@NotNull final String host) {
- super.setHost(host);
- }
-
- @NotNull public String getUsername() {
- return username;
- }
-
- @NotNull public String getPassword() {
- return password;
- }
-
- @Nullable protected OutputStream getOut() {
- return out;
- }
-
- @Nullable protected InputStream getIn() {
- return in;
- }
-} // class AbstractCFConnection
Deleted: trunk/src/net/sf/cherbot/AbstractChannel.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractChannel.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/AbstractChannel.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,33 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import org.jetbrains.annotations.Nullable;
-
-/** Abstract base implementation of {@link Channel}.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public abstract class AbstractChannel implements Channel {
-
- /** The name of this channel.
- * Maybe <code>null</code> if it's the default / no channel.
- */
- @Nullable private String channelName;
-
- /** Creates a Channel.
- * @param channelName name of this channel.
- */
- protected AbstractChannel(@Nullable final String channelName) {
- this.channelName = channelName;
- }
-
- /** {@inheritDoc} */
- @Nullable public String getChannelName() {
- return channelName;
- }
-
-} // class Channel
Deleted: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,126 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.Socket;
-import net.sf.japi.io.args.BasicCommand;
-import net.sf.japi.io.args.Option;
-import net.sf.japi.io.args.OptionType;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** An AbstractConnection represents the connection to a server and has one or more channels.
- * Connections are implemented as command bean.
- * That means:
- * <ul>
- * <li>
- * An object does not reflect an established connection but has a state.
- * The connection state can be established or not established.
- * </li>
- * <li>
- * For testing, trying or standalone usage it is possible to "run" a connection as a standalone java program from the command line.
- * </li>
- * </ul>
- * To query whether the connection is open, get the Socket of the connection and check the socket.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public abstract class AbstractConnection extends BasicCommand implements Closeable, Serializable {
-
- /** The host to connect to.
- * @serial include
- */
- @Nullable private String host;
-
- /** The port to connect to.
- * @serial include
- */
- private int port;
-
- /** The socket for the connection. */
- @Nullable private transient Socket socket;
-
- /** Sets the host of the IRC server to connect to.
- * @param host Host of the IRC server.
- */
- @Option(type = OptionType.REQUIRED, value = {"host"})
- public void setHost(@NotNull final String host) {
- this.host = host;
- }
-
- /** Returns the host to connect to.
- * @return The host to connect to.
- */
- @Nullable public String getHost() {
- return host;
- }
-
- /** Sets the port of the IRC server to connect to.
- * @param port Port of the IRC server.
- */
- @Option({"port"})
- public void setPort(@NotNull final Integer port) {
- this.port = port;
- }
-
- /** Returns the port to connect to.
- * @return The port to connect to.
- */
- public int getPort() {
- return port;
- }
-
- /** Establishes this connection.
- * Implementations of this method must invoke {@link #setSocket(Socket)}.
- * @return The socket created for this connection.
- * @throws IOException in case of connection problems.
- */
- @NotNull public Socket connect() throws IOException {
- final Socket socket = new Socket(host, port);
- setSocket(socket);
- return socket;
- }
-
- /** {@inheritDoc} */
- public void close() throws IOException {
- try {
- final Socket socket = this.socket;
- if (socket != null) {
- socket.close();
- }
- } finally {
- socket = null;
- }
- }
-
- /** Returns whether this connection is established.
- * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
- * @see Socket#isConnected()
- */
- public boolean isConnected() {
- return socket != null && socket.isConnected();
- }
-
- /** Sets the socket for the connection.
- * Use this method if you want to create a connection on an existing socket instead of letting this Connection automatically create its own socket.
- * @param socket Socket for the connection.
- * @throws IOException In case of I/O problems when setting the socket. This is useful for overriding methods which may be interested in using the socket when it's being set.
- */
- public void setSocket(@NotNull final Socket socket) throws IOException {
- this.socket = socket;
- }
-
- /** Returns the socket for the connection.
- * @return The socket for the connection.
- */
- @Nullable public Socket getSocket() {
- return socket;
- }
-
-} // class AbstractConnection
Deleted: trunk/src/net/sf/cherbot/Channel.java
===================================================================
--- trunk/src/net/sf/cherbot/Channel.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/Channel.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,28 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** A Channel uniquely identifies a protocol (type) / server / channel combination.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public interface Channel {
-
- /** Sends a message to this channel.
- * @param msg Message to send
- */
- void send(@NotNull String msg);
-
- /** Returns the name of this channel.
- * Maybe <code>null</code> if it's the default / no channel.
- * @return The channel of this channel or <code>null</code> if default / no channel.
- */
- @Nullable String getChannelName();
-
-} // interface Channel
Deleted: trunk/src/net/sf/cherbot/CrossfireConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,66 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.util.List;
-import net.sf.japi.io.args.ArgParser;
-import org.jetbrains.annotations.NotNull;
-
-/** A CrossfireConnection represents a connection to a Crossfire server.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public class CrossfireConnection extends AbstractCFConnection {
-
- /** Default server host. */
- //@NotNull public static final String DEFAULT_CROSSFIRE_HOST = "crossfire.metalforge.net";
- @NotNull public static final String DEFAULT_CROSSFIRE_HOST = "127.0.0.1";
-
- /** Default server port. */
- public static final int DEFAULT_CROSSFIRE_PORT = 13327;
-
- /** Creates a CrossfireConnection. */
- public CrossfireConnection() {
- setHost(DEFAULT_CROSSFIRE_HOST);
- setPort(DEFAULT_CROSSFIRE_PORT);
- }
-
- /** Main program.
- * @param args Command line arguments.
- */
- public static void main(final String... args) {
- ArgParser.simpleParseAndRun(new CrossfireConnection(), args);
- }
-
- /** {@inheritDoc} */
- @NotNull @Override public Socket connect() throws IOException {
- final Socket socket = super.connect();
- readToNull();
- textMsg("version 1023 1023 CherBot");
- textMsg("setup bot 1");
- readToNull();
- readToNull();
- textMsg("addme");
- readToNull();
- textMsg("reply " + getUsername());
- readToNull();
- textMsg("reply " + getPassword());
- return socket;
- }
-
- /** {@inheritDoc} */
- public int run(@NotNull final List<String> args) throws Exception {
- connect();
- for (int i = 0; i < 10000; i++) {
- readToNull();
- }
- close();
- return 0;
- }
-
-} // class CrossfireConnection
Deleted: trunk/src/net/sf/cherbot/DaimoninConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,64 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.util.List;
-import net.sf.japi.io.args.ArgParser;
-import org.jetbrains.annotations.NotNull;
-
-/** A DaimoninConnection represents a connection to a Daimonin server.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public class DaimoninConnection extends AbstractCFConnection {
-
- /** Default server host. */
- //@NotNull public static final String DEFAULT_DAIMONIN_HOST = "daimonin.game-server.cc";
- @NotNull public static final String DEFAULT_DAIMONIN_HOST = "127.0.0.1";
-
- /** Default server port. */
- public static final int DEFAULT_DAIMONIN_PORT = 13327;
-
- /** Creates a DaimoninConnection. */
- public DaimoninConnection() {
- setHost(DEFAULT_DAIMONIN_HOST);
- setPort(DEFAULT_DAIMONIN_PORT);
- }
-
- /** Main program.
- * @param args Command line arguments.
- */
- public static void main(final String... args) {
- ArgParser.simpleParseAndRun(new DaimoninConnection(), args);
- }
-
- /** {@inheritDoc} */
- @NotNull @Override public Socket connect() throws IOException {
- final Socket socket = super.connect();
- readToNull(); // "991023 991023 Daimonin Server"
- textMsg("version 991023 991023 Daimonin SDL Client"); // we have to cheat or the server won't let us in.
- textMsg("setup bot 1"); // We are a bot
- readToNull(); // "0x17 bot FALSE"
- textMsg("addme");
- readToNull(); // 0x00 0x06 0x18 "4 QNO"
- readToNull(); // 0x00 0x01 0x15
- textMsg("reply L" + getUsername());
- readToNull(); // 0x00 0x06 0x18 "4 QP0"
- textMsg("reply " + getPassword());
- return socket;
- }
-
- /** {@inheritDoc} */
- public int run(@NotNull final List<String> args) throws Exception {
- connect();
- Thread.sleep(100000);
- close();
- return 0;
- }
-
-} // class DaimoninConnection
Deleted: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java 2007-07-01 17:36:00 UTC (rev 112)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-07-01 17:36:38 UTC (rev 113)
@@ -1,270 +0,0 @@
-/*
- * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import net.sf.cherbot.redel.PatternDelegator;
-import net.sf.cherbot.redel.Patterns;
-import net.sf.japi.io.args.ArgParser;
-import net.sf.japi.io.args.Option;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/** An IRCConnection represents a connection to an IRC server.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- * @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc2812.txt">RFC 2812: Internet Relay Chat: Client Protocol</a>
- */
-public class IRCConnection extends AbstractConnection {
-
- /** The default IRC port. */
- public static final int DEFAULT_IRC_PORT = 6667;
-
- /** The username to use for IRC authentication.
- * This is the IRC username, not the IRC nick.
- */
- @NotNull private String username = "cherbot";
-
- /** The realname to use for IRC authentication.
- * This is the realname, not the IRC nick.
- */
- @NotNull private String realname = "CherBot";
-
- /** The nickname to use for IRC. */
- @NotNull private String nickname = "CherBot";
-
- /** The password to authenticate with NickServ or <code>null</code> if no authentication is desired. */
- @Nullable private String nickPassword;
-
- /** The PrintStream to write to. */
- @Nullable private PrintWriter out;
-
- /** The BufferedReader to read from. */
- @Nullable private BufferedReader in;
-
- /** The channels of this connection. */
- private Map<String, IRCChannel> channels = new HashMap<String, IRCChannel>();
-
- /** Creates an IRCConnection. */
- public IRCConnection() {
- setPort(DEFAULT_IRC_PORT);
- }
-
- /** Main program.
- * For testing purposes.
- * @param args Command line arguments
- * @throws IOException In case of I/O problems.
- */
- public static void main(final String... args) throws IOException {
- ArgParser.simpleParseAndRun(new IRCConnection(), args);
- }
-
- /** {@inheritDoc} */
- @Override @NotNull public Socket connect() throws IOException {
- final Socket socket = super.connect();
- final PrintWriter out = this.out;
- assert this.out != null;
- out.println("USER " + username + " 0 * :" + realname);
- out.println("NICK " + nickname);
- if (nickPassword != null) {
- out.println("PRIVMSG NICKSERV :IDENTIFY " + nickPassword);
- }
- out.flush();
- return socket;
- }
-
- /** {@inheritDoc} */
- @Override public void close() throws IOException {
- channels.clear();
- try {
- super.close();
- } finally {
- in = null;
- out = null;
- }
- }
-
- /** {@inheritDoc} */
- @Override public void setSocket(@NotNull final Socket socket) throws IOException {
- super.setSocket(socket);
- out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8"));
- in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8"));
- }
-
- /** {@inheritDoc} */
- public int run(@NotNull final List<String> args) throws Exception {
- connect();
- try {
- final PrintWriter out = this.out;
- assert out != null;
- final BufferedReader in = this.in;
- assert in != null;
- for (final String channelName : args) {
- join(channelName);
- }
- final PatternDelegator delegator = new PatternDelegator(this);
- for (String line; (line = in.readLine()) != null;) {
- System.out.print("> ");
- System.out.println(line);
- delegator.process(line);
- }
- return 0;
- } finally {
- close();
- }
- }
-
- /** Processes an INVITE irc message.
- * @param actor Actor of this JOIN.
- * @param actorIdentity Identity of the actor.
- * @param target Target of the invitation.
- * @param channel Channel to join.
- */
- @Patterns({"^:([^!]+)!([^ ]+) INVITE ([^ ]+) :(.*)$"})
- public void processINVITE(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String target, @NotNull final String channel) {
- System.err.println("Received invitation to " + target + " at " + channel + " by " + actor + " (" + actorIdentity + ")");
- join(channel);
- }
-
- /** Processes a JOIN irc message.
- * @param actor Actor of this JOIN.
- * @param actorIdentity Identity of the actor.
- * @param channel Channel to join.
- */
- @Patterns({"^:([^!]+)!([^ ]+) JOIN :(.*)$"})
- public void processJOIN(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channel) {
- System.err.println("Joined channel " + channel);
- // Nothing to do for a JOIN.
- }
-
- /** Process a MODE irc message.
- * @param actor Actor of this MODE.
- * @param actorIdentity Identity of the actor.
- * @param channel Channel of the mode change.
- * @param change Mode change.
- * @param target Target of the mode change.
- */
- @Patterns({"^:([^!]+)!([^ ]+) MODE ([^ ]+) ([^ ]+) (.*?) ?$"})
- public void processMODE(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channel, @NotNull final String change, @NotNull final String target) {
- System.err.println("Mode change at " + channel + ": " + change + " on " + target + " by " + actor + " (" + actorIdentity + ")");
- // Nothing to do for a MODE.
- }
-
- /** Processes a PING irc message.
- * @param server Server that requests a PONG.
- */
- @Patterns({"^PING :(.*)$"})
- public void processPING(@NotNull final String server) {
- final PrintWriter out = this.out;
- if (out != null) {
- out.println("PONG " + server);
- out.flush();
- }
- }
-
- /** Processes a PRIVMSG irc message.
- * @param actor Actor of this message.
- * @param actorIdentity Identity of the actor.
- * @param channelName Name of the channel.
- * @param message Message text.
- */
- @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);
- }
-
- /** Joins an IRC channel.
- * @param rawChannelName name of the channel to join.
- * @return The channel that was just joined.
- */
- public Channel join(@NotNull final String rawChannelName) {
- final String channelName = rawChannelName.toLowerCase();
- final PrintWriter out = this.out;
- 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;
- }
-
- /** Sets the username to use for connecting to the IRC server.
- * Note that this is the IRC username, not the nick.
- * @param username Username to use for IRC.
- */
- @Option({"username"})
- public void setUsername(@NotNull final String username) {
- this.username = username;
- }
-
- /** Sets the realname to use for connecting to the IRC server.
- * Note that this is the IRC realname, not the nick.
- * @param realname Realname to use for IRC.
- */
- @Option({"realname"})
- public void setRealname(@NotNull final String realname) {
- this.realname = realname;
- }
-
- /** Sets the nickname to use for connecting to the IRC server.
- * @param nickname Nickname to use for IRC.
- */
- @Option({"nickname"})
- public void setNickname(@NotNull final String nickname) {
- this.nickname = nickname;
- }
-
- /** Sets the password to use for authentication with NickServ.
- * Setting it to <code>null</code> means to not authenticate with NickServ.
- * @param nickPassword Password to use for authentication with NickServ.
- */
- @Option({"nickPassword"})
- public void setNickPassword(@Nullable final String nickPassword) {
- this.nickPassword = nickPassword;
- }
-
- /** 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>
- */
- private class IRCChannel extends AbstractChannel {
-
- /** Creates an IRCChannel.
- * @param channelName name of this channel.
- */
- IRCChannel(@NotNull final String channelName) {
- super(channelName);
- }
-
- /** {@inheritDoc} */
- public void send(@NotNull final String msg) {
- final PrintWriter out = IRCConnection.this.out;
- if (out != null) {
- out.println("PRIVMSG " + getChannelName() + " :" + msg);
- out.flush();
- }
- }
-
- } // class IRCChannel
-
-} // class IRCConnection
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-07-01 17:36:08
|
Revision: 112
http://svn.sourceforge.net/cherbot/?rev=112&view=rev
Author: christianhujer
Date: 2007-07-01 10:36:00 -0700 (Sun, 01 Jul 2007)
Log Message:
-----------
Moved connection related stuff into a separate package.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/ClanModule.java
trunk/src/net/sf/cherbot/EchoModule.java
trunk/src/net/sf/cherbot/Module.java
trunk/src/net/sf/cherbot/PlayerModule.java
trunk/src/net/sf/cherbot/ServerModule.java
Added Paths:
-----------
trunk/src/net/sf/cherbot/connection/
trunk/src/net/sf/cherbot/connection/AbstractCFConnection.java
trunk/src/net/sf/cherbot/connection/AbstractChannel.java
trunk/src/net/sf/cherbot/connection/AbstractConnection.java
trunk/src/net/sf/cherbot/connection/Channel.java
trunk/src/net/sf/cherbot/connection/CrossfireConnection.java
trunk/src/net/sf/cherbot/connection/DaimoninConnection.java
trunk/src/net/sf/cherbot/connection/IRCConnection.java
trunk/src/net/sf/cherbot/connection/package-info.java
Modified: trunk/src/net/sf/cherbot/ClanModule.java
===================================================================
--- trunk/src/net/sf/cherbot/ClanModule.java 2007-06-30 20:12:40 UTC (rev 111)
+++ trunk/src/net/sf/cherbot/ClanModule.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -8,6 +8,7 @@
import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
+import net.sf.cherbot.connection.Channel;
/** Module for Clans.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
Modified: trunk/src/net/sf/cherbot/EchoModule.java
===================================================================
--- trunk/src/net/sf/cherbot/EchoModule.java 2007-06-30 20:12:40 UTC (rev 111)
+++ trunk/src/net/sf/cherbot/EchoModule.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -7,6 +7,7 @@
package net.sf.cherbot;
import org.jetbrains.annotations.NotNull;
+import net.sf.cherbot.connection.Channel;
/** Module that simply echoes a message.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
Modified: trunk/src/net/sf/cherbot/Module.java
===================================================================
--- trunk/src/net/sf/cherbot/Module.java 2007-06-30 20:12:40 UTC (rev 111)
+++ trunk/src/net/sf/cherbot/Module.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -7,6 +7,7 @@
package net.sf.cherbot;
import org.jetbrains.annotations.NotNull;
+import net.sf.cherbot.connection.Channel;
/** Interface for Modules.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
Modified: trunk/src/net/sf/cherbot/PlayerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/PlayerModule.java 2007-06-30 20:12:40 UTC (rev 111)
+++ trunk/src/net/sf/cherbot/PlayerModule.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -13,6 +13,7 @@
import java.sql.ResultSet;
import java.util.List;
import java.util.ArrayList;
+import net.sf.cherbot.connection.Channel;
/** Module for managing players.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
Modified: trunk/src/net/sf/cherbot/ServerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/ServerModule.java 2007-06-30 20:12:40 UTC (rev 111)
+++ trunk/src/net/sf/cherbot/ServerModule.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -13,6 +13,7 @@
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
+import net.sf.cherbot.connection.Channel;
/** Module for managing servers.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
Copied: trunk/src/net/sf/cherbot/connection/AbstractCFConnection.java (from rev 111, trunk/src/net/sf/cherbot/AbstractCFConnection.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/AbstractCFConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/AbstractCFConnection.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,141 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.BufferedOutputStream;
+import java.net.Socket;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
+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.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractCFConnection extends AbstractConnection {
+
+ /** The username to authenticate with. */
+ @NotNull private String username;
+
+ /** The password to authenticate with. */
+ @NotNull private String password;
+
+ /** The PrintStream to write to. */
+ @Nullable private OutputStream out;
+
+ /** The BufferedReader to read from. */
+ @Nullable private InputStream in;
+
+ /** Creates an AbstractCFConnection. */
+ protected AbstractCFConnection() {
+ }
+
+ /** Reads and discards a single message.
+ * @throws IOException In case of I/O problems.
+ */
+ protected void readToNull() throws IOException {
+ receivePacket();
+ }
+
+ /** Reads the next data packet.
+ * @throws IOException In case of I/O problems.
+ * @return The data of the next data packet.
+ */
+ @NotNull protected byte[] receivePacket() throws IOException {
+ final InputStream in = this.in;
+ assert in != null;
+ final int h1 = in.read();
+ final int length = h1 != -1 && (h1 & 0x80) == 0x80 ? h1 << 16 | in.read() << 8 | in.read() : h1 << 8 | in.read();
+ if (length == -1) {
+ throw new EOFException();
+ }
+ final byte[] data = new byte[length];
+ for (int read = 0; read < length;) {
+ final int bytesRead = in.read(data, read, length - read);
+ if (bytesRead == -1) {
+ throw new EOFException();
+ }
+ read += bytesRead;
+ }
+ return data;
+ }
+
+ /** Sends a simple text message.
+ * @param msg Message to send
+ * @throws IOException In case of I/O problems.
+ */
+ protected void textMsg(@NotNull final String msg) throws IOException {
+ final OutputStream out = this.out;
+ assert out != null;
+ final byte[] data = msg.getBytes("utf-8");
+ out.write(0xFF & data.length >> 8);
+ out.write(0xFF & data.length);
+ out.write(data);
+ out.flush();
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ try {
+ super.close();
+ } finally {
+ in = null;
+ out = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setSocket(@NotNull final Socket socket) throws IOException {
+ super.setSocket(socket);
+ out = new BufferedOutputStream(socket.getOutputStream());
+ in = socket.getInputStream();
+ }
+
+ /** Sets the username for connecting to this CF-Style server.
+ * @param username Username for connecting to this CF-Style server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"username"})
+ public void setUsername(@NotNull final String username) {
+ this.username = username;
+ }
+
+ /** Sets the password for connecting to this CF-Style server.
+ * @param password Password for connecting to this CF-Style server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"password"})
+ public void setPassword(@NotNull final String password) {
+ this.password = password;
+ }
+
+ /** {@inheritDoc} */
+ // Overridden because for CF-Style servers the host is optional.
+ @Option({"host"})
+ public void setHost(@NotNull final String host) {
+ super.setHost(host);
+ }
+
+ @NotNull public String getUsername() {
+ return username;
+ }
+
+ @NotNull public String getPassword() {
+ return password;
+ }
+
+ @Nullable protected OutputStream getOut() {
+ return out;
+ }
+
+ @Nullable protected InputStream getIn() {
+ return in;
+ }
+} // class AbstractCFConnection
Property changes on: trunk/src/net/sf/cherbot/connection/AbstractCFConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Copied: trunk/src/net/sf/cherbot/connection/AbstractChannel.java (from rev 108, trunk/src/net/sf/cherbot/AbstractChannel.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/AbstractChannel.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/AbstractChannel.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.Nullable;
+
+/** Abstract base implementation of {@link Channel}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractChannel implements Channel {
+
+ /** The name of this channel.
+ * Maybe <code>null</code> if it's the default / no channel.
+ */
+ @Nullable private String channelName;
+
+ /** Creates a Channel.
+ * @param channelName name of this channel.
+ */
+ protected AbstractChannel(@Nullable final String channelName) {
+ this.channelName = channelName;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable public String getChannelName() {
+ return channelName;
+ }
+
+} // class Channel
Property changes on: trunk/src/net/sf/cherbot/connection/AbstractChannel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Copied: trunk/src/net/sf/cherbot/connection/AbstractConnection.java (from rev 108, trunk/src/net/sf/cherbot/AbstractConnection.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/AbstractConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/AbstractConnection.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.Socket;
+import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.Option;
+import net.sf.japi.io.args.OptionType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** An AbstractConnection represents the connection to a server and has one or more channels.
+ * Connections are implemented as command bean.
+ * That means:
+ * <ul>
+ * <li>
+ * An object does not reflect an established connection but has a state.
+ * The connection state can be established or not established.
+ * </li>
+ * <li>
+ * For testing, trying or standalone usage it is possible to "run" a connection as a standalone java program from the command line.
+ * </li>
+ * </ul>
+ * To query whether the connection is open, get the Socket of the connection and check the socket.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractConnection extends BasicCommand implements Closeable, Serializable {
+
+ /** The host to connect to.
+ * @serial include
+ */
+ @Nullable private String host;
+
+ /** The port to connect to.
+ * @serial include
+ */
+ private int port;
+
+ /** The socket for the connection. */
+ @Nullable private transient Socket socket;
+
+ /** Sets the host of the IRC server to connect to.
+ * @param host Host of the IRC server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"host"})
+ public void setHost(@NotNull final String host) {
+ this.host = host;
+ }
+
+ /** Returns the host to connect to.
+ * @return The host to connect to.
+ */
+ @Nullable public String getHost() {
+ return host;
+ }
+
+ /** Sets the port of the IRC server to connect to.
+ * @param port Port of the IRC server.
+ */
+ @Option({"port"})
+ public void setPort(@NotNull final Integer port) {
+ this.port = port;
+ }
+
+ /** Returns the port to connect to.
+ * @return The port to connect to.
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /** Establishes this connection.
+ * Implementations of this method must invoke {@link #setSocket(Socket)}.
+ * @return The socket created for this connection.
+ * @throws IOException in case of connection problems.
+ */
+ @NotNull public Socket connect() throws IOException {
+ final Socket socket = new Socket(host, port);
+ setSocket(socket);
+ return socket;
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ try {
+ final Socket socket = this.socket;
+ if (socket != null) {
+ socket.close();
+ }
+ } finally {
+ socket = null;
+ }
+ }
+
+ /** Returns whether this connection is established.
+ * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
+ * @see Socket#isConnected()
+ */
+ public boolean isConnected() {
+ return socket != null && socket.isConnected();
+ }
+
+ /** Sets the socket for the connection.
+ * Use this method if you want to create a connection on an existing socket instead of letting this Connection automatically create its own socket.
+ * @param socket Socket for the connection.
+ * @throws IOException In case of I/O problems when setting the socket. This is useful for overriding methods which may be interested in using the socket when it's being set.
+ */
+ public void setSocket(@NotNull final Socket socket) throws IOException {
+ this.socket = socket;
+ }
+
+ /** Returns the socket for the connection.
+ * @return The socket for the connection.
+ */
+ @Nullable public Socket getSocket() {
+ return socket;
+ }
+
+} // class AbstractConnection
Property changes on: trunk/src/net/sf/cherbot/connection/AbstractConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Copied: trunk/src/net/sf/cherbot/connection/Channel.java (from rev 108, trunk/src/net/sf/cherbot/Channel.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/Channel.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/Channel.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A Channel uniquely identifies a protocol (type) / server / channel combination.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface Channel {
+
+ /** Sends a message to this channel.
+ * @param msg Message to send
+ */
+ void send(@NotNull String msg);
+
+ /** Returns the name of this channel.
+ * Maybe <code>null</code> if it's the default / no channel.
+ * @return The channel of this channel or <code>null</code> if default / no channel.
+ */
+ @Nullable String getChannelName();
+
+} // interface Channel
Property changes on: trunk/src/net/sf/cherbot/connection/Channel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Copied: trunk/src/net/sf/cherbot/connection/CrossfireConnection.java (from rev 111, trunk/src/net/sf/cherbot/CrossfireConnection.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/CrossfireConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/CrossfireConnection.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.List;
+import net.sf.japi.io.args.ArgParser;
+import org.jetbrains.annotations.NotNull;
+
+/** A CrossfireConnection represents a connection to a Crossfire server.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class CrossfireConnection extends AbstractCFConnection {
+
+ /** Default server host. */
+ //@NotNull public static final String DEFAULT_CROSSFIRE_HOST = "crossfire.metalforge.net";
+ @NotNull public static final String DEFAULT_CROSSFIRE_HOST = "127.0.0.1";
+
+ /** Default server port. */
+ public static final int DEFAULT_CROSSFIRE_PORT = 13327;
+
+ /** Creates a CrossfireConnection. */
+ public CrossfireConnection() {
+ setHost(DEFAULT_CROSSFIRE_HOST);
+ setPort(DEFAULT_CROSSFIRE_PORT);
+ }
+
+ /** Main program.
+ * @param args Command line arguments.
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new CrossfireConnection(), args);
+ }
+
+ /** {@inheritDoc} */
+ @NotNull @Override public Socket connect() throws IOException {
+ final Socket socket = super.connect();
+ readToNull();
+ textMsg("version 1023 1023 CherBot");
+ textMsg("setup bot 1");
+ readToNull();
+ readToNull();
+ textMsg("addme");
+ readToNull();
+ textMsg("reply " + getUsername());
+ readToNull();
+ textMsg("reply " + getPassword());
+ return socket;
+ }
+
+ /** {@inheritDoc} */
+ public int run(@NotNull final List<String> args) throws Exception {
+ connect();
+ for (int i = 0; i < 10000; i++) {
+ readToNull();
+ }
+ close();
+ return 0;
+ }
+
+} // class CrossfireConnection
Property changes on: trunk/src/net/sf/cherbot/connection/CrossfireConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Copied: trunk/src/net/sf/cherbot/connection/DaimoninConnection.java (from rev 111, trunk/src/net/sf/cherbot/DaimoninConnection.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/DaimoninConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/DaimoninConnection.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.List;
+import net.sf.japi.io.args.ArgParser;
+import org.jetbrains.annotations.NotNull;
+
+/** A DaimoninConnection represents a connection to a Daimonin server.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class DaimoninConnection extends AbstractCFConnection {
+
+ /** Default server host. */
+ //@NotNull public static final String DEFAULT_DAIMONIN_HOST = "daimonin.game-server.cc";
+ @NotNull public static final String DEFAULT_DAIMONIN_HOST = "127.0.0.1";
+
+ /** Default server port. */
+ public static final int DEFAULT_DAIMONIN_PORT = 13327;
+
+ /** Creates a DaimoninConnection. */
+ public DaimoninConnection() {
+ setHost(DEFAULT_DAIMONIN_HOST);
+ setPort(DEFAULT_DAIMONIN_PORT);
+ }
+
+ /** Main program.
+ * @param args Command line arguments.
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new DaimoninConnection(), args);
+ }
+
+ /** {@inheritDoc} */
+ @NotNull @Override public Socket connect() throws IOException {
+ final Socket socket = super.connect();
+ readToNull(); // "991023 991023 Daimonin Server"
+ textMsg("version 991023 991023 Daimonin SDL Client"); // we have to cheat or the server won't let us in.
+ textMsg("setup bot 1"); // We are a bot
+ readToNull(); // "0x17 bot FALSE"
+ textMsg("addme");
+ readToNull(); // 0x00 0x06 0x18 "4 QNO"
+ readToNull(); // 0x00 0x01 0x15
+ textMsg("reply L" + getUsername());
+ readToNull(); // 0x00 0x06 0x18 "4 QP0"
+ textMsg("reply " + getPassword());
+ return socket;
+ }
+
+ /** {@inheritDoc} */
+ public int run(@NotNull final List<String> args) throws Exception {
+ connect();
+ Thread.sleep(100000);
+ close();
+ return 0;
+ }
+
+} // class DaimoninConnection
Property changes on: trunk/src/net/sf/cherbot/connection/DaimoninConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Copied: trunk/src/net/sf/cherbot/connection/IRCConnection.java (from rev 110, trunk/src/net/sf/cherbot/IRCConnection.java)
===================================================================
--- trunk/src/net/sf/cherbot/connection/IRCConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/IRCConnection.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,270 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot.connection;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import net.sf.cherbot.redel.PatternDelegator;
+import net.sf.cherbot.redel.Patterns;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.Option;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** An IRCConnection represents a connection to an IRC server.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc2812.txt">RFC 2812: Internet Relay Chat: Client Protocol</a>
+ */
+public class IRCConnection extends AbstractConnection {
+
+ /** The default IRC port. */
+ public static final int DEFAULT_IRC_PORT = 6667;
+
+ /** The username to use for IRC authentication.
+ * This is the IRC username, not the IRC nick.
+ */
+ @NotNull private String username = "cherbot";
+
+ /** The realname to use for IRC authentication.
+ * This is the realname, not the IRC nick.
+ */
+ @NotNull private String realname = "CherBot";
+
+ /** The nickname to use for IRC. */
+ @NotNull private String nickname = "CherBot";
+
+ /** The password to authenticate with NickServ or <code>null</code> if no authentication is desired. */
+ @Nullable private String nickPassword;
+
+ /** The PrintStream to write to. */
+ @Nullable private PrintWriter out;
+
+ /** The BufferedReader to read from. */
+ @Nullable private BufferedReader in;
+
+ /** The channels of this connection. */
+ private Map<String, IRCChannel> channels = new HashMap<String, IRCChannel>();
+
+ /** Creates an IRCConnection. */
+ public IRCConnection() {
+ setPort(DEFAULT_IRC_PORT);
+ }
+
+ /** Main program.
+ * For testing purposes.
+ * @param args Command line arguments
+ * @throws IOException In case of I/O problems.
+ */
+ public static void main(final String... args) throws IOException {
+ ArgParser.simpleParseAndRun(new IRCConnection(), args);
+ }
+
+ /** {@inheritDoc} */
+ @Override @NotNull public Socket connect() throws IOException {
+ final Socket socket = super.connect();
+ final PrintWriter out = this.out;
+ assert this.out != null;
+ out.println("USER " + username + " 0 * :" + realname);
+ out.println("NICK " + nickname);
+ if (nickPassword != null) {
+ out.println("PRIVMSG NICKSERV :IDENTIFY " + nickPassword);
+ }
+ out.flush();
+ return socket;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
+ channels.clear();
+ try {
+ super.close();
+ } finally {
+ in = null;
+ out = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setSocket(@NotNull final Socket socket) throws IOException {
+ super.setSocket(socket);
+ out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8"));
+ in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8"));
+ }
+
+ /** {@inheritDoc} */
+ public int run(@NotNull final List<String> args) throws Exception {
+ connect();
+ try {
+ final PrintWriter out = this.out;
+ assert out != null;
+ final BufferedReader in = this.in;
+ assert in != null;
+ for (final String channelName : args) {
+ join(channelName);
+ }
+ final PatternDelegator delegator = new PatternDelegator(this);
+ for (String line; (line = in.readLine()) != null;) {
+ System.out.print("> ");
+ System.out.println(line);
+ delegator.process(line);
+ }
+ return 0;
+ } finally {
+ close();
+ }
+ }
+
+ /** Processes an INVITE irc message.
+ * @param actor Actor of this JOIN.
+ * @param actorIdentity Identity of the actor.
+ * @param target Target of the invitation.
+ * @param channel Channel to join.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) INVITE ([^ ]+) :(.*)$"})
+ public void processINVITE(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String target, @NotNull final String channel) {
+ System.err.println("Received invitation to " + target + " at " + channel + " by " + actor + " (" + actorIdentity + ")");
+ join(channel);
+ }
+
+ /** Processes a JOIN irc message.
+ * @param actor Actor of this JOIN.
+ * @param actorIdentity Identity of the actor.
+ * @param channel Channel to join.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) JOIN :(.*)$"})
+ public void processJOIN(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channel) {
+ System.err.println("Joined channel " + channel);
+ // Nothing to do for a JOIN.
+ }
+
+ /** Process a MODE irc message.
+ * @param actor Actor of this MODE.
+ * @param actorIdentity Identity of the actor.
+ * @param channel Channel of the mode change.
+ * @param change Mode change.
+ * @param target Target of the mode change.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) MODE ([^ ]+) ([^ ]+) (.*?) ?$"})
+ public void processMODE(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channel, @NotNull final String change, @NotNull final String target) {
+ System.err.println("Mode change at " + channel + ": " + change + " on " + target + " by " + actor + " (" + actorIdentity + ")");
+ // Nothing to do for a MODE.
+ }
+
+ /** Processes a PING irc message.
+ * @param server Server that requests a PONG.
+ */
+ @Patterns({"^PING :(.*)$"})
+ public void processPING(@NotNull final String server) {
+ final PrintWriter out = this.out;
+ if (out != null) {
+ out.println("PONG " + server);
+ out.flush();
+ }
+ }
+
+ /** Processes a PRIVMSG irc message.
+ * @param actor Actor of this message.
+ * @param actorIdentity Identity of the actor.
+ * @param channelName Name of the channel.
+ * @param message Message text.
+ */
+ @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);
+ }
+
+ /** Joins an IRC channel.
+ * @param rawChannelName name of the channel to join.
+ * @return The channel that was just joined.
+ */
+ public Channel join(@NotNull final String rawChannelName) {
+ final String channelName = rawChannelName.toLowerCase();
+ final PrintWriter out = this.out;
+ 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;
+ }
+
+ /** Sets the username to use for connecting to the IRC server.
+ * Note that this is the IRC username, not the nick.
+ * @param username Username to use for IRC.
+ */
+ @Option({"username"})
+ public void setUsername(@NotNull final String username) {
+ this.username = username;
+ }
+
+ /** Sets the realname to use for connecting to the IRC server.
+ * Note that this is the IRC realname, not the nick.
+ * @param realname Realname to use for IRC.
+ */
+ @Option({"realname"})
+ public void setRealname(@NotNull final String realname) {
+ this.realname = realname;
+ }
+
+ /** Sets the nickname to use for connecting to the IRC server.
+ * @param nickname Nickname to use for IRC.
+ */
+ @Option({"nickname"})
+ public void setNickname(@NotNull final String nickname) {
+ this.nickname = nickname;
+ }
+
+ /** Sets the password to use for authentication with NickServ.
+ * Setting it to <code>null</code> means to not authenticate with NickServ.
+ * @param nickPassword Password to use for authentication with NickServ.
+ */
+ @Option({"nickPassword"})
+ public void setNickPassword(@Nullable final String nickPassword) {
+ this.nickPassword = nickPassword;
+ }
+
+ /** 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>
+ */
+ private class IRCChannel extends AbstractChannel {
+
+ /** Creates an IRCChannel.
+ * @param channelName name of this channel.
+ */
+ IRCChannel(@NotNull final String channelName) {
+ super(channelName);
+ }
+
+ /** {@inheritDoc} */
+ public void send(@NotNull final String msg) {
+ final PrintWriter out = IRCConnection.this.out;
+ if (out != null) {
+ out.println("PRIVMSG " + getChannelName() + " :" + msg);
+ out.flush();
+ }
+ }
+
+ } // class IRCChannel
+
+} // class IRCConnection
Property changes on: trunk/src/net/sf/cherbot/connection/IRCConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/connection/package-info.java
===================================================================
--- trunk/src/net/sf/cherbot/connection/package-info.java (rev 0)
+++ trunk/src/net/sf/cherbot/connection/package-info.java 2007-07-01 17:36:00 UTC (rev 112)
@@ -0,0 +1,10 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+/** Connection and Channel related stuff.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+package net.sf.cherbot.connection;
Property changes on: trunk/src/net/sf/cherbot/connection/package-info.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-30 20:13:00
|
Revision: 111
http://svn.sourceforge.net/cherbot/?rev=111&view=rev
Author: christianhujer
Date: 2007-06-30 13:12:40 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Encapsulated fields.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/AbstractCFConnection.java
trunk/src/net/sf/cherbot/CrossfireConnection.java
trunk/src/net/sf/cherbot/DaimoninConnection.java
Modified: trunk/src/net/sf/cherbot/AbstractCFConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractCFConnection.java 2007-06-30 19:48:13 UTC (rev 110)
+++ trunk/src/net/sf/cherbot/AbstractCFConnection.java 2007-06-30 20:12:40 UTC (rev 111)
@@ -24,16 +24,16 @@
public abstract class AbstractCFConnection extends AbstractConnection {
/** The username to authenticate with. */
- @NotNull protected String username;
+ @NotNull private String username;
/** The password to authenticate with. */
- @NotNull protected String password;
+ @NotNull private String password;
/** The PrintStream to write to. */
- @Nullable protected OutputStream out;
+ @Nullable private OutputStream out;
/** The BufferedReader to read from. */
- @Nullable protected InputStream in;
+ @Nullable private InputStream in;
/** Creates an AbstractCFConnection. */
protected AbstractCFConnection() {
@@ -123,4 +123,19 @@
super.setHost(host);
}
+ @NotNull public String getUsername() {
+ return username;
+ }
+
+ @NotNull public String getPassword() {
+ return password;
+ }
+
+ @Nullable protected OutputStream getOut() {
+ return out;
+ }
+
+ @Nullable protected InputStream getIn() {
+ return in;
+ }
} // class AbstractCFConnection
Modified: trunk/src/net/sf/cherbot/CrossfireConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-30 19:48:13 UTC (rev 110)
+++ trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-30 20:12:40 UTC (rev 111)
@@ -47,9 +47,9 @@
readToNull();
textMsg("addme");
readToNull();
- textMsg("reply " + username);
+ textMsg("reply " + getUsername());
readToNull();
- textMsg("reply " + password);
+ textMsg("reply " + getPassword());
return socket;
}
Modified: trunk/src/net/sf/cherbot/DaimoninConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-30 19:48:13 UTC (rev 110)
+++ trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-30 20:12:40 UTC (rev 111)
@@ -47,9 +47,9 @@
textMsg("addme");
readToNull(); // 0x00 0x06 0x18 "4 QNO"
readToNull(); // 0x00 0x01 0x15
- textMsg("reply L" + username);
+ textMsg("reply L" + getUsername());
readToNull(); // 0x00 0x06 0x18 "4 QP0"
- textMsg("reply " + password);
+ textMsg("reply " + getPassword());
return socket;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-30 19:48:15
|
Revision: 110
http://svn.sourceforge.net/cherbot/?rev=110&view=rev
Author: christianhujer
Date: 2007-06-30 12:48:13 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Implemented more IRC commands: INVITE, JOIN, MODE.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/IRCConnection.java
Modified: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-30 19:17:43 UTC (rev 109)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-30 19:48:13 UTC (rev 110)
@@ -115,6 +115,7 @@
}
final PatternDelegator delegator = new PatternDelegator(this);
for (String line; (line = in.readLine()) != null;) {
+ System.out.print("> ");
System.out.println(line);
delegator.process(line);
}
@@ -124,6 +125,54 @@
}
}
+ /** Processes an INVITE irc message.
+ * @param actor Actor of this JOIN.
+ * @param actorIdentity Identity of the actor.
+ * @param target Target of the invitation.
+ * @param channel Channel to join.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) INVITE ([^ ]+) :(.*)$"})
+ public void processINVITE(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String target, @NotNull final String channel) {
+ System.err.println("Received invitation to " + target + " at " + channel + " by " + actor + " (" + actorIdentity + ")");
+ join(channel);
+ }
+
+ /** Processes a JOIN irc message.
+ * @param actor Actor of this JOIN.
+ * @param actorIdentity Identity of the actor.
+ * @param channel Channel to join.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) JOIN :(.*)$"})
+ public void processJOIN(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channel) {
+ System.err.println("Joined channel " + channel);
+ // Nothing to do for a JOIN.
+ }
+
+ /** Process a MODE irc message.
+ * @param actor Actor of this MODE.
+ * @param actorIdentity Identity of the actor.
+ * @param channel Channel of the mode change.
+ * @param change Mode change.
+ * @param target Target of the mode change.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) MODE ([^ ]+) ([^ ]+) (.*?) ?$"})
+ public void processMODE(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channel, @NotNull final String change, @NotNull final String target) {
+ System.err.println("Mode change at " + channel + ": " + change + " on " + target + " by " + actor + " (" + actorIdentity + ")");
+ // Nothing to do for a MODE.
+ }
+
+ /** Processes a PING irc message.
+ * @param server Server that requests a PONG.
+ */
+ @Patterns({"^PING :(.*)$"})
+ public void processPING(@NotNull final String server) {
+ final PrintWriter out = this.out;
+ if (out != null) {
+ out.println("PONG " + server);
+ out.flush();
+ }
+ }
+
/** Processes a PRIVMSG irc message.
* @param actor Actor of this message.
* @param actorIdentity Identity of the actor.
@@ -141,18 +190,6 @@
System.out.println(channel);
}
- /** Processes a PING irc message.
- * @param server Server that requests a PONG.
- */
- @Patterns({"^PING :(.*)$"})
- public void processPING(@NotNull final String server) {
- final PrintWriter out = this.out;
- if (out != null) {
- out.println("PONG " + server);
- out.flush();
- }
- }
-
/** Joins an IRC channel.
* @param rawChannelName name of the channel to join.
* @return The channel that was just joined.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-30 19:17:45
|
Revision: 109
http://svn.sourceforge.net/cherbot/?rev=109&view=rev
Author: christianhujer
Date: 2007-06-30 12:17:43 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Extracted common code of CrossfireConnection and DaimoninConnection into a superclass.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/CrossfireConnection.java
trunk/src/net/sf/cherbot/DaimoninConnection.java
Added Paths:
-----------
trunk/src/net/sf/cherbot/AbstractCFConnection.java
Added: trunk/src/net/sf/cherbot/AbstractCFConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractCFConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/AbstractCFConnection.java 2007-06-30 19:17:43 UTC (rev 109)
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.BufferedOutputStream;
+import java.net.Socket;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
+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.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractCFConnection extends AbstractConnection {
+
+ /** The username to authenticate with. */
+ @NotNull protected String username;
+
+ /** The password to authenticate with. */
+ @NotNull protected String password;
+
+ /** The PrintStream to write to. */
+ @Nullable protected OutputStream out;
+
+ /** The BufferedReader to read from. */
+ @Nullable protected InputStream in;
+
+ /** Creates an AbstractCFConnection. */
+ protected AbstractCFConnection() {
+ }
+
+ /** Reads and discards a single message.
+ * @throws IOException In case of I/O problems.
+ */
+ protected void readToNull() throws IOException {
+ receivePacket();
+ }
+
+ /** Reads the next data packet.
+ * @throws IOException In case of I/O problems.
+ * @return The data of the next data packet.
+ */
+ @NotNull protected byte[] receivePacket() throws IOException {
+ final InputStream in = this.in;
+ assert in != null;
+ final int h1 = in.read();
+ final int length = h1 != -1 && (h1 & 0x80) == 0x80 ? h1 << 16 | in.read() << 8 | in.read() : h1 << 8 | in.read();
+ if (length == -1) {
+ throw new EOFException();
+ }
+ final byte[] data = new byte[length];
+ for (int read = 0; read < length;) {
+ final int bytesRead = in.read(data, read, length - read);
+ if (bytesRead == -1) {
+ throw new EOFException();
+ }
+ read += bytesRead;
+ }
+ return data;
+ }
+
+ /** Sends a simple text message.
+ * @param msg Message to send
+ * @throws IOException In case of I/O problems.
+ */
+ protected void textMsg(@NotNull final String msg) throws IOException {
+ final OutputStream out = this.out;
+ assert out != null;
+ final byte[] data = msg.getBytes("utf-8");
+ out.write(0xFF & data.length >> 8);
+ out.write(0xFF & data.length);
+ out.write(data);
+ out.flush();
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ try {
+ super.close();
+ } finally {
+ in = null;
+ out = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setSocket(@NotNull final Socket socket) throws IOException {
+ super.setSocket(socket);
+ out = new BufferedOutputStream(socket.getOutputStream());
+ in = socket.getInputStream();
+ }
+
+ /** Sets the username for connecting to this CF-Style server.
+ * @param username Username for connecting to this CF-Style server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"username"})
+ public void setUsername(@NotNull final String username) {
+ this.username = username;
+ }
+
+ /** Sets the password for connecting to this CF-Style server.
+ * @param password Password for connecting to this CF-Style server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"password"})
+ public void setPassword(@NotNull final String password) {
+ this.password = password;
+ }
+
+ /** {@inheritDoc} */
+ // Overridden because for CF-Style servers the host is optional.
+ @Option({"host"})
+ public void setHost(@NotNull final String host) {
+ super.setHost(host);
+ }
+
+} // class AbstractCFConnection
Property changes on: trunk/src/net/sf/cherbot/AbstractCFConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: trunk/src/net/sf/cherbot/CrossfireConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-30 18:32:48 UTC (rev 108)
+++ trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-30 19:17:43 UTC (rev 109)
@@ -6,23 +6,16 @@
package net.sf.cherbot;
-import java.io.BufferedOutputStream;
-import java.io.EOFException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.net.Socket;
import java.util.List;
import net.sf.japi.io.args.ArgParser;
-import net.sf.japi.io.args.Option;
-import net.sf.japi.io.args.OptionType;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
/** A CrossfireConnection represents a connection to a Crossfire server.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class CrossfireConnection extends AbstractConnection {
+public class CrossfireConnection extends AbstractCFConnection {
/** Default server host. */
//@NotNull public static final String DEFAULT_CROSSFIRE_HOST = "crossfire.metalforge.net";
@@ -31,18 +24,6 @@
/** Default server port. */
public static final int DEFAULT_CROSSFIRE_PORT = 13327;
- /** The username to authenticate with. */
- @NotNull private String username;
-
- /** The password to authenticate with. */
- @NotNull private String password;
-
- /** The PrintStream to write to. */
- @Nullable private OutputStream out;
-
- /** The BufferedReader to read from. */
- @Nullable private InputStream in;
-
/** Creates a CrossfireConnection. */
public CrossfireConnection() {
setHost(DEFAULT_CROSSFIRE_HOST);
@@ -72,68 +53,7 @@
return socket;
}
- /** Reads and discards a single message.
- * @throws IOException In case of I/O problems.
- */
- private void readToNull() throws IOException {
- receivePacket();
- }
-
- /** Reads the next data packet.
- * @throws IOException In case of I/O problems.
- * @return The data of the next data packet.
- */
- private byte[] receivePacket() throws IOException {
- final InputStream in = this.in;
- assert in != null;
- final int h1 = in.read();
- final int length = h1 != -1 && (h1 & 0x80) == 0x80 ? h1 << 16 | in.read() << 8 | in.read() : h1 << 8 | in.read();
- if (length == -1) {
- throw new EOFException();
- }
- final byte[] data = new byte[length];
- for (int read = 0; read < length;) {
- final int bytesRead = in.read(data, read, length - read);
- if (bytesRead == -1) {
- throw new EOFException();
- }
- read += bytesRead;
- }
- return data;
- }
-
- /** Sends a simple text message.
- * @param msg Message to send
- * @throws IOException In case of I/O problems.
- */
- private void textMsg(@NotNull final String msg) throws IOException {
- final OutputStream out = this.out;
- assert out != null;
- final byte[] data = msg.getBytes("utf-8");
- out.write(0xFF & data.length >> 8);
- out.write(0xFF & data.length);
- out.write(data);
- out.flush();
- }
-
/** {@inheritDoc} */
- public void close() throws IOException {
- try {
- super.close();
- } finally {
- in = null;
- out = null;
- }
- }
-
- /** {@inheritDoc} */
- @Override public void setSocket(@NotNull final Socket socket) throws IOException {
- super.setSocket(socket);
- out = new BufferedOutputStream(socket.getOutputStream());
- in = socket.getInputStream();
- }
-
- /** {@inheritDoc} */
public int run(@NotNull final List<String> args) throws Exception {
connect();
for (int i = 0; i < 10000; i++) {
@@ -143,27 +63,4 @@
return 0;
}
- /** Sets the username for connecting to this Crossfire server.
- * @param username Username for connecting to this Crossfire server.
- */
- @Option(type = OptionType.REQUIRED, value = {"username"})
- public void setUsername(@NotNull final String username) {
- this.username = username;
- }
-
- /** Sets the password for connecting to this Crossfire server.
- * @param password Password for connecting to this Crossfire server.
- */
- @Option(type = OptionType.REQUIRED, value = {"password"})
- public void setPassword(@NotNull final String password) {
- this.password = password;
- }
-
- /** {@inheritDoc} */
- // Overridden because for Crossfire the host is optional.
- @Option({"host"})
- public void setHost(@NotNull final String host) {
- super.setHost(host);
- }
-
} // class CrossfireConnection
Modified: trunk/src/net/sf/cherbot/DaimoninConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-30 18:32:48 UTC (rev 108)
+++ trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-30 19:17:43 UTC (rev 109)
@@ -6,23 +6,16 @@
package net.sf.cherbot;
-import java.io.BufferedOutputStream;
-import java.io.EOFException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.net.Socket;
import java.util.List;
import net.sf.japi.io.args.ArgParser;
-import net.sf.japi.io.args.Option;
-import net.sf.japi.io.args.OptionType;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
/** A DaimoninConnection represents a connection to a Daimonin server.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class DaimoninConnection extends AbstractConnection {
+public class DaimoninConnection extends AbstractCFConnection {
/** Default server host. */
//@NotNull public static final String DEFAULT_DAIMONIN_HOST = "daimonin.game-server.cc";
@@ -31,18 +24,6 @@
/** Default server port. */
public static final int DEFAULT_DAIMONIN_PORT = 13327;
- /** The username to authenticate with. */
- @NotNull private String username;
-
- /** The password to authenticate with. */
- @NotNull private String password;
-
- /** The PrintStream to write to. */
- @Nullable private OutputStream out;
-
- /** The BufferedReader to read from. */
- @Nullable private InputStream in;
-
/** Creates a DaimoninConnection. */
public DaimoninConnection() {
setHost(DEFAULT_DAIMONIN_HOST);
@@ -59,9 +40,6 @@
/** {@inheritDoc} */
@NotNull @Override public Socket connect() throws IOException {
final Socket socket = super.connect();
- this.out = new BufferedOutputStream(socket.getOutputStream());
- this.in = socket.getInputStream();
-
readToNull(); // "991023 991023 Daimonin Server"
textMsg("version 991023 991023 Daimonin SDL Client"); // we have to cheat or the server won't let us in.
textMsg("setup bot 1"); // We are a bot
@@ -75,61 +53,7 @@
return socket;
}
- /** Reads and discards a single message.
- * @throws IOException In case of I/O problems.
- */
- private void readToNull() throws IOException {
- receivePacket();
- }
-
- /** Reads the next data packet.
- * @throws IOException In case of I/O problems.
- * @return The data of the next data packet.
- */
- private byte[] receivePacket() throws IOException {
- final InputStream in = this.in;
- assert in != null;
- final int h1 = in.read();
- final int length = h1 != -1 && (h1 & 0x80) == 0x80 ? h1 << 16 | in.read() << 8 | in.read() : h1 << 8 | in.read();
- if (length == -1) {
- throw new EOFException();
- }
- final byte[] data = new byte[length];
- for (int read = 0; read < length;) {
- final int bytesRead = in.read(data, read, length - read);
- if (bytesRead == -1) {
- throw new EOFException();
- }
- read += bytesRead;
- }
- return data;
- }
-
- /** Sends a simple text message.
- * @param msg Message to send
- * @throws IOException In case of I/O problems.
- */
- private void textMsg(@NotNull final String msg) throws IOException {
- final OutputStream out = this.out;
- assert out != null;
- final byte[] data = msg.getBytes("utf-8");
- out.write(0xFF & data.length >> 8);
- out.write(0xFF & data.length);
- out.write(data);
- out.flush();
- }
-
/** {@inheritDoc} */
- public void close() throws IOException {
- try {
- super.close();
- } finally {
- in = null;
- out = null;
- }
- }
-
- /** {@inheritDoc} */
public int run(@NotNull final List<String> args) throws Exception {
connect();
Thread.sleep(100000);
@@ -137,27 +61,4 @@
return 0;
}
- /** Sets the username for connecting to this Daimonin server.
- * @param username Username for connecting to this Daimonin server.
- */
- @Option(type = OptionType.REQUIRED, value = {"username"})
- public void setUsername(@NotNull final String username) {
- this.username = username;
- }
-
- /** Sets the password for connecting to this Daimonin server.
- * @param password Password for connecting to this Daimonin server.
- */
- @Option(type = OptionType.REQUIRED, value = {"password"})
- public void setPassword(@NotNull final String password) {
- this.password = password;
- }
-
- /** {@inheritDoc} */
- // Overridden because for Daimonin the host is optional.
- @Option({"host"})
- public void setHost(@NotNull final String host) {
- super.setHost(host);
- }
-
} // class DaimoninConnection
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-30 18:32:53
|
Revision: 108
http://svn.sourceforge.net/cherbot/?rev=108&view=rev
Author: christianhujer
Date: 2007-06-30 11:32:48 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Added Configurator. Unfinished.
Added Paths:
-----------
trunk/src/net/sf/cherbot/Configurator.java
Added: trunk/src/net/sf/cherbot/Configurator.java
===================================================================
--- trunk/src/net/sf/cherbot/Configurator.java (rev 0)
+++ trunk/src/net/sf/cherbot/Configurator.java 2007-06-30 18:32:48 UTC (rev 108)
@@ -0,0 +1,23 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot;
+
+import net.sf.japi.io.args.BasicCommand;
+import org.jetbrains.annotations.NotNull;
+import java.util.List;
+
+/** The Configurator creates or modifies the initial server database for CherBot.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class Configurator extends BasicCommand {
+
+ /** {@inheritDoc} */
+ public int run(@NotNull final List<String> args) throws Exception {
+ return 0;
+ }
+
+} // class Configurator
Property changes on: trunk/src/net/sf/cherbot/Configurator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-30 18:31:12
|
Revision: 107
http://svn.sourceforge.net/cherbot/?rev=107&view=rev
Author: christianhujer
Date: 2007-06-30 11:31:09 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Cosmetic - ignore.
Modified Paths:
--------------
trunk/cherbot.ipr
Modified: trunk/cherbot.ipr
===================================================================
--- trunk/cherbot.ipr 2007-06-30 18:30:12 UTC (rev 106)
+++ trunk/cherbot.ipr 2007-06-30 18:31:09 UTC (rev 107)
@@ -84,6 +84,7 @@
<entry name="?*.jpg" />
</wildcardResourcePatterns>
</component>
+ <component name="CppTools.Loader" warnedAboutFileOutOfSourceRoot="true" />
<component name="DataSourceManagerImpl" />
<component name="DependenciesAnalyzeManager">
<option name="myForwardDirection" value="false" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-30 18:30:15
|
Revision: 106
http://svn.sourceforge.net/cherbot/?rev=106&view=rev
Author: christianhujer
Date: 2007-06-30 11:30:12 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
Changed datamodel to architecture.
Modified Paths:
--------------
trunk/src/doc/start.xhtml
Added Paths:
-----------
trunk/src/doc/architecture.xhtml
Removed Paths:
-------------
trunk/src/doc/datamodel.xhtml
Copied: trunk/src/doc/architecture.xhtml (from rev 103, trunk/src/doc/datamodel.xhtml)
===================================================================
--- trunk/src/doc/architecture.xhtml (rev 0)
+++ trunk/src/doc/architecture.xhtml 2007-06-30 18:30:12 UTC (rev 106)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ ~ License: GNU General Public License v2.0 or newer.
+ ~ See file COPYING in the root directory of this project.
+ -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
+ <head>
+ <title>CherBot 2.0 Architecture</title>
+ </head>
+ <body>
+ <h1>CherBot 2.0 Architecture</h1>
+ <p>
+ This is a description of the architecture of CherBot 2.0.
+ </p>
+ <dl>
+ <dt id="Connection">Connection</dt>
+ <dd>
+ A connection represents an active relationship between CherBot and a <a href="#Server">Server</a>.
+ CherBot V2 currently supports Crossfire, Daimonin and IRC.
+ CherBot V2 supports multiple concurrent connections.
+ That means a single instance of CherBot can hold connections to any number of supported servers at the same time.
+ </dd>
+ <dt id="Database">Database</dt>
+ <dd>
+ CherBot now uses an SQL database through JDBC as persistent storage.
+ CherBot defaults to Derby, but CherBot's SQL should be simple enough to be easily portable to any other DB as well.
+ Eventually, CherBot's persistence code will get replaced by a standard for persistent storage like JPA or
+ </dd>
+ <dt id="Multithreading">Multithreading</dt>
+ <dd>
+ Because CherBot supports multiple <a href="#Connection">Connections</a> at the same time CherBot must support Multithreading.
+ That means access to critical resources that might be the subject of race conditions must be synchronized.
+ </dd>
+ <dt id="Server">Server</dt>
+ <dd>
+ A server represents an entity that CherBot can connect to for normal operation.
+ Usually a server will consist of a host and port describing the tcp socket to connect to plus the protocol for establishing a <a href="#Connection">Connection</a>.
+ </dd>
+ </dl>
+ </body>
+</html>
Property changes on: trunk/src/doc/architecture.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:eol-style
+ LF
Deleted: trunk/src/doc/datamodel.xhtml
===================================================================
--- trunk/src/doc/datamodel.xhtml 2007-06-29 20:23:48 UTC (rev 105)
+++ trunk/src/doc/datamodel.xhtml 2007-06-30 18:30:12 UTC (rev 106)
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
- ~ License: GNU General Public License v2.0 or newer.
- ~ See file COPYING in the root directory of this project.
- -->
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
- <head>
- <title>CherBot 2.0 Datamodel</title>
- </head>
- <body>
- <h1>CherBot 2.0 Datamodel</h1>
- <p>
- This is a description of the data model of CherBot 2.0.
- </p>
- </body>
-</html>
Modified: trunk/src/doc/start.xhtml
===================================================================
--- trunk/src/doc/start.xhtml 2007-06-29 20:23:48 UTC (rev 105)
+++ trunk/src/doc/start.xhtml 2007-06-30 18:30:12 UTC (rev 106)
@@ -80,5 +80,8 @@
We've setup a page describing <a href="requirements2.0">requirements</a> for the next major version of CherBot.
If you have any ideas and wishes for CherBot, please use our <a href="http://sourceforge.net/tracker/?group_id=180828&atid=894751">Feature Request Tracker</a> (go to <em>Submit New</em> there).
</p>
+ <p>
+ You can also already read about CherBot V2's <a href="architecture">architecture</a>.
+ </p>
</body>
</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-29 20:23:49
|
Revision: 105
http://svn.sourceforge.net/cherbot/?rev=105&view=rev
Author: christianhujer
Date: 2007-06-29 13:23:48 -0700 (Fri, 29 Jun 2007)
Log Message:
-----------
Cosmetic: Improved variable name.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/redel/PatternDelegator.java
Modified: trunk/src/net/sf/cherbot/redel/PatternDelegator.java
===================================================================
--- trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-29 19:11:37 UTC (rev 104)
+++ trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-29 20:23:48 UTC (rev 105)
@@ -35,8 +35,8 @@
for (final Method method : methods) {
@Nullable final Patterns patterns = method.getAnnotation(Patterns.class);
if (patterns != null) {
- for (final String expression : patterns.value()) {
- targetMethods.put(Pattern.compile(expression), method);
+ for (final String pattern : patterns.value()) {
+ targetMethods.put(Pattern.compile(pattern), method);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-29 19:11:41
|
Revision: 104
http://svn.sourceforge.net/cherbot/?rev=104&view=rev
Author: christianhujer
Date: 2007-06-29 12:11:37 -0700 (Fri, 29 Jun 2007)
Log Message:
-----------
Added missing @Target declaration. This annotation only makes sense for methods.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/redel/Patterns.java
Modified: trunk/src/net/sf/cherbot/redel/Patterns.java
===================================================================
--- trunk/src/net/sf/cherbot/redel/Patterns.java 2007-06-25 20:51:55 UTC (rev 103)
+++ trunk/src/net/sf/cherbot/redel/Patterns.java 2007-06-29 19:11:37 UTC (rev 104)
@@ -8,11 +8,14 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
/** Annotation for methods that should be automatically called when their regular expression matches.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
public @interface Patterns {
/** Returns the regular expressions that should match for this method to be invoked.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-25 20:51:58
|
Revision: 103
http://svn.sourceforge.net/cherbot/?rev=103&view=rev
Author: christianhujer
Date: 2007-06-25 13:51:55 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Fixed checkstyle issues.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/metaserver/MetaServerEntry.java
trunk/src/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java
Modified: trunk/src/net/sf/cherbot/metaserver/MetaServerEntry.java
===================================================================
--- trunk/src/net/sf/cherbot/metaserver/MetaServerEntry.java 2007-06-25 20:51:41 UTC (rev 102)
+++ trunk/src/net/sf/cherbot/metaserver/MetaServerEntry.java 2007-06-25 20:51:55 UTC (rev 103)
@@ -20,7 +20,7 @@
private static final long serialVersionUID = 1L;
/** The pattern for parsing an entryString from the metaserver. */
- @NotNull private static final Pattern entryPattern = Pattern.compile("(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)");
+ @NotNull private static final Pattern ENTRY_PATTERN = Pattern.compile("(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)");
/** The ip address of this entry. */
@NotNull private final String ipaddress;
@@ -77,7 +77,7 @@
* @return MetaServerEntry created by parsing <var>entryString</var>.
*/
@NotNull public static MetaServerEntry parse(@NotNull final String entryString) {
- final Matcher matcher = entryPattern.matcher(entryString);
+ final Matcher matcher = ENTRY_PATTERN.matcher(entryString);
if (matcher.matches()) {
return new MetaServerEntry(
matcher.group(1),
Modified: trunk/src/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java
===================================================================
--- trunk/src/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java 2007-06-25 20:51:41 UTC (rev 102)
+++ trunk/src/test/net/sf/cherbot/metaserver/MetaServerInfoTest.java 2007-06-25 20:51:55 UTC (rev 103)
@@ -29,8 +29,8 @@
* @throws IOException in case of I/O problems (unexpected).
*/
@Test public void testParse() throws IOException {
- final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n" +
- "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
+ final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n"
+ + "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
final MetaServerInfo testling = new MetaServerInfo();
testling.parse(new BufferedReader(new StringReader(metaServerString)));
Assert.assertEquals("MetaServerInfo now must contain 2 entries.", 2, testling.size());
@@ -42,8 +42,8 @@
* @throws IOException in case of I/O problems (unexpected).
*/
@Test public void testParseDeletes() throws IOException {
- final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n" +
- "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
+ final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n"
+ + "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
final MetaServerInfo testling = new MetaServerInfo();
testling.parse(new BufferedReader(new StringReader(metaServerString)));
Assert.assertEquals("MetaServerInfo now must contain 2 entries.", 2, testling.size());
@@ -55,8 +55,8 @@
* @throws IOException in case of I/O problems (unexpected).
*/
@Test public void testUpdate() throws IOException {
- final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n" +
- "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
+ final String metaServerString = "192.168.0.1|177|riedquat|20|0.9.7|My own Daimonin server.|02|03|04\n"
+ + "192.168.0.2|177|lave|20|0.9.7|My other Daimonin server.|02|03|04\n";
final MetaServerInfo testling = new MetaServerInfo("", 0);
testling.parse(new BufferedReader(new StringReader(metaServerString)));
Assert.assertEquals("MetaServerInfo now must contain 2 entries.", 2, testling.size());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-25 20:51:43
|
Revision: 102
http://svn.sourceforge.net/cherbot/?rev=102&view=rev
Author: christianhujer
Date: 2007-06-25 13:51:41 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Added checkstyle task / target.
Modified Paths:
--------------
trunk/build.xml
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2007-06-25 20:50:58 UTC (rev 101)
+++ trunk/build.xml 2007-06-25 20:51:41 UTC (rev 102)
@@ -155,4 +155,13 @@
</junit>
</target>
+ <target name="checkstyle" description="Runs checkstyle over the source code.">
+ <taskdef classpath="common/antlib/checkstyle-all-4.3.jar" resource="checkstyletask.properties" />
+ <checkstyle
+ config="common/sun_checks.xml"
+ >
+ <fileset dir="src" includes="**/*.java,**/*.properties" />
+ </checkstyle>
+ </target>
+
</project>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-25 20:51:00
|
Revision: 101
http://svn.sourceforge.net/cherbot/?rev=101&view=rev
Author: christianhujer
Date: 2007-06-25 13:50:58 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Added common external from JAPI.
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svn:externals
+ common https://japi.svn.sourceforge.net/svnroot/japi/common/trunk
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-25 19:18:51
|
Revision: 100
http://svn.sourceforge.net/cherbot/?rev=100&view=rev
Author: christianhujer
Date: 2007-06-25 12:18:47 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Cosmetic: Renamed and moved field.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/CherBot.java
Modified: trunk/src/net/sf/cherbot/CherBot.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBot.java 2007-06-25 11:25:11 UTC (rev 99)
+++ trunk/src/net/sf/cherbot/CherBot.java 2007-06-25 19:18:47 UTC (rev 100)
@@ -30,6 +30,9 @@
/** The database URL. */
@NotNull private String databaseURL = DEFAULT_DATABASE_URL;
+ /** The JDBC connection for data persistence. */
+ @NotNull private Connection connection;
+
/** Create an instance of CherBot. */
public CherBot() {
modules.add(new ServerModule());
@@ -44,13 +47,10 @@
ArgParser.simpleParseAndRun(new CherBot(), args);
}
- /** The JDBC connection for data persistence. */
- @NotNull private Connection con;
-
/** {@inheritDoc} */
public int run(@NotNull final List<String> strings) throws Exception {
- con = DriverManager.getConnection(databaseURL);
- System.out.println(con);
+ connection = DriverManager.getConnection(databaseURL);
+ System.out.println(connection);
load();
return 0;
}
@@ -61,7 +61,7 @@
private void load() throws SQLException {
for (final Module module : modules) {
if (module instanceof PersistentModule) {
- ((PersistentModule) module).load(con);
+ ((PersistentModule) module).load(connection);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|