1. raichoo
  2. sakura

Commits

raichoo  committed ed57a5a

added tokenizer and minor cleanups

  • Participants
  • Parent commits 92c670c
  • Branches default

Comments (0)

Files changed (5)

File src/sakura/IRCConnector.scala

View file
  • Ignore whitespace
             try {
               println(processInput(input.readLine))
             } catch {
-              case e: Exception => println(e.toString)
+              case e: Exception => {}
             }
           }
         case _ => {}
         }
       case Ping(host) =>
         pong
-      case Part(nick, room) =>
+      case Part(nick, room) => {
         AnonConnector.leave(nick)
+      }
       case Join(nick, room) =>
         AnonConnector.join(nick, room)
-      case Quit(nick) =>
+      case Quit(nick) => {
         AnonConnector.leave(nick)
+      }
       case Nick(from, to) =>
         if (AnonConnector.isDummy(from))
           AnonConnector.renameUser(from, to)
         else
           AnonConnector.join(to, roomname)
       case cmd352(room, nick) =>
-        AnonConnector.pushUser(nick)
-      case cmd315(room) => {}
-        AnonConnector.flushUsers(room)
+        AnonConnector.join(nick, room)
       case _ => {}
     }
     input

File src/sakura/IRCRoom.scala

View file
  • Ignore whitespace
     if (AnonConnector.isDummy(from))
       return
     synchronized {
-      stream.println("PRIVMSG #" + room +
-                     " :[" + from +
-                     "]: " + msg)
-      stream.flush
+
+      tokenizeText(msg) map ( 
+        x => { stream.println("PRIVMSG #" + room +
+                              " :[" + from +
+                              "]: " + x)
+        stream.flush }
+     )
+
     }
   }
 
   }
 
   /**
+   * Split long text into tokens so IRC can swallow it
+   *
+   * @param text Text to be tokenized
+   */
+  private def tokenizeText(text: String): List[String] = {
+    if ((text size) < 480) {
+      List(text)
+    } else {
+      val (left, right) = text splitAt(480)
+      List(left) ++ this.tokenizeText(right)
+    }
+  }
+
+  /**
    * Send a message to this room that informs the occupants of a join
    * that just happened on the XMPP side
    *
    * Leave this room
    *
    * @todo Send a part message to the room
+   *
    */
   def leave(): Unit = {
     IRCConnector.room.leave

File src/sakura/XMPPConnector.scala

View file
  • Ignore whitespace
   val password = Main.config \ "connectors" \ "xmpp" \ "password" text
   val nick     = Main.config \ "connectors" \ "xmpp" \ "nick" text
 
-  // joined room
-  var room: XMPPRoom = null
-
   val JID     = new Regex("""(\w+)@(.+)/(.+)""")
   val Action  = new Regex("""/me (.+)""")
 
   // logon xmpp server and join rooms afterwards
   private val connection = login
-  joinRoom
+  val room = joinRoom
 
   /**
    * Log on XMPP Server with PLAIN Mechanism
   /**
    * Join preconfigued room
    */
-  private def joinRoom(): Unit = {
+  private def joinRoom(): XMPPRoom = {
     join ((Main.config \ "rooms" \ "xmpp") text)
   }
 
    * @todo Get rid of local Regex
    *
    */
-  def join(room: String): Unit = {
+  def join(room: String): XMPPRoom = {
     val tmp = new Regex("""(\w+)@(.+)""")
     val tmp(roomtojoin, service) = room
     val muc = new MultiUserChat(connection, room)
     muc.join(nick)
-    this.room = new XMPPRoom(muc)
+    new XMPPRoom(muc)
   }
 
   /**

File src/sakura/XMPPRoom.scala

View file
  • Ignore whitespace
     muc.sendMessage("[" + who + " left the channel]")
   }
 
-    /**
+ /**
   * Inform the room that someone on the IRC side has quit
   *
   * @param who Name of the user that has quit
    * Leave this room
    */
   def leave(): Unit = {
-    XMPPConnector.room = null
     muc.leave
   }
 

File src/sakura/ZoneStatusObserver.scala

View file
  • Ignore whitespace
 import java.io.InputStreamReader
 import java.io.OutputStreamWriter
 import java.io.PrintWriter
+import java.net.ConnectException
+import java.net.InetSocketAddress
 import java.net.Socket
 import org.jivesoftware.smack.packet.Message
-import org.jivesoftware.smack.packet.Presence
 import scala.actors.Actor
 import scala.actors.Actor._
 import scala.actors.TIMEOUT
    *
    */
   def isOpen(): Boolean = {
-    val wanker = new Socket(provider, 8000)
+    val wanker = new Socket
+    try {
+      wanker.connect(new InetSocketAddress(provider, 8000))
+    } catch {
+      case e: ConnectException => return false
+    }
     val in  = new BufferedReader(new InputStreamReader(wanker.getInputStream))
     val out = new PrintWriter(new OutputStreamWriter(wanker.getOutputStream))