Node.js G-Earth extension API
Requires Node.js V15.0.0+
Docs: https://wiredspast.github.io/G-Node/modules.html
Using npm:
$ npm install gnode-api
Using yarn:
$ yarn add gnode-api
$ node [filename] -p [port]
$ node extension.js -p 9092
import { Extension, HPacket, HDirection } from 'gnode-api';
// Use package.json as extensionInfo or create an object including 'name', 'description', 'version' and 'author'
import { readFile } from 'fs/promises';
const extensionInfo = JSON.parse(
await readFile(
new URL('./package.json', import.meta.url)
)
);
// Create new extension with extensionInfo
let ext = new Extension(extensionInfo);
// Start connection to G-Earth
ext.run();
ext.on('init', () => {
console.log("Connected to G-Earth");
});
ext.on('start', () => {
console.log("Connected to G-Earth");
});
ext.on('connect', (host, connectionPort, hotelVersion, clientIdentifier, clientType) => {
// do something with client info
});
ext.on('end', () => {
console.log("Connection to G-Earth ended");
});
ext.on('click', () => {
console.log("G-Earth button clicked");
});
ext.interceptAll(HDirection.TOCLIENT, hMessage => {
let hPacket = hMessage.getPacket();
...
});
ext.interceptAll(HDirection.TOSERVER, hMessage => {
let hPacket = hMessage.getPacket();
...
});
ext.interceptByHeaderId(HDirection.TOCLIENT, 969, hMessage => {
let hPacket = hMessage.getPacket();
...
});
ext.interceptByHeaderId(HDirection.TOSERVER, 2443, hMessage => {
let hPacket = hMessage.getPacket();
...
});
ext.interceptByNameOrHash(HDirection.TOCLIENT, 'Ping', hMessage => {
let hPacket = hMessage.getPacket();
...
});
ext.interceptByNameOrHash(HDirection.TOSERVER, 'Pong', hMessage => {
let hPacket = hMessage.getPacket();
...
});
let hPacket = hMessage.getPacket(); // Example: {in:Chat}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}{i:0}
let userIndex = hPacket.readInteger();
let message = hPacket.readString();
hPacket.readInteger();
let bubble = hPacket.readInteger();
let hPacket = hMessage.getPacket(); // Example: {in:Chat}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}{i:0}
let vars = hPacket.read('iSiiii');
let userIndex = vars[0];
let message = vars[1];
let bubble = vars[3];
let hPacket = new HPacket('Chat', HDirection.TOCLIENT); // Example: {in:Chat}
hPacket.appendInt(1); // {in:Chat}{i:1}
hPacket.appendString('Hello'); // {in:Chat}{i:1}{s:"Hello"}
hPacket.appendInt(0); // {in:Chat}{i:1}{s:"Hello"}{i:0}
hPacket.appendInt(1); // {in:Chat}{i:1}{s:"Hello"}{i:0}{i:1}
hPacket.appendInt0); // {in:Chat}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}
hPacket.appendInt(0); // {in:Chat}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}{i:0}
let hPacket = new HPacket(1918) // Example: {l}{h:1918}
.appendInt(1) // {l}{h:1918}{i:1}
.appendString('Hello') // {l}{h:1918}{i:1}{s:"Hello"}
.appendInt(0) // {l}{h:1918}{i:1}{s:"Hello"}{i:0}
.appendInt(1) // {l}{h:1918}{i:1}{s:"Hello"}{i:0}{i:1}
.appendInt(0) // {l}{h:1918}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}
.appendInt(0); // {l}{h:1918}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}{i:0}
let hPacket = new HPacket('{in:Chat}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}{i:0}');
OR
let hPacket = new HPacket('{l}{h:1918}{i:1}{s:"Hello"}{i:0}{i:1}{i:0}{i:0}');
ext.sendToClient(hPacket);
ext.sendToServer(hPacket);
For more examples and/or help read the wiki