]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/ircbot.rb
fix: write override behavior
[user/henk/code/ruby/rbot.git] / lib / rbot / ircbot.rb
index 817acd71f537438c267c4860c6b918bbfa43b617..564403f5d3bdfb7868708e6a874bc1cb0ae59b4e 100644 (file)
@@ -444,18 +444,22 @@ class Bot
         end
       end
 
-      def $stdout.write(str=nil)
+      def $stdout.write(*args)
+        str = args.map { |s| s.to_s }.join("")
         log str, 2
-        return str.to_s.size
+        return str.bytesize
       end
-      def $stderr.write(str=nil)
+      def $stderr.write(*args)
+        str = args.map { |s| s.to_s }.join("")
         if str.to_s.match(/:\d+: warning:/)
           warning str, 2
         else
           error str, 2
         end
-        return str.to_s.size
+        return str.bytesize
       end
+
+      LoggerManager.instance.log_session_start
     end
 
     File.open($opts['pidfile'] || File.join(@botclass, 'rbot.pid'), 'w') do |pf|
@@ -927,7 +931,8 @@ class Bot
 
   # begin event handling loop
   def mainloop
-    while true
+    @keep_looping = true
+    while @keep_looping
       too_fast = 0
       quit_msg = nil
       valid_recv = false # did we receive anything (valid) from the server yet?
@@ -957,7 +962,8 @@ class Bot
       # exceptions that ARENT SocketError's. How am I supposed to handle
       # that?
       rescue SystemExit
-        exit 0
+        @keep_looping = false
+        break
       rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, TimeoutError, SocketError => e
         error "network exception: #{e.pretty_inspect}"
         quit_msg = e.to_s
@@ -1254,7 +1260,7 @@ class Bot
     begin
       shutdown(message)
     ensure
-      exit 0
+      @keep_looping = false
     end
   end
 
@@ -1264,6 +1270,10 @@ class Bot
       :wait => @config['server.reconnect_wait']
     } if (!message || message.empty?)
     shutdown(message)
+
+    Irc::Bot::LoggerManager.instance.flush
+    Irc::Bot::LoggerManager.instance.log_session_end
+
     sleep @config['server.reconnect_wait']
     begin
       # now we re-exec