Commit e3136397 authored by 神楽坂玲奈's avatar 神楽坂玲奈

tip

parent 85a01308
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
"author": "zh99998 <zh99998@gmail.com>", "author": "zh99998 <zh99998@gmail.com>",
"dependencies": { "dependencies": {
"underscore": "*", "underscore": "*",
"underscore.string": "*",
"freeport": "*", "freeport": "*",
"struct": "*", "struct": "*",
"inotify": "*" "inotify": "*",
"request": "*"
}, },
"license": "GPLv3", "license": "GPLv3",
"main": "ygopro-server.js", "main": "ygopro-server.js",
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
"CTOS":{ "CTOS":{
"PLAYER_INFO": "CTOS_PlayerInfo", "PLAYER_INFO": "CTOS_PlayerInfo",
"JOIN_GAME":"CTOS_JoinGame", "JOIN_GAME":"CTOS_JoinGame",
"UPDATE_DECK": "deck" "UPDATE_DECK": "deck",
"CHAT": "chat"
}, },
"STOC":{ "STOC":{
"JOIN_GAME":"STOC_JoinGame", "JOIN_GAME":"STOC_JoinGame",
......
...@@ -88,5 +88,8 @@ ...@@ -88,5 +88,8 @@
{"name": "mainc", "type": "unsigned int"}, {"name": "mainc", "type": "unsigned int"},
{"name": "sidec", "type": "unsigned int"}, {"name": "sidec", "type": "unsigned int"},
{"name": "deckbuf", "type": "unsigned int", "length": 75} {"name": "deckbuf", "type": "unsigned int", "length": 75}
],
"chat": [
{"name": "msg", "type": "unsigned short", "length":"255", "encoding": "UTF-16LE"}
] ]
} }
\ No newline at end of file
This diff is collapsed.
...@@ -10,7 +10,11 @@ spawn = require('child_process').spawn ...@@ -10,7 +10,11 @@ spawn = require('child_process').spawn
freeport = require 'freeport' freeport = require 'freeport'
Struct = require('struct').Struct Struct = require('struct').Struct
_ = require 'underscore' _ = require 'underscore'
_.str = require 'underscore.string'
_.mixin(_.str.exports());
_.str.include('Underscore.string', 'string');
Inotify = require('inotify').Inotify Inotify = require('inotify').Inotify
request = require 'request'
#常量/类型声明 #常量/类型声明
structs_declaration = require './structs.json' #结构体声明 structs_declaration = require './structs.json' #结构体声明
...@@ -165,6 +169,15 @@ ctos_send = (socket, proto, info)-> ...@@ -165,6 +169,15 @@ ctos_send = (socket, proto, info)->
socket.write buffer if buffer.length socket.write buffer if buffer.length
console.log 'ctos_sent:', buffer if debug 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)-> server_listener = (port, client, server)->
client.connected = true client.connected = true
...@@ -373,23 +386,32 @@ stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -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)-> stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
msg = buffer.readInt8(0) msg = buffer.readInt8(0)
if constants.MSG[msg] == 'SUMMONING' or constants.MSG[msg] == 'SPSUMMONING' if constants.MSG[msg] == 'SUMMONING' or constants.MSG[msg] == 'SPSUMMONING'
card = buffer.readUInt32LE(1) card = buffer.readUInt32LE(1)
if taici[card] if dialogues[card]
for line in taici[card][Math.floor(Math.random() * taici[card].length)].split("\n") for line in _.lines dialogues[card][Math.floor(Math.random() * dialogues[card].length)]
stoc_send client, 'CHAT', { stoc_send_chat client, line
player: 8 #积分
msg: 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)-> #stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)->
# console.log 'HS_PLAYER_CHANGE', info # console.log 'HS_PLAYER_CHANGE', info
#stoc_follow 'CHAT', false, (buffer, info, client, server)->
# console.log info, buffer
#房间数量 #房间数量
http.createServer (request, response)-> http.createServer (request, response)->
...@@ -429,23 +451,30 @@ setInterval ()-> ...@@ -429,23 +451,30 @@ setInterval ()->
room.process.kill() room.process.kill()
, 900000 , 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 tips = null
###
request = require 'request'
request request
url: 'https://forum.my-card.in/admin/site_contents/faq' url: 'https://my-card.in/tips.json'
json: true json: true
, (error, response, body)-> , (error, response, body)->
console.log body tips = body
console.log "loaded #{tips.length} tips"
stoc_follow 'DUEL_START', false, (buffer, info, client, server)-> stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
stoc_send client, 'CHAT', { stoc_send_random_tip(client)
player: 8
msg: "FAQ: 喵喵喵" ctos_follow 'CHAT', false, (buffer, info, client, server)->
} if _.trim(info.msg) == '/tip'
### stoc_send_random_tip(client)
### ###
# 开包大战 # 开包大战
......
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
(function() { (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'); net = require('net');
...@@ -20,8 +20,16 @@ ...@@ -20,8 +20,16 @@
_ = require('underscore'); _ = require('underscore');
_.str = require('underscore.string');
_.mixin(_.str.exports());
_.str.include('Underscore.string', 'string');
Inotify = require('inotify').Inotify; Inotify = require('inotify').Inotify;
request = require('request');
structs_declaration = require('./structs.json'); structs_declaration = require('./structs.json');
typedefs = require('./typedefs.json'); typedefs = require('./typedefs.json');
...@@ -241,6 +249,16 @@ ...@@ -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) { server_listener = function(port, client, server) {
var buffer, stoc_buffer, stoc_message_length, stoc_proto, _j, _len1, _ref; var buffer, stoc_buffer, stoc_message_length, stoc_proto, _j, _len1, _ref;
client.connected = true; client.connected = true;
...@@ -486,26 +504,34 @@ ...@@ -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) { 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); msg = buffer.readInt8(0);
if (constants.MSG[msg] === 'SUMMONING' || constants.MSG[msg] === 'SPSUMMONING') { if (constants.MSG[msg] === 'SUMMONING' || constants.MSG[msg] === 'SPSUMMONING') {
card = buffer.readUInt32LE(1); card = buffer.readUInt32LE(1);
if (taici[card]) { if (dialogues[card]) {
_ref = taici[card][Math.floor(Math.random() * taici[card].length)].split("\n"); _ref = _.lines(dialogues[card][Math.floor(Math.random() * dialogues[card].length)]);
_results = [];
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
line = _ref[_j]; line = _ref[_j];
_results.push(stoc_send(client, 'CHAT', { stoc_send_chat(client, line);
player: 8,
msg: 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) { http.createServer(function(request, response) {
...@@ -559,21 +585,44 @@ ...@@ -559,21 +585,44 @@
return _results; return _results;
}, 900000); }, 900000);
/* stoc_send_tip = function(client, tip) {
request = require 'request' var line, lines, _j, _len1, _ref, _results;
request lines = _.lines(tip);
url: 'https://forum.my-card.in/admin/site_contents/faq' stoc_send_chat(client, "Tip: " + lines[0]);
json: true _ref = lines.slice(1);
, (error, response, body)-> _results = [];
console.log body for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
line = _ref[_j];
stoc_follow 'DUEL_START', false, (buffer, info, client, server)-> _results.push(stoc_send_chat(client, line));
stoc_send client, 'CHAT', {
player: 8
msg: "FAQ: 喵喵喵"
} }
*/ 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);
}
});
/* /*
# 开包大战 # 开包大战
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment