cherbot-commit Mailing List for CherBot (Page 3)
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...> - 2007-06-25 11:25:14
|
Revision: 99
http://svn.sourceforge.net/cherbot/?rev=99&view=rev
Author: christianhujer
Date: 2007-06-25 04:25:11 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Fixed some cosmetic issues.
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 09:35:04 UTC (rev 98)
+++ trunk/src/net/sf/cherbot/CherBot.java 2007-06-25 11:25:11 UTC (rev 99)
@@ -36,10 +36,11 @@
modules.add(new PlayerModule());
modules.add(new ClanModule());
}
+
/** Main program.
* @param args Command line arguments (currently ignored).
*/
- public static void main(final String... args) {
+ public static void main(@NotNull final String... args) {
ArgParser.simpleParseAndRun(new CherBot(), args);
}
@@ -79,4 +80,5 @@
public void setDatabaseURL(@NotNull final String databaseURL) {
this.databaseURL = databaseURL;
}
+
} // class CherBot
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-25 09:57:21
|
Revision: 98
http://svn.sourceforge.net/cherbot/?rev=98&view=rev
Author: christianhujer
Date: 2007-06-25 02:35:04 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Removed code that's now handled in connections.
Made database URL configurable.
Added primitive implementation of module handling.
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-24 21:40:39 UTC (rev 97)
+++ trunk/src/net/sf/cherbot/CherBot.java 2007-06-25 09:35:04 UTC (rev 98)
@@ -6,12 +6,14 @@
package net.sf.cherbot;
-import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
import java.util.List;
-import java.sql.DriverManager;
-import java.sql.Connection;
+import java.util.ArrayList;
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;
/** Main class of Cherbot.
@@ -19,6 +21,21 @@
*/
public class CherBot extends BasicCommand {
+ /** The default database URL. */
+ @NotNull private static final String DEFAULT_DATABASE_URL = "jdbc:derby:cherbotdb;create=true";
+
+ /** The module registry. */
+ @NotNull private final List<Module> modules = new ArrayList<Module>();
+
+ /** The database URL. */
+ @NotNull private String databaseURL = DEFAULT_DATABASE_URL;
+
+ /** Create an instance of CherBot. */
+ public CherBot() {
+ modules.add(new ServerModule());
+ modules.add(new PlayerModule());
+ modules.add(new ClanModule());
+ }
/** Main program.
* @param args Command line arguments (currently ignored).
*/
@@ -31,46 +48,35 @@
/** {@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");
+ con = DriverManager.getConnection(databaseURL);
System.out.println(con);
+ load();
return 0;
}
- public void metaserver() throws IOException {
- // read "62.75.224.80|177|daimonin.game-server.cc|52|0.9.7|This is the Daimonin 0.9.7 server.|0|0|0\n"
+ /** Loads all modules.
+ * @throws SQLException in case of persistence issues.
+ */
+ private void load() throws SQLException {
+ for (final Module module : modules) {
+ if (module instanceof PersistentModule) {
+ ((PersistentModule) module).load(con);
+ }
+ }
}
- public void connect() throws IOException {
- // write 0x00 0x29 "version 991023 991023 Daimonin SDL Client"
- // read 0x00 0x1e 0x02 "991023 991023 Daimonin Server"
- // write 0x00 0x99 "setup sound 1 map2 cmd 1 mapsize 17x17 darkness 1 facecache 1 skf 3386|dd257ea spf 2737|404f6ead bpf 227483|8ab2a06 stf 2253|16d49f0f amf 262790|ec2627ee"
- // read 0x00 0x75 0x17 " sound 1 map2cmd 1 mapsize 17x17 darkness 1 facecache 1 skf OK spf OK bpf 227639|117ae13a stf OK amf 263415|ec0d5f79"
- // write 0x00 0x04 "rf 4"
- // read lots of data
- // write 0x00 0x04 "rf 3"
- // read lots of data
- // write 0x00 0x05 "addme"
- // read 0x00 0x06 0x18 "4 QN0" 0x00 0x01 0x15
- // write 0x00 0x12 "reply LFoobuzzer49" // L not part of name
- // read 0x00 0x06 0x18 "4 QP0"
- // write 0x00 0x0E "reply xxxxxxxx"
- // read 0x00 0x10 0x06 0x00 0x00 "Welcome Back!"
- // read 0x00 0x24 0x06 0x00 0x00 "Cheristheus has entered the game."
- // read 0x00 0x19 0x11 0x00 0x4e 0x01 0x60 0x00 0x02 0x27 0x2a 0x00 0x00 0x10 0xec 0x0b "Cheristheus"
- // read lots of data
- // read 0x00 0x16 0x05 0x00 0x07 0x02 0x42 0x21 0x80 0x01 "Cheristheus" 0x00 0x90 0xea
- // read 0x00 0x16 0x05 0x00 0x07 0x02 0x42 0x21 0x80 0x01 "Cheristheus" 0x00 0x90 0xeb
- // read 0x00 0x16 0x05 0x00 0x07 0x02 0x42 0x21 0x80 0x01 "Cheristheus" 0x00 0x90 0xec
- // write 0x00 0x0d "ncom " 0x00 0x01 0xff 0xff 0xff 0xff "/n" // north
- // write 0x00 0x0d "ncom " 0x00 0x02 0xff 0xff 0xff 0xff "/n" // north
- // write 0x00 0x0d "ncom " 0x00 0x03 0xff 0xff 0xff 0xff "/e" // east
- // write 0x00 0x0d "ncom " 0x00 0x04 0xff 0xff 0xff 0xff "/s" // south
- // write 0x00 0x0d "ncom " 0x00 0x05 0xff 0xff 0xff 0xff "/w" // west
- // write 0x00 0x0e "ncom " 0x00 0x06 0xff 0xff 0xff 0xff "/sw" // southwest
- // write 0x00 0x0e "ncom " 0x00 0x07 0xff 0xff 0xff 0xff "/se" // southeast
- // write 0x00 0x0e "ncom " 0x00 0x08 0xff 0xff 0xff 0xff "/nw" // northwest
- // write 0x00 0x0e "ncom " 0x00 0x09 0xff 0xff 0xff 0xff "/ne" // northeast
- // write 0x00 0x0f "ncom " 0x00 0x0A 0xff 0xff 0xff 0xff "/who" // /who
+ /** 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;
+ }
} // class CherBot
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-24 21:40:42
|
Revision: 97
http://svn.sourceforge.net/cherbot/?rev=97&view=rev
Author: christianhujer
Date: 2007-06-24 14:40:39 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Added Clan class.
Added Paths:
-----------
trunk/src/net/sf/cherbot/Clan.java
Added: trunk/src/net/sf/cherbot/Clan.java
===================================================================
--- trunk/src/net/sf/cherbot/Clan.java (rev 0)
+++ trunk/src/net/sf/cherbot/Clan.java 2007-06-24 21:40:39 UTC (rev 97)
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class Clan {
+
+ /** Id of this clan. */
+ private int id;
+
+ /** Server of this clan. */
+ private int serverId;
+
+ /** Name of this clan. */
+ @NotNull private String name;
+
+ /** Returns the id of this clan.
+ * @return The id of this clan.
+ */
+ public int getId() {
+ return id;
+ }
+
+ /** Sets the id of this clan.
+ * @param id The id of this clan.
+ */
+ public void setId(final int id) {
+ this.id = id;
+ }
+
+ /** Returns the server of this clan.
+ * @return The server of this clan.
+ */
+ public int getServerId() {
+ return serverId;
+ }
+
+ /** Sets the server of this clan.
+ * @param serverId The server of this clan.
+ */
+ public void setServerId(final int serverId) {
+ this.serverId = serverId;
+ }
+
+ /** Returns the name of this clan.
+ * @return The name of this clan.
+ */
+ @NotNull public String getName() {
+ return name;
+ }
+
+ /** Sets the name of this clan.
+ * @param name The name of this clan.
+ */
+ public void setName(@NotNull final String name) {
+ this.name = name;
+ }
+
+} // class Clan
Property changes on: trunk/src/net/sf/cherbot/Clan.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-24 19:53:38
|
Revision: 96
http://svn.sourceforge.net/cherbot/?rev=96&view=rev
Author: christianhujer
Date: 2007-06-24 12:53:33 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Improved PlayerModule, added ServerModule (unfinished).
Modified Paths:
--------------
trunk/src/net/sf/cherbot/PlayerModule.java
Added Paths:
-----------
trunk/src/net/sf/cherbot/Server.java
trunk/src/net/sf/cherbot/ServerModule.java
Modified: trunk/src/net/sf/cherbot/PlayerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/PlayerModule.java 2007-06-24 18:32:26 UTC (rev 95)
+++ trunk/src/net/sf/cherbot/PlayerModule.java 2007-06-24 19:53:33 UTC (rev 96)
@@ -14,12 +14,12 @@
import java.util.List;
import java.util.ArrayList;
-/**
- * Created by IntelliJ IDEA.
+/** Module for managing players.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public class PlayerModule implements PersistentModule {
+ /** The players. */
private final List<Player> players = new ArrayList<Player>();
/** {@inheritDoc} */
@@ -32,14 +32,32 @@
final String name = result.getString(3);
players.add(new Player(id, serverId, name));
}
+ stmt.close();
}
/** {@inheritDoc} */
public void save(@NotNull final Connection con) throws SQLException {
createTables(con);
final PreparedStatement lookup = con.prepareStatement("SELECT id FROM Player WHERE id = ?");
- final PreparedStatement update = con.prepareStatement("UPDATE Player SET id = ?, serverId = ?, name = ? WHERE id = ?");
+ final PreparedStatement update = con.prepareStatement("UPDATE Player SET serverId = ?, name = ? WHERE id = ?");
final PreparedStatement insert = con.prepareStatement("INSERT INTO Player (id, serverId, name) VALUES (?, ?, ?)");
+ for (final Player player : players) {
+ lookup.setInt(1, player.getId());
+ if (lookup.executeQuery().next()) {
+ update.setInt(1, player.getServerId());
+ update.setString(2, player.getName());
+ update.setInt(3, player.getId());
+ update.executeUpdate();
+ } else {
+ insert.setInt(1, player.getId());
+ insert.setInt(2, player.getServerId());
+ insert.setString(3, player.getName());
+ insert.executeUpdate();
+ }
+ }
+ lookup.close();
+ update.close();
+ insert.close();
}
/** Creates the tables if they don't exist.
@@ -50,6 +68,7 @@
try {
final PreparedStatement stmt = con.prepareStatement("CREATE TABLE Player (id INT, serverId INT, name VARCHAR(32)");
stmt.execute();
+ stmt.close();
} catch (final SQLException ignore) {
System.err.println(ignore);
}
Added: trunk/src/net/sf/cherbot/Server.java
===================================================================
--- trunk/src/net/sf/cherbot/Server.java (rev 0)
+++ trunk/src/net/sf/cherbot/Server.java 2007-06-24 19:53:33 UTC (rev 96)
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+/** A Server represents a single server instance like a certain IRC network, a certain crossfire server or a certain daimonin server.
+ * The server will be used to establish a connection.
+ * A Cherbot account with server-specific properties like username and password will be associated with the server.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * @todo add server type and parameters
+ */
+public class Server {
+
+ /** The id of this server. */
+ private int id;
+
+ /** The host name of this server. */
+ @NotNull private String hostname;
+
+ /** The port of this server. */
+ private int port;
+
+ /** Create a Server.
+ * @param id Id of this server.
+ * @param hostname Hostname of this server.
+ * @param port Port of this server.
+ */
+ public Server(final int id, @NotNull final String hostname, final int port) {
+ this.id = id;
+ this.hostname = hostname;
+ this.port = port;
+ }
+
+ /** Returns the id of this server.
+ * @return The id of this server.
+ */
+ public int getId() {
+ return id;
+ }
+
+ /** Returns the hostname of this server.
+ * @return The hostname of this server.
+ */
+ @NotNull public String getHostname() {
+ return hostname;
+ }
+
+ /** Sets the hostname of this server.
+ * @param hostname The hostname of this serer.
+ */
+ public void setHostname(@NotNull final String hostname) {
+ this.hostname = hostname;
+ }
+
+ /** Returns the port of this server.
+ * @return The port of this server.
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /** Sets the port of this server.
+ * @param port The port of this server.
+ */
+ public void setPort(final int port) {
+ this.port = port;
+ }
+
+} // class Server
Property changes on: trunk/src/net/sf/cherbot/Server.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/ServerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/ServerModule.java (rev 0)
+++ trunk/src/net/sf/cherbot/ServerModule.java 2007-06-24 19:53:33 UTC (rev 96)
@@ -0,0 +1,81 @@
+/*
+ * 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;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
+
+/** Module for managing servers.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ServerModule implements PersistentModule {
+
+ /** The players. */
+ private final List<Server> servers = new ArrayList<Server>();
+
+ /** {@inheritDoc} */
+ public void load(@NotNull final Connection con) throws SQLException {
+ final PreparedStatement stmt = con.prepareStatement("SELECT id, serverId, name FROM Player");
+ 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));
+ }
+ stmt.close();
+ }
+
+ /** {@inheritDoc} */
+ 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 (?, ?, ?)");
+ for (final Server server : servers) {
+ lookup.setInt(1, server.getId());
+ if (lookup.executeQuery().next()) {
+ update.setString(1, server.getHostname());
+ update.setInt(2, server.getPort());
+ update.setInt(3, server.getId());
+ update.executeUpdate();
+ } else {
+ insert.setInt(1, server.getId());
+ insert.setString(2, server.getHostname());
+ insert.setInt(3, server.getPort());
+ insert.executeUpdate();
+ }
+ }
+ lookup.close();
+ update.close();
+ insert.close();
+ }
+
+ /** Creates the tables if they don't exist.
+ * @param con Connection to use for creating the tables.
+ * @throws SQLException In case of persistence problems.
+ */
+ 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");
+ stmt.execute();
+ stmt.close();
+ } catch (final SQLException ignore) {
+ System.err.println(ignore);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void parseMessage(@NotNull final Channel channel, @NotNull final String msg) {
+ }
+
+} // class ServerModule
Property changes on: trunk/src/net/sf/cherbot/ServerModule.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-24 18:32:29
|
Revision: 95
http://svn.sourceforge.net/cherbot/?rev=95&view=rev
Author: christianhujer
Date: 2007-06-24 11:32:26 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Added missing @NotNull annotations for performInvocation() parameters.
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-24 17:36:12 UTC (rev 94)
+++ trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-24 18:32:26 UTC (rev 95)
@@ -73,7 +73,7 @@
* @throws IllegalAccessException see {@link Method#invoke(Object, Object[])}
* @throws InvocationTargetException see {@link Method#invoke(Object, Object[])}
*/
- protected void performInvocation(final Method method, final String[] args) throws IllegalAccessException, InvocationTargetException {
+ protected void performInvocation(@NotNull final Method method, @NotNull final String[] args) throws IllegalAccessException, InvocationTargetException {
method.invoke(target, (Object[]) args);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-24 17:36:19
|
Revision: 94
http://svn.sourceforge.net/cherbot/?rev=94&view=rev
Author: christianhujer
Date: 2007-06-24 10:36:12 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Extracted performInvocation to allow injection of additional arguments.
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-24 17:25:57 UTC (rev 93)
+++ trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-24 17:36:12 UTC (rev 94)
@@ -6,12 +6,12 @@
package net.sf.cherbot.redel;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.regex.Matcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -45,8 +45,8 @@
/** Process a String.
* @param string String to process.
* @return The number of matching methods that were found.
- * @throws IllegalAccessException In case the target method cannot be invoked.
- * @throws InvocationTargetException In case the target method threw an exception.
+ * @throws IllegalAccessException see {@link Method#invoke(Object, Object[])}
+ * @throws InvocationTargetException see {@link Method#invoke(Object, Object[])}
*/
public int process(@NotNull final String string) throws IllegalAccessException, InvocationTargetException {
int matchesFound = 0;
@@ -60,10 +60,21 @@
groups[i] = matcher.group(i + 1);
}
final Method method = entry.getValue();
- method.invoke(target, (Object[]) groups);
+ performInvocation(method, groups);
}
}
return matchesFound;
}
+ /** Invokes the specified method with the specified arguments.
+ * The method is invoked indirectly via this method so you can override it in subclasses to inject additional parameters.
+ * @param method Method to invoke
+ * @param args Arguments found by pattern matching.
+ * @throws IllegalAccessException see {@link Method#invoke(Object, Object[])}
+ * @throws InvocationTargetException see {@link Method#invoke(Object, Object[])}
+ */
+ protected void performInvocation(final Method method, final String[] args) throws IllegalAccessException, InvocationTargetException {
+ method.invoke(target, (Object[]) args);
+ }
+
} // class PatternDelegator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-24 17:26:04
|
Revision: 93
http://svn.sourceforge.net/cherbot/?rev=93&view=rev
Author: christianhujer
Date: 2007-06-24 10:25:57 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Turned Channel into an interface. The class Channel now is AbstractChannel.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/IRCConnection.java
Added Paths:
-----------
trunk/src/net/sf/cherbot/AbstractChannel.java
trunk/src/net/sf/cherbot/Channel.java
Removed Paths:
-------------
trunk/src/net/sf/cherbot/Channel.java
Copied: trunk/src/net/sf/cherbot/AbstractChannel.java (from rev 90, trunk/src/net/sf/cherbot/Channel.java)
===================================================================
--- trunk/src/net/sf/cherbot/AbstractChannel.java (rev 0)
+++ trunk/src/net/sf/cherbot/AbstractChannel.java 2007-06-24 17:25:57 UTC (rev 93)
@@ -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;
+
+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/AbstractChannel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Deleted: trunk/src/net/sf/cherbot/Channel.java
===================================================================
--- trunk/src/net/sf/cherbot/Channel.java 2007-06-24 17:10:25 UTC (rev 92)
+++ trunk/src/net/sf/cherbot/Channel.java 2007-06-24 17:25:57 UTC (rev 93)
@@ -1,42 +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;
-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 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 Channel(@Nullable final String channelName) {
- this.channelName = channelName;
- }
-
- /** Sends a message to this channel.
- * @param msg Message to send
- */
- public abstract 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 public String getChannelName() {
- return channelName;
- }
-
-} // class Channel
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-24 17:25:57 UTC (rev 93)
@@ -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;
+
+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/Channel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-24 17:10:25 UTC (rev 92)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-24 17:25:57 UTC (rev 93)
@@ -210,7 +210,7 @@
* 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 Channel {
+ private class IRCChannel extends AbstractChannel {
/** Creates an IRCChannel.
* @param channelName name of this channel.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-24 17:10:35
|
Revision: 92
http://svn.sourceforge.net/cherbot/?rev=92&view=rev
Author: christianhujer
Date: 2007-06-24 10:10:25 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
DaimoninConnection now works. Tested with trunk and the current public B4 server.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/DaimoninConnection.java
Modified: trunk/src/net/sf/cherbot/DaimoninConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-24 15:55:22 UTC (rev 91)
+++ trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-24 17:10:25 UTC (rev 92)
@@ -56,42 +56,22 @@
ArgParser.simpleParseAndRun(new DaimoninConnection(), args);
}
- /** Establishes a connection.
- * @throws IOException In case of connection problems.
- */
- @NotNull public Socket connect() throws IOException {
+ /** {@inheritDoc} */
+ @NotNull @Override public Socket connect() throws IOException {
final Socket socket = super.connect();
this.out = new BufferedOutputStream(socket.getOutputStream());
this.in = socket.getInputStream();
- // read server version
- readToNull();
-
- // send client version
- //textMsg("version 991023 991023 CherBot");
+ 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");
- //readToNull();
+ textMsg("setup bot 1"); // We are a bot
+ readToNull(); // "0x17 bot FALSE"
textMsg("addme");
- readToNull();
+ readToNull(); // 0x00 0x06 0x18 "4 QNO"
+ readToNull(); // 0x00 0x01 0x15
textMsg("reply L" + username);
- readToNull();
+ readToNull(); // 0x00 0x06 0x18 "4 QP0"
textMsg("reply " + password);
- // write 0x00 0x29 "version 991023 991023 Daimonin SDL Client"
- // TODO
- // read 0x00 0x1e 0x02 "991023 991023 Daimonin Server"
- // write 0x00 0x99 "setup sound 1 map2 cmd 1 mapsize 17x17 darkness 1 facecache 1 skf 3386|dd257ea spf 2737|404f6ead bpf 227483|8ab2a06 stf 2253|16d49f0f amf 262790|ec2627ee"
- // read 0x00 0x75 0x17 " sound 1 map2cmd 1 mapsize 17x17 darkness 1 facecache 1 skf OK spf OK bpf 227639|117ae13a stf OK amf 263415|ec0d5f79"
- // write 0x00 0x04 "rf 4"
- // read lots of data
- // write 0x00 0x04 "rf 3"
- // read lots of data
- // write 0x00 0x05 "addme"
- // read 0x00 0x06 0x18 "4 QN0" 0x00 0x01 0x15
- // write 0x00 0x12 "reply LFoobuzzer49" // L not part of name
- // read 0x00 0x06 0x18 "4 QP0"
- // write 0x00 0x0E "reply xxxxxxxx"
return socket;
}
@@ -152,7 +132,7 @@
/** {@inheritDoc} */
public int run(@NotNull final List<String> args) throws Exception {
connect();
- Thread.sleep(10000);
+ Thread.sleep(100000);
close();
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-24 15:55:27
|
Revision: 91
http://svn.sourceforge.net/cherbot/?rev=91&view=rev
Author: christianhujer
Date: 2007-06-24 08:55:22 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Deleted wrong comment.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/CrossfireConnection.java
Modified: trunk/src/net/sf/cherbot/CrossfireConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-20 22:17:41 UTC (rev 90)
+++ trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-24 15:55:22 UTC (rev 91)
@@ -60,7 +60,7 @@
@NotNull @Override public Socket connect() throws IOException {
final Socket socket = super.connect();
readToNull();
- textMsg("version 1023 1023 CherBot"); // we have to cheat or the server won't let us in.
+ textMsg("version 1023 1023 CherBot");
textMsg("setup bot 1");
readToNull();
readToNull();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 22:17:43
|
Revision: 90
http://svn.sourceforge.net/cherbot/?rev=90&view=rev
Author: christianhujer
Date: 2007-06-20 15:17:41 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Added connection for crossfire (tested).
Added Paths:
-----------
trunk/src/net/sf/cherbot/CrossfireConnection.java
Added: trunk/src/net/sf/cherbot/CrossfireConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/CrossfireConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/CrossfireConnection.java 2007-06-20 22:17:41 UTC (rev 90)
@@ -0,0 +1,169 @@
+/*
+ * 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.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 {
+
+ /** 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;
+
+ /** 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);
+ 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"); // we have to cheat or the server won't let us in.
+ textMsg("setup bot 1");
+ readToNull();
+ readToNull();
+ textMsg("addme");
+ readToNull();
+ textMsg("reply " + username);
+ readToNull();
+ textMsg("reply " + password);
+ 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++) {
+ readToNull();
+ }
+ close();
+ 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
Property changes on: trunk/src/net/sf/cherbot/CrossfireConnection.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-20 20:31:34
|
Revision: 89
http://svn.sourceforge.net/cherbot/?rev=89&view=rev
Author: christianhujer
Date: 2007-06-20 13:31:32 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Fixed bug: in and out were initialized with connect() but not with setSocket().
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-20 20:30:02 UTC (rev 88)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-20 20:31:32 UTC (rev 89)
@@ -73,9 +73,8 @@
/** {@inheritDoc} */
@Override @NotNull public Socket connect() throws IOException {
final Socket socket = super.connect();
- final PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8"));
- this.out = out;
- this.in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8"));
+ final PrintWriter out = this.out;
+ assert this.out != null;
out.println("USER " + username + " 0 * :" + realname);
out.println("NICK " + nickname);
if (nickPassword != null) {
@@ -97,6 +96,13 @@
}
/** {@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 {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 20:30:06
|
Revision: 88
http://svn.sourceforge.net/cherbot/?rev=88&view=rev
Author: christianhujer
Date: 2007-06-20 13:30:02 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Improved documentation.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/AbstractConnection.java
Modified: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:28:03 UTC (rev 87)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:30:02 UTC (rev 88)
@@ -77,6 +77,7 @@
}
/** 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.
*/
@@ -100,7 +101,7 @@
/** Returns whether this connection is established.
* @return <code>true</code> if this connection is established, otherwise <code>false</code>.
- * @see java.net.Socket#isConnected()
+ * @see Socket#isConnected()
*/
public boolean isConnected() {
return socket != null && socket.isConnected();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 20:28:05
|
Revision: 87
http://svn.sourceforge.net/cherbot/?rev=87&view=rev
Author: christianhujer
Date: 2007-06-20 13:28:03 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Allow setSocket() to throw IOException in case an overriding method wants to use the socket when it's being set.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/AbstractConnection.java
Modified: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:14:55 UTC (rev 86)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:28:03 UTC (rev 87)
@@ -6,15 +6,15 @@
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;
-import java.net.Socket;
-import java.io.IOException;
-import java.io.Closeable;
-import java.io.Serializable;
/** An AbstractConnection represents the connection to a server and has one or more channels.
* Connections are implemented as command bean.
@@ -109,8 +109,9 @@
/** 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) {
+ public void setSocket(@NotNull final Socket socket) throws IOException {
this.socket = socket;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 20:14:57
|
Revision: 86
http://svn.sourceforge.net/cherbot/?rev=86&view=rev
Author: christianhujer
Date: 2007-06-20 13:14:55 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Added a method for querying whether the connection is established.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/AbstractConnection.java
Modified: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:14:11 UTC (rev 85)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:14:55 UTC (rev 86)
@@ -98,6 +98,14 @@
}
}
+ /** Returns whether this connection is established.
+ * @return <code>true</code> if this connection is established, otherwise <code>false</code>.
+ * @see java.net.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.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 20:14:13
|
Revision: 85
http://svn.sourceforge.net/cherbot/?rev=85&view=rev
Author: christianhujer
Date: 2007-06-20 13:14:11 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Improved documentation.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/AbstractConnection.java
Modified: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:10:27 UTC (rev 84)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-20 20:14:11 UTC (rev 85)
@@ -17,6 +17,18 @@
import java.io.Serializable;
/** 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 {
@@ -64,7 +76,7 @@
return port;
}
- /** Establishes the connection.
+ /** Establishes this connection.
* @return The socket created for this connection.
* @throws IOException in case of connection problems.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 20:10:28
|
Revision: 84
http://svn.sourceforge.net/cherbot/?rev=84&view=rev
Author: christianhujer
Date: 2007-06-20 13:10:27 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Minor: Bug: IRCConnection accidently opened two sockets to the IRC server. Fixed.
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-20 20:09:35 UTC (rev 83)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-20 20:10:27 UTC (rev 84)
@@ -72,7 +72,6 @@
/** {@inheritDoc} */
@Override @NotNull public Socket connect() throws IOException {
- super.connect();
final Socket socket = super.connect();
final PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8"));
this.out = out;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-20 20:09:38
|
Revision: 83
http://svn.sourceforge.net/cherbot/?rev=83&view=rev
Author: christianhujer
Date: 2007-06-20 13:09:35 -0700 (Wed, 20 Jun 2007)
Log Message:
-----------
Cosmetic: Fixed documentation issue.
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-18 21:18:51 UTC (rev 82)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-20 20:09:35 UTC (rev 83)
@@ -70,9 +70,7 @@
ArgParser.simpleParseAndRun(new IRCConnection(), args);
}
- /** Establishes a connection.
- * @throws IOException In case of connection problems.
- */
+ /** {@inheritDoc} */
@Override @NotNull public Socket connect() throws IOException {
super.connect();
final Socket socket = super.connect();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-18 21:18:56
|
Revision: 82
http://svn.sourceforge.net/cherbot/?rev=82&view=rev
Author: christianhujer
Date: 2007-06-18 14:18:51 -0700 (Mon, 18 Jun 2007)
Log Message:
-----------
Added IRC PING/PONG.
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-17 20:46:29 UTC (rev 81)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-18 21:18:51 UTC (rev 82)
@@ -24,6 +24,7 @@
/** 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 {
@@ -137,6 +138,18 @@
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-17 20:46:31
|
Revision: 81
http://svn.sourceforge.net/cherbot/?rev=81&view=rev
Author: christianhujer
Date: 2007-06-17 13:46:29 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Deactivated echo.
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-17 20:33:19 UTC (rev 80)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 20:46:29 UTC (rev 81)
@@ -132,7 +132,7 @@
if (channel == null) {
// TODO: Create channel on demand.
} else {
- channel.send(message);
+ // channel.send(message); // echo
}
System.out.println(channel);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-17 20:33:20
|
Revision: 80
http://svn.sourceforge.net/cherbot/?rev=80&view=rev
Author: christianhujer
Date: 2007-06-17 13:33:19 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Changed IRCConnection to use delegation based on redel.
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-17 20:32:19 UTC (rev 79)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 20:33:19 UTC (rev 80)
@@ -15,8 +15,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+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;
@@ -109,26 +109,10 @@
for (final String channelName : args) {
join(channelName);
}
- final Pattern pattern = Pattern.compile("^:([^!]+)!([^ ]+) PRIVMSG ([^ ]+) :(.*)$");
- final Matcher matcher = pattern.matcher("");
+ final PatternDelegator delegator = new PatternDelegator(this);
for (String line; (line = in.readLine()) != null;) {
System.out.println(line);
- matcher.reset(line);
- if (matcher.matches()) {
- final String actor = matcher.group(1);
- if (nickname.equals(actor)) {
- continue;
- }
- final String actorIdentity = matcher.group(2);
- final String channelName = matcher.group(3);
- final String message = matcher.group(4);
- Channel channel = channels.get(channelName);
- if (channel == null) {
- // TODO: Create channel on demand.
- }
- System.out.println(channel);
- //channel.send("You are: " + actorIdentity + " and said: " + message);
- }
+ delegator.process(line);
}
return 0;
} finally {
@@ -136,6 +120,23 @@
}
}
+ /** 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);
+ }
+ System.out.println(channel);
+ }
+
/** 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-17 20:32:22
|
Revision: 79
http://svn.sourceforge.net/cherbot/?rev=79&view=rev
Author: christianhujer
Date: 2007-06-17 13:32:19 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Added delegation based on regular expressions.
Added Paths:
-----------
trunk/src/net/sf/cherbot/redel/
trunk/src/net/sf/cherbot/redel/PatternDelegator.java
trunk/src/net/sf/cherbot/redel/Patterns.java
trunk/src/net/sf/cherbot/redel/package-info.java
trunk/src/test/net/sf/cherbot/redel/
trunk/src/test/net/sf/cherbot/redel/PatternDelegatorTest.java
Added: trunk/src/net/sf/cherbot/redel/PatternDelegator.java
===================================================================
--- trunk/src/net/sf/cherbot/redel/PatternDelegator.java (rev 0)
+++ trunk/src/net/sf/cherbot/redel/PatternDelegator.java 2007-06-17 20:32:19 UTC (rev 79)
@@ -0,0 +1,69 @@
+/*
+ * 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.redel;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** Delegator that searches a method that matches a regular expression and invokes it.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class PatternDelegator {
+
+ /** The target to use delegation on. */
+ @NotNull private final Object target;
+
+ /** The methods to use delegation on. */
+ @NotNull private final Map<Pattern, Method> targetMethods = new HashMap<Pattern, Method>();
+
+ /** Create a PatternDelegator.
+ * @param target Object to use delegation on.
+ */
+ public PatternDelegator(@NotNull final Object target) {
+ this.target = target;
+ final Method[] methods = target.getClass().getMethods();
+ 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);
+ }
+ }
+ }
+ }
+
+ /** Process a String.
+ * @param string String to process.
+ * @return The number of matching methods that were found.
+ * @throws IllegalAccessException In case the target method cannot be invoked.
+ * @throws InvocationTargetException In case the target method threw an exception.
+ */
+ public int process(@NotNull final String string) throws IllegalAccessException, InvocationTargetException {
+ int matchesFound = 0;
+ for (final Map.Entry<Pattern, Method> entry : targetMethods.entrySet()) {
+ final Pattern pattern = entry.getKey();
+ final Matcher matcher = pattern.matcher(string);
+ if (matcher.matches()) {
+ matchesFound++;
+ final String[] groups = new String[matcher.groupCount()];
+ for (int i = 0; i < groups.length; i++) {
+ groups[i] = matcher.group(i + 1);
+ }
+ final Method method = entry.getValue();
+ method.invoke(target, (Object[]) groups);
+ }
+ }
+ return matchesFound;
+ }
+
+} // class PatternDelegator
Property changes on: trunk/src/net/sf/cherbot/redel/PatternDelegator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/redel/Patterns.java
===================================================================
--- trunk/src/net/sf/cherbot/redel/Patterns.java (rev 0)
+++ trunk/src/net/sf/cherbot/redel/Patterns.java 2007-06-17 20:32:19 UTC (rev 79)
@@ -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.redel;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/** 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)
+public @interface Patterns {
+
+ /** Returns the regular expressions that should match for this method to be invoked.
+ * @return The regular expressions to match.
+ */
+ String[] value();
+
+} // @interface Patterns
Property changes on: trunk/src/net/sf/cherbot/redel/Patterns.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/redel/package-info.java
===================================================================
--- trunk/src/net/sf/cherbot/redel/package-info.java (rev 0)
+++ trunk/src/net/sf/cherbot/redel/package-info.java 2007-06-17 20:32:19 UTC (rev 79)
@@ -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.
+ */
+
+/** A framework for simple delegating facades based on regular expressions.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+package net.sf.cherbot.redel;
Property changes on: trunk/src/net/sf/cherbot/redel/package-info.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/test/net/sf/cherbot/redel/PatternDelegatorTest.java
===================================================================
--- trunk/src/test/net/sf/cherbot/redel/PatternDelegatorTest.java (rev 0)
+++ trunk/src/test/net/sf/cherbot/redel/PatternDelegatorTest.java 2007-06-17 20:32:19 UTC (rev 79)
@@ -0,0 +1,90 @@
+/*
+ * 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 test.net.sf.cherbot.redel;
+
+import org.junit.Test;
+import org.junit.Assert;
+import org.jetbrains.annotations.NotNull;
+import net.sf.cherbot.redel.Patterns;
+import net.sf.cherbot.redel.PatternDelegator;
+
+/** Unit-Test for{@link net.sf.cherbot.redel.PatternDelegator}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class PatternDelegatorTest {
+
+ /** Tests whether delegation works.
+ * @throws Exception Exception (unexpected).
+ */
+ @Test public void testDelegation() throws Exception {
+ final PatternsDummy dummy = new PatternsDummy();
+ Assert.assertTrue("process1 must not have been invoked yet.", dummy.getInvocations() == 0);
+ final PatternDelegator testling = new PatternDelegator(dummy);
+ Assert.assertTrue("process1 must still not have been invoked yet.", dummy.getInvocations() == 0);
+ testling.process("foo: bar");
+ Assert.assertTrue("process1 must have been invoked once now.", dummy.getInvocations() == 1);
+ Assert.assertEquals("First match group must be passed as first argument.", "foo", dummy.getGroup1());
+ Assert.assertEquals("Second match group must be passed as second argument.", "bar", dummy.getGroup2());
+ }
+
+ /** Dummy for testing the PatternDelegator.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+ public static class PatternsDummy {
+
+ /** Most recent group1 parameter value of {@link #process1(String, String)}. */
+ private String group1;
+
+ /** Most recent group2 parameter value of {@link #process1(String, String)}. */
+ private String group2;
+
+ /** Number of invocations of {@link #process1(String, String)}. */
+ private int invocations;
+
+ /** Dummy test method.
+ * @param group1 First group
+ * @param group2 Second group
+ */
+ @Patterns("^(.*?): (.*)$")
+ public void process1(@NotNull final String group1, @NotNull final String group2) {
+ this.group1 = group1;
+ this.group2 = group2;
+ invocations++;
+ }
+
+ /** Returns the group1 parameter of the most recent {@link #process1(String,String)} invocation.
+ * @return Most recent group1 value.
+ */
+ public String getGroup1() {
+ return group1;
+ }
+
+ /** Returns the group2 parameter of the most recent {@link #process1(String,String)} invocation.
+ * @return Most recent group2 value.
+ */
+ public String getGroup2() {
+ return group2;
+ }
+
+ /** Returns the number of invocations of {@link #process1(String,String)}.
+ * @return The number of invocations of {@link #process1(String,String)}.
+ * @see #resetInvocations()
+ */
+ public int getInvocations() {
+ return invocations;
+ }
+
+ /** Resets the number of invocations.
+ * @see #getInvocations()
+ */
+ public void resetInvocations() {
+ invocations = 0;
+ }
+
+ } // class PatternsDummy
+
+} // class PatternDelegatorTest
Property changes on: trunk/src/test/net/sf/cherbot/redel/PatternDelegatorTest.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-17 18:12:29
|
Revision: 78
http://svn.sourceforge.net/cherbot/?rev=78&view=rev
Author: christianhujer
Date: 2007-06-17 11:12:21 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Improved IRC channel handling, added some missing flush()s.
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-17 17:35:37 UTC (rev 77)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 18:12:21 UTC (rev 78)
@@ -106,9 +106,8 @@
assert out != null;
final BufferedReader in = this.in;
assert in != null;
- for (final String initialChannel : args) {
- out.println("JOIN " + initialChannel);
- out.flush();
+ for (final String channelName : args) {
+ join(channelName);
}
final Pattern pattern = Pattern.compile("^:([^!]+)!([^ ]+) PRIVMSG ([^ ]+) :(.*)$");
final Matcher matcher = pattern.matcher("");
@@ -120,12 +119,15 @@
if (nickname.equals(actor)) {
continue;
}
- //final String actorIdentity = matcher.group(2);
- //final String channel = matcher.group(3);
+ final String actorIdentity = matcher.group(2);
+ final String channelName = 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();
+ Channel channel = channels.get(channelName);
+ if (channel == null) {
+ // TODO: Create channel on demand.
+ }
+ System.out.println(channel);
+ //channel.send("You are: " + actorIdentity + " and said: " + message);
}
}
return 0;
@@ -135,13 +137,15 @@
}
/** Joins an IRC channel.
- * @param channelName name of the channel to join.
+ * @param rawChannelName name of the channel to join.
* @return The channel that was just joined.
*/
- public Channel join(@NotNull final String channelName) {
+ 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);
@@ -203,6 +207,7 @@
final PrintWriter out = IRCConnection.this.out;
if (out != null) {
out.println("PRIVMSG " + getChannelName() + " :" + msg);
+ out.flush();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-17 17:35:39
|
Revision: 77
http://svn.sourceforge.net/cherbot/?rev=77&view=rev
Author: christianhujer
Date: 2007-06-17 10:35:37 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Added Channels.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/Channel.java
trunk/src/net/sf/cherbot/IRCConnection.java
Modified: trunk/src/net/sf/cherbot/Channel.java
===================================================================
--- trunk/src/net/sf/cherbot/Channel.java 2007-06-17 17:09:14 UTC (rev 76)
+++ trunk/src/net/sf/cherbot/Channel.java 2007-06-17 17:35:37 UTC (rev 77)
@@ -14,33 +14,29 @@
*/
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.
+ /** The name of this channel.
* Maybe <code>null</code> if it's the default / no channel.
*/
- @Nullable private String channel;
+ @Nullable private String channelName;
+ /** Creates a Channel.
+ * @param channelName name of this channel.
+ */
+ protected Channel(@Nullable final String channelName) {
+ this.channelName = channelName;
+ }
+
/** Sends a message to this channel.
* @param msg Message to send
*/
- public abstract void send(@NotNull final String msg);
+ public abstract 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 public String getChannelName() {
+ return channelName;
+ }
+
} // class Channel
Modified: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 17:09:14 UTC (rev 76)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 17:35:37 UTC (rev 77)
@@ -12,7 +12,9 @@
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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.japi.io.args.ArgParser;
@@ -50,6 +52,9 @@
/** 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);
@@ -84,6 +89,7 @@
/** {@inheritDoc} */
@Override public void close() throws IOException {
+ channels.clear();
try {
super.close();
} finally {
@@ -128,6 +134,22 @@
}
}
+ /** Joins an IRC channel.
+ * @param channelName name of the channel to join.
+ * @return The channel that was just joined.
+ */
+ public Channel join(@NotNull final String channelName) {
+ final PrintWriter out = this.out;
+ assert out != null;
+ out.println("JOIN " + channelName);
+ 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.
@@ -163,4 +185,27 @@
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 Channel {
+
+ /** 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);
+ }
+ }
+
+ } // 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-06-17 17:09:16
|
Revision: 76
http://svn.sourceforge.net/cherbot/?rev=76&view=rev
Author: christianhujer
Date: 2007-06-17 10:09:14 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Moved common code from DaimoninConnection and IRCConnection into their superclass AbstractConnection.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/AbstractConnection.java
trunk/src/net/sf/cherbot/DaimoninConnection.java
trunk/src/net/sf/cherbot/IRCConnection.java
Modified: trunk/src/net/sf/cherbot/AbstractConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-17 14:37:59 UTC (rev 75)
+++ trunk/src/net/sf/cherbot/AbstractConnection.java 2007-06-17 17:09:14 UTC (rev 76)
@@ -6,9 +6,99 @@
package net.sf.cherbot;
+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;
+import java.net.Socket;
+import java.io.IOException;
+import java.io.Closeable;
+import java.io.Serializable;
+
/** An 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 {
+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 the connection.
+ * @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;
+ }
+ }
+
+ /** 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.
+ */
+ public void setSocket(@NotNull final Socket socket) {
+ this.socket = socket;
+ }
+
+ /** Returns the socket for the connection.
+ * @return The socket for the connection.
+ */
+ @Nullable public Socket getSocket() {
+ return socket;
+ }
+
} // class AbstractConnection
Modified: trunk/src/net/sf/cherbot/DaimoninConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-17 14:37:59 UTC (rev 75)
+++ trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-17 17:09:14 UTC (rev 76)
@@ -6,15 +6,14 @@
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.io.BufferedOutputStream;
-import java.io.EOFException;
import java.net.Socket;
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 net.sf.japi.io.args.OptionType;
import org.jetbrains.annotations.NotNull;
@@ -23,7 +22,7 @@
/** A DaimoninConnection represents a connection to a Daimonin server.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class DaimoninConnection extends BasicCommand {
+public class DaimoninConnection extends AbstractConnection {
/** Default server host. */
//@NotNull public static final String DEFAULT_DAIMONIN_HOST = "daimonin.game-server.cc";
@@ -32,21 +31,12 @@
/** Default server port. */
public static final int DEFAULT_DAIMONIN_PORT = 13327;
- /** The host to connect to. */
- @NotNull private String host = DEFAULT_DAIMONIN_HOST;
-
- /** The port to connect to. */
- private int port = DEFAULT_DAIMONIN_PORT;
-
/** The username to authenticate with. */
@NotNull private String username;
/** The password to authenticate with. */
@NotNull private String password;
- /** The Socket for communication. */
- @Nullable private Socket socket;
-
/** The PrintStream to write to. */
@Nullable private OutputStream out;
@@ -55,6 +45,8 @@
/** Creates a DaimoninConnection. */
public DaimoninConnection() {
+ setHost(DEFAULT_DAIMONIN_HOST);
+ setPort(DEFAULT_DAIMONIN_PORT);
}
/** Main program.
@@ -67,13 +59,10 @@
/** Establishes a connection.
* @throws IOException In case of connection problems.
*/
- private void connect() throws IOException {
- final Socket socket = new Socket(host, port);
- this.socket = socket;
- final OutputStream out = new BufferedOutputStream(socket.getOutputStream());
- this.out = out;
- final InputStream in = socket.getInputStream();
- this.in = in;
+ @NotNull public Socket connect() throws IOException {
+ final Socket socket = super.connect();
+ this.out = new BufferedOutputStream(socket.getOutputStream());
+ this.in = socket.getInputStream();
// read server version
readToNull();
@@ -103,6 +92,7 @@
// write 0x00 0x12 "reply LFoobuzzer49" // L not part of name
// read 0x00 0x06 0x18 "4 QP0"
// write 0x00 0x0E "reply xxxxxxxx"
+ return socket;
}
/** Reads and discards a single message.
@@ -149,17 +139,11 @@
out.flush();
}
- /** Closes a connection.
- * @throws IOException In case of connection problems.
- */
- private void disconnect() throws IOException {
+ /** {@inheritDoc} */
+ public void close() throws IOException {
try {
- final Socket socket = this.socket;
- if (socket != null) {
- socket.close();
- }
+ super.close();
} finally {
- socket = null;
in = null;
out = null;
}
@@ -169,7 +153,7 @@
public int run(@NotNull final List<String> args) throws Exception {
connect();
Thread.sleep(10000);
- disconnect();
+ close();
return 0;
}
@@ -189,20 +173,11 @@
this.password = password;
}
- /** Sets the host to connect to.
- * @param host Host to connect to
- */
+ /** {@inheritDoc} */
+ // Overridden because for Daimonin the host is optional.
@Option({"host"})
public void setHost(@NotNull final String host) {
- this.host = host;
+ super.setHost(host);
}
- /** Sets the port to connect to.
- * @param port Port to connect to
- */
- @Option({"port"})
- public void setPort(@NotNull final Integer port) {
- this.port = port;
- }
-
} // class DaimoninConnection
Modified: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 14:37:59 UTC (rev 75)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 17:09:14 UTC (rev 76)
@@ -15,17 +15,15 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import net.sf.japi.io.args.BasicCommand;
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;
/** An IRCConnection represents a connection to an IRC server.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class IRCConnection extends BasicCommand {
+public class IRCConnection extends AbstractConnection {
/** The default IRC port. */
public static final int DEFAULT_IRC_PORT = 6667;
@@ -46,15 +44,6 @@
/** The password to authenticate with NickServ or <code>null</code> if no authentication is desired. */
@Nullable private String nickPassword;
- /** The IRC server host to connect to. */
- @NotNull private String host;
-
- /** The IRC server port to connect to. */
- private int port = DEFAULT_IRC_PORT;
-
- /** The Socket for communication. */
- @Nullable private Socket socket;
-
/** The PrintStream to write to. */
@Nullable private PrintWriter out;
@@ -63,6 +52,7 @@
/** Creates an IRCConnection. */
public IRCConnection() {
+ setPort(DEFAULT_IRC_PORT);
}
/** Main program.
@@ -77,9 +67,9 @@
/** Establishes a connection.
* @throws IOException In case of connection problems.
*/
- private void connect() throws IOException {
- final Socket socket = new Socket(host, port);
- this.socket = socket;
+ @Override @NotNull public Socket connect() throws IOException {
+ super.connect();
+ final Socket socket = super.connect();
final PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8"));
this.out = out;
this.in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8"));
@@ -89,19 +79,14 @@
out.println("PRIVMSG NICKSERV :IDENTIFY " + nickPassword);
}
out.flush();
+ return socket;
}
- /** Closes a connection.
- * @throws IOException In case of connection problems.
- */
- private void disconnect() throws IOException {
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
try {
- final Socket socket = this.socket;
- if (socket != null) {
- socket.close();
- }
+ super.close();
} finally {
- socket = null;
in = null;
out = null;
}
@@ -139,7 +124,7 @@
}
return 0;
} finally {
- disconnect();
+ close();
}
}
@@ -178,20 +163,4 @@
this.nickPassword = nickPassword;
}
- /** 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;
- }
-
- /** 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;
- }
-
} // class IRCConnection
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2007-06-17 14:38:03
|
Revision: 75
http://svn.sourceforge.net/cherbot/?rev=75&view=rev
Author: christianhujer
Date: 2007-06-17 07:37:59 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Committing current state of DaimoninConnection (doesn't work yet).
Added Paths:
-----------
trunk/src/net/sf/cherbot/DaimoninConnection.java
Added: trunk/src/net/sf/cherbot/DaimoninConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/DaimoninConnection.java (rev 0)
+++ trunk/src/net/sf/cherbot/DaimoninConnection.java 2007-06-17 14:37:59 UTC (rev 75)
@@ -0,0 +1,208 @@
+/*
+ * 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.io.InputStream;
+import java.io.OutputStream;
+import java.io.BufferedOutputStream;
+import java.io.EOFException;
+import java.net.Socket;
+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 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 BasicCommand {
+
+ /** 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;
+
+ /** The host to connect to. */
+ @NotNull private String host = DEFAULT_DAIMONIN_HOST;
+
+ /** The port to connect to. */
+ private int port = DEFAULT_DAIMONIN_PORT;
+
+ /** The username to authenticate with. */
+ @NotNull private String username;
+
+ /** The password to authenticate with. */
+ @NotNull private String password;
+
+ /** The Socket for communication. */
+ @Nullable private Socket socket;
+
+ /** The PrintStream to write to. */
+ @Nullable private OutputStream out;
+
+ /** The BufferedReader to read from. */
+ @Nullable private InputStream in;
+
+ /** Creates a DaimoninConnection. */
+ public DaimoninConnection() {
+ }
+
+ /** Main program.
+ * @param args Command line arguments.
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new DaimoninConnection(), args);
+ }
+
+ /** Establishes a connection.
+ * @throws IOException In case of connection problems.
+ */
+ private void connect() throws IOException {
+ final Socket socket = new Socket(host, port);
+ this.socket = socket;
+ final OutputStream out = new BufferedOutputStream(socket.getOutputStream());
+ this.out = out;
+ final InputStream in = socket.getInputStream();
+ this.in = in;
+
+ // read server version
+ readToNull();
+
+ // send client version
+ //textMsg("version 991023 991023 CherBot");
+ textMsg("version 991023 991023 Daimonin SDL Client"); // we have to cheat or the server won't let us in.
+
+ //textMsg("setup");
+ //readToNull();
+ textMsg("addme");
+ readToNull();
+ textMsg("reply L" + username);
+ readToNull();
+ textMsg("reply " + password);
+ // write 0x00 0x29 "version 991023 991023 Daimonin SDL Client"
+ // TODO
+ // read 0x00 0x1e 0x02 "991023 991023 Daimonin Server"
+ // write 0x00 0x99 "setup sound 1 map2 cmd 1 mapsize 17x17 darkness 1 facecache 1 skf 3386|dd257ea spf 2737|404f6ead bpf 227483|8ab2a06 stf 2253|16d49f0f amf 262790|ec2627ee"
+ // read 0x00 0x75 0x17 " sound 1 map2cmd 1 mapsize 17x17 darkness 1 facecache 1 skf OK spf OK bpf 227639|117ae13a stf OK amf 263415|ec0d5f79"
+ // write 0x00 0x04 "rf 4"
+ // read lots of data
+ // write 0x00 0x04 "rf 3"
+ // read lots of data
+ // write 0x00 0x05 "addme"
+ // read 0x00 0x06 0x18 "4 QN0" 0x00 0x01 0x15
+ // write 0x00 0x12 "reply LFoobuzzer49" // L not part of name
+ // read 0x00 0x06 0x18 "4 QP0"
+ // write 0x00 0x0E "reply xxxxxxxx"
+ }
+
+ /** 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();
+ }
+
+ /** Closes a connection.
+ * @throws IOException In case of connection problems.
+ */
+ private void disconnect() throws IOException {
+ try {
+ final Socket socket = this.socket;
+ if (socket != null) {
+ socket.close();
+ }
+ } finally {
+ socket = null;
+ in = null;
+ out = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public int run(@NotNull final List<String> args) throws Exception {
+ connect();
+ Thread.sleep(10000);
+ disconnect();
+ 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;
+ }
+
+ /** Sets the host to connect to.
+ * @param host Host to connect to
+ */
+ @Option({"host"})
+ public void setHost(@NotNull final String host) {
+ this.host = host;
+ }
+
+ /** Sets the port to connect to.
+ * @param port Port to connect to
+ */
+ @Option({"port"})
+ public void setPort(@NotNull final Integer port) {
+ this.port = port;
+ }
+
+} // class DaimoninConnection
Property changes on: trunk/src/net/sf/cherbot/DaimoninConnection.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.
|