|  | @@ -742,6 +742,7 @@ module CentralProtocolHandler
 | 
											
												
													
														|  |  	# what happens with what input?!
 |  |  	# what happens with what input?!
 | 
											
												
													
														|  |  	def inputting(input)
 |  |  	def inputting(input)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    put_log("to #{@username}: SYS You typed: #{input}")
 | 
											
												
													
														|  |  		write_user("SYS You typed: #{input}")
 |  |  		write_user("SYS You typed: #{input}")
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		if input =~ /^([A-Z_]+)/
 |  |  		if input =~ /^([A-Z_]+)/
 | 
											
										
											
												
													
														|  | @@ -870,6 +871,7 @@ module CentralProtocolHandler
 | 
											
												
													
														|  |            iphost = $1
 |  |            iphost = $1
 | 
											
												
													
														|  |            ipport = $2
 |  |            ipport = $2
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +          put_log("to #{@username}: DNS_RE #{iphost}:#{ipport} #{targetname}")
 | 
											
												
													
														|  |            targetname = $gs.get_cool_dns(iphost, ipport)
 |  |            targetname = $gs.get_cool_dns(iphost, ipport)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |            write_user("DNS_RE #{iphost}:#{ipport} #{targetname}") # write back to asking user.
 |  |            write_user("DNS_RE #{iphost}:#{ipport} #{targetname}") # write back to asking user.
 | 
											
										
											
												
													
														|  | @@ -922,65 +924,67 @@ module CentralProtocolHandler
 | 
											
												
													
														|  |  	# default method that is being run on receiving data!
 |  |  	# default method that is being run on receiving data!
 | 
											
												
													
														|  |  	def receive_data(data) # connection receives a line on the server end
 |  |  	def receive_data(data) # connection receives a line on the server end
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    line = data.chomp unless data.chomp.nil?
 |  | 
 | 
											
												
													
														|  | 
 |  | +    data = data.chomp unless data.chomp.nil?
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    if line
 |  | 
 | 
											
												
													
														|  | 
 |  | +    data.each_line do |line|
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +      unless line.empty?
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -      if entered_username? # oh, it's a known user
 |  | 
 | 
											
												
													
														|  | 
 |  | +        if entered_username? # oh, it's a known user
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        # it's alive! kill ping timer, set a new one:
 |  | 
 | 
											
												
													
														|  | -        if @ping_timer
 |  | 
 | 
											
												
													
														|  | -          EventMachine.cancel_timer(@ping_timer)
 |  | 
 | 
											
												
													
														|  | -        end
 |  | 
 | 
											
												
													
														|  | -        @ping_timer = EventMachine.add_periodic_timer 90, proc { write_user("PING alive?") }
 |  | 
 | 
											
												
													
														|  | 
 |  | +          # it's alive! kill ping timer, set a new one:
 | 
											
												
													
														|  | 
 |  | +          if @ping_timer
 | 
											
												
													
														|  | 
 |  | +            EventMachine.cancel_timer(@ping_timer)
 | 
											
												
													
														|  | 
 |  | +          end
 | 
											
												
													
														|  | 
 |  | +          @ping_timer = EventMachine.add_periodic_timer 90, proc { write_user("PING alive?") }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        # work on input
 |  | 
 | 
											
												
													
														|  | -        inputter = inputting(line)
 |  | 
 | 
											
												
													
														|  | -        if inputter == "bye"
 |  | 
 | 
											
												
													
														|  | -          close_connection
 |  | 
 | 
											
												
													
														|  | -        end
 |  | 
 | 
											
												
													
														|  | 
 |  | +          # work on input
 | 
											
												
													
														|  | 
 |  | +          inputter = inputting(line)
 | 
											
												
													
														|  | 
 |  | +          if inputter == "bye"
 | 
											
												
													
														|  | 
 |  | +            close_connection
 | 
											
												
													
														|  | 
 |  | +          end
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -      else # of username known, then it seems to be the first connect
 |  | 
 | 
											
												
													
														|  | 
 |  | +        else # of username known, then it seems to be the first connect
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        # and this line is the user name coming in!
 |  | 
 | 
											
												
													
														|  | -        username = line
 |  | 
 | 
											
												
													
														|  | 
 |  | +          # and this line is the user name coming in!
 | 
											
												
													
														|  | 
 |  | +          username = line
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if online(username)
 |  | 
 | 
											
												
													
														|  | -          put_log "SYS User '#{username}' tried to double connect. Say bye bye."
 |  | 
 | 
											
												
													
														|  | -          send_data "SYS Hey '#{username}', only one connection allowed. Bye.\n"
 |  | 
 | 
											
												
													
														|  | -          EventMachine.add_timer 1, proc {
 |  | 
 | 
											
												
													
														|  | -            write_user("PING check forced", username)
 |  | 
 | 
											
												
													
														|  | -            close_connection
 |  | 
 | 
											
												
													
														|  | -          }
 |  | 
 | 
											
												
													
														|  | 
 |  | +          if online(username)
 | 
											
												
													
														|  | 
 |  | +            put_log "SYS User '#{username}' tried to double connect. Say bye bye."
 | 
											
												
													
														|  | 
 |  | +            send_data "SYS Hey '#{username}', only one connection allowed. Bye.\n"
 | 
											
												
													
														|  | 
 |  | +            EventMachine.add_timer 1, proc {
 | 
											
												
													
														|  | 
 |  | +              write_user("PING check forced", username)
 | 
											
												
													
														|  | 
 |  | +              close_connection
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -          return false
 |  | 
 | 
											
												
													
														|  | -        end
 |  | 
 | 
											
												
													
														|  | 
 |  | +            return false
 | 
											
												
													
														|  | 
 |  | +          end
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if $user_roles.any? {|k| k.include? username}
 |  | 
 | 
											
												
													
														|  | -          @username = username
 |  | 
 | 
											
												
													
														|  | -          @@connected_clients.push(self)
 |  | 
 | 
											
												
													
														|  | -          @ping_timer = EventMachine.add_periodic_timer 90, proc { write_user("PING alive?") }
 |  | 
 | 
											
												
													
														|  | -          # starting a pinger
 |  | 
 | 
											
												
													
														|  | 
 |  | +          if $user_roles.any? {|k| k.include? username}
 | 
											
												
													
														|  | 
 |  | +            @username = username
 | 
											
												
													
														|  | 
 |  | +            @@connected_clients.push(self)
 | 
											
												
													
														|  | 
 |  | +            @ping_timer = EventMachine.add_periodic_timer 90, proc { write_user("PING alive?") }
 | 
											
												
													
														|  | 
 |  | +            # starting a pinger
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -          put_log("SYS '#{@username}' connected. Online now: #{ousers.join(", ")}")
 |  | 
 | 
											
												
													
														|  | 
 |  | +            put_log("SYS '#{@username}' connected. Online now: #{ousers.join(", ")}")
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -          write_user("HELLO Hi user '#{@username}'! How are you? I'm '#{$version}'")
 |  | 
 | 
											
												
													
														|  | -          write_user("ROLES #{my_roles.join(", ")}")
 |  | 
 | 
											
												
													
														|  | -          write_user("COMMANDS #{my_cmds.join(", ")}")
 |  | 
 | 
											
												
													
														|  | -          write_role($default_role, "JOINED User '#{@username}' just joined the party.", @username)
 |  | 
 | 
											
												
													
														|  | -        else
 |  | 
 | 
											
												
													
														|  | -          put_log "SYS User '#{username}' unknown to me. Saying bye."
 |  | 
 | 
											
												
													
														|  | -          send_data "SYS User '#{username}' unknown to me. Bye.\n"
 |  | 
 | 
											
												
													
														|  | 
 |  | +            write_user("HELLO Hi user '#{@username}'! How are you? I'm '#{$version}'")
 | 
											
												
													
														|  | 
 |  | +            write_user("ROLES #{my_roles.join(", ")}")
 | 
											
												
													
														|  | 
 |  | +            write_user("COMMANDS #{my_cmds.join(", ")}")
 | 
											
												
													
														|  | 
 |  | +            write_role($default_role, "JOINED User '#{@username}' just joined the party.", @username)
 | 
											
												
													
														|  | 
 |  | +          else
 | 
											
												
													
														|  | 
 |  | +            put_log "SYS User '#{username}' unknown to me. Saying bye."
 | 
											
												
													
														|  | 
 |  | +            send_data "SYS User '#{username}' unknown to me. Bye.\n"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -          # disconnect him
 |  | 
 | 
											
												
													
														|  | -          close_connection
 |  | 
 | 
											
												
													
														|  | -        end
 |  | 
 | 
											
												
													
														|  | 
 |  | +            # disconnect him
 | 
											
												
													
														|  | 
 |  | +            close_connection
 | 
											
												
													
														|  | 
 |  | +          end
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -      end # of username known
 |  | 
 | 
											
												
													
														|  | -    end # of line
 |  | 
 | 
											
												
													
														|  | 
 |  | +        end # of username known
 | 
											
												
													
														|  | 
 |  | +      end # of unless line.empty?
 | 
											
												
													
														|  | 
 |  | +    end # of data.each_line
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -	end
 |  | 
 | 
											
												
													
														|  | 
 |  | +	end # of receive data
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	# default method that is being run on disconnection!
 |  |  	# default method that is being run on disconnection!
 | 
											
												
													
														|  |  	def unbind # a connection goes bye bye
 |  |  	def unbind # a connection goes bye bye
 | 
											
										
											
												
													
														|  | @@ -1019,7 +1023,7 @@ def main
 | 
											
												
													
														|  |        EventMachine.start_server("0.0.0.0", 7337, CentralProtocolHandler)
 |  |        EventMachine.start_server("0.0.0.0", 7337, CentralProtocolHandler)
 | 
											
												
													
														|  |      end
 |  |      end
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -end
 |  | 
 | 
											
												
													
														|  | 
 |  | +end # of main
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  main
 |  |  main
 | 
											
												
													
														|  |  
 |  |  
 |