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

avatar and match

parent c95825ee
...@@ -25,7 +25,7 @@ class Scene_Lobby < Scene ...@@ -25,7 +25,7 @@ class Scene_Lobby < Scene
@userlist = Window_UserList.new(24, 204, $game.users) @userlist = Window_UserList.new(24, 204, $game.users)
@roomlist = Window_RoomList.new(320, 50, $game.rooms) @roomlist = Window_RoomList.new(320, 50, $game.rooms)
@userinfo = Window_UserInfo.new(24, 24, $game.user) @userinfo = Window_UserInfo.new(24, 24, $game.user)
@host_window = Window_LobbyButtons.new(678, 18) @host_window = Window_LobbyButtons.new(595, 18)
@active_window = @roomlist @active_window = @roomlist
@chat_window = Window_Chat.new(313, $config['screen']['height'] - 225, 698, 212) @chat_window = Window_Chat.new(313, $config['screen']['height'] - 225, 698, 212)
@count = 0 @count = 0
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require "fileutils" require "fileutils"
require_relative 'card' require_relative 'card'
module Update module Update
Version = '0.9.4' Version = '0.9.6'
URL = "http://my-card.in/mycard/update.json?version=#{Version}" URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self class <<self
attr_reader :thumbnails, :images, :status attr_reader :thumbnails, :images, :status
......
require_relative 'window_host' require_relative 'window_host'
class Window_LobbyButtons < Window_List class Window_LobbyButtons < Window_List
def initialize(x, y) def initialize(x, y)
@items = [I18n.t('lobby.faq'), I18n.t('lobby.filter'), I18n.t('lobby.editdeck'), I18n.t('lobby.newroom')] @items = [I18n.t('lobby.faq'), I18n.t('lobby.filter'), I18n.t('lobby.editdeck'), I18n.t('lobby.newroom'), "自动匹配"]
@button = Surface.load("graphics/lobby/button.png") @button = Surface.load("graphics/lobby/button.png")
super(x, y, @items.size*@button.w/3+@items.size*4, 30) super(x, y, @items.size*@button.w/3+@items.size*4, 30)
@font = TTF.open("fonts/wqy-microhei.ttc", 15) @font = TTF.open("fonts/wqy-microhei.ttc", 15)
...@@ -11,7 +11,7 @@ class Window_LobbyButtons < Window_List ...@@ -11,7 +11,7 @@ class Window_LobbyButtons < Window_List
def draw_item(index, status=0) def draw_item(index, status=0)
x, y, width=item_rect(index) x, y, width=item_rect(index)
Surface.blit(@button, status*@button.w/3, 0, @button.w/3, @button.h, @contents, x, y) Surface.blit(@button, status*@button.w/3, 0, @button.w/3, @button.h, @contents, x, y)
draw_stroked_text(@items[index], x+center_margin(@items[index],width,@font), y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59]) draw_stroked_text(@items[index], x+center_margin(@items[index], width, @font), y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59])
end end
def item_rect(index) def item_rect(index)
...@@ -46,10 +46,35 @@ class Window_LobbyButtons < Window_List ...@@ -46,10 +46,35 @@ class Window_LobbyButtons < Window_List
$game.class.deck_edit $game.class.deck_edit
when 3 #建立房间 when 3 #建立房间
@host_window = Window_Host.new(300, 200) @host_window = Window_Host.new(300, 200)
when 4 #自动匹配
return if @waiting
@waiting = true
waiting_window = Widget_Msgbox.new("自动匹配", "正在等待对手")
require 'open-uri'
Thread.new {
begin
open('http://mycard-server.my-card.in:9997/match.json') { |f|
@waiting = false
if f.read =~ /^mycard:\/\/([\d\.]+):(\d+)\/(.*)$/
room = Room.new(0, $3.to_s)
room.server = Server.new(nil, nil, $1, $2.to_i, false)
$game.join(room)
else
$log.error('自动匹配非法回复'){f.read}
Widget_Msgbox.new("自动匹配", "错误: #{exception}", ok: "确定")
end
}
rescue Exception => exception
@waiting = false
$log.error('自动匹配出错'){exception}
Widget_Msgbox.new("自动匹配", "匹配失败: #{exception}", ok: "确定")
end
}
end end
end end
def update def update
@host_window.update if @host_window and !@host_window.destroyed? @host_window.update if @host_window and !@host_window.destroyed?
end end
end end
...@@ -48,12 +48,6 @@ class Ygocore < Game ...@@ -48,12 +48,6 @@ class Ygocore < Game
$log.error('聊天出错') { [exception, c, where] } $log.error('聊天出错') { [exception, c, where] }
Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天服务连接中断: ' + exception.to_s))) Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天服务连接中断: ' + exception.to_s)))
end end
@@im.add_message_callback do |m|
p m
end
@@im.add_presence_callback do |m|
p m
end
@@im_room.add_message_callback do |m| @@im_room.add_message_callback do |m|
user = m.from.resource == nickname ? @user : User.new(m.from.resource.to_sym, m.from.resource) user = m.from.resource == nickname ? @user : User.new(m.from.resource.to_sym, m.from.resource)
Game_Event.push Game_Event::Chat.new ChatMessage.new(user, m.body, :lobby) rescue $log.error('收到聊天消息') { $! } Game_Event.push Game_Event::Chat.new ChatMessage.new(user, m.body, :lobby) rescue $log.error('收到聊天消息') { $! }
...@@ -126,23 +120,18 @@ class Ygocore < Game ...@@ -126,23 +120,18 @@ class Ygocore < Game
connected = false connected = false
if @@im.jid.domain == "my-card.in" if @@im.jid.domain == "my-card.in"
begin @@im.connect("ygopro-server.my-card.in", 5223) rescue Game_Event.push Game_Event::Error.new('登录', '连接服务器失败')
@@im.connect("chat.my-card.in", 5223) connected = true
connected = true
rescue
Game_Event.push Game_Event::Error.new('登录', '连接服务器失败')
Thread.exit
end
else else
srv = [] srv = []
Resolv::DNS.open { |dns| Resolv::DNS.open { |dns|
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? if srv.empty?
Game_Event.push Game_Event::Error.new('登录', '解析服务器地址失败') Game_Event.push Game_Event::Error.new('登录', '解析服务器地址失败')
Thread.exit Thread.exit
end 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) }
...@@ -192,12 +181,12 @@ class Ygocore < Game ...@@ -192,12 +181,12 @@ class Ygocore < Game
def chat(chatmessage) def chat(chatmessage)
case chatmessage.channel case chatmessage.channel
when :lobby when :lobby
msg = Jabber::Message::new(nil, chatmessage.message) msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg @@im_room.send msg
when User when User
msg = Jabber::Message::new(nil, chatmessage.message) msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg, chatmessage.channel.id @@im_room.send msg, chatmessage.channel.id
#send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time) #send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
end end
end end
...@@ -283,73 +272,73 @@ class Ygocore < Game ...@@ -283,73 +272,73 @@ class Ygocore < Game
#写入配置文件并运行ygocore #写入配置文件并运行ygocore
Dir.chdir(File.dirname(path)) do Dir.chdir(File.dirname(path)) do
case option case option
when Room when Room
room = option room = option
room_name = if room.ot != 0 or room.lp != 8000 room_name = if room.ot != 0 or room.lp != 8000
mode = case when room.match? then mode = case when room.match? then
1; when room.tag? then 1; when room.tag? then
2 2
else else
0 0
end end
room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}" room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}"
elsif room.tag? elsif room.tag?
"T#" + room.name "T#" + room.name
elsif room.pvp? and room.match? elsif room.pvp? and room.match?
"PM#" + room.name "PM#" + room.name
elsif room.pvp? elsif room.pvp?
"P#" + room.name "P#" + room.name
elsif room.match? elsif room.match?
"M#" + room.name "M#" + room.name
else else
room.name room.name
end end
if room.password and !room.password.empty? if room.password and !room.password.empty?
room_name += "$" + room.password room_name += "$" + room.password
end
system_conf = {}
begin
IO.readlines('system.conf').each do |line|
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end end
rescue system_conf = {}
system_conf['antialias'] = 2 begin
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14' IO.readlines('system.conf').each do |line|
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf' line.force_encoding "UTF-8"
end next if line[0, 1] == '#'
if $game.user field, contents = line.chomp.split(' = ', 2)
system_conf['nickname'] = $game.user.name system_conf[field] = contents
system_conf['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth end
end rescue
system_conf['lastip'] = room.server.ip system_conf['antialias'] = 2
system_conf['lastport'] = room.server.port.to_s system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['roompass'] = room_name if room_name and !room_name.empty? system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-j'
when :replay
args = '-r'
when :deck
args = '-d'
when String
system_conf = {}
begin
IO.readlines('system.conf').each do |line|
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end end
rescue if $game.user
system_conf['antialias'] = 2 system_conf['nickname'] = $game.user.name
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14' system_conf['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf' end
end system_conf['lastip'] = room.server.ip
system_conf['lastdeck'] = option system_conf['lastport'] = room.server.port.to_s
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") } system_conf['roompass'] = room_name if room_name and !room_name.empty?
args = '-d' open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-j'
when :replay
args = '-r'
when :deck
args = '-d'
when String
system_conf = {}
begin
IO.readlines('system.conf').each do |line|
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end
rescue
system_conf['antialias'] = 2
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
end
system_conf['lastdeck'] = option
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-d'
end end
IO.popen("ygopro_vs.exe #{args}") IO.popen("ygopro_vs.exe #{args}")
WM.iconify rescue nil WM.iconify rescue nil
...@@ -503,12 +492,12 @@ module WebSocket ...@@ -503,12 +492,12 @@ module WebSocket
def receive_data(data) def receive_data(data)
# debug "Received raw: ", data # debug "Received raw: ", data
case @state case @state
when :connecting then when :connecting then
handle_connecting(data) handle_connecting(data)
when :open then when :open then
handle_open(data) handle_open(data)
when :closing then when :closing then
handle_closing(data) handle_closing(data)
end end
end end
...@@ -563,19 +552,19 @@ module WebSocket ...@@ -563,19 +552,19 @@ module WebSocket
@frame << data @frame << data
while frame = @frame.next while frame = @frame.next
case frame.type case frame.type
when :close when :close
@state = :closing @state = :closing
close close
trigger_onclose(frame.to_s) trigger_onclose(frame.to_s)
when :ping when :ping
pong(frame.to_s) pong(frame.to_s)
trigger_onping(frame.to_s) trigger_onping(frame.to_s)
when :pong when :pong
trigger_onpong(frame.to_s) trigger_onpong(frame.to_s)
when :text when :text
trigger_onmessage(frame.to_s, :text) trigger_onmessage(frame.to_s, :text)
when :binary when :binary
trigger_onmessage(frame.to_s, :binary) trigger_onmessage(frame.to_s, :binary)
end end
end end
unbind if @frame.error? unbind if @frame.error?
......
...@@ -21,14 +21,21 @@ class User ...@@ -21,14 +21,21 @@ class User
end end
end end
def avatar(size = :small) def avatar(size = :small)
cache = "graphics/avatars/mycard_#{@id}_#{size}.png" id = (@id.respond_to?(:bare) ? @id.bare : @id).to_s
cache = "graphics/avatars/mycard_#{id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png") result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene scene = $scene
if block_given? if block_given?
yield result yield result
Thread.new do Thread.new do
require 'cgi' require 'cgi'
open("http://my-card.in/users/#{CGI.escape @id.to_s}.png", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/error_#{size}.png" $log.info('读取头像'){"http://my-card.in/users/#{CGI.escape id.to_s}.png"}
begin
open("http://my-card.in/users/#{CGI.escape id.to_s}.png", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}}
rescue Exception => exception
$log.error('下载头像'){[exception.inspect, *exception.backtrace].join("\n").force_encoding("UTF-8")}
cache = "graphics/avatars/error_#{size}.png"
end
(yield Surface.load(cache) if scene == $scene) rescue nil (yield Surface.load(cache) if scene == $scene) rescue nil
end end
else else
......
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