npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

precursors-client

v0.1.1

Published

A library for communication with the Precursors Server.

Downloads

7

Readme

Node Precursors

This is a simple communication library for the precursors server. It has been designed to make things as straightforward as possible, using things that should be very familiar to node developers.

Installing

Simply install the precursors-client package from npm:

$ npm install --save precursors-client

Client Type

First things first, you need to pick which client type you want to use. You choices are as follows:

  • Game Client
    • Can only have one connected per account.
    • Can control the player's avatar.
    • Complete access to all functions.
    • Useful for official client replacements.
  • Service Client
    • Can have many connected per account.
    • Cannot affect in-game state, such as movement, etc.
    • Limited access to functionality.
    • Useful for management tools or websites.

Note: At the moment, the only supported client is the Game Client. Once service client support is added to precursors server, you will be able to use it.

Connecting

Regardless of which client you choose, you connect the same way:

var prelib = require('precursors');

var client = new prelib.GameClient('localhost', 6006);

client.connect('[email protected]', 'pass123')
    .then(function()
    {
        console.log('Completely Connected.');
    })
    .catch(prelib.errors.RequestDenied, function(message)
    {
        console.log('Failed to log in:', message.reason);
    });

The connect method of the client returns a promise, so you can easily chain it with other promises.

Custom Errors

As you will notice in the example, we use a custom error RequestDenied to indicate that the request (in this case, the login) was denied.

Channels

Once you have a connection to the server, you then will need to create a channel object:

var channel = client.channel('control');

Listening for events

Now that you have a channel, you can listen for events. We emit them based on their 'type' in precursors server.

channel.on('setZone', function(message)
{
    // Would set the client's new zone here.
});

If, however, you need to listen on a more low level, you can listen for the 'event' event, which is fired internally. This gives you the ability to handle the message before it is unwrapped or routed.

Sending events

Sending an event is simple:

// Send a command event
channel.event({ type: 'command', name: 'remove' });

// Send a command event over TCP
channel.event({ type: 'command', name: 'remove' }, 'tcp');

By default, all events and requests are sent over SSL. However, this isn't desirable for things like input events. This is why we allow for you to send events over the TCP channel by passing the string 'tcp' as the second parameter.

Requests

Working with requests is made easy, using promises. Like events, You send your message and (optionally) the transport as a string:

var loginMsg = {
    type: 'login',
    clientName: 'My Client',
    clientType: 'game',
    version: '0.1.0',
    user: 'test',
    password: 'pass1234',
    key: 'random 16bit Key',
    vector: 'random 16bit IV'
};

// Send the request and handle the response
channel.request(loginMsg)
    .then(function(response)
    {
        // handle request being confirmed
    })
    .catch(prelib.errors.RequestDenied, function(message)
    {
        // Handle request being denied 
        console.log('Failed to log in:', message.reason);
    })
    .catch(function(error)
    {
        // Handle Errors
    });

As you can see, request returns a promise that is only resolved if the request is confirmed. Otherwise you will need to catch the custom RequestDenied error. Denied requests should have a human-readable reason in the reason property of the message.