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
d5b64bd1
Commit
d5b64bd1
authored
Oct 28, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add preconn detect
parent
2255fe81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
24 deletions
+24
-24
YGOProMessages.ts
YGOProMessages.ts
+5
-4
ygopro-server.coffee
ygopro-server.coffee
+9
-9
ygopro-server.js
ygopro-server.js
+10
-11
No files found.
YGOProMessages.ts
View file @
d5b64bd1
...
...
@@ -226,12 +226,13 @@ export class YGOProMessagesHelper {
handlerCollection
.
get
(
translatedProto
).
push
(
handlerObj
);
}
async
handleBuffer
(
messageBuffer
:
Buffer
,
direction
:
string
,
protoFilter
?:
string
[],
params
?:
any
,
disconnectIfInvalid
=
false
):
Promise
<
HandleResult
>
{
async
handleBuffer
(
messageBuffer
:
Buffer
,
direction
:
string
,
protoFilter
?:
string
[],
params
?:
any
,
preconnect
=
false
):
Promise
<
HandleResult
>
{
let
feedback
:
Feedback
=
null
;
let
messageLength
=
0
;
let
bufferProto
=
0
;
let
datas
:
Buffer
[]
=
[];
for
(
let
l
=
0
;
l
<
this
.
singleHandleLimit
;
++
l
)
{
const
limit
=
preconnect
?
2
:
this
.
singleHandleLimit
;
for
(
let
l
=
0
;
l
<
limit
;
++
l
)
{
if
(
messageLength
===
0
)
{
if
(
messageBuffer
.
length
>=
2
)
{
messageLength
=
messageBuffer
.
readUInt16LE
(
0
);
...
...
@@ -258,7 +259,7 @@ export class YGOProMessagesHelper {
if
(
messageBuffer
.
length
>=
2
+
messageLength
)
{
const
proto
=
this
.
constants
[
direction
][
bufferProto
];
let
cancel
=
proto
&&
protoFilter
&&
!
protoFilter
.
includes
(
proto
);
if
(
cancel
&&
disconnectIfInvalid
)
{
if
(
cancel
&&
preconnect
)
{
feedback
=
{
type
:
"
INVALID_PACKET
"
,
message
:
`
${
direction
}
proto not allowed`
...
...
@@ -303,7 +304,7 @@ export class YGOProMessagesHelper {
break
;
}
}
if
(
l
===
this
.
singleHandleL
imit
-
1
)
{
if
(
l
===
l
imit
-
1
)
{
feedback
=
{
type
:
"
OVERSIZE
"
,
message
:
`Oversized
${
direction
}
`
...
...
ygopro-server.coffee
View file @
d5b64bd1
...
...
@@ -1813,6 +1813,11 @@ netRequestHandler = (client) ->
ROOM_connected_ip
[
client
.
ip
]
=
connect_count
#log.info "connect", client.ip, ROOM_connected_ip[client.ip]
if
ROOM_bad_ip
[
client
.
ip
]
>
5
or
ROOM_connected_ip
[
client
.
ip
]
>
10
log
.
info
'BAD IP'
,
client
.
ip
client
.
destroy
()
return
# server stand for the connection to ygopro server process
server
=
new
net
.
Socket
()
client
.
server
=
server
...
...
@@ -1894,11 +1899,6 @@ netRequestHandler = (client) ->
SERVER_clear_disconnect
(
server
)
return
if
ROOM_bad_ip
[
client
.
ip
]
>
5
or
ROOM_connected_ip
[
client
.
ip
]
>
10
log
.
info
'BAD IP'
,
client
.
ip
CLIENT_kick
(
client
)
return
if
settings
.
modules
.
cloud_replay
.
enabled
client
.
open_cloud_replay
=
(
replay
)
->
if
!
replay
...
...
@@ -1944,16 +1944,16 @@ netRequestHandler = (client) ->
room
.
watcher
.
write
(
buffer
)
for
buffer
in
handle_data
.
datas
else
ctos_filter
=
null
disconnectIfInvalid
=
false
preconnect
=
false
if
settings
.
modules
.
reconnect
.
enabled
and
client
.
pre_reconnecting_to_room
ctos_filter
=
[
"UPDATE_DECK"
]
if
!
client
.
name
if
client
.
name
==
null
ctos_filter
=
[
"JOIN_GAME"
,
"PLAYER_INFO"
]
disconnectIfInvalid
=
true
preconnect
=
true
handle_data
=
await
ygopro
.
helper
.
handleBuffer
(
ctos_buffer
,
"CTOS"
,
ctos_filter
,
{
client
:
client
,
server
:
client
.
server
},
disconnectIfInvalid
)
},
preconnect
)
if
handle_data
.
feedback
log
.
warn
(
handle_data
.
feedback
.
message
,
client
.
name
,
client
.
ip
)
if
handle_data
.
feedback
.
type
==
"OVERSIZE"
or
handle_data
.
feedback
.
type
==
"INVALID_PACKET"
or
ROOM_bad_ip
[
client
.
ip
]
>
5
...
...
ygopro-server.js
View file @
d5b64bd1
...
...
@@ -2446,7 +2446,11 @@
}
ROOM_connected_ip[client.ip] = connect_count;
//log.info "connect", client.ip, ROOM_connected_ip[client.ip]
if (ROOM_bad_ip[client.ip] > 5 || ROOM_connected_ip[client.ip] > 10) {
log.info('BAD IP', client.ip);
client.destroy();
return;
}
// server stand for the connection to ygopro server process
server = new net.Socket();
client.server = server;
...
...
@@ -2546,11 +2550,6 @@
SERVER_clear_disconnect(server);
}
});
if
(
ROOM_bad_ip
[
client
.
ip
]
>
5
||
ROOM_connected_ip
[
client
.
ip
]
>
10
)
{
log
.
info
(
'
BAD IP
'
,
client
.
ip
);
CLIENT_kick
(
client
);
return
;
}
if (settings.modules.cloud_replay.enabled) {
client.open_cloud_replay = async function(replay) {
var buffer, e, replay_buffer;
...
...
@@ -2578,7 +2577,7 @@
// 客户端到服务端(ctos)协议分析
client.pre_establish_buffers = new Array();
client.on('data', async function(ctos_buffer) {
var
bad_ip_count
,
buffer
,
ctos_filter
,
disconnectIfInvalid
,
handle_data
,
j
,
l
,
len
,
len1
,
len2
,
m
,
ref
,
ref1
,
ref2
,
room
;
var bad_ip_count, buffer, ctos_filter,
handle_data, j, l, len, len1, len2, m, preconnect
, ref, ref1, ref2, room;
if (client.is_post_watcher) {
room = ROOM_all[client.rid];
if (room) {
...
...
@@ -2607,18 +2606,18 @@
}
} else {
ctos_filter = null;
disconnectIfInvalid
=
false
;
preconnect
= false;
if (settings.modules.reconnect.enabled && client.pre_reconnecting_to_room) {
ctos_filter = ["UPDATE_DECK"];
}
if
(
!
client
.
name
)
{
if (
client.name === null
) {
ctos_filter = ["JOIN_GAME", "PLAYER_INFO"];
disconnectIfInvalid
=
true
;
preconnect
= true;
}
handle_data = (await ygopro.helper.handleBuffer(ctos_buffer, "CTOS", ctos_filter, {
client: client,
server: client.server
},
disconnectIfInvalid
));
},
preconnect
));
if (handle_data.feedback) {
log.warn(handle_data.feedback.message, client.name, client.ip);
if (handle_data.feedback.type === "OVERSIZE" || handle_data.feedback.type === "INVALID_PACKET" || ROOM_bad_ip[client.ip] > 5) {
...
...
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