Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
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
MyCard
srvpro
Commits
5fdfc4c7
Commit
5fdfc4c7
authored
Oct 15, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init arena_mode
parent
aefedb6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
12 deletions
+123
-12
config.json
config.json
+5
-0
ygopro-server.coffee
ygopro-server.coffee
+50
-6
ygopro-server.js
ygopro-server.js
+68
-6
No files found.
config.json
View file @
5fdfc4c7
...
@@ -19,6 +19,11 @@
...
@@ -19,6 +19,11 @@
"mycard_auth"
:
"https://ygobbs.com"
,
"mycard_auth"
:
"https://ygobbs.com"
,
"post_deck"
:
"http://mycard.moe/ygopro/analytics/deck/text"
,
"post_deck"
:
"http://mycard.moe/ygopro/analytics/deck/text"
,
"hang_timeout"
:
90
,
"hang_timeout"
:
90
,
"arena_mode"
:
{
"mode"
:
"entertain"
,
"post_score"
:
"https://mycard.moe/ygopro/arena/index.php?c="
,
"get_score"
:
"https://mycard.moe/ygopro/arena/index.php?c=query&username="
},
"tournament_mode"
:
{
"tournament_mode"
:
{
"enabled"
:
false
,
"enabled"
:
false
,
"deck_path"
:
"./decks/"
,
"deck_path"
:
"./decks/"
,
...
...
ygopro-server.coffee
View file @
5fdfc4c7
...
@@ -284,6 +284,7 @@ class Room
...
@@ -284,6 +284,7 @@ class Room
@
watchers
=
[]
@
watchers
=
[]
@
random_type
=
''
@
random_type
=
''
@
welcome
=
''
@
welcome
=
''
@
scores
=
{}
ROOM_all
.
push
this
ROOM_all
.
push
this
@
hostinfo
||=
@
hostinfo
||=
...
@@ -417,6 +418,30 @@ class Room
...
@@ -417,6 +418,30 @@ class Room
delete
:
->
delete
:
->
return
if
@
deleted
return
if
@
deleted
#log.info 'room-delete', this.name, ROOM_all.length
#log.info 'room-delete', this.name, ROOM_all.length
if
@
started
and
settings
.
modules
.
arena_mode
.
post_score
#log.info @scores
score_array
=
[]
for
name
,
score
of
@
scores
score_array
.
push
{
name
:
name
,
score
:
score
}
log
.
info
@
start_time
,
score_array
request
.
post
{
url
:
settings
.
modules
.
arena_mode
.
post_score
,
form
:
{
accesskey
:
process
.
env
.
MYCARD_AUTH_KEY
,
usernameA
:
score_array
[
0
].
name
,
usernameB
:
score_array
[
1
].
name
,
userscoreA
:
score_array
[
0
].
score
,
userscoreB
:
score_array
[
1
].
score
,
start
:
@
start_time
,
end
:
moment
().
format
(),
arena
:
settings
.
modules
.
arena_mode
.
mode
}},
(
error
,
response
,
body
)
=>
if
error
log
.
warn
'SCORE POST ERROR'
,
error
,
response
else
if
response
.
statusCode
!=
204
log
.
warn
'SCORE POST'
,
response
.
statusCode
,
response
.
statusMessage
,
@
name
,
body
else
log
.
info
'SCORE POST'
,
response
.
statusCode
,
response
.
statusMessage
,
@
name
,
body
return
if
@
player_datas
.
length
and
settings
.
modules
.
enable_cloud_replay
if
@
player_datas
.
length
and
settings
.
modules
.
enable_cloud_replay
replay_id
=
@
cloud_replay_id
replay_id
=
@
cloud_replay_id
if
@
has_ygopro_error
if
@
has_ygopro_error
...
@@ -522,8 +547,11 @@ class Room
...
@@ -522,8 +547,11 @@ class Room
index
=
_
.
indexOf
(
@
players
,
client
)
index
=
_
.
indexOf
(
@
players
,
client
)
@
players
.
splice
(
index
,
1
)
unless
index
==
-
1
@
players
.
splice
(
index
,
1
)
unless
index
==
-
1
#log.info(@started,@disconnector,@random_type)
#log.info(@started,@disconnector,@random_type)
if
@
started
and
@
disconnector
!=
'server'
and
@
random_type
and
(
client
.
pos
<
4
or
client
.
is_host
)
if
@
started
and
@
disconnector
!=
'server'
and
(
client
.
pos
<
4
or
client
.
is_host
)
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"强退"
)
@
finished
=
true
@
scores
[
client
.
name
]
=
-
1
if
@
random_type
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"强退"
)
if
@
players
.
length
and
!
(
@
windbot
and
client
.
is_host
)
if
@
players
.
length
and
!
(
@
windbot
and
client
.
is_host
)
ygopro
.
stoc_send_chat_to_room
this
,
"
#{
client
.
name
}
离开了游戏"
+
if
error
then
":
#{
error
}
"
else
''
ygopro
.
stoc_send_chat_to_room
this
,
"
#{
client
.
name
}
离开了游戏"
+
if
error
then
":
#{
error
}
"
else
''
roomlist
.
update
(
this
)
if
!
@
private
and
!
@
started
and
settings
.
modules
.
enable_websocket_roomlist
roomlist
.
update
(
this
)
if
!
@
private
and
!
@
started
and
settings
.
modules
.
enable_websocket_roomlist
...
@@ -1037,7 +1065,17 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
...
@@ -1037,7 +1065,17 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
welcome
,
ygopro
.
constants
.
COLORS
.
GREEN
)
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
welcome
,
ygopro
.
constants
.
COLORS
.
GREEN
)
if
room
.
welcome
if
room
.
welcome
ygopro
.
stoc_send_chat
(
client
,
room
.
welcome
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
ygopro
.
stoc_send_chat
(
client
,
room
.
welcome
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
#log.info(ROOM_all)
if
settings
.
modules
.
arena_mode
.
get_score
request
url
:
settings
.
modules
.
arena_mode
.
get_score
+
encodeURIComponent
(
client
.
name
),
json
:
true
,
(
error
,
response
,
body
)
->
if
error
or
!
body
or
_
.
isString
body
log
.
warn
'LOAD SCORE ERROR'
,
client
.
name
,
error
,
response
,
body
else
log
.
info
'LOAD SCORE'
,
client
.
name
,
body
ygopro
.
stoc_send_chat
(
client
,
"积分系统测试中,您有
#{
body
.
exp
}
点经验,
#{
body
.
pt
}
点战斗力。正式上线前这些数据可能被重置。"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
return
if
!
room
.
recorder
if
!
room
.
recorder
room
.
recorder
=
recorder
=
net
.
connect
room
.
port
,
->
room
.
recorder
=
recorder
=
net
.
connect
room
.
port
,
->
...
@@ -1133,6 +1171,9 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
...
@@ -1133,6 +1171,9 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
#log.info {winner: pos, reason: reason}
#log.info {winner: pos, reason: reason}
#room.duels.push {winner: pos, reason: reason}
#room.duels.push {winner: pos, reason: reason}
room
.
winner
=
pos
room
.
winner
=
pos
if
!
room
.
finished
room
.
winner_name
=
room
.
dueling_players
[
pos
].
name
room
.
scores
[
room
.
winner_name
]
=
room
.
scores
[
room
.
winner_name
]
+
1
#lp跟踪
#lp跟踪
if
ygopro
.
constants
.
MSG
[
msg
]
==
'DAMAGE'
and
client
.
is_host
if
ygopro
.
constants
.
MSG
[
msg
]
==
'DAMAGE'
and
client
.
is_host
...
@@ -1276,11 +1317,13 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
...
@@ -1276,11 +1317,13 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
return
unless
room
return
unless
room
unless
room
.
started
#first start
unless
room
.
started
#first start
room
.
started
=
true
room
.
started
=
true
room
.
start_time
=
moment
().
format
()
roomlist
.
delete
room
.
name
if
settings
.
modules
.
enable_websocket_roomlist
and
not
room
.
private
roomlist
.
delete
room
.
name
if
settings
.
modules
.
enable_websocket_roomlist
and
not
room
.
private
#room.duels = []
#room.duels = []
room
.
dueling_players
=
[]
room
.
dueling_players
=
[]
for
player
in
room
.
players
when
player
.
pos
!=
7
for
player
in
room
.
players
when
player
.
pos
!=
7
room
.
dueling_players
[
player
.
pos
]
=
player
room
.
dueling_players
[
player
.
pos
]
=
player
room
.
scores
[
player
.
name
]
=
0
room
.
player_datas
.
push
ip
:
player
.
ip
,
name
:
player
.
name
room
.
player_datas
.
push
ip
:
player
.
ip
,
name
:
player
.
name
if
settings
.
modules
.
tips
if
settings
.
modules
.
tips
ygopro
.
stoc_send_random_tip
(
client
)
ygopro
.
stoc_send_random_tip
(
client
)
...
@@ -1301,8 +1344,9 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
...
@@ -1301,8 +1344,9 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
log
.
warn
'DECK POST ERROR'
,
error
,
response
log
.
warn
'DECK POST ERROR'
,
error
,
response
else
else
if
response
.
statusCode
!=
200
if
response
.
statusCode
!=
200
log
.
warn
'DECK POST'
,
response
.
statusCode
,
response
.
statusMessage
log
.
warn
'DECK POST'
,
response
.
statusCode
,
client
.
name
,
body
log
.
info
'DECK POST'
,
client
.
name
,
body
else
log
.
info
'DECK POST'
,
response
.
statusCode
,
client
.
name
,
body
return
return
client
.
deck_saved
=
true
client
.
deck_saved
=
true
return
return
...
@@ -1509,7 +1553,7 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server)->
...
@@ -1509,7 +1553,7 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server)->
name
:
room
.
name
,
name
:
room
.
name
,
roomid
:
room
.
port
.
toString
(),
roomid
:
room
.
port
.
toString
(),
cloud_replay_id
:
"R#"
+
room
.
cloud_replay_id
,
cloud_replay_id
:
"R#"
+
room
.
cloud_replay_id
,
players
:
(
for
player
in
room
.
players
players
:
(
for
player
in
room
.
dueling_
players
name
:
player
.
name
,
name
:
player
.
name
,
winner
:
player
.
pos
==
room
.
winner
winner
:
player
.
pos
==
room
.
winner
)
)
...
...
ygopro-server.js
View file @
5fdfc4c7
...
@@ -398,6 +398,7 @@
...
@@ -398,6 +398,7 @@
this
.
watchers
=
[];
this
.
watchers
=
[];
this
.
random_type
=
''
;
this
.
random_type
=
''
;
this
.
welcome
=
''
;
this
.
welcome
=
''
;
this
.
scores
=
{};
ROOM_all
.
push
(
this
);
ROOM_all
.
push
(
this
);
this
.
hostinfo
||
(
this
.
hostinfo
=
{
this
.
hostinfo
||
(
this
.
hostinfo
=
{
lflist
:
settings
.
lflist
.
length
?
0
:
-
1
,
lflist
:
settings
.
lflist
.
length
?
0
:
-
1
,
...
@@ -562,10 +563,47 @@
...
@@ -562,10 +563,47 @@
}
}
Room
.
prototype
[
"
delete
"
]
=
function
()
{
Room
.
prototype
[
"
delete
"
]
=
function
()
{
var
index
,
log_rep_id
,
player_ips
,
player_names
,
recorder_buffer
,
replay_id
;
var
index
,
log_rep_id
,
name
,
player_ips
,
player_names
,
recorder_buffer
,
ref
,
replay_id
,
score
,
score_array
;
if
(
this
.
deleted
)
{
if
(
this
.
deleted
)
{
return
;
return
;
}
}
if
(
this
.
started
&&
settings
.
modules
.
arena_mode
.
post_score
)
{
score_array
=
[];
ref
=
this
.
scores
;
for
(
name
in
ref
)
{
score
=
ref
[
name
];
score_array
.
push
({
name
:
name
,
score
:
score
});
}
log
.
info
(
this
.
start_time
,
score_array
);
request
.
post
({
url
:
settings
.
modules
.
arena_mode
.
post_score
,
form
:
{
accesskey
:
process
.
env
.
MYCARD_AUTH_KEY
,
usernameA
:
score_array
[
0
].
name
,
usernameB
:
score_array
[
1
].
name
,
userscoreA
:
score_array
[
0
].
score
,
userscoreB
:
score_array
[
1
].
score
,
start
:
this
.
start_time
,
end
:
moment
().
format
(),
arena
:
settings
.
modules
.
arena_mode
.
mode
}
},
(
function
(
_this
)
{
return
function
(
error
,
response
,
body
)
{
if
(
error
)
{
log
.
warn
(
'
SCORE POST ERROR
'
,
error
,
response
);
}
else
{
if
(
response
.
statusCode
!==
204
)
{
log
.
warn
(
'
SCORE POST
'
,
response
.
statusCode
,
response
.
statusMessage
,
_this
.
name
,
body
);
}
else
{
log
.
info
(
'
SCORE POST
'
,
response
.
statusCode
,
response
.
statusMessage
,
_this
.
name
,
body
);
}
}
};
})(
this
));
}
if
(
this
.
player_datas
.
length
&&
settings
.
modules
.
enable_cloud_replay
)
{
if
(
this
.
player_datas
.
length
&&
settings
.
modules
.
enable_cloud_replay
)
{
replay_id
=
this
.
cloud_replay_id
;
replay_id
=
this
.
cloud_replay_id
;
if
(
this
.
has_ygopro_error
)
{
if
(
this
.
has_ygopro_error
)
{
...
@@ -696,8 +734,12 @@
...
@@ -696,8 +734,12 @@
if
(
index
!==
-
1
)
{
if
(
index
!==
-
1
)
{
this
.
players
.
splice
(
index
,
1
);
this
.
players
.
splice
(
index
,
1
);
}
}
if
(
this
.
started
&&
this
.
disconnector
!==
'
server
'
&&
this
.
random_type
&&
(
client
.
pos
<
4
||
client
.
is_host
))
{
if
(
this
.
started
&&
this
.
disconnector
!==
'
server
'
&&
(
client
.
pos
<
4
||
client
.
is_host
))
{
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"
强退
"
);
this
.
finished
=
true
;
this
.
scores
[
client
.
name
]
=
-
1
;
if
(
this
.
random_type
)
{
ROOM_ban_player
(
client
.
name
,
client
.
ip
,
"
强退
"
);
}
}
}
if
(
this
.
players
.
length
&&
!
(
this
.
windbot
&&
client
.
is_host
))
{
if
(
this
.
players
.
length
&&
!
(
this
.
windbot
&&
client
.
is_host
))
{
ygopro
.
stoc_send_chat_to_room
(
this
,
(
client
.
name
+
"
离开了游戏
"
)
+
(
error
?
"
:
"
+
error
:
''
));
ygopro
.
stoc_send_chat_to_room
(
this
,
(
client
.
name
+
"
离开了游戏
"
)
+
(
error
?
"
:
"
+
error
:
''
));
...
@@ -1251,6 +1293,19 @@
...
@@ -1251,6 +1293,19 @@
if
(
room
.
welcome
)
{
if
(
room
.
welcome
)
{
ygopro
.
stoc_send_chat
(
client
,
room
.
welcome
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
ygopro
.
stoc_send_chat
(
client
,
room
.
welcome
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
}
}
if
(
settings
.
modules
.
arena_mode
.
get_score
)
{
request
({
url
:
settings
.
modules
.
arena_mode
.
get_score
+
encodeURIComponent
(
client
.
name
),
json
:
true
},
function
(
error
,
response
,
body
)
{
if
(
error
||
!
body
||
_
.
isString
(
body
))
{
log
.
warn
(
'
LOAD SCORE ERROR
'
,
client
.
name
,
error
,
response
,
body
);
}
else
{
log
.
info
(
'
LOAD SCORE
'
,
client
.
name
,
body
);
ygopro
.
stoc_send_chat
(
client
,
"
积分系统测试中,您有
"
+
body
.
exp
+
"
点经验,
"
+
body
.
pt
+
"
点战斗力。正式上线前这些数据可能被重置。
"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
}
});
}
if
(
!
room
.
recorder
)
{
if
(
!
room
.
recorder
)
{
room
.
recorder
=
recorder
=
net
.
connect
(
room
.
port
,
function
()
{
room
.
recorder
=
recorder
=
net
.
connect
(
room
.
port
,
function
()
{
ygopro
.
ctos_send
(
recorder
,
'
PLAYER_INFO
'
,
{
ygopro
.
ctos_send
(
recorder
,
'
PLAYER_INFO
'
,
{
...
@@ -1348,6 +1403,10 @@
...
@@ -1348,6 +1403,10 @@
}
}
reason
=
buffer
.
readUInt8
(
2
);
reason
=
buffer
.
readUInt8
(
2
);
room
.
winner
=
pos
;
room
.
winner
=
pos
;
if
(
!
room
.
finished
)
{
room
.
winner_name
=
room
.
dueling_players
[
pos
].
name
;
room
.
scores
[
room
.
winner_name
]
=
room
.
scores
[
room
.
winner_name
]
+
1
;
}
}
}
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
DAMAGE
'
&&
client
.
is_host
)
{
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
DAMAGE
'
&&
client
.
is_host
)
{
pos
=
buffer
.
readUInt8
(
1
);
pos
=
buffer
.
readUInt8
(
1
);
...
@@ -1558,6 +1617,7 @@
...
@@ -1558,6 +1617,7 @@
}
}
if
(
!
room
.
started
)
{
if
(
!
room
.
started
)
{
room
.
started
=
true
;
room
.
started
=
true
;
room
.
start_time
=
moment
().
format
();
if
(
settings
.
modules
.
enable_websocket_roomlist
&&
!
room
[
"
private
"
])
{
if
(
settings
.
modules
.
enable_websocket_roomlist
&&
!
room
[
"
private
"
])
{
roomlist
[
"
delete
"
](
room
.
name
);
roomlist
[
"
delete
"
](
room
.
name
);
}
}
...
@@ -1569,6 +1629,7 @@
...
@@ -1569,6 +1629,7 @@
continue
;
continue
;
}
}
room
.
dueling_players
[
player
.
pos
]
=
player
;
room
.
dueling_players
[
player
.
pos
]
=
player
;
room
.
scores
[
player
.
name
]
=
0
;
room
.
player_datas
.
push
({
room
.
player_datas
.
push
({
ip
:
player
.
ip
,
ip
:
player
.
ip
,
name
:
player
.
name
name
:
player
.
name
...
@@ -1601,9 +1662,10 @@
...
@@ -1601,9 +1662,10 @@
log
.
warn
(
'
DECK POST ERROR
'
,
error
,
response
);
log
.
warn
(
'
DECK POST ERROR
'
,
error
,
response
);
}
else
{
}
else
{
if
(
response
.
statusCode
!==
200
)
{
if
(
response
.
statusCode
!==
200
)
{
log
.
warn
(
'
DECK POST
'
,
response
.
statusCode
,
response
.
statusMessage
);
log
.
warn
(
'
DECK POST
'
,
response
.
statusCode
,
client
.
name
,
body
);
}
else
{
log
.
info
(
'
DECK POST
'
,
response
.
statusCode
,
client
.
name
,
body
);
}
}
log
.
info
(
'
DECK POST
'
,
client
.
name
,
body
);
}
}
});
});
}
}
...
@@ -1893,7 +1955,7 @@
...
@@ -1893,7 +1955,7 @@
cloud_replay_id
:
"
R#
"
+
room
.
cloud_replay_id
,
cloud_replay_id
:
"
R#
"
+
room
.
cloud_replay_id
,
players
:
(
function
()
{
players
:
(
function
()
{
var
k
,
len
,
ref
,
results
;
var
k
,
len
,
ref
,
results
;
ref
=
room
.
players
;
ref
=
room
.
dueling_
players
;
results
=
[];
results
=
[];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
player
=
ref
[
k
];
player
=
ref
[
k
];
...
...
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