Skip to content

Instantly share code, notes, and snippets.

@znz
Last active April 6, 2018 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znz/c8d70ed84c385e88adb275fdc915d170 to your computer and use it in GitHub Desktop.
Save znz/c8d70ed84c385e88adb275fdc915d170 to your computer and use it in GitHub Desktop.
JIS (IRCnet) <-> UTF-8 (IRC client) proxy
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'nkf'
require 'socket'
Socket.tcp_server_loop(6668) do |socket, client_addr|
begin
begin
ircnet_socket = Socket.tcp('irc.ircnet.ne.jp', 6667)
loop do
rs, = IO.select([socket, ircnet_socket])
break if rs.empty?
if rs.include?(ircnet_socket)
jis_line = ircnet_socket.gets
socket.puts NKF.nkf('-Jwxm0 --fb-xml', jis_line)
end
if rs.include?(socket)
utf8_line = socket.gets
ircnet_socket.puts NKF.nkf('-Wjxm0 --fb-xml', utf8_line)
end
end
rescue
p $!
ensure
ircnet_socket.close if ircnet_socket && !ircnet_socket.closed?
end
ensure
socket.close if !socket.closed?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment