var cfg = require('./config.js');
const express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.use('/dist', express.static(__dirname + '/dist'));
// routes
app.all('/*', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
server.listen(cfg.httpPort, () => console.log('[Website] Http server started!'));
//rcon
require('./rcon.js');
// feedback online
var feedback = io.of('/fb');
const cluster = require('cluster');
const Rcon = require('rcon');
if(cluster.isMaster) {
cluster.setupMaster({
exec: 'rcon.js'
});
cluster.fork();
cluster.on('exit', () => {
setTimeout(() => cluster.fork(), 10*1000);
});
} else {
const rconCon = new Rcon('localhost', 25575, '12341');
rconCon.on('auth', function() {
console.log('[Website(rcon)] Rcon connection created');
})
.on('response', function(data) {})
.on('end', function() {
console.log('[Website(rcon)] Socket closed!');
});
rconCon.connect();
}
-m reserved-blocks-percentage
Specify the percentage of the filesystem blocks reserved for the super-user. This
avoids fragmentation, and allows root-owned daemons, such as syslogd(8), to con‐
tinue to function correctly after non-privileged processes are prevented from writ‐
ing to the filesystem. The default percentage is 5%.
const net = require('net');
const HOST = '192.168.0.75';
const PORT = '30001';
class Api {
constructor(host, port) {
this.HOST = host || HOST;
this.PORT = port || PORT;
this.socket = new net.Socket();
this.socket.connect(this.PORT, this.HOST, () => {
console.log(`Client connected to: ${this.HOST}:${this.PORT}`);
});
this.socket.on('close', () => {
console.log('FiscalAPI: connection closed');
});
}
clearListeners(data, error) {
this.socket.off('data', data);
this.socket.off('error', error);
}
sendCommand(cmd) {
if(cmd) {
this.socket.write(cmd + '\u0000\r\n');
return new Promise((resolve, reject) => {
const chunks = [];
const handleData = chunk => {
chunks.push(chunk);
const data = Buffer.concat(chunks).toString().match(/.*?\r\n/g);
if (data.length > 1) {
resolve(data);
this.clearListeners(handleData, handleError);
}
};
const handleError = err => {
reject(err);
this.clearListeners(handleData, handleError);
};
this.socket.on('data', handleData);
this.socket.on('error', handleError);
});
}
}
checkPumpState(dispenser_index){
this.sendCommand('0;open')
.then(([echo, data]) => {
console.log(`echo: ${echo}data: ${data}`);
return this.sendCommand(`0;dispenser_get;${dispenser_index};1`);
})
.then(([echo, data]) => {
console.log(`echo: ${echo}data: ${data}`);
return this.sendCommand(`0;store_get;0;16`);
})
.then(([echo, data]) => {
console.log(`echo: ${echo}data: ${data}`);
})
.catch((error) => console.log(error));
}
}