Permalink
Browse files

Refactorization

  • Loading branch information...
1 parent 1fb98cb commit 3593ac0fcb46533904c29d3b05886b3dc496cfa2 @Sutto committed Nov 4, 2008
Showing with 790 additions and 1,545 deletions.
  1. +2 −0 .gitignore
  2. +23 −0 default_stores.rb
  3. +89 −0 irc_channel.rb
  4. +496 −0 irc_client.rb
  5. 0 ircreplies.rb → irc_replies.rb
  6. +125 −0 irc_server.rb
  7. +0 −609 ircclient.rb
  8. +17 −901 ircd.rb
  9. +14 −0 net_utils.rb
  10. +0 −35 netutils.rb
  11. +24 −0 synchronized_store.rb
View
@@ -0,0 +1,2 @@
+**/.DS_Store
+messages.data
View
@@ -0,0 +1,23 @@
+$user_store = SynchronizedStore.new
+class << $user_store
+ def <<(client)
+ self[client.nick] = client
+ end
+
+ alias nicks keys
+ alias each_user each_value
+end
+
+$channel_store = SynchronizedStore.new
+class << $channel_store
+ def add(c)
+ self[c] ||= IRCChannel.new(c)
+ end
+
+ def remove(c)
+ self.delete[c]
+ end
+
+ alias each_channel each_value
+ alias channels keys
+end
View
@@ -0,0 +1,89 @@
+class IRCChannel < SynchronizedStore
+ include NetUtils
+ attr_reader :name, :topic
+ alias each_user each_value
+
+ def initialize(name)
+ super()
+
+ @topic = "There is no topic"
+ @name = name
+ @oper = []
+ carp "create channel:#{@name}"
+ end
+
+ def add(client)
+ @oper << client.nick if @oper.empty? and @store.empty?
+ self[client.nick] = client
+ end
+
+ def remove(client)
+ delete(client.nick)
+ end
+
+ def join(client)
+ return false if is_member? client
+ add client
+ #send join to each user in the channel
+ each_user {|user|
+ user.reply :join, client.userprefix, @name
+ }
+ return true
+ end
+
+ def part(client, msg)
+ return false if !is_member? client
+ each_user {|user|
+ user.reply :part, client.userprefix, @name, msg
+ }
+ remove client
+ $channel_store.delete(@name) if self.empty?
+ return true
+ end
+
+ def quit(client, msg)
+ #remove client should happen before sending notification
+ #to others since we dont want a notification to ourselves
+ #after quit.
+ remove client
+ each_user {|user|
+ user.reply :quit, client.userprefix, @name, msg if user!= client
+ }
+ $channel_store.delete(@name) if self.empty?
+ end
+
+ def privatemsg(msg, client)
+ each_user {|user|
+ user.reply :privmsg, client.userprefix, @name, msg if user != client
+ }
+ end
+
+ def notice(msg, client)
+ each_user {|user|
+ user.reply :notice, client.userprefix, @name, msg if user != client
+ }
+ end
+
+ def topic(msg=nil,client=nil)
+ return @topic if msg.nil?
+ @topic = msg
+ each_user {|user|
+ user.reply :topic, client.userprefix, @name, msg
+ }
+ return @topic
+ end
+
+ def nicks
+ return keys
+ end
+
+ def mode(u)
+ return @oper.include?(u.nick) ? '@' : ''
+ end
+
+ def is_member?(m)
+ values.include?(m)
+ end
+
+ alias has_nick? is_member?
+end
Oops, something went wrong.

0 comments on commit 3593ac0

Please sign in to comment.