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
b4d79dac
Commit
b4d79dac
authored
Aug 16, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ban bad connection
parent
94c494dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
13 deletions
+86
-13
ygopro-server.coffee
ygopro-server.coffee
+38
-4
ygopro-server.js
ygopro-server.js
+48
-9
No files found.
ygopro-server.coffee
View file @
b4d79dac
...
...
@@ -142,6 +142,8 @@ Cloud_replay_ids = []
ROOM_all
=
[]
ROOM_players_oppentlist
=
{}
ROOM_players_banned
=
[]
ROOM_connected_ip
=
{}
ROOM_bad_ip
=
{}
# automatically ban user to use random duel
ROOM_ban_player
=
(
name
,
ip
,
reason
,
countadd
=
1
)
->
...
...
@@ -539,6 +541,13 @@ class Room
connect
:
(
client
)
->
@
players
.
push
client
client
.
ip
=
client
.
remoteAddress
connect_count
=
0
if
client
.
remoteAddress
!=
'::ffff:127.0.0.1'
if
connect_count
=
ROOM_connected_ip
[
client
.
remoteAddress
]
connect_count
++
else
connect_count
=
1
ROOM_connected_ip
[
client
.
remoteAddress
]
=
connect_count
if
@
random_type
client
.
abuse_count
=
0
host_player
=
@
get_host
()
...
...
@@ -594,6 +603,10 @@ net.createServer (client) ->
client
.
on
'close'
,
(
had_error
)
->
#log.info "client closed", client.name, had_error
room
=
ROOM_all
[
client
.
rid
]
connect_count
=
ROOM_connected_ip
[
client
.
ip
]
if
connect_count
>
0
connect_count
--
ROOM_connected_ip
[
client
.
ip
]
=
connect_count
tribute
(
client
)
unless
client
.
closed
client
.
closed
=
true
...
...
@@ -604,6 +617,10 @@ net.createServer (client) ->
client
.
on
'error'
,
(
error
)
->
#log.info "client error", client.name, error
room
=
ROOM_all
[
client
.
rid
]
connect_count
=
ROOM_connected_ip
[
client
.
ip
]
if
connect_count
>
0
connect_count
--
ROOM_connected_ip
[
client
.
ip
]
=
connect_count
tribute
(
client
)
unless
client
.
closed
client
.
closed
=
error
...
...
@@ -637,6 +654,11 @@ net.createServer (client) ->
client
.
end
()
return
if
ROOM_bad_ip
[
client
.
remoteAddress
]
>
5
log
.
info
'BAD IP'
,
client
.
remoteAddress
client
.
end
()
return
if
settings
.
modules
.
enable_cloud_replay
client
.
open_cloud_replay
=
(
err
,
replay
)
->
if
err
or
!
replay
...
...
@@ -709,8 +731,13 @@ net.createServer (client) ->
looplimit
++
#log.info(looplimit)
if
looplimit
>
800
log
.
info
(
"error ctos"
,
client
.
name
)
if
looplimit
>
800
or
ROOM_bad_ip
[
client
.
remoteAddress
]
>
5
or
ROOM_connected_ip
[
client
.
remoteAddress
]
>
10
log
.
info
(
"error ctos"
,
client
.
name
,
client
.
remoteAddress
)
bad_ip_count
=
ROOM_bad_ip
[
client
.
remoteAddress
]
if
bad_ip_count
ROOM_bad_ip
[
client
.
remoteAddress
]
=
bad_ip_count
+
1
else
ROOM_bad_ip
[
client
.
remoteAddress
]
=
1
server
.
end
()
break
...
...
@@ -964,9 +991,13 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
users_cache
[
client
.
name
]
=
body
.
user
.
id
finish
(
buffer
)
else
if
!
client
.
name
or
client
.
name
==
""
ygopro
.
stoc_die
(
client
,
"请输入正确的用户名"
)
else
if
info
.
pass
.
length
&&
!
ROOM_validate
(
info
.
pass
)
ygopro
.
stoc_die
(
client
,
"房间密码不正确"
)
else
if
ROOM_connected_ip
[
client
.
remoteAddress
]
>
10
log
.
warn
(
"MULTI LOGIN"
,
client
.
name
,
client
.
remoteAddress
)
ygopro
.
stoc_die
(
client
,
"同时开启的客户端数量过多 "
+
client
.
remoteAddress
)
else
if
_
.
indexOf
(
settings
.
ban
.
banned_user
,
client
.
name
)
>
-
1
#账号被封
settings
.
ban
.
banned_ip
.
push
(
client
.
remoteAddress
)
...
...
@@ -997,6 +1028,9 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
,
name
=
client
.
name
)
log
.
warn
(
"BAD NAME LEVEL 1"
,
client
.
name
,
client
.
remoteAddress
)
ygopro
.
stoc_die
(
client
,
"您的用户名存在不适当的内容,请注意更改"
)
else
if
info
.
pass
.
length
&&
!
ROOM_validate
(
info
.
pass
)
ygopro
.
stoc_die
(
client
,
"房间密码不正确"
)
else
if
info
.
version
==
4921
#YGOMobile不更新,强行兼容
...
...
ygopro-server.js
View file @
b4d79dac
// Generated by CoffeeScript 1.10.0
(
function
()
{
var
Cloud_replay_ids
,
Graveyard
,
ROOM_all
,
ROOM_ba
n_player
,
ROOM_find_by_name
,
ROOM_find_by_port
,
ROOM_find_or_create_ai
,
ROOM_find_or_create_by_name
,
ROOM_find_or_create_random
,
ROOM_players_banned
,
ROOM_players_oppentlist
,
ROOM_validate
,
Room
,
_
,
ban_user
,
bunyan
,
crypto
,
date
,
defaultconfig
,
execFile
,
fs
,
get_memory_usage
,
http
,
http_server
,
https
,
https_server
,
list
,
load_dialogues
,
load_tips
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pg
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
tribute
,
url
,
users_cache
,
wait_room_start
,
ygopro
,
zlib
;
var
Cloud_replay_ids
,
Graveyard
,
ROOM_all
,
ROOM_ba
d_ip
,
ROOM_ban_player
,
ROOM_connected_ip
,
ROOM_find_by_name
,
ROOM_find_by_port
,
ROOM_find_or_create_ai
,
ROOM_find_or_create_by_name
,
ROOM_find_or_create_random
,
ROOM_players_banned
,
ROOM_players_oppentlist
,
ROOM_validate
,
Room
,
_
,
ban_user
,
bunyan
,
crypto
,
date
,
defaultconfig
,
execFile
,
fs
,
get_memory_usage
,
http
,
http_server
,
https
,
https_server
,
list
,
load_dialogues
,
load_tips
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pg
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
tribute
,
url
,
users_cache
,
wait_room_start
,
ygopro
,
zlib
;
net
=
require
(
'
net
'
);
...
...
@@ -200,6 +200,10 @@
ROOM_players_banned
=
[];
ROOM_connected_ip
=
{};
ROOM_bad_ip
=
{};
ROOM_ban_player
=
function
(
name
,
ip
,
reason
,
countadd
)
{
var
bannedplayer
,
bantime
;
if
(
countadd
==
null
)
{
...
...
@@ -710,9 +714,18 @@
};
Room
.
prototype
.
connect
=
function
(
client
)
{
var
host_player
;
var
connect_count
,
host_player
;
this
.
players
.
push
(
client
);
client
.
ip
=
client
.
remoteAddress
;
connect_count
=
0
;
if
(
client
.
remoteAddress
!==
'
::ffff:127.0.0.1
'
)
{
if
(
connect_count
=
ROOM_connected_ip
[
client
.
remoteAddress
])
{
connect_count
++
;
}
else
{
connect_count
=
1
;
}
}
ROOM_connected_ip
[
client
.
remoteAddress
]
=
connect_count
;
if
(
this
.
random_type
)
{
client
.
abuse_count
=
0
;
host_player
=
this
.
get_host
();
...
...
@@ -778,8 +791,13 @@
client
.
server
=
server
;
client
.
setTimeout
(
300000
);
client
.
on
(
'
close
'
,
function
(
had_error
)
{
var
room
;
var
connect_count
,
room
;
room
=
ROOM_all
[
client
.
rid
];
connect_count
=
ROOM_connected_ip
[
client
.
ip
];
if
(
connect_count
>
0
)
{
connect_count
--
;
}
ROOM_connected_ip
[
client
.
ip
]
=
connect_count
;
tribute
(
client
);
if
(
!
client
.
closed
)
{
client
.
closed
=
true
;
...
...
@@ -790,8 +808,13 @@
server
.
end
();
});
client
.
on
(
'
error
'
,
function
(
error
)
{
var
room
;
var
connect_count
,
room
;
room
=
ROOM_all
[
client
.
rid
];
connect_count
=
ROOM_connected_ip
[
client
.
ip
];
if
(
connect_count
>
0
)
{
connect_count
--
;
}
ROOM_connected_ip
[
client
.
ip
]
=
connect_count
;
tribute
(
client
);
if
(
!
client
.
closed
)
{
client
.
closed
=
error
;
...
...
@@ -832,6 +855,11 @@
client
.
end
();
}
});
if
(
ROOM_bad_ip
[
client
.
remoteAddress
]
>
5
)
{
log
.
info
(
'
BAD IP
'
,
client
.
remoteAddress
);
client
.
end
();
return
;
}
if
(
settings
.
modules
.
enable_cloud_replay
)
{
client
.
open_cloud_replay
=
function
(
err
,
replay
)
{
var
buffer
;
...
...
@@ -856,7 +884,7 @@
}
client
.
pre_establish_buffers
=
new
Array
();
client
.
on
(
'
data
'
,
function
(
data
)
{
var
b
,
buffer
,
cancel
,
ctos_buffer
,
ctos_message_length
,
ctos_proto
,
datas
,
k
,
l
,
len
,
len1
,
looplimit
,
room
,
struct
;
var
b
,
b
ad_ip_count
,
b
uffer
,
cancel
,
ctos_buffer
,
ctos_message_length
,
ctos_proto
,
datas
,
k
,
l
,
len
,
len1
,
looplimit
,
room
,
struct
;
if
(
client
.
is_post_watcher
)
{
room
=
ROOM_all
[
client
.
rid
];
if
(
room
)
{
...
...
@@ -909,8 +937,14 @@
}
}
looplimit
++
;
if
(
looplimit
>
800
)
{
log
.
info
(
"
error ctos
"
,
client
.
name
);
if
(
looplimit
>
800
||
ROOM_bad_ip
[
client
.
remoteAddress
]
>
5
||
ROOM_connected_ip
[
client
.
remoteAddress
]
>
10
)
{
log
.
info
(
"
error ctos
"
,
client
.
name
,
client
.
remoteAddress
);
bad_ip_count
=
ROOM_bad_ip
[
client
.
remoteAddress
];
if
(
bad_ip_count
)
{
ROOM_bad_ip
[
client
.
remoteAddress
]
=
bad_ip_count
+
1
;
}
else
{
ROOM_bad_ip
[
client
.
remoteAddress
]
=
1
;
}
server
.
end
();
break
;
}
...
...
@@ -1186,8 +1220,11 @@
users_cache
[
client
.
name
]
=
body
.
user
.
id
;
return
finish
(
buffer
);
});
}
else
if
(
info
.
pass
.
length
&&
!
ROOM_validate
(
info
.
pass
))
{
ygopro
.
stoc_die
(
client
,
"
房间密码不正确
"
);
}
else
if
(
!
client
.
name
||
client
.
name
===
""
)
{
ygopro
.
stoc_die
(
client
,
"
请输入正确的用户名
"
);
}
else
if
(
ROOM_connected_ip
[
client
.
remoteAddress
]
>
10
)
{
log
.
warn
(
"
MULTI LOGIN
"
,
client
.
name
,
client
.
remoteAddress
);
ygopro
.
stoc_die
(
client
,
"
同时开启的客户端数量过多
"
+
client
.
remoteAddress
);
}
else
if
(
_
.
indexOf
(
settings
.
ban
.
banned_user
,
client
.
name
)
>
-
1
)
{
settings
.
ban
.
banned_ip
.
push
(
client
.
remoteAddress
);
log
.
warn
(
"
BANNED USER LOGIN
"
,
client
.
name
,
client
.
remoteAddress
);
...
...
@@ -1216,6 +1253,8 @@
},
name
=
client
.
name
))
{
log
.
warn
(
"
BAD NAME LEVEL 1
"
,
client
.
name
,
client
.
remoteAddress
);
ygopro
.
stoc_die
(
client
,
"
您的用户名存在不适当的内容,请注意更改
"
);
}
else
if
(
info
.
pass
.
length
&&
!
ROOM_validate
(
info
.
pass
))
{
ygopro
.
stoc_die
(
client
,
"
房间密码不正确
"
);
}
else
{
if
(
info
.
version
===
4921
)
{
info
.
version
=
settings
.
version
;
...
...
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