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
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
nanahira
srvpro
Commits
bba69ea7
Commit
bba69ea7
authored
Sep 06, 2015
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memory leak test4, synchronous ctos_follow, hide password, add http stop server
parent
5df13214
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
207 additions
and
138 deletions
+207
-138
room.coffee
room.coffee
+6
-1
room.js
room.js
+8
-1
ygopro-server.coffee
ygopro-server.coffee
+60
-55
ygopro-server.js
ygopro-server.js
+119
-81
ygopro.coffee
ygopro.coffee
+6
-0
ygopro.js
ygopro.js
+8
-0
No files found.
room.coffee
View file @
bba69ea7
...
...
@@ -122,10 +122,12 @@ class Room
return
if
@
deleted
#log.info 'room-delete', this.name, Room.all.length
@
watcher_buffers
=
[]
@
players
=
[]
@
watcher
.
end
()
if
@
watcher
@
deleted
=
true
index
=
_
.
indexOf
(
Room
.
all
,
this
)
#Room.all[index] = null unless index == -1
Room
.
all
.
splice
(
index
,
1
)
unless
index
==
-
1
@
deleted
=
true
return
connect
:
(
client
)
->
...
...
@@ -144,13 +146,16 @@ class Room
ygopro
.
stoc_send_chat_to_room
this
,
"
#{
client
.
name
}
#{
'退出了观战'
}#{
if
error
then
":
#{
error
}
"
else
''
}
"
index
=
_
.
indexOf
(
@
watchers
,
client
)
@
watchers
.
splice
(
index
,
1
)
unless
index
==
-
1
client
.
room
=
null
else
index
=
_
.
indexOf
(
@
players
,
client
)
@
players
.
splice
(
index
,
1
)
unless
index
==
-
1
if
@
players
.
length
ygopro
.
stoc_send_chat_to_room
this
,
"
#{
client
.
name
}
#{
'离开了游戏'
}#{
if
error
then
":
#{
error
}
"
else
''
}
"
client
.
room
=
null
else
@
process
.
kill
()
client
.
room
=
null
this
.
delete
()
return
...
...
room.js
View file @
bba69ea7
...
...
@@ -154,11 +154,15 @@
return
;
}
this
.
watcher_buffers
=
[];
this
.
players
=
[];
if
(
this
.
watcher
)
{
this
.
watcher
.
end
();
}
this
.
deleted
=
true
;
index
=
_
.
indexOf
(
Room
.
all
,
this
);
if
(
index
!==
-
1
)
{
Room
.
all
.
splice
(
index
,
1
);
}
this
.
deleted
=
true
;
};
Room
.
prototype
.
connect
=
function
(
client
)
{
...
...
@@ -185,6 +189,7 @@
if
(
index
!==
-
1
)
{
this
.
watchers
.
splice
(
index
,
1
);
}
client
.
room
=
null
;
}
else
{
index
=
_
.
indexOf
(
this
.
players
,
client
);
if
(
index
!==
-
1
)
{
...
...
@@ -192,8 +197,10 @@
}
if
(
this
.
players
.
length
)
{
ygopro
.
stoc_send_chat_to_room
(
this
,
client
.
name
+
"
"
+
'
离开了游戏
'
+
(
error
?
"
:
"
+
error
:
''
));
client
.
room
=
null
;
}
else
{
this
.
process
.
kill
();
client
.
room
=
null
;
this
[
"
delete
"
]();
}
}
...
...
ygopro-server.coffee
View file @
bba69ea7
...
...
@@ -35,21 +35,24 @@ if process.argv[2] == '--debug'
log
=
bunyan
.
createLogger
name
:
"mycard-debug"
else
log
=
bunyan
.
createLogger
name
:
"mycard"
###
#定时清理关闭的连接
Graveyard
=
[]
send_to_graveyard = (socket) ->
unless _.indexOf(Graveyard, socket)
Graveyard.push(socket)
tribute
=
(
socket
)
->
setTimeout send_to_graveyard(socket), 30000
setTimeout
((
socket
)
->
Graveyard
.
push
(
socket
);
return
)(
socket
),
3000
return
setInterval
()
->
log.info Graveyard
, 30000
###
for
fuck
,
i
in
Graveyard
Graveyard
[
i
].
destroy
()
if
Graveyard
[
i
]
for
you
,
j
in
Graveyard
[
i
]
Graveyard
[
i
][
j
]
=
null
Graveyard
[
i
]
=
null
Graveyard
=
[]
return
,
3000
#网络连接
net
.
createServer
(
client
)
->
server
=
new
net
.
Socket
()
...
...
@@ -60,7 +63,7 @@ net.createServer (client) ->
#释放处理
client
.
on
'close'
,
(
had_error
)
->
#log.info "client closed", client.name, had_error
#
tribute(client)
tribute
(
client
)
unless
client
.
closed
client
.
closed
=
true
client
.
room
.
disconnect
(
client
)
if
client
.
room
...
...
@@ -69,7 +72,7 @@ net.createServer (client) ->
client
.
on
'error'
,
(
error
)
->
#log.info "client error", client.name, error
#
tribute(client)
tribute
(
client
)
unless
client
.
closed
client
.
closed
=
error
client
.
room
.
disconnect
(
client
,
error
)
if
client
.
room
...
...
@@ -82,7 +85,7 @@ net.createServer (client) ->
server
.
on
'close'
,
(
had_error
)
->
#log.info "server closed", client.name, had_error
#
tribute(server)
tribute
(
server
)
server
.
closed
=
true
unless
server
.
closed
unless
client
.
closed
ygopro
.
stoc_send_chat
(
client
,
"服务器关闭了连接"
)
...
...
@@ -91,7 +94,7 @@ net.createServer (client) ->
server
.
on
'error'
,
(
error
)
->
#log.info "server error", client.name, error
#
tribute(server)
tribute
(
server
)
server
.
closed
=
error
unless
client
.
closed
ygopro
.
stoc_send_chat
(
client
,
"服务器错误:
#{
error
}
"
)
...
...
@@ -112,10 +115,7 @@ net.createServer (client) ->
else
ctos_buffer
=
Buffer
.
concat
([
ctos_buffer
,
data
],
ctos_buffer
.
length
+
data
.
length
)
#buffer的错误使用方式,好孩子不要学
if
client
.
established
server
.
write
data
else
client
.
pre_establish_buffers
.
push
data
datas
=
[]
while
true
if
ctos_message_length
==
0
...
...
@@ -131,19 +131,28 @@ net.createServer (client) ->
else
if
ctos_buffer
.
length
>=
2
+
ctos_message_length
#console.log "CTOS", ygopro.constants.CTOS[ctos_proto]
cancel
=
false
if
ygopro
.
ctos_follows
[
ctos_proto
]
b
=
ctos_buffer
.
slice
(
3
,
ctos_message_length
-
1
+
3
)
if
struct
=
ygopro
.
structs
[
ygopro
.
proto_structs
.
CTOS
[
ygopro
.
constants
.
CTOS
[
ctos_proto
]]]
struct
.
_setBuff
(
b
)
if
ygopro
.
ctos_follows
[
ctos_proto
].
synchronous
cancel
=
ygopro
.
ctos_follows
[
ctos_proto
].
callback
b
,
_
.
clone
(
struct
.
fields
),
client
,
server
else
ygopro
.
ctos_follows
[
ctos_proto
].
callback
b
,
_
.
clone
(
struct
.
fields
),
client
,
server
else
ygopro
.
ctos_follows
[
ctos_proto
].
callback
b
,
null
,
client
,
server
datas
.
push
ctos_buffer
.
slice
(
0
,
2
+
ctos_message_length
)
unless
cancel
ctos_buffer
=
ctos_buffer
.
slice
(
2
+
ctos_message_length
)
ctos_message_length
=
0
ctos_proto
=
0
else
break
if
client
.
established
server
.
write
buffer
for
buffer
in
datas
else
client
.
pre_establish_buffers
.
push
buffer
for
buffer
in
datas
return
#服务端到客户端(stoc)
...
...
@@ -194,8 +203,13 @@ net.createServer (client) ->
#功能模块
ygopro
.
ctos_follow
'PLAYER_INFO'
,
true
,
(
buffer
,
info
,
client
,
server
)
->
client
.
name
=
info
.
name
#在创建room之前暂存
return
name
=
info
.
name
.
split
(
"$"
)[
0
];
struct
=
ygopro
.
structs
[
"CTOS_PlayerInfo"
]
struct
.
_setBuff
(
buffer
)
struct
.
set
(
"name"
,
name
)
buffer
=
struct
.
buffer
client
.
name
=
name
return
false
ygopro
.
ctos_follow
'JOIN_GAME'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
#log.info info
...
...
@@ -272,6 +286,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
ygopro
.
stoc_follow
'JOIN_GAME'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
#欢迎信息
return
unless
client
.
room
if
settings
.
modules
.
welcome
ygopro
.
stoc_send_chat
client
,
settings
.
modules
.
welcome
if
(
os
.
freemem
()
/
os
.
totalmem
())
<=
0.1
...
...
@@ -292,6 +307,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
watcher
.
on
'data'
,
(
data
)
->
return
unless
client
.
room
client
.
room
.
watcher_buffers
.
push
data
for
w
in
client
.
room
.
watchers
w
.
write
data
if
w
#a WTF fix
...
...
@@ -327,20 +343,21 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
client
.
lp
=
client
.
room
.
hostinfo
.
start_lp
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
###
if ygopro.constants.MSG[msg] == 'WIN' and _.startsWith(client.room.name, 'M#') and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first or pos == 2
reason = buffer.readUInt8(2)
#log.info {winner: pos, reason: reason}
client.room.duels.push {winner: pos, reason: reason}
###
#lp跟踪
if
ygopro
.
constants
.
MSG
[
msg
]
==
'DAMAGE'
and
client
.
is_host
pos
=
buffer
.
readUInt8
(
1
)
pos
=
1
-
pos
unless
client
.
is_first
val
=
buffer
.
readInt32LE
(
2
)
client
.
room
.
dueling_players
[
pos
].
lp
-=
val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 受到伤害 #{val},现在的LP为 #{client.room.dueling_players[pos].lp}")
if
0
<
client
.
room
.
dueling_players
[
pos
].
lp
<=
100
ygopro
.
stoc_send_chat_to_room
(
client
.
room
,
"你的生命已经如风中残烛了!"
)
...
...
@@ -350,29 +367,20 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
val
=
buffer
.
readInt32LE
(
2
)
client
.
room
.
dueling_players
[
pos
].
lp
+=
val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 回复 #{val},现在的LP为 #{client.room.dueling_players[pos].lp}")
if
ygopro
.
constants
.
MSG
[
msg
]
==
'LPUPDATE'
and
client
.
is_host
pos
=
buffer
.
readUInt8
(
1
)
pos
=
1
-
pos
unless
client
.
is_first
val
=
buffer
.
readInt32LE
(
2
)
client
.
room
.
dueling_players
[
pos
].
lp
=
val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 的LP变成 #{client.room.dueling_players[pos].lp}")
if
ygopro
.
constants
.
MSG
[
msg
]
==
'PAY_LPCOST'
and
client
.
is_host
pos
=
buffer
.
readUInt8
(
1
)
pos
=
1
-
pos
unless
client
.
is_first
val
=
buffer
.
readInt32LE
(
2
)
client
.
room
.
dueling_players
[
pos
].
lp
-=
val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 支付 #{val},现在的LP为 #{client.room.dueling_players[pos].lp}")
if
0
<
client
.
room
.
dueling_players
[
pos
].
lp
<=
100
ygopro
.
stoc_send_chat_to_room
(
client
.
room
,
"背水一战!"
)
#登场台词
if
settings
.
modules
.
dialogues
if
ygopro
.
constants
.
MSG
[
msg
]
==
'SUMMONING'
or
ygopro
.
constants
.
MSG
[
msg
]
==
'SPSUMMONING'
...
...
@@ -383,8 +391,6 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
return
#房间管理
ygopro
.
stoc_follow
'TYPE_CHANGE'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
selftype
=
info
.
type
&
0xf
;
is_host
=
((
info
.
type
>>
4
)
&
0xf
)
!=
0
;
...
...
@@ -409,9 +415,10 @@ if settings.modules.tips
return
ygopro
.
stoc_follow
'DUEL_START'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
return
unless
client
.
room
unless
client
.
room
.
started
#first start
client
.
room
.
started
=
true
client
.
room
.
duels
=
[]
#
client.room.duels = []
client
.
room
.
dueling_players
=
[]
for
player
in
client
.
room
.
players
when
player
.
pos
!=
7
client
.
room
.
dueling_players
[
player
.
pos
]
=
player
...
...
@@ -419,7 +426,8 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
ygopro
.
stoc_send_random_tip
(
client
)
return
ygopro
.
ctos_follow
'CHAT'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
ygopro
.
ctos_follow
'CHAT'
,
true
,
(
buffer
,
info
,
client
,
server
)
->
cancel
=
_
.
startsWith
(
_
.
trim
(
info
.
msg
),
"/"
)
switch
_
.
trim
(
info
.
msg
)
when
'/ping'
execFile
'ss'
,
[
'-it'
,
"dst
#{
client
.
remoteAddress
}
:
#{
client
.
remotePort
}
"
],
(
error
,
stdout
,
stderr
)
->
...
...
@@ -438,10 +446,10 @@ ygopro.ctos_follow 'CHAT', false, (buffer, info, client, server)->
ygopro
.
stoc_send_chat
(
client
,
"YGOSrv233 指令帮助"
)
ygopro
.
stoc_send_chat
(
client
,
"/help 显示这个帮助信息"
)
ygopro
.
stoc_send_chat
(
client
,
"/tip 显示一条提示"
)
if
settings
.
modules
.
tips
#ygopro.stoc_send_chat(client,"/senddeck 发送自己的卡组")
when
'/tip'
ygopro
.
stoc_send_random_tip
(
client
)
if
settings
.
modules
.
tips
return
return
cancel
ygopro
.
ctos_follow
'UPDATE_DECK'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
#log.info info
...
...
@@ -451,22 +459,9 @@ ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
client
.
side
=
side
return
###
if settings.modules.skip_empty_side
ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
if client.side
ygopro.ctos_send server, 'UPDATE_DECK', {
mainc: client.main.length,
sidec: 0,
deckbuf: client.main
}
ygopro.stoc_send_chat client, '等待更换副卡组中...'
###
#http
if
settings
.
modules
.
http
http_server
=
http
.
createServer
(
request
,
response
)
->
#http://122.0.65.70:7922/?operation=getroomjson
u
=
url
.
parse
(
request
.
url
,
1
)
#log.info u
if
u
.
pathname
==
'/count.json'
...
...
@@ -506,8 +501,18 @@ if settings.modules.http
else
if
u
.
query
.
pass
==
settings
.
modules
.
http
.
password
&&
u
.
query
.
shout
for
room
in
Room
.
all
ygopro
.
stoc_send_chat_to_room
(
room
,
u
.
query
.
shout
)
response
.
writeHead
(
200
);
response
.
end
(
"shout "
+
u
.
query
.
shout
+
" ok"
);
response
.
writeHead
(
200
)
response
.
end
(
"shout "
+
u
.
query
.
shout
+
" ok"
)
else
if
u
.
query
.
pass
==
settings
.
modules
.
http
.
password
&&
u
.
query
.
stop
settings
.
modules
.
stop
=
u
.
query
.
stop
response
.
writeHead
(
200
)
response
.
end
(
"stop "
+
u
.
query
.
shout
+
" ok"
)
else
if
u
.
query
.
pass
==
settings
.
modules
.
http
.
password
&&
u
.
query
.
welcome
settings
.
modules
.
welcome
=
u
.
query
.
welcome
response
.
writeHead
(
200
)
response
.
end
(
"welcome "
+
u
.
query
.
shout
+
" ok"
)
else
response
.
writeHead
(
404
);
...
...
ygopro-server.js
View file @
bba69ea7
// Generated by CoffeeScript 1.9.3
(
function
()
{
var
Room
,
_
,
bunyan
,
debug
,
dialogues
,
execFile
,
fs
,
http
,
http_server
,
log
,
net
,
os
,
path
,
request
,
settings
,
tips
,
url
,
ygopro
;
var
Graveyard
,
Room
,
_
,
bunyan
,
debug
,
dialogues
,
execFile
,
fs
,
http
,
http_server
,
log
,
net
,
os
,
path
,
request
,
settings
,
tips
,
tribute
,
url
,
ygopro
;
net
=
require
(
'
net
'
);
...
...
@@ -50,22 +50,30 @@
});
}
Graveyard
=
[];
/*
#定时清理关闭的连接
Graveyard = []
send_to_graveyard = (socket) ->
unless _.indexOf(Graveyard, socket)
Graveyard.push(socket)
tribute = (socket) ->
setTimeout send_to_graveyard(socket), 30000
tribute
=
function
(
socket
)
{
setTimeout
((
function
(
socket
)
{
Graveyard
.
push
(
socket
);
})(
socket
),
3000
);
};
setInterval ()->
log.info Graveyard
, 30000
*/
setInterval
(
function
()
{
var
fuck
,
i
,
j
,
k
,
l
,
len
,
len1
,
ref
,
you
;
for
(
i
=
k
=
0
,
len
=
Graveyard
.
length
;
k
<
len
;
i
=
++
k
)
{
fuck
=
Graveyard
[
i
];
if
(
Graveyard
[
i
])
{
Graveyard
[
i
].
destroy
();
}
ref
=
Graveyard
[
i
];
for
(
j
=
l
=
0
,
len1
=
ref
.
length
;
l
<
len1
;
j
=
++
l
)
{
you
=
ref
[
j
];
Graveyard
[
i
][
j
]
=
null
;
}
Graveyard
[
i
]
=
null
;
}
Graveyard
=
[];
},
3000
);
net
.
createServer
(
function
(
client
)
{
var
ctos_buffer
,
ctos_message_length
,
ctos_proto
,
server
,
stoc_buffer
,
stoc_message_length
,
stoc_proto
;
...
...
@@ -73,6 +81,7 @@
client
.
server
=
server
;
client
.
setTimeout
(
300000
);
client
.
on
(
'
close
'
,
function
(
had_error
)
{
tribute
(
client
);
if
(
!
client
.
closed
)
{
client
.
closed
=
true
;
if
(
client
.
room
)
{
...
...
@@ -82,6 +91,7 @@
server
.
end
();
});
client
.
on
(
'
error
'
,
function
(
error
)
{
tribute
(
client
);
if
(
!
client
.
closed
)
{
client
.
closed
=
error
;
if
(
client
.
room
)
{
...
...
@@ -94,6 +104,7 @@
server
.
end
();
});
server
.
on
(
'
close
'
,
function
(
had_error
)
{
tribute
(
server
);
if
(
!
server
.
closed
)
{
server
.
closed
=
true
;
}
...
...
@@ -103,6 +114,7 @@
}
});
server
.
on
(
'
error
'
,
function
(
error
)
{
tribute
(
server
);
server
.
closed
=
error
;
if
(
!
client
.
closed
)
{
ygopro
.
stoc_send_chat
(
client
,
"
服务器错误:
"
+
error
);
...
...
@@ -114,16 +126,12 @@
ctos_proto
=
0
;
client
.
pre_establish_buffers
=
new
Array
();
client
.
on
(
'
data
'
,
function
(
data
)
{
var
b
,
struct
;
var
b
,
buffer
,
cancel
,
datas
,
k
,
l
,
len
,
len1
,
struct
;
if
(
client
.
is_post_watcher
)
{
client
.
room
.
watcher
.
write
(
data
);
}
else
{
ctos_buffer
=
Buffer
.
concat
([
ctos_buffer
,
data
],
ctos_buffer
.
length
+
data
.
length
);
if
(
client
.
established
)
{
server
.
write
(
data
);
}
else
{
client
.
pre_establish_buffers
.
push
(
data
);
}
datas
=
[];
while
(
true
)
{
if
(
ctos_message_length
===
0
)
{
if
(
ctos_buffer
.
length
>=
2
)
{
...
...
@@ -139,15 +147,23 @@
}
}
else
{
if
(
ctos_buffer
.
length
>=
2
+
ctos_message_length
)
{
cancel
=
false
;
if
(
ygopro
.
ctos_follows
[
ctos_proto
])
{
b
=
ctos_buffer
.
slice
(
3
,
ctos_message_length
-
1
+
3
);
if
(
struct
=
ygopro
.
structs
[
ygopro
.
proto_structs
.
CTOS
[
ygopro
.
constants
.
CTOS
[
ctos_proto
]]])
{
struct
.
_setBuff
(
b
);
if
(
ygopro
.
ctos_follows
[
ctos_proto
].
synchronous
)
{
cancel
=
ygopro
.
ctos_follows
[
ctos_proto
].
callback
(
b
,
_
.
clone
(
struct
.
fields
),
client
,
server
);
}
else
{
ygopro
.
ctos_follows
[
ctos_proto
].
callback
(
b
,
_
.
clone
(
struct
.
fields
),
client
,
server
);
}
}
else
{
ygopro
.
ctos_follows
[
ctos_proto
].
callback
(
b
,
null
,
client
,
server
);
}
}
if
(
!
cancel
)
{
datas
.
push
(
ctos_buffer
.
slice
(
0
,
2
+
ctos_message_length
));
}
ctos_buffer
=
ctos_buffer
.
slice
(
2
+
ctos_message_length
);
ctos_message_length
=
0
;
ctos_proto
=
0
;
...
...
@@ -156,6 +172,17 @@
}
}
}
if
(
client
.
established
)
{
for
(
k
=
0
,
len
=
datas
.
length
;
k
<
len
;
k
++
)
{
buffer
=
datas
[
k
];
server
.
write
(
buffer
);
}
}
else
{
for
(
l
=
0
,
len1
=
datas
.
length
;
l
<
len1
;
l
++
)
{
buffer
=
datas
[
l
];
client
.
pre_establish_buffers
.
push
(
buffer
);
}
}
}
});
stoc_buffer
=
new
Buffer
(
0
);
...
...
@@ -204,11 +231,18 @@
});
ygopro
.
ctos_follow
(
'
PLAYER_INFO
'
,
true
,
function
(
buffer
,
info
,
client
,
server
)
{
client
.
name
=
info
.
name
;
var
name
,
struct
;
name
=
info
.
name
.
split
(
"
$
"
)[
0
];
struct
=
ygopro
.
structs
[
"
CTOS_PlayerInfo
"
];
struct
.
_setBuff
(
buffer
);
struct
.
set
(
"
name
"
,
name
);
buffer
=
struct
.
buffer
;
client
.
name
=
name
;
return
false
;
});
ygopro
.
ctos_follow
(
'
JOIN_GAME
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
j
,
len
,
ref
;
var
k
,
len
,
ref
;
if
(
settings
.
modules
.
stop
)
{
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
stop
);
ygopro
.
stoc_send
(
client
,
'
ERROR_MSG
'
,
{
...
...
@@ -257,8 +291,8 @@
ygopro
.
stoc_send_chat_to_room
(
client
.
room
,
client
.
name
+
"
加入了观战
"
);
client
.
room
.
watchers
.
push
(
client
);
ref
=
client
.
room
.
watcher_buffers
;
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
buffer
=
ref
[
j
];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
buffer
=
ref
[
k
];
client
.
write
(
buffer
);
}
ygopro
.
stoc_send_chat
(
client
,
"
观战中.
"
);
...
...
@@ -278,6 +312,9 @@
ygopro
.
stoc_follow
(
'
JOIN_GAME
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
watcher
;
if
(
!
client
.
room
)
{
return
;
}
if
(
settings
.
modules
.
welcome
)
{
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
welcome
);
}
...
...
@@ -298,11 +335,14 @@
ygopro
.
ctos_send
(
watcher
,
'
HS_TOOBSERVER
'
);
});
watcher
.
on
(
'
data
'
,
function
(
data
)
{
var
j
,
len
,
ref
,
w
;
var
k
,
len
,
ref
,
w
;
if
(
!
client
.
room
)
{
return
;
}
client
.
room
.
watcher_buffers
.
push
(
data
);
ref
=
client
.
room
.
watchers
;
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
w
=
ref
[
j
];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
w
=
ref
[
k
];
if
(
w
)
{
w
.
write
(
data
);
}
...
...
@@ -329,24 +369,22 @@
}
ygopro
.
stoc_follow
(
'
GAME_MSG
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
card
,
j
,
len
,
line
,
msg
,
playertype
,
pos
,
reason
,
ref
,
ref1
,
ref2
,
val
;
var
card
,
k
,
len
,
line
,
msg
,
playertype
,
pos
,
ref
,
ref1
,
ref2
,
val
;
msg
=
buffer
.
readInt8
(
0
);
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
START
'
)
{
playertype
=
buffer
.
readUInt8
(
1
);
client
.
is_first
=
!
(
playertype
&
0xf
);
client
.
lp
=
client
.
room
.
hostinfo
.
start_lp
;
}
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
WIN
'
&&
_
.
startsWith
(
client
.
room
.
name
,
'
M#
'
)
&&
client
.
is_host
)
{
pos
=
buffer
.
readUInt8
(
1
);
if
(
!
(
client
.
is_first
||
pos
===
2
))
{
pos
=
1
-
pos
;
}
reason
=
buffer
.
readUInt8
(
2
);
client
.
room
.
duels
.
push
({
winner
:
pos
,
reason
:
reason
});
}
/*
if ygopro.constants.MSG[msg] == 'WIN' and _.startsWith(client.room.name, 'M#') and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first or pos == 2
reason = buffer.readUInt8(2)
#log.info {winner: pos, reason: reason}
client.room.duels.push {winner: pos, reason: reason}
*/
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
DAMAGE
'
&&
client
.
is_host
)
{
pos
=
buffer
.
readUInt8
(
1
);
if
(
!
client
.
is_first
)
{
...
...
@@ -390,8 +428,8 @@
card
=
buffer
.
readUInt32LE
(
1
);
if
(
dialogues
[
card
])
{
ref2
=
_
.
lines
(
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]);
for
(
j
=
0
,
len
=
ref2
.
length
;
j
<
len
;
j
++
)
{
line
=
ref2
[
j
];
for
(
k
=
0
,
len
=
ref2
.
length
;
k
<
len
;
k
++
)
{
line
=
ref2
[
k
];
ygopro
.
stoc_send_chat
(
client
,
line
);
}
}
...
...
@@ -425,14 +463,16 @@
}
ygopro
.
stoc_follow
(
'
DUEL_START
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
j
,
len
,
player
,
ref
;
var
k
,
len
,
player
,
ref
;
if
(
!
client
.
room
)
{
return
;
}
if
(
!
client
.
room
.
started
)
{
client
.
room
.
started
=
true
;
client
.
room
.
duels
=
[];
client
.
room
.
dueling_players
=
[];
ref
=
client
.
room
.
players
;
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
player
=
ref
[
j
];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
player
=
ref
[
k
];
if
(
player
.
pos
!==
7
)
{
client
.
room
.
dueling_players
[
player
.
pos
]
=
player
;
}
...
...
@@ -443,7 +483,9 @@
}
});
ygopro
.
ctos_follow
(
'
CHAT
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
ygopro
.
ctos_follow
(
'
CHAT
'
,
true
,
function
(
buffer
,
info
,
client
,
server
)
{
var
cancel
;
cancel
=
_
.
startsWith
(
_
.
trim
(
info
.
msg
),
"
/
"
);
switch
(
_
.
trim
(
info
.
msg
))
{
case
'
/ping
'
:
execFile
(
'
ss
'
,
[
'
-it
'
,
"
dst
"
+
client
.
remoteAddress
+
"
:
"
+
client
.
remotePort
],
function
(
error
,
stdout
,
stderr
)
{
...
...
@@ -472,22 +514,23 @@
ygopro
.
stoc_send_random_tip
(
client
);
}
}
return
cancel
;
});
ygopro
.
ctos_follow
(
'
UPDATE_DECK
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
i
,
main
,
side
;
main
=
(
function
()
{
var
j
,
ref
,
results
;
var
k
,
ref
,
results
;
results
=
[];
for
(
i
=
j
=
0
,
ref
=
info
.
mainc
;
0
<=
ref
?
j
<
ref
:
j
>
ref
;
i
=
0
<=
ref
?
++
j
:
--
j
)
{
for
(
i
=
k
=
0
,
ref
=
info
.
mainc
;
0
<=
ref
?
k
<
ref
:
k
>
ref
;
i
=
0
<=
ref
?
++
k
:
--
k
)
{
results
.
push
(
info
.
deckbuf
[
i
]);
}
return
results
;
})();
side
=
(
function
()
{
var
j
,
ref
,
ref1
,
results
;
var
k
,
ref
,
ref1
,
results
;
results
=
[];
for
(
i
=
j
=
ref
=
info
.
mainc
,
ref1
=
info
.
mainc
+
info
.
sidec
;
ref
<=
ref1
?
j
<
ref1
:
j
>
ref1
;
i
=
ref
<=
ref1
?
++
j
:
--
j
)
{
for
(
i
=
k
=
ref
=
info
.
mainc
,
ref1
=
info
.
mainc
+
info
.
sidec
;
ref
<=
ref1
?
k
<
ref1
:
k
>
ref1
;
i
=
ref
<=
ref1
?
++
k
:
--
k
)
{
results
.
push
(
info
.
deckbuf
[
i
]);
}
return
results
;
...
...
@@ -496,22 +539,9 @@
client
.
side
=
side
;
});
/*
if settings.modules.skip_empty_side
ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
if client.side
ygopro.ctos_send server, 'UPDATE_DECK', {
mainc: client.main.length,
sidec: 0,
deckbuf: client.main
}
ygopro.stoc_send_chat client, '等待更换副卡组中...'
*/
if
(
settings
.
modules
.
http
)
{
http_server
=
http
.
createServer
(
function
(
request
,
response
)
{
var
j
,
len
,
player
,
ref
,
room
,
roomsjson
,
u
;
var
k
,
len
,
player
,
ref
,
room
,
roomsjson
,
u
;
u
=
url
.
parse
(
request
.
url
,
1
);
if
(
u
.
pathname
===
'
/count.json
'
)
{
response
.
writeHead
(
200
);
...
...
@@ -520,22 +550,22 @@
response
.
writeHead
(
200
);
roomsjson
=
JSON
.
stringify
({
rooms
:
(
function
()
{
var
j
,
len
,
ref
,
results
;
var
k
,
len
,
ref
,
results
;
ref
=
Room
.
all
;
results
=
[];
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
room
=
ref
[
j
];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
room
=
ref
[
k
];
if
(
room
.
established
)
{
results
.
push
({
roomid
:
room
.
port
.
toString
(),
roomname
:
room
.
name
.
split
(
'
$
'
,
2
)[
0
],
needpass
:
(
room
.
name
.
indexOf
(
'
$
'
)
!==
-
1
).
toString
(),
users
:
(
function
()
{
var
k
,
len1
,
ref1
,
results1
;
var
l
,
len1
,
ref1
,
results1
;
ref1
=
room
.
players
;
results1
=
[];
for
(
k
=
0
,
len1
=
ref1
.
length
;
k
<
len1
;
k
++
)
{
player
=
ref1
[
k
];
for
(
l
=
0
,
len1
=
ref1
.
length
;
l
<
len1
;
l
++
)
{
player
=
ref1
[
l
];
if
(
player
.
pos
!=
null
)
{
results1
.
push
({
id
:
(
-
1
).
toString
(),
...
...
@@ -558,22 +588,22 @@
response
.
writeHead
(
200
);
response
.
end
(
JSON
.
stringify
({
rooms
:
(
function
()
{
var
j
,
len
,
ref
,
results
;
var
k
,
len
,
ref
,
results
;
ref
=
Room
.
all
;
results
=
[];
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
room
=
ref
[
j
];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
room
=
ref
[
k
];
if
(
room
.
established
)
{
results
.
push
({
roomid
:
room
.
port
.
toString
(),
roomname
:
room
.
name
.
split
(
'
$
'
,
2
)[
0
],
needpass
:
(
room
.
name
.
indexOf
(
'
$
'
)
!==
-
1
).
toString
(),
users
:
(
function
()
{
var
k
,
len1
,
ref1
,
results1
;
var
l
,
len1
,
ref1
,
results1
;
ref1
=
room
.
players
;
results1
=
[];
for
(
k
=
0
,
len1
=
ref1
.
length
;
k
<
len1
;
k
++
)
{
player
=
ref1
[
k
];
for
(
l
=
0
,
len1
=
ref1
.
length
;
l
<
len1
;
l
++
)
{
player
=
ref1
[
l
];
if
(
player
.
pos
!=
null
)
{
results1
.
push
({
id
:
(
-
1
).
toString
(),
...
...
@@ -593,12 +623,20 @@
}));
}
else
if
(
u
.
query
.
pass
===
settings
.
modules
.
http
.
password
&&
u
.
query
.
shout
)
{
ref
=
Room
.
all
;
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
room
=
ref
[
j
];
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
room
=
ref
[
k
];
ygopro
.
stoc_send_chat_to_room
(
room
,
u
.
query
.
shout
);
}
response
.
writeHead
(
200
);
response
.
end
(
"
shout
"
+
u
.
query
.
shout
+
"
ok
"
);
}
else
if
(
u
.
query
.
pass
===
settings
.
modules
.
http
.
password
&&
u
.
query
.
stop
)
{
settings
.
modules
.
stop
=
u
.
query
.
stop
;
response
.
writeHead
(
200
);
response
.
end
(
"
stop
"
+
u
.
query
.
shout
+
"
ok
"
);
}
else
if
(
u
.
query
.
pass
===
settings
.
modules
.
http
.
password
&&
u
.
query
.
welcome
)
{
settings
.
modules
.
welcome
=
u
.
query
.
welcome
;
response
.
writeHead
(
200
);
response
.
end
(
"
welcome
"
+
u
.
query
.
shout
+
"
ok
"
);
}
else
{
response
.
writeHead
(
404
);
response
.
end
();
...
...
ygopro.coffee
View file @
bba69ea7
...
...
@@ -110,6 +110,9 @@ for name, declaration of structs_declaration
#util
@
stoc_send_chat
=
(
client
,
msg
,
player
=
8
)
->
if
!
client
console
.
log
"err stoc_send_chat"
return
for
line
in
_
.
lines
(
msg
)
@
stoc_send
client
,
'CHAT'
,
{
player
:
player
...
...
@@ -118,6 +121,9 @@ for name, declaration of structs_declaration
return
@
stoc_send_chat_to_room
=
(
room
,
msg
,
player
=
8
)
->
if
!
room
console
.
log
"err stoc_send_chat_to_room"
return
for
client
in
room
.
players
@
stoc_send_chat
(
client
,
msg
,
player
)
if
client
for
client
in
room
.
watchers
...
...
ygopro.js
View file @
bba69ea7
...
...
@@ -171,6 +171,10 @@
if
(
player
==
null
)
{
player
=
8
;
}
if
(
!
client
)
{
console
.
log
(
"
err stoc_send_chat
"
);
return
;
}
ref
=
_
.
lines
(
msg
);
for
(
j
=
0
,
len1
=
ref
.
length
;
j
<
len1
;
j
++
)
{
line
=
ref
[
j
];
...
...
@@ -186,6 +190,10 @@
if
(
player
==
null
)
{
player
=
8
;
}
if
(
!
room
)
{
console
.
log
(
"
err stoc_send_chat_to_room
"
);
return
;
}
ref
=
room
.
players
;
for
(
j
=
0
,
len1
=
ref
.
length
;
j
<
len1
;
j
++
)
{
client
=
ref
[
j
];
...
...
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