Commit 27a922fd authored by JoyJ's avatar JoyJ

AI update

parent 57d97b02
ygopro.ctos_follow_after( ygopro.ctos_follow_after("UPDATE_DECK", true, async (buffer, info, client, server, datas) => {
"UPDATE_DECK",
true,
async (buffer, info, client, server, datas) => {
var room = ROOM_all[client.rid]; var room = ROOM_all[client.rid];
if (!room) { if (!room) {
return null; return null;
} }
if (room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN) { if (room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN) {
return null; return null;
}
if (client.is_local) {
return null;
} }
// if (client.is_local) {
// return null;
// }
var room_parameters = room.name.split("#", 2)[0].split(/[,,]/); //房间名的参数 var room_parameters = room.name.split('#', 2)[0].split(/[,,]/); //房间名的参数
var MirrorMode = false; var MirrorMode = false;
for (var parameter of room_parameters) { for(var parameter of room_parameters) {
if (parameter.toUpperCase() == "MM") { if (parameter.toUpperCase() == "MM") { //关键字[MM]
//关键字[MM] MirrorMode = true;
MirrorMode = true; break;
break; }
}
} }
var AllowSelfDeck = false;
for(var parameter of room_parameters) {
if (parameter.toUpperCase() == "MD") { //关键字[MD]
AllowSelfDeck = true;
break;
}
}
if (AllowSelfDeck && client.name.substr(0,4)=="[MM]") {
return;
}
var deckindex = global.dc_decks_index; var deckindex = global.dc_decks_index;
if (MirrorMode) { if (MirrorMode) {
if (room.mm_deck == undefined) { if (room.mm_deck == undefined) {
global.dc_decks_index++;
if (global.dc_decks_index == global.dc_decks_index_max) {
global.dc_decks_index = 0;
}
room.mm_deck = global.dc_decks_main[deckindex];
room.mm_side = global.dc_decks_side[deckindex];
room.mm_md5 = global.dc_decks_md5[deckindex];
MirrorMode=false;
}
client.main = room.mm_deck;
client.side = room.mm_side;
var compat_deckbuf = client.main.concat(client.side);
client.deckMd5 = room.mm_md5;
}
else {
global.dc_decks_index++; global.dc_decks_index++;
if (global.dc_decks_index == global.dc_decks_index_max) { if (global.dc_decks_index == global.dc_decks_index_max) {
global.dc_decks_index = 0; global.dc_decks_index = 0;
} }
room.mm_deck = global.dc_decks_main[deckindex]; client.main = global.dc_decks_main[deckindex];
room.mm_side = global.dc_decks_side[deckindex]; client.side = global.dc_decks_side[deckindex];
room.mm_md5 = global.dc_decks_md5[deckindex]; var compat_deckbuf = client.main.concat(client.side);
MirrorMode = false; client.deckMd5 = global.dc_decks_md5[deckindex];
}
client.main = room.mm_deck;
client.side = room.mm_side;
var compat_deckbuf = client.main.concat(client.side);
client.deckMd5 = room.mm_md5;
} else {
global.dc_decks_index++;
if (global.dc_decks_index == global.dc_decks_index_max) {
global.dc_decks_index = 0;
}
client.main = global.dc_decks_main[deckindex];
client.side = global.dc_decks_side[deckindex];
var compat_deckbuf = client.main.concat(client.side);
client.deckMd5 = global.dc_decks_md5[deckindex];
} }
ygopro.ctos_send(server, "UPDATE_DECK", { ygopro.ctos_send(server, "UPDATE_DECK", {
mainc: client.main.length, mainc: client.main.length,
sidec: client.side.length, sidec: client.side.length,
deckbuf: compat_deckbuf, deckbuf: compat_deckbuf
}); });
if (MirrorMode) { if (MirrorMode) {
return true; return true;
} }
var sql = var sql = "SELECT * FROM RandomDecks AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM RandomDecks)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;"
"SELECT * FROM RandomDecks AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM RandomDecks)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;";
global.mysqldb.query(sql, null, function(err, result) {
global.mysqldb.query(sql, null, function (err, result) { if (err) {
if (err) { global.mysqldb=mysql.createConnection(global.settings.modules.cloud_replay.mysql);
global.mysqldb = mysql.createConnection( log.info(err);
global.settings.modules.cloud_replay.mysql return;
); }
log.info(err); if (result == null || result.length == 0) {
return; return null;
} }
if (result == null || result.length == 0) { var buff_main = [];
return null; var buff_side = [];
} var cards = result[0].content.split(/[\r\n\t ]+/);
var buff_main = []; var side = false;
var buff_side = []; var valid = false;
var cards = result[0].content.split(/[\r\n\t ]+/); for (var i = 0; i < cards.length; i++) {
var side = false; var code = parseInt(cards[i].trim());
var valid = false; if (!isNaN(code)) {
for (var i = 0; i < cards.length; i++) { if (!side) {
var code = parseInt(cards[i].trim()); buff_main.push(code);
if (!isNaN(code)) { valid = true;
if (!side) { }
buff_main.push(code); else {
valid = true; buff_side.push(code);
} else { }
buff_side.push(code); }
} else if (cards[i].substring(0, 5) == "!side") {
} else if (cards[i].substring(0, 5) == "!side") { side = true;
side = true; }
}
if (valid) {
dc_decks_main[deckindex] = buff_main;
dc_decks_side[deckindex] = buff_side;
dc_decks_md5[deckindex] = result[0].md5;
} }
}
if (valid) {
dc_decks_main[deckindex] = buff_main;
dc_decks_side[deckindex] = buff_side;
dc_decks_md5[deckindex] = result[0].md5;
}
}); });
return true; return true;
} });
);
ygopro.ctos_follow_before("CHAT", true, async function ( ygopro.ctos_follow_before('CHAT', true, async function(buffer, info, client, server, datas) {
buffer, room = ROOM_all[client.rid];
info, if (!room) {
client, return;
server,
datas
) {
room = ROOM_all[client.rid];
if (!room) {
return;
}
if (!client.deckMd5) {
return;
}
var md5 = client.deckMd5;
if (room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING) {
return;
}
var msg = _.trim(info.msg);
if (msg.substring(0, 7) != "/report") {
return;
}
msg = msg.substring(7);
msg = _.trim(msg);
if (msg.length < 2) {
ygopro.stoc_send_chat(
client,
"请以【/report 举报原因】的格式写明举报原因",
ygopro.constants.COLORS.YELLOW
);
return;
}
//"CREATE TABLE DCReportServer(reporterIp varchar(255),reportDate DateTime)";
var sql =
"SELECT * FROM `DCReportServer` WHERE reporterIp=? AND reportDate > date_sub(now(), interval 5 minute)";
sqlParams = [client.ip];
mysqldb.query(sql, sqlParams, function (err, result) {
if (err) {
mysql.createConnection(settings.modules.cloud_replay.mysql);
log.info(err);
ygopro.stoc_send_chat(
client,
"服务器出现异常,请重试",
ygopro.constants.COLORS.RED
);
return;
} }
if (result.length > 0) { if (!client.deckMd5) {
ygopro.stoc_send_chat( return;
client,
"服务器端的举报在5分钟内只能进行一次,请稍后再试",
ygopro.constants.COLORS.YELLOW
);
return;
} }
sql = "INSERT INTO `DCReportServer` VALUES(?,now())"; var md5 = client.deckMd5;
sqlParams = [client.ip]; if (room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING) {
mysqldb.query(sql, sqlParams, function (err, result) { return;
if (err) { }
global.mysqldb = mysql.createConnection( var msg = _.trim(info.msg);
global.settings.modules.cloud_replay.mysql if (msg.substring(0, 7) != "/report") {
); return;
log.info(err); }
ygopro.stoc_send_chat( msg = msg.substring(7);
client, msg = _.trim(msg);
"出现异常,请重试", if (msg.length < 2) {
ygopro.constants.COLORS.RED ygopro.stoc_send_chat(client, "请以【/report 举报原因】的格式写明举报原因", ygopro.constants.COLORS.YELLOW);
);
return; return;
} }
sql = "SELECT * FROM DCDeckNoChangeList WHERE deckMd5=?"; //"CREATE TABLE DCReportServer(reporterIp varchar(255),reportDate DateTime)";
sqlParams = [md5]; var sql = "SELECT * FROM `DCReportServer` WHERE reporterIp=? AND reportDate > date_sub(now(), interval 5 minute)";
mysqldb.query(sql, sqlParams, function (err, result) { sqlParams = [client.ip];
mysqldb.query(sql, sqlParams, function(err, result) {
if (err) { if (err) {
global.mysqldb = mysql.createConnection( mysql.createConnection(settings.modules.cloud_replay.mysql);
global.settings.modules.cloud_replay.mysql log.info(err);
); ygopro.stoc_send_chat(client, "服务器出现异常,请重试", ygopro.constants.COLORS.RED);
log.info(err); return;
ygopro.stoc_send_chat(
client,
"例外库无法检索卡组,提交失败",
ygopro.constants.COLORS.RED
);
return;
} }
if (result.length > 0) { if (result.length > 0) {
ygopro.stoc_send_chat( ygopro.stoc_send_chat(client, "服务器端的举报在5分钟内只能进行一次,请稍后再试", ygopro.constants.COLORS.YELLOW);
client,
"此卡组已被判定为无需修改,提交失败",
ygopro.constants.COLORS.RED
);
return;
}
msg =
new Date().toString() +
" - 由服务器端提交(提交者:" +
client.name +
"\r\n\r\n" +
msg;
sql = "INSERT INTO DCReport VALUES(?,?,?,'')";
sqlParams = [md5, client.ip, msg];
mysqldb.query(sql, sqlParams, function (err, result) {
if (err) {
global.mysqldb = mysql.createConnection(
global.settings.modules.cloud_replay.mysql
);
log.info(err);
ygopro.stoc_send_chat(
client,
"提交失败",
ygopro.constants.COLORS.RED
);
return; return;
} }
ygopro.stoc_send_chat( sql = "INSERT INTO `DCReportServer` VALUES(?,now())";
client, sqlParams = [client.ip];
"提交成功,感谢您的举报。\n举报ID为" + mysqldb.query(sql, sqlParams, function(err, result) {
md5 + if (err) {
",可用编年史客户端查看并修改。", global.mysqldb=mysql.createConnection(global.settings.modules.cloud_replay.mysql);
ygopro.constants.COLORS.YELLOW log.info(err);
); ygopro.stoc_send_chat(client, "出现异常,请重试", ygopro.constants.COLORS.RED);
return;
}
sql = "SELECT * FROM DCDeckNoChangeList WHERE deckMd5=?";
sqlParams = [md5];
mysqldb.query(sql, sqlParams, function(err, result) {
if (err) {
global.mysqldb=mysql.createConnection(global.settings.modules.cloud_replay.mysql);
log.info(err);
ygopro.stoc_send_chat(client, "例外库无法检索卡组,提交失败", ygopro.constants.COLORS.RED);
return;
}
if (result.length > 0) {
ygopro.stoc_send_chat(client, "此卡组已被判定为无需修改,提交失败", ygopro.constants.COLORS.RED);
return;
}
msg = (new Date().toString()) + " - 由服务器端提交(提交者:" + client.name + "\r\n\r\n" + msg;
sql = "INSERT INTO DCReport VALUES(?,?,?,'')";
sqlParams = [md5, client.ip, msg];
mysqldb.query(sql, sqlParams, function(err, result) {
if (err) {
global.mysqldb=mysql.createConnection(global.settings.modules.cloud_replay.mysql);
log.info(err);
ygopro.stoc_send_chat(client, "提交失败", ygopro.constants.COLORS.RED);
return;
}
ygopro.stoc_send_chat(client, "提交成功,感谢您的举报。\n举报ID为"+md5+",可用编年史客户端查看并修改。", ygopro.constants.COLORS.YELLOW);
});
});
}); });
});
}); });
}); return true;
return true;
}); });
ygopro.stoc_follow_after( ygopro.stoc_follow_after("DUEL_START", false, (buffer, info, client, server, datas) => {
"DUEL_START",
false,
(buffer, info, client, server, datas) => {
var room = ROOM_all[client.rid]; var room = ROOM_all[client.rid];
room.mm_deck = null; room.mm_deck = null;
} });
);
ygopro.stoc_follow_after( ygopro.stoc_follow_after("CHANGE_SIDE", true, (buffer, info, client, server, datas) => {
"CHANGE_SIDE",
true,
(buffer, info, client, server, datas) => {
var room = ROOM_all[client.rid]; var room = ROOM_all[client.rid];
if (!room) { if (!room) {
return false; return false;
}
if (client.is_local) {
return false;
} }
// if (client.is_local) {
// return false;
// }
var room_parameters = room.name.split("#", 2)[0].split(/[,,]/); //房间名的参数 var room_parameters = room.name.split('#', 2)[0].split(/[,,]/); //房间名的参数
var MirrorMode = false; var MirrorMode = false;
for (var parameter of room_parameters) { for(var parameter of room_parameters) {
if (parameter.toUpperCase() == "MM") { if (parameter.toUpperCase() == "MM") { //关键字[MM]
//关键字[MM] MirrorMode = true;
MirrorMode = true; break;
break; }
}
} }
var deckindex = global.dc_decks_index; var deckindex = global.dc_decks_index;
if (MirrorMode) { if (MirrorMode) {
if (room.mm_deck == null) { if (room.mm_deck == null) {
global.dc_decks_index++; global.dc_decks_index++;
if (global.dc_decks_index == global.dc_decks_index_max) {
global.dc_decks_index = 0;
}
room.mm_deck = global.dc_decks_main[deckindex];
room.mm_side = global.dc_decks_side[deckindex];
room.mm_md5 = global.dc_decks_md5[deckindex];
MirrorMode=false;
}
client.main = room.mm_deck;
client.side = room.mm_side;
var compat_deckbuf = client.main.concat(client.side);
client.deckMd5 = room.mm_md5;
}
else {
global.dc_decks_index++;
if (global.dc_decks_index == global.dc_decks_index_max) { if (global.dc_decks_index == global.dc_decks_index_max) {
global.dc_decks_index = 0; global.dc_decks_index = 0;
} }
room.mm_deck = global.dc_decks_main[deckindex]; client.main = global.dc_decks_main[deckindex];
room.mm_side = global.dc_decks_side[deckindex]; client.side = global.dc_decks_side[deckindex];
room.mm_md5 = global.dc_decks_md5[deckindex]; var compat_deckbuf = client.main.concat(client.side);
MirrorMode = false; client.deckMd5 = global.dc_decks_md5[deckindex];
}
client.main = room.mm_deck;
client.side = room.mm_side;
var compat_deckbuf = client.main.concat(client.side);
client.deckMd5 = room.mm_md5;
} else {
global.dc_decks_index++;
if (global.dc_decks_index == global.dc_decks_index_max) {
global.dc_decks_index = 0;
}
client.main = global.dc_decks_main[deckindex];
client.side = global.dc_decks_side[deckindex];
var compat_deckbuf = client.main.concat(client.side);
client.deckMd5 = global.dc_decks_md5[deckindex];
} }
ygopro.ctos_send(server, "UPDATE_DECK", { ygopro.ctos_send(server, "UPDATE_DECK", {
mainc: client.main.length, mainc: client.main.length,
sidec: client.side.length, sidec: client.side.length,
deckbuf: compat_deckbuf, deckbuf: compat_deckbuf
}); });
if (MirrorMode) { if (MirrorMode) {
return true; return true;
} }
var sql = var sql = "SELECT * FROM RandomDecks AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM RandomDecks)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;"
"SELECT * FROM RandomDecks AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM RandomDecks)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;";
global.mysqldb.query(sql, null, function(err, result) {
global.mysqldb.query(sql, null, function (err, result) { if (err) {
if (err) { global.mysqldb=mysql.createConnection(global.settings.modules.cloud_replay.mysql);
global.mysqldb = mysql.createConnection( log.info(err);
global.settings.modules.cloud_replay.mysql return;
); }
log.info(err); if (result == null || result.length == 0) {
return; return null;
} }
if (result == null || result.length == 0) { var buff_main = [];
return null; var buff_side = [];
} var cards = result[0].content.split(/[\r\n\t ]+/);
var buff_main = []; var side = false;
var buff_side = []; var valid = false;
var cards = result[0].content.split(/[\r\n\t ]+/); for (var i = 0; i < cards.length; i++) {
var side = false; var code = parseInt(cards[i].trim());
var valid = false; if (!isNaN(code)) {
for (var i = 0; i < cards.length; i++) { if (!side) {
var code = parseInt(cards[i].trim()); buff_main.push(code);
if (!isNaN(code)) { valid = true;
if (!side) { }
buff_main.push(code); else {
valid = true; buff_side.push(code);
} else { }
buff_side.push(code); }
} else if (cards[i].substring(0, 5) == "!side") {
} else if (cards[i].substring(0, 5) == "!side") { side = true;
side = true; }
}
if (valid) {
dc_decks_main[deckindex] = buff_main;
dc_decks_side[deckindex] = buff_side;
dc_decks_md5[deckindex] = result[0].md5;
} }
}
if (valid) {
dc_decks_main[deckindex] = buff_main;
dc_decks_side[deckindex] = buff_side;
dc_decks_md5[deckindex] = result[0].md5;
}
}); });
return true; return true;
} });
);
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