Skip to content

Commit

Permalink
add the advertiser
Browse files Browse the repository at this point in the history
  • Loading branch information
flareofghast committed Nov 22, 2014
1 parent a463987 commit c25a04c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node-advertiser
===============

Node.js implementation of minecraft advertiser

To run simply type node advert.js
35 changes: 35 additions & 0 deletions advert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* based on the work from kebian
* http://void7.net/advertising-linux-minecraft-servers-to-the-lan/
* author: FlareOfGhast
*/

var dgram = require('dgram');
var socket = dgram.createSocket("udp4");
var broadcastIP = "255.255.255.255"
var broadcastPort = 4445

// add your servers like the example separated by commas eg. [MOTD,PORT],[MOTD,PORT]
// there is no tailing comma
var servers = [
["A MOTD here", 25565]
];

// allow broadcast
socket.bind( function(){
socket.setBroadcast(true);
});

// simple output
console.log("Broadcasting Minecraft servers to LAN")

//run broadcast method every 1500 ms
setInterval(broadcast,1500);

function broadcast() {
for (var i in servers){
var msg = new Buffer("[MOTD]" + servers[i][0] + "[/MOTD][AD]" + servers[i][1] + "[/AD]");
socket.send(msg, 0, msg.length, broadcastPort, broadcastIP, function(err, bytes) {
});
};
}

0 comments on commit c25a04c

Please sign in to comment.