Add built-in proxy support for SOCKS4/5 and HTTP proxies#1420
Add built-in proxy support for SOCKS4/5 and HTTP proxies#1420
Conversation
- Add new proxy.js module with built-in SOCKS4, SOCKS5, and HTTP CONNECT implementations
- Enhance createClient() to accept proxy configuration via simple `proxy` option
- Automatically configure proxy agents for authentication modules
- Maintain backward compatibility with existing `connect` function approach
- Add comprehensive test coverage with real MC server integration
- Include simple example demonstrating new proxy API
Fixes connection issues through proxies by providing proper authentication
handling and eliminating need for external proxy dependencies.
Example usage:
```js
const client = mc.createClient({
host: 'localhost',
port: 25565,
username: 'testuser',
proxy: {
type: 'socks5',
host: '127.0.0.1',
port: 1080,
auth: { username: 'user', password: 'pass' }
}
})
```
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace custom SOCKS/HTTP protocol implementations with simple wrapper
functions that leverage existing packages and examples:
- Use 'socks' package for SOCKS4/5 (like existing client_socks_proxy example)
- Use built-in http module for HTTP CONNECT (like existing client_http_proxy example)
- Auto-generate connect function instead of complex custom protocols
- Add socks and proxy-agent as dependencies
- Fix test SOCKS5 proxy to send proper response format
Benefits:
- Reduced from 267 to ~100 lines of code
- Leverages battle-tested external packages
- Reuses proven patterns from existing examples
- Same simple user API: proxy: { type: 'socks5', host: '...', port: 1080 }
- Better reliability and maintainability
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Move proxy connection logic after SRV resolution to ensure that domain names like 'mc.hypixel.net' are properly resolved to their actual server addresses before connecting through proxy. Before: proxy bypassed SRV lookup entirely After: SRV lookup → then connect via proxy to resolved address 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
- Add command line argument parsing - Include proper error handling and event listeners - Add usage instructions with example - Use 'use strict' directive - Follow consistent structure with other client examples 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Document proxy option with all supported types (SOCKS4/5, HTTP/HTTPS) - Include authentication configuration details - Add comprehensive usage examples - Show integration with Microsoft auth and SRV records 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Keep documentation concise by referencing example folder - Avoid duplication with examples/client_builtin_proxy/ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
What do you think @extremeheat ? That would allow closing the million issues we have around proxies in nmp and mineflayer It adds a dep but I think it might be worth it |
Related Issues This PR FixesThis built-in proxy support implementation addresses numerous long-standing proxy issues across both mineflayer and node-minecraft-protocol repositories: Mineflayer Issues Fixed:
Node-Minecraft-Protocol Issues Fixed:
How This PR Solves These Issues:
Instead of users having to implement complex proxy logic themselves (often incorrectly), they can now simply use: const client = mc.createClient({
host: 'blocksmc.com', // Works with SRV records now\!
username: 'player',
auth: 'microsoft', // Auth works through proxies\!
proxy: {
type: 'socks5',
host: '127.0.0.1',
port: 1080,
auth: { username: 'user', password: 'pass' }
}
})This should resolve the majority of proxy-related issues that users have been struggling with for years, spanning 25+ issues across both repositories. |
|
LGTM but we might have to add a polyfill for webpack in prismarine-viewer / pwc |
| return function (client) { | ||
| let socks | ||
| try { | ||
| socks = require('socks').SocksClient |
There was a problem hiding this comment.
this should be at the top level
| */ | ||
| function createProxyAgent (proxyConfig) { | ||
| try { | ||
| const ProxyAgent = require('proxy-agent') |
There was a problem hiding this comment.
this should be at the top level
|
This would be really cool if it were merged, the current connect system works for me in connecting to servers but even using the agent field a proxy doesn't get passed thru to msa auth and I'm having to implement a janky fork in prismarine-auth |
Summary
This PR adds comprehensive built-in proxy support to node-minecraft-protocol, addressing issues with proxy connections that require external dependencies and complex setup.
Features Added
sockspackage for reliabilityproxy: { type: 'socks5', host: '...', port: 1080 }to createClientconnectfunction approach still worksExample Usage
Command Line Example
Problem Solved
Fixes authentication and connection issues through proxies (addresses mineflayer issue #3457) by:
connectfunction overridessocks,proxy-agent)Test Coverage
🤖 Generated with Claude Code