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
e3136397
Commit
e3136397
authored
Sep 05, 2013
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tip
parent
85a01308
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
130 additions
and
116 deletions
+130
-116
package.json
package.json
+3
-1
proto_structs.json
proto_structs.json
+2
-1
structs.json
structs.json
+3
-0
taici.json
taici.json
+0
-70
tips.json
tips.json
+0
-0
ygopro-server.coffee
ygopro-server.coffee
+48
-19
ygopro-server.js
ygopro-server.js
+73
-24
ygopro-server.map
ygopro-server.map
+1
-1
No files found.
package.json
View file @
e3136397
...
...
@@ -14,9 +14,11 @@
"author"
:
"zh99998 <zh99998@gmail.com>"
,
"dependencies"
:
{
"
underscore
"
:
"
*
"
,
"
underscore.string
"
:
"
*
"
,
"
freeport
"
:
"
*
"
,
"
struct
"
:
"
*
"
,
"
inotify
"
:
"
*
"
"
inotify
"
:
"
*
"
,
"
request
"
:
"
*
"
},
"license"
:
"GPLv3"
,
"main"
:
"ygopro-server.js"
,
...
...
proto_structs.json
View file @
e3136397
...
...
@@ -2,7 +2,8 @@
"CTOS"
:{
"PLAYER_INFO"
:
"CTOS_PlayerInfo"
,
"JOIN_GAME"
:
"CTOS_JoinGame"
,
"UPDATE_DECK"
:
"deck"
"UPDATE_DECK"
:
"deck"
,
"CHAT"
:
"chat"
},
"STOC"
:{
"JOIN_GAME"
:
"STOC_JoinGame"
,
...
...
structs.json
View file @
e3136397
...
...
@@ -88,5 +88,8 @@
{
"name"
:
"mainc"
,
"type"
:
"unsigned int"
},
{
"name"
:
"sidec"
,
"type"
:
"unsigned int"
},
{
"name"
:
"deckbuf"
,
"type"
:
"unsigned int"
,
"length"
:
75
}
],
"chat"
:
[
{
"name"
:
"msg"
,
"type"
:
"unsigned short"
,
"length"
:
"255"
,
"encoding"
:
"UTF-16LE"
}
]
}
\ No newline at end of file
taici.json
deleted
100644 → 0
View file @
85a01308
This diff is collapsed.
Click to expand it.
tips.json
0 → 100644
View file @
e3136397
ygopro-server.coffee
View file @
e3136397
...
...
@@ -10,7 +10,11 @@ spawn = require('child_process').spawn
freeport
=
require
'freeport'
Struct
=
require
(
'struct'
).
Struct
_
=
require
'underscore'
_
.
str
=
require
'underscore.string'
_
.
mixin
(
_
.
str
.
exports
());
_
.
str
.
include
(
'Underscore.string'
,
'string'
);
Inotify
=
require
(
'inotify'
).
Inotify
request
=
require
'request'
#常量/类型声明
structs_declaration
=
require
'./structs.json'
#结构体声明
...
...
@@ -165,6 +169,15 @@ ctos_send = (socket, proto, info)->
socket
.
write
buffer
if
buffer
.
length
console
.
log
'ctos_sent:'
,
buffer
if
debug
#util
stoc_send_chat
=
(
client
,
msg
,
player
=
8
)
->
stoc_send
client
,
'CHAT'
,
{
player
:
player
msg
:
msg
}
#服务器端消息监听函数
server_listener
=
(
port
,
client
,
server
)
->
client
.
connected
=
true
...
...
@@ -373,23 +386,32 @@ stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
}
#登场台词
taici
=
require
'./taici.json'
dialogues
=
{}
request
url
:
'https://my-card.in/dialogues.json'
json
:
true
,
(
error
,
response
,
body
)
->
dialogues
=
body
console
.
log
"loaded
#{
_
.
size
body
}
dialogues"
stoc_follow
'GAME_MSG'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
msg
=
buffer
.
readInt8
(
0
)
if
constants
.
MSG
[
msg
]
==
'SUMMONING'
or
constants
.
MSG
[
msg
]
==
'SPSUMMONING'
card
=
buffer
.
readUInt32LE
(
1
)
if
taici
[
card
]
for
line
in
taici
[
card
][
Math
.
floor
(
Math
.
random
()
*
taici
[
card
].
length
)].
split
(
"
\n
"
)
stoc_send
client
,
'CHAT'
,
{
player
:
8
msg
:
line
}
if
dialogues
[
card
]
for
line
in
_
.
lines
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]
stoc_send_chat
client
,
line
#积分
if
constants
.
MSG
[
msg
]
==
'WIN'
player
=
buffer
.
readUInt8
(
1
)
type
=
buffer
.
readUInt8
(
2
)
console
.
log
player
,
type
#stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)->
# console.log 'HS_PLAYER_CHANGE', info
#stoc_follow 'CHAT', false, (buffer, info, client, server)->
# console.log info, buffer
#房间数量
http
.
createServer
(
request
,
response
)
->
...
...
@@ -429,23 +451,30 @@ setInterval ()->
room
.
process
.
kill
()
,
900000
#tip
stoc_send_tip
=
(
client
,
tip
)
->
lines
=
_
.
lines
(
tip
)
stoc_send_chat
(
client
,
"Tip:
#{
lines
[
0
]
}
"
)
for
line
in
lines
.
slice
(
1
)
stoc_send_chat
(
client
,
line
)
stoc_send_random_tip
=
(
client
)
->
stoc_send_tip
client
,
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)]
if
tips
#tip
###
request = require 'request'
tips
=
null
request
url: 'https://
forum.my-card.in/admin/site_contents/faq
'
url
:
'https://
my-card.in/tips.json
'
json
:
true
,
(
error
,
response
,
body
)
->
console.log body
tips
=
body
console
.
log
"loaded
#{
tips
.
length
}
tips"
stoc_follow
'DUEL_START'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
stoc_send
client, 'CHAT', {
player: 8
msg: "FAQ: 喵喵喵"
}
###
stoc_send
_random_tip
(
client
)
ctos_follow
'CHAT'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
if
_
.
trim
(
info
.
msg
)
==
'/tip'
stoc_send_random_tip
(
client
)
###
# 开包大战
...
...
ygopro-server.js
View file @
e3136397
// Generated by CoffeeScript 1.6.3
(
function
()
{
var
Inotify
,
Room
,
Struct
,
constants
,
ctos_follow
,
ctos_follows
,
ctos_send
,
debug
,
declaration
,
field
,
freeport
,
fs
,
http
,
inotify
,
listener
,
name
,
net
,
path
,
proto_structs
,
result
,
server_listener
,
settings
,
spawn
,
stoc_follow
,
stoc_follows
,
stoc_send
,
structs
,
structs_declaration
,
taici
,
type
,
typedefs
,
url
,
_
,
_i
,
_len
;
var
Inotify
,
Room
,
Struct
,
constants
,
ctos_follow
,
ctos_follows
,
ctos_send
,
debug
,
declaration
,
dialogues
,
field
,
freeport
,
fs
,
http
,
inotify
,
listener
,
name
,
net
,
path
,
proto_structs
,
request
,
result
,
server_listener
,
settings
,
spawn
,
stoc_follow
,
stoc_follows
,
stoc_send
,
stoc_send_chat
,
stoc_send_random_tip
,
stoc_send_tip
,
structs
,
structs_declaration
,
tips
,
type
,
typedefs
,
url
,
_
,
_i
,
_len
;
net
=
require
(
'
net
'
);
...
...
@@ -20,8 +20,16 @@
_
=
require
(
'
underscore
'
);
_
.
str
=
require
(
'
underscore.string
'
);
_
.
mixin
(
_
.
str
.
exports
());
_
.
str
.
include
(
'
Underscore.string
'
,
'
string
'
);
Inotify
=
require
(
'
inotify
'
).
Inotify
;
request
=
require
(
'
request
'
);
structs_declaration
=
require
(
'
./structs.json
'
);
typedefs
=
require
(
'
./typedefs.json
'
);
...
...
@@ -241,6 +249,16 @@
}
};
stoc_send_chat
=
function
(
client
,
msg
,
player
)
{
if
(
player
==
null
)
{
player
=
8
;
}
return
stoc_send
(
client
,
'
CHAT
'
,
{
player
:
player
,
msg
:
msg
});
};
server_listener
=
function
(
port
,
client
,
server
)
{
var
buffer
,
stoc_buffer
,
stoc_message_length
,
stoc_proto
,
_j
,
_len1
,
_ref
;
client
.
connected
=
true
;
...
...
@@ -486,26 +504,34 @@
});
});
taici
=
require
(
'
./taici.json
'
);
dialogues
=
{};
request
({
url
:
'
https://my-card.in/dialogues.json
'
,
json
:
true
},
function
(
error
,
response
,
body
)
{
dialogues
=
body
;
return
console
.
log
(
"
loaded
"
+
(
_
.
size
(
body
))
+
"
dialogues
"
);
});
stoc_follow
(
'
GAME_MSG
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
var
card
,
line
,
msg
,
_j
,
_len1
,
_ref
,
_results
;
var
card
,
line
,
msg
,
player
,
_j
,
_len1
,
_ref
;
msg
=
buffer
.
readInt8
(
0
);
if
(
constants
.
MSG
[
msg
]
===
'
SUMMONING
'
||
constants
.
MSG
[
msg
]
===
'
SPSUMMONING
'
)
{
card
=
buffer
.
readUInt32LE
(
1
);
if
(
taici
[
card
])
{
_ref
=
taici
[
card
][
Math
.
floor
(
Math
.
random
()
*
taici
[
card
].
length
)].
split
(
"
\n
"
);
_results
=
[];
if
(
dialogues
[
card
])
{
_ref
=
_
.
lines
(
dialogues
[
card
][
Math
.
floor
(
Math
.
random
()
*
dialogues
[
card
].
length
)]);
for
(
_j
=
0
,
_len1
=
_ref
.
length
;
_j
<
_len1
;
_j
++
)
{
line
=
_ref
[
_j
];
_results
.
push
(
stoc_send
(
client
,
'
CHAT
'
,
{
player
:
8
,
msg
:
line
}));
stoc_send_chat
(
client
,
line
);
}
return
_results
;
}
}
if
(
constants
.
MSG
[
msg
]
===
'
WIN
'
)
{
player
=
buffer
.
readUInt8
(
1
);
type
=
buffer
.
readUInt8
(
2
);
return
console
.
log
(
player
,
type
);
}
});
http
.
createServer
(
function
(
request
,
response
)
{
...
...
@@ -559,21 +585,44 @@
return
_results
;
},
900000
);
/*
request = require 'request'
request
url: 'https://forum.my-card.in/admin/site_contents/faq'
json: true
, (error, response, body)->
console.log body
stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
stoc_send client, 'CHAT', {
player: 8
msg: "FAQ: 喵喵喵"
stoc_send_tip
=
function
(
client
,
tip
)
{
var
line
,
lines
,
_j
,
_len1
,
_ref
,
_results
;
lines
=
_
.
lines
(
tip
);
stoc_send_chat
(
client
,
"
Tip:
"
+
lines
[
0
]);
_ref
=
lines
.
slice
(
1
);
_results
=
[];
for
(
_j
=
0
,
_len1
=
_ref
.
length
;
_j
<
_len1
;
_j
++
)
{
line
=
_ref
[
_j
];
_results
.
push
(
stoc_send_chat
(
client
,
line
));
}
*/
return
_results
;
};
stoc_send_random_tip
=
function
(
client
)
{
if
(
tips
)
{
return
stoc_send_tip
(
client
,
tips
[
Math
.
floor
(
Math
.
random
()
*
tips
.
length
)]);
}
};
tips
=
null
;
request
({
url
:
'
https://my-card.in/tips.json
'
,
json
:
true
},
function
(
error
,
response
,
body
)
{
tips
=
body
;
return
console
.
log
(
"
loaded
"
+
tips
.
length
+
"
tips
"
);
});
stoc_follow
(
'
DUEL_START
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
return
stoc_send_random_tip
(
client
);
});
ctos_follow
(
'
CHAT
'
,
false
,
function
(
buffer
,
info
,
client
,
server
)
{
if
(
_
.
trim
(
info
.
msg
)
===
'
/tip
'
)
{
return
stoc_send_random_tip
(
client
);
}
});
/*
# 开包大战
...
...
ygopro-server.map
View file @
e3136397
This diff is collapsed.
Click to expand it.
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