Commit ed7f6950 authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:moecube/srvpro into mc

parents 9aeaa05d 4e8e35b9
Pipeline #4758 passed with stages
in 5 minutes and 5 seconds
......@@ -178,6 +178,7 @@ settings = {}
tips = null
dialogues = null
badwords = null
badwordR = null
lflists = global.lflists = []
real_windbot_server_ip = null
long_resolve_cards = []
......@@ -380,6 +381,13 @@ init = () ->
await loadLFList('ygopro/expansions/lflist.conf')
await loadLFList('ygopro/lflist.conf')
badwordR = global.badwordR = {}
badwordR.level0=new RegExp('(?:'+badwords.level0.join(')|(?:')+')','i');
badwordR.level1=new RegExp('(?:'+badwords.level1.join(')|(?:')+')','i');
badwordR.level1g=new RegExp('(?:'+badwords.level1.join(')|(?:')+')','ig');
badwordR.level2=new RegExp('(?:'+badwords.level2.join(')|(?:')+')','i');
badwordR.level3=new RegExp('(?:'+badwords.level3.join(')|(?:')+')','i');
setInterval ()->
moment_now = moment()
moment_now_string = moment_now.format()
......@@ -2151,24 +2159,15 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
}
options.lflist = _.findIndex lflists, (list)-> ((options.rule == 1) == list.tcg) and list.date.isBefore()
room_title = info.pass.slice(8).replace(String.fromCharCode(0xFEFF), ' ')
if _.any(badwords.level3, (badword) ->
regexp = new RegExp(badword, 'i')
return room_title.match(regexp)
, room_title)
if badwordR.level3.test(room_title)
log.warn("BAD ROOM NAME LEVEL 3", room_title, client.name, client.ip)
ygopro.stoc_die(client, "${bad_roomname_level3}")
return
else if _.any(badwords.level2, (badword) ->
regexp = new RegExp(badword, 'i')
return room_title.match(regexp)
, room_title)
else if badwordR.level2.test(room_title)
log.warn("BAD ROOM NAME LEVEL 2", room_title, client.name, client.ip)
ygopro.stoc_die(client, "${bad_roomname_level2}")
return
else if _.any(badwords.level1, (badword) ->
regexp = new RegExp(badword, 'i')
return room_title.match(regexp)
, room_title)
else if badwordR.level1.test(room_title)
log.warn("BAD ROOM NAME LEVEL 1", room_title, client.name, client.ip)
ygopro.stoc_die(client, "${bad_roomname_level1}")
return
......@@ -2383,24 +2382,15 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
log.warn("MULTI LOGIN", client.name, client.ip)
ygopro.stoc_die(client, "${too_much_connection}" + client.ip)
else if !settings.modules.tournament_mode.enabled and !settings.modules.challonge.enabled and _.any(badwords.level3, (badword) ->
regexp = new RegExp(badword, 'i')
return name.match(regexp)
, name = client.name)
else if !settings.modules.tournament_mode.enabled and !settings.modules.challonge.enabled and badwordR.level3.test(client.name)
log.warn("BAD NAME LEVEL 3", client.name, client.ip)
ygopro.stoc_die(client, "${bad_name_level3}")
else if !settings.modules.tournament_mode.enabled and !settings.modules.challonge.enabled and _.any(badwords.level2, (badword) ->
regexp = new RegExp(badword, 'i')
return name.match(regexp)
, name = client.name)
else if !settings.modules.tournament_mode.enabled and !settings.modules.challonge.enabled and badwordR.level2.test(client.name)
log.warn("BAD NAME LEVEL 2", client.name, client.ip)
ygopro.stoc_die(client, "${bad_name_level2}")
else if !settings.modules.tournament_mode.enabled and !settings.modules.challonge.enabled and _.any(badwords.level1, (badword) ->
regexp = new RegExp(badword, 'i')
return name.match(regexp)
, name = client.name)
else if !settings.modules.tournament_mode.enabled and !settings.modules.challonge.enabled and badwordR.level1.test(client.name)
log.warn("BAD NAME LEVEL 1", client.name, client.ip)
ygopro.stoc_die(client, "${bad_name_level1}")
......@@ -3192,10 +3182,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
ygopro.stoc_send_chat(client, "${banned_chat_tip}" + (if client.ban_mc and client.ban_mc.message then (": " + client.ban_mc.message) else ""), ygopro.constants.COLORS.RED)
return true
oldmsg = msg
if (_.any(badwords.level3, (badword) ->
regexp = new RegExp(badword, 'i')
return msg.match(regexp)
, msg))
if badwordR.level3.test(msg)
log.warn "BAD WORD LEVEL 3", client.name, client.ip, oldmsg, RegExp.$1
report_to_big_brother room.name, client.name, client.ip, 3, oldmsg, RegExp.$1
cancel = true
......@@ -3221,22 +3208,14 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
client.abuse_count=client.abuse_count+2
ygopro.stoc_send_chat(client, "${chat_warn_level0}", ygopro.constants.COLORS.RED)
cancel = true
else if (_.any(badwords.level2, (badword) ->
regexp = new RegExp(badword, 'i')
return msg.match(regexp)
, msg))
else if badwordR.level2.test(msg)
log.warn "BAD WORD LEVEL 2", client.name, client.ip, oldmsg, RegExp.$1
report_to_big_brother room.name, client.name, client.ip, 2, oldmsg, RegExp.$1
client.abuse_count=client.abuse_count+3
ygopro.stoc_send_chat(client, "${chat_warn_level2}", ygopro.constants.COLORS.RED)
cancel = true
else
_.each(badwords.level1, (badword) ->
#log.info msg
regexp = new RegExp(badword, "ig")
msg = msg.replace(regexp, "**")
return
, msg)
msg = msg.replace(badwordR.level1g,'**')
if oldmsg != msg
log.warn "BAD WORD LEVEL 1", client.name, client.ip, oldmsg, RegExp.$1
report_to_big_brother room.name, client.name, client.ip, 1, oldmsg, RegExp.$1
......@@ -3246,10 +3225,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
struct._setBuff(buffer)
struct.set("msg", msg)
buffer = struct.buffer
else if (_.any(badwords.level0, (badword) ->
regexp = new RegExp(badword, 'i')
return msg.match(regexp)
, msg))
else if badwordR.level0.test(msg)
log.info "BAD WORD LEVEL 0", client.name, client.ip, oldmsg, RegExp.$1
report_to_big_brother room.name, client.name, client.ip, 0, oldmsg, RegExp.$1
if client.abuse_count>=2
......
This diff is collapsed.
......@@ -7,6 +7,15 @@ loadJSON = require('load-json-file').sync
@i18ns = loadJSON './data/i18n.json'
@i18nR = {}
for lang, data of @i18ns
@i18nR[lang]={}
for key, text of data
@i18nR[lang][key]={
regex: new RegExp("\\$\\{"+key+"\\}",'g'),
text: text
}
YGOProMessagesHelper = require("./YGOProMessages.js").YGOProMessagesHelper # 为 SRVPro2 准备的库,这里拿这个库只用来测试,SRVPro1 对异步支持不是特别完善,因此不会有很多异步优化
@helper = new YGOProMessagesHelper(9000)
......@@ -54,9 +63,8 @@ translateHandler = (handler) ->
for line in _.lines(msg)
if player>=10
line="[Server]: "+line
for o,r of @i18ns[client.lang]
re=new RegExp("\\$\\{"+o+"\\}",'g')
line=line.replace(re,r)
for o,r of @i18nR[client.lang]
line=line.replace(r.regex, r.text)
@stoc_send client, 'CHAT', {
player: player
msg: line
......
// Generated by CoffeeScript 2.5.1
(function() {
var Struct, YGOProMessagesHelper, _, loadJSON, translateHandler;
var Struct, YGOProMessagesHelper, _, data, key, lang, loadJSON, ref, text, translateHandler;
_ = require('underscore');
......@@ -14,6 +14,21 @@
this.i18ns = loadJSON('./data/i18n.json');
this.i18nR = {};
ref = this.i18ns;
for (lang in ref) {
data = ref[lang];
this.i18nR[lang] = {};
for (key in data) {
text = data[key];
this.i18nR[lang][key] = {
regex: new RegExp("\\$\\{" + key + "\\}", 'g'),
text: text
};
}
}
YGOProMessagesHelper = require("./YGOProMessages.js").YGOProMessagesHelper; // 为 SRVPro2 准备的库,这里拿这个库只用来测试,SRVPro1 对异步支持不是特别完善,因此不会有很多异步优化
this.helper = new YGOProMessagesHelper(9000);
......@@ -69,22 +84,21 @@
//util
this.stoc_send_chat = function(client, msg, player = 8) {
var i, len, line, o, r, re, ref, ref1;
var i, len, line, o, r, ref1, ref2;
if (!client) {
console.log("err stoc_send_chat");
return;
}
ref = _.lines(msg);
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
ref1 = _.lines(msg);
for (i = 0, len = ref1.length; i < len; i++) {
line = ref1[i];
if (player >= 10) {
line = "[Server]: " + line;
}
ref1 = this.i18ns[client.lang];
for (o in ref1) {
r = ref1[o];
re = new RegExp("\\$\\{" + o + "\\}", 'g');
line = line.replace(re, r);
ref2 = this.i18nR[client.lang];
for (o in ref2) {
r = ref2[o];
line = line.replace(r.regex, r.text);
}
this.stoc_send(client, 'CHAT', {
player: player,
......@@ -94,21 +108,21 @@
};
this.stoc_send_chat_to_room = function(room, msg, player = 8) {
var client, i, j, len, len1, ref, ref1;
var client, i, j, len, len1, ref1, ref2;
if (!room) {
console.log("err stoc_send_chat_to_room");
return;
}
ref = room.players;
for (i = 0, len = ref.length; i < len; i++) {
client = ref[i];
ref1 = room.players;
for (i = 0, len = ref1.length; i < len; i++) {
client = ref1[i];
if (client) {
this.stoc_send_chat(client, msg, player);
}
}
ref1 = room.watchers;
for (j = 0, len1 = ref1.length; j < len1; j++) {
client = ref1[j];
ref2 = room.watchers;
for (j = 0, len1 = ref2.length; j < len1; j++) {
client = ref2[j];
if (client) {
this.stoc_send_chat(client, msg, player);
}
......@@ -116,14 +130,14 @@
};
this.stoc_send_hint_card_to_room = function(room, card) {
var client, i, j, len, len1, ref, ref1;
var client, i, j, len, len1, ref1, ref2;
if (!room) {
console.log("err stoc_send_hint_card_to_room");
return;
}
ref = room.players;
for (i = 0, len = ref.length; i < len; i++) {
client = ref[i];
ref1 = room.players;
for (i = 0, len = ref1.length; i < len; i++) {
client = ref1[i];
if (client) {
this.stoc_send(client, 'GAME_MSG', {
curmsg: 2,
......@@ -133,9 +147,9 @@
});
}
}
ref1 = room.watchers;
for (j = 0, len1 = ref1.length; j < len1; j++) {
client = ref1[j];
ref2 = room.watchers;
for (j = 0, len1 = ref2.length; j < len1; j++) {
client = ref2[j];
if (client) {
this.stoc_send(client, 'GAME_MSG', {
curmsg: 2,
......
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