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
syntax_j
mycard
Commits
cd38339e
Commit
cd38339e
authored
Dec 08, 2012
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
filter
parent
6abbb711
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
447 additions
and
496 deletions
+447
-496
graphics/avatars/loading_middle.gif
graphics/avatars/loading_middle.gif
+0
-0
graphics/avatars/loading_small.gif
graphics/avatars/loading_small.gif
+0
-0
graphics/avatars/noavatar_middle.gif
graphics/avatars/noavatar_middle.gif
+0
-0
graphics/avatars/noavatar_small.gif
graphics/avatars/noavatar_small.gif
+0
-0
graphics/lobby/filter.png
graphics/lobby/filter.png
+0
-0
lib/game.rb
lib/game.rb
+50
-47
lib/game_event.rb
lib/game_event.rb
+7
-0
lib/scene_lobby.rb
lib/scene_lobby.rb
+4
-1
lib/server.rb
lib/server.rb
+19
-0
lib/window_filter.rb
lib/window_filter.rb
+25
-121
lib/window_lobbybuttons.rb
lib/window_lobbybuttons.rb
+5
-1
lib/ygocore/event.rb
lib/ygocore/event.rb
+7
-0
lib/ygocore/game.rb
lib/ygocore/game.rb
+327
-326
locales/zh.yml
locales/zh.yml
+3
-0
No files found.
graphics/avatars/loading_middle.gif
deleted
100644 → 0
View file @
6abbb711
5.85 KB
graphics/avatars/loading_small.gif
deleted
100644 → 0
View file @
6abbb711
2.05 KB
graphics/avatars/noavatar_middle.gif
deleted
100644 → 0
View file @
6abbb711
3.88 KB
graphics/avatars/noavatar_small.gif
deleted
100644 → 0
View file @
6abbb711
1.54 KB
graphics/lobby/filter.png
View file @
cd38339e
This diff was suppressed by a .gitattributes entry.
lib/game.rb
View file @
cd38339e
#游戏适配器的抽象类
#游戏适配器的抽象类
require_relative
'game_event'
require_relative
'game_event'
require_relative
'action'
require_relative
'action'
require_relative
'user'
require_relative
'user'
require_relative
'room'
require_relative
'room'
class
Game
require_relative
'server'
attr_reader
:users
,
:rooms
class
Game
attr_accessor
:user
,
:room
,
:player_field
,
:opponent_field
,
:turn
,
:turn_player
,
:phase
attr_reader
:users
,
:rooms
,
:servers
,
:filter
def
initialize
attr_accessor
:user
,
:room
,
:player_field
,
:opponent_field
,
:turn
,
:turn_player
,
:phase
@users
=
[]
def
initialize
@rooms
=
[]
@users
=
[]
end
@rooms
=
[]
def
login
(
username
,
password
=
nil
)
@servers
=
[]
end
@filter
=
{
servers:
[],
waiting_only:
false
,
normal_only:
false
}
def
refresh
end
end
def
login
(
username
,
password
=
nil
)
def
host
(
room_name
,
room_config
)
end
end
def
refresh
def
join
(
room
)
end
end
def
host
(
room_name
,
room_config
)
def
watch
(
room
)
end
end
def
join
(
room
)
def
leave
end
end
def
watch
(
room
)
def
action
(
action
)
end
end
def
leave
def
chat
(
chatmessage
)
end
end
def
action
(
action
)
def
exit
end
$scene
=
Scene_Login
.
new
if
$scene
def
chat
(
chatmessage
)
end
end
def
watching?
def
exit
@room
and
@room
.
include?
@user
$scene
=
Scene_Login
.
new
if
$scene
end
end
def
self
.
deck_edit
def
watching?
require_relative
'window_deck'
@room
and
@room
.
include?
@user
@deck_window
=
Window_Deck
.
new
end
end
def
self
.
deck_edit
def
refresh_interval
require_relative
'window_deck'
5
@deck_window
=
Window_Deck
.
new
end
end
def
show_chat_self
def
refresh_interval
false
5
end
end
end
def
show_chat_self
false
end
end
lib/game_event.rb
View file @
cd38339e
...
@@ -40,6 +40,13 @@ class Game_Event
...
@@ -40,6 +40,13 @@ class Game_Event
end
end
end
end
class
AllServers
<
Game_Event
attr_reader
:servers
def
initialize
(
servers
)
$game
.
servers
.
replace
servers
end
end
class
NewUser
<
AllUsers
class
NewUser
<
AllUsers
attr_reader
:users
attr_reader
:users
...
...
lib/scene_lobby.rb
View file @
cd38339e
...
@@ -11,6 +11,7 @@ class Scene_Lobby < Scene
...
@@ -11,6 +11,7 @@ class Scene_Lobby < Scene
require_relative
'window_roomlist'
require_relative
'window_roomlist'
require_relative
'window_chat'
require_relative
'window_chat'
require_relative
'window_host'
require_relative
'window_host'
require_relative
'window_filter'
require_relative
'window_lobbybuttons'
require_relative
'window_lobbybuttons'
require_relative
'chatmessage'
require_relative
'chatmessage'
require_relative
'scene_duel'
require_relative
'scene_duel'
...
@@ -62,7 +63,9 @@ class Scene_Lobby < Scene
...
@@ -62,7 +63,9 @@ class Scene_Lobby < Scene
when
Game_Event
::
AllUsers
when
Game_Event
::
AllUsers
@userlist
.
items
=
$game
.
users
@userlist
.
items
=
$game
.
users
when
Game_Event
::
AllRooms
when
Game_Event
::
AllRooms
@roomlist
.
items
=
$game
.
rooms
@roomlist
.
items
=
$game
.
rooms
.
find_all
{
|
room
|
$game
.
filter
[
:servers
].
collect
{
|
server
|
server
.
id
}.
include?
(
room
.
server_id
)}
when
Game_Event
::
AllServers
@roomlist
.
items
=
$game
.
rooms
.
find_all
{
|
room
|
$game
.
filter
[
:servers
].
collect
{
|
server
|
server
.
id
}.
include?
(
room
.
server_id
)}
when
Game_Event
::
Join
when
Game_Event
::
Join
join
(
event
.
room
)
join
(
event
.
room
)
when
Game_Event
::
Watch
when
Game_Event
::
Watch
...
...
lib/server.rb
0 → 100644
View file @
cd38339e
require_relative
'cacheable'
class
Server
attr_accessor
:id
,
:name
,
:ip
,
:port
,
:auth
extend
Cacheable
def
initialize
(
id
,
name
=
""
,
ip
=
""
,
port
=
0
,
auth
=
false
)
@id
=
id
@name
=
name
@ip
=
ip
@port
=
port
@auth
=
auth
end
def
set
(
id
,
name
=
:keep
,
ip
=
:keep
,
port
=
:keep
,
auth
=
:keep
)
@id
=
id
@name
=
name
unless
name
==
:keep
@ip
=
ip
unless
ip
==
:keep
@port
=
name
unless
port
==
:keep
@auth
=
name
unless
auth
==
:keep
end
end
\ No newline at end of file
lib/window_filter.rb
View file @
cd38339e
...
@@ -2,137 +2,41 @@ class Window_Filter < Window
...
@@ -2,137 +2,41 @@ class Window_Filter < Window
attr_reader
:index
attr_reader
:index
def
initialize
(
x
,
y
)
def
initialize
(
x
,
y
)
@background
=
Surface
.
load
(
'graphics/lobby/filter.png'
).
display_format
@background
=
Surface
.
load
(
'graphics/lobby/filter.png'
).
display_format
super
(
(
1024
-
@background
.
w
)
/
2
,
230
,
@background
.
w
,
@background
.
h
)
super
(
x
,
y
,
@background
.
w
,
@background
.
h
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
16
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
16
)
@color
=
[
0x04
,
0x47
,
0x7c
]
@color
=
[
0x04
,
0x47
,
0x7c
]
@title_color
=
[
0xFF
,
0xFF
,
0xFF
]
[]
@pvp
=
Widget_Checkbox
.
new
(
self
,
33
+
@x
,
@y
+
41
+
WLH
*
2
,
120
,
24
,
false
,
"竞技场"
)
{
|
checked
|
(
@ocg
.
checked
=
true
;
@tcg
.
checked
=
@tag
.
checked
=
false
;
@lp_inputbox
.
value
=
"8000"
)
if
checked
}
@pvp
.
background
=
@background
.
copy_rect
(
33
,
70
,
120
,
24
)
@match
=
Widget_Checkbox
.
new
(
self
,
120
+
@x
,
@y
+
41
+
WLH
*
2
,
120
,
24
,
true
,
"三回决斗"
){
|
checked
|
@tag
.
checked
=
false
if
checked
}
@match
.
background
=
@background
.
copy_rect
(
120
,
70
,
120
,
24
)
@tag
=
Widget_Checkbox
.
new
(
self
,
33
+
@x
,
@y
+
41
+
WLH
*
4
+
4
,
120
,
24
,
false
,
"TAG双打"
){
|
checked
|
@pvp
.
checked
=
@match
.
checked
=
false
if
checked
}
@tag
.
background
=
@background
.
copy_rect
(
120
,
70
,
120
,
24
)
@ocg
=
Widget_Checkbox
.
new
(
self
,
33
+
@x
,
@y
+
41
+
WLH
*
5
+
4
,
120
,
24
,
true
,
"OCG"
){
|
checked
|
@tcg
.
checked
=
true
if
!
checked
}
@ocg
.
background
=
@background
.
copy_rect
(
120
,
70
,
120
,
24
)
@tcg
=
Widget_Checkbox
.
new
(
self
,
120
+
@x
,
@y
+
41
+
WLH
*
5
+
4
,
120
,
24
,
false
,
"TCG"
){
|
checked
|
@pvp
.
checked
=
false
if
checked
;
@ocg
.
checked
=
true
if
!
checked
}
@tcg
.
background
=
@background
.
copy_rect
(
120
,
70
,
120
,
24
)
@roomname_inputbox
.
value
=
rand
(
1000
).
to_s
@servers
=
$game
.
servers
.
each_with_index
.
collect
do
|
server
,
index
|
@lp_inputbox
.
value
=
8000
.
to_s
result
=
Widget_Checkbox
.
new
(
self
,
4
+
@x
,
@y
+
WLH
+
WLH
*
index
,
@width
-
8
,
24
,
true
,
server
.
name
){
|
checked
|
checked
?
$game
.
filter
[:
servers
].
push
(
server
)
:
$game
.
filter
[
:servers
].
delete
(
server
)
;
Game_Event
.
push
(
Game_Event
::
AllRooms
.
new
(
$game
.
rooms
))}
@password_inputbox
.
refresh
result
.
background
=
@background
.
copy_rect
(
4
,
WLH
+
WLH
*
index
,
@width
-
8
,
24
)
@pvp
.
refresh
result
.
refresh
@match
.
refresh
result
@tag
.
refresh
end
@ocg
.
refresh
@tcg
.
refresh
@waiting_only
=
Widget_Checkbox
.
new
(
self
,
4
+
@x
,
@y
+
WLH
*
7
-
4
,
@width
-
8
,
24
,
true
,
I18n
.
t
(
'lobby.waiting_only'
)){
|
checked
|
$game
.
filter
[
:waiting_only
]
=
checked
;
Game_Event
.
push
(
Game_Event
::
AllRooms
.
new
(
$game
.
rooms
))}
@waiting_only
.
background
=
@background
.
copy_rect
(
4
,
WLH
*
7
-
4
,
@width
-
8
,
24
)
@waiting_only
.
checked
=
false
@waiting_only
.
refresh
@normal_only
=
Widget_Checkbox
.
new
(
self
,
4
+
@x
,
@y
+
WLH
*
7
+
WLH
-
4
,
120
,
24
,
true
,
I18n
.
t
(
'lobby.normal_only'
)){
|
checked
|
$game
.
filter
[
:normal_only
]
=
checked
;
Game_Event
.
push
(
Game_Event
::
AllRooms
.
new
(
$game
.
rooms
))}
@normal_only
.
background
=
@background
.
copy_rect
(
4
,
WLH
*
7
+
WLH
-
4
,
120
,
24
)
@normal_only
.
checked
=
false
@normal_only
.
refresh
refresh
refresh
end
end
def
refresh
def
refresh
clear
clear
@font
.
draw_blended_utf8
(
@contents
,
"建立房间"
,
(
@width
-
@font
.
text_size
(
"建立房间"
)[
0
])
/
2
,
2
,
*
@title_color
)
@font
.
draw_blended_utf8
(
@contents
,
"服务器"
,
4
,
4
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
"房间名"
,
33
,
43
,
*
@color
)
@contents
.
fill_rect
(
4
,
WLH
,
@contents
.
w
-
8
,
2
,
0xAA0A7AC5
)
@font
.
draw_blended_utf8
(
@contents
,
"房间密码"
,
33
,
43
+
WLH
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
"房间属性"
,
4
,
WLH
*
6
+
4
-
4
,
*
@color
)
@contents
.
fill_rect
(
4
,
43
+
WLH
*
3
,
@contents
.
w
-
8
,
2
,
0xAA0A7AC5
)
@contents
.
fill_rect
(
4
,
WLH
*
7
-
4
,
@contents
.
w
-
8
,
2
,
0xAA0A7AC5
)
@font
.
draw_blended_utf8
(
@contents
,
"自定义模式"
,
20
,
43
+
WLH
*
3
+
4
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
"初始LP"
,
33
,
44
+
WLH
*
6
+
4
,
*
@color
)
@items
.
each_key
do
|
index
|
draw_item
(
index
,
self
.
index
==
index
?
1
:
0
)
end
end
def
draw_item
(
index
,
status
=
0
)
Surface
.
blit
(
@button
,
@button
.
w
/
3
*
status
,
0
,
@button
.
w
/
3
,
@button
.
h
,
@contents
,
@items
[
index
][
0
],
@items
[
index
][
1
])
text_size
=
@font
.
text_size
(
@buttons
[
index
])
@font
.
draw_blended_utf8
(
@contents
,
@buttons
[
index
],
@items
[
index
][
0
]
+
(
@button
.
w
/
3
-
text_size
[
0
])
/
2
,
@items
[
index
][
1
]
+
(
@button
.
h
-
text_size
[
1
])
/
2
,
0xFF
,
0xFF
,
0xFF
)
end
def
mousemoved
(
x
,
y
)
new_index
=
nil
@items
.
each_key
do
|
index
|
if
(
x
-
@x
).
between?
(
@items
[
index
][
0
],
@items
[
index
][
0
]
+
@items
[
index
][
2
])
and
(
y
-
@y
).
between?
(
@items
[
index
][
1
],
@items
[
index
][
1
]
+
@items
[
index
][
3
])
new_index
=
index
break
end
end
self
.
index
=
new_index
end
def
item_rect
(
index
)
@items
[
index
]
end
def
index
=
(
index
)
return
if
index
==
@index
if
@index
clear
(
*
item_rect
(
@index
))
draw_item
(
@index
,
0
)
end
if
index
.
nil?
or
!
@items
.
include?
index
@index
=
nil
else
@index
=
index
draw_item
(
@index
,
1
)
end
end
def
clicked
case
self
.
index
when
:ok
if
@roomname_inputbox
.
value
.
empty?
Widget_Msgbox
.
new
(
"建立房间"
,
"请输入房间名"
,
ok:
"确定"
)
elsif
!
name_check
Widget_Msgbox
.
new
(
"建立房间"
,
"房间名/房间密码超过长度上限"
,
ok:
"确定"
)
elsif
@lp_inputbox
.
value
.
to_i
>=
99999
Widget_Msgbox
.
new
(
"建立房间"
,
"初始LP超过上限"
,
ok:
"确定"
)
else
Widget_Msgbox
.
new
(
"建立房间"
,
"正在建立房间"
)
destroy
$game
.
host
(
@roomname_inputbox
.
value
,
password:
@password_inputbox
.
value
,
pvp:
@pvp
.
checked?
,
match:
@match
.
checked?
,
tag:
@tag
.
checked?
,
ot:
@tcg
.
checked?
?
@ocg
.
checked?
?
2
:
1
:
0
,
lp:
@lp_inputbox
.
value
.
to_i
)
end
when
:cancel
destroy
end
end
end
def
destroy
def
destroy
@roomname_inputbox
.
destroy
@servers
.
each
{
|
server
|
server
.
destroy
}
@password_inputbox
.
destroy
@normal_only
.
destroy
@lp_inputbox
.
destroy
@waiting_only
.
destroy
@pvp
.
destroy
@match
.
destroy
@tag
.
destroy
@ocg
.
destroy
@tcg
.
destroy
super
super
end
end
def
update
@roomname_inputbox
.
update
@password_inputbox
.
update
@lp_inputbox
.
update
end
def
name_check
name
=
@roomname_inputbox
.
value
# P#/PM#/M#/T# 的总房名长度允许为13
# 其他情况下如果全英文,那么上限19,否则上限20
# TCG代码自定义房占15个字符
# 一个汉字两个字符,密码算在内
if
@tcg
.
checked
#代码自定义房
max
=
5
max
-=
1
if
name
.
ascii_only?
elsif
@pvp
.
checked
or
@match
.
checked
or
@tag
.
checked
# 去掉那个#占用的
max
=
12
max
-=
1
if
@pvp
.
checked
max
-=
1
if
@match
.
checked
max
-=
1
if
@tag
.
checked
else
max
=
20
max
-=
1
if
name
.
ascii_only?
end
max
-=
@lp_inputbox
.
value
.
size
-
4
if
!
@password_inputbox
.
value
.
empty?
max
-=
1
max
-=
@password_inputbox
.
value
.
encode
(
"GBK"
).
bytesize
end
max
-=
name
.
encode
(
"GBK"
).
bytesize
return
max
>=
0
end
end
end
end
\ No newline at end of file
lib/window_lobbybuttons.rb
View file @
cd38339e
...
@@ -36,7 +36,11 @@ class Window_LobbyButtons < Window_List
...
@@ -36,7 +36,11 @@ class Window_LobbyButtons < Window_List
require_relative
'dialog'
require_relative
'dialog'
Dialog
.
web
"http://my-card.in/login?user[name]=
#{
CGI
.
escape
$game
.
user
.
name
}
&user[password]=
#{
CGI
.
escape
$game
.
password
}
&continue=/topics/1453"
Dialog
.
web
"http://my-card.in/login?user[name]=
#{
CGI
.
escape
$game
.
user
.
name
}
&user[password]=
#{
CGI
.
escape
$game
.
password
}
&continue=/topics/1453"
when
1
#房间筛选
when
1
#房间筛选
if
@filter_window
and
!
@filter_window
.
destroyed?
@filter_window
.
destroy
else
@filter_window
=
Window_Filter
.
new
(
678
,
44
)
end
when
2
#卡组编辑
when
2
#卡组编辑
require_relative
'deck'
require_relative
'deck'
$game
.
class
.
deck_edit
$game
.
class
.
deck_edit
...
...
lib/ygocore/event.rb
View file @
cd38339e
...
@@ -11,6 +11,10 @@ class Game_Event
...
@@ -11,6 +11,10 @@ class Game_Event
AllRooms
.
new
data
.
collect
{
|
room
|
parse_room
(
room
)}
AllRooms
.
new
data
.
collect
{
|
room
|
parse_room
(
room
)}
when
:rooms_update
when
:rooms_update
RoomsUpdate
.
new
data
.
collect
{
|
room
|
parse_room
(
room
)}
RoomsUpdate
.
new
data
.
collect
{
|
room
|
parse_room
(
room
)}
when
:servers
servers
=
data
.
collect
{
|
server
|
parse_server
(
server
)}
$game
.
filter
[
:servers
].
concat
(
servers
-
$game
.
servers
)
AllServers
.
new
servers
#when :newuser
#when :newuser
#NewUser.new parse_user data
#NewUser.new parse_user data
#when :missinguser
#when :missinguser
...
@@ -49,4 +53,7 @@ class Game_Event
...
@@ -49,4 +53,7 @@ class Game_Event
def
self
.
parse_user
(
user
)
def
self
.
parse_user
(
user
)
User
.
new
(
user
[
:id
],
user
[
:name
],
user
[
:certified
])
User
.
new
(
user
[
:id
],
user
[
:name
],
user
[
:certified
])
end
end
def
self
.
parse_server
(
server
)
Server
.
new
(
server
[
:id
],
server
[
:name
],
server
[
:ip
],
server
[
:port
],
server
[
:auth
])
end
end
end
lib/ygocore/game.rb
View file @
cd38339e
#encoding: UTF-8
#encoding: UTF-8
load
'lib/ygocore/window_login.rb'
load
'lib/ygocore/window_login.rb'
require
'eventmachine'
require
'eventmachine'
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
"mycard-server.my-card.in"
,
9997
,
Client
EventMachine
::
connect
"localhost"
,
9997
,
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(I18n.t('lobby.room'), I18n.t('lobby.server'), nickname))
# @@im_room.join(Jabber::JID.new(I18n.t('lobby.room'), I18n.t('lobby.server'), 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
chat
(
chatmessage
)
def
chat
(
chatmessage
)
case
chatmessage
.
channel
case
chatmessage
.
channel
when
:lobby
when
:lobby
send
(
:chat
,
channel: :lobby
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
send
(
:chat
,
channel: :lobby
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
when
User
when
User
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
]
room
.
server_ip
=
$game
.
server
server
=
@filter
[
:servers
].
sample
||
Server
.
new
(
nil
,
""
,
$game
.
server
,
$game
.
port
,
true
)
room
.
server_port
=
$game
.
port
room
.
server_ip
=
server
.
ip
room
.
server_auth
=
true
room
.
server_port
=
server
.
port
if
$game
.
rooms
.
any?
{
|
game_room
|
game_room
.
name
==
room_name
}
room
.
server_auth
=
server
.
auth
Widget_Msgbox
.
new
(
"建立房间"
,
"房间名已存在"
,
:ok
=>
"确定"
)
if
$game
.
rooms
.
any?
{
|
game_room
|
game_room
.
name
==
room_name
}
else
Widget_Msgbox
.
new
(
"建立房间"
,
"房间名已存在"
,
:ok
=>
"确定"
)
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
else
end
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
end
end
end
def
watch
(
room
)
Widget_Msgbox
.
new
(
"加入房间"
,
"游戏已经开始"
,
:ok
=>
"确定"
)
def
watch
(
room
)
end
Widget_Msgbox
.
new
(
"加入房间"
,
"游戏已经开始"
,
:ok
=>
"确定"
)
end
def
join
(
room
)
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
def
join
(
room
)
end
Game_Event
.
push
Game_Event
::
Join
.
new
(
room
)
end
def
refresh
send
(
:refresh
)
def
refresh
end
send
(
:refresh
)
end
def
send
(
header
,
data
=
nil
)
$log
.
info
(
'发送消息'
)
{
{
header:
header
,
data:
data
}
}
def
send
(
header
,
data
=
nil
)
Client
::
MycardChannel
.
push
header:
header
,
data:
data
$log
.
info
(
'发送消息'
)
{
{
header:
header
,
data:
data
}
}
end
Client
::
MycardChannel
.
push
header:
header
,
data:
data
end
def
exit
@recv
.
exit
if
@recv
def
exit
@recv
=
nil
@recv
.
exit
if
@recv
end
@recv
=
nil
end
def
ygocore_path
"ygocore/ygopro_vs.exe"
def
ygocore_path
end
"ygocore/ygopro_vs.exe"
end
def
self
.
register
Dialog
.
web
@@config
[
'register'
]
def
self
.
register
end
Dialog
.
web
@@config
[
'register'
]
end
def
server
@@config
[
'server'
]
def
server
end
@@config
[
'server'
]
end
def
port
@@config
[
'port'
]
def
port
end
@@config
[
'port'
]
end
def
server
=
(
server
)
@@config
[
'server'
]
=
server
def
server
=
(
server
)
end
@@config
[
'server'
]
=
server
end
def
port
=
(
port
)
@@config
[
'port'
]
=
port
def
port
=
(
port
)
end
@@config
[
'port'
]
=
port
end
def
self
.
run_ygocore
(
option
,
image_downloading
=
false
)
if
!
image_downloading
and
!
Update
.
images
.
empty?
def
self
.
run_ygocore
(
option
,
image_downloading
=
false
)
return
Widget_Msgbox
.
new
(
"加入房间"
,
"卡图正在下载中,可能显示不出部分卡图"
,
:ok
=>
"确定"
)
{
run_ygocore
(
option
,
true
)
}
if
!
image_downloading
and
!
Update
.
images
.
empty?
end
return
Widget_Msgbox
.
new
(
"加入房间"
,
"卡图正在下载中,可能显示不出部分卡图"
,
:ok
=>
"确定"
)
{
run_ygocore
(
option
,
true
)
}
path
=
'ygocore/ygopro_vs.exe'
end
Widget_Msgbox
.
new
(
"ygocore"
,
"正在启动ygocore"
)
rescue
nil
path
=
'ygocore/ygopro_vs.exe'
#写入配置文件并运行ygocore
Widget_Msgbox
.
new
(
"ygocore"
,
"正在启动ygocore"
)
rescue
nil
Dir
.
chdir
(
File
.
dirname
(
path
))
do
#写入配置文件并运行ygocore
case
option
Dir
.
chdir
(
File
.
dirname
(
path
))
do
when
Room
case
option
room
=
option
when
Room
room_name
=
if
room
.
ot
!=
0
or
room
.
lp
!=
8000
room
=
option
mode
=
case
when
room
.
match?
then
room_name
=
if
room
.
ot
!=
0
or
room
.
lp
!=
8000
1
;
when
room
.
tag?
then
mode
=
case
when
room
.
match?
then
2
1
;
when
room
.
tag?
then
else
2
0
else
end
0
room_name
=
"
#{
room
.
ot
}#{
mode
}
FFF
#{
room
.
lp
}
,5,1,
#{
room
.
name
}
"
end
elsif
room
.
tag?
room_name
=
"
#{
room
.
ot
}#{
mode
}
FFF
#{
room
.
lp
}
,5,1,
#{
room
.
name
}
"
"T#"
+
room
.
name
elsif
room
.
tag?
elsif
room
.
pvp?
and
room
.
match?
"T#"
+
room
.
name
"PM#"
+
room
.
name
elsif
room
.
pvp?
and
room
.
match?
elsif
room
.
pvp?
"PM#"
+
room
.
name
"P#"
+
room
.
name
elsif
room
.
pvp?
elsif
room
.
match?
"P#"
+
room
.
name
"M#"
+
room
.
name
elsif
room
.
match?
else
"M#"
+
room
.
name
room
.
name
else
end
room
.
name
if
room
.
password
and
!
room
.
password
.
empty?
end
room_name
+=
"$"
+
room
.
password
if
room
.
password
and
!
room
.
password
.
empty?
end
room_name
+=
"$"
+
room
.
password
system_conf
=
{}
end
begin
system_conf
=
{}
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
begin
line
.
force_encoding
"UTF-8"
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
next
if
line
[
0
,
1
]
==
'#'
line
.
force_encoding
"UTF-8"
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
next
if
line
[
0
,
1
]
==
'#'
system_conf
[
field
]
=
contents
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
end
system_conf
[
field
]
=
contents
rescue
end
system_conf
[
'antialias'
]
=
2
rescue
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
system_conf
[
'antialias'
]
=
2
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
end
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
system_conf
[
'nickname'
]
=
$game
.
user
.
name
end
system_conf
[
'nickname'
]
+=
'$'
+
$game
.
password
if
$game
.
password
and
!
$game
.
password
.
empty?
and
room
.
server_auth
system_conf
[
'nickname'
]
=
$game
.
user
.
name
p
room
system_conf
[
'nickname'
]
+=
'$'
+
$game
.
password
if
$game
.
password
and
!
$game
.
password
.
empty?
and
room
.
server_auth
system_conf
[
'lastip'
]
=
room
.
server_ip
p
room
system_conf
[
'lastport'
]
=
room
.
server_port
.
to_s
system_conf
[
'lastip'
]
=
room
.
server_ip
system_conf
[
'roompass'
]
=
room_name
system_conf
[
'lastport'
]
=
room
.
server_port
.
to_s
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
system_conf
[
'roompass'
]
=
room_name
args
=
'-j'
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
when
:replay
args
=
'-j'
args
=
'-r'
when
:replay
when
:deck
args
=
'-r'
args
=
'-d'
when
:deck
when
String
args
=
'-d'
system_conf
=
{}
when
String
begin
system_conf
=
{}
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
begin
line
.
force_encoding
"UTF-8"
IO
.
readlines
(
'system.conf'
).
each
do
|
line
|
next
if
line
[
0
,
1
]
==
'#'
line
.
force_encoding
"UTF-8"
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
next
if
line
[
0
,
1
]
==
'#'
system_conf
[
field
]
=
contents
field
,
contents
=
line
.
chomp
.
split
(
' = '
,
2
)
end
system_conf
[
field
]
=
contents
rescue
end
system_conf
[
'antialias'
]
=
2
rescue
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
system_conf
[
'antialias'
]
=
2
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
system_conf
[
'textfont'
]
=
'c:/windows/fonts/simsun.ttc 14'
end
system_conf
[
'numfont'
]
=
'c:/windows/fonts/arialbd.ttf'
system_conf
[
'lastdeck'
]
=
option
end
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
system_conf
[
'lastdeck'
]
=
option
args
=
'-d'
open
(
'system.conf'
,
'w'
)
{
|
file
|
file
.
write
system_conf
.
collect
{
|
key
,
value
|
"
#{
key
}
=
#{
value
}
"
}.
join
(
"
\n
"
)
}
end
args
=
'-d'
IO
.
popen
(
"ygopro_vs.exe
#{
args
}
"
)
end
WM
.
iconify
rescue
nil
IO
.
popen
(
"ygopro_vs.exe
#{
args
}
"
)
end
WM
.
iconify
rescue
nil
Widget_Msgbox
.
destroy
rescue
nil
end
end
Widget_Msgbox
.
destroy
rescue
nil
end
def
self
.
replay
(
file
,
skip_image_downloading
=
false
)
require
'fileutils'
def
self
.
replay
(
file
,
skip_image_downloading
=
false
)
FileUtils
.
mv
Dir
.
glob
(
'ygocore/replay/*.yrp'
),
'replay/'
require
'fileutils'
FileUtils
.
copy_file
(
file
,
"ygocore/replay/
#{
File
.
basename
(
file
)
}
"
)
FileUtils
.
mv
Dir
.
glob
(
'ygocore/replay/*.yrp'
),
'replay/'
run_ygocore
(
:replay
,
skip_image_downloading
)
FileUtils
.
copy_file
(
file
,
"ygocore/replay/
#{
File
.
basename
(
file
)
}
"
)
end
run_ygocore
(
:replay
,
skip_image_downloading
)
end
private
private
def
self
.
get_announcements
#公告
def
self
.
get_announcements
$config
[
'ygocore'
]
||=
{}
#公告
$config
[
'ygocore'
][
'announcements'
]
||=
[
Announcement
.
new
(
"开放注册"
,
nil
,
nil
)]
$config
[
'ygocore'
]
||=
{}
#Thread.new do
$config
[
'ygocore'
][
'announcements'
]
||=
[
Announcement
.
new
(
"开放注册"
,
nil
,
nil
)]
# begin
#Thread.new do
# open(@@config['api']) do |file|
# begin
# file.set_encoding "GBK"
# open(@@config['api']) do |file|
# announcements = []
# file.set_encoding "GBK"
# file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title, others|
# announcements = []
# announcements << Announcement.new(title, @@config['index'], nil)
# file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title, others|
# end
# announcements << Announcement.new(title, @@config['index'], nil)
# $config['ygocore']['announcements'].replace announcements
# end
# Config.save
# $config['ygocore']['announcements'].replace announcements
# end
# Config.save
# rescue Exception => exception
# end
# $log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
# rescue Exception => exception
# end
# $log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
#end
# end
end
#end
end
module
Client
MycardChannel
=
EM
::
Channel
.
new
module
Client
include
EM
::
P
::
ObjectProtocol
MycardChannel
=
EM
::
Channel
.
new
include
EM
::
P
::
ObjectProtocol
def
post_init
send_object
header: :login
,
data:
{
name:
$game
.
username
,
password:
$game
.
password
}
def
post_init
MycardChannel
.
subscribe
{
|
msg
|
send_object
(
msg
)
}
send_object
header: :login
,
data:
{
name:
$game
.
username
,
password:
$game
.
password
}
end
MycardChannel
.
subscribe
{
|
msg
|
send_object
(
msg
)
}
end
def
receive_object
obj
$log
.
info
(
'收到消息'
)
{
obj
.
inspect
}
def
receive_object
obj
Game_Event
.
push
Game_Event
.
parse
obj
[
:header
],
obj
[
:data
]
$log
.
info
(
'收到消息'
)
{
obj
.
inspect
}
end
Game_Event
.
push
Game_Event
.
parse
obj
[
:header
],
obj
[
:data
]
end
def
unbind
Game_Event
.
push
Game_Event
::
Error
.
new
(
'ygocore'
,
'网络连接中断'
,
true
)
def
unbind
end
Game_Event
.
push
Game_Event
::
Error
.
new
(
'ygocore'
,
'网络连接中断'
,
true
)
end
end
get_announcements
end
get_announcements
end
end
\ No newline at end of file
locales/zh.yml
View file @
cd38339e
...
@@ -16,4 +16,7 @@ en:
...
@@ -16,4 +16,7 @@ en:
newroom
:
"
建立房间"
newroom
:
"
建立房间"
lobby
:
"
大厅"
lobby
:
"
大厅"
filter
:
"
房间筛选"
filter
:
"
房间筛选"
waiting_only
:
"
仅等待中"
normal_only
:
"
仅标准房"
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