summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-08-03 18:20:56 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-08-03 18:20:56 +0000
commit9e008a694be3c87e7cf13f9b5c353d32afd4468a (patch)
tree759e90b661417c820d6dcc9bbf359bfe1aa63c0e /lib
parent9541057a74e533127377dfee4d3bc4831c564f8e (diff)
More responsive quits and some extra debug info for the new irc framework
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/irc.rb3
-rw-r--r--lib/rbot/ircbot.rb79
2 files changed, 43 insertions, 39 deletions
diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb
index 81bb48eb..93ac6b85 100644
--- a/lib/rbot/irc.rb
+++ b/lib/rbot/irc.rb
@@ -1159,7 +1159,8 @@ module Irc
# new_user(_str_, +false+)
#
def user(str)
- new_user(str, false)
+ u = new_user(str, false)
+ debug "Server user #{u.inspect} from #{str.inspect}"
end
# Remove User _someuser_ from the list of <code>User</code>s.
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index bbb58fac..d83a5fe4 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -340,6 +340,7 @@ class IrcBot
@timer = Timer::Timer.new(1.0) # only need per-second granularity
@save_mutex = Mutex.new
@timer.add(@config['core.save_every']) { save } if @config['core.save_every']
+ @quit_mutex = Mutex.new
@logs = Hash.new
@@ -549,14 +550,12 @@ class IrcBot
def got_sig(sig)
debug "received #{sig}, queueing quit"
$interrupted += 1
+ quit unless @quit_mutex.locked?
debug "interrupted #{$interrupted} times"
- if $interrupted >= 5
+ if $interrupted >= 3
debug "drastic!"
log_session_end
exit 2
- elsif $interrupted >= 3
- debug "quitting"
- quit
end
end
@@ -577,8 +576,10 @@ class IrcBot
rescue => e
raise e.class, "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e
end
+ quit if $interrupted > 0
@socket.emergency_puts "PASS " + @config['server.password'] if @config['server.password']
@socket.emergency_puts "NICK #{@config['irc.nick']}\nUSER #{@config['irc.user']} 4 #{@config['server.name']} :Ruby bot. (c) Tom Gilbert"
+ quit if $interrupted > 0
start_server_pings
end
@@ -591,11 +592,11 @@ class IrcBot
@timer.start
while @socket.connected?
+ quit if $interrupted > 0
if @socket.select
break unless reply = @socket.gets
@client.process reply
end
- quit if $interrupted > 0
end
# I despair of this. Some of my users get "connection reset by peer"
@@ -780,39 +781,41 @@ class IrcBot
# disconnect from the server and cleanup all plugins and modules
def shutdown(message = nil)
- debug "Shutting down ..."
- ## No we don't restore them ... let everything run through
- # begin
- # trap("SIGINT", "DEFAULT")
- # trap("SIGTERM", "DEFAULT")
- # trap("SIGHUP", "DEFAULT")
- # rescue => e
- # debug "failed to restore signals: #{e.inspect}\nProbably running on windows?"
- # end
- message = @lang.get("quit") if (message.nil? || message.empty?)
- if @socket.connected?
- debug "Clearing socket"
- @socket.clearq
- debug "Sending quit message"
- @socket.emergency_puts "QUIT :#{message}"
- debug "Flushing socket"
- @socket.flush
- debug "Shutting down socket"
- @socket.shutdown
- end
- debug "Logging quits"
- server.channels.each { |ch|
- irclog "@ quit (#{message})", ch
- }
- debug "Saving"
- save
- debug "Cleaning up"
- @plugins.cleanup
- # debug "Closing registries"
- # @registry.close
- debug "Cleaning up the db environment"
- DBTree.cleanup_env
- log "rbot quit (#{message})"
+ @quit_mutex.synchronize do
+ debug "Shutting down ..."
+ ## No we don't restore them ... let everything run through
+ # begin
+ # trap("SIGINT", "DEFAULT")
+ # trap("SIGTERM", "DEFAULT")
+ # trap("SIGHUP", "DEFAULT")
+ # rescue => e
+ # debug "failed to restore signals: #{e.inspect}\nProbably running on windows?"
+ # end
+ message = @lang.get("quit") if (message.nil? || message.empty?)
+ if @socket.connected?
+ debug "Clearing socket"
+ @socket.clearq
+ debug "Sending quit message"
+ @socket.emergency_puts "QUIT :#{message}"
+ debug "Flushing socket"
+ @socket.flush
+ debug "Shutting down socket"
+ @socket.shutdown
+ end
+ debug "Logging quits"
+ server.channels.each { |ch|
+ irclog "@ quit (#{message})", ch
+ }
+ debug "Saving"
+ save
+ debug "Cleaning up"
+ @plugins.cleanup
+ # debug "Closing registries"
+ # @registry.close
+ debug "Cleaning up the db environment"
+ DBTree.cleanup_env
+ log "rbot quit (#{message})"
+ end
end
# message:: optional IRC quit message