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

pokemon-showdown-api

v0.0.2

Published

A low-level library for connecting to and interacting with the Pokemon Showdown server

Downloads

3

Readme

pokemon-showdown-api

pokemon-showdown-api is a low-level library for connecting to and interacting with the Pokemon Showdown server.

This package is under development. Its documentation is not complete and there remain additional events to be added, but it is mostly API-stable.

Overview

This package presents a low-level API for interacting with Pokemon Showdown servers, and tries to avoid making any assumptions about the consumer's goals. In particular, this API is designed so that other APIs can be built on top of it (for example, to add logic for handling rooms or battles).

Explicit goals:

  1. Don't leak memory over time (this is critical for long-running consumers).
  2. Be fast.

(Goal 1 implies that no O(n) logs can be stored, precluding the storing of messages or rooms. If a consumer needs these features, they should implement this on their own.)

These lead to two explicit non-goals:

  1. No handling logic for rooms.
  2. No handling logic for battles.

Instead, this API is built to enable additional libraries to provide such functionality.

Usage

To install, run npm install pokemon-showdown-api.

(If you want to use a REPL to try and interact with Pokemon Showdown from the command line, try out npm install --global pokemon-showdown-api and use pokerepl.)

In order to instantiate a client, pass the server websocket URL and login server URL. Both are optional, defaulting to the official Pokemon Showdown servers.

var PokeClient = require('pokemon-showdown-api');

var client = new PokeClient();
// By default, this is equivalent to:
// var client = new PokeClient('ws://sim.smogon.com:8000/showdown/websocket', 'https://play.pokemonshowdown.com/action.php');

The client will emit events for consumers to listen on. The client does not store any messages, instead delegating this responsibility to consumers. (Storing messages uses memory over time, and not all consumers may need this.)

client.connect();

// Websocket has connected.
client.on('ready', function() {
  client.login('username', 'password');
});

// Successful login.
client.on('login', function(user) {
  console.log('Logged in as:', user);
});

// A battle challenge from another user has been received.
client.on('challenge', function(user) {
  console.log(user, 'would like to battle!');
});

// Login failed.
client.on('error:login', function(err) {
  console.log('Error encountered while logging in:', err.message);
});

In general, any sort of message can be sent using client.send. This package also provides a convenience method authentication using client.login(username, password).

For more details, see the API docs.

For notes on protocol specifics, see Pokemon Showdown Protocol, command parsing source code, and socket message parsing source code.

Notes about Pokemon Showdown's implementation

Pokemon Showdown is effectively implemented as a fancy chat room. Some of these are considered regular "chat" rooms, and others are considered "battle" rooms. Within battle rooms, a battle is conducted by sending special chat messages back and forth, with the server validating each message.

Authentication occurs by talking to a separate authentication server. The process is as follows:

  1. Get the challenge string (challstr) upon connecting to the main server
  2. Pass the challstr along with a proposed username (and password, if needed) to the login server
  3. The login server returns an assertion, which is passed to the main server to prove ownership of a username.

Roadmap

Ongoing

  1. Additional documentation
  2. Additional events

Next up

  1. An adapter taking JSON or MessagePack commands on stdin and emitting output on stdout to allow this library to be embedded in other projects.