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
8b1eeeb0
Commit
8b1eeeb0
authored
Nov 15, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use axios to replace request
parent
72c22165
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
40 deletions
+43
-40
ygopro-server.coffee
ygopro-server.coffee
+18
-14
ygopro-server.js
ygopro-server.js
+25
-26
No files found.
ygopro-server.coffee
View file @
8b1eeeb0
...
...
@@ -174,6 +174,7 @@ settings = {}
tips
=
null
dialogues
=
null
badwords
=
null
chat_color
=
null
lflists
=
global
.
lflists
=
[]
real_windbot_server_ip
=
null
long_resolve_cards
=
[]
...
...
@@ -182,6 +183,7 @@ athleticChecker = null
users_cache
=
{}
geoip
=
null
dataManager
=
null
windbots
=
[]
disconnect_list
=
{}
# {old_client, old_server, room_id, timeout, deckbuf}
challonge
=
null
...
...
@@ -336,7 +338,7 @@ init = () ->
await
loadLFList
(
'ygopro/lflist.conf'
)
if
settings
.
modules
.
windbot
.
enabled
windbots
=
global
.
windbots
=
await
loadJSONAsync
(
settings
.
modules
.
windbot
.
botlist
).
windbots
windbots
=
global
.
windbots
=
(
await
loadJSONAsync
(
settings
.
modules
.
windbot
.
botlist
)
).
windbots
real_windbot_server_ip
=
global
.
real_windbot_server_ip
=
settings
.
modules
.
windbot
.
server_ip
if
!
settings
.
modules
.
windbot
.
server_ip
.
includes
(
"127.0.0.1"
)
dns
=
require
(
'dns'
)
...
...
@@ -486,18 +488,19 @@ init = () ->
scores_by_win
=
_
.
sortBy
(
scores_by_lose
,
(
score
)
->
return
score
[
1
].
win
).
reverse
()
# 然后胜场由低到高,再逆转,就是先排胜场再排败场
scores
=
_
.
first
(
scores_by_win
,
10
)
#log.info scores
request
.
post
{
url
:
settings
.
modules
.
random_duel
.
post_match_scores
,
form
:
{
accesskey
:
settings
.
modules
.
random_duel
.
post_match_accesskey
,
rank
:
JSON
.
stringify
(
scores
)
}},
(
error
,
response
,
body
)
=>
if
error
log
.
warn
'RANDOM SCORE POST ERROR'
,
error
else
if
response
.
statusCode
!=
204
and
response
.
statusCode
!=
200
log
.
warn
'RANDOM SCORE POST FAIL'
,
response
.
statusCode
,
response
.
statusMessage
,
body
#else
# log.info 'RANDOM SCORE POST OK', response.statusCode, response.statusMessage
return
try
await
axios
.
post
(
settings
.
modules
.
random_duel
.
post_match_scores
,
{
headers
:
{
'content-type'
:
'application/x-www-form-urlencoded'
},
data
:
qs
.
stringify
({
accesskey
:
settings
.
modules
.
random_duel
.
post_match_accesskey
,
rank
:
JSON
.
stringify
(
scores
)
responseType
:
"json"
})
})
catch
e
log
.
warn
'RANDOM SCORE POST ERROR'
,
e
.
toString
()
return
,
60000
)
...
...
@@ -534,7 +537,6 @@ init = () ->
CLIENT_kick
(
room
.
waiting_for_player
)
else
if
time_passed
>=
(
settings
.
modules
.
random_duel
.
hang_timeout
-
20
)
and
not
(
time_passed
%
10
)
ygopro
.
stoc_send_chat_to_room
(
room
,
"
#{
room
.
waiting_for_player
.
name
}
${afk_warn_part1}
#{
settings
.
modules
.
random_duel
.
hang_timeout
-
time_passed
}
${afk_warn_part2}"
,
ygopro
.
constants
.
COLORS
.
RED
)
return
if
true
# settings.modules.arena_mode.punish_quit_before_match
for
room
in
ROOM_all
when
room
and
room
.
arena
and
room
.
duel_stage
==
ygopro
.
constants
.
DUEL_STAGE
.
BEGIN
and
room
.
get_playing_player
().
length
<
2
...
...
@@ -605,6 +607,8 @@ init = () ->
require
(
plugin_path
)
log
.
info
(
"Plugin loaded:"
,
plugin_filename
)
return
# 获取可用内存
memory_usage
=
global
.
memory_usage
=
0
get_memory_usage
=
global
.
get_memory_usage
=
()
->
...
...
ygopro-server.js
View file @
8b1eeeb0
// Generated by CoffeeScript 2.5.1
(
function
()
{
// 标准库
var
CLIENT_get_authorize_key
,
CLIENT_get_kick_reconnect_target
,
CLIENT_heartbeat_register
,
CLIENT_heartbeat_unregister
,
CLIENT_import_data
,
CLIENT_is_able_to_kick_reconnect
,
CLIENT_is_able_to_reconnect
,
CLIENT_is_banned_by_mc
,
CLIENT_is_player
,
CLIENT_kick
,
CLIENT_kick_reconnect
,
CLIENT_pre_reconnect
,
CLIENT_reconnect
,
CLIENT_reconnect_register
,
CLIENT_reconnect_unregister
,
CLIENT_send_pre_reconnect_info
,
CLIENT_send_reconnect_info
,
CLIENT_send_replays
,
Q
,
ROOM_all
,
ROOM_bad_ip
,
ROOM_ban_player
,
ROOM_clear_disconnect
,
ROOM_connected_ip
,
ROOM_find_by_name
,
ROOM_find_by_pid
,
ROOM_find_by_port
,
ROOM_find_by_title
,
ROOM_find_or_create_ai
,
ROOM_find_or_create_by_name
,
ROOM_find_or_create_random
,
ROOM_kick
,
ROOM_player_flee
,
ROOM_player_get_score
,
ROOM_player_lose
,
ROOM_player_win
,
ROOM_players_oppentlist
,
ROOM_players_scores
,
ROOM_unwelcome
,
ROOM_validate
,
ReplayParser
,
ResolveData
,
Room
,
SERVER_clear_disconnect
,
SERVER_kick
,
SOCKET_flush_data
,
_
,
_async
,
addCallback
,
athleticChecker
,
auth
,
axios
,
badwords
,
ban_user
,
bunyan
,
challonge
,
challonge_cache
,
challonge_queue_callbacks
,
ch
eckFileExists
,
createDirectoryIfNotExists
,
crypto
,
dataManager
,
deck_name_match
,
dialogues
,
disconnect_list
,
exec
,
execFile
,
fs
,
geoip
,
getSeedTimet
,
get_callback
,
get_memory_usage
,
http
,
httpRequestListener
,
importOldConfig
,
import_datas
,
init
,
is_challonge_requesting
,
lflists
,
loadJSON
,
loadJSONAsync
,
loadLFList
,
loadRemoteData
,
load_dialogues
,
load_tips
,
log
,
long_resolve_cards
,
memory_usage
,
merge
,
moment
,
net
,
netRequestHandler
,
os
,
path
,
qs
,
real_windbot_server_ip
,
refresh_challonge_cache
,
release_disconnect
,
replaced_index
,
report_to_big_brother
,
request
,
roomlist
,
setting_change
,
setting_save
,
settings
,
spawn
,
spawnSync
,
spawn_windbot
,
tips
,
url
,
users_cache
,
util
,
wait_room_start
,
wait_room_start_arena
,
windbot_looplimit
,
windbot_proces
s
,
ygopro
,
zlib
;
var
CLIENT_get_authorize_key
,
CLIENT_get_kick_reconnect_target
,
CLIENT_heartbeat_register
,
CLIENT_heartbeat_unregister
,
CLIENT_import_data
,
CLIENT_is_able_to_kick_reconnect
,
CLIENT_is_able_to_reconnect
,
CLIENT_is_banned_by_mc
,
CLIENT_is_player
,
CLIENT_kick
,
CLIENT_kick_reconnect
,
CLIENT_pre_reconnect
,
CLIENT_reconnect
,
CLIENT_reconnect_register
,
CLIENT_reconnect_unregister
,
CLIENT_send_pre_reconnect_info
,
CLIENT_send_reconnect_info
,
CLIENT_send_replays
,
Q
,
ROOM_all
,
ROOM_bad_ip
,
ROOM_ban_player
,
ROOM_clear_disconnect
,
ROOM_connected_ip
,
ROOM_find_by_name
,
ROOM_find_by_pid
,
ROOM_find_by_port
,
ROOM_find_by_title
,
ROOM_find_or_create_ai
,
ROOM_find_or_create_by_name
,
ROOM_find_or_create_random
,
ROOM_kick
,
ROOM_player_flee
,
ROOM_player_get_score
,
ROOM_player_lose
,
ROOM_player_win
,
ROOM_players_oppentlist
,
ROOM_players_scores
,
ROOM_unwelcome
,
ROOM_validate
,
ReplayParser
,
ResolveData
,
Room
,
SERVER_clear_disconnect
,
SERVER_kick
,
SOCKET_flush_data
,
_
,
_async
,
addCallback
,
athleticChecker
,
auth
,
axios
,
badwords
,
ban_user
,
bunyan
,
challonge
,
challonge_cache
,
challonge_queue_callbacks
,
ch
at_color
,
checkFileExists
,
createDirectoryIfNotExists
,
crypto
,
dataManager
,
deck_name_match
,
dialogues
,
disconnect_list
,
exec
,
execFile
,
fs
,
geoip
,
getSeedTimet
,
get_callback
,
get_memory_usage
,
http
,
httpRequestListener
,
importOldConfig
,
import_datas
,
init
,
is_challonge_requesting
,
lflists
,
loadJSON
,
loadJSONAsync
,
loadLFList
,
loadRemoteData
,
load_dialogues
,
load_tips
,
log
,
long_resolve_cards
,
memory_usage
,
merge
,
moment
,
net
,
netRequestHandler
,
os
,
path
,
qs
,
real_windbot_server_ip
,
refresh_challonge_cache
,
release_disconnect
,
replaced_index
,
report_to_big_brother
,
request
,
roomlist
,
setting_change
,
setting_save
,
settings
,
spawn
,
spawnSync
,
spawn_windbot
,
tips
,
url
,
users_cache
,
util
,
wait_room_start
,
wait_room_start_arena
,
windbot_looplimit
,
windbot_process
,
windbot
s
,
ygopro
,
zlib
;
net
=
require
(
'
net
'
);
...
...
@@ -202,6 +202,8 @@
badwords
=
null
;
chat_color
=
null
;
lflists
=
global
.
lflists
=
[];
real_windbot_server_ip
=
null
;
...
...
@@ -218,6 +220,8 @@
dataManager
=
null
;
windbots
=
[];
disconnect_list
=
{};
// {old_client, old_server, room_id, timeout, deckbuf}
challonge
=
null
;
...
...
@@ -289,7 +293,7 @@
};
init
=
async
function
()
{
var
AthleticChecker
,
DataManager
,
challonge_module_name
,
challonge_type
,
c
hat_color
,
config
,
cppversion
,
defaultConfig
,
default_data
,
dns
,
e
,
http_server
,
https
,
https_server
,
imported
,
j
,
l
,
len
,
len1
,
len2
,
m
,
mkdirList
,
options
,
pgClient
,
pg_client
,
pg_query
,
plugin_filename
,
plugin_list
,
plugin_path
,
postData
,
ref
,
results
,
windbots
;
var
AthleticChecker
,
DataManager
,
challonge_module_name
,
challonge_type
,
c
onfig
,
cppversion
,
defaultConfig
,
default_data
,
dns
,
e
,
http_server
,
https
,
https_server
,
imported
,
j
,
l
,
len
,
len1
,
len2
,
m
,
mkdirList
,
options
,
pgClient
,
pg_client
,
pg_query
,
plugin_filename
,
plugin_list
,
plugin_path
,
postData
,
ref
;
await
createDirectoryIfNotExists
(
"
./config
"
);
await
importOldConfig
();
defaultConfig
=
(
await
loadJSONAsync
(
'
./data/default_config.json
'
));
...
...
@@ -434,7 +438,7 @@
await
loadLFList
(
'
ygopro/expansions/lflist.conf
'
);
await
loadLFList
(
'
ygopro/lflist.conf
'
);
if
(
settings
.
modules
.
windbot
.
enabled
)
{
windbots
=
global
.
windbots
=
(
await
loadJSONAsync
(
settings
.
modules
.
windbot
.
botlist
).
windbots
)
;
windbots
=
global
.
windbots
=
(
(
await
loadJSONAsync
(
settings
.
modules
.
windbot
.
botlist
))).
windbots
;
real_windbot_server_ip
=
global
.
real_windbot_server_ip
=
settings
.
modules
.
windbot
.
server_ip
;
if
(
!
settings
.
modules
.
windbot
.
server_ip
.
includes
(
"
127.0.0.1
"
))
{
dns
=
require
(
'
dns
'
);
...
...
@@ -611,7 +615,7 @@
load_dialogues
();
}
if
(
settings
.
modules
.
random_duel
.
post_match_scores
)
{
setInterval
(
function
()
{
setInterval
(
async
function
()
{
var
scores
,
scores_by_lose
,
scores_by_win
,
scores_pair
;
scores_pair
=
_
.
pairs
(
ROOM_players_scores
);
scores_by_lose
=
_
.
sortBy
(
scores_pair
,
function
(
score
)
{
...
...
@@ -621,24 +625,22 @@
return
score
[
1
].
win
;
}).
reverse
();
// 然后胜场由低到高,再逆转,就是先排胜场再排败场
scores
=
_
.
first
(
scores_by_win
,
10
);
//log.info scores
request
.
post
({
url
:
settings
.
modules
.
random_duel
.
post_match_scores
,
form
:
{
accesskey
:
settings
.
modules
.
random_duel
.
post_match_accesskey
,
rank
:
JSON
.
stringify
(
scores
)
}
},
(
error
,
response
,
body
)
=>
{
if
(
error
)
{
log
.
warn
(
'
RANDOM SCORE POST ERROR
'
,
error
);
}
else
{
if
(
response
.
statusCode
!==
204
&&
response
.
statusCode
!==
200
)
{
log
.
warn
(
'
RANDOM SCORE POST FAIL
'
,
response
.
statusCode
,
response
.
statusMessage
,
body
);
}
}
});
//else
// log.info 'RANDOM SCORE POST OK', response.statusCode, response.statusMessage
try
{
//log.info scores
await
axios
.
post
(
settings
.
modules
.
random_duel
.
post_match_scores
,
{
headers
:
{
'
content-type
'
:
'
application/x-www-form-urlencoded
'
},
data
:
qs
.
stringify
({
accesskey
:
settings
.
modules
.
random_duel
.
post_match_accesskey
,
rank
:
JSON
.
stringify
(
scores
),
responseType
:
"
json
"
})
});
}
catch
(
error1
)
{
e
=
error1
;
log
.
warn
(
'
RANDOM SCORE POST ERROR
'
,
e
.
toString
());
}
},
60000
);
}
if
(
settings
.
modules
.
random_duel
.
enabled
)
{
...
...
@@ -687,7 +689,6 @@
ygopro
.
stoc_send_chat_to_room
(
room
,
`
${
room
.
waiting_for_player
.
name
}
\${afk_warn_part1}
${
settings
.
modules
.
random_duel
.
hang_timeout
-
time_passed
}
\${afk_warn_part2}`
,
ygopro
.
constants
.
COLORS
.
RED
);
}
}
return
;
if
(
true
)
{
// settings.modules.arena_mode.punish_quit_before_match
for
(
m
=
0
,
len2
=
ROOM_all
.
length
;
m
<
len2
;
m
++
)
{
room
=
ROOM_all
[
m
];
...
...
@@ -768,14 +769,12 @@
await
createDirectoryIfNotExists
(
path
);
}
plugin_list
=
(
await
fs
.
promises
.
readdir
(
"
./plugins
"
));
results
=
[];
for
(
m
=
0
,
len2
=
plugin_list
.
length
;
m
<
len2
;
m
++
)
{
plugin_filename
=
plugin_list
[
m
];
plugin_path
=
process
.
cwd
()
+
"
/plugins/
"
+
plugin_filename
;
require
(
plugin_path
);
results
.
push
(
log
.
info
(
"
Plugin loaded:
"
,
plugin_filename
)
);
log
.
info
(
"
Plugin loaded:
"
,
plugin_filename
);
}
return
results
;
};
// 获取可用内存
...
...
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