mwc-proxy 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Minecraft Web Client Proxies
2
+
3
+ This repository contains the **WebSocket proxy** for making Minecraft servers accessible to web clients.
4
+
5
+ ---
6
+
7
+ ## MWC proxy (this repo)
8
+
9
+ - **WebSocket-based Minecraft proxy** — browser clients connect via WebSocket; the proxy forwards to Java Minecraft servers (TCP).
10
+ - **Microsoft/Mojang authentication** — makes it possible to connect to official Minecraft servers!
11
+ - **Connection management & rate limiting** — per-IP limits, configurable caps.
12
+ - **SOCKS proxy support** — optional SOCKS5 upstream for outbound connections.
13
+ - **Signal Server integration** — reports to a central server (e.g. signal.mcraft.fun): description, domain, players, CPU, RAM; heartbeat every 10 seconds.
14
+ - **Prometheus metrics** — built-in metrics and optional `express-prom-bundle` middleware.
15
+ - **Callback interface for extensions** — e.g. custom connection routing, connection limits, banned origins.
16
+
17
+
18
+ ## Using this package as NPM library
19
+
20
+ Install:
21
+
22
+ ```sh
23
+ pnpm add mwc-proxy
24
+ ```
25
+
26
+ Build the project (if you use the source), then:
27
+
28
+ ```js
29
+ const { createProxyMiddleware } = require('mwc-proxy')
30
+ // or
31
+ import { createProxyMiddleware } from 'mwc-proxy'
32
+ ```
33
+
34
+ Use `createProxyMiddleware(options)` with Express. See `src/api.ts` for `ProxyMiddlewareOptions` (e.g. `urlRoot`, `allowOrigin`, `maxConnectionsPerIp`, `signal`, `to` for host/port allowlist).
35
+
36
+ CLI entry (standalone server):
37
+
38
+ ```sh
39
+ npx minecraft-web-proxy
40
+ # or
41
+ npx mwp
42
+ ```
43
+
44
+ Environment variables: `PORT`, `URL_ROOT`, `ALLOW_ORIGIN`, `MAX_CONNECTIONS_PER_IP`, `ACCESS_CODE`, `SIGNAL_SERVER_URL`, `SIGNAL_DESCRIPTION`, `SIGNAL_DOMAIN`.
45
+
46
+ ---
47
+
48
+ ## Docker (auto-updated images)
49
+
50
+ Images are published to GitHub Container Registry and updated on releases.
51
+
52
+ ```sh
53
+ docker pull ghcr.io/zardoy/mwc-proxy:latest
54
+ # or a specific version
55
+ docker pull ghcr.io/zardoy/mwc-proxy:0.1.0
56
+ ```
57
+
58
+ Run:
59
+
60
+ ```sh
61
+ docker run -p 2344:2344 -e PORT=2344 ghcr.io/zardoy/mwc-proxy
62
+ ```
63
+
64
+ The container exposes port **2344** by default. Override with `PORT` or pass `--port` to the app.
65
+
66
+ ---
67
+
68
+ For more information and the web client itself, visit the [main repo](https://github.com/zardoy/prismarine-web-client/).
69
+
70
+ ---
71
+
72
+ ## Bun WebSocket Proxy (standalone script)
73
+
74
+ For a minimal setup that only bridges WebSocket ↔ TCP (no auth, no Signal Server), you can use the Bun script so your Minecraft server accepts WebSocket connections.
75
+
76
+ Connect in the client with something like:
77
+
78
+ ```sh
79
+ wss://ws.your-domain.com
80
+ ```
81
+
82
+ 1. **Install [Bun](https://bun.sh/docs/installation)**
83
+ 2. **Copy [`ws-proxy.ts`](https://github.com/zardoy/mwc-proxy/blob/main/bun/ws-proxy.ts) to your server** (if present in this repo) and edit:
84
+ - `YOUR_SERVER_HOST` and `YOUR_SERVER_PORT` — your Minecraft server.
85
+ - `THIS_PUBLIC_IP` — public address used for redirects.
86
+ 3. **Run with PM2** (or systemctl / another process manager):
87
+ ```sh
88
+ pm2 start "bun run ws-proxy.ts" --name bun-proxy
89
+ ```
90
+
91
+ ### Limitations
92
+
93
+ - Not usable on hosters that block SSH or extra ports (e.g. Aternos).
94
+ - Intended to run on the **same server** as the Minecraft server to avoid extra latency; otherwise consider using MWC proxy servers.
package/dist/api.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ import http from 'http';
2
+ export type MwcCallbacks = {
3
+ log?: (line: string) => void;
4
+ getConnectData?: () => Record<string, any>;
5
+ onConnectionChange?: (count: number) => void;
6
+ getTooManyConnectionsMessage?: (currentCount: number, limit: number) => string;
7
+ getBannedOriginMessage?: (origin: string) => string;
8
+ handleConnectionRequest?: (req: any, res: any, handler: (proxies?: string[], timeLimit?: number) => Promise<void>) => Promise<boolean>;
9
+ };
10
+ export type ProxyMiddlewareOptions = {
11
+ onPing?: (req: any) => void;
12
+ log?: boolean | ((str: any) => any);
13
+ urlRoot?: string;
14
+ server?: http.Server;
15
+ allowOrigin?: boolean | string;
16
+ allowOriginApp?: boolean;
17
+ maxConnectionsPerIp?: number;
18
+ mwcCallbacks?: MwcCallbacks;
19
+ https?: {
20
+ key: string;
21
+ cert: string;
22
+ };
23
+ to?: {
24
+ host?: string;
25
+ port?: number;
26
+ blacklist?: boolean;
27
+ } | Array<{
28
+ host?: string;
29
+ port?: number;
30
+ blacklist?: boolean;
31
+ }>;
32
+ /**
33
+ * Optional signal server integration. When provided a SignalClient is created internally
34
+ * and reports connection counts automatically. Pass `getExtraSystemInfo` to include
35
+ * host-level metrics (cpu/ram) from the calling environment.
36
+ */
37
+ signal?: {
38
+ serverUrl?: string;
39
+ description?: string;
40
+ domain?: string;
41
+ /** When set, signal client runs a self-check (public IP + loop request to self) before reporting */
42
+ listenPort?: number;
43
+ getExtraSystemInfo?: () => {
44
+ cpuLoad?: number;
45
+ ramLoad?: number;
46
+ };
47
+ };
48
+ /**
49
+ * @default true
50
+ */
51
+ debugUrlEndpoint?: boolean;
52
+ /**
53
+ * Allow connections from IPv6 addresses. When false, IPv6 clients get 403.
54
+ * @default true
55
+ */
56
+ allowIPv6?: boolean;
57
+ /**
58
+ * Expose Prometheus /metrics scrape endpoint. Metrics are always collected; set to false to hide the endpoint.
59
+ * @default true
60
+ */
61
+ metricsEndpoint?: boolean;
62
+ /**
63
+ * Enable p-auth toggle-debug endpoint (GET /toggle-debug) for prismarine-auth debug scope. String for your own endpoint.
64
+ * @default false
65
+ */
66
+ authToggleDebugEndpoint?: boolean | string;
67
+ /**
68
+ * Max concurrent auth requests from the same IP.
69
+ * @default 2
70
+ */
71
+ authMaxConcurrentPerIp?: number;
72
+ /**
73
+ * Max total concurrent auth requests (all IPs).
74
+ * @default 5
75
+ */
76
+ authMaxConcurrentTotal?: number;
77
+ };
78
+ export declare const currentState: {
79
+ activeConnections: {
80
+ [token: string]: {
81
+ startTime: number;
82
+ ip: string;
83
+ host: string;
84
+ };
85
+ };
86
+ pendingConnections: {
87
+ [requestId: string]: {
88
+ ip: string;
89
+ startTime: number;
90
+ };
91
+ };
92
+ everConnected: number;
93
+ };
94
+ export declare function createProxyMiddleware(options?: ProxyMiddlewareOptions, connectionListener?: (ws: any) => void): import("express-serve-static-core").Express;
95
+ export default createProxyMiddleware;
96
+ export declare const parseSocksProxy: (proxy: string) => {
97
+ ipaddress: string;
98
+ port: number;
99
+ type: any;
100
+ userId?: undefined;
101
+ password?: undefined;
102
+ } | {
103
+ ipaddress: string;
104
+ port: number;
105
+ userId: string;
106
+ password: string;
107
+ type: any;
108
+ };
109
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AAqCvB,MAAM,MAAM,YAAY,GAAG;IACvB,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1C,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C,4BAA4B,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAC9E,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;IACnD,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE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