Commit 804cdbc3 authored by 神楽坂玲奈's avatar 神楽坂玲奈

版本0.4.9 大厅聊天

parent 5c53e428
...@@ -24,7 +24,7 @@ end ...@@ -24,7 +24,7 @@ end
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'mycard' s.name = 'mycard'
s.version = '0.4.8' s.version = '0.4.9'
s.extra_rdoc_files = ['README.txt', 'LICENSE.txt'] s.extra_rdoc_files = ['README.txt', 'LICENSE.txt']
s.summary = 'a card game' s.summary = 'a card game'
s.description = s.summary s.description = s.summary
......
...@@ -2,7 +2,7 @@ require 'open-uri' ...@@ -2,7 +2,7 @@ require 'open-uri'
require "fileutils" require "fileutils"
require_relative 'card' require_relative 'card'
module Update module Update
Version = '0.4.8' Version = '0.4.9'
URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}" URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}"
class <<self class <<self
attr_reader :thumbnails, :images, :status attr_reader :thumbnails, :images, :status
...@@ -30,6 +30,9 @@ module Update ...@@ -30,6 +30,9 @@ module Update
IO.popen('./mycard') IO.popen('./mycard')
$scene = nil $scene = nil
end end
@images = []
@thumbnails = []
@status = '正在检查更新' @status = '正在检查更新'
Thread.new do Thread.new do
open(URL) do |file| open(URL) do |file|
...@@ -51,11 +54,10 @@ module Update ...@@ -51,11 +54,10 @@ module Update
if File.file? "ygocore/cards.cdb" if File.file? "ygocore/cards.cdb"
require 'sqlite3' require 'sqlite3'
db = SQLite3::Database.new( "ygocore/cards.cdb" ) db = SQLite3::Database.new( "ygocore/cards.cdb" )
@thumbnails = []
db.execute( "select id from datas" ) do |row| db.execute( "select id from datas" ) do |row|
@thumbnails << row[0] @thumbnails << row[0]
end end
@images = @thumbnails.dup @images.replace @thumbnails
if !File.directory?('ygocore/pics/thumbnail') if !File.directory?('ygocore/pics/thumbnail')
FileUtils.mkdir_p('ygocore/pics/thumbnail') FileUtils.mkdir_p('ygocore/pics/thumbnail')
......
...@@ -76,11 +76,11 @@ module RM_IME ...@@ -76,11 +76,11 @@ module RM_IME
module_function module_function
def init def init
return if @active return if @active
$log.info('输入法'){'开启'}
_init(HWND, 0, 0) _init(HWND, 0, 0)
@x = 0 @x = 0
@y = 0 @y = 0
@active = true @active = true
$log.info('输入法'){'开启'}
end end
def set(x,y) def set(x,y)
@x = x @x = x
...@@ -102,8 +102,8 @@ module RM_IME ...@@ -102,8 +102,8 @@ module RM_IME
end end
def dispose def dispose
return if !@active return if !@active
_dispose
$log.info('输入法'){'关闭'} $log.info('输入法'){'关闭'}
_dispose
@active = false @active = false
end end
def active? def active?
......
...@@ -24,10 +24,12 @@ class Window_Chat < Window_Scrollable ...@@ -24,10 +24,12 @@ class Window_Chat < Window_Scrollable
@chat_input = Widget_InputBox.new(@x+8, @y+@height-24-10, @width-14, 24) do |key| @chat_input = Widget_InputBox.new(@x+8, @y+@height-24-10, @width-14, 24) do |key|
case key case key
when :ENTER when :ENTER
if !@chat_input.value.empty?
chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel) chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel)
$game.chat chatmessage $game.chat chatmessage
Game_Event.push Game_Event::Chat.new(chatmessage) Game_Event.push Game_Event::Chat.new(chatmessage)
true true
end
when :ESC when :ESC
true true
end end
...@@ -48,7 +50,10 @@ class Window_Chat < Window_Scrollable ...@@ -48,7 +50,10 @@ class Window_Chat < Window_Scrollable
end end
def add(chatmessage) def add(chatmessage)
@@list[chatmessage.channel] ||= [] @@list[chatmessage.channel] ||= []
@channels << chatmessage.channel unless @channels.include? chatmessage.channel unless @channels.include? chatmessage.channel
@channels << chatmessage.channel
refresh
end
@@list[chatmessage.channel] << chatmessage @@list[chatmessage.channel] << chatmessage
scroll_bottom = @items.size - self.scroll <= @page_size scroll_bottom = @items.size - self.scroll <= @page_size
add_split(chatmessage) add_split(chatmessage)
......
...@@ -69,13 +69,8 @@ class Game_Event ...@@ -69,13 +69,8 @@ class Game_Event
@users << room.player1 if room.player1 @users << room.player1 if room.player1
@users << room.player2 if room.player2 @users << room.player2 if room.player2
end end
@users.uniq!
self.new @users self.new @users
end end
end end
class Join < Game_Event
def initialize(room)
@room = room
$game.room = @room
end
end
end end
\ No newline at end of file
...@@ -37,6 +37,41 @@ class Ygocore < Game ...@@ -37,6 +37,41 @@ class Ygocore < Game
end end
end end
end end
def user=(user)
super
begin
require 'net/yail'
$log.info('聊天'){user.inspect}
@irc = Net::YAIL.new(
address: 'card.touhou.cc',
username: hexencode(user.id),
nicknames: [hexencode(user.name), hexencode("#{user.name}_#{rand(10000)}"), hexencode("#{user.name}_#{rand(10000)}")])
$log.info('聊天连接')
@irc.on_welcome proc { |event| $log.info('连接聊天服务器成功'); Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'system'), '聊天服务器连接成功,聊天功能测试中,可能引发程序崩溃,如果崩得过于频繁请暂时不要使用.', :lobby))); @irc.join('#lobby') }
@irc.hearing_msg {|event|
user = User.new(hexdecode(event.msg.user).to_sym, hexdecode(event.nick))
Game_Event.push Game_Event::Chat.new(ChatMessage.new(user, event.message, event.channel ? event.channel[1,event.channel.size-1].to_sym : user))
}
$log.info('聊天开始监听')
@irc.start_listening
$log.info('聊天加载完毕')
rescue Exception => exception
$log.error('聊天出错'){[exception.inspect, *exception.backtrace].collect{|str|str.encode("UTF-8")}.join("\n")}
Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'system'), '连接聊天服务器失败', :lobby)))
end
end
def chat(chatmessage)
$log.info('发送聊天消息'){chatmessage.inspect}
return unless @irc
case chatmessage.channel
when Symbol
@irc.msg "##{chatmessage.channel}", chatmessage.message
when User
@irc.msg hexencode(chatmessage.channel.id), chatmessage.message
end
$log.info('发送聊天消息完毕')
end
def host(room_name, room_config) def host(room_name, room_config)
if $game.password.nil? or $game.password.empty? if $game.password.nil? or $game.password.empty?
return Widget_Msgbox.new("建立房间", "必须有账号才能建立房间", :ok => "确定") return Widget_Msgbox.new("建立房间", "必须有账号才能建立房间", :ok => "确定")
...@@ -100,6 +135,11 @@ class Ygocore < Game ...@@ -100,6 +135,11 @@ class Ygocore < Game
end end
end end
end end
def exit
(@irc.quit if @irc) rescue nil
@irc = nil
@chat_thread = nil
end
def ygocore_path def ygocore_path
# return $config['ygocore']['path'] if $config['ygocore']['path'] and File.file? $config['ygocore']['path'] # return $config['ygocore']['path'] if $config['ygocore']['path'] and File.file? $config['ygocore']['path']
# return if @last_clicked and Time.now - @last_clicked < 3 #防止重复点击 # return if @last_clicked and Time.now - @last_clicked < 3 #防止重复点击
...@@ -175,6 +215,16 @@ class Ygocore < Game ...@@ -175,6 +215,16 @@ class Ygocore < Game
def connect def connect
require 'open-uri' require 'open-uri'
end end
def hexencode(str)
'_' + str.to_s.unpack('H*').first
end
def hexdecode(str)
result = str[1, str.size-1]
[result.to_s].pack('H*')
end
def MAKELPARAM(w1,w2)
(w2<<16) | w1
end
def self.get_announcements def self.get_announcements
#公告 #公告
$config['ygocore'] ||= {} $config['ygocore'] ||= {}
...@@ -198,7 +248,3 @@ class Ygocore < Game ...@@ -198,7 +248,3 @@ class Ygocore < Game
end end
get_announcements get_announcements
end end
\ No newline at end of file
def MAKELPARAM(w1,w2)
(w2<<16) | w1
end
\ No newline at end of file
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