gnode-api
TypeScript icon, indicating that this package has built-in type declarations

0.2.18 • Public • Published

G-Node

Node.js G-Earth extension API
Requires Node.js V15.0.0+
Docs: https://wiredspast.github.io/G-Node/modules.html

How to install

Using npm:

$ npm install gnode-api

Using yarn:

$ yarn add gnode-api

How to run selfmade extension

$ node [filename] -p [port]

Example

$ node extension.js -p 9092

Example

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();

Listeners

Do on connection to G-Earth

ext.on('init', () => {
  console.log("Connected to G-Earth");
});

Do on connection to hotel

ext.on('start', () => {
  console.log("Connected to G-Earth");
});

Do on connection to hotel and get client info

ext.on('connect', (host, connectionPort, hotelVersion, clientIdentifier, clientType) => {
  // do something with client info
});

Do on connection to hotel ended

ext.on('end', () => {
  console.log("Connection to G-Earth ended");
});

Do on click on button in G-Earth Extensions tab

ext.on('click', () => {
  console.log("G-Earth button clicked");
});

Packet intercepting

Intercept all packets in one direction

ext.interceptAll(HDirection.TOCLIENT, hMessage => {
  let hPacket = hMessage.getPacket();
  ...
});

ext.interceptAll(HDirection.TOSERVER, hMessage => {
  let hPacket = hMessage.getPacket();
  ...
});

Intercept all packets with a certain header id in one direction

ext.interceptByHeaderId(HDirection.TOCLIENT, 969, hMessage => {
  let hPacket = hMessage.getPacket();
  ...
});

ext.interceptByHeaderId(HDirection.TOSERVER, 2443, hMessage => {
  let hPacket = hMessage.getPacket();
  ...
});

Intercept all packets by name or hash in one direction

ext.interceptByNameOrHash(HDirection.TOCLIENT, 'Ping', hMessage => {
  let hPacket = hMessage.getPacket();
  ...
});

ext.interceptByNameOrHash(HDirection.TOSERVER, 'Pong', hMessage => {
  let hPacket = hMessage.getPacket();
  ...
});

Reading a packet

Reading a var by var

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();

Reading a structure into an array

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];

Creating a packet

Creating packet from identifier (name or hash) and direction

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}

Creating packet from header Id

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}

Creating packet from packet expression

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}');

Sending a packet

Send packet to client

ext.sendToClient(hPacket);

Send packet to server

ext.sendToServer(hPacket);

More

For more examples and/or help read the wiki

Readme

Keywords

none

Package Sidebar

Install

npm i gnode-api

Weekly Downloads

48

Version

0.2.18

License

ISC

Unpacked Size

309 kB

Total Files

92

Last publish

Collaborators

  • wiredspast