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

tip

parent 85a01308
......@@ -14,9 +14,11 @@
"author": "zh99998 <zh99998@gmail.com>",
"dependencies": {
"underscore": "*",
"underscore.string": "*",
"freeport": "*",
"struct": "*",
"inotify": "*"
"inotify": "*",
"request": "*"
},
"license": "GPLv3",
"main": "ygopro-server.js",
......
......@@ -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",
......
......@@ -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
This diff is collapsed.
......@@ -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)
###
# 开包大战
......
// 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);
}
});
/*
# 开包大战
......
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