Commit 4c934078 authored by mercury233's avatar mercury233

add support for short room code and C盟服 code

parent 2edd956c
...@@ -87,6 +87,7 @@ class Room ...@@ -87,6 +87,7 @@ class Room
else if name[0...2] == 'T#' else if name[0...2] == 'T#'
@hostinfo.mode = 2 @hostinfo.mode = 2
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i) else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i)
@hostinfo.rule = parseInt(param[1]) @hostinfo.rule = parseInt(param[1])
@hostinfo.mode = parseInt(param[2]) @hostinfo.mode = parseInt(param[2])
...@@ -96,64 +97,136 @@ class Room ...@@ -96,64 +97,136 @@ class Room
@hostinfo.start_lp = parseInt(param[6]) @hostinfo.start_lp = parseInt(param[6])
@hostinfo.start_hand = parseInt(param[7]) @hostinfo.start_hand = parseInt(param[7])
@hostinfo.draw_count = parseInt(param[8]) @hostinfo.draw_count = parseInt(param[8])
else if (param = name.match /(.+)#/)
rule=param[1] else if (((param = name.match /(.+)#/) != null) and ( (param[1].length<=2 and param[1].match(/(S|N|M|T)(0|1|2|T|A)/i)) or (param[1].match(/^(S|N|M|T)(0|1|2|O|T|A)(0|1|O|T)/i)) ) )
log.info rule rule=param[1].toUpperCase()
if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/i) log.info "C", rule
switch rule.charAt(0)
when "M","1"
@hostinfo.mode = 1
when "T","2"
@hostinfo.mode = 2
@hostinfo.start_lp = 16000
else
@hostinfo.mode = 0
switch rule.charAt(1)
when "0","O"
@hostinfo.rule = 0
when "1","T"
@hostinfo.rule = 1
else
@hostinfo.rule = 2
switch rule.charAt(2)
when "1","T"
@hostinfo.lflist = settings.modules.TCG_banlist_id
else
@hostinfo.lflist = 0
if ((param = rule.charAt(3).match(/\d/)) > 0)
@hostinfo.time_limit=param*60
switch rule.charAt(4)
when "T","1"
@hostinfo.enable_priority = true
else
@hostinfo.enable_priority = false
switch rule.charAt(5)
when "T","1"
@hostinfo.no_check_deck = true
else
@hostinfo.no_check_deck = false
switch rule.charAt(6)
when "T","1"
@hostinfo.no_shuffle_deck = true
else
@hostinfo.no_shuffle_deck = false
if ((param = rule.charAt(7).match(/\d/)) > 0)
@hostinfo.start_lp=param*4000
if ((param = rule.charAt(8).match(/\d/)) > 0)
@hostinfo.start_hand=param
if ((param = rule.charAt(3).match(/\d/)) >= 0)
@hostinfo.draw_count=param
else if ((param = name.match /(.+)#/) != null)
rule=param[1].toUpperCase()
log.info "233", rule
if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/)
@hostinfo.mode = 1 @hostinfo.mode = 1
if (rule.match /(^|,|,)(T|TAG)(,|,|$)/i)
if (rule.match /(^|,|,)(T|TAG)(,|,|$)/)
@hostinfo.mode = 2 @hostinfo.mode = 2
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/i)
if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/)
@hostinfo.rule = 1 @hostinfo.rule = 1
@hostinfo.lflist = settings.modules.TCG_banlist_id @hostinfo.lflist = settings.modules.TCG_banlist_id
if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/i)
if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/)
@hostinfo.rule = 2 @hostinfo.rule = 2
if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/i)
if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/)
start_lp = parseInt(param[2]) start_lp = parseInt(param[2])
if (start_lp <= 0) then start_lp = 1 if (start_lp <= 0) then start_lp = 1
if (start_lp >= 99999) then start_lp = 99999 if (start_lp >= 99999) then start_lp = 99999
@hostinfo.start_lp = start_lp @hostinfo.start_lp = start_lp
if (param = rule.match /(^|,|,)TIME(\d+)(,|,|$)/i)
if (param = rule.match /(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/)
time_limit = parseInt(param[2]) time_limit = parseInt(param[2])
if (time_limit <= 0) then time_limit = 180 if (time_limit <= 0) then time_limit = 180
if (time_limit >= 1 and time_limit <= 60) then time_limit = time_limit*60 if (time_limit >= 1 and time_limit <= 60) then time_limit = time_limit*60
if (time_limit >= 999) then time_limit = 999 if (time_limit >= 999) then time_limit = 999
@hostinfo.time_limit = time_limit @hostinfo.time_limit = time_limit
if (param = rule.match /(^|,|,)START(\d+)(,|,|$)/i)
if (param = rule.match /(^|,|,)(START|ST)(\d+)(,|,|$)/)
start_hand = parseInt(param[2]) start_hand = parseInt(param[2])
if (start_hand <= 0) then start_hand = 1 if (start_hand <= 0) then start_hand = 1
if (start_hand >= 40) then start_hand = 40 if (start_hand >= 40) then start_hand = 40
@hostinfo.start_hand = start_hand @hostinfo.start_hand = start_hand
if (param = rule.match /(^|,|,)DRAW(\d+)(,|,|$)/i)
if (param = rule.match /(^|,|,)(DRAW|DR)(\d+)(,|,|$)/)
draw_count = parseInt(param[2]) draw_count = parseInt(param[2])
if (draw_count >= 35) then draw_count = 35 if (draw_count >= 35) then draw_count = 35
@hostinfo.draw_count = draw_count @hostinfo.draw_count = draw_count
if (param = rule.match /(^|,|,)LFLIST(\d+)(,|,|$)/i)
if (param = rule.match /(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/)
lflist = parseInt(param[2])-1 lflist = parseInt(param[2])-1
@hostinfo.lflist = lflist @hostinfo.lflist = lflist
if (param = rule.match /(^|,|,)NOLFLIST(,|,|$)/i)
if (rule.match /(^|,|,)(NOLFLIST|NF)(,|,|$)/)
@hostinfo.lflist = -1 @hostinfo.lflist = -1
if (param = rule.match /(^|,|,)NOUNIQUE(,|,|$)/i)
if (rule.match /(^|,|,)(NOUNIQUE|NU)(,|,|$)/)
@hostinfo.rule = 3 @hostinfo.rule = 3
if (param = rule.match /(^|,|,)NOCHECK(,|,|$)/i)
@hostinfo.no_check_deck = "T"
if (param = rule.match /(^|,|,)NOSHUFFLE(,|,|$)/i)
@hostinfo.no_shuffle_deck = "T"
if (param = rule.match /(^|,|,)IGPRIORITY(,|,|$)/i)
@hostinfo.enable_priority = "T"
if (rule.match /(^|,|,)(NOCHECK|NC)(,|,|$)/)
@hostinfo.no_check_deck = true
if (rule.match /(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)
@hostinfo.no_shuffle_deck = true
if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/)
@hostinfo.enable_priority = true
param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'), (if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'), @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit] param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'), (if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'), @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit]
@process = spawn './ygopro', param, cwd: 'ygocore' @process = spawn './ygopro', param, cwd: 'ygocore'
@process.on 'exit', (code)=> @process.on 'exit', (code)=>
#log.info 'room-exit', this.name, this.port, code log.info 'room-exit', this.name, this.port, code
@disconnector = 'server' unless @disconnector @disconnector = 'server' unless @disconnector
this.delete() this.delete()
return return
@process.stdout.setEncoding('utf8') @process.stdout.setEncoding('utf8')
@process.stdout.once 'data', (data)=> @process.stdout.once 'data', (data)=>
log.info data
@established = true @established = true
@port = parseInt data @port = parseInt data
_.each @players, (player)=> _.each @players, (player)=>
......
...@@ -114,24 +114,96 @@ ...@@ -114,24 +114,96 @@
this.hostinfo.start_lp = parseInt(param[6]); this.hostinfo.start_lp = parseInt(param[6]);
this.hostinfo.start_hand = parseInt(param[7]); this.hostinfo.start_hand = parseInt(param[7]);
this.hostinfo.draw_count = parseInt(param[8]); this.hostinfo.draw_count = parseInt(param[8]);
} else if ((param = name.match(/(.+)#/))) { } else if (((param = name.match(/(.+)#/)) !== null) && ((param[1].length <= 2 && param[1].match(/(S|N|M|T)(0|1|2|T|A)/i)) || (param[1].match(/^(S|N|M|T)(0|1|2|O|T|A)(0|1|O|T)/i)))) {
rule = param[1]; rule = param[1].toUpperCase();
log.info(rule); log.info("C", rule);
if (rule.match(/(^|,|,)(M|MATCH)(,|,|$)/i)) { switch (rule.charAt(0)) {
case "M":
case "1":
this.hostinfo.mode = 1;
break;
case "T":
case "2":
this.hostinfo.mode = 2;
this.hostinfo.start_lp = 16000;
break;
default:
this.hostinfo.mode = 0;
}
switch (rule.charAt(1)) {
case "0":
case "O":
this.hostinfo.rule = 0;
break;
case "1":
case "T":
this.hostinfo.rule = 1;
break;
default:
this.hostinfo.rule = 2;
}
switch (rule.charAt(2)) {
case "1":
case "T":
this.hostinfo.lflist = settings.modules.TCG_banlist_id;
break;
default:
this.hostinfo.lflist = 0;
}
if ((param = rule.charAt(3).match(/\d/)) > 0) {
this.hostinfo.time_limit = param * 60;
}
switch (rule.charAt(4)) {
case "T":
case "1":
this.hostinfo.enable_priority = true;
break;
default:
this.hostinfo.enable_priority = false;
}
switch (rule.charAt(5)) {
case "T":
case "1":
this.hostinfo.no_check_deck = true;
break;
default:
this.hostinfo.no_check_deck = false;
}
switch (rule.charAt(6)) {
case "T":
case "1":
this.hostinfo.no_shuffle_deck = true;
break;
default:
this.hostinfo.no_shuffle_deck = false;
}
if ((param = rule.charAt(7).match(/\d/)) > 0) {
this.hostinfo.start_lp = param * 4000;
}
if ((param = rule.charAt(8).match(/\d/)) > 0) {
this.hostinfo.start_hand = param;
}
if ((param = rule.charAt(3).match(/\d/)) >= 0) {
this.hostinfo.draw_count = param;
}
} else if ((param = name.match(/(.+)#/)) !== null) {
rule = param[1].toUpperCase();
log.info("233", rule);
if (rule.match(/(^|,|,)(M|MATCH)(,|,|$)/)) {
this.hostinfo.mode = 1; this.hostinfo.mode = 1;
} }
if (rule.match(/(^|,|,)(T|TAG)(,|,|$)/i)) { if (rule.match(/(^|,|,)(T|TAG)(,|,|$)/)) {
this.hostinfo.mode = 2; this.hostinfo.mode = 2;
this.hostinfo.start_lp = 16000; this.hostinfo.start_lp = 16000;
} }
if (rule.match(/(^|,|,)(TCGONLY|TO)(,|,|$)/i)) { if (rule.match(/(^|,|,)(TCGONLY|TO)(,|,|$)/)) {
this.hostinfo.rule = 1; this.hostinfo.rule = 1;
this.hostinfo.lflist = settings.modules.TCG_banlist_id; this.hostinfo.lflist = settings.modules.TCG_banlist_id;
} }
if (rule.match(/(^|,|,)(OT|TCG)(,|,|$)/i)) { if (rule.match(/(^|,|,)(OT|TCG)(,|,|$)/)) {
this.hostinfo.rule = 2; this.hostinfo.rule = 2;
} }
if ((param = rule.match(/(^|,|,)LP(\d+)(,|,|$)/i))) { if ((param = rule.match(/(^|,|,)LP(\d+)(,|,|$)/))) {
start_lp = parseInt(param[2]); start_lp = parseInt(param[2]);
if (start_lp <= 0) { if (start_lp <= 0) {
start_lp = 1; start_lp = 1;
...@@ -141,7 +213,7 @@ ...@@ -141,7 +213,7 @@
} }
this.hostinfo.start_lp = start_lp; this.hostinfo.start_lp = start_lp;
} }
if ((param = rule.match(/(^|,|,)TIME(\d+)(,|,|$)/i))) { if ((param = rule.match(/(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/))) {
time_limit = parseInt(param[2]); time_limit = parseInt(param[2]);
if (time_limit <= 0) { if (time_limit <= 0) {
time_limit = 180; time_limit = 180;
...@@ -154,7 +226,7 @@ ...@@ -154,7 +226,7 @@
} }
this.hostinfo.time_limit = time_limit; this.hostinfo.time_limit = time_limit;
} }
if ((param = rule.match(/(^|,|,)START(\d+)(,|,|$)/i))) { if ((param = rule.match(/(^|,|,)(START|ST)(\d+)(,|,|$)/))) {
start_hand = parseInt(param[2]); start_hand = parseInt(param[2]);
if (start_hand <= 0) { if (start_hand <= 0) {
start_hand = 1; start_hand = 1;
...@@ -164,31 +236,31 @@ ...@@ -164,31 +236,31 @@
} }
this.hostinfo.start_hand = start_hand; this.hostinfo.start_hand = start_hand;
} }
if ((param = rule.match(/(^|,|,)DRAW(\d+)(,|,|$)/i))) { if ((param = rule.match(/(^|,|,)(DRAW|DR)(\d+)(,|,|$)/))) {
draw_count = parseInt(param[2]); draw_count = parseInt(param[2]);
if (draw_count >= 35) { if (draw_count >= 35) {
draw_count = 35; draw_count = 35;
} }
this.hostinfo.draw_count = draw_count; this.hostinfo.draw_count = draw_count;
} }
if ((param = rule.match(/(^|,|,)LFLIST(\d+)(,|,|$)/i))) { if ((param = rule.match(/(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/))) {
lflist = parseInt(param[2]) - 1; lflist = parseInt(param[2]) - 1;
this.hostinfo.lflist = lflist; this.hostinfo.lflist = lflist;
} }
if ((param = rule.match(/(^|,|,)NOLFLIST(,|,|$)/i))) { if (rule.match(/(^|,|,)(NOLFLIST|NF)(,|,|$)/)) {
this.hostinfo.lflist = -1; this.hostinfo.lflist = -1;
} }
if ((param = rule.match(/(^|,|,)NOUNIQUE(,|,|$)/i))) { if (rule.match(/(^|,|,)(NOUNIQUE|NU)(,|,|$)/)) {
this.hostinfo.rule = 3; this.hostinfo.rule = 3;
} }
if ((param = rule.match(/(^|,|,)NOCHECK(,|,|$)/i))) { if (rule.match(/(^|,|,)(NOCHECK|NC)(,|,|$)/)) {
this.hostinfo.no_check_deck = "T"; this.hostinfo.no_check_deck = true;
} }
if ((param = rule.match(/(^|,|,)NOSHUFFLE(,|,|$)/i))) { if (rule.match(/(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)) {
this.hostinfo.no_shuffle_deck = "T"; this.hostinfo.no_shuffle_deck = true;
} }
if ((param = rule.match(/(^|,|,)IGPRIORITY(,|,|$)/i))) { if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) {
this.hostinfo.enable_priority = "T"; this.hostinfo.enable_priority = true;
} }
} }
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit]; param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit];
...@@ -197,6 +269,7 @@ ...@@ -197,6 +269,7 @@
}); });
this.process.on('exit', (function(_this) { this.process.on('exit', (function(_this) {
return function(code) { return function(code) {
log.info('room-exit', _this.name, _this.port, code);
if (!_this.disconnector) { if (!_this.disconnector) {
_this.disconnector = 'server'; _this.disconnector = 'server';
} }
...@@ -206,6 +279,7 @@ ...@@ -206,6 +279,7 @@
this.process.stdout.setEncoding('utf8'); this.process.stdout.setEncoding('utf8');
this.process.stdout.once('data', (function(_this) { this.process.stdout.once('data', (function(_this) {
return function(data) { return function(data) {
log.info(data);
_this.established = true; _this.established = true;
_this.port = parseInt(data); _this.port = parseInt(data);
_.each(_this.players, function(player) { _.each(_this.players, function(player) {
......
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