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

@realmlib/net

v3.3.3

Published

A networking library for Realm of the Mad God.

Downloads

24

Readme

realmlib/net

Build Status CodeFactor

A networking library for Realm of the Mad God.

Contents

Install

npm install @realmlib/net

Use

The realmlib networking module cannot be used on its own. It is designed to be used as a building block for larger RotMG projects which require an implementation of the RotMG networking protocol. Such project may include

  • MITM proxies (such as KRelay or JRelay).
  • Clientless applications (such as nrelay).

Using the PacketIO class

The PacketIO class provides an event based way of sending and receiving RotMG packets. It is very likely that a project which depends upon @realmlib/net will make use of the PacketIO class.

When a new PacketIO instance is constructed, it expects an object with 3 optional properties.

  • socket - An instance of net.Socket
  • rc4 - An object which contains an incoming RC4 key and an outgoing RC4 key.
  • packetMap - An object which maps packet types to their IDs.

By default,

  • socket will be initialised to undefined.
  • rc4 will be initialised to an object containing the current RotMG incoming and outgoing RC4 keys.
  • packetMap will be initialised to an empty object literal ({}).

If a socket is provided, the PacketIO instance will be immediately attached to that socket. A PacketIO instance can always be attached to a socket after constructed via the attach() method, so providing a socket to the constructor is not necessary.

The default values which are used for the rc4 property are set up for a clientless application. However, they are configurable to allow the PacketIO class to be used for other applications. For example, when building a MITM proxy, the PacketIO instance which listens to traffic coming from the server should use the incoming key for both the incoming and outgoing key configurations. The PacketIO instance which is listening to traffic coming from the client should use the outgoing key for both the incoming and outgoing key configurations.

import { PacketIO, INCOMING_KEY, OUTGOING_KEY } from '@realmlib/net';

const serverIO = new PacketIO({
  rc4: {
    incomingKey: INCOMING_KEY,
    outgoingKey: INCOMING_KEY,
  }
});

const clientIO = new PacketIO({
  rc4: {
    incomingKey: OUTGOING_KEY,
    outgoingKey: OUTGOING_KEY,
  }
})

The packetMap property is the most important one, as it allows the PacketIO instance to resolve packet ids to their types. This is necessary in order to create the right instances of packets when they are received, and to use the right id when sending packets.

The packetMap object is expected to bidirectional. That is, if the map contains the property

import { PacketMap, PacketType } from '@realmlib/net';

const packetMap: PacketMap = {
  FAILURE: 0,
};

it should also contain the reverse of that property.

const packetMap: PacketMap = {
  FAILURE: 0,
  0: PacketType.FAILURE,
};

Ideally, the packetMap should contain an entry for each property present in the PacketType enum. This will ensure that the PacketIO instance knows how to create any type of packet which it may receive. If some of the packet types are missing, the PacketIO will be unable to send those packets, and will not be able to create an instance of the packet when one is received.