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
17ae1837
Commit
17ae1837
authored
Dec 05, 2012
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0.8.1
parent
1e26242c
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
294 additions
and
185 deletions
+294
-185
lib/config.rb
lib/config.rb
+3
-0
lib/game_event.rb
lib/game_event.rb
+38
-12
lib/iduel/user.rb
lib/iduel/user.rb
+2
-2
lib/main.rb
lib/main.rb
+25
-18
lib/quickstart.rb
lib/quickstart.rb
+5
-3
lib/room.rb
lib/room.rb
+4
-1
lib/update.rb
lib/update.rb
+1
-1
lib/widget_msgbox.rb
lib/widget_msgbox.rb
+1
-1
lib/window.rb
lib/window.rb
+47
-27
lib/window_chat.rb
lib/window_chat.rb
+1
-1
lib/window_config.rb
lib/window_config.rb
+2
-2
lib/window_lobbybuttons.rb
lib/window_lobbybuttons.rb
+3
-3
lib/window_login.rb
lib/window_login.rb
+7
-7
lib/window_roomlist.rb
lib/window_roomlist.rb
+2
-3
lib/ygocore/event.rb
lib/ygocore/event.rb
+15
-20
lib/ygocore/game.rb
lib/ygocore/game.rb
+133
-80
lib/ygocore/room.rb
lib/ygocore/room.rb
+1
-0
lib/ygocore/server.yml
lib/ygocore/server.yml
+2
-2
lib/ygocore/user.rb
lib/ygocore/user.rb
+2
-2
No files found.
lib/config.rb
View file @
17ae1837
...
@@ -9,6 +9,9 @@ module Config
...
@@ -9,6 +9,9 @@ module Config
config
[
'bgm'
]
=
true
if
config
[
'bgm'
].
nil?
config
[
'bgm'
]
=
true
if
config
[
'bgm'
].
nil?
config
[
'screen'
]
||=
{}
config
[
'screen'
]
||=
{}
config
[
'screen'
][
'width'
],
config
[
'screen'
][
'height'
]
=
Resolution
.
default
unless
Resolution
.
all
.
include?
[
config
[
'screen'
][
'width'
],
config
[
'screen'
][
'height'
]]
config
[
'screen'
][
'width'
],
config
[
'screen'
][
'height'
]
=
Resolution
.
default
unless
Resolution
.
all
.
include?
[
config
[
'screen'
][
'width'
],
config
[
'screen'
][
'height'
]]
config
[
'i18n'
]
||=
{}
config
[
'i18n'
][
'locale'
]
||=
"
#{
Locale
.
current
.
language
}
-
#{
Locale
.
current
.
region
}
"
I18n
.
locale
=
config
[
'i18n'
][
'locale'
]
config
config
end
end
def
save
(
config
=
$config
,
file
=
"config.yml"
)
def
save
(
config
=
$config
,
file
=
"config.yml"
)
...
...
lib/game_event.rb
View file @
17ae1837
#游戏事件的抽象类
#游戏事件的抽象类
class
Game_Event
class
Game_Event
@queue
=
[]
@queue
=
[]
def
self
.
push
(
event
)
def
self
.
push
(
event
)
@queue
<<
event
@queue
<<
event
end
end
def
self
.
poll
def
self
.
poll
@queue
.
shift
@queue
.
shift
end
end
def
self
.
parse
(
info
,
*
args
)
def
self
.
parse
(
info
,
*
args
)
#适配器定义
#适配器定义
end
end
...
@@ -14,14 +17,16 @@ class Game_Event
...
@@ -14,14 +17,16 @@ class Game_Event
class
Login
<
Game_Event
class
Login
<
Game_Event
attr_reader
:user
attr_reader
:user
def
initialize
(
user
)
def
initialize
(
user
)
@user
=
user
@user
=
user
$game
.
user
=
@user
$game
.
user
=
@user
end
end
end
end
class
AllUsers
<
Game_Event
class
AllUsers
<
Game_Event
attr_reader
:users
attr_reader
:users
def
initialize
(
users
)
def
initialize
(
users
)
@users
=
[]
@users
=
[]
users
.
each
do
|
user
|
users
.
each
do
|
user
|
...
@@ -34,9 +39,10 @@ class Game_Event
...
@@ -34,9 +39,10 @@ class Game_Event
$game
.
users
.
replace
@users
$game
.
users
.
replace
@users
end
end
end
end
class
NewUser
<
AllUsers
class
NewUser
<
AllUsers
attr_reader
:users
attr_reader
:users
def
initialize
(
user
)
def
initialize
(
user
)
@user
=
user
@user
=
user
unless
$game
.
users
.
include?
@user
unless
$game
.
users
.
include?
@user
...
@@ -51,6 +57,7 @@ class Game_Event
...
@@ -51,6 +57,7 @@ class Game_Event
class
MissingUser
<
AllUsers
class
MissingUser
<
AllUsers
attr_reader
:users
attr_reader
:users
def
initialize
(
user
)
def
initialize
(
user
)
@user
=
user
@user
=
user
$game
.
users
.
delete
@user
$game
.
users
.
delete
@user
...
@@ -59,14 +66,27 @@ class Game_Event
...
@@ -59,14 +66,27 @@ class Game_Event
class
AllRooms
<
Game_Event
class
AllRooms
<
Game_Event
attr_reader
:rooms
attr_reader
:rooms
def
initialize
(
rooms
)
def
initialize
(
rooms
)
@rooms
=
rooms
@rooms
=
rooms
$game
.
rooms
.
replace
@rooms
$game
.
rooms
.
replace
@rooms
$game
.
rooms
.
sort_by!
{
|
room
|
[
room
.
status
==
:start
?
1
:
0
,
room
.
private
?
1
:
0
,
room
.
id
]
}
end
end
class
RoomsUpdate
<
AllRooms
attr_reader
:rooms
def
initialize
(
rooms
)
@rooms
=
rooms
$game
.
rooms
.
replace
$game
.
rooms
|
@rooms
$game
.
rooms
.
delete_if
{
|
room
|
room
.
_deleted
}
$game
.
rooms
.
sort_by!
{
|
room
|
[
room
.
status
==
:start
?
1
:
0
,
room
.
private
?
1
:
0
,
room
.
id
]
}
end
end
end
end
class
NewRoom
<
AllRooms
class
NewRoom
<
AllRooms
attr_reader
:room
attr_reader
:room
def
initialize
(
room
)
def
initialize
(
room
)
@room
=
room
@room
=
room
unless
$game
.
rooms
.
include?
@room
unless
$game
.
rooms
.
include?
@room
...
@@ -80,6 +100,7 @@ class Game_Event
...
@@ -80,6 +100,7 @@ class Game_Event
end
end
class
MissingRoom
<
AllRooms
class
MissingRoom
<
AllRooms
attr_reader
:room
attr_reader
:room
def
initialize
(
room
)
def
initialize
(
room
)
@room
=
room
@room
=
room
$game
.
rooms
.
delete
@room
$game
.
rooms
.
delete
@room
...
@@ -87,9 +108,9 @@ class Game_Event
...
@@ -87,9 +108,9 @@ class Game_Event
end
end
class
Chat
<
Game_Event
class
Chat
<
Game_Event
attr_reader
:chatmessage
attr_reader
:chatmessage
def
initialize
(
chatmessage
)
def
initialize
(
chatmessage
)
@chatmessage
=
chatmessage
@chatmessage
=
chatmessage
end
end
...
@@ -97,8 +118,9 @@ class Game_Event
...
@@ -97,8 +118,9 @@ class Game_Event
class
Join
<
Game_Event
class
Join
<
Game_Event
attr_reader
:room
attr_reader
:room
def
initialize
(
room
)
def
initialize
(
room
)
@room
=
room
@room
=
room
$game
.
room
=
@room
$game
.
room
=
@room
end
end
end
end
...
@@ -106,8 +128,9 @@ class Game_Event
...
@@ -106,8 +128,9 @@ class Game_Event
end
end
class
Watch
<
Game_Event
class
Watch
<
Game_Event
attr_reader
:room
attr_reader
:room
def
initialize
(
room
)
def
initialize
(
room
)
@room
=
room
@room
=
room
$game
.
room
=
@room
$game
.
room
=
@room
end
end
end
end
...
@@ -117,8 +140,9 @@ class Game_Event
...
@@ -117,8 +140,9 @@ class Game_Event
end
end
class
PlayerJoin
<
Game_Event
class
PlayerJoin
<
Game_Event
attr_reader
:user
attr_reader
:user
def
initialize
(
user
)
def
initialize
(
user
)
@user
=
user
@user
=
user
$game
.
room
.
player2
=
@user
$game
.
room
.
player2
=
@user
end
end
end
end
...
@@ -130,20 +154,22 @@ class Game_Event
...
@@ -130,20 +154,22 @@ class Game_Event
class
Action
<
Game_Event
class
Action
<
Game_Event
attr_reader
:action
,
:str
attr_reader
:action
,
:str
def
initialize
(
action
,
str
=
action
.
escape
)
def
initialize
(
action
,
str
=
action
.
escape
)
@action
=
action
@action
=
action
@str
=
str
@str
=
str
end
end
end
end
class
Error
<
Game_Event
class
Error
<
Game_Event
attr_reader
:title
,
:message
,
:fatal
attr_reader
:title
,
:message
,
:fatal
def
initialize
(
title
,
message
,
fatal
=
true
)
def
initialize
(
title
,
message
,
fatal
=
true
)
@title
=
title
@title
=
title
@message
=
message
@message
=
message
@fatal
=
fatal
@fatal
=
fatal
$log
.
error
(
@fatal
?
"致命错误"
:
"一般错误"
)
{
"
#{
@title
}
:
#{
@message
}
#{
caller
}
"
}
$log
.
error
(
@fatal
?
"致命错误"
:
"一般错误"
)
{
"
#{
@title
}
:
#{
@message
}
#{
caller
}
"
}
end
end
end
end
class
Unknown
<
Error
class
Unknown
<
Error
...
...
lib/iduel/user.rb
View file @
17ae1837
...
@@ -21,12 +21,12 @@ class User
...
@@ -21,12 +21,12 @@ class User
end
end
def
avatar
(
size
=
:small
)
def
avatar
(
size
=
:small
)
cache
=
"graphics/avatars/
#{
@id
}
_
#{
size
}
.png"
cache
=
"graphics/avatars/
#{
@id
}
_
#{
size
}
.png"
result
=
Surface
.
load
(
cache
)
rescue
Surface
.
load
(
"graphics/avatars/loading_
#{
size
}
.
gif
"
)
result
=
Surface
.
load
(
cache
)
rescue
Surface
.
load
(
"graphics/avatars/loading_
#{
size
}
.
png
"
)
scene
=
$scene
scene
=
$scene
if
block_given?
if
block_given?
yield
result
yield
result
Thread
.
new
do
Thread
.
new
do
open
(
"http://www.duelcn.com/uc_server/avatar.php?uid=
#{
id
-
100000
}
&size=
#{
size
}
"
,
'rb'
)
{
|
io
|
open
(
cache
,
'wb'
)
{
|
c
|
c
.
write
io
.
read
}}
rescue
cache
=
"graphics/avatars/
noavatar_
#{
size
}
.gif
"
open
(
"http://www.duelcn.com/uc_server/avatar.php?uid=
#{
id
-
100000
}
&size=
#{
size
}
"
,
'rb'
)
{
|
io
|
open
(
cache
,
'wb'
)
{
|
c
|
c
.
write
io
.
read
}}
rescue
cache
=
"graphics/avatars/
error_
#{
size
}
.png
"
(
yield
Surface
.
load
(
cache
)
if
scene
==
$scene
)
rescue
nil
(
yield
Surface
.
load
(
cache
)
if
scene
==
$scene
)
rescue
nil
end
end
else
else
...
...
lib/main.rb
View file @
17ae1837
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
begin
begin
Windows
=
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
Windows
=
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
Dir
.
glob
(
'post_update_*.rb'
).
sort
.
each
{
|
file
|
load
file
}
Thread
.
abort_on_exception
=
true
Thread
.
abort_on_exception
=
true
require_relative
'resolution'
require_relative
'resolution'
...
@@ -9,30 +10,36 @@ begin
...
@@ -9,30 +10,36 @@ begin
require_relative
'config'
require_relative
'config'
require_relative
'association'
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
=
Config
.
load
Config
.
save
Config
.
save
#读取命令行参数
#读取命令行参数
log
=
"log.log"
log
=
"log.log"
log_level
=
"INFO"
log_level
=
"INFO"
profile
=
nil
profile
=
nil
ARGV
.
each
do
|
arg
|
ARGV
.
each
do
|
arg
|
arg
=
arg
.
dup
.
force_encoding
(
"UTF-8"
)
arg
=
arg
.
dup
.
force_encoding
(
"UTF-8"
)
arg
.
force_encoding
(
"GBK"
)
unless
arg
.
valid_encoding?
arg
.
force_encoding
(
"GBK"
)
unless
arg
.
valid_encoding?
case
arg
case
arg
when
/--log=(.*)/
when
/--log=(.*)/
log
.
replace
$1
log
.
replace
$1
when
/--log-level=(.*)/
when
/--log-level=(.*)/
log_level
.
replace
$1
log_level
.
replace
$1
when
/--profile=(.*)/
when
/--profile=(.*)/
profile
=
$1
profile
=
$1
when
/^mycard:.*|\.ydk$|\.yrp$|\.deck$/
when
/^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative
'quickstart'
require_relative
'quickstart'
$scene
=
false
$scene
=
false
when
/register_association/
when
/register_association/
Association
.
register
Association
.
register
$scene
=
false
$scene
=
false
end
end
end
end
...
@@ -51,7 +58,7 @@ begin
...
@@ -51,7 +58,7 @@ begin
if
log
==
"STDOUT"
#调试用
if
log
==
"STDOUT"
#调试用
log
=
STDOUT
log
=
STDOUT
end
end
$log
=
Logger
.
new
(
log
)
$log
=
Logger
.
new
(
log
)
$log
.
level
=
Logger
.
const_get
log_level
$log
.
level
=
Logger
.
const_get
log_level
#性能分析
#性能分析
...
@@ -63,7 +70,7 @@ begin
...
@@ -63,7 +70,7 @@ begin
end
end
require
'profiler'
require
'profiler'
RubyVM
::
InstructionSequence
.
compile_option
=
{
RubyVM
::
InstructionSequence
.
compile_option
=
{
:trace_instruction
=>
true
,
:trace_instruction
=>
true
,
:specialized_instruction
=>
false
:specialized_instruction
=>
false
}
}
Profiler__
::
start_profile
Profiler__
::
start_profile
...
@@ -71,13 +78,13 @@ begin
...
@@ -71,13 +78,13 @@ begin
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPACTIVE
=
4
SDL
::
Event
::
APPACTIVE
=
4
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
.
init
(
INIT_VIDEO
)
SDL
.
init
(
INIT_VIDEO
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
TTF
.
init
TTF
.
init
#声音
#声音
...
...
lib/quickstart.rb
View file @
17ae1837
...
@@ -49,7 +49,9 @@ case file
...
@@ -49,7 +49,9 @@ case file
require
'uri'
require
'uri'
$game
.
user
=
User
.
new
(
$1
.
to_sym
,
$1
)
if
$1
$game
.
user
=
User
.
new
(
$1
.
to_sym
,
$1
)
if
$1
$game
.
password
=
$2
if
$2
$game
.
password
=
$2
if
$2
$game
.
server
=
$3
room
=
Room
.
new
(
0
,
$5
)
$game
.
port
=
$4
.
to_i
room
.
server_ip
=
$3
Ygocore
.
run_ygocore
Room
.
new
(
0
,
$5
),
true
room
.
server_port
=
$4
.
to_i
room
.
server_auth
=
true
if
$2
Ygocore
.
run_ygocore
room
,
true
end
end
\ No newline at end of file
lib/room.rb
View file @
17ae1837
...
@@ -2,7 +2,7 @@ require_relative 'cacheable'
...
@@ -2,7 +2,7 @@ require_relative 'cacheable'
class
Room
class
Room
Color
=
[[
0
,
0
,
0
],
[
255
,
0
,
0
],
[
0
,
128
,
0
],
[
0
,
0
,
255
],
[
255
,
165
,
0
]]
Color
=
[[
0
,
0
,
0
],
[
255
,
0
,
0
],
[
0
,
128
,
0
],
[
0
,
0
,
255
],
[
255
,
165
,
0
]]
extend
Cacheable
extend
Cacheable
attr_accessor
:id
,
:name
,
:player1
,
:player2
,
:private
,
:color
,
:forbid
attr_accessor
:id
,
:name
,
:player1
,
:player2
,
:private
,
:color
,
:forbid
,
:_deleted
attr_accessor
:password
attr_accessor
:password
def
initialize
(
id
,
name
=
"等待更新"
,
player1
=
nil
,
player2
=
nil
,
private
=
false
,
color
=
[
0
,
0
,
0
],
session
=
nil
,
forbid
=
nil
)
def
initialize
(
id
,
name
=
"等待更新"
,
player1
=
nil
,
player2
=
nil
,
private
=
false
,
color
=
[
0
,
0
,
0
],
session
=
nil
,
forbid
=
nil
)
@id
=
id
@id
=
id
...
@@ -30,6 +30,9 @@ class Room
...
@@ -30,6 +30,9 @@ class Room
def
extra
def
extra
{}
{}
end
end
def
status
player2
?
:
start
:
:wait
end
alias
full?
player2
alias
full?
player2
alias
private
?
private
alias
private
?
private
end
end
\ No newline at end of file
lib/update.rb
View file @
17ae1837
...
@@ -2,7 +2,7 @@ require 'open-uri'
...
@@ -2,7 +2,7 @@ require 'open-uri'
require
"fileutils"
require
"fileutils"
require_relative
'card'
require_relative
'card'
module
Update
module
Update
Version
=
'0.
7.4
'
Version
=
'0.
8.1
'
URL
=
"http://my-card.in/mycard/update.json?version=
#{
Version
}
"
URL
=
"http://my-card.in/mycard/update.json?version=
#{
Version
}
"
class
<<
self
class
<<
self
attr_reader
:thumbnails
,
:images
,
:status
attr_reader
:thumbnails
,
:images
,
:status
...
...
lib/widget_msgbox.rb
View file @
17ae1837
...
@@ -4,7 +4,7 @@ class Widget_Msgbox < Window
...
@@ -4,7 +4,7 @@ class Widget_Msgbox < Window
class
<<
self
class
<<
self
alias
old_new
new
alias
old_new
new
def
new
(
title
,
message
,
buttons
=
{},
&
proc
)
def
new
(
title
,
message
,
buttons
=
{},
&
proc
)
if
instance
=
$scene
.
windows
.
find
{
|
window
|
window
.
class
==
self
and
!
window
.
destroyed?
}
if
instance
=
$scene
.
windows
.
find
{
|
window
|
window
.
class
==
self
and
!
window
.
destroyed?
}
rescue
nil
instance
.
set
(
title
,
message
,
buttons
,
&
proc
)
instance
.
set
(
title
,
message
,
buttons
,
&
proc
)
instance
instance
else
else
...
...
lib/window.rb
View file @
17ae1837
...
@@ -2,91 +2,111 @@ class Window
...
@@ -2,91 +2,111 @@ class Window
WLH
=
24
WLH
=
24
attr_accessor
:x
,
:y
,
:width
,
:height
,
:z
,
:contents
,
:visible
,
:viewport
,
:background
attr_accessor
:x
,
:y
,
:width
,
:height
,
:z
,
:contents
,
:visible
,
:viewport
,
:background
alias
visible?
visible
alias
visible?
visible
def
initialize
(
x
,
y
,
width
,
height
,
z
=
200
)
def
initialize
(
x
,
y
,
width
,
height
,
z
=
200
)
@x
=
x
@x
=
x
@y
=
y
@y
=
y
@z
=
z
@z
=
z
@width
=
width
@width
=
width
@height
=
height
@height
=
height
@visible
=
true
@visible
=
true
#@angle = 0
#@angle = 0
@viewport
=
[
0
,
0
,
@width
,
@height
]
@viewport
=
[
0
,
0
,
@width
,
@height
]
@destroyed
=
false
@destroyed
=
false
amask
=
0xff000000
amask
=
0xff000000
rmask
=
0x00ff0000
rmask
=
0x00ff0000
gmask
=
0x0000ff00
gmask
=
0x0000ff00
bmask
=
0x000000ff
bmask
=
0x000000ff
#@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
#@background ||= Surface.new(SWSURFACE, @width, @height, 32, rmask, gmask, bmask, amask)
@contents
||=
Surface
.
new
(
SWSURFACE
,
@width
,
@height
,
32
,
rmask
,
gmask
,
bmask
,
amask
)
@contents
||=
Surface
.
new
(
SWSURFACE
,
@width
,
@height
,
32
,
rmask
,
gmask
,
bmask
,
amask
)
#按Z坐标插入
#按Z坐标插入
unless
$scene
.
windows
.
each_with_index
do
|
window
,
index
|
unless
$scene
.
windows
.
each_with_index
do
|
window
,
index
|
if
window
.
z
>
@z
if
window
.
z
>
@z
$scene
.
windows
.
insert
(
index
,
self
)
$scene
.
windows
.
insert
(
index
,
self
)
break
true
break
true
end
end
end
==
true
end
==
true
$scene
.
windows
<<
self
$scene
.
windows
<<
self
end
end
end
def
center_margin
(
text
,
width
,
font
=
@font
)
(
width
-
font
.
text_size
(
text
)[
0
])
/
2
end
end
def
draw_stroked_text
(
text
,
x
,
y
,
size
=
1
,
font
=
@font
,
color
=
@color
,
color_stroke
=
@color_stroke
)
[[
x
-
size
,
y
-
size
],
[
x
-
size
,
y
],
[
x
-
size
,
y
+
size
],
def
draw_stroked_text
(
text
,
x
,
y
,
size
=
1
,
font
=
@font
,
color
=
@color
,
color_stroke
=
@color_stroke
)
[
x
,
y
-
size
],
[
x
,
y
+
size
],
[[
x
-
size
,
y
-
size
],
[
x
-
size
,
y
],
[
x
-
size
,
y
+
size
],
[
x
+
size
,
y
-
size
],
[
x
+
size
,
y
],
[
x
+
size
,
y
+
size
],
[
x
,
y
-
size
],
[
x
,
y
+
size
],
].
each
{
|
pos
|
font
.
draw_blended_utf8
(
@contents
,
text
,
pos
[
0
],
pos
[
1
],
*
color
)}
[
x
+
size
,
y
-
size
],
[
x
+
size
,
y
],
[
x
+
size
,
y
+
size
],
].
each
{
|
pos
|
font
.
draw_blended_utf8
(
@contents
,
text
,
pos
[
0
],
pos
[
1
],
*
color
)
}
font
.
draw_blended_utf8
(
@contents
,
text
,
x
,
y
,
*
color_stroke
)
font
.
draw_blended_utf8
(
@contents
,
text
,
x
,
y
,
*
color_stroke
)
end
end
def
include?
(
x
,
y
)
def
include?
(
x
,
y
)
x
>=
@x
&&
x
<
@x
+
@width
&&
y
>=
@y
&&
y
<
@y
+
@height
x
>=
@x
&&
x
<
@x
+
@width
&&
y
>=
@y
&&
y
<
@y
+
@height
end
end
def
destroy
def
destroy
@destroyed
=
true
@destroyed
=
true
@contents
.
destroy
if
@contents
@contents
.
destroy
if
@contents
$scene
.
windows
.
delete
self
if
$scene
$scene
.
windows
.
delete
self
if
$scene
end
end
def
destroyed?
def
destroyed?
@destroyed
@destroyed
end
end
def
draw
(
screen
)
def
draw
(
screen
)
return
unless
self
.
contents
&&
self
.
visible?
&&
!
self
.
destroyed?
return
unless
self
.
contents
&&
self
.
visible?
&&
!
self
.
destroyed?
Surface
.
blit
(
self
.
contents
,
*
self
.
viewport
,
screen
,
self
.
x
,
self
.
y
)
Surface
.
blit
(
self
.
contents
,
*
self
.
viewport
,
screen
,
self
.
x
,
self
.
y
)
end
end
def
clear
(
x
=
0
,
y
=
0
,
width
=
@width
,
height
=
@height
)
def
clear
(
x
=
0
,
y
=
0
,
width
=
@width
,
height
=
@height
)
if
@background
if
@background
Surface
.
blit
(
@background
,
x
,
y
,
width
,
height
,
@contents
,
x
,
y
)
Surface
.
blit
(
@background
,
x
,
y
,
width
,
height
,
@contents
,
x
,
y
)
elsif
$scene
and
$scene
.
background
elsif
$scene
and
$scene
.
background
Surface
.
blit
(
$scene
.
background
,
@x
+
x
,
@y
+
y
,
width
,
height
,
@contents
,
x
,
y
)
Surface
.
blit
(
$scene
.
background
,
@x
+
x
,
@y
+
y
,
width
,
height
,
@contents
,
x
,
y
)
else
else
@contents
.
fill_rect
(
x
,
y
,
width
,
height
,
0xFF000000
)
@contents
.
fill_rect
(
x
,
y
,
width
,
height
,
0xFF000000
)
end
end
end
end
def
update
def
update
#子类定义
#子类定义
end
end
def
refresh
def
refresh
#子类定义
#子类定义
end
end
def
mousemoved
(
x
,
y
)
def
mousemoved
(
x
,
y
)
#子类定义
#子类定义
end
end
def
clicked
def
clicked
#子类定义
#子类定义
end
end
def
mouseleftbuttonup
def
mouseleftbuttonup
#子类定义
#子类定义
end
end
def
lostfocus
(
active_window
=
nil
)
def
lostfocus
(
active_window
=
nil
)
#子类定义
#子类定义
end
end
def
cursor_up
(
wrap
=
false
)
def
cursor_up
(
wrap
=
false
)
#子类定义
#子类定义
end
end
def
cursor_down
(
wrap
=
false
)
def
cursor_down
(
wrap
=
false
)
#子类定义
#子类定义
end
end
def
scroll_up
def
scroll_up
cursor_up
cursor_up
end
end
def
scroll_down
def
scroll_down
cursor_down
cursor_down
end
end
...
...
lib/window_chat.rb
View file @
17ae1837
...
@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable
...
@@ -27,7 +27,7 @@ class Window_Chat < Window_Scrollable
if
!
@chat_input
.
value
.
empty?
if
!
@chat_input
.
value
.
empty?
chatmessage
=
ChatMessage
.
new
(
$game
.
user
,
@chat_input
.
value
,
@channel
)
chatmessage
=
ChatMessage
.
new
(
$game
.
user
,
@chat_input
.
value
,
@channel
)
$game
.
chat
chatmessage
$game
.
chat
chatmessage
Game_Event
.
push
Game_Event
::
Chat
.
new
(
chatmessage
)
if
$game
.
show_chat_self
Game_Event
.
push
Game_Event
::
Chat
.
new
(
chatmessage
)
#
if $game.show_chat_self
true
true
end
end
end
end
...
...
lib/window_config.rb
View file @
17ae1837
...
@@ -42,7 +42,7 @@ class Window_Config < Window
...
@@ -42,7 +42,7 @@ class Window_Config < Window
when
:avatar_cache
when
:avatar_cache
size
=
0
size
=
0
count
=
0
count
=
0
Dir
.
glob
(
"graphics/avatars/*
_*.png"
)
do
|
file
|
Dir
.
glob
(
"graphics/avatars/*
"
).
reject
{
|
file
|
File
.
basename
(
file
)
=~
/(?:error|loading)_(?:small|middle|large)\.png/
}.
each
do
|
file
|
count
+=
1
count
+=
1
size
+=
File
.
size
(
file
)
size
+=
File
.
size
(
file
)
end
end
...
@@ -105,7 +105,7 @@ class Window_Config < Window
...
@@ -105,7 +105,7 @@ class Window_Config < Window
draw_item
(
@index
,
1
)
draw_item
(
@index
,
1
)
when
:avatar_cache
when
:avatar_cache
#clear(*item_rect(@index))
#clear(*item_rect(@index))
Dir
.
glob
(
"graphics/avatars/*
_*.png"
)
do
|
file
|
Dir
.
glob
(
"graphics/avatars/*
"
).
reject
{
|
file
|
File
.
basename
(
file
)
=~
/(?:error|loading)_(?:small|middle|large)\.png/
}.
each
do
|
file
|
File
.
delete
file
File
.
delete
file
end
end
refresh
refresh
...
...
lib/window_lobbybuttons.rb
View file @
17ae1837
require_relative
'window_host'
require_relative
'window_host'
class
Window_LobbyButtons
<
Window_List
class
Window_LobbyButtons
<
Window_List
def
initialize
(
x
,
y
)
def
initialize
(
x
,
y
)
@items
=
[
"常见问题"
,
"卡组编辑"
,
"建立房间"
]
@items
=
[
I18n
.
t
(
'lobby.faq'
),
I18n
.
t
(
'lobby.editdeck'
),
I18n
.
t
(
'lobby.newroom'
)
]
@button
=
Surface
.
load
(
"graphics/lobby/button.png"
)
@button
=
Surface
.
load
(
"graphics/lobby/button.png"
)
super
(
x
,
y
,
@items
.
size
*
@button
.
w
/
3
+
@items
.
size
*
4
,
30
)
super
(
x
,
y
,
@items
.
size
*
@button
.
w
/
3
+
@items
.
size
*
4
,
30
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
15
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
15
)
...
@@ -9,9 +9,9 @@ class Window_LobbyButtons < Window_List
...
@@ -9,9 +9,9 @@ class Window_LobbyButtons < Window_List
end
end
def
draw_item
(
index
,
status
=
0
)
def
draw_item
(
index
,
status
=
0
)
x
,
y
=
item_rect
(
index
)
x
,
y
,
width
=
item_rect
(
index
)
Surface
.
blit
(
@button
,
status
*
@button
.
w
/
3
,
0
,
@button
.
w
/
3
,
@button
.
h
,
@contents
,
x
,
y
)
Surface
.
blit
(
@button
,
status
*
@button
.
w
/
3
,
0
,
@button
.
w
/
3
,
@button
.
h
,
@contents
,
x
,
y
)
draw_stroked_text
(
@items
[
index
],
x
+
8
,
y
+
3
,
2
,
@font
,
[
0xdf
,
0xf1
,
0xff
],
[
0x27
,
0x43
,
0x59
])
draw_stroked_text
(
@items
[
index
],
x
+
center_margin
(
@items
[
index
],
width
,
@font
)
,
y
+
3
,
2
,
@font
,
[
0xdf
,
0xf1
,
0xff
],
[
0x27
,
0x43
,
0x59
])
end
end
def
item_rect
(
index
)
def
item_rect
(
index
)
...
...
lib/window_login.rb
View file @
17ae1837
...
@@ -45,23 +45,23 @@ class Window_Login < Window
...
@@ -45,23 +45,23 @@ class Window_Login < Window
:replay
=>
[
378
,
200
,
@button
.
w
/
3
,
@button
.
h
]
:replay
=>
[
378
,
200
,
@button
.
w
/
3
,
@button
.
h
]
}
}
@items_text
=
{
@items_text
=
{
:login
=>
"登录"
,
:login
=>
I18n
.
t
(
"login.login"
)
,
:register
=>
"注册"
,
:register
=>
I18n
.
t
(
"login.register"
)
,
:replay
=>
"录像"
:replay
=>
I18n
.
t
(
"login.replay"
),
}
}
#self.index = nil
#self.index = nil
@remember_password
=
Widget_Checkbox
.
new
(
self
,
357
+
@x
,
80
+
@y
,
self
.
width
-
357
,
24
,
password
,
"记住密码"
)
@remember_password
=
Widget_Checkbox
.
new
(
self
,
357
+
@x
,
80
+
@y
,
self
.
width
-
357
,
24
,
password
,
I18n
.
t
(
'login.remember'
)
)
refresh
refresh
end
end
def
refresh
def
refresh
clear
clear
@items
.
each_pair
{
|
index
,
rect
|
draw_item
(
index
,
rect
)}
@items
.
each_pair
{
|
index
,
rect
|
draw_item
(
index
,
rect
)}
draw_stroked_text
(
"用户名"
,
105
,
80
+
2
,
1
)
draw_stroked_text
(
I18n
.
t
(
'login.name'
)
,
105
,
80
+
2
,
1
)
draw_stroked_text
(
"密码"
,
105
,
125
+
2
,
1
)
draw_stroked_text
(
I18n
.
t
(
'login.password'
)
,
105
,
125
+
2
,
1
)
end
end
def
draw_item
(
index
,
rect
,
status
=
0
)
def
draw_item
(
index
,
rect
,
status
=
0
)
Surface
.
blit
(
@button
,
rect
[
2
]
*
status
,
0
,
rect
[
2
],
rect
[
3
],
@contents
,
rect
[
0
],
rect
[
1
])
Surface
.
blit
(
@button
,
rect
[
2
]
*
status
,
0
,
rect
[
2
],
rect
[
3
],
@contents
,
rect
[
0
],
rect
[
1
])
draw_stroked_text
(
@items_text
[
index
],
rect
[
0
]
+
24
,
rect
[
1
]
+
9
,
1
,
@font_button
)
draw_stroked_text
(
@items_text
[
index
],
rect
[
0
]
+
center_margin
(
@items_text
[
index
],
rect
[
2
],
@font_button
)
,
rect
[
1
]
+
9
,
1
,
@font_button
)
end
end
def
mousemoved
(
x
,
y
)
def
mousemoved
(
x
,
y
)
self
.
index
=
@items
.
each_pair
{
|
index
,
rect
|
break
index
if
(
x
-
@x
>=
rect
[
0
]
and
x
-
@x
<
rect
[
0
]
+
rect
[
2
]
and
y
-
@y
>=
rect
[
1
]
and
y
-
@y
<
rect
[
1
]
+
rect
[
3
])}
self
.
index
=
@items
.
each_pair
{
|
index
,
rect
|
break
index
if
(
x
-
@x
>=
rect
[
0
]
and
x
-
@x
<
rect
[
0
]
+
rect
[
2
]
and
y
-
@y
>=
rect
[
1
]
and
y
-
@y
<
rect
[
1
]
+
rect
[
3
])}
...
...
lib/window_roomlist.rb
View file @
17ae1837
...
@@ -26,10 +26,9 @@ class Window_RoomList < Window_Scrollable
...
@@ -26,10 +26,9 @@ class Window_RoomList < Window_Scrollable
y
=
item_rect
(
index
)[
1
]
y
=
item_rect
(
index
)[
1
]
room
=
@items
[
index
]
room
=
@items
[
index
]
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
,
room
.
id
.
to_s
,
24
,
y
+
8
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
room
.
id
.
to_s
,
24
,
y
+
8
,
*
@color
)
unless
room
.
id
.
to_s
.
empty?
@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
)
unless
room
.
name
.
empty?
or
room
.
name
.
size
>
100
@font
.
draw_blended_utf8
(
@contents
,
room
.
name
,
128
,
y
+
8
,
*
room
.
color
)
unless
room
.
name
.
nil?
or
room
.
name
.
empty?
or
room
.
name
.
size
>
100
$log
.
error
(
'标题过长'
)
{
room
.
name
}
if
room
.
name
.
size
>
100
@font
.
draw_blended_utf8
(
@contents
,
room
.
player1
.
name
,
128
,
y
+
24
,
*
room
.
player1
.
color
)
if
room
.
player1
and
!
room
.
player1
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
room
.
player1
.
name
,
128
,
y
+
24
,
*
room
.
player1
.
color
)
if
room
.
player1
and
!
room
.
player1
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
room
.
player2
.
name
,
320
,
y
+
24
,
*
room
.
player2
.
color
)
if
room
.
player2
and
!
room
.
player2
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
room
.
player2
.
name
,
320
,
y
+
24
,
*
room
.
player2
.
color
)
if
room
.
player2
and
!
room
.
player2
.
name
.
empty?
room
.
extra
.
each_with_index
do
|
extra
,
index
|
room
.
extra
.
each_with_index
do
|
extra
,
index
|
...
...
lib/ygocore/event.rb
View file @
17ae1837
...
@@ -7,20 +7,10 @@ class Game_Event
...
@@ -7,20 +7,10 @@ class Game_Event
else
else
Error
.
new
(
'登录'
,
'用户名或密码错误'
)
Error
.
new
(
'登录'
,
'用户名或密码错误'
)
end
end
#when :users
# AllUsers.new data.collect{|user|parse_user(user)}
when
:rooms
when
:rooms
rooms_wait
=
[]
AllRooms
.
new
data
.
collect
{
|
room
|
parse_room
(
room
)}
rooms_start
=
[]
when
:rooms_update
data
.
each
do
|
room
|
RoomsUpdate
.
new
data
.
collect
{
|
room
|
parse_room
(
room
)}
room
=
parse_room
(
room
)
if
room
.
full?
rooms_start
<<
room
else
rooms_wait
<<
room
end
end
AllRooms
.
new
rooms_wait
+
rooms_start
#when :newuser
#when :newuser
#NewUser.new parse_user data
#NewUser.new parse_user data
#when :missinguser
#when :missinguser
...
@@ -29,13 +19,13 @@ class Game_Event
...
@@ -29,13 +19,13 @@ class Game_Event
NewRoom
.
new
parse_room
data
NewRoom
.
new
parse_room
data
when
:missingroom
when
:missingroom
MissingRoom
.
new
parse_room
data
MissingRoom
.
new
parse_room
data
#
when :chat
when
:chat
#
case data[:channel]
case
data
[
:channel
]
#
when :lobby
when
:lobby
#
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
Chat
.
new
ChatMessage
.
new
User
.
new
(
data
[
:from
][
:id
],
data
[
:from
][
:name
]),
data
[
:message
],
:lobby
#
else
else
#
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
Chat
.
new
ChatMessage
.
new
User
.
new
(
data
[
:from
][
:id
],
data
[
:from
][
:name
]),
data
[
:message
],
User
.
new
(
data
[
:channel
])
#
end
end
end
end
end
end
def
self
.
parse_room
(
room
)
def
self
.
parse_room
(
room
)
...
@@ -49,6 +39,11 @@ class Game_Event
...
@@ -49,6 +39,11 @@ class Game_Event
result
.
ot
=
room
[
:ot
]
result
.
ot
=
room
[
:ot
]
result
.
status
=
room
[
:status
]
result
.
status
=
room
[
:status
]
result
.
lp
=
room
[
:lp
]
result
.
lp
=
room
[
:lp
]
result
.
_deleted
=
room
[
:_deleted
]
result
.
server_id
=
room
[
:server_id
]
result
.
server_ip
=
room
[
:server_ip
]
result
.
server_port
=
room
[
:server_port
]
result
.
server_auth
=
room
[
:server_auth
]
result
result
end
end
def
self
.
parse_user
(
user
)
def
self
.
parse_user
(
user
)
...
...
lib/ygocore/game.rb
View file @
17ae1837
#encoding: UTF-8
#encoding: UTF-8
load
'lib/ygocore/window_login.rb'
load
'lib/ygocore/window_login.rb'
require
'eventmachine'
require
'open-uri'
require
'open-uri'
require
'yaml'
require
'yaml'
class
Ygocore
<
Game
class
Ygocore
<
Game
...
@@ -14,8 +15,8 @@ class Ygocore < Game
...
@@ -14,8 +15,8 @@ class Ygocore < Game
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
...
@@ -25,100 +26,107 @@ class Ygocore < Game
...
@@ -25,100 +26,107 @@ class Ygocore < Game
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
"
mycard-server.my-card.in"
,
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
(
'lobby@conference.my-card.in/'
+
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)
# 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
)
def
chat
(
chatmessage
)
case
chatmessage
.
channel
case
chatmessage
.
channel
when
:lobby
when
:lobby
msg
=
Jabber
::
Message
::
new
(
nil
,
chatmessage
.
message
)
send
(
:chat
,
channel: :lobby
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
@@im_room
.
send
msg
when
User
when
User
msg
=
Jabber
::
Message
::
new
(
nil
,
chatmessage
.
message
)
send
(
:chat
,
channel:
chatmessage
.
channel
.
id
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
@@im_room
.
send
msg
,
chatmessage
.
channel
.
id
#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
)
...
@@ -129,6 +137,9 @@ class Ygocore < Game
...
@@ -129,6 +137,9 @@ class Ygocore < Game
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
room
.
server_port
=
$game
.
port
room
.
server_auth
=
true
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
...
@@ -228,9 +239,11 @@ class Ygocore < Game
...
@@ -228,9 +239,11 @@ class Ygocore < Game
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
system_conf
[
'lastip'
]
=
$game
.
server
system_conf
[
'nickname'
]
+=
'$'
+
$game
.
password
if
$game
.
password
and
!
$game
.
password
.
empty?
and
room
.
server_auth
system_conf
[
'lastport'
]
=
$game
.
port
.
to_s
p
room
system_conf
[
'lastip'
]
=
room
.
server_ip
system_conf
[
'lastport'
]
=
room
.
server_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'
...
@@ -271,4 +284,44 @@ class Ygocore < Game
...
@@ -271,4 +284,44 @@ class Ygocore < Game
private
private
def
self
.
get_announcements
#公告
$config
[
'ygocore'
]
||=
{}
$config
[
'ygocore'
][
'announcements'
]
||=
[
Announcement
.
new
(
"开放注册"
,
nil
,
nil
)]
#Thread.new do
# begin
# open(@@config['api']) do |file|
# file.set_encoding "GBK"
# announcements = []
# file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title, others|
# announcements << Announcement.new(title, @@config['index'], nil)
# end
# $config['ygocore']['announcements'].replace announcements
# Config.save
# end
# rescue Exception => exception
# $log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
# end
#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
end
\ No newline at end of file
lib/ygocore/room.rb
View file @
17ae1837
...
@@ -5,6 +5,7 @@ class Room
...
@@ -5,6 +5,7 @@ class Room
attr_accessor
:ot
attr_accessor
:ot
attr_accessor
:lp
attr_accessor
:lp
attr_accessor
:status
attr_accessor
:status
attr_accessor
:server_id
,
:server_ip
,
:server_port
,
:server_auth
alias
pvp?
pvp
alias
pvp?
pvp
alias
match?
match
alias
match?
match
alias
tag?
tag
alias
tag?
tag
...
...
lib/ygocore/server.yml
View file @
17ae1837
register
:
http://my-card.in/register
register
:
http://my-card.in/register
api
:
http://
122.0.65.71
:7922/
api
:
http://
master.smdcn.net
:7922/
index
:
http://my-card.in/
index
:
http://my-card.in/
server
:
122.0.65.7
1
server
:
122.0.65.7
0
port
:
7911
port
:
7911
\ No newline at end of file
lib/ygocore/user.rb
View file @
17ae1837
...
@@ -22,13 +22,13 @@ class User
...
@@ -22,13 +22,13 @@ class User
end
end
def
avatar
(
size
=
:small
)
def
avatar
(
size
=
:small
)
cache
=
"graphics/avatars/mycard_
#{
@id
}
_
#{
size
}
.png"
cache
=
"graphics/avatars/mycard_
#{
@id
}
_
#{
size
}
.png"
result
=
Surface
.
load
(
cache
)
rescue
Surface
.
load
(
"graphics/avatars/loading_
#{
size
}
.
gif
"
)
result
=
Surface
.
load
(
cache
)
rescue
Surface
.
load
(
"graphics/avatars/loading_
#{
size
}
.
png
"
)
scene
=
$scene
scene
=
$scene
if
block_given?
if
block_given?
yield
result
yield
result
Thread
.
new
do
Thread
.
new
do
require
'cgi'
require
'cgi'
open
(
"http://my-card.in/users/
#{
CGI
.
escape
@id
.
to_s
}
.png"
,
'rb'
)
{
|
io
|
open
(
cache
,
'wb'
)
{
|
c
|
c
.
write
io
.
read
}}
rescue
cache
=
"graphics/avatars/
noavatar_
#{
size
}
.gif
"
open
(
"http://my-card.in/users/
#{
CGI
.
escape
@id
.
to_s
}
.png"
,
'rb'
)
{
|
io
|
open
(
cache
,
'wb'
)
{
|
c
|
c
.
write
io
.
read
}}
rescue
cache
=
"graphics/avatars/
error_
#{
size
}
.png
"
(
yield
Surface
.
load
(
cache
)
if
scene
==
$scene
)
rescue
nil
(
yield
Surface
.
load
(
cache
)
if
scene
==
$scene
)
rescue
nil
end
end
else
else
...
...
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