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

srb2kartjs

v2.2.9

Published

javascript module for everything related to the open source game srb2kart

Downloads

9

Readme

SRB2KARTJS

Javascript module for everything related to the open source game srb2kart.

Documentation

All functions are exported in main:

import {getSrb2Info, openFile, logger, parseSocFile} from "srb2kartjs";

Network

getSrb2Info(address, port=5029, servercb, playercb, errorcb)

  • Connects to a srb2kart server using it's ip address + port number and returns the response using the server and player callbacks containing the data as defined by the serverinfo_pak and plrinfo structs in d_clisrv.h. Same property names are used. Errors on the connection are passed to the error callback.
  • servercb: callback with server info object.
  • playercb: callback with player info object.
  • errorcb: called when errors occur.

File

openFile(path);

  • Open either a wad or pk3 file using the given path. Returns a Promise containing an object representing the file, or throws an error.
  • Returns: Promise<Srb2kfile>

file.setBaseFile(path);

  • Set the srb2.pk3 file. This is needed for the palette when extracting images.
  • Returns: Promise<>

file.getDirectory();

  • Get a nested object structure representing the inner file structure.
  • Return: object

file.getText(path);

  • Get a string from the file using the full path as given by the directory.
  • returns: Promise<String>

file.getImage(path);

  • Get a graphic from the file using the full path as given by the directory. Needs setBaseFile if no custom palette is used.
  • Returns: Promise<ReadableStream>

file.getSoc(path);

  • Get a soc object from the file using the full path as given by the directory.
  • Returns: Promise<Object>

file.getAllSocs();

  • Get the soc object from every soc text in the file.
  • Returns: Promise<Object>

file.getBuffer(path);

  • Get a nodebuffer from any file in the file using the full path as given by the directory.
  • Returns: Promise<nodebuffer>

Directory

Object used by the wad and pk3 file objects. This contains the entire directory and supports searching through it. This contains no data and files are represented by empty folders.

directory.fullname;

  • String of the full path starting from root. Use this in file methods.

directory.get(name);

  • Get a child of this directory using the name.
  • Returns: Directory object

directory.search(regex);

  • Find all children where the name matches the regex.
  • Returns: [Directory object]

directory.allFiles();

  • Get a list of all the file paths (fullname) starting from this directory.
  • Returns [String]

log

logger(filepath="~/.srb2kart/log.txt")

  • Listens to the srb2kart log file at filepath and returns an event emitter eg. const eventemitter = logger(); eventemitter.on("playerJoin", (o) => console.log(o.name + " has joined the game."))
  • Returns: EventEmitter
Log events
"line" // emitted on every line
{
    line
}
"playerJoin"
{
    name,
    ip,
    node
}
"playerRename"
{
    oldName,
    newName,
    player: {
        name,
        ip,
        node
    }
}
"playerLeave"
{
    name,
    ip,
    node
}
"playerSay"
{
    player: {
        name,
        ip,
        node
    },
    message
}
"newMap"
{
    mapid,
    mapname
}
"command"
{
    command
}
"playerFinish"
{
    player: {
        name,
        ip,
        node
    }
}
"playerVoteCalled"
{
    player: { // the player calling the vote
        name,
        ip,
        node,
    },
    command
}
"playerVote"
{
    player: { // the player voting yes or no
        name,
        ip,
        node,
    },
    choice, // the player's vote, -1 or 1
    vote: {
        callee: {
            name,
            ip,
            node
        },
        command,
        votedYes: [ {player} ], // list of player objects that already have voted yes
        votedNo: [ {player} ], // list of player objects that already have voted no
    }
}
"voteComplete"
{
    passed,
    vote: {
        callee: {
            name,
            ip,
            node
        },
        command,
        votedYes: [ {player} ], // list of player objects that already have voted yes
        votedNo: [ {player} ], // list of player objects that already have voted no
    }
}
"kitchenSinkHit"
{
    player: {
        name,
        node,
        ip
    }
}

The next events are exact matches with lines in the log without any state or data. Use these as a shortcut around doing exact matches with the "line" event.

"ttyShutdown"
{}
"speedingOffTo"
{}
"roundEnd"
{}
"logStreamEnd"
{}
"gameLoopEnter"
{}
"pwadNotFoundOrInvalid"
{}

Basics

pk3

openPk3(filename): Opens a soc file. Return a Promise containing a JsZip object.

extractSoc(filepath, socs={}): parses the soc files in filepath and adds returns the soc socs object with the new data.

wad

Each function returns a promise.

getHeader(filename): The header of the wad file.

getDirectory(filename): Get a list of lump information.

getLumps(filename, lumpname): Get a list of lumps matching the filename as buffers.

soc

parseSocFile(filename, lines, socs={}): given the content of a socfile in lines, parse the content and add the definitions to the socs object which this function returns. filename is added to the map metadata.