|
@@ -58,24 +58,25 @@ STDOUT.sync = true
|
|
|
|
|
|
|
|
|
# display loop ... it is displaying the display_queue
|
|
|
-def displaying(client, user)
|
|
|
+def displaying(c, user)
|
|
|
|
|
|
- #client.puts "#{user} connected."
|
|
|
begin
|
|
|
loop do
|
|
|
|
|
|
-
|
|
|
while line = $display_queue[user][0]
|
|
|
- client.puts line
|
|
|
+ c.puts line
|
|
|
$display_queue[user].delete_at(0)
|
|
|
end
|
|
|
sleep 0.1
|
|
|
|
|
|
end
|
|
|
-
|
|
|
+ #rescue Errno::EPIPE
|
|
|
rescue Exception => e
|
|
|
- puts e.message
|
|
|
- puts e.backtrace.inspect
|
|
|
+ #puts e.message
|
|
|
+ #puts e.backtrace.inspect
|
|
|
+
|
|
|
+ kill_conn(c, user, Thread.current)
|
|
|
+ put_log "Failed while writing to #{user}. Online users now: #{online_users.join(", ")}"
|
|
|
end
|
|
|
|
|
|
end
|
|
@@ -100,7 +101,7 @@ def kill_conn(c, user, t_display)
|
|
|
# shut down displaying thread and connection
|
|
|
t_display.exit
|
|
|
# shut down connection
|
|
|
- c.close
|
|
|
+ c.close unless c.nil?
|
|
|
end
|
|
|
|
|
|
def online_users
|
|
@@ -326,14 +327,17 @@ def thinking(c, user, t_display)
|
|
|
while input != "PART" do
|
|
|
|
|
|
begin
|
|
|
- status = Timeout::timeout(90) do
|
|
|
+ status = Timeout::timeout(300) do
|
|
|
input = c.gets.chomp # waits for user input
|
|
|
execution = inputting(user, input)
|
|
|
end
|
|
|
- rescue Exception => e
|
|
|
+ rescue Timeout::Error => e
|
|
|
write_user(user, "PING Still alive?") # if writing fails, then it may be a broken pipe .. so it will lose the connection and delete the user from the online user list.
|
|
|
+ rescue Exception => e
|
|
|
+ #puts e.message
|
|
|
+ #puts e.backtrace.inspect
|
|
|
end
|
|
|
-
|
|
|
+
|
|
|
end
|
|
|
rescue Exception => e
|
|
|
puts e.message
|
|
@@ -363,7 +367,7 @@ def spawn_server
|
|
|
# only one connection from a user allowed - we don't handle multiple display_queues for one user!!!!!11111
|
|
|
if online_users.user(user)
|
|
|
user = c.puts "Only one connection allowed per user."
|
|
|
- c.close
|
|
|
+ c.close unless c.nil?
|
|
|
else
|
|
|
$display_queue[user] = Array.new
|
|
|
#p $display_queue # ok we can take $display_queue to check for online users.
|
|
@@ -372,14 +376,14 @@ def spawn_server
|
|
|
t_user_display = Thread.new{ displaying(c, user) }
|
|
|
|
|
|
begin
|
|
|
- execution = thinking(c, user, t_user_display)
|
|
|
|
|
|
+ execution = thinking(c, user, t_user_display)
|
|
|
if not execution
|
|
|
- # shut down displaying thread and connection
|
|
|
+ # shut down the displaying thread and connection
|
|
|
kill_conn(c, user, t_user_display)
|
|
|
end
|
|
|
|
|
|
- rescue Exception => e
|
|
|
+ rescue Exception => e
|
|
|
puts e.message
|
|
|
puts e.backtrace.inspect
|
|
|
|