[Cherbot-commit] SF.net SVN: cherbot: [60] trunk
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-06-16 20:22:59
|
Revision: 60
http://svn.sourceforge.net/cherbot/?rev=60&view=rev
Author: christianhujer
Date: 2007-06-16 13:22:54 -0700 (Sat, 16 Jun 2007)
Log Message:
-----------
Added unfinnished framework for servers, channels, modules and commands.
Modified Paths:
--------------
trunk/cherbot.iml
trunk/cherbot.ipr
trunk/src/doc/requirements2.0.xhtml
trunk/src/net/sf/cherbot/CherBot.java
Added Paths:
-----------
trunk/src/doc/datamodel.xhtml
trunk/src/net/sf/cherbot/AbstractConnection.java
trunk/src/net/sf/cherbot/Channel.java
trunk/src/net/sf/cherbot/ClanModule.java
trunk/src/net/sf/cherbot/Command.java
trunk/src/net/sf/cherbot/EchoModule.java
trunk/src/net/sf/cherbot/IRCConnection.java
trunk/src/net/sf/cherbot/Module.java
trunk/src/net/sf/cherbot/PersistentModule.java
Modified: trunk/cherbot.iml
===================================================================
--- trunk/cherbot.iml 2007-06-16 11:07:54 UTC (rev 59)
+++ trunk/cherbot.iml 2007-06-16 20:22:54 UTC (rev 60)
@@ -39,6 +39,7 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="library" name="derby" level="project" />
<orderEntryProperties />
</component>
<component name="copyright">
Modified: trunk/cherbot.ipr
===================================================================
--- trunk/cherbot.ipr 2007-06-16 11:07:54 UTC (rev 59)
+++ trunk/cherbot.ipr 2007-06-16 20:22:54 UTC (rev 60)
@@ -1110,6 +1110,13 @@
<JAVADOC />
<SOURCES />
</library>
+ <library name="derby">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/../../../Documents/Downloads/jdk1.6.0_01/db/lib/derby.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
</component>
<component name="uidesigner-configuration" />
</project>
Added: trunk/src/doc/datamodel.xhtml
===================================================================
--- trunk/src/doc/datamodel.xhtml (rev 0)
+++ trunk/src/doc/datamodel.xhtml 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,18 @@
+<?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>
Property changes on: trunk/src/doc/datamodel.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:eol-style
+ LF
Modified: trunk/src/doc/requirements2.0.xhtml
===================================================================
--- trunk/src/doc/requirements2.0.xhtml 2007-06-16 11:07:54 UTC (rev 59)
+++ trunk/src/doc/requirements2.0.xhtml 2007-06-16 20:22:54 UTC (rev 60)
@@ -31,9 +31,15 @@
<li>CherBot must work for Daimonin.</li>
<li>CherBot must work for Crossfire.</li>
<li>CherBot must work for IRC.</li>
- <li>CherBot must be able to connect to more than one server.</li>
+ <li>CherBot must be able to connect to more than one daimonin server.</li>
+ <li>CherBot must be able to connect to more than one crossfire server.</li>
+ <li>CherBot must be able to connect to more than one irc server.</li>
+ <li>CherBot must be able to join more than one IRC channel.</li>
<li>CherBot must maintain groups called clans.</li>
<li>CherBot must be able to act as a communication proxy / multiplexer for members of a clan.</li>
+ <li>It must be possible to ask CherBot when a player was last seen on a specific server.</li>
+ <li>It must be possible to ask CherBot whether a player is currently online on a specific server.</li>
+ <li>CherBot must be able to log all communication.</li>
</ul>
</body>
</html>
Added: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,14 @@
+/*
+ * 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;
+
+/** A AbstractConnection represents the connection to a server and has one or more channels.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractConnection {
+
+} // class AbstractConnection
Property changes on: trunk/src/net/sf/cherbot/AbstractConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/Channel.java
===================================================================
--- trunk/src/net/sf/cherbot/Channel.java (rev 0)
+++ trunk/src/net/sf/cherbot/Channel.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,46 @@
+/*
+ * 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;
+import org.jetbrains.annotations.NotNull;
+
+/** A Channel uniquely identifies a protocol (type) / server / channel combination.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class Channel {
+
+ /** The types of channels. */
+ public static enum Type {
+
+ /** A Crossfire channel. */
+ CROSSFIRE,
+
+ /** A Daimonin channel. */
+ DAIMONIN,
+
+ /** An IRC channel. */
+ IRC
+ } // enum Type
+
+ /** The type of this channel. */
+ @NotNull private Type type;
+
+ /** The server of this channel. */
+ @NotNull private String server;
+
+ /** The channel of this channel.
+ * Maybe <code>null</code> if it's the default / no channel.
+ */
+ @Nullable private String channel;
+
+ /** Sends a message to this channel.
+ * @param msg Message to send
+ */
+ public abstract void send(@NotNull final String msg);
+
+} // class Channel
Property changes on: trunk/src/net/sf/cherbot/Channel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: trunk/src/net/sf/cherbot/CherBot.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBot.java 2007-06-16 11:07:54 UTC (rev 59)
+++ trunk/src/net/sf/cherbot/CherBot.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -8,6 +8,8 @@
import java.io.IOException;
import java.util.List;
+import java.sql.DriverManager;
+import java.sql.Connection;
import net.sf.japi.io.args.ArgParser;
import net.sf.japi.io.args.BasicCommand;
import org.jetbrains.annotations.NotNull;
@@ -24,8 +26,14 @@
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 {
+ //DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
+ con = DriverManager.getConnection("jdbc:derby:cherbotdb;create=true");
+ System.out.println(con);
return 0;
}
Added: trunk/src/net/sf/cherbot/ClanModule.java
===================================================================
--- trunk/src/net/sf/cherbot/ClanModule.java (rev 0)
+++ trunk/src/net/sf/cherbot/ClanModule.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,29 @@
+/*
+ * 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 java.sql.Connection;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ClanModule implements PersistentModule {
+
+ /** {@inheritDoc} */
+ public void load(@NotNull final Connection con) {
+ }
+
+ /** {@inheritDoc} */
+ public void save(@NotNull final Connection con) {
+ }
+
+ public void parseMessage(@NotNull Channel channel, @NotNull String msg) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+} // class ClanModule
Property changes on: trunk/src/net/sf/cherbot/ClanModule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/Command.java
===================================================================
--- trunk/src/net/sf/cherbot/Command.java (rev 0)
+++ trunk/src/net/sf/cherbot/Command.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,37 @@
+/*
+ * 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.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/** Annotation that marks a method as command method.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD})
+public @interface Command {
+
+ /** The regular expressions for executing this command.
+ * The number of groups must match the parameter count of the annotated method after its two mandatory parameters server and actor.
+ * @return Regular expressions for executing this command.
+ */
+ String[] values();
+
+ /** The description of this command.
+ * @return Description of this command.
+ */
+ String description();
+
+ /** The examples for this command.
+ * @return Examples for this command.
+ */
+ String examples();
+
+} // @interface Command
Property changes on: trunk/src/net/sf/cherbot/Command.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/EchoModule.java
===================================================================
--- trunk/src/net/sf/cherbot/EchoModule.java (rev 0)
+++ trunk/src/net/sf/cherbot/EchoModule.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,21 @@
+/*
+ * 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;
+
+/** Module that simply echoes a message.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class EchoModule implements Module {
+
+ /** {@inheritDoc} */
+ public void parseMessage(@NotNull final Channel channel, @NotNull final String msg) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+} // class EchoModule
Property changes on: trunk/src/net/sf/cherbot/EchoModule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,94 @@
+/*
+ * 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.regex.Pattern;
+import java.util.regex.Matcher;
+import org.jetbrains.annotations.NotNull;
+
+/** An IRCConnection represents a connection to an IRC server.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class IRCConnection extends AbstractConnection implements Runnable {
+
+ /** The Socket for communication. */
+ @NotNull private final Socket socket;
+
+ /** The PrintStream to write to. */
+ @NotNull private final PrintWriter out;
+
+ /** The BufferedReader to read from. */
+ @NotNull private final BufferedReader in;
+
+ /** Creates an IRCConnecntion.
+ * @param socket Socket
+ * @throws IOException In case of I/O problems.
+ */
+ public IRCConnection(@NotNull final Socket socket) throws IOException {
+ this.socket = socket;
+ out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8"));
+ in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8"));
+ new Thread(this).start();
+ }
+
+ /** {@inheritDoc} */
+ public void run() {
+ final String username = "cherbot";
+ final String realname = "CherBot";
+ final String nick = "CherBot";
+ final String password = "foobar";
+ final boolean registerWithNickServ = true;
+ final String[] initialChannels = { "#cherbot" };
+ out.println("USER " + username + " 0 * :" + realname);
+ out.println("NICK " + nick);
+ for (final String initialChannel : initialChannels) {
+ out.println("JOIN " + initialChannel);
+ }
+ if (registerWithNickServ) {
+ out.println("PRIVMSG NICKSERV :IDENTIFY " + password);
+ }
+ out.flush();
+ try {
+ final Pattern pattern = Pattern.compile("^:([^!]+)!([^ ]+) PRIVMSG ([^ ]+) :(.*)$");
+ final Matcher matcher = pattern.matcher("");
+ for (String line; (line = in.readLine()) != null;) {
+ System.out.println(line);
+ matcher.reset(line);
+ if (matcher.matches()) {
+ final String actor = matcher.group(1);
+ if (nick.equals(actor)) {
+ continue;
+ }
+ final String actorIdentity = matcher.group(2);
+ final String channel = matcher.group(3);
+ final String message = matcher.group(4);
+ System.out.println("<" + actor + "> " + message);
+ out.println("PRIVMSG " + (channel.startsWith("#") ? channel : actor) + " :" + "you said: " + message);
+ out.flush();
+ }
+ }
+ } catch (final IOException e) {
+ System.err.println(e);
+ }
+ }
+
+ /** 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 {
+ new IRCConnection(new Socket(args[0], Integer.parseInt(args[1])));
+ }
+
+} // class IRCConnection
Property changes on: trunk/src/net/sf/cherbot/IRCConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/Module.java
===================================================================
--- trunk/src/net/sf/cherbot/Module.java (rev 0)
+++ trunk/src/net/sf/cherbot/Module.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,16 @@
+package net.sf.cherbot;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface Module {
+
+ /** Parses a message from a channel.
+ * @param channel Channel this message comes from
+ * @param msg Message to parse
+ */
+ void parseMessage(@NotNull Channel channel, @NotNull String msg);
+}
Property changes on: trunk/src/net/sf/cherbot/Module.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/PersistentModule.java
===================================================================
--- trunk/src/net/sf/cherbot/PersistentModule.java (rev 0)
+++ trunk/src/net/sf/cherbot/PersistentModule.java 2007-06-16 20:22:54 UTC (rev 60)
@@ -0,0 +1,27 @@
+/*
+ * 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 java.sql.Connection;
+
+/** A module provides a specific feature for CherBot.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface PersistentModule extends Module {
+
+ /** Instructs this module to load its data.
+ * @param con Database connection for persistence.
+ */
+ void load(@NotNull Connection con);
+
+ /** Instructs this module to save its data.
+ * @param con Database connection for persistence.
+ */
+ void save(@NotNull Connection con);
+
+} // interface Module
Property changes on: trunk/src/net/sf/cherbot/PersistentModule.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.
|