Implement Discord CnC Server into Emmelia
This commit is contained in:
54
libUtils.js
54
libUtils.js
@@ -1,7 +1,59 @@
|
||||
const { DebugBuilder } = require("./utilities/debugBuilder");
|
||||
const log = new DebugBuilder("server", "libUtils");
|
||||
|
||||
/**
|
||||
* sleep - sleep/wait
|
||||
* @constructor
|
||||
*/
|
||||
exports.sleep = (ms) => new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Normalize a port into a number, string, or false.
|
||||
*
|
||||
* @param {*} val Value to be normalized
|
||||
* @returns Normalized value
|
||||
*/
|
||||
exports.normalizePort = (val) => {
|
||||
var port = parseInt(val, 10);
|
||||
|
||||
if (isNaN(port)) {
|
||||
// named pipe
|
||||
return val;
|
||||
}
|
||||
|
||||
if (port >= 0) {
|
||||
// port number
|
||||
return port;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
exports.onError = (error) => {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
var bind = typeof port === 'string'
|
||||
? 'Pipe ' + port
|
||||
: 'Port ' + port;
|
||||
|
||||
// handle specific listen errors with friendly messages
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
log.ERROR(bind + ' requires elevated privileges');
|
||||
process.exit(1);
|
||||
break;
|
||||
case 'EADDRINUSE':
|
||||
log.ERROR(bind + ' is already in use');
|
||||
process.exit(1);
|
||||
break;
|
||||
default:
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user