Added README and more error Handling to client_socks_proxy example (#846)

* Added README and more error Handling to client_socks_proxy example.

* Lint fixing
This commit is contained in:
IceTank 2021-04-11 23:15:15 +02:00 committed by GitHub
parent f509095bd2
commit ebbd93f2b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 2 deletions

View file

@ -0,0 +1,43 @@
### Socks5 Proxy example
- **!This Example only works with socks5 proxys!**
Make sure your proxy connection is working.
#### Testing proxy connections with curl on Unix systems or Command prompt on Windows:
```bash
curl -x "socks5://<proxyAddress>:<proxyPort>" "http://ifconfig.me"
```
If you see an ip address the proxy is working. If you see anything else it's not.
#### These Errors what do they mean????
```
FetchError: request to https://authserver.mojang.com/authenticate failed, reason: Socket closed
```
- The Proxy is not working
--------
```
SocksClientError: Socket closed
```
- General Socket error Bad Proxy/Proxy refuses the connection
--------
```
SocksClientError: connect ECONNREFUSED <some ip address>
```
- The Connection to the proxy Failed
--------
```
SocksClientError: Proxy connection timed out
```
- Destination Address is wrong/not reachable. Or the Proxy is not working.
--------
```
Connection Refused: Blocked by CloudFront/CloudFlare
```
- Proxy Ip has been banned/block by Cloudflare.

View file

@ -10,6 +10,25 @@ if (process.argv.length < 6 || process.argv.length > 8) {
const proxyHost = process.argv[4] const proxyHost = process.argv[4]
const proxyPort = process.argv[5] const proxyPort = process.argv[5]
// This part tests the proxy
// You can comment out this part if you know what you are doing
require('http').get({
method: 'GET',
host: 'ifconfig.me',
path: '/',
agent: new ProxyAgent({ protocol: 'socks5:', host: proxyHost, port: proxyPort })
}, (res) => {
if (res.statusCode === 200) {
process.stdout.write('Proxy ok ip: ')
res.pipe(process.stdout)
res.on('close', () => {
process.stdout.write('\nProxy Connection closed\n')
})
} else {
throw Error('Proxy not working')
}
})
const client = mc.createClient({ const client = mc.createClient({
connect: client => { connect: client => {
socks.createConnection({ socks.createConnection({
@ -47,6 +66,12 @@ client.on('disconnect', function (packet) {
client.on('end', function () { client.on('end', function () {
console.log('Connection lost') console.log('Connection lost')
}) })
client.on('error', function (error) {
console.log('Client Error', error)
})
client.on('kick_disconnect', (reason) => {
console.log('Kicked for reason', reason)
})
client.on('chat', function (packet) { client.on('chat', function (packet) {
const jsonMsg = JSON.parse(packet.message) const jsonMsg = JSON.parse(packet.message)
if (jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') { if (jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {

View file

@ -37,12 +37,12 @@
"@types/node": "^14.0.1", "@types/node": "^14.0.1",
"espower-loader": "^1.0.0", "espower-loader": "^1.0.0",
"intelli-espower-loader": "^1.0.0", "intelli-espower-loader": "^1.0.0",
"minecraft-packets": "^1.1.5",
"minecraft-wrap": "^1.2.3", "minecraft-wrap": "^1.2.3",
"mocha": "^8.0.1", "mocha": "^8.0.1",
"power-assert": "^1.0.0", "power-assert": "^1.0.0",
"require-self": "^0.2.3", "require-self": "^0.2.3",
"standard": "^16.0.1", "standard": "^16.0.1"
"minecraft-packets": "^1.1.5"
}, },
"dependencies": { "dependencies": {
"@azure/msal-node": "^1.0.0-beta.3", "@azure/msal-node": "^1.0.0-beta.3",