Skip to content

Instantly share code, notes, and snippets.

@rom1504
Last active September 21, 2015 14:09
Show Gist options
  • Save rom1504/9770088454486dede1b8 to your computer and use it in GitHub Desktop.
Save rom1504/9770088454486dede1b8 to your computer and use it in GitHub Desktop.
var fs = require('fs');
function parsePackets(path)
{
var files = fs.readdirSync(path);
return files
.filter(function(name) {return !(name == "DataPacket.php" || name == "Info.php");})
.map(function(name){
var file = (fs.readFileSync(path + name, 'utf8'));
var packetName;
var fields=[];
var lines = file.split("\n");
lines.forEach(function(line) {
var results;
if(results=line.match("const NETWORK_ID = Info::(.+);"))
packetName=results[1];
else if(results=line.match("\\$this->put(.+?)\\(\\$this->(.+?)\\);"))
fields.push({
name:results[1],
type:results[2]
});
});
return {
packetName:packetName,
fields:fields
}
});
}
function writePackets(packets)
{
fs.writeFile("packets.json", JSON.stringify(packets, null, 2));
}
writePackets(parsePackets("./pocketmine/src/pocketmine/network/protocol"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment