Git Product home page Git Product logo

g-node's Introduction

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

g-node's People

Contributors

wiredspast avatar ruangustavo avatar alynva avatar unfamiliarlegacy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.