mirror of https://github.com/calzoneman/sync.git
Add config option for mysql pool size, optimize restart login flood case
This commit is contained in:
parent
3020060627
commit
5487d15bdf
|
@ -9,6 +9,7 @@ mysql:
|
|||
database: 'cytube3'
|
||||
user: 'cytube3'
|
||||
password: ''
|
||||
pool-size: 10
|
||||
|
||||
# Define IPs/ports to listen on
|
||||
# Each entry MUST define ip and port (ip can be '' to bind all available addresses)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.28.2",
|
||||
"version": "3.29.0",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -44,25 +44,28 @@ function checkNameBan(cname, name, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function checkBan(cname, ip, name, cb) {
|
||||
db.channels.isBanned(cname, ip, name, function (err, banned) {
|
||||
if (err) {
|
||||
cb(false);
|
||||
} else {
|
||||
cb(banned);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
KickBanModule.prototype.onUserPreJoin = function (user, data, cb) {
|
||||
if (!this.channel.is(Flags.C_REGISTERED)) {
|
||||
return cb(null, ChannelModule.PASSTHROUGH);
|
||||
}
|
||||
|
||||
var cname = this.channel.name;
|
||||
checkIPBan(cname, user.realip, function (banned) {
|
||||
checkBan(cname, user.realip, user.getName(), function (banned) {
|
||||
if (banned) {
|
||||
cb(null, ChannelModule.DENY);
|
||||
user.kick("Your IP address is banned from this channel.");
|
||||
user.kick("You are banned from this channel.");
|
||||
} else {
|
||||
checkNameBan(cname, user.getName(), function (banned) {
|
||||
if (banned) {
|
||||
cb(null, ChannelModule.DENY);
|
||||
user.kick("Your username is banned from this channel.");
|
||||
} else {
|
||||
cb(null, ChannelModule.PASSTHROUGH);
|
||||
}
|
||||
});
|
||||
cb(null, ChannelModule.PASSTHROUGH);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ var defaults = {
|
|||
database: "cytube3",
|
||||
user: "cytube3",
|
||||
password: "",
|
||||
"pool-size": 10
|
||||
},
|
||||
listen: [
|
||||
{
|
||||
|
|
|
@ -19,7 +19,8 @@ module.exports.init = function () {
|
|||
password: Config.get("mysql.password"),
|
||||
database: Config.get("mysql.database"),
|
||||
multipleStatements: true,
|
||||
charset: "UTF8MB4_GENERAL_CI" // Needed for emoji and other non-BMP unicode
|
||||
charset: "UTF8MB4_GENERAL_CI", // Needed for emoji and other non-BMP unicode
|
||||
connectionLimit: Config.get("mysql.pool-size")
|
||||
});
|
||||
|
||||
// Test the connection
|
||||
|
@ -40,6 +41,10 @@ module.exports.init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
pool.on("enqueue", function () {
|
||||
Metrics.incCounter("db:queryQueued", 1);
|
||||
});
|
||||
|
||||
global_ipbans = {};
|
||||
module.exports.users = require("./database/accounts");
|
||||
module.exports.channels = require("./database/channels");
|
||||
|
@ -66,6 +71,7 @@ module.exports.query = function (query, sub, callback) {
|
|||
callback("Database failure", null);
|
||||
} else {
|
||||
function cback(err, res) {
|
||||
conn.release();
|
||||
if (err) {
|
||||
Logger.errlog.log("! DB query failed: " + query);
|
||||
if (sub) {
|
||||
|
@ -76,7 +82,6 @@ module.exports.query = function (query, sub, callback) {
|
|||
} else {
|
||||
callback(null, res);
|
||||
}
|
||||
conn.release();
|
||||
Metrics.stopTimer(timer);
|
||||
}
|
||||
|
||||
|
@ -84,10 +89,16 @@ module.exports.query = function (query, sub, callback) {
|
|||
console.log(query);
|
||||
}
|
||||
|
||||
if (sub) {
|
||||
conn.query(query, sub, cback);
|
||||
} else {
|
||||
conn.query(query, cback);
|
||||
try {
|
||||
if (sub) {
|
||||
conn.query(query, sub, cback);
|
||||
} else {
|
||||
conn.query(query, cback);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.errlog.log("Broken query: " + error.stack);
|
||||
callback("Broken query", null);
|
||||
conn.release();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -571,6 +571,29 @@ module.exports = {
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a user's name or IP is banned
|
||||
*/
|
||||
isBanned: function (chan, ip, name, callback) {
|
||||
if (typeof callback !== "function") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!valid(chan)) {
|
||||
callback("Invalid channel name", null);
|
||||
return;
|
||||
}
|
||||
|
||||
var range = util.getIPRange(ip);
|
||||
var wrange = util.getWideIPRange(ip);
|
||||
|
||||
db.query("SELECT COUNT(1) AS count FROM `channel_bans` WHERE (ip IN (?, ?, ?) OR name=?) AND channel=?",
|
||||
[ip, range, wrange, name, chan],
|
||||
function (err, rows) {
|
||||
callback(err, err ? false : rows.length > 0 && rows[0].count > 0);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Lists all bans
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue