[vlma-devel] commit: An IRC Notifier. (Adrien Grand )

git version control git at videolan.org
Thu May 15 00:56:01 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Thu May 15 00:55:31 2008 +0200| [41d032bc5dc226624e41b6b36dd21ab933a3aec1]

An IRC Notifier.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=41d032bc5dc226624e41b6b36dd21ab933a3aec1
---

 .../org/videolan/vlma/notifier/IRCNotifier.java    |   79 ++++++++++++++++++++
 vlma-daemon/src/main/resources/config.properties   |    4 +
 vlma-daemon/src/main/resources/daemon.xml          |    3 +
 3 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java b/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java
new file mode 100644
index 0000000..2fa5e55
--- /dev/null
+++ b/vlma-core/src/main/java/org/videolan/vlma/notifier/IRCNotifier.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2006-2008 the VideoLAN team
+ *
+ * This file is part of VLMa.
+ *
+ * VLMa is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * VLMa is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VLMa. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package org.videolan.vlma.notifier;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.Socket;
+
+import org.videolan.vlma.VLMa;
+
+/**
+ * An IRC notifier.
+ *
+ * @author jpountz
+ */
+public class IRCNotifier extends Notifier {
+
+    private Socket ircSocket = new Socket();
+    private PrintWriter out;
+    private String chan;
+    private String host;
+    private int port;
+    private String nick;
+
+    private void connect() throws IOException {
+        nick = VLMa.getInstance().getString("vlma.notification.irc.nick");
+        host = VLMa.getInstance().getString("vlma.notification.irc.host");
+        port = VLMa.getInstance().getInt("vlma.notification.irc.port");
+        chan = VLMa.getInstance().getString("vlma.notification.irc.chan");
+        ircSocket = new Socket(host, port);
+        ircSocket.setKeepAlive(true);
+        out = new PrintWriter(new OutputStreamWriter(ircSocket.getOutputStream()),true);
+        out.println("NICK " + nick);
+        out.println("USER " + nick + " hostname " + host +" :Hallo");
+        out.println("JOIN " + chan);
+    }
+
+    private boolean isIRCEnabled() {
+        String tmp = VLMa.getInstance().getString("vlma.notification.irc.chan");
+        return (tmp != null && tmp.length() > 0);
+    }
+
+    @Override
+    public void sendNotification(String message) {
+        if (isIRCEnabled()) {
+            if (!ircSocket.isConnected()) {
+                try {
+                    connect();
+                } catch (IOException e) {
+                    logger.error("Unable to connect.", e);
+                    return;
+                }
+            }
+            out.println("PRIVMSG " + chan + " " + message);
+        }
+    }
+
+}
diff --git a/vlma-daemon/src/main/resources/config.properties b/vlma-daemon/src/main/resources/config.properties
index e9f516d..6b5d271 100644
--- a/vlma-daemon/src/main/resources/config.properties
+++ b/vlma-daemon/src/main/resources/config.properties
@@ -9,6 +9,10 @@ vlc.stream.ttl = 12
 vlc.telnet.delay = 1000
 vlc.telnet.password = admin
 vlc.telnet.port = 4212
+vlma.notification.irc.chan =
+vlma.notification.irc.host = irc.freenode.net
+vlma.notification.irc.nick = vlma
+vlma.notification.irc.port = 6667
 vlma.notification.mail.host = localhost
 vlma.notification.mail.recipients =
 vlma.notification.mail.sender = VideoLAN Manager <noreply at videolan.org>
diff --git a/vlma-daemon/src/main/resources/daemon.xml b/vlma-daemon/src/main/resources/daemon.xml
index 7b1e931..83426ca 100644
--- a/vlma-daemon/src/main/resources/daemon.xml
+++ b/vlma-daemon/src/main/resources/daemon.xml
@@ -49,6 +49,7 @@
         <property name="notifiers">
             <list>
                 <ref bean="mailNotifier" />
+                <ref bean="ircNotifier" />
             </list>
         </property>
     </bean>
@@ -57,6 +58,8 @@
 	    <property name="data" ref="dataSource" />
 	</bean>
 
+    <bean id="ircNotifier" class="org.videolan.vlma.notifier.IRCNotifier" />
+
     <bean id="mailNotifier" class="org.videolan.vlma.notifier.MailNotifier">
         <property name="mailSender" ref="mailSender" />
     </bean>



More information about the vlma-devel mailing list