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

093, failure

parent de17066c
......@@ -3,3 +3,13 @@ ruby '1.9.3'
gem 'rubysdl', :platform => :ruby
gem 'rubysdl-mswin32-1.9', :platforms => [:mswin, :mingw]
gem 'eventmachine'
gem 'em-http-request'
gem 'xmpp4r'
gem 'locale'
gem 'i18n'
gem 'ruby-ogginfo'
gem 'sqlite3'
gem 'zip'
gem 'websocket'
gem 'net-http-pipeline'
\ No newline at end of file
......@@ -20,7 +20,7 @@ end
spec = Gem::Specification.new do |s|
s.name = 'mycard'
s.version = '0.8.5'
s.version = '0.9.3'
s.extra_rdoc_files = ['README.txt', 'LICENSE.txt']
s.summary = 'a card game'
s.description = s.summary
......
......@@ -2,6 +2,8 @@
begin
Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
#System_Encoding = Windows ? "CP#{`chcp`.scan(/\d+$/)}" : `locale |grep LANG |awk -F '=' '{print $2}'`
Dir.glob('post_update_*.rb').sort.each { |file| load file }
Thread.abort_on_exception = true
......@@ -45,6 +47,9 @@ begin
unless $scene == false
#加载文件
require 'openssl'
require 'digest/sha1'
require 'digest/md5'
require 'logger'
require 'sdl'
include SDL
......
......@@ -4,13 +4,20 @@ require_relative 'room'
require_relative 'ygocore/game'
$game = Ygocore.new
open('debug.txt', 'wb'){|f|f.write ARGV.first}
file = ARGV.first.dup.force_encoding("UTF-8")
file.force_encoding("GBK") unless file.valid_encoding?
file.encode!("UTF-8")
if ARGV.first[0, 9] == 'mycard://'
file = URI.unescape URI.unescape ARGV.first[9, ARGV.first.size-9]
file = URI.unescape file[9, file.size-9]
uri = "http://" + URI.escape(file)
#elsif ARGV.first[0, 2] == '//'
# file = URI.unescape URI.unescape ARGV.first[2, ARGV.first.size-2]
# uri = "http://" + URI.escape(file)
else
file = ARGV.first.dup.force_encoding("UTF-8")
file.force_encoding("GBK") unless file.valid_encoding?
file.encode!("UTF-8")
uri = file
end
case file
......@@ -45,13 +52,12 @@ case file
deck.side.each { |card| dest.puts card.number }
end
Ygocore.run_ygocore($2, true)
when /^(?:(.*)\:(.*)\@)?(.*)\:(\d+)\/(.*)$/
when /^(?:(.+?)(?:\:(.+?))?\@)?([\d\.]+)\:(\d+)(?:\/(.*))$/
require 'uri'
require_relative 'server'
$game.user = User.new($1.to_sym, $1) if $1
$game.password = $2 if $2
room = Room.new(0, $5)
room.server_ip = $3
room.server_port = $4.to_i
room.server_auth = true if $2
room = Room.new(0, $5.to_s)
room.server = Server.new(nil, nil, $3, $4.to_i, !!$2)
Ygocore.run_ygocore room, true
end
\ No newline at end of file
require 'open-uri'
require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
Version = '0.8.6'
Version = '0.9.3'
URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
def start
Dir.glob("mycard-update-*-*.zip") do |file|
file =~ /mycard-update-(.+?)-(.+?)\.zip/
if $1 <= Version and $2 > Version
$log.info('安装更新'){file}
$log.info('安装更新') { file }
WM::set_caption("MyCard - 正在更新 #{Version} -> #{$2}", "MyCard")
require 'zip/zip'
Zip::ZipFile::open(file) do |zip|
......@@ -18,9 +19,9 @@ module Update
if !File.directory?(f.name)
FileUtils.mkdir_p(File.dirname(f.name))
end
f.extract{true}
f.extract { true }
end
end rescue $log.error('安装更新出错'){file+$!.inspect+$!.backtrace.inspect}
end rescue $log.error('安装更新出错') { file+$!.inspect+$!.backtrace.inspect }
Version.replace $2
File.delete file
@updated = true
......@@ -35,33 +36,33 @@ module Update
@status = '正在检查更新'
@updated = false
Thread.new do
(Thread.new do
open(URL) do |file|
require 'json'
reply = file.read
$log.info('下载更新-服务器回传'){reply}
$log.info('下载更新-服务器回传') { reply }
reply = JSON.parse(reply)
$log.info('下载更新-解析后'){reply.inspect}
$log.info('下载更新-解析后') { reply.inspect }
reply.each do |fil|
name = File.basename fil
@status.replace "正在下载更新#{name}"
open(fil, 'rb') do |fi|
$log.info('下载完毕'){name}
$log.info('下载完毕') { name }
@updated = true
open(name, 'wb') do |f|
f.write fi.read
end
end rescue $log.error('下载更新'){'下载更新失败'}
end rescue $log.error('下载更新') { '下载更新失败' }
end
end rescue $log.error('检查更新'){'检查更新失败'}
end rescue $log.error('检查更新') { '检查更新失败' }
if @updated
require_relative 'widget_msgbox'
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定"){IO.popen('./mycard'); $scene = nil}
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定") { IO.popen('./mycard'); $scene = nil }
end
if File.file? "ygocore/cards.cdb"
require 'sqlite3'
db = SQLite3::Database.new( "ygocore/cards.cdb" )
db.execute( "select id from datas" ) do |row|
db = SQLite3::Database.new("ygocore/cards.cdb")
db.execute("select id from datas") do |row|
@thumbnails << row[0]
end
@images.replace @thumbnails
......@@ -86,9 +87,9 @@ module Update
@images -= existed_images
existed_images = []
if (!@images.empty? or !@thumbnails.empty?) and File.file?("#{Card::PicPath}/1.jpg")
db_mycard = SQLite3::Database.new( "data/data.sqlite" )
db_mycard = SQLite3::Database.new("data/data.sqlite")
db_mycard.execute( "select id, number from `yu-gi-oh` where number in (#{(@images+@thumbnails).uniq.collect{|number|"'%08d'" % number}.join(',')})" ) do |row|
db_mycard.execute("select id, number from `yu-gi-oh` where number in (#{(@images+@thumbnails).uniq.collect { |number| "'%08d'" % number }.join(',')})") do |row|
id = row[0]
number = row[1].to_i
src = "#{Card::PicPath}/#{id}.jpg"
......@@ -108,39 +109,69 @@ module Update
@thumbnails -= existed_images
@thumbnails = (@thumbnails & @images) + (@thumbnails - @images)
unless @thumbnails.empty? and @images.empty?
$log.info('待下载的完整卡图'){@images.inspect}
$log.info('待下载的缩略卡图'){@thumbnails.inspect}
threads = 5.times.collect do
$log.info('待下载的完整卡图') { @images.inspect }
$log.info('待下载的缩略卡图') { @thumbnails.inspect }
open('http://my-card.in/cards/image.json') do |f|
image_index = JSON.parse(f.read)
url = image_index['url']
uri = URI(url)
image_req = uri.path
image_req += '?' + uri.query if uri.query
image_req += '#' + uri.fragment if uri.fragment
url = image_index['thumbnail_url']
uri = URI(url)
thumbnail_req = uri.path
thumbnail_req += '?' + uri.query if uri.query
thumbnail_req += '#' + uri.fragment if uri.fragment
require 'net/http/pipeline'
@thumbnails_left = @thumbnails.size
@images_left = @images.size
threads = 1.times.collect do
thread = Thread.new do
while number = @thumbnails.pop
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)"
open("http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/thumbnail/#{number}.jpg"
#$log.debug('下载缩略卡图'){"http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue $log.error('下载缩略出错'){"http://my-card.in/images/cards/ygocore/thumbnail/#{number}.jpg 到 ygocore/pics/thumbnail/#{number}.jpg" }
end
while number = @images.pop
@status.replace "正在下载完整卡图 (剩余#{@images.size}张)"
#$log.debug('下载完整卡图'){"http://my-card.in/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
open("http://my-card.in/images/cards/ygocore/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/#{number}.jpg"
open("ygocore/pics/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue $log.error('下载完整卡图出错'){"http://my-card.in/images/cards/ygocore/#{number}.jpg 到 ygocore/pics/#{number}.jpg" }
end
Net::HTTP.start uri.host, uri.port do |http|
http.pipelining = true
while !@thumbnails.empty?
ids = @thumbnails.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new image_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res|
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails_left}张)"
@thumbnails_left -= 1
id = ids.pop
next if File.file? "ygocore/pics/thumbnail/#{id}.jpg"
content = res.body
open("ygocore/pics/thumbnail/#{id}.jpg", 'wb') do |local|
local.write content
end
end rescue $log.error('下载缩略卡图') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
end
while !@images_reqs.empty?
ids = @images_reqs.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new thumbnail_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res|
@status.replace "正在下载完整卡图 (剩余#{@images_left}张)"
@images_left -= 1
id = ids.pop
next if File.file? "ygocore/pics/#{id}.jpg"
content = res.body
open("ygocore/pics/#{id}.jpg", 'wb') do |local|
local.write content
end
end rescue $log.error('下载完整卡图') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
end
end rescue $log.error('下载完整卡图出错') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
end
thread.priority = -1
thread
end
threads.each{|thread|thread.join}
threads.each { |thread| thread.join }
end
end
end rescue $log.error('卡图更新'){'找不到ygocore卡片数据库'}
end rescue $log.error('卡图更新') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
@status = nil
end.priority = -1
end).priority = -1
end
end
end
#encoding: UTF-8
#encoding: UTF-8
load 'lib/ygocore/window_login.rb'
require 'eventmachine'
require 'em-http'
......@@ -32,9 +32,9 @@ class Ygocore < Game
matched = @username.match Jabber::JID::PATTERN
if matched[1] && matched[2]
@username = matched[1]
jid = Jabber::JID::new matched[1], matched[2], matched[3] || 'mycard'
jid = Jabber::JID::new @username, matched[2], matched[3] || 'mycard'
else
jid = Jabber::JID::new @username.dup, 'my-card.in', 'mycard'
jid = Jabber::JID::new @username, 'my-card.in', 'mycard'
end
@@im = Jabber::Client.new(jid)
......@@ -116,45 +116,45 @@ class Ygocore < Game
@@im.allow_tls = false
@@im.use_ssl = true
if @@im.jid.domain == 'my-card.in'
@@im.connect(record.target.to_s, 5223)
connected = false
if @@im.jid.domain == "my-card.in"
@@im.connect("ygopro-server.my-card.in", 5223) rescue Game_Event.push Game_Event::Error.new('登录', '连接服务器失败')
connected = true
else
#由于XMPP4r在windows下TLS有问题...
srv = []
Resolv::DNS.open { |dns|
# If ruby version is too old and SRV is unknown, this will raise a NameError
# which is caught below
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)
}
if srv.empty?
Game_Event.push Game_Event::Error.new('登录', '解析服务器地址失败')
Thread.exit
end
# 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.each { |record|
begin
@@im.connect
@@im.connect(record.target.to_s, 5223)
# Success
connected = true
break
rescue SocketError, Errno::ECONNREFUSED
rescue
# Try next SRV record
end
}
end
if connected
begin
@@im.auth(@password)
rescue Jabber::ClientAuthenticationFailure
Game_Event.push Game_Event::Error.new('登录', '用户名或密码错误')
Thread.exit
end
Game_Event.push Game_Event::Login.new User.new(@@im.jid, @username, true)
@@im.send(Jabber::Presence.new.set_type(:available))
Game_Event.push Game_Event::Login.new User.new(@@im.jid, @username, true)
begin
nickname = nickname()
#@@im_room.join(Jabber::JID.new(I18n.t('lobby.room'), I18n.t('lobby.server'), nickname))
......@@ -166,9 +166,13 @@ class Ygocore < Game
end
end
Game_Event.push Game_Event::AllUsers.new @@im_room.roster.keys.collect { |nick| User.new(nick.to_sym, nick) } rescue p $!
else
$log.error('聊天连接出错.1') { exception }
Game_Event.push Game_Event::Error.new('登录', '连接服务器失败.1')
end
rescue StandardError => exception
$log.error('聊天连接出错') { exception }
Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天服务器连接失败')))
Game_Event.push Game_Event::Error.new('登录', '登录失败')
end
}
end
......@@ -229,7 +233,6 @@ class Ygocore < Game
end
def exit
@@im.close rescue nil
@recv.exit if @recv
@recv = nil
end
......@@ -304,12 +307,13 @@ class Ygocore < Game
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
end
if $game.user
system_conf['nickname'] = $game.user.name
system_conf['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth
$log.info room
end
system_conf['lastip'] = room.server.ip
system_conf['lastport'] = room.server.port.to_s
system_conf['roompass'] = room_name
system_conf['roompass'] = room_name if room_name and !room_name.empty?
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-j'
when :replay
......
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