Skip to content

Commit

Permalink
Merge remote branch 'bpmcd/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
danlarkin committed Sep 21, 2012
2 parents e2b95d5 + 54fdd85 commit 3679378
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -5,3 +5,6 @@ classes
*~
log
.lein-failures
.classpath
.project
.lein-deps-sum
10 changes: 6 additions & 4 deletions project.clj
Expand Up @@ -3,10 +3,12 @@
:resources-path "etc"
:repositories {"jboss"
"http://repository.jboss.org/nexus/content/groups/public/"}
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[org.clojure/tools.logging "0.2.3"]
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/tools.logging "0.2.4"]
[org.clojure/tools.namespace "0.1.3"]
[slingshot "0.10.3"]
[log4j "1.2.16"]
[org.jboss.netty/netty "3.2.1.Final"]
[swank-clojure "1.3.2"]]
:dev-dependencies [[lein-tar "1.0.5"]])
:dev-dependencies [[lein-tar "1.0.5"]
[commons-io "2.2"]])
7 changes: 4 additions & 3 deletions src/subrosa/client.clj
@@ -1,6 +1,7 @@
(ns subrosa.client
(:require [subrosa.database :as db])
(:use [clojure.contrib.condition :only [raise]]
(:use [clojure.set :only [difference]]
[slingshot.slingshot :only [throw+]]
[subrosa.server]
[subrosa.config :only [config]]))

Expand Down Expand Up @@ -129,7 +130,7 @@
(send-welcome channel)
(send-motd channel)
(send-lusers channel))
(raise {:type :protocol-error
(throw+ {:type :protocol-error
:disconnect true
:msg ":Bad Password"})))))

Expand Down Expand Up @@ -230,7 +231,7 @@
(send-to-client* chan msg)))

(defn send-to-clients-in-rooms-for-nick [nick msg channel]
(doseq [chan (clojure.set/difference
(doseq [chan (difference
(into #{} (for [room-name (rooms-for-nick nick)
chan (channels-in-room room-name)]
chan))
Expand Down
80 changes: 40 additions & 40 deletions src/subrosa/commands.clj
Expand Up @@ -5,7 +5,7 @@
[subrosa.config :only [config]]
[subrosa.server :only [supported-room-modes]]
[clojure.string :only [join]]
[clojure.contrib.condition :only [raise]])
[slingshot.slingshot :only [throw+]])
(:require [clojure.tools.logging :as log])
(:import [org.jboss.netty.channel ChannelFutureListener]))

Expand All @@ -17,7 +17,7 @@
(when-not (empty? message)
(log/debug "Received unhandled command:" message)
(when (authenticated? channel)
(raise {:type :client-error
(throw+ {:type :client-error
:code 421
:msg (format "%s :Unknown command" cmd)})))))))

Expand Down Expand Up @@ -65,13 +65,13 @@
(add-user-for-nick! channel nick)
(maybe-add-authentication-step! channel "NICK")
(maybe-update-authentication! channel))
(raise {:type :client-error
(throw+ {:type :client-error
:code 433
:msg (format "%s :Nickname is already in use" nick)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 432
:msg (format "%s :Erroneous nickname" nick)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 431
:msg ":No nickname given"})))

Expand All @@ -83,10 +83,10 @@
(update-user-for-nick! (nick-for-channel channel) parts)
(maybe-add-authentication-step! channel "USER")
(maybe-update-authentication! channel))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "USER :Not enough parameters"})))
(raise {:type :client-error
(throw+ {:type :client-error
:code 462
:msg ":Unauthorized command (already registered)"})))

