Commit 39af0bcd authored by mercury233's avatar mercury233

fix long ai name

parent 5bf73b28
......@@ -225,12 +225,14 @@ ROOM_find_or_create_ai = (name)->
name = 'AI'
if name[0...3] == 'AI_'
name = 'AI#' + name.slice(3)
namea = name.split('#')
if room = ROOM_find_by_name(name)
return room
else if name == 'AI'
windbot = _.sample settings.modules.windbots
name = 'AI#' + Math.floor(Math.random() * 100000)
else if ainame = name.split('#')[1]
else if namea.length>1
ainame = namea[namea.length-1]
windbot = _.sample _.filter settings.modules.windbots, (w)->
w.name == ainame or w.deck == ainame
if !windbot
......@@ -239,7 +241,9 @@ ROOM_find_or_create_ai = (name)->
else
windbot = _.sample settings.modules.windbots
name = name + '#' + Math.floor(Math.random() * 100000)
if name.replace(/[^\x00-\xff]/g,"00").length>20
log.info "long ai name", name
return { "error": "AI房间名过长" }
result = new Room(name)
result.windbot = windbot
return result
......
......@@ -308,19 +308,21 @@
};
ROOM_find_or_create_ai = function(name) {
var ainame, result, room, windbot;
var ainame, namea, result, room, windbot;
if (name === '') {
name = 'AI';
}
if (name.slice(0, 3) === 'AI_') {
name = 'AI#' + name.slice(3);
}
namea = name.split('#');
if (room = ROOM_find_by_name(name)) {
return room;
} else if (name === 'AI') {
windbot = _.sample(settings.modules.windbots);
name = 'AI#' + Math.floor(Math.random() * 100000);
} else if (ainame = name.split('#')[1]) {
} else if (namea.length > 1) {
ainame = namea[namea.length - 1];
windbot = _.sample(_.filter(settings.modules.windbots, function(w) {
return w.name === ainame || w.deck === ainame;
}));
......@@ -334,6 +336,12 @@
windbot = _.sample(settings.modules.windbots);
name = name + '#' + Math.floor(Math.random() * 100000);
}
if (name.replace(/[^\x00-\xff]/g, "00").length > 20) {
log.info("long ai name", name);
return {
"error": "AI房间名过长"
};
}
result = new Room(name);
result.windbot = windbot;
return result;
......
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