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

fs-rcon

v5.0.0

Published

A connection to remote fs

Downloads

31

Readme

A connection to remote fs

API

Instance methods

FSRCON.Client

create a client instance

var rcon = new FSRCON.Client({
    protocol: 'http',
    hostname: 'localhost',
    port: 3000,
    // optional: account id
    accountId: 'xyz',
    // optional: XMLHttpRequest
    XMLHttpRequest: XMLHttpRequest
})

Client.init(urlPathname)

initialize a connection to remote server. Returns a promise.

rcon.init('fsrcon/init')
  .then(
    // resolved
    function () {
      ..
    },  
    // rejected
    function (err) {
      ..
    }
  );

Client.connect(urlPathname, secret)

start authenticated connection. Returns a promise.

var rcon = new FSRCON.Client({
    protocol: 'http',
    hostname: 'localhost',
    port: 3000,
    // required: account id
    accountId: 'xyz'
  });

rcon.init('fsrcon/init')
  .then(
    // resolved
    function () {
      rcon.connect('fsrcon/connect', 'my secret')
        .then(
          function () {
            // authenticated
            ..
          },
          function (err) {
            // authentication failed
            ..
          }
        );
    },  
    // rejected
    function (err) {
      ..
    }
  );

Client.send(data, urlPathname, callback)

send data to remote server. init() must be called before send().

For authenticated connections data will be sent encrypted.

Returns xhr.

  • data: string of data to be sent
  • urlPathname: string url path
var xhr = rcon.send(data, 'test', function (err, result) {
  // JSON.parse(result).foo.data
});

xhr.upload.onprogress = function(e) {
  if (e.lengthComputable) {
    console.log('progress: ', (e.loaded / e.total) * 100);
  }
};

data will be sent as stringified JSON via POST:

{
  SID: <string>,
  data: <string|object>
}

Client instance fields

  • protocol
  • hostname
  • port
  • clientNonce
  • serverNonce
  • SID
  • serverOK

FSRCON.Server()

create a server instance

 var rcon = new FSRCON.Server();

Server.init(clientNonce)

initializes a connection to a client when Client.init() was received.

var connections = {};

server.post('/init', function (req, res){

  var rcon = FSRCON.Server();

  rcon.init({
    clientNonce: req.body && req.body.CN,
    clientAccountKey: eq.body && req.body.CAK
  }, function (err) {

    if (err) {
      res.status(500).end(err.message);
      return;        
    }

    connections[rcon.SID] = rcon;

    res.end(JSON.stringify({
      SN: rcon.serverNonce
    }));
    
  });

});

Server.connect(options)

authenticate connection.

rcon.connect(
  {
    accounts: accounts,
    clientHashedPassword: req.body.CHP,
    clientVerificationKey: req.body.CVK
  }, 
  function (err, accountId) {     
    if (err) {
      res.status(503).end();
    }
    else {
      res.json({STR: rcon.serverVerification});
    }
  }
);

Server instance fields

  • clientNonce
  • serverNonce
  • SID
  • clientOK

Static Methods

FSRCON.hash(..val)

get a SHA-512-based fingerprint

FSRCON.hash('0.1234')
-> '56KwnzFuvBUaqvqhFkG46Psj0bUIz9LiMGy7dgZPtDF8wj5tpkBPp6FDUvZF2iOuE2uCkgotDmtHAo6JA'

FSRCON.encrypt(message, secret)

get the AES-encrypted string for message

FSRCON.encrypt('my message', 'my secret')
-> '{"ct":"yX4XfECTghy/Cf8LYwzmOQ==","iv":"01472720a2455c96b297dc9ba68e3cbe","s":"34c58f289265cbfc"}'

FSRCON.decrypt(encrypted, secret)

get the decrypted string for the AES-encryped message

FSRCON.decrypt(
  '{"ct":"yX4XfECTghy/Cf8LYwzmOQ==","iv":"01472720a2455c96b297dc9ba68e3cbe","s":"34c58f289265cbfc"}', 
  'my secret'
)
-> 'my message'

load

to Browser-DOM (or CommonJS or AMD)

Client:

<script src="fs-rcon.js">
<script>
  // DOM
  var connection = new window.FSRCON.Client();
  ..
</script>

Server:

var FSRCON = require('fs-rcon'),
  connection = new FSRCON.Server();
..

Test

$ grunt test

License

MIT