-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a463987
commit c25a04c
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ node-advertiser | |
=============== | ||
|
||
Node.js implementation of minecraft advertiser | ||
|
||
To run simply type node advert.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
}); | ||
}; | ||
} |