Commit 1fcaaa19 authored by nanahira's avatar nanahira

Merge branch 'master' of git.mycard.moe:nanahira/srvpro

parents 33727617 36683943
Pipeline #33669 failed with stages
in 16 minutes and 40 seconds
...@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); ...@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeDeck = exports.encodeDeck = void 0; exports.decodeDeck = exports.encodeDeck = void 0;
const assert_1 = __importDefault(require("assert")); const assert_1 = __importDefault(require("assert"));
function encodeDeck(deck) { function encodeDeck(deck) {
deck.main ??= [];
deck.side ??= [];
let pointer = 0; let pointer = 0;
const bufferSize = (2 + deck.main.length + deck.side.length) * 4; const bufferSize = (2 + deck.main.length + deck.side.length) * 4;
const buffer = Buffer.allocUnsafe(bufferSize); const buffer = Buffer.allocUnsafe(bufferSize);
......
...@@ -6,6 +6,8 @@ export interface Deck { ...@@ -6,6 +6,8 @@ export interface Deck {
} }
export function encodeDeck(deck: Deck) { export function encodeDeck(deck: Deck) {
deck.main ??= [];
deck.side ??= [];
let pointer = 0; let pointer = 0;
const bufferSize = (2 + deck.main.length + deck.side.length) * 4; const bufferSize = (2 + deck.main.length + deck.side.length) * 4;
const buffer = Buffer.allocUnsafe(bufferSize); const buffer = Buffer.allocUnsafe(bufferSize);
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
"draw_count": 1, "draw_count": 1,
"time_limit": 180, "time_limit": 180,
"no_watch": false, "no_watch": false,
"auto_death": false "auto_death": false,
"bo5": false,
"sideins": false
}, },
"modules": { "modules": {
"welcome": "MyCard YGOPro Server", "welcome": "MyCard YGOPro Server",
......
...@@ -278,7 +278,7 @@ loadLFList = (path) -> ...@@ -278,7 +278,7 @@ loadLFList = (path) ->
lflists.push({date: moment(list.match(/!([\d\.]+)/)[1], 'YYYY.MM.DD').utcOffset("-08:00"), tcg: list.indexOf('TCG') != -1}) lflists.push({date: moment(list.match(/!([\d\.]+)/)[1], 'YYYY.MM.DD').utcOffset("-08:00"), tcg: list.indexOf('TCG') != -1})
catch catch
init = () -> init = () ->
log.info('Reading config.') log.info('Reading config.')
await createDirectoryIfNotExists("./config") await createDirectoryIfNotExists("./config")
await importOldConfig() await importOldConfig()
...@@ -624,6 +624,13 @@ init = () -> ...@@ -624,6 +624,13 @@ init = () ->
return return
, 60000) , 60000)
# clean zombie rooms
setInterval ()->
for room in ROOM_all when room and !room.players.length
room.terminate()
return
, 300000
if settings.modules.random_duel.enabled if settings.modules.random_duel.enabled
setInterval ()-> setInterval ()->
for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.random_type and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0 and (!settings.modules.side_timeout or room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING) and !room.recovered for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.random_type and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0 and (!settings.modules.side_timeout or room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING) and !room.recovered
...@@ -642,6 +649,7 @@ init = () -> ...@@ -642,6 +649,7 @@ init = () ->
return return
, 1000 , 1000
if settings.modules.mycard.enabled if settings.modules.mycard.enabled
setInterval ()-> setInterval ()->
for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.arena and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0 and (!settings.modules.side_timeout or room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING) and !room.recovered for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.arena and room.last_active_time and room.waiting_for_player and room.get_disconnected_count() == 0 and (!settings.modules.side_timeout or room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING) and !room.recovered
...@@ -826,7 +834,7 @@ ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = (name, player ...@@ -826,7 +834,7 @@ ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = (name, player
return await ROOM_find_or_create_random(uname, player_ip) return await ROOM_find_or_create_random(uname, player_ip)
if room = ROOM_find_by_name(name) if room = ROOM_find_by_name(name)
return room return room
else if memory_usage >= 90 or (settings.modules.max_rooms_count and rooms_count >= settings.modules.max_rooms_count) else if memory_usage >= 95 or (settings.modules.max_rooms_count and rooms_count >= settings.modules.max_rooms_count)
return null return null
else else
room = new Room(name) room = new Room(name)
...@@ -868,7 +876,7 @@ ROOM_find_or_create_random = global.ROOM_find_or_create_random = (type, player_i ...@@ -868,7 +876,7 @@ ROOM_find_or_create_random = global.ROOM_find_or_create_random = (type, player_i
if result if result
result.welcome = '${random_duel_enter_room_waiting}' result.welcome = '${random_duel_enter_room_waiting}'
#log.info 'found room', player_name #log.info 'found room', player_name
else if memory_usage < 90 and not (settings.modules.max_rooms_count and rooms_count >= settings.modules.max_rooms_count) else if memory_usage < 95 and not (settings.modules.max_rooms_count and rooms_count >= settings.modules.max_rooms_count)
type = if type then type else settings.modules.random_duel.default_type type = if type then type else settings.modules.random_duel.default_type
name = type + ',RANDOM#' + Math.floor(Math.random() * 100000) name = type + ',RANDOM#' + Math.floor(Math.random() * 100000)
result = new Room(name) result = new Room(name)
...@@ -1489,6 +1497,13 @@ class Room ...@@ -1489,6 +1497,13 @@ class Room
else else
@hostinfo.auto_death = 40 @hostinfo.auto_death = 40
if (rule.match /(^|,|,)(30EX|SIDEINS)(,|,|$)/)
@hostinfo.sideins = true
if (rule.match /(^|,|,)(BO5|BESTOF5)(,|,|$)/)
@hostinfo.mode = 1
@hostinfo.bo5 = true
if settings.modules.tournament_mode.enable_recover and (param = rule.match /(^|,|,)(RC|RECOVER)(\d*)T(\d*)(,|,|$)/) if settings.modules.tournament_mode.enable_recover and (param = rule.match /(^|,|,)(RC|RECOVER)(\d*)T(\d*)(,|,|$)/)
@recovered = true @recovered = true
@recovering = true @recovering = true
...@@ -1510,7 +1525,12 @@ class Room ...@@ -1510,7 +1525,12 @@ class Room
@spawn() @spawn()
spawn: (firstSeed) -> spawn: (firstSeed) ->
param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, @hostinfo.duel_rule, duel_rule_flags = (@hostinfo.duel_rule & 0xf)
if @hostinfo.sideins
duel_rule_flags |= 0x10
if @hostinfo.bo5
duel_rule_flags |= 0x20
param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, duel_rule_flags,
(if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck 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, @hostinfo.replay_mode] @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit, @hostinfo.replay_mode]
...@@ -1747,8 +1767,11 @@ class Room ...@@ -1747,8 +1767,11 @@ class Room
add_windbot: (botdata)-> add_windbot: (botdata)->
@windbot = botdata @windbot = botdata
bot_url = "http://#{settings.modules.windbot.server_ip}:#{settings.modules.windbot.port}/?name=#{encodeURIComponent(botdata.name)}&deck=#{encodeURIComponent(botdata.deck)}&host=#{settings.modules.windbot.my_ip}&port=#{settings.port}&dialog=#{encodeURIComponent(botdata.dialog)}&version=#{settings.version}&password=#{encodeURIComponent(@name)}"
if botdata.deckcode
bot_url += "&deckcode=#{encodeURIComponent(botdata.deckcode.toString('base64'))}"
request request
url: "http://#{settings.modules.windbot.server_ip}:#{settings.modules.windbot.port}/?name=#{encodeURIComponent(botdata.name)}&deck=#{encodeURIComponent(botdata.deck)}&host=#{settings.modules.windbot.my_ip}&port=#{settings.port}&dialog=#{encodeURIComponent(botdata.dialog)}&version=#{settings.version}&password=#{encodeURIComponent(@name)}" url: bot_url
, (error, response, body)=> , (error, response, body)=>
if error if error
log.warn 'windbot add error', error, this.name log.warn 'windbot add error', error, this.name
...@@ -2789,7 +2812,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2789,7 +2812,7 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
ygopro.stoc_send_chat_to_room(room, "${death_remain_final}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat_to_room(room, "${death_remain_final}", ygopro.constants.COLORS.BABYBLUE)
else else
ygopro.stoc_send_chat_to_room(room, "${death_remain_part1}" + (room.death - room.turn) + "${death_remain_part2}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat_to_room(room, "${death_remain_part1}" + (room.death - room.turn) + "${death_remain_part2}", ygopro.constants.COLORS.BABYBLUE)
if client.surrend_confirm if client.surrend_confirm and (r_player & 0x2) == 0
client.surrend_confirm = false client.surrend_confirm = false
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE)
......
...@@ -791,6 +791,16 @@ ...@@ -791,6 +791,16 @@
} }
}, 60000); }, 60000);
} }
// clean zombie rooms
setInterval(function() {
var l, len1, room;
for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (room && !room.players.length) {
room.terminate();
}
}
}, 300000);
if (settings.modules.random_duel.enabled) { if (settings.modules.random_duel.enabled) {
setInterval(async function() { setInterval(async function() {
var l, len1, room, time_passed; var l, len1, room, time_passed;
...@@ -1062,7 +1072,7 @@ ...@@ -1062,7 +1072,7 @@
} }
if (room = ROOM_find_by_name(name)) { if (room = ROOM_find_by_name(name)) {
return room; return room;
} else if (memory_usage >= 90 || (settings.modules.max_rooms_count && rooms_count >= settings.modules.max_rooms_count)) { } else if (memory_usage >= 95 || (settings.modules.max_rooms_count && rooms_count >= settings.modules.max_rooms_count)) {
return null; return null;
} else { } else {
room = new Room(name); room = new Room(name);
...@@ -1115,7 +1125,7 @@ ...@@ -1115,7 +1125,7 @@
if (result) { if (result) {
result.welcome = '${random_duel_enter_room_waiting}'; result.welcome = '${random_duel_enter_room_waiting}';
//log.info 'found room', player_name //log.info 'found room', player_name
} else if (memory_usage < 90 && !(settings.modules.max_rooms_count && rooms_count >= settings.modules.max_rooms_count)) { } else if (memory_usage < 95 && !(settings.modules.max_rooms_count && rooms_count >= settings.modules.max_rooms_count)) {
type = type ? type : settings.modules.random_duel.default_type; type = type ? type : settings.modules.random_duel.default_type;
name = type + ',RANDOM#' + Math.floor(Math.random() * 100000); name = type + ',RANDOM#' + Math.floor(Math.random() * 100000);
result = new Room(name); result = new Room(name);
...@@ -1931,6 +1941,13 @@ ...@@ -1931,6 +1941,13 @@
this.hostinfo.auto_death = 40; this.hostinfo.auto_death = 40;
} }
} }
if (rule.match(/(^|,|,)(30EX|SIDEINS)(,|,|$)/)) {
this.hostinfo.sideins = true;
}
if (rule.match(/(^|,|,)(BO5|BESTOF5)(,|,|$)/)) {
this.hostinfo.mode = 1;
this.hostinfo.bo5 = true;
}
if (settings.modules.tournament_mode.enable_recover && (param = rule.match(/(^|,|,)(RC|RECOVER)(\d*)T(\d*)(,|,|$)/))) { if (settings.modules.tournament_mode.enable_recover && (param = rule.match(/(^|,|,)(RC|RECOVER)(\d*)T(\d*)(,|,|$)/))) {
this.recovered = true; this.recovered = true;
this.recovering = true; this.recovering = true;
...@@ -1956,8 +1973,15 @@ ...@@ -1956,8 +1973,15 @@
} }
spawn(firstSeed) { spawn(firstSeed) {
var e, i, j, l, param, seeds; var duel_rule_flags, e, i, j, l, param, seeds;
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, this.hostinfo.duel_rule, (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, this.hostinfo.replay_mode]; duel_rule_flags = this.hostinfo.duel_rule & 0xf;
if (this.hostinfo.sideins) {
duel_rule_flags |= 0x10;
}
if (this.hostinfo.bo5) {
duel_rule_flags |= 0x20;
}
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, duel_rule_flags, (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, this.hostinfo.replay_mode];
if (firstSeed) { if (firstSeed) {
param.push(firstSeed); param.push(firstSeed);
seeds = getSeedTimet(2); seeds = getSeedTimet(2);
...@@ -2307,9 +2331,14 @@ ...@@ -2307,9 +2331,14 @@
} }
add_windbot(botdata) { add_windbot(botdata) {
var bot_url;
this.windbot = botdata; this.windbot = botdata;
bot_url = `http://${settings.modules.windbot.server_ip}:${settings.modules.windbot.port}/?name=${encodeURIComponent(botdata.name)}&deck=${encodeURIComponent(botdata.deck)}&host=${settings.modules.windbot.my_ip}&port=${settings.port}&dialog=${encodeURIComponent(botdata.dialog)}&version=${settings.version}&password=${encodeURIComponent(this.name)}`;
if (botdata.deckcode) {
bot_url += `&deckcode=${encodeURIComponent(botdata.deckcode.toString('base64'))}`;
}
request({ request({
url: `http://${settings.modules.windbot.server_ip}:${settings.modules.windbot.port}/?name=${encodeURIComponent(botdata.name)}&deck=${encodeURIComponent(botdata.deck)}&host=${settings.modules.windbot.my_ip}&port=${settings.port}&dialog=${encodeURIComponent(botdata.dialog)}&version=${settings.version}&password=${encodeURIComponent(this.name)}` url: bot_url
}, (error, response, body) => { }, (error, response, body) => {
if (error) { if (error) {
log.warn('windbot add error', error, this.name); log.warn('windbot add error', error, this.name);
...@@ -3656,7 +3685,7 @@ ...@@ -3656,7 +3685,7 @@
} }
} }
} }
if (client.surrend_confirm) { if (client.surrend_confirm && (r_player & 0x2) === 0) {
client.surrend_confirm = false; client.surrend_confirm = false;
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE);
} }
......
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