Add internal banning (cvmban) using MySQL
This commit is contained in:
@@ -6,23 +6,31 @@ import TCPClient from './TCPClient.js';
|
||||
import { IPDataManager } from '../IPData.js';
|
||||
import { User } from '../User.js';
|
||||
import pino from 'pino';
|
||||
import { BanManager } from '../BanManager.js';
|
||||
|
||||
export default class TCPServer extends EventEmitter implements NetworkServer {
|
||||
listener: Server;
|
||||
Config: IConfig;
|
||||
logger = pino({name: 'CVMTS.TCPServer'});
|
||||
clients: TCPClient[];
|
||||
private banmgr: BanManager;
|
||||
|
||||
constructor(config: IConfig) {
|
||||
constructor(config: IConfig, banmgr: BanManager) {
|
||||
super();
|
||||
this.Config = config;
|
||||
this.listener = new Server();
|
||||
this.clients = [];
|
||||
this.listener.on('connection', (socket) => this.onConnection(socket));
|
||||
this.banmgr = banmgr;
|
||||
}
|
||||
|
||||
private onConnection(socket: Socket) {
|
||||
private async onConnection(socket: Socket) {
|
||||
this.logger.info(`New TCP connection from ${socket.remoteAddress}`);
|
||||
if (await this.banmgr.isIPBanned(socket.remoteAddress!)) {
|
||||
socket.write("6.banned;");
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
var client = new TCPClient(socket);
|
||||
this.clients.push(client);
|
||||
this.emit('connect', new User(client, IPDataManager.GetIPData(client.getIP()), this.Config));
|
||||
|
||||
Reference in New Issue
Block a user