Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaoye
mycard
Commits
1e26242c
Commit
1e26242c
authored
Dec 01, 2012
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nothing
parent
2250ddb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
273 additions
and
273 deletions
+273
-273
lib/ygocore/game.rb
lib/ygocore/game.rb
+273
-273
No files found.
lib/ygocore/game.rb
View file @
1e26242c
#encoding: UTF-8
#encoding: UTF-8
load
'lib/ygocore/window_login.rb'
load
'lib/ygocore/window_login.rb'
require
'open-uri'
require
'open-uri'
require
'yaml'
require
'yaml'
class
Ygocore
<
Game
class
Ygocore
<
Game
attr_reader
:username
attr_reader
:username
attr_accessor
:password
attr_accessor
:password
@@config
=
YAML
.
load_file
(
"lib/ygocore/server.yml"
)
@@config
=
YAML
.
load_file
(
"lib/ygocore/server.yml"
)
def
initialize
def
initialize
super
super
load
'lib/ygocore/event.rb'
load
'lib/ygocore/event.rb'
load
'lib/ygocore/user.rb'
load
'lib/ygocore/user.rb'
load
'lib/ygocore/room.rb'
load
'lib/ygocore/room.rb'
load
'lib/ygocore/scene_lobby.rb'
load
'lib/ygocore/scene_lobby.rb'
require
'json'
require
'json'
require
'xmpp4r/client'
require
'xmpp4r/client'
require
'xmpp4r/muc'
require
'xmpp4r/muc'
end
end
def
refresh_interval
def
refresh_interval
60
60
end
end
def
login
(
username
,
password
)
def
login
(
username
,
password
)
@username
=
username
@username
=
username
@password
=
password
@password
=
password
@nickname_conflict
=
[]
@nickname_conflict
=
[]
@@im
=
Jabber
::
Client
.
new
(
Jabber
::
JID
::
new
(
@username
,
'my-card.in'
,
'mycard'
))
@@im
=
Jabber
::
Client
.
new
(
Jabber
::
JID
::
new
(
@username
,
'my-card.in'
,
'mycard'
))
@@im_room
=
Jabber
::
MUC
::
MUCClient
.
new
(
@@im
)
@@im_room
=
Jabber
::
MUC
::
MUCClient
.
new
(
@@im
)
#Jabber.debug = true
#Jabber.debug = true
@@im
.
on_exception
do
|
exception
,
c
,
where
|
@@im
.
on_exception
do
|
exception
,
c
,
where
|
$log
.
error
(
'聊天出错'
)
{
[
exception
,
c
,
where
]
}
$log
.
error
(
'聊天出错'
)
{
[
exception
,
c
,
where
]
}
if
where
==
:close
if
where
==
:close
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天连接断开, 可能是网络问题或帐号从其他地点登录'
)))
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天连接断开, 可能是网络问题或帐号从其他地点登录'
)))
else
else
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天连接断开, 5秒后重新连接'
)))
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天连接断开, 5秒后重新连接'
)))
sleep
5
sleep
5
im_connect
im_connect
end
end
end
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
(
'收到聊天消息'
)
{
$!
}
end
end
@@im_room
.
add_private_message_callback
do
|
m
|
@@im_room
.
add_private_message_callback
do
|
m
|
if
m
.
body
#忽略无消息的正在输入等内容
if
m
.
body
#忽略无消息的正在输入等内容
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
,
user
)
rescue
$log
.
error
(
'收到私聊消息'
)
{
$!
}
Game_Event
.
push
Game_Event
::
Chat
.
new
ChatMessage
.
new
(
user
,
m
.
body
,
user
)
rescue
$log
.
error
(
'收到私聊消息'
)
{
$!
}
end
end
end
end
@@im_room
.
add_join_callback
do
|
m
|
@@im_room
.
add_join_callback
do
|
m
|
Game_Event
.
push
Game_Event
::
NewUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
Game_Event
.
push
Game_Event
::
NewUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
end
end
@@im_room
.
add_leave_callback
do
|
m
|
@@im_room
.
add_leave_callback
do
|
m
|
Game_Event
.
push
Game_Event
::
MissingUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
Game_Event
.
push
Game_Event
::
MissingUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
end
end
connect
connect
im_connect
im_connect
end
end
def
nickname
def
nickname
return
@nickname
if
@nickname
return
@nickname
if
@nickname
if
@nickname_conflict
.
include?
@username
if
@nickname_conflict
.
include?
@username
1
.
upto
(
9
)
do
|
i
|
1
.
upto
(
9
)
do
|
i
|
result
=
"
#{
@username
}
-
#{
i
}
"
result
=
"
#{
@username
}
-
#{
i
}
"
return
result
unless
@nickname_conflict
.
include?
result
return
result
unless
@nickname_conflict
.
include?
result
end
end
raise
'can`t get available nickname'
raise
'can`t get available nickname'
else
else
@username
@username
end
end
end
end
def
connect
def
connect
@recv
=
Thread
.
new
do
@recv
=
Thread
.
new
do
EventMachine
::
run
{
EventMachine
::
run
{
EventMachine
::
connect
"bbs.66rpg.com"
,
9998
,
Client
EventMachine
::
connect
"bbs.66rpg.com"
,
9998
,
Client
}
}
end
end
end
end
def
im_connect
def
im_connect
Thread
.
new
{
Thread
.
new
{
begin
begin
@@im
.
allow_tls
=
false
@@im
.
allow_tls
=
false
@@im
.
use_ssl
=
true
@@im
.
use_ssl
=
true
@@im
.
connect
(
'my-card.in'
,
5223
)
@@im
.
connect
(
'my-card.in'
,
5223
)
#ruby19/windows下 使用tls连接时会卡住
#ruby19/windows下 使用tls连接时会卡住
@@im
.
auth
(
@password
)
@@im
.
auth
(
@password
)
@@im
.
send
(
Jabber
::
Presence
.
new
.
set_type
(
:available
))
@@im
.
send
(
Jabber
::
Presence
.
new
.
set_type
(
:available
))
begin
begin
nickname
=
nickname
()
nickname
=
nickname
()
@@im_room
.
join
(
Jabber
::
JID
.
new
(
'lobby@conference.my-card.in/'
+
nickname
))
@@im_room
.
join
(
Jabber
::
JID
.
new
(
'lobby@conference.my-card.in/'
+
nickname
))
rescue
Jabber
::
ServerError
=>
exception
rescue
Jabber
::
ServerError
=>
exception
if
exception
.
error
.
error
==
'conflict'
if
exception
.
error
.
error
==
'conflict'
@nickname_conflict
<<
nickname
@nickname_conflict
<<
nickname
retry
retry
end
end
end
end
Game_Event
.
push
Game_Event
::
AllUsers
.
new
@@im_room
.
roster
.
keys
.
collect
{
|
nick
|
User
.
new
(
nick
.
to_sym
,
nick
)
}
rescue
p
$!
Game_Event
.
push
Game_Event
::
AllUsers
.
new
@@im_room
.
roster
.
keys
.
collect
{
|
nick
|
User
.
new
(
nick
.
to_sym
,
nick
)
}
rescue
p
$!
rescue
StandardError
=>
exception
rescue
StandardError
=>
exception
$log
.
error
(
'聊天连接出错'
)
{
exception
}
$log
.
error
(
'聊天连接出错'
)
{
exception
}
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天服务器连接失败'
)))
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天服务器连接失败'
)))
end
end
}
}
end
end
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
def
host
(
room_name
,
room_config
)
def
host
(
room_name
,
room_config
)
room
=
Room
.
new
(
0
,
room_name
)
room
=
Room
.
new
(
0
,
room_name
)
room
.
pvp
=
room_config
[
:pvp
]
room
.
pvp
=
room_config
[
:pvp
]
room
.
match
=
room_config
[
:match
]
room
.
match
=
room_config
[
:match
]
room
.
tag
=
room_config
[
:tag
]
room
.
tag
=
room_config
[
:tag
]
room
.
password
=
room_config
[
:password
]
room
.
password
=
room_config
[
:password
]
room
.
ot
=
room_config
[
:ot
]
room
.
ot
=
room_config
[
:ot
]
room
.
lp
=
room_config
[
:lp
]
room
.
lp
=
room_config
[
:lp
]
if
$game
.
rooms
.
any?
{
|
game_room
|
game_room
.
name
==
room_name
}
if
$game
.
rooms
.
any?
{
|
game_room
|
game_room
.
name
==
room_name
}
Widget_Msgbox
.
new
(
"建立房间"
,
"房间名已存在"
,
:ok
=>
"确定"
)
Widget_Msgbox
.
new
(
"建立房间"
,
"房间名已存在"
,
:ok
=>
"确定"
)
else
else
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
end
end
end
end
def
watch
(
room
)
def
watch
(
room
)
Widget_Msgbox
.
new
(
"加入房间"
,
"游戏已经开始"
,
:ok
=>
"确定"
)
Widget_Msgbox
.
new
(
"加入房间"
,
"游戏已经开始"
,
:ok
=>
"确定"
)
end
end
def
join
(
room
)
def
join
(
room
)
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
end
end
def
refresh
def
refresh
send
(
:refresh
)
send
(
:refresh
)
end
end
def
send
(
header
,
data
=
nil
)
def
send
(
header
,
data
=
nil
)
$log
.
info
(
'发送消息'
)
{
{
header:
header
,
data:
data
}
}
$log
.
info
(
'发送消息'
)
{
{
header:
header
,
data:
data
}
}
Client
::
MycardChannel
.
push
header:
header
,
data:
data
Client
::
MycardChannel
.
push
header:
header
,
data:
data
end
end
def
exit
def
exit
@recv
.
exit
if
@recv
@recv
.
exit
if
@recv
@recv
=
nil
@recv
=
nil
end
end
def
ygocore_path
def
ygocore_path
"ygocore/ygopro_vs.exe"
"ygocore/ygopro_vs.exe"
end
end
def
self
.
register
def
self
.
register
Dialog
.
web
@@config
[
'register'
]
Dialog
.
web
@@config
[
'register'
]
end
end
def
server
def
server
@@config
[
'server'
]
@@config
[
'server'
]
end
end
def
port
def
port
@@config
[
'port'
]
@@config
[
'port'
]
end
end
def
server
=
(
server
)
def
server
=
(
server
)
@@config
[
'server'
]
=
server
@@config
[
'server'
]
=
server
end
end
def
port
=
(
port
)
def
port
=
(
port
)
@@config
[
'port'
]
=
port
@@config
[
'port'
]
=
port
end
end
def
self
.
run_ygocore
(
option
,
image_downloading
=
false
)
def
self
.
run_ygocore
(
option
,
image_downloading
=
false
)
if
!
image_downloading
and
!
Update
.
images
.
empty?
if
!
image_downloading
and
!
Update
.
images
.
empty?
return
Widget_Msgbox
.
new
(
"加入房间"
,
"卡图正在下载中,可能显示不出部分卡图"
,
:ok
=>
"确定"
)
{
run_ygocore
(
option
,
true
)
}
return
Widget_Msgbox
.
new
(
"加入房间"
,
"卡图正在下载中,可能显示不出部分卡图"
,
:ok
=>
"确定"
)
{
run_ygocore
(
option
,
true
)
}
end
end
path
=
'ygocore/ygopro_vs.exe'
path
=
'ygocore/ygopro_vs.exe'
Widget_Msgbox
.
new
(
"ygocore"
,
"正在启动ygocore"
)
rescue
nil
Widget_Msgbox
.
new
(
"ygocore"
,
"正在启动ygocore"
)
rescue
nil
#写入配置文件并运行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
end
system_conf
=
{}
system_conf
=
{}
begin
begin
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
line
.
force_encoding
"UTF-8"
line
.
force_encoding
"UTF-8"
next
if
line
[
0
,
1
]
==
'#'
next
if
line
[
0
,
1
]
==
'#'
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
system_conf
[
field
]
=
contents
system_conf
[
field
]
=
contents
end
end
rescue
rescue
system_conf
[
'antialias'
]
=
2
system_conf
[
'antialias'
]
=
2
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
end
end
(
system_conf
[
'nickname'
]
=
"
#{
$game
.
user
.
name
}#{
"$"
unless
$game
.
password
.
nil?
or
$game
.
password
.
empty?
}#{
$game
.
password
}
"
)
rescue
nil
(
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
[
'lastip'
]
=
$game
.
server
system_conf
[
'lastport'
]
=
$game
.
port
.
to_s
system_conf
[
'lastport'
]
=
$game
.
port
.
to_s
system_conf
[
'roompass'
]
=
room_name
system_conf
[
'roompass'
]
=
room_name
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
args
=
'-j'
args
=
'-j'
when
:replay
when
:replay
args
=
'-r'
args
=
'-r'
when
:deck
when
:deck
args
=
'-d'
args
=
'-d'
when
String
when
String
system_conf
=
{}
system_conf
=
{}
begin
begin
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
line
.
force_encoding
"UTF-8"
line
.
force_encoding
"UTF-8"
next
if
line
[
0
,
1
]
==
'#'
next
if
line
[
0
,
1
]
==
'#'
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
system_conf
[
field
]
=
contents
system_conf
[
field
]
=
contents
end
end
rescue
rescue
system_conf
[
'antialias'
]
=
2
system_conf
[
'antialias'
]
=
2
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
end
end
system_conf
[
'lastdeck'
]
=
option
system_conf
[
'lastdeck'
]
=
option
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
args
=
'-d'
args
=
'-d'
end
end
IO
.
popen
(
"ygopro_vs.exe
#{
args
}
"
)
IO
.
popen
(
"ygopro_vs.exe
#{
args
}
"
)
WM
.
iconify
rescue
nil
WM
.
iconify
rescue
nil
end
end
Widget_Msgbox
.
destroy
rescue
nil
Widget_Msgbox
.
destroy
rescue
nil
end
end
def
self
.
replay
(
file
,
skip_image_downloading
=
false
)
def
self
.
replay
(
file
,
skip_image_downloading
=
false
)
require
'fileutils'
require
'fileutils'
FileUtils
.
mv
Dir
.
glob
(
'ygocore/replay/*.yrp'
),
'replay/'
FileUtils
.
mv
Dir
.
glob
(
'ygocore/replay/*.yrp'
),
'replay/'
FileUtils
.
copy_file
(
file
,
"ygocore/replay/
#{
File
.
basename
(
file
)
}
"
)
FileUtils
.
copy_file
(
file
,
"ygocore/replay/
#{
File
.
basename
(
file
)
}
"
)
run_ygocore
(
:replay
,
skip_image_downloading
)
run_ygocore
(
:replay
,
skip_image_downloading
)
end
end
private
private
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment