How to receive log from SRCDS in node.js

Posted on

How to receive log from SRCDS in node.js

I have srcds (source dedicated server)

at console add logaddress_add 0.0.0.0:25001

this turn on sending the log to the remote server

tried to catch the log in this way

var net = require('net');
var server = net.createServer(function(c) { 
    c.on('end', function() {
        console.log('server disconnected');
    });
    c.pipe(c);
});
server.listen(25001);

and that

var net = require('net');
var client = net.connect({port: 25001});

client.on('data', function(data) {
    console.log(data.toString());
    client.end();
});
client.on('end', function() {
    console.log('client disconnected');
});

and that

var s = dgram.createSocket('udp4');
s.bind(25001, function(data) {
    console.log(data)
});

no result. can someone help?

thanks in advance

Solution :

[solved]

at SRCDS server

logaddress_add 0.0.0.0:8006 //for local ip

at app.js

var dgram = require('dgram'),
    server = dgram.createSocket('udp4');

server.on('message', function (message, rinfo) {
var msg = message.toString('ascii').slice(5,-1);    
console.log(msg);
    });
server.on('listening', function () {
    var address = server.address();
    console.log('UDP Server listening ' + address.address + ':' + address.port);
});

server.bind(8006);  

I ended up writing a little library to do this (srcds-log-receiver), which validates the packet format, extracts out the date and allows you to use the sv_logsecret function to put a small amount of authentication on the connection, since UDP packets are easily forged.

I also wrote a parser to turn those log lines in to useful objects.

Leave a Reply

Your email address will not be published. Required fields are marked *