Commit de17066c authored by 神楽坂玲奈's avatar 神楽坂玲奈

dns resolve

parent 3072acbf
...@@ -32,9 +32,9 @@ class Ygocore < Game ...@@ -32,9 +32,9 @@ class Ygocore < Game
matched = @username.match Jabber::JID::PATTERN matched = @username.match Jabber::JID::PATTERN
if matched[1] && matched[2] if matched[1] && matched[2]
@username = matched[1] @username = matched[1]
jid = Jabber::JID::new @username, matched[2], matched[3] || 'mycard' jid = Jabber::JID::new matched[1], matched[2], matched[3] || 'mycard'
else else
jid = Jabber::JID::new @username, 'my-card.in', 'mycard' jid = Jabber::JID::new @username.dup, 'my-card.in', 'mycard'
end end
@@im = Jabber::Client.new(jid) @@im = Jabber::Client.new(jid)
...@@ -116,7 +116,10 @@ class Ygocore < Game ...@@ -116,7 +116,10 @@ class Ygocore < Game
@@im.allow_tls = false @@im.allow_tls = false
@@im.use_ssl = true @@im.use_ssl = true
#由于XMPP4r在windows if @@im.jid.domain == 'my-card.in'
@@im.connect(record.target.to_s, 5223)
else
#由于XMPP4r在windows下TLS有问题...
srv = [] srv = []
Resolv::DNS.open { |dns| Resolv::DNS.open { |dns|
# If ruby version is too old and SRV is unknown, this will raise a NameError # If ruby version is too old and SRV is unknown, this will raise a NameError
...@@ -124,12 +127,17 @@ class Ygocore < Game ...@@ -124,12 +127,17 @@ class Ygocore < Game
Jabber::debuglog("RESOLVING:\n_xmpp-client._tcp.#{@@im.jid.domain} (SRV)") Jabber::debuglog("RESOLVING:\n_xmpp-client._tcp.#{@@im.jid.domain} (SRV)")
srv = dns.getresources("_xmpp-client._tcp.#{@@im.jid.domain}", Resolv::DNS::Resource::IN::SRV) srv = dns.getresources("_xmpp-client._tcp.#{@@im.jid.domain}", Resolv::DNS::Resource::IN::SRV)
} }
if srv.empty?
Game_Event.push Game_Event::Error.new('登录', '解析服务器地址失败')
Thread.exit
end
# Sort SRV records: lowest priority first, highest weight first # Sort SRV records: lowest priority first, highest weight first
srv.sort! { |a,b| (a.priority != b.priority) ? (a.priority <=> b.priority) : (b.weight <=> a.weight) } srv.sort! { |a,b| (a.priority != b.priority) ? (a.priority <=> b.priority) : (b.weight <=> a.weight) }
srv.each { |record| srv.each { |record|
begin begin
@@im.connect(record.target.to_s, 5223) @@im.connect
# Success # Success
break break
rescue SocketError, Errno::ECONNREFUSED rescue SocketError, Errno::ECONNREFUSED
...@@ -137,6 +145,8 @@ class Ygocore < Game ...@@ -137,6 +145,8 @@ class Ygocore < Game
end end
} }
end
begin begin
@@im.auth(@password) @@im.auth(@password)
rescue Jabber::ClientAuthenticationFailure rescue Jabber::ClientAuthenticationFailure
...@@ -219,6 +229,7 @@ class Ygocore < Game ...@@ -219,6 +229,7 @@ class Ygocore < Game
end end
def exit def exit
@@im.close rescue nil
@recv.exit if @recv @recv.exit if @recv
@recv = nil @recv = nil
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment