Class: IRC::Server
- Defined in:
- lib/failirc/server.rb,
lib/failirc/server/link.rb,
lib/failirc/server/user.rb,
lib/failirc/server/links.rb,
lib/failirc/server/users.rb,
lib/failirc/server/client.rb,
lib/failirc/server/module.rb,
lib/failirc/server/channel.rb,
lib/failirc/server/clients.rb,
lib/failirc/server/channels.rb,
lib/failirc/server/dispatcher.rb,
lib/failirc/server/modules/Base.rb,
lib/failirc/server/modules/Netlog.rb,
lib/failirc/server/modules/TinyURL.rb,
lib/failirc/server/dispatcher/event.rb,
lib/failirc/server/modules/Cloaking.rb,
lib/failirc/server/modules/Firewall.rb,
lib/failirc/server/modules/Roulette.rb,
lib/failirc/server/modules/Translate.rb,
lib/failirc/server/modules/WordFilter.rb,
lib/failirc/server/dispatcher/eventdispatcher.rb,
lib/failirc/server/dispatcher/connectiondispatcher.rb
Defined Under Namespace
Modules: Modules Classes: Channel, Channels, Client, Clients, Dispatcher, Link, Links, Module, User, Users
Constant Summary collapse
- Event =
Dispatcher::Event
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#config ⇒ Object
Returns the value of attribute config.
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#createdOn ⇒ Object
readonly
Returns the value of attribute createdOn.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #clients ⇒ Object
- #comments ⇒ Object
- #host ⇒ Object (also: #to_s)
-
#initialize(conf, verbose) ⇒ Server
constructor
A new instance of Server.
- #ip ⇒ Object
-
#kill(thing, message = nil, force = false) ⇒ Object
kill connection with harpoons on fire.
- #links ⇒ Object
- #listen(*args) ⇒ Object
- #loadModule(name, path = nil, reload = false) ⇒ Object
- #name ⇒ Object
-
#rehash ⇒ Object
reload the config and modules’ configurations.
- #start ⇒ Object
- #stop ⇒ Object
- #stopping? ⇒ Boolean
Constructor Details
#initialize(conf, verbose) ⇒ Server
Returns a new instance of Server.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/failirc/server.rb', line 38 def initialize (conf, verbose) @version = IRC::VERSION @createdOn = Time.now @verbose = verbose ? true : false @dispatcher = Dispatcher.new(self) @modules = {} @data = ThreadSafeHash.new @channels = Channels.new(self) self.config = conf end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def channels @channels end |
#config ⇒ Object
Returns the value of attribute config.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def config @config end |
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def connections @connections end |
#createdOn ⇒ Object (readonly)
Returns the value of attribute createdOn.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def createdOn @createdOn end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def data @data end |
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def dispatcher @dispatcher end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def modules @modules end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def verbose @verbose end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
36 37 38 |
# File 'lib/failirc/server.rb', line 36 def version @version end |
Instance Method Details
#clients ⇒ Object
54 55 56 |
# File 'lib/failirc/server.rb', line 54 def clients dispatcher.connection.clients end |
#comments ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/failirc/server.rb', line 62 def comments result = '' modules.each_value {|mod| begin result << " #{mod.description}" rescue end } return result[1, result.length] end |
#host ⇒ Object Also known as: to_s
75 76 77 |
# File 'lib/failirc/server.rb', line 75 def host @config.elements['config/server/host'].text end |
#ip ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/failirc/server.rb', line 79 def ip begin return Resolv.getaddress(@config.elements['config/server/host'].text) rescue return Resolv.getaddress('localhost') end end |
#kill(thing, message = nil, force = false) ⇒ Object
kill connection with harpoons on fire
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/failirc/server.rb', line 169 def kill (thing, =nil, force=false) if !thing || (thing.modes[:killing] && (!force || thing.modes[:kill_forcing])) || !@dispatcher.connections.exists?(thing.socket) return end if thing.is_a?(User) thing = thing.client end thing.modes[:killing] = true if force thing.modes[:kill_forcing] = true tmp = @dispatcher.output[thing].drop_while {|item| item != :EOC } @dispatcher.output[thing].clear @dispatcher.output[thing].insert(-1, *tmp) end @dispatcher.output.push(thing, :EOC) @dispatcher.output.push(thing, ) end |
#links ⇒ Object
58 59 60 |
# File 'lib/failirc/server.rb', line 58 def links dispatcher.connection.links end |
#listen(*args) ⇒ Object
164 165 166 |
# File 'lib/failirc/server.rb', line 164 def listen (*args) @dispatcher.connection.listen(*args) end |
#loadModule(name, path = nil, reload = false) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/failirc/server.rb', line 91 def loadModule (name, path=nil, reload=false) if @modules[name] && !reload return end begin if path[0] == '/' $LOAD_PATH.push path require name $LOAD_PATH.pop else require "#{path}/#{name}" end klass = eval("Modules::#{name}") rescue nil if klass @modules[name] = klass.new(self) self.debug "Loaded `#{name}`." else raise Exception end rescue Exception => e self.debug "Failed to load `#{name}`." self.debug e end end |
#name ⇒ Object
87 88 89 |
# File 'lib/failirc/server.rb', line 87 def name @config.elements['config/server/name'].text end |
#rehash ⇒ Object
reload the config and modules’ configurations
196 197 198 |
# File 'lib/failirc/server.rb', line 196 def rehash self.config = @configReference end |
#start ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/failirc/server.rb', line 119 def start if @started return end if !@config raise 'config is missing.' end @started = true @config.elements.each('config/server/listen') {|listen| self.listen({ :bind => listen.attributes['bind'], :port => listen.attributes['port'], :ssl => listen.attributes['ssl'], :ssl_cert => listen.attributes['sslCert'], :ssl_key => listen.attributes['sslKey'] }, listen) } @dispatcher.start end |
#stop ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/failirc/server.rb', line 144 def stop @stopping = true begin dispatcher.stop @modules.each {|mod| mod.finalize } rescue end @stopping = false @started = false end |
#stopping? ⇒ Boolean
160 161 162 |
# File 'lib/failirc/server.rb', line 160 def stopping? @stopping end |