Expand All @@ -98,14 +98,14 @@
(dosync
(maybe-add-authentication-step! channel "PASS")
(maybe-update-authentication! channel))
(raise {:type :protocol-error
(throw+ {:type :protocol-error
:disconnect true
:msg ":Bad Password"}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:disconnect true
:msg "PASS :Not enough parameters"}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 462
:disconnect true
:msg ":Unauthorized command (already registered)"})))
Expand Down Expand Up @@ -150,13 +150,13 @@
(dispatch-message (format "TOPIC %s" room-name) channel)
(dispatch-message (format "NAMES %s" room-name) channel)
(run-hook 'join-hook channel room-name))
(raise {:type :client-error
(throw+ {:type :client-error
:code 403
:msg (format "%s :No such channel" room-name)})))))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "JOIN :Not enough parameters"}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "JOIN :Too many parameters"}))))

Expand All @@ -179,22 +179,22 @@
room-name
new-topic)))
(run-hook 'topic-hook channel room-name old-topic new-topic))
(raise {:type :client-error
(throw+ {:type :client-error
:code 442
:msg (format "%s :You're not on that channel"
room-name)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg (format "TOPIC :Not enough parameters")}))
(if-let [topic (topic-for-room room-name)]
(send-to-client channel 332
(format "%s :%s" room-name topic))
(send-to-client channel 331
(format "%s :No topic is set" room-name))))
(raise {:type :client-error
(throw+ {:type :client-error
:code 403
:msg (format "%s :No such channel" room-name)})))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "TOPIC :Not enough parameters"})))

Expand Down Expand Up @@ -224,13 +224,13 @@
(send-to-client* channel msg)
(run-hook 'privmsg-nick-hook
channel recipient plain-msg))
(raise {:type :client-error
(throw+ {:type :client-error
:code 401
:msg (format "%s :No such nick/channel" recipient)}))))
(raise {:type :client-error
(throw+ {:type :client-error
:code 412
:msg ":No text to send"}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 411
:msg ":No recipient given (PRIVMSG)"}))))

Expand All @@ -252,13 +252,13 @@
(defcommand ping [channel server]
(if (not (empty? server))
(send-to-client* channel (format "PONG %s :%s" (hostname) server))
(raise {:type :client-error
(throw+ {:type :client-error
:code 409
:msg ":No origin specified"})))

(defcommand pong [channel server]
(when (empty? server)
(raise {:type :client-error
(throw+ {:type :client-error
:code 409
:msg ":No origin specified"})))

Expand All @@ -278,10 +278,10 @@
user-name
(apply str (interpose " " rooms))))
(send-to-client channel 318 ":End of WHOIS list"))
(raise {:type :client-error
(throw+ {:type :client-error
:code 401
:msg (format "%s :No such nick/channel" username)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 431
:msg ":No nickname given"})))

Expand Down Expand Up @@ -326,13 +326,13 @@
part-message))
(remove-nick-from-room! nick room)
(run-hook 'part-hook channel room part-message))
(raise {:type :client-error
(throw+ {:type :client-error
:code 442
:msg (format "%s :You're not on that channel" room)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 403
:msg (format "%s :No such channel" room)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "PART :Not enough parameters"})))))

Expand Down Expand Up @@ -373,7 +373,7 @@
(send-to-client channel 303 (format ":%s"
(apply str
(interpose " " on-nicks)))))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "ISON :Not enough parameters"})))

Expand All @@ -396,20 +396,20 @@
(if (room-for-name room-name)
(if (nick-in-room? sender-nick room-name)
(do-invite)
(raise {:type :client-error
(throw+ {:type :client-error
:code 442
:msg (format "%s :You're not on that channel"
room-name)}))
(do-invite))
(raise {:type :client-error
(throw+ {:type :client-error
:code 443
:msg (format "%s %s :is already on channel"
target-nick
room-name)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 401
:msg (format "%s :No such nick/channel" target-nick)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "INVITE :Not enough parameters"}))))

Expand All @@ -432,17 +432,17 @@
comment))
(remove-nick-from-room! nick room)
(run-hook 'kick-hook channel room nick comment))
(raise {:type :client-error
(throw+ {:type :client-error
:code 441
:msg (format
"%s %s :They aren't on that channel"
nick
room)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 442
:msg (format "%s :You're not on that channel"
room)}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 403
:msg (format "%s :No such channel" room)})))]
(cond
Expand All @@ -456,10 +456,10 @@
(doseq [[room nick] (zipmap rooms nicks)]
(do-kick nick room))

:else (raise {:type :client-error
:else (throw+ {:type :client-error
:code 461
:msg "KICK :Not enough parameters"})))
(raise {:type :client-error
(throw+ {:type :client-error
:code 461
:msg "KICK :Not enough parameters"}))))

