Commit 62baa2e3 authored by 神楽坂玲奈's avatar 神楽坂玲奈

ygocore初步

parent d5eec823
...@@ -13,14 +13,13 @@ class Scene_Login < Scene ...@@ -13,14 +13,13 @@ class Scene_Login < Scene
def start def start
WM::set_caption("MyCard", "MyCard") WM::set_caption("MyCard", "MyCard")
@background = Surface.load("graphics/login/background.png").display_format @background = Surface.load("graphics/login/background.png").display_format
$config['game'] = 'iDuel' #临时修补点击过一次局域网之后无限进入局域网的问题 $config['game'] = 'iDuel' if $config['game'] == '局域网' #临时修补点击过一次局域网之后无限进入局域网的问题
@gameselect_window = Window_GameSelect.new(117,269) @gameselect_window = Window_GameSelect.new(117,269)
@announcements_window = Window_Announcements.new(313,265,600,24)
super super
end end
def update def update
@announcements_window.update #@announcements_window.update
#@gameselect_window.update @gameselect_window.update
super super
end end
def handle_game(event) def handle_game(event)
......
...@@ -42,7 +42,8 @@ class Window_Announcements < Window ...@@ -42,7 +42,8 @@ class Window_Announcements < Window
@transforming = 0 @transforming = 0
end end
end end
if @item != @items[@index] if @item != $config[$config['game']]['announcements'][@index]
@items = $config[$config['game']]['announcements']
@index = 0 @index = 0
@count = 0 @count = 0
@item = @items[@index] @item = @items[@index]
......
...@@ -25,6 +25,7 @@ class Window_GameSelect < Window_List ...@@ -25,6 +25,7 @@ class Window_GameSelect < Window_List
self.items = @items self.items = @items
self.index = @items.find_index{|game|game["name"] == $config['game']} || 0 self.index = @items.find_index{|game|game["name"] == $config['game']} || 0
clicked clicked
@announcements_window = Window_Announcements.new(313,265,600,24)
refresh refresh
end end
def draw_item(index, status=0) def draw_item(index, status=0)
...@@ -59,9 +60,11 @@ class Window_GameSelect < Window_List ...@@ -59,9 +60,11 @@ class Window_GameSelect < Window_List
$config['game'] = @items[@index]['name'] $config['game'] = @items[@index]['name']
@login_window.destroy if @login_window @login_window.destroy if @login_window
@login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"]) @login_window = Window_Login.new(316,316,$config[$config['game']]["username"],$config[$config['game']]["password"])
@announcements_window.refresh if @announcements_window
end end
def update def update
@login_window.update if @login_window @announcements_window.update if @announcements_window
end end
#def destroy #def destroy
# @login_window.destroy if @login_window # @login_window.destroy if @login_window
......
...@@ -27,9 +27,10 @@ class Window_RoomList < Window_Scrollable ...@@ -27,9 +27,10 @@ class Window_RoomList < Window_Scrollable
Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y) Surface.blit(@button, @width*status, room.full? ? WLH : 0, @width, WLH, @contents, 0, y)
@font.draw_blended_utf8(@contents, "R-#{room.id}", 24, y+8, *@color) @font.draw_blended_utf8(@contents, "R-#{room.id}", 24, y+8, *@color)
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color) @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) @font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *@color) p room.name if room.name.size > 100
@font.draw_blended_utf8(@contents, room.player2.name, 256, y+24, *@color) if room.full? @font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *@color) if room.player1
@font.draw_blended_utf8(@contents, room.player2.name, 256, y+24, *@color) if room.player2
end end
def mousemoved(x,y) def mousemoved(x,y)
...@@ -42,7 +43,7 @@ class Window_RoomList < Window_Scrollable ...@@ -42,7 +43,7 @@ class Window_RoomList < Window_Scrollable
$game.watch room $game.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战") @joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战")
else else
$game.join room, "test" $game.join room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间") @joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
end end
end end
......
#encoding: UTF-8
class Game_Event
User_Filter = /<li>(:::观战:|===决斗1=|===决斗2=)<font color="(?:blue|gray)">(.+?)(\(未认证\)|)<\/font>;<\/li>/
Room_Filter = /<div style="width:300px; height:150px; border:1px #ececec solid; float:left;padding:5px; margin:5px;">房间名称:(.+?) (<font color=red>决斗已开始!<\/font>|<font color=blue>等待<\/font>)(<font color="#CC6633" title="竞技场,接受服务器录像、场次统计,非认证玩家不得加入">[竞]<\/font>|)<font size="1">\(ID:(\d+)\)<\/font>#{User_Filter}+?<\/div>/
def initialize
end
class AllRooms < Game_Event
def self.parse(info)
@rooms = []
info.scan(Room_Filter) do |name, status, private, id|
player1 = player2 = nil
$&.scan(User_Filter) do |player, name, certified|
if player["1"]
player1 = User.new(name.to_sym, name)
elsif player["2"]
player2 = User.new(name.to_sym, name)
end
end
@rooms << Room.new(id.to_i, name, player1, player2, !!private, status["等待"] ? [0,0,255] : [255,0,0])
end
self.new @rooms
end
end
end
\ No newline at end of file
#encoding: UTF-8
load File.expand_path('window_login.rb', File.dirname(__FILE__))
require 'open-uri'
class Ygocore < Game
Register_Url = 'http://sh.convnet.net:7922/?userregist=NEW'
Port = 7911
Server = '221.226.68.62'
require 'win32api'
WM_LBUTTONDOWN = 0x201
WM_LBUTTONUP = 0x202
VK_CONTROL = 0x11
VK_A = 0x41
VK_V = 0x56
VK_TAB = 0x09
VK_RETURN = 0x0D
KEYEVENTF_KEYUP = 0x02
FindWindow = Win32API.new("user32","FindWindow","pp","l")
SendMessage = Win32API.new('user32', 'SendMessage', ["L", "L", "L", "L"], "L")
SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow', 'l', 'v')
Keybd_event = Win32API.new('user32', 'keybd_event', 'llll', 'v')
def initialize
super
load File.expand_path('event.rb', File.dirname(__FILE__))
end
def login(username, password)
connect
@password = password
Game_Event.push Game_Event::Login.new(User.new(username.to_sym, username))
end
def watch(room)
join(room)
end
def join(room)
return if @last_clicked and Time.now - @last_clicked < 3 #防止重复点击
unless $config['ygocore']['path'] and File.file? $config['ygocore']['path']
Widget_Msgbox.new("加入房间", "请指定ygocore主程序位置")
$scene.draw
require 'tk'
$config['ygocore']['path'] = Tk.getOpenFile
save_config
@last_clicked = Time.now
end
if $config['ygocore']['path'] and File.file? $config['ygocore']['path']
$scene.draw
#写入ygocore配置文件
Dir.chdir(File.dirname($config['ygocore']['path'])) do
system_conf = {}
IO.readlines('system.conf').each do |line|
next if line[0,1] == '#'
field, contents = line.chomp.split(' = ',2)
system_conf[field] = contents
system_conf['nickname'] = "#{@user.name}$#{@password}"
system_conf['lastip'] = Server
system_conf['lastport'] = Port.to_s
end
open('system.conf', 'w') {|file|file.write system_conf.collect{|key,value|"#{key} = #{value}"}.join("\n")}
#运行ygocore
require 'launchy'
Launchy.open $config['ygocore']['path']
#获取句柄
hwnd = nil
100.times do
if (hwnd = FindWindow.call('CIrrDeviceWin32', nil)) != 0
break
else
sleep 0.1
end
end
if hwnd and hwnd != 0
#操作ygocore进入主机
SendMessage.call(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(507,242))
SendMessage.call(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(507,242))
sleep 0.2
require 'win32/clipboard'
Win32::Clipboard.set_data(room.name)
SetForegroundWindow.call(hwnd)
SendMessage.call(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(380,500))
SendMessage.call(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(380,500))
Keybd_event.call(VK_CONTROL,0,0,0)
Keybd_event.call(VK_A,0,0,0)#全选以避免密码处已经有字的情况,正常情况下应该无用
Keybd_event.call(VK_A,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_V,0,0,0)
Keybd_event.call(VK_V,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_CONTROL,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_TAB,0,0,0)
Keybd_event.call(VK_TAB,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_RETURN,0,0,0)
Keybd_event.call(VK_RETURN,0,KEYEVENTF_KEYUP,0)
else
Widget_Msgbox.new("加入房间", 'ygocore运行失败')
end
end
end
$scene = Scene_Lobby.new
end
def refresh
#Thread.new do
begin
open('http://sh.convnet.net:7922/') do |file|
file.set_encoding("GBK")
Game_Event.push Game_Event::AllRooms.parse file.read.encode("UTF-8")
end
end
#end
end
private
def connect
end
def MAKELPARAM(w1,w2)
return (w2<<16) | w1
end
def self.get_announcements
#公告
$config['ygocore']['announcements'] ||= [Announcement.new("正在读取公告...", nil, nil)]
Thread.new do
begin
open('http://sh.convnet.net:7922/') do |file|
file.set_encoding "GBK"
announcements = []
file.read.scan(/<div style="color:red" >(.*?)<\/div>/).each do |title,others|
announcements << Announcement.new(title.encode("UTF-8"), "http://sh.convnet.net:7922/", nil)
end
$config['ygocore']['announcements'].replace announcements
save_config
end
rescue Exception => exception
$log.error('公告') {[exception.inspect, *exception.backtrace].join("\n")}
end
end
end
get_announcements
end
\ No newline at end of file
name: ygocore
\ No newline at end of file
#encoding: UTF-8
class Window_Login
def clicked
return if @last_clicked and Time.now - @last_clicked < 3 #防止重复点击
case @index
when :login
#Widget_Msgbox.new("iDuel", "正在登陆")
$scene.draw #强制重绘一次,下面会阻塞
$game = Ygocore.new
$config[$config['game']]['username'] = @username_inputbox.value
$config[$config['game']]['password'] = @remember_password.checked? ? @password_inputbox.value : nil
save_config
$game.login(@username_inputbox.value, @password_inputbox.value)
@last_clicked = Time.now
when :register
require 'launchy'
Launchy.open(Ygocore::Register_Url)
@last_clicked = Time.now
#when :replay
# require 'tk'
# file = Tk.getOpenFile
# if !file.empty?
# $game = Iduel.new
# $game.user = User.new(0)
# Widget_Msgbox.new("回放战报", "战报读取中...")
# $scene.draw
# $log.debug('iduel window_login'){'loading reply file'}
# $scene = Scene_Replay.new Replay.load file
# end
# @last_clicked = Time.now
end
end
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