commit 54e4e997cd19fd6bea001a559d794135a98690ad Author: Lucas Pleß Date: Tue Jun 12 17:30:41 2012 +0200 initial commit diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..1b8cd54 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +crashtestCardPlayer \ No newline at end of file diff --git a/.idea/ant.xml b/.idea/ant.xml new file mode 100644 index 0000000..2581ca3 --- /dev/null +++ b/.idea/ant.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/artifacts/crashtestcardplayer.xml b/.idea/artifacts/crashtestcardplayer.xml new file mode 100644 index 0000000..720d1a9 --- /dev/null +++ b/.idea/artifacts/crashtestcardplayer.xml @@ -0,0 +1,13 @@ + + + $PROJECT_DIR$/out/artifacts/crashtestcardplayer + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..a1b41c5 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..3572571 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/libraries/jerklib.xml b/.idea/libraries/jerklib.xml new file mode 100644 index 0000000..2090b94 --- /dev/null +++ b/.idea/libraries/jerklib.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1676c22 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,48 @@ + + + + + + + http://www.w3.org/1999/xhtml + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..41f1038 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..275077f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..6bdcfe7 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,621 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + 1339452055659 + 1339452055659 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + crashtestcardplayer + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.6 + + + + + + + + crashtestCardPlayer + + + + + + + + 1.6 + + + + + + + + jerklib + + + + + + + + + diff --git a/crashtestCardPlayer.iml b/crashtestCardPlayer.iml new file mode 100644 index 0000000..bdbba10 --- /dev/null +++ b/crashtestCardPlayer.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/libs/jerklib.jar b/libs/jerklib.jar new file mode 100644 index 0000000..ac29b29 Binary files /dev/null and b/libs/jerklib.jar differ diff --git a/messages.txt b/messages.txt new file mode 100644 index 0000000..a9d49f1 --- /dev/null +++ b/messages.txt @@ -0,0 +1,10 @@ +NICHT DEN RAUM ZERSTOEREN +**** COMMODORE 64 BASIC V2 **** 64K RAM SYSTEM 38911 BASIC BYTES FREE READY. +Ich sag euch nicht alles vor - der freundliche schildermaler +mindestens drei von euch muessen es schafffen +jeder eine rakete +konzentriert euch auf den tisch!! +Beachtet die Dose und die Punkte +ja +weiter +.... au backe \ No newline at end of file diff --git a/out/artifacts/crashtestcardplayer/crashtestcardplayer.jar b/out/artifacts/crashtestcardplayer/crashtestcardplayer.jar new file mode 100644 index 0000000..e138f13 Binary files /dev/null and b/out/artifacts/crashtestcardplayer/crashtestcardplayer.jar differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/HostHelper.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/HostHelper.class new file mode 100644 index 0000000..324adea Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/HostHelper.class differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/Main.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/Main.class new file mode 100644 index 0000000..3433e78 Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/Main.class differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/MainFrame$1.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/MainFrame$1.class new file mode 100644 index 0000000..de09ace Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/MainFrame$1.class differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/MainFrame.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/MainFrame.class new file mode 100644 index 0000000..24f20bd Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/MainFrame.class differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IIrcClient.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IIrcClient.class new file mode 100644 index 0000000..17e5eda Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IIrcClient.class differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IRCEventListener.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IRCEventListener.class new file mode 100644 index 0000000..de2070e Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IRCEventListener.class differ diff --git a/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IrcClient.class b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IrcClient.class new file mode 100644 index 0000000..d150f1e Binary files /dev/null and b/out/production/crashtestCardPlayer/de/ctdo/crashtest/cardplayer/irc/IrcClient.class differ diff --git a/src/MANIFEST.MF b/src/MANIFEST.MF new file mode 100644 index 0000000..d967ac5 --- /dev/null +++ b/src/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: de.ctdo.crashtest.cardplayer.Main + diff --git a/src/de/ctdo/crashtest/cardplayer/HostHelper.java b/src/de/ctdo/crashtest/cardplayer/HostHelper.java new file mode 100644 index 0000000..2a5621e --- /dev/null +++ b/src/de/ctdo/crashtest/cardplayer/HostHelper.java @@ -0,0 +1,25 @@ +package de.ctdo.crashtest.cardplayer; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * User: lpless + * Date: 12.06.12 + * Time: 00:12 + */ +public class HostHelper { + + public static String getHostName() { + String retVal = "CardPlayer"; + + try { + InetAddress addr = InetAddress.getLocalHost(); + byte[] ipAddr = addr.getAddress(); + retVal = addr.getHostName(); + } catch (UnknownHostException e) { + } + + return retVal; + } +} diff --git a/src/de/ctdo/crashtest/cardplayer/Main.java b/src/de/ctdo/crashtest/cardplayer/Main.java new file mode 100644 index 0000000..1ea3d7d --- /dev/null +++ b/src/de/ctdo/crashtest/cardplayer/Main.java @@ -0,0 +1,15 @@ +package de.ctdo.crashtest.cardplayer; + +/** + * User: lpless + * Date: 12.06.12 + * Time: 00:03 + */ +public class Main { + + public static void main(String args[]) { + + new MainFrame(); + + } +} diff --git a/src/de/ctdo/crashtest/cardplayer/MainFrame.java b/src/de/ctdo/crashtest/cardplayer/MainFrame.java new file mode 100644 index 0000000..95141c5 --- /dev/null +++ b/src/de/ctdo/crashtest/cardplayer/MainFrame.java @@ -0,0 +1,77 @@ +package de.ctdo.crashtest.cardplayer; + +import de.ctdo.crashtest.cardplayer.irc.*; +import javax.swing.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.*; +import java.util.Vector; + +public class MainFrame extends JFrame { + private IrcClient irc; + private JList jList; + + public MainFrame() { + setDefaultCloseOperation(EXIT_ON_CLOSE); + setTitle("CrastestCardPlayer"); + setBounds(100, 100, 600, 400); + + irc = new IrcClient(HostHelper.getHostName(), "#crashtest", "irc.ctdo.de"); + + initGui(); + + setVisible(true); + } + + private void initGui() { + jList = new JList(readData()); + jList.setLayoutOrientation(JList.VERTICAL); + jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + jList.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if(e.getClickCount() == 2){ + int index = jList.locationToIndex(e.getPoint()); + ListModel dlm = jList.getModel(); + Object item = dlm.getElementAt(index); + jList.ensureIndexIsVisible(index); + System.out.println("Double clicked on " + item); + irc.say("crashtest: wall " + item); + } + } + }); + + add(jList); + } + + + private Vector readData() { + try { + File file; + BufferedReader br; + + file = new File ("messages.txt"); + if(file.exists()) { + br = new BufferedReader(new FileReader (file)); + } else { + InputStream is = Main.class.getResourceAsStream("/messages.txt"); + br = new BufferedReader(new InputStreamReader(is)); + } + + Vector lines = new Vector(); + String line; + while((line=br.readLine())!=null) { + lines.add(line); + } + + return lines; + } catch(Exception e) { + e.printStackTrace(); + Vector vector = new Vector(); + vector.add("could not read the input file..."); + } + return null; + } + +} diff --git a/src/de/ctdo/crashtest/cardplayer/irc/IIrcClient.java b/src/de/ctdo/crashtest/cardplayer/irc/IIrcClient.java new file mode 100644 index 0000000..aff22de --- /dev/null +++ b/src/de/ctdo/crashtest/cardplayer/irc/IIrcClient.java @@ -0,0 +1,10 @@ +package de.ctdo.crashtest.cardplayer.irc; + +/** + * @author: lucas + * @date: 01.06.12 10:05 + */ +public interface IIrcClient { + void say(String message); + void addListener(IRCEventListener listenerIRC); +} diff --git a/src/de/ctdo/crashtest/cardplayer/irc/IRCEventListener.java b/src/de/ctdo/crashtest/cardplayer/irc/IRCEventListener.java new file mode 100644 index 0000000..c37afb2 --- /dev/null +++ b/src/de/ctdo/crashtest/cardplayer/irc/IRCEventListener.java @@ -0,0 +1,10 @@ +package de.ctdo.crashtest.cardplayer.irc; + +/** + * @author: lucas + * @date: 01.06.12 11:49 + */ +public interface IRCEventListener { + + void handleMessage(final String message); +} diff --git a/src/de/ctdo/crashtest/cardplayer/irc/IrcClient.java b/src/de/ctdo/crashtest/cardplayer/irc/IrcClient.java new file mode 100644 index 0000000..d85f525 --- /dev/null +++ b/src/de/ctdo/crashtest/cardplayer/irc/IrcClient.java @@ -0,0 +1,75 @@ +package de.ctdo.crashtest.cardplayer.irc; + +import jerklib.Channel; +import jerklib.ConnectionManager; +import jerklib.ProfileImpl; +import jerklib.Session; +import jerklib.events.ChannelMsgEvent; +import jerklib.events.ConnectionCompleteEvent; +import jerklib.events.IRCEvent; +import jerklib.events.JoinCompleteEvent; + +import java.util.ArrayList; +import java.util.List; + +/** + * IRC Client wrapper + * simplifies communication with the de.ctdo.crashtest.cardplayer.irc channel + */ +public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventListener { + private final List listenerListIRC = new ArrayList(); + private Session ircsession; + private final String channel; + private boolean joined = false; + + public IrcClient(String nick, String channel, String server) { + this.channel = channel; + ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl(nick,nick, nick+2, nick+3)); + ircsession = ircConnection.requestConnection(server); + ircsession.addIRCEventListener(this); + } + + @Override + public void recieveEvent(IRCEvent ircEvent) { + + if(ircEvent instanceof ConnectionCompleteEvent) { + ircEvent.getSession().joinChannel(channel); + System.out.println("connected"); + } + else if (ircEvent instanceof JoinCompleteEvent) { + JoinCompleteEvent jce = (JoinCompleteEvent) ircEvent; + jce.getChannel().say("hello master. what's your order?"); + System.out.println("joined"); + joined = true; + } + else if(ircEvent instanceof ChannelMsgEvent) { + ChannelMsgEvent cme = (ChannelMsgEvent)ircEvent; + + String message = cme.getMessage(); + final String nick = ircsession.getNick(); + + if(message.contains(nick)) { + message = message.substring(Math.max(nick.length(), message.indexOf(":")+1)); + message = message.trim(); + + for(IRCEventListener listenerIRC : listenerListIRC) { + listenerIRC.handleMessage(message); + } + } + } + } + + @Override + public void say(String message) { + if(ircsession != null && joined) { + for(Channel chan: ircsession.getChannels()) { + chan.say(message); + } + } + } + + @Override + public void addListener(final IRCEventListener listenerIRC) { + listenerListIRC.add(listenerIRC); + } +}