Giter VIP home page Giter VIP logo

pterosocket's Introduction

pterosocket

A websocket implementation for the pterodactyl server console.

Pterosocket class creates a websocket that connects to a Pterodactyl panel. It manages the events generated, and keeps the connection open (re-authentication is needed every 10-15 min otherwise). Using this tool you can easily implement a discord bot or webhook that streams the game-console through which you can send commands, check the logs, and even get the server stats in real time.

Check the Documentation for details on the usage of this class. The original documentation for the Pterodactyl API protocol can be found here.

Installation

Run the following line in your terminal:

npm install pterosocket

Usage

In order to connect you need to find the domain of your hosting panel (origin), the number of the server, and generate an API key form the "Account" section of the panel. Now you can subscribe the events you are interested in, and send packets to the panel.

const { pterosocket } = require('pterosocket')

const origin = "https://games.hosting.com"; // your panel's domain
const api_key = "dwaQaLKSWmVoZfJ7jC2rAnhW6y6mKAUPuF22bqqgA5daM79S"; //the api-key generated
const server_no = "194v3220"; //the number of the server

const socket = new pterosocket(origin, api_key, server_no);

socket.on("start", ()=>{
    console.log("Connected!")
    socket.writeCommand("say console connected!");
})

How do I find the parameters needed to create a new pterosocket?

Regardless the hosting company your server is hosted by, each panel has a fixed structure. For example the webpage from which you access your console will have this format: {origin}/server/{server number}. So, if your hosting company is e.g. www.bisecthosting.com (one of several gaming companies), your console website address will be https://games.bisecthosting.com/server/274w3925, and your code will be as follows

const origin = "https://games.bisecthosting.com"; //everything that comes before "/server" in the console url
const server_no = "274w3925"; //everything that comes after "/server/" in the console url

Now in order to generate an API key for the pterosocket instance you need to navigate to this page {origin}/account/api (in our example it will be https://games.bisecthosting.com/account/api) and generate a new API key, which we can add to our code.

const api_key = "dwaQaLKSWmVoZfJ7jC2rAnhW6y6mKAUPuF22bqqgA5daM79S"; //the api-key generated

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.