Commit 91aa5d1b authored by mercury233's avatar mercury233
parents b687d05e a956cba1
FROM node FROM node
RUN apt-get update RUN apt-get update
RUN apt-get install -y git build-essential premake4 libfreetype6-dev libevent-dev libsqlite3-dev liblua5.2-dev libglu-dev libirrlicht-dev RUN apt-get install -y git build-essential premake4 libfreetype6-dev libevent-dev libsqlite3-dev liblua5.2-dev mono-complete
RUN mkdir -p /usr/src/app RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app WORKDIR /usr/src/app
...@@ -16,5 +16,13 @@ RUN make config=release ygopro ...@@ -16,5 +16,13 @@ RUN make config=release ygopro
WORKDIR /usr/src/app/ygopro WORKDIR /usr/src/app/ygopro
RUN ln -s bin/release/ygopro ygopro RUN ln -s bin/release/ygopro ygopro
RUN strip ygopro RUN strip ygopro
RUN mv /usr/src/app/windbot /usr/src/app/windbot-source
WORKDIR /usr/src/app/windbot-source
RUN xbuild /property:Configuration=Release /property:OutDir=/usr/src/app/windbot/
WORKDIR /usr/src/app
RUN rm -rf /usr/src/app/windbot-source
RUN ln -s /usr/src/app/ygopro/cards.cdb /usr/src/app/windbot/cards.cdb
WORKDIR /usr/src/app WORKDIR /usr/src/app
CMD [ "npm", "start" ] CMD [ "npm", "start" ]
{ {
"port": 7911, "port": 7911,
"ygopro_path": "ygopro", "ygopro_path": "ygopro",
"modules": { "modules": {
"welcome": "YGOPRO Server", "welcome": "YGOPRO Server",
"update": "请更新游戏版本", "update": "请更新游戏版本",
"stop": false, "stop": false,
"tips": "http://mycard.moe/ygopro/tips.json", "tips": "http://mycard.moe/ygopro/tips.json",
"dialogues": "http://mycard.moe/ygopro/dialogues.json", "dialogues": "http://mycard.moe/ygopro/dialogues.json",
"redis_port": 6379, "redis_port": 6379,
"enable_websocket_roomlist": false, "enable_websocket_roomlist": false,
"enable_random_duel": false, "enable_random_duel": false,
"mycard_auth": false, "mycard_auth": false,
"post_start_watching": true,
"post_start_watching": true, "TCG_banlist_id": 8,
"TCG_banlist_id": 8, "enable_TCG_as_default": false,
"enable_TCG_as_default": false, "http": {
"http": { "port": 7922,
"port": 7922, "password": "123456",
"password": "123456", "ssl": {
"ssl": { "enabled": false,
"enabled": false, "port": 7923,
"port": 7923, "cert": "ssl/ygopro-server.crt",
"cert": "ssl/ygopro-server.crt", "key": "ssl/ygopro-server.key"
"key": "ssl/ygopro-server.key" }
} },
} "windbot": [
} {
"name": "啪啪尼",
"deck": "Dragunity",
"dialog": "zh-CN"
}
]
}
} }
...@@ -3,6 +3,7 @@ _.str = require 'underscore.string' ...@@ -3,6 +3,7 @@ _.str = require 'underscore.string'
_.mixin(_.str.exports()); _.mixin(_.str.exports());
spawn = require('child_process').spawn spawn = require('child_process').spawn
spawnSync = require('child_process').spawnSync spawnSync = require('child_process').spawnSync
settings = require './config.json'
ygopro = require './ygopro.js' ygopro = require './ygopro.js'
roomlist = require './roomlist' if settings.modules.enable_websocket_roomlist roomlist = require './roomlist' if settings.modules.enable_websocket_roomlist
bunyan = require 'bunyan' bunyan = require 'bunyan'
...@@ -23,7 +24,6 @@ moment.locale('zh-cn', { relativeTime : { ...@@ -23,7 +24,6 @@ moment.locale('zh-cn', { relativeTime : {
y : '1年', y : '1年',
yy : '%d年' yy : '%d年'
}}) }})
settings = require './config.json'
log = bunyan.createLogger name: "mycard-room" log = bunyan.createLogger name: "mycard-room"
#redisdb = redis.createClient host: "127.0.0.1", port: settings.modules.redis_port #redisdb = redis.createClient host: "127.0.0.1", port: settings.modules.redis_port
...@@ -318,6 +318,16 @@ class Room ...@@ -318,6 +318,16 @@ class Room
player.pre_establish_buffers = [] player.pre_establish_buffers = []
return return
return return
console.log @windbot
if @windbot
spawn 'mono', ['WindBot.exe'], {cwd: 'windbot', env: {
YGOPRO_VERSION: settings.version
YGOPRO_HOST: '127.0.0.1'
YGOPRO_PORT: @port
YGOPRO_NAME: @windbot.name
YGOPRO_DECK: @windbot.deck
YGOPRO_DIALOG: @windbot.dialog
}}
return return
catch catch
@error = "建立房间失败,请重试" @error = "建立房间失败,请重试"
...@@ -413,4 +423,4 @@ class Room ...@@ -413,4 +423,4 @@ class Room
this.delete() this.delete()
return return
module.exports = Room module.exports = Room
\ No newline at end of file
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
spawnSync = require('child_process').spawnSync; spawnSync = require('child_process').spawnSync;
settings = require('./config.json');
ygopro = require('./ygopro.js'); ygopro = require('./ygopro.js');
if (settings.modules.enable_websocket_roomlist) { if (settings.modules.enable_websocket_roomlist) {
...@@ -40,8 +42,6 @@ ...@@ -40,8 +42,6 @@
} }
}); });
settings = require('./config.json');
log = bunyan.createLogger({ log = bunyan.createLogger({
name: "mycard-room" name: "mycard-room"
}); });
...@@ -412,6 +412,20 @@ ...@@ -412,6 +412,20 @@
player.pre_establish_buffers = []; player.pre_establish_buffers = [];
}); });
}); });
console.log(_this.windbot);
if (_this.windbot) {
spawn('mono', ['WindBot.exe'], {
cwd: 'windbot',
env: {
YGOPRO_VERSION: settings.version,
YGOPRO_HOST: '127.0.0.1',
YGOPRO_PORT: _this.port,
YGOPRO_NAME: _this.windbot.name,
YGOPRO_DECK: _this.windbot.deck,
YGOPRO_DIALOG: _this.windbot.dialog
}
});
}
}; };
})(this)); })(this));
} catch (error1) { } catch (error1) {
......
...@@ -320,6 +320,29 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -320,6 +320,29 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
} }
client.end() client.end()
else if settings.modules.windbot and info.pass[0...2] == 'AI'
if info.pass.length > 3 and info.pass[0...3] == 'AI#'
name = info.pass.slice(3)
windbot = _.sample _.filter settings.modules.windbot, (w)->
w.name == name or w.deck == name
if !windbot
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Windbot Name)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
else
windbot = _.sample settings.modules.windbot
room = Room.find_or_create_by_name('AI#' + Math.random().toString()) # 这个 AI# 没有特殊作用, 仅作为标记
room.windbot = windbot
room.private = true
client.room = room
client.room.connect(client)
else if info.pass.length and settings.modules.mycard_auth else if info.pass.length and settings.modules.mycard_auth
ygopro.stoc_send_chat(client,'正在读取用户信息...', 11) ygopro.stoc_send_chat(client,'正在读取用户信息...', 11)
if info.pass.length <= 8 if info.pass.length <= 8
...@@ -719,9 +742,9 @@ if settings.modules.tips ...@@ -719,9 +742,9 @@ if settings.modules.tips
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');
pg.connect process.env.MYCARD_AUTH_DATABASE, (error, client, done)-> pg.connect process.env.MYCARD_AUTH_DATABASE, (error, client, done)->
if(error) throw error if error
return console.error('error fetching client from pool', err);
client.query 'SELECT username, id from users', (error, result)-> client.query 'SELECT username, id from users', (error, result)->
throw error if error
done(); done();
for row in result.rows for row in result.rows
users_cache[row.username] = row.id users_cache[row.username] = row.id
...@@ -737,6 +760,8 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)-> ...@@ -737,6 +760,8 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
for player in client.room.players when player.pos != 7 for player in client.room.players when player.pos != 7
client.room.dueling_players[player.pos] = player client.room.dueling_players[player.pos] = player
client.room.player_datas.push ip:player.remoteAddress, name:player.name client.room.player_datas.push ip:player.remoteAddress, name:player.name
if client.room.windbot
client.room.dueling_players[1 - player.pos] = {}
if settings.modules.tips if settings.modules.tips
ygopro.stoc_send_random_tip(client) ygopro.stoc_send_random_tip(client)
return return
......
...@@ -293,7 +293,7 @@ ...@@ -293,7 +293,7 @@
}); });
ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) { ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var check, decrypted_buffer, finish, i, id, k, l, len, len1, ref, ref1, room, secret; var check, decrypted_buffer, finish, i, id, k, l, len, len1, name, ref, ref1, room, secret, windbot;
if (settings.modules.stop) { if (settings.modules.stop) {
ygopro.stoc_send_chat(client, settings.modules.stop, 11); ygopro.stoc_send_chat(client, settings.modules.stop, 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
...@@ -350,6 +350,29 @@ ...@@ -350,6 +350,29 @@
code: 2 code: 2
}); });
client.end(); client.end();
} else if (settings.modules.windbot && info.pass.slice(0, 2) === 'AI') {
if (info.pass.length > 3 && info.pass.slice(0, 3) === 'AI#') {
name = info.pass.slice(3);
windbot = _.sample(_.filter(settings.modules.windbot, function(w) {
return w.name === name || w.deck === name;
}));
if (!windbot) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Windbot Name)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
} else {
windbot = _.sample(settings.modules.windbot);
}
room = Room.find_or_create_by_name('AI#' + Math.random().toString());
room.windbot = windbot;
room["private"] = true;
client.room = room;
client.room.connect(client);
} else if (info.pass.length && settings.modules.mycard_auth) { } else if (info.pass.length && settings.modules.mycard_auth) {
ygopro.stoc_send_chat(client, '正在读取用户信息...', 11); ygopro.stoc_send_chat(client, '正在读取用户信息...', 11);
if (info.pass.length <= 8) { if (info.pass.length <= 8) {
...@@ -380,7 +403,7 @@ ...@@ -380,7 +403,7 @@
return (checksum & 0xFF) === 0; return (checksum & 0xFF) === 0;
}; };
finish = function(buffer) { finish = function(buffer) {
var action, name, opt1, opt2, opt3, options, room; var action, opt1, opt2, opt3, options;
action = buffer.readUInt8(1) >> 4; action = buffer.readUInt8(1) >> 4;
if (buffer !== decrypted_buffer && (action === 1 || action === 2 || action === 4)) { if (buffer !== decrypted_buffer && (action === 1 || action === 2 || action === 4)) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Unauthorized)', 11); ygopro.stoc_send_chat(client, '主机密码不正确 (Unauthorized)', 11);
...@@ -816,10 +839,13 @@ ...@@ -816,10 +839,13 @@
pg = require('pg'); pg = require('pg');
pg.connect(process.env.MYCARD_AUTH_DATABASE, function(error, client, done) { pg.connect(process.env.MYCARD_AUTH_DATABASE, function(error, client, done) {
if (error) { if (error) {
return console.error('error fetching client from pool', err); throw error;
} }
return client.query('SELECT username, id from users', function(error, result) { return client.query('SELECT username, id from users', function(error, result) {
var k, len, ref, row; var k, len, ref, row;
if (error) {
throw error;
}
done(); done();
ref = result.rows; ref = result.rows;
for (k = 0, len = ref.length; k < len; k++) { for (k = 0, len = ref.length; k < len; k++) {
...@@ -853,6 +879,9 @@ ...@@ -853,6 +879,9 @@
ip: player.remoteAddress, ip: player.remoteAddress,
name: player.name name: player.name
}); });
if (client.room.windbot) {
client.room.dueling_players[1 - player.pos] = {};
}
} }
} }
if (settings.modules.tips) { if (settings.modules.tips) {
......
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