Commit 693361fd authored by nanahira's avatar nanahira

random duel ban

parent c8b15204
......@@ -2,6 +2,7 @@
jsconfig.json
coffeelint.json
.vscode/
.idea
password.json
config.*.json
......
......@@ -2,6 +2,7 @@
jsconfig.json
coffeelint.json
.vscode/
.idea
password.json
config.*.json
......
......@@ -9,6 +9,8 @@ const typeorm_1 = require("typeorm");
const CloudReplay_1 = require("./entities/CloudReplay");
const CloudReplayPlayer_1 = require("./entities/CloudReplayPlayer");
const Ban_1 = require("./entities/Ban");
const RandomDuelBan_1 = require("./entities/RandomDuelBan");
const underscore_1 = __importDefault(require("underscore"));
class DataManager {
constructor(config, log) {
this.config = config;
......@@ -125,6 +127,62 @@ class DataManager {
return null;
}
}
async getRandomDuelBan(ip) {
const repo = this.db.getRepository(RandomDuelBan_1.RandomDuelBan);
try {
const ban = await repo.findOne(ip);
//console.log(ip, ban);
return ban;
}
catch (e) {
this.log.warn(`Failed to fetch random duel ban ${ip}: ${e.toString()}`);
return null;
}
}
async updateRandomDuelBan(ban) {
const repo = this.db.getRepository(RandomDuelBan_1.RandomDuelBan);
try {
await repo.save(ban);
}
catch (e) {
this.log.warn(`Failed to update random duel ban ${ban.ip}: ${e.toString()}`);
}
}
async randomDuelBanPlayer(ip, reason, countadd) {
const count = countadd || 1;
const repo = this.db.getRepository(RandomDuelBan_1.RandomDuelBan);
try {
let ban = await repo.findOne(ip);
if (ban) {
ban.count += count;
const banTime = ban.count > 3 ? Math.pow(2, ban.count - 3) * 2 : 0;
const banDate = moment_1.default(ban.time);
if (moment_1.default().isAfter(banDate)) {
ban.time = moment_1.default().add(banTime, 'm').toDate();
}
else {
ban.time = moment_1.default(banDate).add(banTime, 'm').toDate();
}
if (!underscore_1.default.contains(ban.reasons, reason)) {
ban.reasons.push(reason);
}
ban.needTip = 1;
}
else {
ban = new RandomDuelBan_1.RandomDuelBan();
ban.ip = ip;
ban.time = moment_1.default().toDate();
ban.count = count;
ban.reasons = [reason];
ban.needTip = 1;
}
return await repo.save(ban);
}
catch (e) {
this.log.warn(`Failed to update random duel ban ${ip}: ${e.toString()}`);
return null;
}
}
}
exports.DataManager = DataManager;
//# sourceMappingURL=DataManager.js.map
\ No newline at end of file
......@@ -5,6 +5,8 @@ import { Connection, ConnectionOptions, createConnection, Transaction } from "ty
import { CloudReplay } from "./entities/CloudReplay";
import { CloudReplayPlayer } from "./entities/CloudReplayPlayer";
import { Ban } from "./entities/Ban";
import {RandomDuelBan} from "./entities/RandomDuelBan";
import _ from "underscore";
export interface CloudReplayPlayerInfo {
......@@ -134,4 +136,59 @@ export class DataManager {
return null;
}
}
async getRandomDuelBan(ip: string) {
const repo = this.db.getRepository(RandomDuelBan);
try {
const ban = await repo.findOne(ip);
//console.log(ip, ban);
return ban;
} catch (e) {
this.log.warn(`Failed to fetch random duel ban ${ip}: ${e.toString()}`);
return null;
}
}
async updateRandomDuelBan(ban: RandomDuelBan) {
const repo = this.db.getRepository(RandomDuelBan);
try {
await repo.save(ban);
} catch (e) {
this.log.warn(`Failed to update random duel ban ${ban.ip}: ${e.toString()}`);
}
}
async randomDuelBanPlayer(ip: string, reason: string, countadd?: number){
const count = countadd || 1;
const repo = this.db.getRepository(RandomDuelBan);
try {
let ban = await repo.findOne(ip);
if(ban) {
ban.count += count;
const banTime = ban.count > 3 ? Math.pow(2, ban.count - 3) * 2 : 0;
const banDate = moment(ban.time);
if(moment().isAfter(banDate)) {
ban.time = moment().add(banTime, 'm').toDate();
} else {
ban.time = moment(banDate).add(banTime, 'm').toDate();
}
if(!_.contains(ban.reasons, reason)) {
ban.reasons.push(reason);
}
ban.needTip = 1;
} else {
ban = new RandomDuelBan();
ban.ip = ip;
ban.time = moment().toDate();
ban.count = count;
ban.reasons = [reason];
ban.needTip = 1;
}
return await repo.save(ban);
} catch (e) {
this.log.warn(`Failed to update random duel ban ${ip}: ${e.toString()}`);
return null;
}
}
}
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RandomDuelBan = void 0;
const typeorm_1 = require("typeorm");
let RandomDuelBan = /** @class */ (() => {
let RandomDuelBan = class RandomDuelBan {
setNeedTip(need) {
this.needTip = need ? 1 : 0;
}
getNeedTip() {
return this.needTip > 0 ? true : false;
}
};
__decorate([
typeorm_1.PrimaryColumn({ type: "varchar", length: 64 }),
__metadata("design:type", String)
], RandomDuelBan.prototype, "ip", void 0);
__decorate([
typeorm_1.Column("datetime"),
__metadata("design:type", Date)
], RandomDuelBan.prototype, "time", void 0);
__decorate([
typeorm_1.Column("smallint"),
__metadata("design:type", Number)
], RandomDuelBan.prototype, "count", void 0);
__decorate([
typeorm_1.Column({ type: "simple-array" }),
__metadata("design:type", Array)
], RandomDuelBan.prototype, "reasons", void 0);
__decorate([
typeorm_1.Column({ type: "tinyint", unsigned: true }),
__metadata("design:type", Number)
], RandomDuelBan.prototype, "needTip", void 0);
RandomDuelBan = __decorate([
typeorm_1.Entity()
], RandomDuelBan);
return RandomDuelBan;
})();
exports.RandomDuelBan = RandomDuelBan;
//# sourceMappingURL=RandomDuelBan.js.map
\ No newline at end of file
import {Column, Entity, PrimaryColumn} from "typeorm";
@Entity()
export class RandomDuelBan {
@PrimaryColumn({type: "varchar", length: 64})
ip: string;
@Column("datetime")
time: Date;
@Column("smallint")
count: number;
@Column({type: "simple-array"})
reasons: string[]
@Column({type: "tinyint", unsigned: true})
needTip: number;
setNeedTip(need: boolean) {
this.needTip = need ? 1 : 0;
}
getNeedTip() {
return this.needTip > 0 ? true : false;
}
}
\ No newline at end of file
......@@ -479,11 +479,8 @@ get_memory_usage = get_memory_usage = ()->
get_memory_usage()
setInterval(get_memory_usage, 3000)
Cloud_replay_ids = global.Cloud_replay_ids = []
ROOM_all = global.ROOM_all = []
ROOM_players_oppentlist = global.ROOM_players_oppentlist = {}
ROOM_players_banned = global.ROOM_players_banned = []
ROOM_players_scores = global.ROOM_players_scores = {}
ROOM_connected_ip = global.ROOM_connected_ip = {}
ROOM_bad_ip = global.ROOM_bad_ip = {}
......@@ -507,20 +504,8 @@ ban_user = global.ban_user = (name) ->
# automatically ban user to use random duel
ROOM_ban_player = global.ROOM_ban_player = (name, ip, reason, countadd = 1)->
return if settings.modules.test_mode.no_ban_player
bannedplayer = _.find ROOM_players_banned, (bannedplayer)->
ip == bannedplayer.ip
if bannedplayer
bannedplayer.count = bannedplayer.count + countadd
bantime = if bannedplayer.count > 3 then Math.pow(2, bannedplayer.count - 3) * 2 else 0
bannedplayer.time = if moment() < bannedplayer.time then moment(bannedplayer.time).add(bantime, 'm') else moment().add(bantime, 'm')
bannedplayer.reasons.push(reason) if not _.find bannedplayer.reasons, (bannedreason)->
bannedreason == reason
bannedplayer.need_tip = true
else
bannedplayer = {"ip": ip, "time": moment(), "count": countadd, "reasons": [reason], "need_tip": true}
ROOM_players_banned.push(bannedplayer)
#log.info("banned", name, ip, reason, bannedplayer.count)
return if settings.modules.test_mode.no_ban_player or !settings.modules.mysql.enabled
await dataManager.randomDuelBanPlayer(ip, reason, countadd)
return
ROOM_kick = (name, callback)->
......@@ -601,7 +586,7 @@ ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = (name, player
if settings.modules.windbot.enabled and (uname[0...2] == 'AI' or (!settings.modules.random_duel.enabled and uname == ''))
return ROOM_find_or_create_ai(name)
if settings.modules.random_duel.enabled and (uname == '' or uname == 'S' or uname == 'M' or uname == 'T')
return 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)
return room
else if memory_usage >= 90
......@@ -610,21 +595,24 @@ ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = (name, player
return new Room(name)
ROOM_find_or_create_random = global.ROOM_find_or_create_random = (type, player_ip)->
bannedplayer = _.find ROOM_players_banned, (bannedplayer)->
return player_ip == bannedplayer.ip
if bannedplayer
if bannedplayer.count > 6 and moment() < bannedplayer.time
return {"error": "${random_banned_part1}#{bannedplayer.reasons.join('${random_ban_reason_separator}')}${random_banned_part2}#{moment(bannedplayer.time).fromNow(true)}${random_banned_part3}"}
if bannedplayer.count > 3 and moment() < bannedplayer.time and bannedplayer.need_tip and type != 'T'
bannedplayer.need_tip = false
return {"error": "${random_deprecated_part1}#{bannedplayer.reasons.join('${random_ban_reason_separator}')}${random_deprecated_part2}#{moment(bannedplayer.time).fromNow(true)}${random_deprecated_part3}"}
else if bannedplayer.need_tip
bannedplayer.need_tip = false
return {"error": "${random_warn_part1}#{bannedplayer.reasons.join('${random_ban_reason_separator}')}${random_warn_part2}"}
else if bannedplayer.count > 2
bannedplayer.need_tip = true
if settings.modules.mysql.enabled
randomDuelBanRecord = await dataManager.getRandomDuelBan(player_ip)
if randomDuelBanRecord
if randomDuelBanRecord.count > 6 and moment().isBefore(randomDuelBanRecord.time)
return {"error": "${random_banned_part1}#{randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}${random_banned_part2}#{moment(randomDuelBanRecord.time).fromNow(true)}${random_banned_part3}"}
if randomDuelBanRecord.count > 3 and moment().isBefore(randomDuelBanRecord.time) and randomDuelBanRecord.getNeedTip() and type != 'T'
randomDuelBanRecord.setNeedTip(false)
await dataManager.updateRandomDuelBan(randomDuelBanRecord)
return {"error": "${random_deprecated_part1}#{randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}${random_deprecated_part2}#{moment(randomDuelBanRecord.time).fromNow(true)}${random_deprecated_part3}"}
else if randomDuelBanRecord.getNeedTip()
randomDuelBanRecord.setNeedTip(false)
await dataManager.updateRandomDuelBan(randomDuelBanRecord)
return {"error": "${random_warn_part1}#{randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}${random_warn_part2}"}
else if randomDuelBanRecord.count > 2
randomDuelBanRecord.setNeedTip(true)
await dataManager.updateRandomDuelBan(randomDuelBanRecord)
max_player = if type == 'T' then 4 else 2
playerbanned = (bannedplayer and bannedplayer.count > 3 and moment() < bannedplayer.time)
playerbanned = (randomDuelBanRecord and randomDuelBanRecord.count > 3 and moment() < randomDuelBanRecord.time)
result = _.find ROOM_all, (room)->
return room and room.random_type != '' and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and !room.windbot and
((type == '' and
......@@ -2013,7 +2001,7 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
if match_permit and !match_permit.permit
ygopro.stoc_die(client, '${invalid_password_unauthorized}')
return
room = ROOM_find_or_create_by_name('M#' + info.pass.slice(8))
room = await ROOM_find_or_create_by_name('M#' + info.pass.slice(8))
if room
for player in room.get_playing_player() when player and player.name == client.name
ygopro.stoc_die(client, '${invalid_password_unauthorized}')
......@@ -2211,7 +2199,7 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
create_room_name = 'M#' + found.id
if recover_match
create_room_name = recover_match[0] + ',' + create_room_name
room = ROOM_find_or_create_by_name(create_room_name)
room = await ROOM_find_or_create_by_name(create_room_name)
if room
room.challonge_info = found
# room.max_player = 2
......@@ -2297,7 +2285,7 @@ ygopro.ctos_follow 'JOIN_GAME', true, (buffer, info, client, server, datas)->
buffer = struct.buffer
#log.info 'join_game',info.pass, client.name
room = ROOM_find_or_create_by_name(info.pass, client.ip)
room = await ROOM_find_or_create_by_name(info.pass, client.ip)
if !room
ygopro.stoc_die(client, "${server_full}")
else if room.error
......@@ -2741,7 +2729,7 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server, datas)->
client.kick_count = if client.kick_count then client.kick_count+1 else 1
if client.kick_count>=5 and room.random_type
ygopro.stoc_send_chat_to_room(room, "#{client.name} ${kicked_by_system}", ygopro.constants.COLORS.RED)
ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}")
await ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}")
CLIENT_kick(client)
return true
ygopro.stoc_send_chat_to_room(room, "#{player.name} ${kicked_by_player}", ygopro.constants.COLORS.RED)
......@@ -2856,7 +2844,7 @@ wait_room_start = (room, time)->
else
for player in room.players
if player and player.is_host
ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}")
await ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}")
ygopro.stoc_send_chat_to_room(room, "#{player.name} ${kicked_by_system}", ygopro.constants.COLORS.RED)
CLIENT_kick(player)
await return
......@@ -3119,8 +3107,8 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
cancel = true
if client.abuse_count>0
ygopro.stoc_send_chat(client, "${banned_duel_tip}", ygopro.constants.COLORS.RED)
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}")
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}", 3)
await ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}")
await ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}", 3)
CLIENT_send_replays(client, room)
CLIENT_kick(client)
return true
......@@ -3174,7 +3162,7 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server, datas)->
ROOM_unwelcome(room, client, "${random_ban_reason_abuse}")
if client.abuse_count>=5
ygopro.stoc_send_chat_to_room(room, "#{client.name} ${chat_banned}", ygopro.constants.COLORS.RED)
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}")
await ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}")
if !cancel and settings.modules.display_watchers and client.is_post_watcher
ygopro.stoc_send_chat_to_room(room, "#{client.name}: #{msg}", 9)
return true
......@@ -3484,8 +3472,6 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server, datas)->
ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid]
return settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.block_replay_to_player or settings.modules.replay_delay unless room
if settings.modules.cloud_replay.enabled and room.random_type
Cloud_replay_ids.push room.cloud_replay_id
if !room.replays[room.duel_count - 1]
# console.log("Replay saved: ", room.duel_count - 1, client.pos)
room.replays[room.duel_count - 1] = buffer
......@@ -3534,15 +3520,12 @@ ygopro.stoc_follow 'REPLAY', true, (buffer, info, client, server, datas)->
if settings.modules.random_duel.enabled
setInterval ()->
_async.each(ROOM_all, (room, done) ->
if !(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)
done()
return
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
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
room.last_active_time = moment()
ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}")
await ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}")
room.scores[room.waiting_for_player.name_vpass] = -9
#log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} ${kicked_by_system}", ygopro.constants.COLORS.RED)
......@@ -3551,18 +3534,12 @@ if settings.modules.random_duel.enabled
else if time_passed >= (settings.modules.random_duel.hang_timeout - 20) and not (time_passed % 10)
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} ${afk_warn_part1}#{settings.modules.random_duel.hang_timeout - time_passed}${afk_warn_part2}", ygopro.constants.COLORS.RED)
ROOM_unwelcome(room, room.waiting_for_player, "${random_ban_reason_AFK}")
done()
return
)
return
, 1000
if settings.modules.mycard.enabled
setInterval ()->
_async.each(ROOM_all, (room, done) ->
if not (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)
done()
return
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
time_passed = Math.floor((moment() - room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.random_duel.hang_timeout
......@@ -3574,15 +3551,10 @@ if settings.modules.mycard.enabled
CLIENT_kick(room.waiting_for_player)
else if time_passed >= (settings.modules.random_duel.hang_timeout - 20) and not (time_passed % 10)
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} ${afk_warn_part1}#{settings.modules.random_duel.hang_timeout - time_passed}${afk_warn_part2}", ygopro.constants.COLORS.RED)
done()
return
)
return
if true # settings.modules.arena_mode.punish_quit_before_match
_async.each(ROOM_all, (room, done) ->
if not (room and room.arena and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.get_playing_player().length < 2)
done()
return
for room in ROOM_all when room and room.arena and room.duel_stage == ygopro.constants.DUEL_STAGE.BEGIN and room.get_playing_player().length < 2
player = room.get_playing_player()[0]
if player and player.join_time and !player.arena_quit_free
waited_time = moment() - player.join_time
......@@ -3591,33 +3563,22 @@ if settings.modules.mycard.enabled
player.arena_quit_free = true
else if waited_time >= 5000 and waited_time < 6000
ygopro.stoc_send_chat(player, "${arena_wait_hint}", ygopro.constants.COLORS.BABYBLUE)
done()
return
)
return
, 1000
if settings.modules.heartbeat_detection.enabled
setInterval ()->
_async.each ROOM_all, (room, done)->
if room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and (room.hostinfo.time_limit == 0 or room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING) and !room.windbot
_async.each(room.get_playing_player(), (player, _done)->
if player and (room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING or player.selected_preduel)
CLIENT_heartbeat_register(player, true)
_done()
, done)
else
done()
for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and (room.hostinfo.time_limit == 0 or room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING) and !room.windbot
for player in room.get_playing_player() when player and (room.duel_stage != ygopro.constants.DUEL_STAGE.SIDING or player.selected_preduel)
CLIENT_heartbeat_register(player, true)
return
, settings.modules.heartbeat_detection.interval
setInterval ()->
current_time = moment()
_async.each ROOM_all, (room, done)->
if room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.hostinfo.auto_death and !room.auto_death_triggered and current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death
room.auto_death_triggered = true
room.start_death()
done()
for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and room.hostinfo.auto_death and !room.auto_death_triggered and current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death
room.auto_death_triggered = true
room.start_death()
, 1000
......
// Generated by CoffeeScript 2.5.1
(function() {
// 标准库
var AthleticChecker, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, Cloud_replay_ids, DataManager, Q, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_banned, ROOM_players_oppentlist, ROOM_players_scores, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, athleticChecker, auth, axios, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, challonge_type, chat_color, config, cppversion, crypto, dataManager, date, deck_name_match, default_config, default_data, dialogues, disconnect_list, dns, duel_log, e, exec, execFile, fs, geoip, getSeedTimet, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_challonge_requesting, j, l, len, len1, len2, len3, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, m, memory_usage, merge, moment, n, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, qs, real_windbot_server_ip, ref, ref1, ref2, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, util, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, ygopro, zlib;
var AthleticChecker, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, DataManager, Q, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_oppentlist, ROOM_players_scores, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, _, _async, addCallback, athleticChecker, auth, axios, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, challonge_type, chat_color, config, cppversion, crypto, dataManager, date, deck_name_match, default_config, default_data, dialogues, disconnect_list, dns, duel_log, e, exec, execFile, fs, geoip, getSeedTimet, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_challonge_requesting, j, l, len, len1, len2, len3, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, m, memory_usage, merge, moment, n, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, qs, real_windbot_server_ip, ref, ref1, ref2, refresh_challonge_cache, release_disconnect, replaced_index, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, util, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, ygopro, zlib;
net = require('net');
......@@ -624,14 +624,10 @@
setInterval(get_memory_usage, 3000);
Cloud_replay_ids = global.Cloud_replay_ids = [];
ROOM_all = global.ROOM_all = [];
ROOM_players_oppentlist = global.ROOM_players_oppentlist = {};
ROOM_players_banned = global.ROOM_players_banned = [];
ROOM_players_scores = global.ROOM_players_scores = {};
ROOM_connected_ip = global.ROOM_connected_ip = {};
......@@ -675,37 +671,13 @@
};
// automatically ban user to use random duel
ROOM_ban_player = global.ROOM_ban_player = function(name, ip, reason, countadd = 1) {
var bannedplayer, bantime;
if (settings.modules.test_mode.no_ban_player) {
ROOM_ban_player = global.ROOM_ban_player = async function(name, ip, reason, countadd = 1) {
if (settings.modules.test_mode.no_ban_player || !settings.modules.mysql.enabled) {
return;
}
bannedplayer = _.find(ROOM_players_banned, function(bannedplayer) {
return ip === bannedplayer.ip;
});
if (bannedplayer) {
bannedplayer.count = bannedplayer.count + countadd;
bantime = bannedplayer.count > 3 ? Math.pow(2, bannedplayer.count - 3) * 2 : 0;
bannedplayer.time = moment() < bannedplayer.time ? moment(bannedplayer.time).add(bantime, 'm') : moment().add(bantime, 'm');
if (!_.find(bannedplayer.reasons, function(bannedreason) {
return bannedreason === reason;
})) {
bannedplayer.reasons.push(reason);
}
bannedplayer.need_tip = true;
} else {
bannedplayer = {
"ip": ip,
"time": moment(),
"count": countadd,
"reasons": [reason],
"need_tip": true
};
ROOM_players_banned.push(bannedplayer);
}
await dataManager.randomDuelBanPlayer(ip, reason, countadd);
};
//log.info("banned", name, ip, reason, bannedplayer.count)
ROOM_kick = function(name, callback) {
var found;
found = false;
......@@ -812,14 +784,14 @@
}, 60000);
}
ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = function(name, player_ip) {
ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = async function(name, player_ip) {
var room, uname;
uname = name.toUpperCase();
if (settings.modules.windbot.enabled && (uname.slice(0, 2) === 'AI' || (!settings.modules.random_duel.enabled && uname === ''))) {
return ROOM_find_or_create_ai(name);
}
if (settings.modules.random_duel.enabled && (uname === '' || uname === 'S' || uname === 'M' || uname === 'T')) {
return 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)) {
return room;
......@@ -830,33 +802,36 @@
}
};
ROOM_find_or_create_random = global.ROOM_find_or_create_random = function(type, player_ip) {
var bannedplayer, max_player, name, playerbanned, result;
bannedplayer = _.find(ROOM_players_banned, function(bannedplayer) {
return player_ip === bannedplayer.ip;
});
if (bannedplayer) {
if (bannedplayer.count > 6 && moment() < bannedplayer.time) {
return {
"error": `\${random_banned_part1}${bannedplayer.reasons.join('${random_ban_reason_separator}')}\${random_banned_part2}${moment(bannedplayer.time).fromNow(true)}\${random_banned_part3}`
};
}
if (bannedplayer.count > 3 && moment() < bannedplayer.time && bannedplayer.need_tip && type !== 'T') {
bannedplayer.need_tip = false;
return {
"error": `\${random_deprecated_part1}${bannedplayer.reasons.join('${random_ban_reason_separator}')}\${random_deprecated_part2}${moment(bannedplayer.time).fromNow(true)}\${random_deprecated_part3}`
};
} else if (bannedplayer.need_tip) {
bannedplayer.need_tip = false;
return {
"error": `\${random_warn_part1}${bannedplayer.reasons.join('${random_ban_reason_separator}')}\${random_warn_part2}`
};
} else if (bannedplayer.count > 2) {
bannedplayer.need_tip = true;
ROOM_find_or_create_random = global.ROOM_find_or_create_random = async function(type, player_ip) {
var max_player, name, playerbanned, randomDuelBanRecord, result;
if (settings.modules.mysql.enabled) {
randomDuelBanRecord = (await dataManager.getRandomDuelBan(player_ip));
if (randomDuelBanRecord) {
if (randomDuelBanRecord.count > 6 && moment().isBefore(randomDuelBanRecord.time)) {
return {
"error": `\${random_banned_part1}${randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}\${random_banned_part2}${moment(randomDuelBanRecord.time).fromNow(true)}\${random_banned_part3}`
};
}
if (randomDuelBanRecord.count > 3 && moment().isBefore(randomDuelBanRecord.time) && randomDuelBanRecord.getNeedTip() && type !== 'T') {
randomDuelBanRecord.setNeedTip(false);
await dataManager.updateRandomDuelBan(randomDuelBanRecord);
return {
"error": `\${random_deprecated_part1}${randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}\${random_deprecated_part2}${moment(randomDuelBanRecord.time).fromNow(true)}\${random_deprecated_part3}`
};
} else if (randomDuelBanRecord.getNeedTip()) {
randomDuelBanRecord.setNeedTip(false);
await dataManager.updateRandomDuelBan(randomDuelBanRecord);
return {
"error": `\${random_warn_part1}${randomDuelBanRecord.reasons.join('${random_ban_reason_separator}')}\${random_warn_part2}`
};
} else if (randomDuelBanRecord.count > 2) {
randomDuelBanRecord.setNeedTip(true);
await dataManager.updateRandomDuelBan(randomDuelBanRecord);
}
}
}
max_player = type === 'T' ? 4 : 2;
playerbanned = bannedplayer && bannedplayer.count > 3 && moment() < bannedplayer.time;
playerbanned = randomDuelBanRecord && randomDuelBanRecord.count > 3 && moment() < randomDuelBanRecord.time;
result = _.find(ROOM_all, function(room) {
return room && room.random_type !== '' && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && !room.windbot && ((type === '' && (room.random_type === settings.modules.random_duel.default_type || settings.modules.random_duel.blank_pass_modes[room.random_type])) || room.random_type === type) && room.get_playing_player().length < max_player && (settings.modules.random_duel.no_rematch_check || room.get_host() === null || room.get_host().ip !== ROOM_players_oppentlist[player_ip]) && (playerbanned === room.deprecated || type === 'T');
});
......@@ -2605,7 +2580,7 @@
}
return (checksum & 0xFF) === 0;
};
create_room_with_action = function(buffer, decrypted_buffer, match_permit) {
create_room_with_action = async function(buffer, decrypted_buffer, match_permit) {
var action, len4, len5, name, o, opt1, opt2, opt3, options, p, player, ref3, ref4, room, room_title, title;
if (client.closed) {
return;
......@@ -2693,7 +2668,7 @@
ygopro.stoc_die(client, '${invalid_password_unauthorized}');
return;
}
room = ROOM_find_or_create_by_name('M#' + info.pass.slice(8));
room = (await ROOM_find_or_create_by_name('M#' + info.pass.slice(8)));
if (room) {
ref3 = room.get_playing_player();
for (o = 0, len4 = ref3.length; o < len4; o++) {
......@@ -2895,7 +2870,7 @@
no_cache: !!recover_match
});
}
}, function(err, datas) {
}, async function(err, datas) {
var create_room_name, found, k, len5, len6, match, p, player, q, ref4, ref5, ref6, ref7, user;
if (client.closed) {
return;
......@@ -2939,7 +2914,7 @@
if (recover_match) {
create_room_name = recover_match[0] + ',' + create_room_name;
}
room = ROOM_find_or_create_by_name(create_room_name);
room = (await ROOM_find_or_create_by_name(create_room_name));
if (room) {
room.challonge_info = found;
// room.max_player = 2
......@@ -3032,7 +3007,7 @@
buffer = struct.buffer;
}
//log.info 'join_game',info.pass, client.name
room = ROOM_find_or_create_by_name(info.pass, client.ip);
room = (await ROOM_find_or_create_by_name(info.pass, client.ip));
if (!room) {
ygopro.stoc_die(client, "${server_full}");
} else if (room.error) {
......@@ -3624,7 +3599,7 @@
client.kick_count = client.kick_count ? client.kick_count + 1 : 1;
if (client.kick_count >= 5 && room.random_type) {
ygopro.stoc_send_chat_to_room(room, `${client.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}");
await ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}");
CLIENT_kick(client);
return true;
}
......@@ -3801,7 +3776,7 @@
for (n = 0, len3 = ref3.length; n < len3; n++) {
player = ref3[n];
if (player && player.is_host) {
ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}");
await ROOM_ban_player(player.name, player.ip, "${random_ban_reason_zombie}");
ygopro.stoc_send_chat_to_room(room, `${player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
CLIENT_kick(player);
}
......@@ -4185,8 +4160,8 @@
cancel = true;
if (client.abuse_count > 0) {
ygopro.stoc_send_chat(client, "${banned_duel_tip}", ygopro.constants.COLORS.RED);
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}");
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}", 3);
await ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}");
await ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}", 3);
CLIENT_send_replays(client, room);
CLIENT_kick(client);
return true;
......@@ -4247,7 +4222,7 @@
}
if (client.abuse_count >= 5) {
ygopro.stoc_send_chat_to_room(room, `${client.name} \${chat_banned}`, ygopro.constants.COLORS.RED);
ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}");
await ROOM_ban_player(client.name, client.ip, "${random_ban_reason_abuse}");
}
if (!cancel && settings.modules.display_watchers && client.is_post_watcher) {
ygopro.stoc_send_chat_to_room(room, `${client.name}: ${msg}`, 9);
......@@ -4690,9 +4665,6 @@
if (!room) {
return settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.block_replay_to_player || settings.modules.replay_delay;
}
if (settings.modules.cloud_replay.enabled && room.random_type) {
Cloud_replay_ids.push(room.cloud_replay_id);
}
if (!room.replays[room.duel_count - 1]) {
// console.log("Replay saved: ", room.duel_count - 1, client.pos)
room.replays[room.duel_count - 1] = buffer;
......@@ -4763,18 +4735,18 @@
});
if (settings.modules.random_duel.enabled) {
setInterval(function() {
_async.each(ROOM_all, function(room, done) {
var time_passed;
setInterval(async function() {
var len3, n, room, time_passed;
for (n = 0, len3 = ROOM_all.length; n < len3; n++) {
room = ROOM_all[n];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.random_type && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
done();
return;
continue;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
//log.info time_passed
if (time_passed >= settings.modules.random_duel.hang_timeout) {
room.last_active_time = moment();
ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}");
await ROOM_ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "${random_ban_reason_AFK}");
room.scores[room.waiting_for_player.name_vpass] = -9;
//log.info room.waiting_for_player.name, room.scores[room.waiting_for_player.name_vpass]
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${kicked_by_system}`, ygopro.constants.COLORS.RED);
......@@ -4784,18 +4756,17 @@
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${afk_warn_part1}${settings.modules.random_duel.hang_timeout - time_passed}\${afk_warn_part2}`, ygopro.constants.COLORS.RED);
ROOM_unwelcome(room, room.waiting_for_player, "${random_ban_reason_AFK}");
}
done();
});
}
}, 1000);
}
if (settings.modules.mycard.enabled) {
setInterval(function() {
_async.each(ROOM_all, function(room, done) {
var time_passed;
var len3, len4, n, o, player, room, time_passed, waited_time;
for (n = 0, len3 = ROOM_all.length; n < len3; n++) {
room = ROOM_all[n];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.arena && room.last_active_time && room.waiting_for_player && room.get_disconnected_count() === 0 && (!settings.modules.side_timeout || room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING) && !room.recovered)) {
done();
return;
continue;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
//log.info time_passed
......@@ -4809,14 +4780,13 @@
} else if (time_passed >= (settings.modules.random_duel.hang_timeout - 20) && !(time_passed % 10)) {
ygopro.stoc_send_chat_to_room(room, `${room.waiting_for_player.name} \${afk_warn_part1}${settings.modules.random_duel.hang_timeout - time_passed}\${afk_warn_part2}`, ygopro.constants.COLORS.RED);
}
done();
});
}
return;
if (true) { // settings.modules.arena_mode.punish_quit_before_match
_async.each(ROOM_all, function(room, done) {
var player, waited_time;
for (o = 0, len4 = ROOM_all.length; o < len4; o++) {
room = ROOM_all[o];
if (!(room && room.arena && room.duel_stage === ygopro.constants.DUEL_STAGE.BEGIN && room.get_playing_player().length < 2)) {
done();
return;
continue;
}
player = room.get_playing_player()[0];
if (player && player.join_time && !player.arena_quit_free) {
......@@ -4828,39 +4798,42 @@
ygopro.stoc_send_chat(player, "${arena_wait_hint}", ygopro.constants.COLORS.BABYBLUE);
}
}
done();
});
}
}
}, 1000);
}
if (settings.modules.heartbeat_detection.enabled) {
setInterval(function() {
_async.each(ROOM_all, function(room, done) {
var len3, len4, n, o, player, ref3, room;
for (n = 0, len3 = ROOM_all.length; n < len3; n++) {
room = ROOM_all[n];
if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && (room.hostinfo.time_limit === 0 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING) && !room.windbot) {
return _async.each(room.get_playing_player(), function(player, _done) {
ref3 = room.get_playing_player();
for (o = 0, len4 = ref3.length; o < len4; o++) {
player = ref3[o];
if (player && (room.duel_stage !== ygopro.constants.DUEL_STAGE.SIDING || player.selected_preduel)) {
CLIENT_heartbeat_register(player, true);
}
return _done();
}, done);
} else {
return done();
}
}
});
}
}, settings.modules.heartbeat_detection.interval);
}
setInterval(function() {
var current_time;
var current_time, len3, n, results, room;
current_time = moment();
return _async.each(ROOM_all, function(room, done) {
if (room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.auto_death && !room.auto_death_triggered && current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death) {
room.auto_death_triggered = true;
room.start_death();
results = [];
for (n = 0, len3 = ROOM_all.length; n < len3; n++) {
room = ROOM_all[n];
if (!(room && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && room.hostinfo.auto_death && !room.auto_death_triggered && current_time - moment(room.start_time) > 60000 * room.hostinfo.auto_death)) {
continue;
}
return done();
});
room.auto_death_triggered = true;
results.push(room.start_death());
}
return results;
}, 1000);
// spawn windbot
......
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