2017-06-27 20:23:09 +01:00
|
|
|
const net = require('net');
|
|
|
|
const RpcMessage = require('./rpc-message');
|
|
|
|
|
|
|
|
console.log('Start up');
|
|
|
|
|
|
|
|
let PipePrefix;
|
2017-06-27 21:19:36 +01:00
|
|
|
let PipePostfix;
|
2017-06-27 20:23:09 +01:00
|
|
|
if (process.platform == 'win32') {
|
2017-06-27 21:19:36 +01:00
|
|
|
PipePrefix = '\\\\.\\pipe\\';
|
|
|
|
PipePostfix = '';
|
2017-06-27 20:23:09 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PipePrefix = "/tmp";
|
2017-06-27 21:19:36 +01:00
|
|
|
PipePostfix = '.pipe';
|
2017-06-27 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
2017-06-27 21:19:36 +01:00
|
|
|
const PipePath = PipePrefix + "DiscordRpcServer" + PipePostfix;
|
2017-06-27 20:23:09 +01:00
|
|
|
|
|
|
|
var server = net.createServer(function(stream) {
|
2017-06-27 21:19:36 +01:00
|
|
|
console.log('Server: on connection');
|
2017-06-27 20:23:09 +01:00
|
|
|
|
|
|
|
stream.on('data', function(data) {
|
|
|
|
const msgObj = RpcMessage.deserialize(data);
|
|
|
|
if (msgObj != null) {
|
|
|
|
console.log('Server: on data:', msgObj);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('Server: got some data');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
stream.on('end', function() {
|
|
|
|
console.log('Server: on end')
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
server.on('close', function(){
|
|
|
|
console.log('Server: on close');
|
|
|
|
})
|
|
|
|
|
|
|
|
try {
|
|
|
|
server.listen(PipePath, function(){
|
|
|
|
console.log('Server: on listening');
|
|
|
|
});
|
|
|
|
} catch(e) {
|
|
|
|
console.error('could not start server:', e);
|
|
|
|
}
|