Commit 44e3a13b authored by nanahira's avatar nanahira Committed by GitHub

Merge pull request #1 from moecube/master

mg
parents 4e22671d c12e2ad3
This diff is collapsed.
## ygopro-server
## SRVPro
一个YGOPro服务器。
现用于[萌卡](https://mycard.moe/)[YGOPRO 233服](http://mercury233.me/ygosrv233/)
现用于[萌卡](https://mycard.moe/)[YGOPro 233服](https://ygo233.com/)
### 支持功能
* Linux上运行
......@@ -12,7 +12,7 @@
* 广播消息
* 召唤台词
* 先行卡一键更新
* Windbot在线AI
* WindBot在线AI
* 萌卡用户登陆
### 不支持功能
......@@ -21,13 +21,12 @@
### 使用方法
* 可参考[wiki](https://github.com/mercury233/ygopro-server/wiki)安装
* 手动安装:
* 安装修改后的YGOPro服务端:https://github.com/mycard/ygopro/tree/server
* `git clone https://github.com/mycard/ygopro-server.git`
* `cd ygopro-server`
* 安装修改后的YGOPro服务端:https://github.com/moecube/ygopro/tree/server
* `git clone https://github.com/moecube/srvpro.git`
* `cd srvpro`
* `npm install`
*`config.json`复制为`config.user.json`并进行修改
* `port`为你想要的端口
* `modules.stop`为文本时,表示服务器关闭
* ~~更多选项参见wiki~~
* `node ygopro-server.js`即可运行
* 简易的控制台在 http://mercury233.me/ygosrv233/dashboard.html
......@@ -61,3 +60,21 @@
* expansions updater
* user and admin account system
* new database for cloud replay
### License
SRVPro
Copyright (C) 2013-2017 MoeCube Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
......@@ -40,6 +40,7 @@
},
"random_duel": {
"enabled": false,
"no_rematch_check": false,
"hang_timeout": 90
},
"cloud_replay": {
......@@ -89,6 +90,11 @@
"password": "123456",
"port": 7933
},
"test_mode": {
"watch_public_hand": false,
"no_connect_count_limit": false,
"no_ban_player": false
},
"pre_util": {
"enabled": false,
"port": 7944,
......
......@@ -344,7 +344,7 @@ var packDatas = function () {
execSync('cp -r "' + config.db_path +'script" "'+ config.db_path +'expansions/script"');
execSync('cp -r "' + config.db_path +'pics" "'+ config.db_path +'expansions/pics"');
execSync('cp -r "' + config.db_path +'pics/field" "'+ config.db_path +'picture/field"');
var proc = spawn("7za", ["a", "-x!*.zip", "-x!mobile.cdb", "-x!cdb", "-x!script", "-x!pics", "-x!picture", "ygosrv233-pre.zip", "*"], { cwd: config.db_path, env: process.env });
var proc = spawn("7za", ["a", "-x!*.zip", "-x!mobile.cdb", "-x!cdb", "-x!script", "-x!pics", "-x!expansions/pics/thumbnail", "-x!picture", "ygosrv233-pre.zip", "*"], { cwd: config.db_path, env: process.env });
proc.stdout.setEncoding('utf8');
proc.stdout.on('data', function(data) {
//sendResponse("7z: "+data);
......@@ -358,7 +358,7 @@ var packDatas = function () {
execSync('rm -rf "' + config.db_path +'expansions/script" "'+ config.db_path +'expansions/pics"');
sendResponse("电脑更新包打包完成。");
});
var proc2 = spawn("7za", ["a", "-x!*.zip", "-x!expansions", "-x!cdb", "-x!pics/thumbnail", "-x!picture", "ygosrv233-pre-mobile.zip", "*"], { cwd: config.db_path, env: process.env });
var proc2 = spawn("7za", ["a", "-x!*.zip", "-x!expansions/pics", "-x!expansions/script", "-x!cdb", "-x!pics/thumbnail", "-x!picture", "ygosrv233-pre-mobile.zip", "*"], { cwd: config.db_path, env: process.env });
proc2.stdout.setEncoding('utf8');
proc2.stdout.on('data', function(data) {
//sendResponse("7z: "+data);
......@@ -371,7 +371,7 @@ var packDatas = function () {
execSync('mv -f "' + config.db_path +'ygosrv233-pre-mobile.zip" "'+ file_path +'"');
sendResponse("手机更新包打包完成。");
});
var proc3 = spawn("7za", ["a", "-x!*.zip", "-x!mobile.cdb", "-x!expansions", "-x!pics", "ygosrv233-pre-2.zip", "*"], { cwd: config.db_path, env: process.env });
var proc3 = spawn("7za", ["a", "-x!*.zip", "-x!expansions", "-x!pics", "ygosrv233-pre-2.zip", "*"], { cwd: config.db_path, env: process.env });
proc3.stdout.setEncoding('utf8');
proc3.stdout.on('data', function(data) {
//sendResponse("7z: "+data);
......
......@@ -163,6 +163,7 @@ ban_user = (name) ->
# automatically ban user to use random duel
ROOM_ban_player = (name, ip, reason, countadd = 1)->
return if settings.modules.test_mode.no_ban_player
bannedplayer = _.find ROOM_players_banned, (bannedplayer)->
ip == bannedplayer.ip
if bannedplayer
......@@ -211,7 +212,8 @@ ROOM_find_or_create_random = (type, player_ip)->
return room and room.random_type != '' and !room.started and
((type == '' and room.random_type != 'T') or room.random_type == type) and
room.get_playing_player().length < max_player and
(room.get_host() == null or room.get_host().ip != ROOM_players_oppentlist[player_ip]) and
(settings.modules.random_duel.no_rematch_check or room.get_host() == null or
room.get_host().ip != ROOM_players_oppentlist[player_ip]) and
(playerbanned == room.deprecated or type == 'T')
if result
result.welcome = '${random_duel_enter_room_waiting}'
......@@ -596,7 +598,7 @@ class Room
net.createServer (client) ->
client.ip = client.remoteAddress
connect_count = ROOM_connected_ip[client.ip] or 0
if client.ip != '::ffff:127.0.0.1'
if !settings.modules.test_mode.no_connect_count_limit and client.ip != '::ffff:127.0.0.1'
connect_count++
ROOM_connected_ip[client.ip] = connect_count
#log.info "connect", client.ip, ROOM_connected_ip[client.ip]
......@@ -862,6 +864,7 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#log.info info
info.pass=info.pass.trim()
if settings.modules.stop
ygopro.stoc_die(client, settings.modules.stop)
......@@ -905,7 +908,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
replay_id=Cloud_replay_ids[Math.floor(Math.random()*Cloud_replay_ids.length)]
redisdb.hgetall "replay:"+replay_id, client.open_cloud_replay
else if info.version != settings.version and (info.version < 9020 or settings.version != 4927) #强行兼容23333版
else if info.version != settings.version # and (info.version < 9020 or settings.version != 4927) #强行兼容23333版
ygopro.stoc_send_chat(client, settings.modules.update, ygopro.constants.COLORS.RED)
ygopro.stoc_send client, 'ERROR_MSG', {
msg: 4
......@@ -922,12 +925,12 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
ygopro.stoc_die(client, '${invalid_password_length}')
return
if info.version >= 9020 and settings.version == 4927 #强行兼容23333版
info.version = settings.version
struct = ygopro.structs["CTOS_JoinGame"]
struct._setBuff(buffer)
struct.set("version", info.version)
buffer = struct.buffer
#if info.version >= 9020 and settings.version == 4927 #强行兼容23333版
# info.version = settings.version
# struct = ygopro.structs["CTOS_JoinGame"]
# struct._setBuff(buffer)
# struct.set("version", info.version)
# buffer = struct.buffer
buffer = new Buffer(info.pass[0...8], 'base64')
......@@ -1097,13 +1100,13 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
ygopro.stoc_die(client, "${invalid_password_room}")
else
if info.version >= 9020 and settings.version == 4927 #强行兼容23333版
info.version = settings.version
struct = ygopro.structs["CTOS_JoinGame"]
struct._setBuff(buffer)
struct.set("version", info.version)
buffer = struct.buffer
#ygopro.stoc_send_chat(client, "看起来你是YGOMobile的用户,请记得更新先行卡补丁,否则会看到白卡", ygopro.constants.COLORS.GREEN)
#if info.version >= 9020 and settings.version == 4927 #强行兼容23333版
# info.version = settings.version
# struct = ygopro.structs["CTOS_JoinGame"]
# struct._setBuff(buffer)
# struct.set("version", info.version)
# buffer = struct.buffer
# #ygopro.stoc_send_chat(client, "看起来你是YGOMobile的用户,请记得更新先行卡补丁,否则会看到白卡", ygopro.constants.COLORS.GREEN)
#log.info 'join_game',info.pass, client.name
room = ROOM_find_or_create_by_name(info.pass, client.ip)
......@@ -1175,7 +1178,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
return
if settings.modules.cloud_replay.enable_halfway_watch and !room.watcher
room.watcher = watcher = net.connect room.port, ->
room.watcher = watcher = if settings.modules.test_mode.watch_public_hand then room.recorder else net.connect room.port, ->
ygopro.ctos_send watcher, 'PLAYER_INFO', {
name: "the Big Brother"
}
......@@ -1767,7 +1770,15 @@ if settings.modules.mycard.enabled
# spawn windbot
if settings.modules.windbot.spawn
windbot_process = spawn 'mono', ['WindBot.exe', settings.modules.windbot.port], {cwd: 'windbot'}
if /^win/.test(process.platform)
windbot_bin = 'WindBot.exe'
windbot_parameters = []
else
windbot_bin = 'mono'
windbot_parameters = ['WindBot.exe']
windbot_parameters.push('ServerMode=true')
windbot_parameters.push('ServerPort='+settings.modules.windbot.port)
windbot_process = spawn windbot_bin, windbot_parameters, {cwd: 'windbot'}
windbot_process.on 'error', (err)->
log.warn 'WindBot ERROR', err
return
......
// Generated by CoffeeScript 1.12.2
(function() {
var Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, _, addCallback, ban_user, bunyan, cppversion, crypto, date, defaultconfig, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, list, load_dialogues, load_tips, log, moment, nconf, net, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, report_to_big_brother, request, requestListener, roomlist, settings, spawn, spawnSync, url, users_cache, wait_room_start, windbot_process, ygopro, zlib;
var Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, _, addCallback, ban_user, bunyan, cppversion, crypto, date, defaultconfig, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, list, load_dialogues, load_tips, log, moment, nconf, net, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, report_to_big_brother, request, requestListener, roomlist, settings, spawn, spawnSync, url, users_cache, wait_room_start, windbot_bin, windbot_parameters, windbot_process, ygopro, zlib;
net = require('net');
......@@ -221,6 +221,9 @@
if (countadd == null) {
countadd = 1;
}
if (settings.modules.test_mode.no_ban_player) {
return;
}
bannedplayer = _.find(ROOM_players_banned, function(bannedplayer) {
return ip === bannedplayer.ip;
});
......@@ -292,7 +295,7 @@
max_player = type === 'T' ? 4 : 2;
playerbanned = bannedplayer && bannedplayer.count > 3 && moment() < bannedplayer.time;
result = _.find(ROOM_all, function(room) {
return room && room.random_type !== '' && !room.started && ((type === '' && room.random_type !== 'T') || room.random_type === type) && room.get_playing_player().length < max_player && (room.get_host() === null || room.get_host().ip !== ROOM_players_oppentlist[player_ip]) && (playerbanned === room.deprecated || type === 'T');
return room && room.random_type !== '' && !room.started && ((type === '' && room.random_type !== 'T') || room.random_type === type) && room.get_playing_player().length < max_player && (settings.modules.random_duel.no_rematch_check || room.get_host() === null || room.get_host().ip !== ROOM_players_oppentlist[player_ip]) && (playerbanned === room.deprecated || type === 'T');
});
if (result) {
result.welcome = '${random_duel_enter_room_waiting}';
......@@ -799,7 +802,7 @@
var connect_count, server;
client.ip = client.remoteAddress;
connect_count = ROOM_connected_ip[client.ip] || 0;
if (client.ip !== '::ffff:127.0.0.1') {
if (!settings.modules.test_mode.no_connect_count_limit && client.ip !== '::ffff:127.0.0.1') {
connect_count++;
}
ROOM_connected_ip[client.ip] = connect_count;
......@@ -1086,7 +1089,8 @@
});
ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var check, decrypted_buffer, finish, i, id, j, k, len, len1, name, ref, ref1, replay_id, room, secret, struct;
var check, decrypted_buffer, finish, i, id, j, k, len, len1, name, ref, ref1, replay_id, room, secret;
info.pass = info.pass.trim();
if (settings.modules.stop) {
ygopro.stoc_die(client, settings.modules.stop);
} else if (info.pass.toUpperCase() === "R" && settings.modules.cloud_replay.enabled) {
......@@ -1132,7 +1136,7 @@
} else if (info.pass.toUpperCase() === "W" && settings.modules.cloud_replay.enabled) {
replay_id = Cloud_replay_ids[Math.floor(Math.random() * Cloud_replay_ids.length)];
redisdb.hgetall("replay:" + replay_id, client.open_cloud_replay);
} else if (info.version !== settings.version && (info.version < 9020 || settings.version !== 4927)) {
} else if (info.version !== settings.version) {
ygopro.stoc_send_chat(client, settings.modules.update, ygopro.constants.COLORS.RED);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 4,
......@@ -1147,13 +1151,6 @@
ygopro.stoc_die(client, '${invalid_password_length}');
return;
}
if (info.version >= 9020 && settings.version === 4927) {
info.version = settings.version;
struct = ygopro.structs["CTOS_JoinGame"];
struct._setBuff(buffer);
struct.set("version", info.version);
buffer = struct.buffer;
}
buffer = new Buffer(info.pass.slice(0, 8), 'base64');
if (buffer.length !== 6) {
ygopro.stoc_die(client, '${invalid_password_payload}');
......@@ -1333,13 +1330,6 @@
} else if (info.pass.length && !ROOM_validate(info.pass)) {
ygopro.stoc_die(client, "${invalid_password_room}");
} else {
if (info.version >= 9020 && settings.version === 4927) {
info.version = settings.version;
struct = ygopro.structs["CTOS_JoinGame"];
struct._setBuff(buffer);
struct.set("version", info.version);
buffer = struct.buffer;
}
room = ROOM_find_or_create_by_name(info.pass, client.ip);
if (!room) {
ygopro.stoc_die(client, "${server_full}");
......@@ -1418,7 +1408,7 @@
recorder.on('error', function(error) {});
}
if (settings.modules.cloud_replay.enable_halfway_watch && !room.watcher) {
room.watcher = watcher = net.connect(room.port, function() {
room.watcher = watcher = settings.modules.test_mode.watch_public_hand ? room.recorder : net.connect(room.port, function() {
ygopro.ctos_send(watcher, 'PLAYER_INFO', {
name: "the Big Brother"
});
......@@ -2220,7 +2210,16 @@
}
if (settings.modules.windbot.spawn) {
windbot_process = spawn('mono', ['WindBot.exe', settings.modules.windbot.port], {
if (/^win/.test(process.platform)) {
windbot_bin = 'WindBot.exe';
windbot_parameters = [];
} else {
windbot_bin = 'mono';
windbot_parameters = ['WindBot.exe'];
}
windbot_parameters.push('ServerMode=true');
windbot_parameters.push('ServerPort=' + settings.modules.windbot.port);
windbot_process = spawn(windbot_bin, windbot_parameters, {
cwd: 'windbot'
});
windbot_process.on('error', function(err) {
......
......@@ -117,7 +117,7 @@ for name, declaration of structs_declaration
return
for line in _.lines(msg)
if player>=10
line="[System]: "+line
line="[Server]: "+line
for o,r of i18ns[client.lang]
re=new RegExp("\\$\\{"+o+"\\}",'g')
line=line.replace(re,r)
......
......@@ -181,7 +181,7 @@
for (j = 0, len1 = ref.length; j < len1; j++) {
line = ref[j];
if (player >= 10) {
line = "[System]: " + line;
line = "[Server]: " + line;
}
ref1 = i18ns[client.lang];
for (o in ref1) {
......
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