Commit 17ae1837 authored by 神楽坂玲奈's avatar 神楽坂玲奈

0.8.1

parent 1e26242c
......@@ -9,6 +9,9 @@ module Config
config['bgm'] = true if config['bgm'].nil?
config['screen'] ||= {}
config['screen']['width'], config['screen']['height'] = Resolution.default unless Resolution.all.include? [config['screen']['width'], config['screen']['height']]
config['i18n'] ||= {}
config['i18n']['locale'] ||= "#{Locale.current.language}-#{Locale.current.region}"
I18n.locale = config['i18n']['locale']
config
end
def save(config=$config, file="config.yml")
......
#游戏事件的抽象类
class Game_Event
@queue = []
def self.push(event)
@queue << event
end
def self.poll
@queue.shift
end
def self.parse(info, *args)
#适配器定义
end
......@@ -14,14 +17,16 @@ class Game_Event
class Login < Game_Event
attr_reader :user
def initialize(user)
@user = user
@user = user
$game.user = @user
end
end
class AllUsers < Game_Event
attr_reader :users
def initialize(users)
@users = []
users.each do |user|
......@@ -34,9 +39,10 @@ class Game_Event
$game.users.replace @users
end
end
class NewUser < AllUsers
attr_reader :users
def initialize(user)
@user = user
unless $game.users.include? @user
......@@ -51,6 +57,7 @@ class Game_Event
class MissingUser < AllUsers
attr_reader :users
def initialize(user)
@user = user
$game.users.delete @user
......@@ -59,14 +66,27 @@ class Game_Event
class AllRooms < Game_Event
attr_reader :rooms
def initialize(rooms)
@rooms = rooms
$game.rooms.replace @rooms
$game.rooms.sort_by! { |room| [room.status == :start ? 1 : 0, room.private ? 1 : 0, room.id] }
end
end
class RoomsUpdate < AllRooms
attr_reader :rooms
def initialize(rooms)
@rooms = rooms
$game.rooms.replace $game.rooms | @rooms
$game.rooms.delete_if { |room| room._deleted }
$game.rooms.sort_by! { |room| [room.status == :start ? 1 : 0, room.private ? 1 : 0, room.id] }
end
end
class NewRoom < AllRooms
attr_reader :room
def initialize(room)
@room = room
unless $game.rooms.include? @room
......@@ -80,6 +100,7 @@ class Game_Event
end
class MissingRoom < AllRooms
attr_reader :room
def initialize(room)
@room = room
$game.rooms.delete @room
......@@ -87,9 +108,9 @@ class Game_Event
end
class Chat < Game_Event
attr_reader :chatmessage
def initialize(chatmessage)
@chatmessage = chatmessage
end
......@@ -97,8 +118,9 @@ class Game_Event
class Join < Game_Event
attr_reader :room
def initialize(room)
@room = room
@room = room
$game.room = @room
end
end
......@@ -106,8 +128,9 @@ class Game_Event
end
class Watch < Game_Event
attr_reader :room
def initialize(room)
@room = room
@room = room
$game.room = @room
end
end
......@@ -117,8 +140,9 @@ class Game_Event
end
class PlayerJoin < Game_Event
attr_reader :user
def initialize(user)
@user = user
@user = user
$game.room.player2 = @user
end
end
......@@ -130,20 +154,22 @@ class Game_Event
class Action < Game_Event
attr_reader :action, :str
def initialize(action, str=action.escape)
@action = action
@str = str
@str = str
end
end
class Error < Game_Event
attr_reader :title, :message, :fatal
def initialize(title, message, fatal=true)
@title = title
@title = title
@message = message
@fatal = fatal
$log.error(@fatal ? "致命错误" : "一般错误"){"#{@title}: #{@message} #{caller}"}
@fatal = fatal
$log.error(@fatal ? "致命错误" : "一般错误") { "#{@title}: #{@message} #{caller}" }
end
end
class Unknown < Error
......
......@@ -21,12 +21,12 @@ class User
end
def avatar(size = :small)
cache = "graphics/avatars/#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif")
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene
if block_given?
yield result
Thread.new do
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/noavatar_#{size}.gif"
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') {|io|open(cache, 'wb') {|c|c.write io.read}} rescue cache = "graphics/avatars/error_#{size}.png"
(yield Surface.load(cache) if scene == $scene) rescue nil
end
else
......
......@@ -2,6 +2,7 @@
begin
Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
Dir.glob('post_update_*.rb').sort.each { |file| load file }
Thread.abort_on_exception = true
require_relative 'resolution'
......@@ -9,30 +10,36 @@ begin
require_relative 'config'
require_relative 'association'
#i18n
require 'i18n'
require 'locale'
I18n.load_path += Dir['locales/*.yml']
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
#读取配置文件
$config = Config.load
Config.save
#读取命令行参数
log = "log.log"
log = "log.log"
log_level = "INFO"
profile = nil
profile = nil
ARGV.each do |arg|
arg = arg.dup.force_encoding("UTF-8")
arg.force_encoding("GBK") unless arg.valid_encoding?
case arg
when /--log=(.*)/
log.replace $1
when /--log-level=(.*)/
log_level.replace $1
when /--profile=(.*)/
profile = $1
when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart'
$scene = false
when /register_association/
Association.register
$scene = false
when /--log=(.*)/
log.replace $1
when /--log-level=(.*)/
log_level.replace $1
when /--profile=(.*)/
profile = $1
when /^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative 'quickstart'
$scene = false
when /register_association/
Association.register
$scene = false
end
end
......@@ -51,7 +58,7 @@ begin
if log == "STDOUT" #调试用
log = STDOUT
end
$log = Logger.new(log)
$log = Logger.new(log)
$log.level = Logger.const_get log_level
#性能分析
......@@ -63,7 +70,7 @@ begin
end
require 'profiler'
RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true,
:trace_instruction => true,
:specialized_instruction => false
}
Profiler__::start_profile
......@@ -71,13 +78,13 @@ begin
SDL::Event::APPMOUSEFOCUS = 1
SDL::Event::APPINPUTFOCUS = 2
SDL::Event::APPACTIVE = 4
SDL::Event::APPACTIVE = 4
SDL.putenv ("SDL_VIDEO_CENTERED=1");
SDL.init(INIT_VIDEO)
WM::set_caption("MyCard", "MyCard")
WM::icon = Surface.load("graphics/system/icon.gif")
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
TTF.init
#声音
......
......@@ -49,7 +49,9 @@ case file
require 'uri'
$game.user = User.new($1.to_sym, $1) if $1
$game.password = $2 if $2
$game.server = $3
$game.port = $4.to_i
Ygocore.run_ygocore Room.new(0, $5), true
room = Room.new(0, $5)
room.server_ip = $3
room.server_port = $4.to_i
room.server_auth = true if $2
Ygocore.run_ygocore room, true
end
\ No newline at end of file
......@@ -2,7 +2,7 @@ require_relative 'cacheable'
class Room
Color = [[0,0,0], [255,0,0], [0,128,0], [0,0,255], [255, 165, 0]]
extend Cacheable
attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid
attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid, :_deleted
attr_accessor :password
def initialize(id, name="等待更新", player1=nil, player2=nil, private=false, color=[0,0,0], session = nil, forbid = nil)
@id = id
......@@ -30,6 +30,9 @@ class Room
def extra
{}
end
def status
player2 ? :start : :wait
end
alias full? player2
alias private? private
end
\ No newline at end of file
......@@ -2,7 +2,7 @@ require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
Version = '0.7.4'
Version = '0.8.1'
URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
......
......@@ -4,7 +4,7 @@ class Widget_Msgbox < Window
class <<self
alias old_new new
def new(title, message, buttons={}, &proc)
if instance = $scene.windows.find{|window|window.class == self and !window.destroyed?}
if instance = $scene.windows.find{|window|window.class == self and !window.destroyed?} rescue nil
instance.set(title, message, buttons, &proc)
instance
else
......
......@@ -2,91 +2,111 @@ class Window
WLH = 24
attr_accessor :x, :y, :width, :height, :z, :contents, :visible, :viewport, :background
alias visible? visible
def initialize(x, y, width, height, z=200)
@x = x
@y = y
@z = z
@width = width
@height = height
@visible = true
@x = x
@y = y
@z = z
@width = width
@height = height
@visible = true
#@angle = 0
@viewport = [0, 0, @width, @height]
@viewport = [0, 0, @width, @height]
@destroyed = false
amask = 0xff000000
rmask = 0x00ff0000
gmask = 0x0000ff00
bmask = 0x000000ff
amask = 0xff000000
rmask = 0x00ff0000
gmask = 0x0000ff00
bmask = 0x000000ff
#@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@contents ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@contents ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
#按Z坐标插入
unless $scene.windows.each_with_index do |window, index|
if window.z > @z
$scene.windows.insert(index, self)
break true
end
end == true
if window.z > @z
$scene.windows.insert(index, self)
break true
end
end == true
$scene.windows << self
end
end
def center_margin(text, width, font=@font)
(width - font.text_size(text)[0]) /2
end
def draw_stroked_text(text,x,y,size=1,font=@font,color=@color,color_stroke=@color_stroke)
[[x-size,y-size], [x-size,y], [x-size,y+size],
[x,y-size], [x,y+size],
[x+size,y-size], [x+size,y], [x+size,y+size],
].each{|pos|font.draw_blended_utf8(@contents, text, pos[0], pos[1], *color)}
def draw_stroked_text(text, x, y, size=1, font=@font, color=@color, color_stroke=@color_stroke)
[[x-size, y-size], [x-size, y], [x-size, y+size],
[x, y-size], [x, y+size],
[x+size, y-size], [x+size, y], [x+size, y+size],
].each { |pos| font.draw_blended_utf8(@contents, text, pos[0], pos[1], *color) }
font.draw_blended_utf8(@contents, text, x, y, *color_stroke)
end
def include?(x,y)
def include?(x, y)
x >= @x && x < @x + @width && y >= @y && y < @y + @height
end
def destroy
@destroyed = true
@contents.destroy if @contents
$scene.windows.delete self if $scene
end
def destroyed?
@destroyed
end
def draw(screen)
return unless self.contents && self.visible? && !self.destroyed?
Surface.blit(self.contents, *self.viewport, screen, self.x, self.y)
end
def clear(x=0, y=0, width=@width, height=@height)
if @background
Surface.blit(@background,x,y,width,height,@contents,x,y)
Surface.blit(@background, x, y, width, height, @contents, x, y)
elsif $scene and $scene.background
Surface.blit($scene.background,@x+x,@y+y,width,height,@contents,x,y)
Surface.blit($scene.background, @x+x, @y+y, width, height, @contents, x, y)
else
@contents.fill_rect(x,y,width,height,0xFF000000)
@contents.fill_rect(x, y, width, height, 0xFF000000)
end
end
def update
#子类定义
end
def refresh
#子类定义
end
def mousemoved(x,y)
def mousemoved(x, y)
#子类定义
end
def clicked
#子类定义
end
def mouseleftbuttonup
#子类定义
end
def lostfocus(active_window=nil)
#子类定义
end
def cursor_up(wrap=false)
#子类定义
end
def cursor_down(wrap=false)
#子类定义
end
def scroll_up
cursor_up
end
def scroll_down
cursor_down
end
......
......@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable
if !@chat_input.value.empty?
chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel)
$game.chat chatmessage
Game_Event.push Game_Event::Chat.new(chatmessage) if $game.show_chat_self
Game_Event.push Game_Event::Chat.new(chatmessage)# if $game.show_chat_self
true
end
end
......
......@@ -42,7 +42,7 @@ class Window_Config < Window
when :avatar_cache
size = 0
count = 0
Dir.glob("graphics/avatars/*_*.png") do |file|
Dir.glob("graphics/avatars/*").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/}.each do |file|
count += 1
size += File.size(file)
end
......@@ -105,7 +105,7 @@ class Window_Config < Window
draw_item(@index, 1)
when :avatar_cache
#clear(*item_rect(@index))
Dir.glob("graphics/avatars/*_*.png") do |file|
Dir.glob("graphics/avatars/*").reject{|file|File.basename(file) =~ /(?:error|loading)_(?:small|middle|large)\.png/}.each do |file|
File.delete file
end
refresh
......
require_relative 'window_host'
class Window_LobbyButtons < Window_List
def initialize(x, y)
@items = ["常见问题", "卡组编辑", "建立房间"]
@items = [I18n.t('lobby.faq'), I18n.t('lobby.editdeck'), I18n.t('lobby.newroom')]
@button = Surface.load("graphics/lobby/button.png")
super(x, y, @items.size*@button.w/3+@items.size*4, 30)
@font = TTF.open("fonts/wqy-microhei.ttc", 15)
......@@ -9,9 +9,9 @@ class Window_LobbyButtons < Window_List
end
def draw_item(index, status=0)
x, y=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)
draw_stroked_text(@items[index], x+8, 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
def item_rect(index)
......
......@@ -45,23 +45,23 @@ class Window_Login < Window
:replay => [378,200,@button.w/3,@button.h]
}
@items_text = {
:login => "登录",
:register => "注册",
:replay => "录像"
:login => I18n.t("login.login"),
:register => I18n.t("login.register"),
:replay => I18n.t("login.replay"),
}
#self.index = nil
@remember_password = Widget_Checkbox.new(self, 357+@x,80+@y,self.width-357,24,password,"记住密码")
@remember_password = Widget_Checkbox.new(self, 357+@x,80+@y,self.width-357,24,password,I18n.t('login.remember'))
refresh
end
def refresh
clear
@items.each_pair{|index, rect|draw_item(index, rect)}
draw_stroked_text("用户名", 105,80+2,1)
draw_stroked_text("密码", 105,125+2,1)
draw_stroked_text(I18n.t('login.name'), 105,80+2,1)
draw_stroked_text(I18n.t('login.password'), 105,125+2,1)
end
def draw_item(index, rect, status=0)
Surface.blit(@button,rect[2]*status,0,rect[2],rect[3],@contents,rect[0],rect[1])
draw_stroked_text(@items_text[index], rect[0]+24, rect[1]+9,1,@font_button)
draw_stroked_text(@items_text[index], rect[0] + center_margin(@items_text[index], rect[2], @font_button), rect[1]+9,1,@font_button)
end
def mousemoved(x,y)
self.index = @items.each_pair{|index, rect|break index if (x-@x >= rect[0] and x-@x < rect[0]+rect[2] and y-@y >= rect[1] and y-@y < rect[1]+rect[3])}
......
......@@ -26,10 +26,9 @@ class Window_RoomList < Window_Scrollable
y = item_rect(index)[1]
room = @items[index]
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color)
@font.draw_blended_utf8(@contents, room.id.to_s, 24, y+8, *@color) unless room.id.to_s.empty?
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100
$log.error('标题过长') {room.name} if room.name.size > 100
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.nil? or room.name.empty? or room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1 and !room.player1.name.empty?
@font.draw_blended_utf8(@contents, room.player2.name, 320, y+24, *room.player2.color) if room.player2 and !room.player2.name.empty?
room.extra.each_with_index do |extra, index|
......
......@@ -7,20 +7,10 @@ class Game_Event
else
Error.new('登录', '用户名或密码错误')
end
#when :users
# AllUsers.new data.collect{|user|parse_user(user)}
when :rooms
rooms_wait = []
rooms_start = []
data.each do |room|
room = parse_room(room)
if room.full?
rooms_start << room
else
rooms_wait << room
end
end
AllRooms.new rooms_wait + rooms_start
AllRooms.new data.collect{|room|parse_room(room)}
when :rooms_update
RoomsUpdate.new data.collect{|room|parse_room(room)}
#when :newuser
#NewUser.new parse_user data
#when :missinguser
......@@ -29,13 +19,13 @@ class Game_Event
NewRoom.new parse_room data
when :missingroom
MissingRoom.new parse_room data
#when :chat
# case data[:channel]
# when :lobby
# Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
# else
# Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
# end
when :chat
case data[:channel]
when :lobby
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
else
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
end
end
end
def self.parse_room(room)
......@@ -49,6 +39,11 @@ class Game_Event
result.ot = room[:ot]
result.status = room[:status]
result.lp = room[:lp]
result._deleted = room[:_deleted]
result.server_id = room[:server_id]
result.server_ip = room[:server_ip]
result.server_port = room[:server_port]
result.server_auth = room[:server_auth]
result
end
def self.parse_user(user)
......
#encoding: UTF-8
load 'lib/ygocore/window_login.rb'
require 'eventmachine'
require 'open-uri'
require 'yaml'
class Ygocore < Game
......@@ -14,8 +15,8 @@ class Ygocore < Game
load 'lib/ygocore/room.rb'
load 'lib/ygocore/scene_lobby.rb'
require 'json'
require 'xmpp4r/client'
require 'xmpp4r/muc'
#require 'xmpp4r/client'
#require 'xmpp4r/muc'
end
def refresh_interval
......@@ -25,100 +26,107 @@ class Ygocore < Game
def login(username, password)
@username = username
@password = password
@nickname_conflict = []
@@im = Jabber::Client.new(Jabber::JID::new(@username, 'my-card.in', 'mycard'))
@@im_room = Jabber::MUC::MUCClient.new(@@im)
#@nickname_conflict = []
#@@im = Jabber::Client.new(Jabber::JID::new(@username, 'my-card.in', 'mycard'))
#@@im_room = Jabber::MUC::MUCClient.new(@@im)
#Jabber.debug = true
@@im.on_exception do |exception, c, where|
$log.error('聊天出错') { [exception, c, where] }
if where == :close
Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天连接断开, 可能是网络问题或帐号从其他地点登录')))
else
Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天连接断开, 5秒后重新连接')))
sleep 5
im_connect
end
end
@@im_room.add_message_callback do |m|
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('收到聊天消息') { $! }
end
@@im_room.add_private_message_callback do |m|
if m.body #忽略无消息的正在输入等内容
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, user) rescue $log.error('收到私聊消息') { $! }
end
end
@@im_room.add_join_callback do |m|
Game_Event.push Game_Event::NewUser.new User.new m.from.resource.to_sym, m.from.resource
end
@@im_room.add_leave_callback do |m|
Game_Event.push Game_Event::MissingUser.new User.new m.from.resource.to_sym, m.from.resource
end
#@@im.on_exception do |exception, c, where|
# $log.error('聊天出错') { [exception, c, where] }
# if where == :close
# Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天连接断开, 可能是网络问题或帐号从其他地点登录')))
# else
# Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天连接断开, 5秒后重新连接')))
# sleep 5
# im_connect
# end
#end
#@@im_room.add_message_callback do |m|
# 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('收到聊天消息') { $! }
#end
#@@im_room.add_private_message_callback do |m|
# if m.body #忽略无消息的正在输入等内容
# 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, user) rescue $log.error('收到私聊消息') { $! }
# end
#end
#@@im_room.add_join_callback do |m|
# Game_Event.push Game_Event::NewUser.new User.new m.from.resource.to_sym, m.from.resource
#end
#@@im_room.add_leave_callback do |m|
# Game_Event.push Game_Event::MissingUser.new User.new m.from.resource.to_sym, m.from.resource
#end
connect
im_connect
#im_connect
end
def nickname
return @nickname if @nickname
if @nickname_conflict.include? @username
1.upto(9) do |i|
result = "#{@username}-#{i}"
return result unless @nickname_conflict.include? result
end
raise 'can`t get available nickname'
else
@username
end
end
#def nickname
# return @nickname if @nickname
# if @nickname_conflict.include? @username
# 1.upto(9) do |i|
# result = "#{@username}-#{i}"
# return result unless @nickname_conflict.include? result
# end
# raise 'can`t get available nickname'
# else
# @username
# end
#end
def connect
@recv = Thread.new do
EventMachine::run {
EventMachine::connect "bbs.66rpg.com", 9998, Client
EventMachine::connect "mycard-server.my-card.in", 9997, Client
}
end
end
def im_connect
Thread.new {
begin
@@im.allow_tls = false
@@im.use_ssl = true
@@im.connect('my-card.in', 5223)
#ruby19/windows下 使用tls连接时会卡住
@@im.auth(@password)
@@im.send(Jabber::Presence.new.set_type(:available))
begin
nickname = nickname()
@@im_room.join(Jabber::JID.new('lobby@conference.my-card.in/' + nickname))
rescue Jabber::ServerError => exception
if exception.error.error == 'conflict'
@nickname_conflict << nickname
retry
end
end
Game_Event.push Game_Event::AllUsers.new @@im_room.roster.keys.collect { |nick| User.new(nick.to_sym, nick) } rescue p $!
rescue StandardError => exception
$log.error('聊天连接出错') { exception }
Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天服务器连接失败')))
end
}
end
#def im_connect
# Thread.new {
# begin
# @@im.allow_tls = false
# @@im.use_ssl = true
# @@im.connect('my-card.in', 5223)
# #ruby19/windows下 使用tls连接时会卡住
#
# @@im.auth(@password)
# @@im.send(Jabber::Presence.new.set_type(:available))
# begin
# nickname = nickname()
# @@im_room.join(Jabber::JID.new(I18n.t('lobby.room'), I18n.t('lobby.server'), nickname))
# rescue Jabber::ServerError => exception
# if exception.error.error == 'conflict'
# @nickname_conflict << nickname
# retry
# end
# end
# Game_Event.push Game_Event::AllUsers.new @@im_room.roster.keys.collect { |nick| User.new(nick.to_sym, nick) } rescue p $!
# rescue StandardError => exception
# $log.error('聊天连接出错') { exception }
# Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天服务器连接失败')))
# end
# }
#end
#def chat(chatmessage)
# case chatmessage.channel
# when :lobby
# msg = Jabber::Message::new(nil, chatmessage.message)
# @@im_room.send msg
# when User
# msg = Jabber::Message::new(nil, chatmessage.message)
# @@im_room.send msg, chatmessage.channel.id
# #send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
# end
#end
def chat(chatmessage)
case chatmessage.channel
when :lobby
msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg
send(:chat, channel: :lobby, message: chatmessage.message, time: chatmessage.time)
when User
msg = Jabber::Message::new(nil, chatmessage.message)
@@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
def host(room_name, room_config)
......@@ -129,6 +137,9 @@ class Ygocore < Game
room.password = room_config[:password]
room.ot = room_config[:ot]
room.lp = room_config[:lp]
room.server_ip = $game.server
room.server_port = $game.port
room.server_auth = true
if $game.rooms.any? { |game_room| game_room.name == room_name }
Widget_Msgbox.new("建立房间", "房间名已存在", :ok => "确定")
else
......@@ -228,9 +239,11 @@ class Ygocore < Game
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
end
(system_conf['nickname'] = "#{$game.user.name}#{"$" unless $game.password.nil? or $game.password.empty?}#{$game.password}") rescue nil
system_conf['lastip'] = $game.server
system_conf['lastport'] = $game.port.to_s
system_conf['nickname'] = $game.user.name
system_conf['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server_auth
p room
system_conf['lastip'] = room.server_ip
system_conf['lastport'] = room.server_port.to_s
system_conf['roompass'] = room_name
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-j'
......@@ -271,4 +284,44 @@ class Ygocore < Game
private
def self.get_announcements
#公告
$config['ygocore'] ||= {}
$config['ygocore']['announcements'] ||= [Announcement.new("开放注册", nil, nil)]
#Thread.new do
# begin
# open(@@config['api']) do |file|
# file.set_encoding "GBK"
# announcements = []
# file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title, others|
# announcements << Announcement.new(title, @@config['index'], nil)
# end
# $config['ygocore']['announcements'].replace announcements
# Config.save
# end
# rescue Exception => exception
# $log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
# end
#end
end
module Client
MycardChannel = EM::Channel.new
include EM::P::ObjectProtocol
def post_init
send_object header: :login, data: {name: $game.username, password: $game.password}
MycardChannel.subscribe { |msg| send_object(msg) }
end
def receive_object obj
$log.info('收到消息') { obj.inspect }
Game_Event.push Game_Event.parse obj[:header], obj[:data]
end
def unbind
Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true)
end
end
get_announcements
end
\ No newline at end of file
......@@ -5,6 +5,7 @@ class Room
attr_accessor :ot
attr_accessor :lp
attr_accessor :status
attr_accessor :server_id, :server_ip, :server_port, :server_auth
alias pvp? pvp
alias match? match
alias tag? tag
......
register: http://my-card.in/register
api: http://122.0.65.71:7922/
api: http://master.smdcn.net:7922/
index: http://my-card.in/
server: 122.0.65.71
server: 122.0.65.70
port: 7911
\ No newline at end of file
......@@ -22,13 +22,13 @@ class User
end
def avatar(size = :small)
cache = "graphics/avatars/mycard_#{@id}_#{size}.png"
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.gif")
result = Surface.load(cache) rescue Surface.load("graphics/avatars/loading_#{size}.png")
scene = $scene
if block_given?
yield result
Thread.new do
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/noavatar_#{size}.gif"
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"
(yield Surface.load(cache) if scene == $scene) rescue nil
end
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