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
e77701fc
Commit
e77701fc
authored
Dec 20, 2012
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.8.5, xmpp
parent
ff51a04b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
466 additions
and
459 deletions
+466
-459
Rakefile
Rakefile
+1
-1
lib/main.rb
lib/main.rb
+134
-134
lib/scene_lobby.rb
lib/scene_lobby.rb
+1
-1
lib/update.rb
lib/update.rb
+1
-1
lib/window_chat.rb
lib/window_chat.rb
+175
-175
lib/window_userinfo.rb
lib/window_userinfo.rb
+35
-35
lib/ygocore/event.rb
lib/ygocore/event.rb
+6
-6
lib/ygocore/game.rb
lib/ygocore/game.rb
+113
-106
No files found.
Rakefile
View file @
e77701fc
...
...
@@ -20,7 +20,7 @@ end
spec
=
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
'mycard'
s
.
version
=
'0.8.
4
'
s
.
version
=
'0.8.
5
'
s
.
extra_rdoc_files
=
[
'README.txt'
,
'LICENSE.txt'
]
s
.
summary
=
'a card game'
s
.
description
=
s
.
summary
...
...
lib/main.rb
View file @
e77701fc
#!/usr/bin/env ruby
begin
Windows
=
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
Dir
.
glob
(
'post_update_*.rb'
).
sort
.
each
{
|
file
|
load
file
}
Thread
.
abort_on_exception
=
true
require_relative
'resolution'
require_relative
'announcement'
require_relative
'config'
require_relative
'association'
#i18n
require
'i18n'
require
'locale'
I18n
.
load_path
+=
Dir
[
'locales/*.yml'
]
I18n
::
Backend
::
Simple
.
include
(
I18n
::
Backend
::
Fallbacks
)
#读取配置文件
$config
=
Config
.
load
Config
.
save
#读取命令行参数
log
=
"log.log"
log_level
=
"INFO"
profile
=
nil
ARGV
.
each
do
|
arg
|
arg
=
arg
.
dup
.
force_encoding
(
"UTF-8"
)
arg
.
force_encoding
(
"GBK"
)
unless
arg
.
valid_encoding?
case
arg
when
/--log=(.*)/
log
.
replace
$1
when
/--log-level=(.*)/
log_level
.
replace
$1
when
/--profile=(.*)/
profile
=
$1
when
/^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative
'quickstart'
$scene
=
false
when
/register_association/
Association
.
register
$scene
=
false
end
end
unless
$scene
==
false
#加载文件
require
'logger'
require
'sdl'
include
SDL
require_relative
'dialog'
require_relative
'graphics'
require_relative
'window'
require_relative
'widget_msgbox'
#日志
if
log
==
"STDOUT"
#调试用
log
=
STDOUT
end
$log
=
Logger
.
new
(
log
)
$log
.
level
=
Logger
.
const_get
log_level
#性能分析
if
profile
if
profile
==
"STDOUT"
profile
=
STDOUT
else
profile
=
open
(
profile
,
'w'
)
end
require
'profiler'
RubyVM
::
InstructionSequence
.
compile_option
=
{
:trace_instruction
=>
true
,
:specialized_instruction
=>
false
}
Profiler__
::
start_profile
end
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPACTIVE
=
4
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
.
init
(
INIT_VIDEO
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
TTF
.
init
#声音
begin
SDL
.
init
(
INIT_AUDIO
)
Mixer
.
open
(
Mixer
::
DEFAULT_FREQUENCY
,
Mixer
::
DEFAULT_FORMAT
,
Mixer
::
DEFAULT_CHANNELS
,
1536
)
Mixer
.
set_volume_music
(
60
)
rescue
nil
end
#标题场景
require_relative
'scene_title'
$scene
=
Scene_Title
.
new
#自动更新, 加载放到SDL前面会崩, 原因不明
require_relative
'update'
Update
.
start
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
#文件关联
Association
.
start
#初始化完毕
$log
.
info
(
"main"
)
{
"初始化成功"
}
end
rescue
Exception
=>
exception
open
(
'error-程序出错请到论坛反馈.txt'
,
'w'
)
{
|
f
|
f
.
write
[
exception
.
inspect
,
*
exception
.
backtrace
].
join
(
"
\n
"
)
}
$scene
=
false
end
#主循环
begin
$scene
.
main
while
$scene
rescue
Exception
=>
exception
exception
.
backtrace
.
each
{
|
backtrace
|
break
if
backtrace
=~
/^(.*)\.rb:\d+:in `.*'"$/
}
#由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log
.
fatal
(
$1
)
{
[
exception
.
inspect
,
*
exception
.
backtrace
].
collect
{
|
str
|
str
.
force_encoding
(
"UTF-8"
)
}.
join
(
"
\n
"
)
}
$game
.
exit
if
$game
require_relative
'scene_error'
$scene
=
Scene_Error
.
new
retry
ensure
if
profile
Profiler__
::
print_profile
(
profile
)
profile
.
close
end
$log
.
close
rescue
nil
#!/usr/bin/env ruby
begin
Windows
=
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
Dir
.
glob
(
'post_update_*.rb'
).
sort
.
each
{
|
file
|
load
file
}
Thread
.
abort_on_exception
=
true
require_relative
'resolution'
require_relative
'announcement'
require_relative
'config'
require_relative
'association'
#i18n
require
'i18n'
require
'locale'
I18n
.
load_path
+=
Dir
[
'locales/*.yml'
]
I18n
::
Backend
::
Simple
.
include
(
I18n
::
Backend
::
Fallbacks
)
#读取配置文件
$config
=
Config
.
load
Config
.
save
#读取命令行参数
log
=
"log.log"
log_level
=
"INFO"
profile
=
nil
ARGV
.
each
do
|
arg
|
arg
=
arg
.
dup
.
force_encoding
(
"UTF-8"
)
arg
.
force_encoding
(
"GBK"
)
unless
arg
.
valid_encoding?
case
arg
when
/--log=(.*)/
log
.
replace
$1
when
/--log-level=(.*)/
log_level
.
replace
$1
when
/--profile=(.*)/
profile
=
$1
when
/^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative
'quickstart'
$scene
=
false
when
/register_association/
Association
.
register
$scene
=
false
end
end
unless
$scene
==
false
#加载文件
require
'logger'
require
'sdl'
include
SDL
require_relative
'dialog'
require_relative
'graphics'
require_relative
'window'
require_relative
'widget_msgbox'
#日志
if
log
==
"STDOUT"
#调试用
log
=
STDOUT
end
$log
=
Logger
.
new
(
log
,
1
,
1024000
)
$log
.
level
=
Logger
.
const_get
log_level
#性能分析
if
profile
if
profile
==
"STDOUT"
profile
=
STDOUT
else
profile
=
open
(
profile
,
'w'
)
end
require
'profiler'
RubyVM
::
InstructionSequence
.
compile_option
=
{
:trace_instruction
=>
true
,
:specialized_instruction
=>
false
}
Profiler__
::
start_profile
end
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPACTIVE
=
4
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
.
init
(
INIT_VIDEO
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
TTF
.
init
#声音
begin
SDL
.
init
(
INIT_AUDIO
)
Mixer
.
open
(
Mixer
::
DEFAULT_FREQUENCY
,
Mixer
::
DEFAULT_FORMAT
,
Mixer
::
DEFAULT_CHANNELS
,
1536
)
Mixer
.
set_volume_music
(
60
)
rescue
nil
end
#标题场景
require_relative
'scene_title'
$scene
=
Scene_Title
.
new
#自动更新, 加载放到SDL前面会崩, 原因不明
require_relative
'update'
Update
.
start
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
#文件关联
Association
.
start
#初始化完毕
$log
.
info
(
"main"
)
{
"初始化成功"
}
end
rescue
Exception
=>
exception
open
(
'error-程序出错请到论坛反馈.txt'
,
'w'
)
{
|
f
|
f
.
write
[
exception
.
inspect
,
*
exception
.
backtrace
].
join
(
"
\n
"
)
}
$scene
=
false
end
#主循环
begin
$scene
.
main
while
$scene
rescue
Exception
=>
exception
exception
.
backtrace
.
each
{
|
backtrace
|
break
if
backtrace
=~
/^(.*)\.rb:\d+:in `.*'"$/
}
#由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log
.
fatal
(
$1
)
{
[
exception
.
inspect
,
*
exception
.
backtrace
].
collect
{
|
str
|
str
.
force_encoding
(
"UTF-8"
)
}.
join
(
"
\n
"
)
}
$game
.
exit
if
$game
require_relative
'scene_error'
$scene
=
Scene_Error
.
new
retry
ensure
if
profile
Profiler__
::
print_profile
(
profile
)
profile
.
close
end
$log
.
close
rescue
nil
end
\ No newline at end of file
lib/scene_lobby.rb
View file @
e77701fc
...
...
@@ -66,7 +66,7 @@ class Scene_Lobby < Scene
when
Game_Event
::
AllUsers
@userlist
.
items
=
$game
.
users
when
Game_Event
::
AllRooms
,
Game_Event
::
AllServers
@roomlist
.
items
=
p
$game
.
rooms
.
find_all
{
|
room
|
@roomlist
.
items
=
$game
.
rooms
.
find_all
{
|
room
|
$game
.
filter
[
:servers
].
include?
(
room
.
server
)
and
$game
.
filter
[
:waiting_only
]
?
(
room
.
status
==
:
wait
)
:
true
and
$game
.
filter
[
:normal_only
]
?
(
!
room
.
tag?
&&
(
room
.
ot
==
0
)
&&
(
room
.
lp
=
8000
))
:
true
...
...
lib/update.rb
View file @
e77701fc
...
...
@@ -2,7 +2,7 @@ require 'open-uri'
require
"fileutils"
require_relative
'card'
module
Update
Version
=
'0.8.
4
'
Version
=
'0.8.
5
'
URL
=
"http://my-card.in/mycard/update.json?version=
#{
Version
}
"
class
<<
self
attr_reader
:thumbnails
,
:images
,
:status
...
...
lib/window_chat.rb
View file @
e77701fc
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
# title
#==============================================================================
require_relative
'widget_scrollbar'
require_relative
'widget_inputbox'
require_relative
'chatmessage'
require_relative
'window_scrollable'
class
Window_Chat
<
Window_Scrollable
WLH
=
16
def
initialize
(
x
,
y
,
width
,
height
)
super
(
x
,
y
,
width
,
height
)
if
@width
>
600
#判断大厅还是房间,这个判据比较囧,待优化
@chat_background
=
Surface
.
load
(
"graphics/system/chat.png"
).
display_format
else
@chat_background
=
Surface
.
load
(
"graphics/system/chat_room.png"
).
display_format
end
@background
=
@contents
.
copy_rect
(
0
,
0
,
@contents
.
w
,
@contents
.
h
)
#new而已。。
@background
.
fill_rect
(
0
,
0
,
@background
.
w
,
@background
.
h
,
0xFFb2cefe
)
@background
.
put
(
@chat_background
,
0
,
31
-
4
)
@tab
=
Surface
.
load
"graphics/system/tab.png"
@chat_input
=
Widget_InputBox
.
new
(
@x
+
8
,
@y
+
@height
-
24
-
10
,
@width
-
14
,
24
)
do
|
key
|
case
key
when
:ENTER
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
)
# if $game.show_chat_self
true
end
end
end
@chat_input
.
refresh
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
14
)
@scrollbar
=
Widget_ScrollBar
.
new
(
self
,
@x
+
@width
-
20
-
8
,
@y
+
31
+
3
,
@height
-
68
)
@page_size
=
(
@height
-
68
)
/
WLH
@@list
||=
{}
@list_splited
=
{}
@@list
.
each_pair
do
|
channel
,
chatmessages
|
chatmessages
.
each
do
|
chatmessage
|
add_split
(
chatmessage
)
end
end
@channels
=
[]
self
.
channel
=
:lobby
end
def
add
(
chatmessage
)
@@list
[
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
)
if
chatmessage
.
channel
==
@channel
@scroll
=
[
@items
.
size
-
@page_size
,
0
].
max
if
scroll_bottom
refresh
end
end
def
add_split
(
chatmessage
)
@list_splited
[
chatmessage
.
channel
]
||=
[]
@list_splited
[
chatmessage
.
channel
]
<<
[
chatmessage
,
""
]
width
=
name_width
(
chatmessage
)
line
=
0
chatmessage
.
message
.
each_char
do
|
char
|
if
char
==
"
\n
"
line
+=
1
width
=
0
@list_splited
[
chatmessage
.
channel
]
<<
[
chatmessage
.
message_color
,
""
]
else
char_width
=
@font
.
text_size
(
char
)[
0
]
if
char_width
+
width
>
@width
-
14
-
20
line
+=
1
width
=
char_width
@list_splited
[
chatmessage
.
channel
]
<<
[
chatmessage
.
message_color
,
char
]
else
@list_splited
[
chatmessage
.
channel
].
last
[
1
]
<<
char
width
+=
char_width
end
end
end
end
def
mousemoved
(
x
,
y
)
if
y
-
@y
<
31
and
(
x
-
@x
)
<
@channels
.
size
*
100
self
.
index
=
@channels
[(
x
-
@x
)
/
100
]
else
self
.
index
=
nil
end
end
def
clicked
case
@index
when
nil
when
Integer
else
self
.
channel
=
@index
end
end
def
channel
=
(
channel
)
return
if
@channel
==
channel
@channel
=
channel
@channels
<<
channel
unless
@channels
.
include?
channel
@list_splited
[
channel
]
||=
[]
@items
=
@list_splited
[
channel
]
@scroll
=
[
@items
.
size
-
@page_size
,
0
].
max
refresh
end
def
draw_item
(
index
,
status
=
0
)
case
index
when
nil
when
Integer
#描绘聊天消息
draw_item_chatmessage
(
index
,
status
)
else
#描绘频道标签
draw_item_channel
(
index
,
status
)
end
end
def
draw_item_channel
(
channel
,
status
)
index
=
@channels
.
index
(
channel
)
Surface
.
blit
(
@tab
,
0
,
@channel
==
channel
?
0
:
31
,
100
,
31
,
@contents
,
index
*
100
+
3
,
0
)
channel_name
=
ChatMessage
.
channel_name
channel
x
=
index
*
100
+
(
100
-
@font
.
text_size
(
channel_name
)[
0
])
/
2
draw_stroked_text
(
channel_name
,
x
,
8
,
1
,
@font
,
[
255
,
255
,
255
],
ChatMessage
.
channel_color
(
channel
))
end
def
draw_item_chatmessage
(
index
,
status
)
x
,
y
=
item_rect_chatmessage
(
index
)
chatmessage
,
message
=
@items
[
index
]
if
chatmessage
.
is_a?
ChatMessage
@font
.
draw_blended_utf8
(
@contents
,
chatmessage
.
user
.
name
+
':'
,
x
,
y
,
*
chatmessage
.
name_color
)
if
chatmessage
.
name_visible?
@font
.
draw_blended_utf8
(
@contents
,
message
,
x
+
name_width
(
chatmessage
),
y
,
*
chatmessage
.
message_color
)
unless
chatmessage
.
message
.
empty?
else
@font
.
draw_blended_utf8
(
@contents
,
message
,
x
,
y
,
*
chatmessage
)
unless
message
.
empty?
end
end
def
item_rect
(
index
)
case
index
when
nil
when
Integer
#描绘聊天消息
item_rect_chatmessage
(
index
)
else
#描绘频道标签
item_rect_channel
(
index
)
end
end
def
item_rect_channel
(
channel
)
[
@channels
.
index
(
channel
)
*
100
+
3
,
0
,
100
,
31
]
end
def
item_rect_chatmessage
(
index
)
[
8
,
(
index
-
@scroll
)
*
WLH
+
31
+
3
,
@width
,
self
.
class
::
WLH
]
end
def
refresh
super
@channels
.
each
{
|
channel
|
draw_item_channel
(
channel
,
@index
==
channel
)}
end
def
name_width
(
chatmessage
)
chatmessage
.
name_visible?
?
@font
.
text_size
(
chatmessage
.
user
.
name
+
':'
)[
0
]
:
0
end
def
index_legal?
(
index
)
case
index
when
nil
,
Integer
super
else
@channels
.
include?
index
end
end
def
scroll_up
self
.
scroll
-=
1
end
def
scroll_down
self
.
scroll
+=
1
end
def
update
@chat_input
.
update
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
# title
#==============================================================================
require_relative
'widget_scrollbar'
require_relative
'widget_inputbox'
require_relative
'chatmessage'
require_relative
'window_scrollable'
class
Window_Chat
<
Window_Scrollable
WLH
=
16
def
initialize
(
x
,
y
,
width
,
height
)
super
(
x
,
y
,
width
,
height
)
if
@width
>
600
#判断大厅还是房间,这个判据比较囧,待优化
@chat_background
=
Surface
.
load
(
"graphics/system/chat.png"
).
display_format
else
@chat_background
=
Surface
.
load
(
"graphics/system/chat_room.png"
).
display_format
end
@background
=
@contents
.
copy_rect
(
0
,
0
,
@contents
.
w
,
@contents
.
h
)
#new而已。。
@background
.
fill_rect
(
0
,
0
,
@background
.
w
,
@background
.
h
,
0xFFb2cefe
)
@background
.
put
(
@chat_background
,
0
,
31
-
4
)
@tab
=
Surface
.
load
"graphics/system/tab.png"
@chat_input
=
Widget_InputBox
.
new
(
@x
+
8
,
@y
+
@height
-
24
-
10
,
@width
-
14
,
24
)
do
|
key
|
case
key
when
:ENTER
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
)
if
!
$game
.
is_a?
Ygocore
true
end
end
end
@chat_input
.
refresh
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
14
)
@scrollbar
=
Widget_ScrollBar
.
new
(
self
,
@x
+
@width
-
20
-
8
,
@y
+
31
+
3
,
@height
-
68
)
@page_size
=
(
@height
-
68
)
/
WLH
@@list
||=
{}
@list_splited
=
{}
@@list
.
each_pair
do
|
channel
,
chatmessages
|
chatmessages
.
each
do
|
chatmessage
|
add_split
(
chatmessage
)
end
end
@channels
=
[]
self
.
channel
=
:lobby
end
def
add
(
chatmessage
)
@@list
[
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
)
if
chatmessage
.
channel
==
@channel
@scroll
=
[
@items
.
size
-
@page_size
,
0
].
max
if
scroll_bottom
refresh
end
end
def
add_split
(
chatmessage
)
@list_splited
[
chatmessage
.
channel
]
||=
[]
@list_splited
[
chatmessage
.
channel
]
<<
[
chatmessage
,
""
]
width
=
name_width
(
chatmessage
)
line
=
0
chatmessage
.
message
.
each_char
do
|
char
|
if
char
==
"
\n
"
line
+=
1
width
=
0
@list_splited
[
chatmessage
.
channel
]
<<
[
chatmessage
.
message_color
,
""
]
else
char_width
=
@font
.
text_size
(
char
)[
0
]
if
char_width
+
width
>
@width
-
14
-
20
line
+=
1
width
=
char_width
@list_splited
[
chatmessage
.
channel
]
<<
[
chatmessage
.
message_color
,
char
]
else
@list_splited
[
chatmessage
.
channel
].
last
[
1
]
<<
char
width
+=
char_width
end
end
end
end
def
mousemoved
(
x
,
y
)
if
y
-
@y
<
31
and
(
x
-
@x
)
<
@channels
.
size
*
100
self
.
index
=
@channels
[(
x
-
@x
)
/
100
]
else
self
.
index
=
nil
end
end
def
clicked
case
@index
when
nil
when
Integer
else
self
.
channel
=
@index
end
end
def
channel
=
(
channel
)
return
if
@channel
==
channel
@channel
=
channel
@channels
<<
channel
unless
@channels
.
include?
channel
@list_splited
[
channel
]
||=
[]
@items
=
@list_splited
[
channel
]
@scroll
=
[
@items
.
size
-
@page_size
,
0
].
max
refresh
end
def
draw_item
(
index
,
status
=
0
)
case
index
when
nil
when
Integer
#描绘聊天消息
draw_item_chatmessage
(
index
,
status
)
else
#描绘频道标签
draw_item_channel
(
index
,
status
)
end
end
def
draw_item_channel
(
channel
,
status
)
index
=
@channels
.
index
(
channel
)
Surface
.
blit
(
@tab
,
0
,
@channel
==
channel
?
0
:
31
,
100
,
31
,
@contents
,
index
*
100
+
3
,
0
)
channel_name
=
ChatMessage
.
channel_name
channel
x
=
index
*
100
+
(
100
-
@font
.
text_size
(
channel_name
)[
0
])
/
2
draw_stroked_text
(
channel_name
,
x
,
8
,
1
,
@font
,
[
255
,
255
,
255
],
ChatMessage
.
channel_color
(
channel
))
end
def
draw_item_chatmessage
(
index
,
status
)
x
,
y
=
item_rect_chatmessage
(
index
)
chatmessage
,
message
=
@items
[
index
]
if
chatmessage
.
is_a?
ChatMessage
@font
.
draw_blended_utf8
(
@contents
,
chatmessage
.
user
.
name
+
':'
,
x
,
y
,
*
chatmessage
.
name_color
)
if
chatmessage
.
name_visible?
@font
.
draw_blended_utf8
(
@contents
,
message
,
x
+
name_width
(
chatmessage
),
y
,
*
chatmessage
.
message_color
)
unless
chatmessage
.
message
.
empty?
else
@font
.
draw_blended_utf8
(
@contents
,
message
,
x
,
y
,
*
chatmessage
)
unless
message
.
empty?
end
end
def
item_rect
(
index
)
case
index
when
nil
when
Integer
#描绘聊天消息
item_rect_chatmessage
(
index
)
else
#描绘频道标签
item_rect_channel
(
index
)
end
end
def
item_rect_channel
(
channel
)
[
@channels
.
index
(
channel
)
*
100
+
3
,
0
,
100
,
31
]
end
def
item_rect_chatmessage
(
index
)
[
8
,
(
index
-
@scroll
)
*
WLH
+
31
+
3
,
@width
,
self
.
class
::
WLH
]
end
def
refresh
super
@channels
.
each
{
|
channel
|
draw_item_channel
(
channel
,
@index
==
channel
)}
end
def
name_width
(
chatmessage
)
chatmessage
.
name_visible?
?
@font
.
text_size
(
chatmessage
.
user
.
name
+
':'
)[
0
]
:
0
end
def
index_legal?
(
index
)
case
index
when
nil
,
Integer
super
else
@channels
.
include?
index
end
end
def
scroll_up
self
.
scroll
-=
1
end
def
scroll_down
self
.
scroll
+=
1
end
def
update
@chat_input
.
update
end
end
\ No newline at end of file
lib/window_userinfo.rb
View file @
e77701fc
#encoding: UTF-8
#==============================================================================
# Window_UserInfo
#------------------------------------------------------------------------------
# 游戏大厅显示用户信息的类
#==============================================================================
class
Window_UserInfo
<
Window
def
initialize
(
x
,
y
,
user
)
@avatar_boarder
=
Surface
.
load
(
"graphics/lobby/avatar_boader.png"
)
super
(
x
,
y
,
280
,
144
)
@font
=
TTF
.
open
(
'fonts/wqy-microhei.ttc'
,
16
)
@user
=
user
@background
=
Surface
.
load
(
"graphics/lobby/userinfo.png"
).
display_format
refresh
end
def
refresh
@contents
.
put
(
@background
,
0
,
0
)
@thread
=
@user
.
avatar
(
:middle
)
do
|
avatar
|
clear
(
0
,
0
,
@avatar_boarder
.
w
,
@avatar_boarder
.
h
)
@contents
.
put
(
avatar
,
12
,
12
)
@contents
.
put
(
@avatar_boarder
,
0
,
0
)
end
@font
.
draw_blended_utf8
(
@contents
,
@user
.
name
,
160
,
12
,
0x00
,
0x00
,
0x00
)
unless
@user
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
"id:
#{
@user
.
id
}
"
,
160
,
12
+
16
*
2
,
0x00
,
0x00
,
0x00
)
@font
.
draw_blended_utf8
(
@contents
,
"Lv:
#{
@user
.
level
}
"
,
160
,
12
+
16
*
3
,
0x00
,
0x00
,
0x00
)
if
@user
.
respond_to?
:level
and
@user
.
level
#TODO:规范化,level是iduel专属的,但是又不太想让iduel来重定义这个window
@font
.
draw_blended_utf8
(
@contents
,
"经验:
#{
@user
.
exp
}
"
,
160
,
12
+
16
*
4
,
0x00
,
0x00
,
0x00
)
if
@user
.
respond_to?
:exp
and
@user
.
exp
end
def
dispose
@thread
.
exit
super
end
end
#encoding: UTF-8
#==============================================================================
# Window_UserInfo
#------------------------------------------------------------------------------
# 游戏大厅显示用户信息的类
#==============================================================================
class
Window_UserInfo
<
Window
def
initialize
(
x
,
y
,
user
)
@avatar_boarder
=
Surface
.
load
(
"graphics/lobby/avatar_boader.png"
)
super
(
x
,
y
,
280
,
144
)
@font
=
TTF
.
open
(
'fonts/wqy-microhei.ttc'
,
16
)
@user
=
user
@background
=
Surface
.
load
(
"graphics/lobby/userinfo.png"
).
display_format
refresh
end
def
refresh
@contents
.
put
(
@background
,
0
,
0
)
@thread
=
@user
.
avatar
(
:middle
)
do
|
avatar
|
clear
(
0
,
0
,
@avatar_boarder
.
w
,
@avatar_boarder
.
h
)
@contents
.
put
(
avatar
,
12
,
12
)
@contents
.
put
(
@avatar_boarder
,
0
,
0
)
end
@font
.
draw_blended_utf8
(
@contents
,
@user
.
name
,
160
,
12
,
0x00
,
0x00
,
0x00
)
unless
@user
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
@user
.
id
.
to_s
,
160
,
12
+
16
*
2
,
0x00
,
0x00
,
0x00
)
unless
@user
.
id
.
to_s
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
"Lv:
#{
@user
.
level
}
"
,
160
,
12
+
16
*
3
,
0x00
,
0x00
,
0x00
)
if
@user
.
respond_to?
:level
and
@user
.
level
#TODO:规范化,level是iduel专属的,但是又不太想让iduel来重定义这个window
@font
.
draw_blended_utf8
(
@contents
,
"经验:
#{
@user
.
exp
}
"
,
160
,
12
+
16
*
4
,
0x00
,
0x00
,
0x00
)
if
@user
.
respond_to?
:exp
and
@user
.
exp
end
def
dispose
@thread
.
exit
super
end
end
lib/ygocore/event.rb
View file @
e77701fc
class
Game_Event
def
self
.
parse
(
header
,
data
)
case
header
when
:login
if
data
Login
.
new
parse_user
data
else
Error
.
new
(
'登录'
,
'用户名或密码错误'
)
end
#
when :login
#
if data
#
Login.new parse_user data
#
else
#
Error.new('登录', '用户名或密码错误')
#
end
#when :rooms
#AllRooms.new data.collect{|room|parse_room(room)}
#when :rooms_update
...
...
lib/ygocore/game.rb
View file @
e77701fc
...
...
@@ -17,8 +17,8 @@ class Ygocore < Game
load
'lib/ygocore/room.rb'
load
'lib/ygocore/scene_lobby.rb'
require
'json'
#
require 'xmpp4r/client'
#
require 'xmpp4r/muc'
require
'xmpp4r/client'
require
'xmpp4r/muc'
end
def
refresh_interval
...
...
@@ -28,53 +28,54 @@ class Ygocore < Game
def
login
(
username
,
password
)
@username
=
username
@password
=
password
#@nickname_conflict = []
#@@im = Jabber::Client.new(Jabber::JID::new(@username, 'my-card.in', 'mycard'))
#@@im_room = Jabber::MUC::MUCClient.new(@@im)
#Jabber.debug = true
#@@im.on_exception do |exception, c, where|
# $log.error('聊天出错') { [exception, c, where] }
# if where == :close
# Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天连接断开, 可能是网络问题或帐号从其他地点登录')))
# else
# Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天连接断开, 5秒后重新连接')))
# sleep 5
# im_connect
# end
#end
#@@im_room.add_message_callback do |m|
# 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('收到聊天消息') { $! }
#end
#@@im_room.add_private_message_callback do |m|
# if m.body #忽略无消息的正在输入等内容
# 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('收到私聊消息') { $! }
# end
#end
#@@im_room.add_join_callback do |m|
# Game_Event.push Game_Event::NewUser.new User.new m.from.resource.to_sym, m.from.resource
#end
#@@im_room.add_leave_callback do |m|
# Game_Event.push Game_Event::MissingUser.new User.new m.from.resource.to_sym, m.from.resource
#end
@nickname_conflict
=
[]
@@im
=
Jabber
::
Client
.
new
(
Jabber
::
JID
::
new
(
@username
,
'my-card.in'
,
'mycard'
))
@@im_room
=
Jabber
::
MUC
::
MUCClient
.
new
(
@@im
)
Jabber
.
logger
=
$log
Jabber
.
debug
=
true
@@im
.
on_exception
do
|
exception
,
c
,
where
|
$log
.
error
(
'聊天出错'
)
{
[
exception
,
c
,
where
]
}
if
where
==
:close
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天服务连接中断'
)))
else
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天服务连接中断, 5秒后重新连接'
)))
sleep
5
im_connect
end
end
@@im_room
.
add_message_callback
do
|
m
|
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
(
'收到聊天消息'
)
{
$!
}
end
@@im_room
.
add_private_message_callback
do
|
m
|
if
m
.
body
#忽略无消息的正在输入等内容
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
(
'收到私聊消息'
)
{
$!
}
end
end
@@im_room
.
add_join_callback
do
|
m
|
Game_Event
.
push
Game_Event
::
NewUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
end
@@im_room
.
add_leave_callback
do
|
m
|
Game_Event
.
push
Game_Event
::
MissingUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
end
connect
#
im_connect
im_connect
end
#
def nickname
#
return @nickname if @nickname
#
if @nickname_conflict.include? @username
#
1.upto(9) do |i|
#
result = "#{@username}-#{i}"
#
return result unless @nickname_conflict.include? result
#
end
#
raise 'can`t get available nickname'
#
else
#
@username
#
end
#
end
def
nickname
return
@nickname
if
@nickname
if
@nickname_conflict
.
include?
@username
1
.
upto
(
9
)
do
|
i
|
result
=
"
#{
@username
}
-
#{
i
}
"
return
result
unless
@nickname_conflict
.
include?
result
end
raise
'can`t get available nickname'
else
@username
end
end
def
connect
@recv
=
Thread
.
new
do
...
...
@@ -88,7 +89,7 @@ class Ygocore < Game
Game_Event
.
push
Game_Event
::
Error
.
new
(
'ygocore'
,
'读取服务器列表失败'
,
true
)
end
EventMachine
::
connect
"mycard-server.my-card.in"
,
9997
,
Client
#
EventMachine::connect "mycard-server.my-card.in", 9997, Client
ws
=
WebSocket
::
EventMachine
::
Client
.
connect
(
:host
=>
"mycard-server.my-card.in"
,
:port
=>
9998
);
ws
.
onmessage
do
|
msg
,
type
|
$log
.
info
(
'收到websocket消息'
){
msg
.
force_encoding
(
"UTF-8"
)}
...
...
@@ -107,52 +108,58 @@ class Ygocore < Game
end
end
#def im_connect
# Thread.new {
# begin
# @@im.allow_tls = false
# @@im.use_ssl = true
# @@im.connect('my-card.in', 5223)
# #ruby19/windows下 使用tls连接时会卡住
#
# @@im.auth(@password)
# @@im.send(Jabber::Presence.new.set_type(:available))
# begin
# nickname = nickname()
# @@im_room.join(Jabber::JID.new(I18n.t('lobby.room'), I18n.t('lobby.server'), nickname))
# rescue Jabber::ServerError => exception
# if exception.error.error == 'conflict'
# @nickname_conflict << nickname
# retry
# end
# end
# Game_Event.push Game_Event::AllUsers.new @@im_room.roster.keys.collect { |nick| User.new(nick.to_sym, nick) } rescue p $!
# rescue StandardError => exception
# $log.error('聊天连接出错') { exception }
# Game_Event.push(Game_Event::Chat.new(ChatMessage.new(User.new(:system, 'System'), '聊天服务器连接失败')))
# end
# }
#end
def
im_connect
Thread
.
new
{
begin
@@im
.
allow_tls
=
false
@@im
.
use_ssl
=
true
@@im
.
connect
(
'chat.my-card.in'
,
5223
)
#ruby19/windows下 使用tls连接时会卡住
begin
@@im
.
auth
(
@password
)
rescue
Jabber
::
ClientAuthenticationFailure
Game_Event
.
push
Game_Event
::
Error
.
new
(
'登录'
,
'用户名或密码错误'
)
Thread
.
exit
end
Game_Event
.
push
Game_Event
::
Login
.
new
User
.
new
(
@@im
.
jid
,
@username
,
true
)
@@im
.
send
(
Jabber
::
Presence
.
new
.
set_type
(
:available
))
begin
nickname
=
nickname
()
#@@im_room.join(Jabber::JID.new(I18n.t('lobby.room'), I18n.t('lobby.server'), nickname))
@@im_room
.
join
(
Jabber
::
JID
.
new
(
'mycard'
,
'conference.my-card.in'
,
nickname
))
rescue
Jabber
::
ServerError
=>
exception
if
exception
.
error
.
error
==
'conflict'
@nickname_conflict
<<
nickname
retry
end
end
Game_Event
.
push
Game_Event
::
AllUsers
.
new
@@im_room
.
roster
.
keys
.
collect
{
|
nick
|
User
.
new
(
nick
.
to_sym
,
nick
)
}
rescue
p
$!
rescue
StandardError
=>
exception
$log
.
error
(
'聊天连接出错'
)
{
exception
}
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天服务器连接失败'
)))
end
}
end
#def chat(chatmessage)
# case chatmessage.channel
# when :lobby
# msg = Jabber::Message::new(nil, chatmessage.message)
# @@im_room.send msg
# when User
# msg = Jabber::Message::new(nil, chatmessage.message)
# @@im_room.send msg, chatmessage.channel.id
# #send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
# end
#end
def
chat
(
chatmessage
)
case
chatmessage
.
channel
when
:lobby
send
(
:chat
,
channel: :lobby
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
msg
=
Jabber
::
Message
::
new
(
nil
,
chatmessage
.
message
)
@@im_room
.
send
msg
when
User
send
(
:chat
,
channel:
chatmessage
.
channel
.
id
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
msg
=
Jabber
::
Message
::
new
(
nil
,
chatmessage
.
message
)
@@im_room
.
send
msg
,
chatmessage
.
channel
.
id
#send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
end
end
#def chat(chatmessage)
# case chatmessage.channel
# when :lobby
# send(:chat, channel: :lobby, message: chatmessage.message, time: chatmessage.time)
# when User
# send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
# end
#end
def
host
(
room_name
,
room_config
)
room
=
Room
.
new
(
0
,
room_name
)
...
...
@@ -185,8 +192,8 @@ class Ygocore < Game
end
def
send
(
header
,
data
=
nil
)
$log
.
info
(
'发送消息'
)
{
{
header:
header
,
data:
data
}
}
Client
::
MycardChannel
.
push
header:
header
,
data:
data
#
$log.info('发送消息') { {header: header, data: data} }
#
Client::MycardChannel.push header: header, data: data
end
def
exit
...
...
@@ -330,24 +337,24 @@ class Ygocore < Game
#end
end
module
Client
MycardChannel
=
EM
::
Channel
.
new
include
EM
::
P
::
ObjectProtocol
def
post_init
send_object
header: :login
,
data:
{
name:
$game
.
username
,
password:
$game
.
password
}
MycardChannel
.
subscribe
{
|
msg
|
send_object
(
msg
)
}
end
def
receive_object
obj
$log
.
info
(
'收到消息'
)
{
obj
.
inspect
}
Game_Event
.
push
Game_Event
.
parse
obj
[
:header
],
obj
[
:data
]
end
def
unbind
Game_Event
.
push
Game_Event
::
Error
.
new
(
'ygocore'
,
'网络连接中断'
,
true
)
end
end
#
module Client
#
MycardChannel = EM::Channel.new
#
include EM::P::ObjectProtocol
#
#
def post_init
#
send_object header: :login, data: {name: $game.username, password: $game.password}
#
MycardChannel.subscribe { |msg| send_object(msg) }
#
end
#
#
def receive_object obj
#
$log.info('收到消息') { obj.inspect }
#
Game_Event.push Game_Event.parse obj[:header], obj[:data]
#
end
#
#
def unbind
#
Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true)
#
end
#
end
get_announcements
end
...
...
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