Removed old IRC implementation

User accounts are now only for streamers, update CLI, API, and config to reflect that.
Fixed a bug with registration in api.ts
Made http port configurable
Added beginnings of socket.io chat server

Possibly more, I took a break in the middle of this commit.
This commit is contained in:
knotteye
2019-10-17 16:01:35 -05:00
parent fad832fe38
commit 1afe462c0b
11 changed files with 354 additions and 108 deletions

View File

@ -13,7 +13,10 @@ async function register(name: string, password: string, confirm: string) {
if (name === config.restrictedNames[i]) return {"error":"restricted name"};
}
let r: boolean = await db.addUser(name, password);
if(r) return {"success":""};
if(r) {
let k = await db.query('select stream_key from users where username='+db.raw.escape(name));
return k;
}
return {"error":""};
}

View File

@ -1,35 +0,0 @@
import * as irc from "irc";
function chanReg(channel: string, owner: string){
let bot = new irc.Client('127.0.0.1', 'ChanReg', {
channels: [''],
userName: 'ChanReg',
realName: 'Channel Registration Bot',
floodProtection: false,
});
bot.once('registered', (message) => {
bot.send('OPER', 'admin', 'test');
bot.join(channel);
bot.send('MODE', channel, '+P');
bot.send('MODE', channel, '+w', 'o:'+owner+'!*@*');
bot.disconnect();
});
}
function chanUnReg(channel: string){
let bot = new irc.Client('127.0.0.1', 'ChanReg', {
channels: [''],
userName: 'ChanReg',
realName: 'Channel Registration Bot',
floodProtection: false,
debug: true
});
bot.once('registered', (message) => {
bot.send('OPER', 'admin', 'test');
bot.join(channel);
bot.send('MODE', channel, '-P');
bot.disconnect();
});
}
export {chanReg, chanUnReg};

View File

@ -4,24 +4,22 @@ import * as config from "config"
db.init(config.database, config.bcrypt);
flags.defineString('add', '', 'User to add');
flags.defineString('remove', '', 'User to remove');
flags.defineString('adduser', '', 'User to add');
flags.defineString('rmuser', '', 'User to remove');
flags.defineString('password', '', 'password to hash');
flags.defineBoolean('admin');
flags.defineBoolean('streamer');
flags.parse();
if(flags.get('add') !== ''){
db.addUser(flags.get('add'), flags.get('password')).then((result) => {
if(flags.get('adduser') !== ''){
db.addUser(flags.get('adduser'), flags.get('password')).then((result) => {
if(result) console.log("User added successfully.");
else console.log("Could not add user. Is the password field empty?");
process.exit();
});
}
if(flags.get('remove') !== ''){
db.rmUser(flags.get('remove')).then((result) => {
if(flags.get('rmuser') !== ''){
db.rmUser(flags.get('rmuser')).then((result) => {
if(result) console.log("User removed successfully.");
else console.log("Could not remove user.");
process.exit();

View File

@ -1,5 +1,4 @@
import * as mediaserver from "./server";
import * as ircd from "./ircd";
import * as db from "./database";
import * as api from "./api";
import * as http from "./http";
@ -30,7 +29,7 @@ function run(): void{
ping_timeout: config.server.rtmp.ping_timeout,
},
http: {
port: config.server.http.port,
port: config.server.http.port + 1,
mediaroot: config.server.http.directory,
allow_origin: config.server.http.allow_origin
},
@ -54,10 +53,9 @@ function run(): void{
};
api.init(satyr);
http.init(satyr);
http.init(satyr, config.server.http.port);
db.init(dbcfg, bcryptcfg);
mediaserver.init(nms, satyr);
ircd.init();
}
run();
export { run };

View File

@ -17,7 +17,7 @@ async function addUser(name: string, password: string){
let hash: string = await bcrypt.hash(password, cryptoconfig.saltRounds);
let dupe = await query('select * from users where username='+raw.escape(name));
if(dupe[0]) return false;
await query('INSERT INTO users (username, password_hash, stream_key, record_flag) VALUES ('+raw.escape(name)+', '+raw.escape(hash)+', '+raw.escape(key)+', 0');
await query('INSERT INTO users (username, password_hash, stream_key, record_flag) VALUES ('+raw.escape(name)+', '+raw.escape(hash)+', '+raw.escape(key)+', 0)');
await query('INSERT INTO user_meta (username, title, about, live) VALUES ('+raw.escape(name)+',\'\',\'\',false)');
return true;
}

View File

@ -2,14 +2,17 @@ import * as express from "express";
import * as njk from "nunjucks";
import * as bodyparser from "body-parser";
import * as fs from "fs";
import * as socketio from "socket.io";
import * as http from "http";
import * as api from "./api";
import * as db from "./database";
var app = express();
const app = express();
const server = http.createServer(app);
const io = socketio(server);
var njkconf;
function init(satyr: any){
app.listen(8000);
function init(satyr: any, port: number){
njk.configure('templates', {
autoescape: true,
express : app,
@ -107,6 +110,11 @@ function init(satyr: any){
app.use(function (req, res, next) {
res.status(404).render('404.njk', njkconf);
});
//socket.io chat logic
io.on('connection', (socket) => {
});
server.listen(port);
}
export { init };

View File

@ -1,20 +0,0 @@
import * as child from "child_process";
var ircd: child.ChildProcess;
function init():void{
ircd = child.execFile("./lib/inspircd-3.3.0/run/inspircd", ["restart"], (error, stdout, stderr) => {
if (error){
console.log("[IRCD] Failed to start Inspircd");
console.log(stdout);
throw error;
}
else {
console.log("[IRCD] Started Inspircd");
}
});
}
function reloadSSL():void{
ircd.kill("SIGUSR1");
}
export { init, reloadSSL };