Expand Down Expand Up @@ -491,14 +491,14 @@
(format-client channel)
room-name
(format-mode enable? new-mode))))))
(raise {:type :client-error
(throw+ {:type :client-error
:code 472
:msg (format "%s :is unknown mode char to me for %s"
(first new-mode)
room-name)}))))
(raise {:type :client-error
(throw+ {:type :client-error
:code 501
:msg ":Unknown MODE flag"}))
(raise {:type :client-error
(throw+ {:type :client-error
:code 401
:msg (format "%s :No such nick/channel" room-name)}))))
2 changes: 1 addition & 1 deletion src/subrosa/database.clj
Expand Up @@ -2,7 +2,7 @@
(:refer-clojure :exclude [get])
(:import [java.util UUID]))

(defonce db (ref {}))
(defonce ^:dynamic db (ref {}))

(defn ensure-id [m]
(if (:id m)
Expand Down
7 changes: 4 additions & 3 deletions src/subrosa/netty.clj
Expand Up @@ -8,7 +8,8 @@
[subrosa.plugins :only [load-plugins]]
[clojure.stacktrace :only [root-cause]])
(:require [clojure.tools.logging :as log])
(:import [java.net InetSocketAddress]
(:import clojure.lang.ExceptionInfo
[java.net InetSocketAddress]
[java.util.concurrent Executors]
[org.jboss.netty.bootstrap ServerBootstrap]
[org.jboss.netty.channel ChannelUpstreamHandler
Expand Down Expand Up @@ -48,8 +49,8 @@

(defn netty-error-handler [up-or-down evt]
(when (instance? ExceptionEvent evt)
(if (instance? clojure.contrib.condition.Condition (root-cause evt))
(let [condition (meta (root-cause evt))
(if (instance? ExceptionInfo (root-cause evt))
(let [condition (:object (ex-data (root-cause evt)))
chan-future-agent
(condp = (:type condition)
:client-error (send-to-client
Expand Down
2 changes: 1 addition & 1 deletion src/subrosa/plugins.clj
@@ -1,5 +1,5 @@
(ns subrosa.plugins
(:use [clojure.contrib.find-namespaces]))
(:use [clojure.tools.namespace]))

(defn find-plugins []
(filter #(.startsWith (str %) "subrosa.plugins.")
Expand Down
4 changes: 2 additions & 2 deletions src/subrosa/plugins/catchup.clj
Expand Up @@ -3,7 +3,7 @@
[subrosa.config :only [config]]
[subrosa.client]
[subrosa.hooks :only [add-hook]]
[clojure.contrib.condition :only [raise]])
[slingshot.slingshot :only [throw+]])
(:import (java.util Date)
(java.text SimpleDateFormat)))

Expand Down Expand Up @@ -61,6 +61,6 @@
sender type room msg)))
(send-to-client*
channel (format ":*** PRIVMSG %s :%s" room "Catchup Complete")))
(raise {:type :client-error
(throw+ {:type :client-error
:code 442
:msg (format "%s :You're not on that channel" room)}))))))
2 changes: 1 addition & 1 deletion src/subrosa/utils.clj
Expand Up @@ -16,7 +16,7 @@
(if (not (seq bindings))
`(do ~@body)
(let [old-value-sym (gensym)]
`(let [~old-value-sym (.getRoot #'~(first bindings))]
`(let [~old-value-sym (.getRawRoot #'~(first bindings))]
(alter-var-root #'~(first bindings) (fn [& _#] ~(second bindings)))
(try (with-var-root ~(nnext bindings) ~@body)
(finally
Expand Down

0 comments on commit 3679378

Please sign in to comment.