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
03fa19c8
Commit
03fa19c8
authored
Jan 10, 2017
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test geoip
parent
66fd1cd1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
49 deletions
+87
-49
config.json
config.json
+10
-1
ygopro-server.coffee
ygopro-server.coffee
+32
-19
ygopro-server.js
ygopro-server.js
+45
-29
No files found.
config.json
View file @
03fa19c8
...
...
@@ -18,7 +18,16 @@
"welcome"
:
"MyCard YGOPro Server"
,
"update"
:
"请更新游戏版本"
,
"stop"
:
false
,
"lang"
:
"zh-cn"
,
"i18n"
:
{
"auto_pick"
:
true
,
"default"
:
"zh-cn"
,
"fallback"
:
"en-us"
,
"map"
:
{
"CN"
:
"zh-cn"
,
"HK"
:
"zh-cn"
,
"TW"
:
"zh-cn"
}
},
"tips"
:
{
"enabled"
:
true
,
"get"
:
false
...
...
ygopro-server.coffee
View file @
03fa19c8
...
...
@@ -66,22 +66,6 @@ nconf.myset = (settings, path, val) ->
target
[
key
]
=
val
return
# ban a user manually and permanently
ban_user
=
(
name
)
->
settings
.
ban
.
banned_user
.
push
(
name
)
nconf
.
myset
(
settings
,
"ban:banned_user"
,
settings
.
ban
.
banned_user
)
bad_ip
=
0
for
room
in
ROOM_all
when
room
and
room
.
established
for
player
in
room
.
players
if
player
and
(
player
.
name
==
name
or
player
.
ip
==
bad_ip
)
bad_ip
=
player
.
ip
ROOM_bad_ip
[
bad_ip
]
=
99
settings
.
ban
.
banned_ip
.
push
(
player
.
ip
)
ygopro
.
stoc_send_chat_to_room
(
room
,
"
#{
player
.
name
}
${kicked_by_system}"
,
ygopro
.
constants
.
COLORS
.
RED
)
player
.
destroy
()
continue
return
try
cppversion
=
parseInt
(
fs
.
readFileSync
(
'ygopro/gframe/game.cpp'
,
'utf8'
).
match
(
/PRO_VERSION = ([x\dABCDEF]+)/
)[
1
],
'16'
)
nconf
.
myset
(
settings
,
"version"
,
cppversion
)
...
...
@@ -110,6 +94,9 @@ if settings.modules.windbot.enabled
ygopro
=
require
'./ygopro.js'
roomlist
=
require
'./roomlist.js'
if
settings
.
modules
.
http
.
websocket_roomlist
if
settings
.
modules
.
i18n
.
auto_pick
geoip
=
require
(
'geoip-country-lite'
)
# cache users of mycard login
users_cache
=
{}
...
...
@@ -152,6 +139,22 @@ ROOM_players_banned = []
ROOM_connected_ip
=
{}
ROOM_bad_ip
=
{}
# ban a user manually and permanently
ban_user
=
(
name
)
->
settings
.
ban
.
banned_user
.
push
(
name
)
nconf
.
myset
(
settings
,
"ban:banned_user"
,
settings
.
ban
.
banned_user
)
bad_ip
=
0
for
room
in
ROOM_all
when
room
and
room
.
established
for
player
in
room
.
players
if
player
and
(
player
.
name
==
name
or
player
.
ip
==
bad_ip
)
bad_ip
=
player
.
ip
ROOM_bad_ip
[
bad_ip
]
=
99
settings
.
ban
.
banned_ip
.
push
(
player
.
ip
)
ygopro
.
stoc_send_chat_to_room
(
room
,
"
#{
player
.
name
}
${kicked_by_system}"
,
ygopro
.
constants
.
COLORS
.
RED
)
player
.
destroy
()
continue
return
# automatically ban user to use random duel
ROOM_ban_player
=
(
name
,
ip
,
reason
,
countadd
=
1
)
->
bannedplayer
=
_
.
find
ROOM_players_banned
,
(
bannedplayer
)
->
...
...
@@ -821,9 +824,19 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
buffer
=
struct
.
buffer
client
.
name
=
name
client
.
lang
=
settings
.
modules
.
lang
if
name
==
"P233"
client
.
lang
=
"en-us"
if
not
settings
.
modules
.
i18n
.
auto_pick
client
.
lang
=
settings
.
modules
.
i18n
.
default
else
geo
=
geoip
.
lookup
(
client
.
ip
)
if
not
geo
log
.
warn
(
"fail to locate ip"
,
client
.
ip
)
client
.
lang
=
settings
.
modules
.
i18n
.
fallback
else
if
lang
=
settings
.
modules
.
i18n
.
map
[
geo
.
country
]
client
.
lang
=
lang
else
log
.
info
(
"TMP: not in china"
,
client
.
ip
)
client
.
lang
=
settings
.
modules
.
i18n
.
fallback
return
false
ygopro
.
ctos_follow
'JOIN_GAME'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
...
...
ygopro-server.js
View file @
03fa19c8
// Generated by CoffeeScript 1.12.1
(
function
()
{
var
Cloud_replay_ids
,
ROOM_all
,
ROOM_bad_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
,
_
,
addCallback
,
ban_user
,
bunyan
,
cppversion
,
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
,
pgClient
,
pg_client
,
pg_query
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
url
,
users_cache
,
wait_room_start
,
windbot_process
,
ygopro
,
zlib
;
var
Cloud_replay_ids
,
ROOM_all
,
ROOM_bad_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
,
_
,
addCallback
,
ban_user
,
bunyan
,
cppversion
,
crypto
,
date
,
defaultconfig
,
execFile
,
fs
,
ge
oip
,
ge
t_memory_usage
,
http
,
http_server
,
https
,
https_server
,
list
,
load_dialogues
,
load_tips
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pgClient
,
pg_client
,
pg_query
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
url
,
users_cache
,
wait_room_start
,
windbot_process
,
ygopro
,
zlib
;
net
=
require
(
'
net
'
);
...
...
@@ -87,30 +87,6 @@
}
};
ban_user
=
function
(
name
)
{
var
bad_ip
,
j
,
k
,
len
,
len1
,
player
,
ref
,
room
;
settings
.
ban
.
banned_user
.
push
(
name
);
nconf
.
myset
(
settings
,
"
ban:banned_user
"
,
settings
.
ban
.
banned_user
);
bad_ip
=
0
;
for
(
j
=
0
,
len
=
ROOM_all
.
length
;
j
<
len
;
j
++
)
{
room
=
ROOM_all
[
j
];
if
(
room
&&
room
.
established
)
{
ref
=
room
.
players
;
for
(
k
=
0
,
len1
=
ref
.
length
;
k
<
len1
;
k
++
)
{
player
=
ref
[
k
];
if
(
player
&&
(
player
.
name
===
name
||
player
.
ip
===
bad_ip
))
{
bad_ip
=
player
.
ip
;
ROOM_bad_ip
[
bad_ip
]
=
99
;
settings
.
ban
.
banned_ip
.
push
(
player
.
ip
);
ygopro
.
stoc_send_chat_to_room
(
room
,
player
.
name
+
"
${kicked_by_system}
"
,
ygopro
.
constants
.
COLORS
.
RED
);
player
.
destroy
();
continue
;
}
}
}
}
};
try
{
cppversion
=
parseInt
(
fs
.
readFileSync
(
'
ygopro/gframe/game.cpp
'
,
'
utf8
'
).
match
(
/PRO_VERSION =
([
x
\d
ABCDEF
]
+
)
/
)[
1
],
'
16
'
);
nconf
.
myset
(
settings
,
"
version
"
,
cppversion
);
...
...
@@ -159,6 +135,10 @@
roomlist
=
require
(
'
./roomlist.js
'
);
}
if
(
settings
.
modules
.
i18n
.
auto_pick
)
{
geoip
=
require
(
'
geoip-country-lite
'
);
}
users_cache
=
{};
if
(
settings
.
modules
.
mycard
.
enabled
)
{
...
...
@@ -206,6 +186,30 @@
ROOM_bad_ip
=
{};
ban_user
=
function
(
name
)
{
var
bad_ip
,
j
,
k
,
len
,
len1
,
player
,
ref
,
room
;
settings
.
ban
.
banned_user
.
push
(
name
);
nconf
.
myset
(
settings
,
"
ban:banned_user
"
,
settings
.
ban
.
banned_user
);
bad_ip
=
0
;
for
(
j
=
0
,
len
=
ROOM_all
.
length
;
j
<
len
;
j
++
)
{
room
=
ROOM_all
[
j
];
if
(
room
&&
room
.
established
)
{
ref
=
room
.
players
;
for
(
k
=
0
,
len1
=
ref
.
length
;
k
<
len1
;
k
++
)
{
player
=
ref
[
k
];
if
(
player
&&
(
player
.
name
===
name
||
player
.
ip
===
bad_ip
))
{
bad_ip
=
player
.
ip
;
ROOM_bad_ip
[
bad_ip
]
=
99
;
settings
.
ban
.
banned_ip
.
push
(
player
.
ip
);
ygopro
.
stoc_send_chat_to_room
(
room
,
player
.
name
+
"
${kicked_by_system}
"
,
ygopro
.
constants
.
COLORS
.
RED
);
player
.
destroy
();
continue
;
}
}
}
}
};
ROOM_ban_player
=
function
(
name
,
ip
,
reason
,
countadd
)
{
var
bannedplayer
,
bantime
;
if
(
countadd
==
null
)
{
...
...
@@ -1016,7 +1020,7 @@
});
ygopro
.
ctos_follow
(
'
PLAYER_INFO
'
,
true
,
function
(
buffer
,
info
,
client
,
server
)
{
var
name
,
struct
;
var
geo
,
lang
,
name
,
struct
;
name
=
info
.
name
.
split
(
"
$
"
)[
0
];
if
(
_
.
any
(
settings
.
ban
.
illegal_id
,
function
(
badid
)
{
var
matchs
,
regexp
;
...
...
@@ -1035,9 +1039,21 @@
struct
.
set
(
"
name
"
,
name
);
buffer
=
struct
.
buffer
;
client
.
name
=
name
;
client
.
lang
=
settings
.
modules
.
lang
;
if
(
name
===
"
P233
"
)
{
client
.
lang
=
"
en-us
"
;
if
(
!
settings
.
modules
.
i18n
.
auto_pick
)
{
client
.
lang
=
settings
.
modules
.
i18n
[
"
default
"
];
}
else
{
geo
=
geoip
.
lookup
(
client
.
ip
);
if
(
!
geo
)
{
log
.
warn
(
"
fail to locate ip
"
,
client
.
ip
);
client
.
lang
=
settings
.
modules
.
i18n
.
fallback
;
}
else
{
if
(
lang
=
settings
.
modules
.
i18n
.
map
[
geo
.
country
])
{
client
.
lang
=
lang
;
}
else
{
log
.
info
(
"
TMP: not in china
"
,
client
.
ip
);
client
.
lang
=
settings
.
modules
.
i18n
.
fallback
;
}
}
}
return
false
;
});
...
...
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