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 @@
...
@@ -2,9 +2,8 @@
jsconfig.json
jsconfig.json
coffeelint.json
coffeelint.json
config.deckstats.json
password.json
password.json
config.
user
.json
config.
*
.json
/node_modules/
/node_modules/
!/node_modules/struct/
!/node_modules/struct/
...
...
ygopro-server.coffee
View file @
7fbad66c
...
@@ -24,15 +24,14 @@ moment = require 'moment'
...
@@ -24,15 +24,14 @@ moment = require 'moment'
#配置
#配置
nconf
=
require
'nconf'
nconf
=
require
'nconf'
nconf
.
file
(
'user'
,
'./config.user.json'
)
nconf
.
file
(
'./config.user.json'
)
#nconf.file('user2', './config.user2.json')
defaultconfig
=
require
(
'./config.json'
)
defaultconfig
=
require
(
'./config.json'
)
nconf
.
defaults
(
defaultconfig
)
nconf
.
defaults
(
defaultconfig
)
settings
=
global
.
settings
=
nconf
.
get
()
settings
=
global
.
settings
=
nconf
.
get
()
nconf
.
myset
=
(
settings
,
path
,
val
)
->
nconf
.
myset
=
(
settings
,
path
,
val
)
->
nconf
.
set
(
path
,
val
)
nconf
.
set
(
path
,
val
)
nconf
.
save
(
'user'
)
nconf
.
save
()
log
.
info
(
"setting changed"
,
path
,
val
)
log
.
info
(
"setting changed"
,
path
,
val
)
if
_
.
isString
(
val
)
path
=
path
.
split
(
':'
)
path
=
path
.
split
(
':'
)
if
path
.
length
==
0
if
path
.
length
==
0
settings
[
path
[
0
]]
=
val
settings
[
path
[
0
]]
=
val
...
@@ -47,6 +46,7 @@ nconf.myset = (settings, path, val) ->
...
@@ -47,6 +46,7 @@ nconf.myset = (settings, path, val) ->
settings
.
BANNED_user
=
[]
settings
.
BANNED_user
=
[]
settings
.
BANNED_IP
=
[]
settings
.
BANNED_IP
=
[]
settings
.
version
=
parseInt
(
fs
.
readFileSync
(
'ygopro/gframe/game.cpp'
,
'utf8'
).
match
(
/PRO_VERSION = ([x\d]+)/
)[
1
],
'16'
)
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
)
settings
.
lflist
=
(
for
list
in
fs
.
readFileSync
(
'ygopro/lflist.conf'
,
'utf8'
).
match
(
/!.*/g
)
date
=
list
.
match
(
/!([\d\.]+)/
)
date
=
list
.
match
(
/!([\d\.]+)/
)
...
@@ -558,8 +558,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
...
@@ -558,8 +558,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
return
#登场台词
#登场台词
if
settings
.
modules
.
dialogues
load_dialogues
=
()
->
dialogues
=
{}
request
request
url
:
settings
.
modules
.
dialogues
url
:
settings
.
modules
.
dialogues
json
:
true
json
:
true
...
@@ -569,9 +568,13 @@ if settings.modules.dialogues
...
@@ -569,9 +568,13 @@ if settings.modules.dialogues
else
if
error
or
!
body
else
if
error
or
!
body
log
.
warn
'dialogues error'
,
error
,
response
log
.
warn
'dialogues error'
,
error
,
response
else
else
#log.info "dialogues loaded", _.size body
nconf
.
myset
(
settings
,
"dialogues"
,
body
)
dialogues
=
body
log
.
info
"dialogues loaded"
,
_
.
size
body
return
return
return
if
settings
.
modules
.
dialogues
load_dialogues
()
ygopro
.
stoc_follow
'GAME_MSG'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
ygopro
.
stoc_follow
'GAME_MSG'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
msg
=
buffer
.
readInt8
(
0
)
msg
=
buffer
.
readInt8
(
0
)
...
@@ -630,8 +633,8 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
...
@@ -630,8 +633,8 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
if
settings
.
modules
.
dialogues
if
settings
.
modules
.
dialogues
if
ygopro
.
constants
.
MSG
[
msg
]
==
'SUMMONING'
or
ygopro
.
constants
.
MSG
[
msg
]
==
'SPSUMMONING'
if
ygopro
.
constants
.
MSG
[
msg
]
==
'SUMMONING'
or
ygopro
.
constants
.
MSG
[
msg
]
==
'SPSUMMONING'
card
=
buffer
.
readUInt32LE
(
1
)
card
=
buffer
.
readUInt32LE
(
1
)
if
dialogues
[
card
]
if
settings
.
dialogues
[
card
]
for
line
in
_
.
lines
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]
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
)
ygopro
.
stoc_send_chat
(
client
,
line
,
ygopro
.
constants
.
COLORS
.
PINK
)
return
return
...
@@ -684,26 +687,34 @@ wait_room_start = (room, time)->
...
@@ -684,26 +687,34 @@ wait_room_start = (room, time)->
#tip
#tip
ygopro
.
stoc_send_random_tip
=
(
client
)
->
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
return
ygopro
.
stoc_send_random_tip_to_room
=
(
room
)
->
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
return
tips
=
null
load_tips
=
()
->
if
settings
.
modules
.
tips
request
request
url
:
settings
.
modules
.
tips
url
:
settings
.
modules
.
tips
json
:
true
json
:
true
,
(
error
,
response
,
body
)
->
,
(
error
,
response
,
body
)
->
tips
=
body
if
_
.
isString
body
#log.info "tips loaded", tips.length
log
.
warn
"tips bad json"
,
body
if
tips
then
setInterval
()
->
else
if
error
or
!
body
for
room
in
Room
.
all
log
.
warn
'tips error'
,
error
,
response
ygopro
.
stoc_send_random_tip_to_room
(
room
)
unless
room
and
room
.
started
else
return
nconf
.
myset
(
settings
,
"tips"
,
body
)
,
30000
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
return
,
30000
if
settings
.
modules
.
mycard_auth
and
process
.
env
.
MYCARD_AUTH_DATABASE
if
settings
.
modules
.
mycard_auth
and
process
.
env
.
MYCARD_AUTH_DATABASE
pg
=
require
(
'pg'
)
pg
=
require
(
'pg'
)
...
...
ygopro-server.js
View file @
7fbad66c
// Generated by CoffeeScript 1.10.0
// Generated by CoffeeScript 1.10.0
(
function
()
{
(
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
'
);
net
=
require
(
'
net
'
);
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
nconf
=
require
(
'
nconf
'
);
nconf
=
require
(
'
nconf
'
);
nconf
.
file
(
'
user
'
,
'
./config.user.json
'
);
nconf
.
file
(
'
./config.user.json
'
);
defaultconfig
=
require
(
'
./config.json
'
);
defaultconfig
=
require
(
'
./config.json
'
);
...
@@ -47,8 +47,10 @@
...
@@ -47,8 +47,10 @@
nconf
.
myset
=
function
(
settings
,
path
,
val
)
{
nconf
.
myset
=
function
(
settings
,
path
,
val
)
{
var
key
,
target
;
var
key
,
target
;
nconf
.
set
(
path
,
val
);
nconf
.
set
(
path
,
val
);
nconf
.
save
(
'
user
'
);
nconf
.
save
();
log
.
info
(
"
setting changed
"
,
path
,
val
);
if
(
_
.
isString
(
val
))
{
log
.
info
(
"
setting changed
"
,
path
,
val
);
}
path
=
path
.
split
(
'
:
'
);
path
=
path
.
split
(
'
:
'
);
if
(
path
.
length
===
0
)
{
if
(
path
.
length
===
0
)
{
settings
[
path
[
0
]]
=
val
;
settings
[
path
[
0
]]
=
val
;
...
@@ -635,8 +637,7 @@
...
@@ -635,8 +637,7 @@
}
}
});
});
if
(
settings
.
modules
.
dialogues
)
{
load_dialogues
=
function
()
{
dialogues
=
{};
request
({
request
({
url
:
settings
.
modules
.
dialogues
,
url
:
settings
.
modules
.
dialogues
,
json
:
true
json
:
true
...
@@ -646,9 +647,14 @@
...
@@ -646,9 +647,14 @@
}
else
if
(
error
||
!
body
)
{
}
else
if
(
error
||
!
body
)
{
log
.
warn
(
'
dialogues error
'
,
error
,
response
);
log
.
warn
(
'
dialogues error
'
,
error
,
response
);
}
else
{
}
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
)
{
ygopro
.
stoc_follow
(
'
GAME_MSG
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
...
@@ -713,8 +719,8 @@
...
@@ -713,8 +719,8 @@
if
(
settings
.
modules
.
dialogues
)
{
if
(
settings
.
modules
.
dialogues
)
{
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
SUMMONING
'
||
ygopro
.
constants
.
MSG
[
msg
]
===
'
SPSUMMONING
'
)
{
if
(
ygopro
.
constants
.
MSG
[
msg
]
===
'
SUMMONING
'
||
ygopro
.
constants
.
MSG
[
msg
]
===
'
SPSUMMONING
'
)
{
card
=
buffer
.
readUInt32LE
(
1
);
card
=
buffer
.
readUInt32LE
(
1
);
if
(
dialogues
[
card
])
{
if
(
settings
.
dialogues
[
card
])
{
ref2
=
_
.
lines
(
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]);
ref2
=
_
.
lines
(
settings
.
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
settings
.
dialogues
[
card
].
length
)]);
for
(
k
=
0
,
len
=
ref2
.
length
;
k
<
len
;
k
++
)
{
for
(
k
=
0
,
len
=
ref2
.
length
;
k
<
len
;
k
++
)
{
line
=
ref2
[
k
];
line
=
ref2
[
k
];
ygopro
.
stoc_send_chat
(
client
,
line
,
ygopro
.
constants
.
COLORS
.
PINK
);
ygopro
.
stoc_send_chat
(
client
,
line
,
ygopro
.
constants
.
COLORS
.
PINK
);
...
@@ -800,38 +806,45 @@
...
@@ -800,38 +806,45 @@
};
};
ygopro
.
stoc_send_random_tip
=
function
(
client
)
{
ygopro
.
stoc_send_random_tip
=
function
(
client
)
{
if
(
tips
)
{
if
(
settings
.
modules
.
tips
)
{
ygopro
.
stoc_send_chat
(
client
,
"
Tip:
"
+
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)]);
ygopro
.
stoc_send_chat
(
client
,
"
Tip:
"
+
settings
.
tips
[
Math
.
floor
(
Math
.
random
()
*
settings
.
tips
.
length
)]);
}
}
};
};
ygopro
.
stoc_send_random_tip_to_room
=
function
(
room
)
{
ygopro
.
stoc_send_random_tip_to_room
=
function
(
room
)
{
if
(
tips
)
{
if
(
settings
.
modules
.
tips
)
{
ygopro
.
stoc_send_chat_to_room
(
room
,
"
Tip:
"
+
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)]);
ygopro
.
stoc_send_chat_to_room
(
room
,
"
Tip:
"
+
settings
.
tips
[
Math
.
floor
(
Math
.
random
()
*
settings
.
tips
.
length
)]);
}
}
};
};
tips
=
null
;
load_tips
=
function
()
{
if
(
settings
.
modules
.
tips
)
{
request
({
request
({
url
:
settings
.
modules
.
tips
,
url
:
settings
.
modules
.
tips
,
json
:
true
json
:
true
},
function
(
error
,
response
,
body
)
{
},
function
(
error
,
response
,
body
)
{
tips
=
body
;
if
(
_
.
isString
(
body
))
{
if
(
tips
)
{
log
.
warn
(
"
tips bad json
"
,
body
);
setInterval
(
function
()
{
}
else
if
(
error
||
!
body
)
{
var
k
,
len
,
ref
,
room
;
log
.
warn
(
'
tips error
'
,
error
,
response
);
ref
=
Room
.
all
;
}
else
{
for
(
k
=
0
,
len
=
ref
.
length
;
k
<
len
;
k
++
)
{
nconf
.
myset
(
settings
,
"
tips
"
,
body
);
room
=
ref
[
k
];
log
.
info
(
"
tips loaded
"
,
settings
.
tips
.
length
);
if
(
!
(
room
&&
room
.
started
))
{
ygopro
.
stoc_send_random_tip_to_room
(
room
);
}
}
},
30000
);
}
}
});
});
};
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
)
{
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