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

版本0.4.9 大厅聊天

parent 5c53e428
......@@ -24,7 +24,7 @@ end
spec = Gem::Specification.new do |s|
s.name = 'mycard'
s.version = '0.4.8'
s.version = '0.4.9'
s.extra_rdoc_files = ['README.txt', 'LICENSE.txt']
s.summary = 'a card game'
s.description = s.summary
......
......@@ -2,7 +2,7 @@ require 'open-uri'
require "fileutils"
require_relative 'card'
module Update
Version = '0.4.8'
Version = '0.4.9'
URL = "http://card.touhou.cc/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
......@@ -30,6 +30,9 @@ module Update
IO.popen('./mycard')
$scene = nil
end
@images = []
@thumbnails = []
@status = '正在检查更新'
Thread.new do
open(URL) do |file|
......@@ -51,11 +54,10 @@ module Update
if File.file? "ygocore/cards.cdb"
require 'sqlite3'
db = SQLite3::Database.new( "ygocore/cards.cdb" )
@thumbnails = []
db.execute( "select id from datas" ) do |row|
@thumbnails << row[0]
end
@images = @thumbnails.dup
@images.replace @thumbnails
if !File.directory?('ygocore/pics/thumbnail')
FileUtils.mkdir_p('ygocore/pics/thumbnail')
......
......@@ -76,11 +76,11 @@ module RM_IME
module_function
def init
return if @active
$log.info('输入法'){'开启'}
_init(HWND, 0, 0)
@x = 0
@y = 0
@active = true
$log.info('输入法'){'开启'}
end
def set(x,y)
@x = x
......@@ -102,8 +102,8 @@ module RM_IME
end
def dispose
return if !@active
_dispose
$log.info('输入法'){'关闭'}
_dispose
@active = false
end
def active?
......
......@@ -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|
case key
when :ENTER
chatmessage = ChatMessage.new($game.user, @chat_input.value, @channel)
$game.chat chatmessage
Game_Event.push Game_Event::Chat.new(chatmessage)
true
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)
true
end
when :ESC
true
end
......@@ -48,7 +50,10 @@ class Window_Chat < Window_Scrollable
end
def add(chatmessage)
@@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
scroll_bottom = @items.size - self.scroll <= @page_size
add_split(chatmessage)
......
......@@ -69,13 +69,8 @@ class Game_Event
@users << room.player1 if room.player1
@users << room.player2 if room.player2
end
@users.uniq!
self.new @users
end
end
class Join < Game_Event
def initialize(room)
@room = room
$game.room = @room
end
end
end
\ No newline at end of file
......@@ -37,6 +37,41 @@ class Ygocore < Game
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)
if $game.password.nil? or $game.password.empty?
return Widget_Msgbox.new("建立房间", "必须有账号才能建立房间", :ok => "确定")
......@@ -100,6 +135,11 @@ class Ygocore < Game
end
end
end
def exit
(@irc.quit if @irc) rescue nil
@irc = nil
@chat_thread = nil
end
def 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 #防止重复点击
......@@ -175,6 +215,16 @@ class Ygocore < Game
def connect
require 'open-uri'
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
#公告
$config['ygocore'] ||= {}
......@@ -197,8 +247,4 @@ class Ygocore < Game
end
end
get_announcements
end
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