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
7fbad66c
Commit
7fbad66c
authored
May 25, 2016
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache jsons
parent
ae8ee1a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
51 deletions
+74
-51
.gitignore
.gitignore
+1
-2
ygopro-server.coffee
ygopro-server.coffee
+32
-21
ygopro-server.js
ygopro-server.js
+41
-28
No files found.
.gitignore
View file @
7fbad66c
...
...
@@ -2,9 +2,8 @@
jsconfig.json
coffeelint.json
config.deckstats.json
password.json
config.
user
.json
config.
*
.json
/node_modules/
!/node_modules/struct/
...
...
ygopro-server.coffee
View file @
7fbad66c
...
...
@@ -24,15 +24,14 @@ moment = require 'moment'
#配置
nconf
=
require
'nconf'
nconf
.
file
(
'user'
,
'./config.user.json'
)
#nconf.file('user2', './config.user2.json')
nconf
.
file
(
'./config.user.json'
)
defaultconfig
=
require
(
'./config.json'
)
nconf
.
defaults
(
defaultconfig
)
settings
=
global
.
settings
=
nconf
.
get
()
nconf
.
myset
=
(
settings
,
path
,
val
)
->
nconf
.
set
(
path
,
val
)
nconf
.
save
(
'user'
)
log
.
info
(
"setting changed"
,
path
,
val
)
nconf
.
save
()
log
.
info
(
"setting changed"
,
path
,
val
)
if
_
.
isString
(
val
)
path
=
path
.
split
(
':'
)
if
path
.
length
==
0
settings
[
path
[
0
]]
=
val
...
...
@@ -47,6 +46,7 @@ nconf.myset = (settings, path, val) ->
settings
.
BANNED_user
=
[]
settings
.
BANNED_IP
=
[]
settings
.
version
=
parseInt
(
fs
.
readFileSync
(
'ygopro/gframe/game.cpp'
,
'utf8'
).
match
(
/PRO_VERSION = ([x\d]+)/
)[
1
],
'16'
)
settings
.
lflist
=
(
for
list
in
fs
.
readFileSync
(
'ygopro/lflist.conf'
,
'utf8'
).
match
(
/!.*/g
)
date
=
list
.
match
(
/!([\d\.]+)/
)
...
...
@@ -558,8 +558,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
#登场台词
if
settings
.
modules
.
dialogues
dialogues
=
{}
load_dialogues
=
()
->
request
url
:
settings
.
modules
.
dialogues
json
:
true
...
...
@@ -569,9 +568,13 @@ if settings.modules.dialogues
else
if
error
or
!
body
log
.
warn
'dialogues error'
,
error
,
response
else
#log.info "dialogues loaded", _.size body
dialogues
=
body
nconf
.
myset
(
settings
,
"dialogues"
,
body
)
log
.
info
"dialogues loaded"
,
_
.
size
body
return
return
if
settings
.
modules
.
dialogues
load_dialogues
()
ygopro
.
stoc_follow
'GAME_MSG'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
msg
=
buffer
.
readInt8
(
0
)
...
...
@@ -630,8 +633,8 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
if
settings
.
modules
.
dialogues
if
ygopro
.
constants
.
MSG
[
msg
]
==
'SUMMONING'
or
ygopro
.
constants
.
MSG
[
msg
]
==
'SPSUMMONING'
card
=
buffer
.
readUInt32LE
(
1
)
if
dialogues
[
card
]
for
line
in
_
.
lines
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]
if
settings
.
dialogues
[
card
]
for
line
in
_
.
lines
settings
.
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
settings
.
dialogues
[
card
].
length
)]
ygopro
.
stoc_send_chat
(
client
,
line
,
ygopro
.
constants
.
COLORS
.
PINK
)
return
...
...
@@ -684,26 +687,34 @@ wait_room_start = (room, time)->
#tip
ygopro
.
stoc_send_random_tip
=
(
client
)
->
ygopro
.
stoc_send_chat
(
client
,
"Tip: "
+
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)])
if
tips
ygopro
.
stoc_send_chat
(
client
,
"Tip: "
+
settings
.
tips
[
Math
.
floor
(
Math
.
random
()
*
settings
.
tips
.
length
)])
if
settings
.
modules
.
tips
return
ygopro
.
stoc_send_random_tip_to_room
=
(
room
)
->
ygopro
.
stoc_send_chat_to_room
(
room
,
"Tip: "
+
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)])
if
tips
ygopro
.
stoc_send_chat_to_room
(
room
,
"Tip: "
+
settings
.
tips
[
Math
.
floor
(
Math
.
random
()
*
settings
.
tips
.
length
)])
if
settings
.
modules
.
tips
return
tips
=
null
if
settings
.
modules
.
tips
load_tips
=
()
->
request
url
:
settings
.
modules
.
tips
json
:
true
,
(
error
,
response
,
body
)
->
tips
=
body
#log.info "tips loaded", tips.length
if
tips
then
setInterval
()
->
for
room
in
Room
.
all
ygopro
.
stoc_send_random_tip_to_room
(
room
)
unless
room
and
room
.
started
return
,
30000
if
_
.
isString
body
log
.
warn
"tips bad json"
,
body
else
if
error
or
!
body
log
.
warn
'tips error'
,
error
,
response
else
nconf
.
myset
(
settings
,
"tips"
,
body
)
log
.
info
"tips loaded"
,
settings
.
tips
.
length
return
return
if
settings
.
modules
.
tips
load_tips
()
setInterval
()
->
for
room
in
Room
.
all
ygopro
.
stoc_send_random_tip_to_room
(
room
)
unless
room
and
room
.
started
return
,
30000
if
settings
.
modules
.
mycard_auth
and
process
.
env
.
MYCARD_AUTH_DATABASE
pg
=
require
(
'pg'
)
...
...
ygopro-server.js
View file @
7fbad66c
// Generated by CoffeeScript 1.10.0
(
function
()
{
var
Graveyard
,
Room
,
_
,
bunyan
,
crypto
,
date
,
defaultconfig
,
dialogues
,
execFile
,
fs
,
http
,
http_server
,
https
,
https_server
,
list
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pg
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
settings
,
tip
s
,
tribute
,
url
,
users_cache
,
wait_room_start
,
ygopro
,
zlib
;
var
Graveyard
,
Room
,
_
,
bunyan
,
crypto
,
date
,
defaultconfig
,
execFile
,
fs
,
http
,
http_server
,
https
,
https_server
,
list
,
load_dialogues
,
load_tips
,
log
,
moment
,
nconf
,
net
,
options
,
os
,
path
,
pg
,
redis
,
redisdb
,
request
,
requestListener
,
roomlist
,
setting
s
,
tribute
,
url
,
users_cache
,
wait_room_start
,
ygopro
,
zlib
;
net
=
require
(
'
net
'
);
...
...
@@ -36,7 +36,7 @@
nconf
=
require
(
'
nconf
'
);
nconf
.
file
(
'
user
'
,
'
./config.user.json
'
);
nconf
.
file
(
'
./config.user.json
'
);
defaultconfig
=
require
(
'
./config.json
'
);
...
...
@@ -47,8 +47,10 @@
nconf
.
myset
=
function
(
settings
,
path
,
val
)
{
var
key
,
target
;
nconf
.
set
(
path
,
val
);
nconf
.
save
(
'
user
'
);
log
.
info
(
"
setting changed
"
,
path
,
val
);
nconf
.
save
();
if
(
_
.
isString
(
val
))
{
log
.
info
(
"
setting changed
"
,
path
,
val
);
}
path
=
path
.
split
(
'
:
'
);
if
(
path
.
length
===
0
)
{
settings
[
path
[
0
]]
=
val
;
...
...
@@ -635,8 +637,7 @@
}
});
if
(
settings
.
modules
.
dialogues
)
{
dialogues
=
{};
load_dialogues
=
function
()
{
request
({
url
:
settings
.
modules
.
dialogues
,
json
:
true
...
...
@@ -646,9 +647,14 @@
}
else
if
(
error
||
!
body
)
{
log
.
warn
(
'
dialogues error
'
,
error
,
response
);
}
else
{
dialogues
=
body
;
nconf
.
myset
(
settings
,
"
dialogues
"
,
body
);
log
.
info
(
"
dialogues loaded
"
,
_
.
size
(
body
));
}
});
};
if
(
settings
.
modules
.
dialogues
)
{
load_dialogues
();
}
ygopro
.
stoc_follow
(
'
GAME_MSG
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
...
...
@@ -713,8 +719,8 @@
if
(
settings
.
modules
.
dialogues
)
{
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
SUMMONING
'
||
ygopro
.
constants
.
MSG
[
msg
]
===
'
SPSUMMONING
'
)
{
card
=
buffer
.
readUInt32LE
(
1
);
if
(
dialogues
[
card
])
{
ref2
=
_
.
lines
(
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]);
if
(
settings
.
dialogues
[
card
])
{
ref2
=
_
.
lines
(
settings
.
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
settings
.
dialogues
[
card
].
length
)]);
for
(
k
=
0
,
len
=
ref2
.
length
;
k
<
len
;
k
++
)
{
line
=
ref2
[
k
];
ygopro
.
stoc_send_chat
(
client
,
line
,
ygopro
.
constants
.
COLORS
.
PINK
);
...
...
@@ -800,38 +806,45 @@
};
ygopro
.
stoc_send_random_tip
=
function
(
client
)
{
if
(
tips
)
{
ygopro
.
stoc_send_chat
(
client
,
"
Tip:
"
+
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)]);
if
(
settings
.
modules
.
tips
)
{
ygopro
.
stoc_send_chat
(
client
,
"
Tip:
"
+
settings
.
tips
[
Math
.
floor
(
Math
.
random
()
*
settings
.
tips
.
length
)]);
}
};
ygopro
.
stoc_send_random_tip_to_room
=
function
(
room
)
{
if
(
tips
)
{
ygopro
.
stoc_send_chat_to_room
(
room
,
"
Tip:
"
+
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)]);
if
(
settings
.
modules
.
tips
)
{
ygopro
.
stoc_send_chat_to_room
(
room
,
"
Tip:
"
+
settings
.
tips
[
Math
.
floor
(
Math
.
random
()
*
settings
.
tips
.
length
)]);
}
};
tips
=
null
;
if
(
settings
.
modules
.
tips
)
{
load_tips
=
function
()
{
request
({
url
:
settings
.
modules
.
tips
,
json
:
true
},
function
(
error
,
response
,
body
)
{
tips
=
body
;
if
(
tips
)
{
setInterval
(
function
()
{
var
k
,
len
,
ref
,
room
;
ref
=
Room
.
all
;
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
room
=
ref
[
k
];
if
(
!
(
room
&&
room
.
started
))
{
ygopro
.
stoc_send_random_tip_to_room
(
room
);
}
}
},
30000
);
if
(
_
.
isString
(
body
))
{
log
.
warn
(
"
tips bad json
"
,
body
);
}
else
if
(
error
||
!
body
)
{
log
.
warn
(
'
tips error
'
,
error
,
response
);
}
else
{
nconf
.
myset
(
settings
,
"
tips
"
,
body
);
log
.
info
(
"
tips loaded
"
,
settings
.
tips
.
length
);
}
});
};
if
(
settings
.
modules
.
tips
)
{
load_tips
();
setInterval
(
function
()
{
var
k
,
len
,
ref
,
room
;
ref
=
Room
.
all
;
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
room
=
ref
[
k
];
if
(
!
(
room
&&
room
.
started
))
{
ygopro
.
stoc_send_random_tip_to_room
(
room
);
}
}
},
30000
);
}
if
(
settings
.
modules
.
mycard_auth
&&
process
.
env
.
MYCARD_AUTH_DATABASE
)
{
...
...
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