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
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
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
MyCard
srvpro
Commits
6dc7febd
Commit
6dc7febd
authored
Oct 20, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge
parent
5a09cdf9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
87 deletions
+89
-87
ygopro-server.coffee
ygopro-server.coffee
+41
-36
ygopro-server.js
ygopro-server.js
+48
-51
No files found.
ygopro-server.coffee
View file @
6dc7febd
...
...
@@ -107,6 +107,21 @@ roomlist = require './roomlist.js' if settings.modules.enable_websocket_roomlist
# cache users of mycard login
users_cache
=
{}
if
settings
.
modules
.
mycard_auth
and
process
.
env
.
MYCARD_AUTH_DATABASE
pgClient
=
require
(
'pg'
).
Client
pg_client
=
new
pgClient
(
process
.
env
.
MYCARD_AUTH_DATABASE
)
pg_query
=
pg_client
.
query
(
'SELECT username, id from users'
)
pg_query
.
on
'row'
,
(
row
)
->
#log.info "load user", row.username, row.id
users_cache
[
row
.
username
]
=
row
.
id
return
pg_query
.
on
'end'
,
(
result
)
->
log
.
info
"users loaded"
,
result
.
rowCount
return
pg_client
.
on
'drain'
,
pg_client
.
end
.
bind
(
pg_client
)
log
.
info
"loading mycard user..."
pg_client
.
connect
()
# 获取可用内存
get_memory_usage
=
()
->
prc_free
=
spawnSync
(
"free"
,
[])
...
...
@@ -423,25 +438,26 @@ class Room
score_array
=
[]
for
name
,
score
of
@
scores
score_array
.
push
{
name
:
name
,
score
:
score
}
log
.
info
@
start_time
,
score_array
request
.
post
{
url
:
settings
.
modules
.
arena_mode
.
post_score
,
form
:
{
accesskey
:
process
.
env
.
MYCARD_SCORE_KEY
,
usernameA
:
score_array
[
0
].
name
,
usernameB
:
score_array
[
1
].
name
,
userscoreA
:
score_array
[
0
].
score
,
userscoreB
:
score_array
[
1
].
score
,
start
:
@
start_time
,
end
:
moment
().
format
(),
arena
:
if
room
.
hostinfo
.
mode
==
1
then
'athletic'
else
'entertain'
#settings.modules.arena_mode.mode
}},
(
error
,
response
,
body
)
=>
if
error
log
.
warn
'SCORE POST ERROR'
,
error
,
response
else
if
response
.
statusCode
!=
204
log
.
warn
'SCORE POST'
,
response
.
statusCode
,
response
.
statusMessage
,
@
name
,
body
log
.
info
'SCORE'
,
score_array
,
@
start_time
if
score_array
.
length
==
2
request
.
post
{
url
:
settings
.
modules
.
arena_mode
.
post_score
,
form
:
{
accesskey
:
process
.
env
.
MYCARD_ARENA_KEY
,
usernameA
:
score_array
[
0
].
name
,
usernameB
:
score_array
[
1
].
name
,
userscoreA
:
score_array
[
0
].
score
,
userscoreB
:
score_array
[
1
].
score
,
start
:
@
start_time
,
end
:
moment
().
format
(),
arena
:
if
@
hostinfo
.
mode
==
1
then
'athletic'
else
'entertain'
#settings.modules.arena_mode.mode
}},
(
error
,
response
,
body
)
=>
if
error
log
.
warn
'SCORE POST ERROR'
,
error
,
response
.
statusCode
,
response
.
statusMessage
,
body
else
log
.
info
'SCORE POST'
,
response
.
statusCode
,
response
.
statusMessage
,
@
name
,
body
return
if
response
.
statusCode
!=
204
log
.
warn
'SCORE POST FAIL'
,
response
.
statusCode
,
response
.
statusMessage
,
@
name
,
body
else
log
.
info
'SCORE POST OK'
,
response
.
statusCode
,
response
.
statusMessage
,
@
name
,
body
return
if
@
player_datas
.
length
and
settings
.
modules
.
enable_cloud_replay
replay_id
=
@
cloud_replay_id
if
@
has_ygopro_error
...
...
@@ -1065,16 +1081,18 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
ygopro
.
stoc_send_chat
(
client
,
settings
.
modules
.
welcome
,
ygopro
.
constants
.
COLORS
.
GREEN
)
if
room
.
welcome
ygopro
.
stoc_send_chat
(
client
,
room
.
welcome
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
if
settings
.
modules
.
arena_mode
.
get_score
if
settings
.
modules
.
arena_mode
.
get_score
#and not client.score_shown
request
url
:
settings
.
modules
.
arena_mode
.
get_score
+
encodeURIComponent
(
client
.
name
),
json
:
true
,
(
error
,
response
,
body
)
->
if
error
or
!
body
or
_
.
isString
body
log
.
warn
'LOAD SCORE ERROR'
,
client
.
name
,
error
,
response
,
body
log
.
warn
'LOAD SCORE ERROR'
,
client
.
name
,
error
,
response
.
statusCode
,
response
.
statusMessage
,
body
else
log
.
info
'LOAD SCORE'
,
client
.
name
,
body
ygopro
.
stoc_send_chat
(
client
,
"您有
#{
body
.
exp
}
点经验,排名第
#{
body
.
exp_rank
}
,
#{
body
.
pt
}
点战斗力,排名第
#{
body
.
arena_rank
}
。正式上线前这些积分可能被重置。"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
rank_txt
=
if
body
.
arena_rank
>
0
then
"排名第"
+
body
.
arena_rank
else
"暂无排名"
ygopro
.
stoc_send_chat
(
client
,
"
#{
client
.
name
}
,你有
#{
body
.
exp
}
点经验,你的战斗力是
#{
Math
.
round
(
body
.
pt
)
}
,
#{
rank_txt
}
。正式上线前这些积分可能被重置。"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
)
#client.score_shown = true
return
if
!
room
.
recorder
...
...
@@ -1299,19 +1317,6 @@ if settings.modules.tips
return
,
30000
if
settings
.
modules
.
mycard_auth
and
process
.
env
.
MYCARD_AUTH_DATABASE
pg
=
require
(
'pg'
)
pg
.
connect
process
.
env
.
MYCARD_AUTH_DATABASE
,
(
error
,
client
,
done
)
->
throw
error
if
error
client
.
query
'SELECT username, id from users'
,
(
error
,
result
)
->
throw
error
if
error
done
()
for
row
in
result
.
rows
users_cache
[
row
.
username
]
=
row
.
id
console
.
log
(
"users loaded"
,
_
.
keys
(
users_cache
).
length
)
return
return
ygopro
.
stoc_follow
'DUEL_START'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
room
=
ROOM_all
[
client
.
rid
]
return
unless
room
...
...
@@ -1345,9 +1350,9 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
log
.
warn
'DECK POST ERROR'
,
error
,
response
else
if
response
.
statusCode
!=
200
log
.
warn
'DECK POST'
,
response
.
statusCode
,
client
.
name
,
body
log
.
warn
'DECK POST
FAIL
'
,
response
.
statusCode
,
client
.
name
,
body
else
log
.
info
'DECK POST'
,
response
.
statusCode
,
client
.
name
,
body
log
.
info
'DECK POST
OK
'
,
response
.
statusCode
,
client
.
name
,
body
return
client
.
deck_saved
=
true
return
...
...
ygopro-server.js
View file @
6dc7febd
// Generated by CoffeeScript 1.10.0
(
function
()
{
var
Cloud_replay_ids
,
Graveyard
,
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
,
_
,
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
,
windbot_process
,
ygopro
,
zlib
;
var
Cloud_replay_ids
,
Graveyard
,
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
,
_
,
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
Client
,
pg_client
,
pg_query
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
spawn
,
spawnSync
,
tribute
,
url
,
users_cache
,
wait_room_start
,
windbot_process
,
ygopro
,
zlib
;
net
=
require
(
'
net
'
);
...
...
@@ -155,6 +155,21 @@
users_cache
=
{};
if
(
settings
.
modules
.
mycard_auth
&&
process
.
env
.
MYCARD_AUTH_DATABASE
)
{
pgClient
=
require
(
'
pg
'
).
Client
;
pg_client
=
new
pgClient
(
process
.
env
.
MYCARD_AUTH_DATABASE
);
pg_query
=
pg_client
.
query
(
'
SELECT username, id from users
'
);
pg_query
.
on
(
'
row
'
,
function
(
row
)
{
users_cache
[
row
.
username
]
=
row
.
id
;
});
pg_query
.
on
(
'
end
'
,
function
(
result
)
{
log
.
info
(
"
users loaded
"
,
result
.
rowCount
);
});
pg_client
.
on
(
'
drain
'
,
pg_client
.
end
.
bind
(
pg_client
));
log
.
info
(
"
loading mycard user...
"
);
pg_client
.
connect
();
}
get_memory_usage
=
function
()
{
var
actualFree
,
buffers
,
cached
,
free
,
line
,
lines
,
percentUsed
,
prc_free
,
total
;
prc_free
=
spawnSync
(
"
free
"
,
[]);
...
...
@@ -577,32 +592,34 @@
score
:
score
});
}
log
.
info
(
this
.
start_time
,
score_array
);
request
.
post
({
url
:
settings
.
modules
.
arena_mode
.
post_score
,
form
:
{
accesskey
:
process
.
env
.
MYCARD_SCORE_KEY
,
usernameA
:
score_array
[
0
].
name
,
usernameB
:
score_array
[
1
].
name
,
userscoreA
:
score_array
[
0
].
score
,
userscoreB
:
score_array
[
1
].
score
,
start
:
this
.
start_time
,
end
:
moment
().
format
(),
arena
:
room
.
hostinfo
.
mode
===
1
?
'
athletic
'
:
'
entertain
'
}
},
(
function
(
_this
)
{
return
function
(
error
,
response
,
body
)
{
if
(
error
)
{
log
.
warn
(
'
SCORE POST ERROR
'
,
error
,
response
);
}
else
{
if
(
response
.
statusCode
!==
204
)
{
log
.
warn
(
'
SCORE POST
'
,
response
.
statusCode
,
response
.
statusMessage
,
_this
.
name
,
body
);
log
.
info
(
'
SCORE
'
,
score_array
,
this
.
start_time
);
if
(
score_array
.
length
===
2
)
{
request
.
post
({
url
:
settings
.
modules
.
arena_mode
.
post_score
,
form
:
{
accesskey
:
process
.
env
.
MYCARD_ARENA_KEY
,
usernameA
:
score_array
[
0
].
name
,
usernameB
:
score_array
[
1
].
name
,
userscoreA
:
score_array
[
0
].
score
,
userscoreB
:
score_array
[
1
].
score
,
start
:
this
.
start_time
,
end
:
moment
().
format
(),
arena
:
this
.
hostinfo
.
mode
===
1
?
'
athletic
'
:
'
entertain
'
}
},
(
function
(
_this
)
{
return
function
(
error
,
response
,
body
)
{
if
(
error
)
{
log
.
warn
(
'
SCORE POST ERROR
'
,
error
,
response
.
statusCode
,
response
.
statusMessage
,
body
);
}
else
{
log
.
info
(
'
SCORE POST
'
,
response
.
statusCode
,
response
.
statusMessage
,
_this
.
name
,
body
);
if
(
response
.
statusCode
!==
204
)
{
log
.
warn
(
'
SCORE POST FAIL
'
,
response
.
statusCode
,
response
.
statusMessage
,
_this
.
name
,
body
);
}
else
{
log
.
info
(
'
SCORE POST OK
'
,
response
.
statusCode
,
response
.
statusMessage
,
_this
.
name
,
body
);
}
}
}
};
}
)(
this
));
}
;
}
)(
this
))
;
}
}
if
(
this
.
player_datas
.
length
&&
settings
.
modules
.
enable_cloud_replay
)
{
replay_id
=
this
.
cloud_replay_id
;
...
...
@@ -1298,11 +1315,13 @@
url
:
settings
.
modules
.
arena_mode
.
get_score
+
encodeURIComponent
(
client
.
name
),
json
:
true
},
function
(
error
,
response
,
body
)
{
var
rank_txt
;
if
(
error
||
!
body
||
_
.
isString
(
body
))
{
log
.
warn
(
'
LOAD SCORE ERROR
'
,
client
.
name
,
error
,
response
,
body
);
log
.
warn
(
'
LOAD SCORE ERROR
'
,
client
.
name
,
error
,
response
.
statusCode
,
response
.
statusMessage
,
body
);
}
else
{
log
.
info
(
'
LOAD SCORE
'
,
client
.
name
,
body
);
ygopro
.
stoc_send_chat
(
client
,
"
您有
"
+
body
.
exp
+
"
点经验,排名第
"
+
body
.
exp_rank
+
"
,
"
+
body
.
pt
+
"
点战斗力,排名第
"
+
body
.
arena_rank
+
"
。正式上线前这些积分可能被重置。
"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
rank_txt
=
body
.
arena_rank
>
0
?
"
排名第
"
+
body
.
arena_rank
:
"
暂无排名
"
;
ygopro
.
stoc_send_chat
(
client
,
client
.
name
+
"
,你有
"
+
body
.
exp
+
"
点经验,你的战斗力是
"
+
(
Math
.
round
(
body
.
pt
))
+
"
,
"
+
rank_txt
+
"
。正式上线前这些积分可能被重置。
"
,
ygopro
.
constants
.
COLORS
.
BABYBLUE
);
}
});
}
...
...
@@ -1587,28 +1606,6 @@
},
30000
);
}
if
(
settings
.
modules
.
mycard_auth
&&
process
.
env
.
MYCARD_AUTH_DATABASE
)
{
pg
=
require
(
'
pg
'
);
pg
.
connect
(
process
.
env
.
MYCARD_AUTH_DATABASE
,
function
(
error
,
client
,
done
)
{
if
(
error
)
{
throw
error
;
}
client
.
query
(
'
SELECT username, id from users
'
,
function
(
error
,
result
)
{
var
k
,
len
,
ref
,
row
;
if
(
error
)
{
throw
error
;
}
done
();
ref
=
result
.
rows
;
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
row
=
ref
[
k
];
users_cache
[
row
.
username
]
=
row
.
id
;
}
console
.
log
(
"
users loaded
"
,
_
.
keys
(
users_cache
).
length
);
});
});
}
ygopro
.
stoc_follow
(
'
DUEL_START
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
deck_name
,
deck_text
,
k
,
len
,
player
,
ref
,
room
;
room
=
ROOM_all
[
client
.
rid
];
...
...
@@ -1663,9 +1660,9 @@
log
.
warn
(
'
DECK POST ERROR
'
,
error
,
response
);
}
else
{
if
(
response
.
statusCode
!==
200
)
{
log
.
warn
(
'
DECK POST
'
,
response
.
statusCode
,
client
.
name
,
body
);
log
.
warn
(
'
DECK POST
FAIL
'
,
response
.
statusCode
,
client
.
name
,
body
);
}
else
{
log
.
info
(
'
DECK POST
'
,
response
.
statusCode
,
client
.
name
,
body
);
log
.
info
(
'
DECK POST
OK
'
,
response
.
statusCode
,
client
.
name
,
body
);
}
}
});
...
...
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