deathcap / wsmc

WebSocket proxy to Minecraft
33 stars 10 forks source link

Detect when login will fail because server is in online mode #18

Open deathcap opened 9 years ago

deathcap commented 9 years ago

wsmc should more gracefully handle when the server is not in offline mode, causing login to fail:

wsmc $ npm start

> wsmc@0.0.1 start /Users/admin/games/voxeljs/wsmc
> NODE_DEBUG=mc-proto node wsmc.js

You are using a pure-javascript implementation of RSA.
Your performance might be subpar. Please consider installing URSA
WS(0.0.0.0:24444) <--> MC(localhost:25565)
MC-PROTO: 17784 Old-styling packet
MC-PROTO: 17784 writing packetId handshaking.set_protocol (0x0)
MC-PROTO: 17784 { protocolVersion: 47,
  serverHost: 'localhost',
  serverPort: 25565,
  nextState: 2 }
MC-PROTO: 17784 Old-styling packet
MC-PROTO: 17784 writing packetId login.login_start (0x0)
MC-PROTO: 17784 { username: 'webuser-1' }
Successfully connected to MC
MC-PROTO: 17784 read packetId login.encryption_begin (0x1)
MC-PROTO: 17784 { id: 1,
  state: 'login',
  serverId: '-6c9e4c4a7c52a266',
  publicKeyLength: 162,
  publicKey: <Buffer 30 81 9f 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 81 8d 00 30 81 89 02 81 81 00 bb 09 bf fc 55 0b 1c b4 86 d1 09 89 00 34 e3 e0 d9 c7 9e 3d 71 ... >,
  verifyTokenLength: 4,
  verifyToken: <Buffer 71 69 db f5> }
MC-PROTO: 17784 This server appears to be an online server and you are providing no password, the authentication will probably fail
MC-PROTO: 17784 Old-styling packet
MC-PROTO: 17784 writing packetId login.encryption_begin (0x1)
MC-PROTO: 17784 { sharedSecret: <Buffer 90 8c 46 c9 7e 84 e9 8b 57 e8 f1 fc 11 70 7c be c6 75 ae f7 9a 8a cf 6b ef 4e ae 4a 62 a0 6a 80 a3 d2 4d 44 41 bc 52 a1 51 1a fd a2 f0 6a 9a 30 58 4e ... >,
  verifyToken: <Buffer 9c 11 19 f2 66 ab 8a 7b 9c ad d4 12 ba b9 b0 65 df 02 ae f0 ea c1 a2 f4 4c 35 12 1e 88 37 77 97 65 64 d8 e9 b9 f0 98 2f cf ac df fb 98 0a 86 2e 71 84 ... > }
WS requested username: user1

testing with https://github.com/GlowstoneMC/Glowstone - this is shown on the server-side:

Glowstone++ $ java -jar target/glowstone-0.0.1-SNAPSHOT.jar
20:05:49 [INFO] This server is running Glowstone version git-Glowstone-1.8-171-g352b7b9 (Implementing API version 1.8-R1-SNAPSHOT)
20:05:49 [INFO] Recipes: 295 shaped, 63 shapeless, 24 furnace, 15 fuels.
20:05:49 [INFO] Preparing spawn for world...
20:05:50 [INFO] Preparing spawn for world: 78%
20:05:50 [INFO] Preparing spawn for world: done
20:05:50 [INFO] Preparing spawn for world_nether...
20:05:51 [INFO] Preparing spawn for world_nether: done
20:05:51 [INFO] Preparing spawn for world_the_end...
20:05:51 [INFO] Preparing spawn for world_the_end: done
20:05:51 [INFO] Binding to address: 0.0.0.0/0.0.0.0:25565...
20:05:51 [INFO] Successfully bound to: /0:0:0:0:0:0:0:0:25565
20:05:51 [INFO] Ready for connections.
20:06:07 [WARNING] Could not decrypt shared secret
javax.crypto.BadPaddingException: Decryption error
    at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:380)
    at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:291)
    at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:365)
    at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:391)
    at javax.crypto.Cipher.doFinal(Cipher.java:2087)
    at net.glowstone.net.handler.login.EncryptionKeyResponseHandler.handle(EncryptionKeyResponseHandler.java:55)
    at net.glowstone.net.handler.login.EncryptionKeyResponseHandler.handle(EncryptionKeyResponseHandler.java:35)
    at com.flowpowered.networking.session.BasicSession.handleMessage(BasicSession.java:80)
    at com.flowpowered.networking.session.BasicSession.messageReceived(BasicSession.java:139)
    at net.glowstone.net.GlowSession.pulse(GlowSession.java:408)
    at net.glowstone.net.SessionRegistry.pulse(SessionRegistry.java:23)
    at net.glowstone.scheduler.GlowScheduler.pulse(GlowScheduler.java:174)
    at net.glowstone.scheduler.GlowScheduler.access$100(GlowScheduler.java:25)
    at net.glowstone.scheduler.GlowScheduler$2.run(GlowScheduler.java:111)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
20:06:07 [INFO] [/127.0.0.1:62899] kicked: Unable to decrypt shared secret.

config/glowstone.yml server online-mode: true

and then http://github.com/deathcap/voxel-clientmc crashes in mf-worker:

  self.move = function(event) {
    self.bot.entity.position.set(event.position[0], event.position[1], event.position[2]);
  };

(self.bot.entity undefined)