Giter VIP home page Giter VIP logo

mcproxy's Introduction

Release Continuous Integration Latest Beta

mcproxy [WIP]

a minecraft proxy library powered by mineflayer that replicates data as well as possible from available information of mineflayer

Contribution

This project was inspired by 2bored2wait and now serves as a dependency of it. This project relies heavily on the great work that the awesome people of the PrismarineJS project have done.

Installation

To add this to your project, just install it with your favourite package manager.

npm install @rob9315/mcproxy
# or
yarn add @rob9315/mcproxy
# or
pnpm add @rob9315/mcproxy

API

This project provides the Conn class, which enables you to create a connection to a server and connect clients to the Conn instance. The connection will stay after you disconnect from the Conn instance.

// How to instanciate Conn:
import { Conn } from '@rob9315/mcproxy';
const conn = new Conn(botOptions: mineflayer.BotOptions, options: ConnOptions);

Types and Classes

BotOptions

The botOptions which are needed in the constructor of Conn, are the same as the ones from mineflayer itself.

ConnOptions

ConnOptions regulate Conn-specific settings.

  • ConnOptions.events: extra events you can specify that will listen on every pclient that is attached. You can also specify methods in the array that return an event. They can take the Conn and specific pclient as options. The type definition of events looks as such:

    type ClientEventTuple = [event: string, listener: (...args: any) => void];
    type ClientEvents = (ClientEventTuple | ((conn: Conn, pclient: Client) => ClientEventTuple))[];
  • ConnOptions.internalWhitelist: a packet name whitelist for the internal bot. Whitelisted packets are still sent even if a proxyClient is currently linked.

  • ConnOptions.toServerBlackList: a packet name blacklist for all proxyClients. Blacklisted packets will not be transmitted from the proxyClient to the server.

  • ConnOptions.toServerBlackList: a packet name blacklist for all proxyClients. Blacklisted packets will not be transmitted from the server to the proxyClient.

Client | pclient

The Client class is the same as the minecraft-protocol client class with the one exception that it can also contain the following settings used in the Conn class to cause different behaviors.

  • pclient.toServerWhiteList: a packet name whitelist for the client. Whitelisted packets will still be sent to the server even if the client isn't linked.
  • pclient.toServerBlackList: a packet name blacklist for the client. Blacklisted packets will not be sent to the server even if the client is linked.
  • pclient.toClientBlackList: a packet name blacklist for the client. Blacklisted packets will not be sent to the client it it is attached.

Packet

A tuple consisting of the name and data of the packet. Reason for this is to be easily used with the .write function of any client.

import type { Packet } from '@rob9315/mcproxy';
const packet: Packet = ['chat', { message: 'Welcome to mcproxy!', position: 0 }];
pclient.write(...packet);

generatePackets()

import { generatePackets } from '@rob9315/mcproxy';
let packets: Packet[] = generatePackets(bot, pclient?: Client);
packets.forEach((packet)=>pclient.write(...packet));

the internal method used to generate packets from a bot and an optional pclient. If a pclient is provided some aspects of the packets are changed such as the uuid and some version specific changes might be done for compatibility (though not all versions are supported [yet])

Conn.bot

the mineflayer Bot integrated into the library, You cannot write with the bot's bot._client.write() method, instead use the Conn.write() method if you need to manually send packets.

Conn.pclient

The proxyClient which is able to send packets to the server. Also receives them as a part of the Conn.pclients array. Do not write to this manually

Conn.pclients

An array of all proxyClients which are attached to the Connection. Use Conn.attach() to add a client to the array and Conn.detach(), they handle some more things which you'll probably want as well.

Conn.generatePackets()

Conn.generatePackets(pclient?: Client): Packet[]

returns the generated packets for the current gamestate

Conn.sendPackets()

Conn.sendPackets(pclient: Client);

calls Conn.generatePackets() and sends the result to the proxyClient specified

Conn.attach()

Conn.attach(pclient: Client)

the pclient specified will be added to the Conn.pclients array, which means that it will receive all packets from the server. If you want the client to be able to send packets to the server as well, don't forget to call Conn.link()

Conn.detach()

Conn.detach(pclient: Client)

the pclient specified will be removed from the Conn.pclients array, meaning that it will no longer receive packets from the server. If the client was linked before, Conn.unlink() will also be called.

Conn.link()

Conn.link(pclient: Client)

stops the internal bot from sending any packets to the server and starts relaying all packets from the proxyClient to the server.

Conn.unlink()

Conn.unlink();

reverses the link method. The bot becomes the one to send packets to the server again. If the proxyClient should be detached as well

Conn.writeIf()

Conn.writeIf(name, data);

an internal method for filtering the bots Packets, can be used outside but as an API method basically useless.

Conn.disconnect()

disconnects from the server and detaches all pclients

mcproxy's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.