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

mcpews

v4.0.0

Published

A library that supports MCPE Websocket Protocol

Downloads

23

Readme

MCPEWS

A library that supports MCPE Websocket Protocol.

Usage

Server-side:

import { WSServer, Version } from 'mcpews';
const server = new WSServer(19134); // port

server.on('client', ({ session }) => {
    // someone type "/connect <ip address>:19134" in the game console

    // execute a command
    session.sendCommand('say Connected!');

    // execute a command and receive the response
    session.sendCommand('list', ({ body }) => {
        console.log(`currentPlayerCount = ${body.currentPlayerCount}`);
    });

    // subscribe a event
    session.subscribe('PlayerMessage', (event) => {
        // when event triggered
        const { body, version } = event;
        let message, messageType;
        if (version === Version.V1_1_0) {
            message = body.message;
            messageType = body.type;
        } else {
            message = body.properties.Message;
            messageType = body.properties.MessageType;
        }
        if (message === 'close') {
            // disconnect from the game
            session.disconnect();
        } else if (messageType === 'chat') {
            session.sendCommand('say You just said ' + message);
        }
    });

    // enable encrypted connection
    session.enableEncryption();
});

Client-side:

import { WSClient } from "mcpews";
const client = new WSClient('ws://127.0.0.1:19134'); // address

process.stdin.on('data', (buffer) => {
    // trigger a event (will be ignored if not subscribed)
    client.publishEvent('input', {
        data: buffer.toString()
    });
});

client.on('command', (event) => {
    const { commandLine } = event;

    // pass encryption handshake to client itself
    if (event.handleEncryptionHandshake()) return;

    // command received
    console.log('command: ' + commandLine);

    // respond the command, must be called after handling
    event.respond({
        length: commandLine.length
    });
});

WSApp, optimized for async/await:

import { WSApp } from "mcpews";

const app = new WSApp(19134);
app.on('session', async ({ session }) => {
    const playerNames = (await session.command('testfor @a')).body.victim;
    const names = await Promise.all(
        playerNames.map(async (playerName) => {
            await session.command(`tell ${playerName} What's your name?`);
            try {
                const name = (await session.waitForEvent('PlayerMessage', 30000, (ev) => ev.body.sender === playerName))
                    .body.message;
                await session.command(`tell ${playerName} Your name is ${name}`);
                return name;
            } catch (err) {
                return playerName;
            }
        })
    );
    console.log(names);
    await session.disconnect();
});

REPL:

mcpews [<custom port>]

MITM:

mcpewsmitm <destination address> [<listen port>]