js-minecraft icon indicating copy to clipboard operation
js-minecraft copied to clipboard

How to test multiplayer

Open codingwatching opened this issue 3 years ago • 5 comments

Hi @LabyStudio Thank you so much for this awesome project When I press the demo and enter multiplayer, nothing happens https://labystudio.de/page/minecraft/ Could you please help me how set up and test that function? Thank you!

codingwatching avatar Sep 11 '22 09:09 codingwatching

Hey, the multiplayer feature is currently an experimental implementation and works over a websocket proxy that only allows my local demo server for testing purposes.

You should be still able to join this demo server, doesn't matter which ip address you enter. Maybe open the devtools network tab and check for any error messages when connecting to the the websocket server.

I'm not at home right now and I tested it on my phone and it works just fine!

LabyStudio avatar Sep 14 '22 17:09 LabyStudio

Hi @LabyStudio Thank you so much!

Here is the error log

image

Zoom in

image

codingwatching avatar Sep 15 '22 10:09 codingwatching

the code that forwards the websocket looks like this (run with: "npm init -y","npm i ws net" and "node proxy.js")

proxy.js:

//Simple local Websocket server for forwarding to
//minecraft server
import { WebSocketServer } from 'ws';
import * as net from "net";
const wss = new WebSocketServer({ port: 30023 });

wss.on('connection', function connection(ws) {
  ws.on('message', function message(data) {
    let a;
  
    try {
        if(ws.client) {
          ws.client.write(data);
          return;
        }
      
        a = JSON.parse(data);
      
        if(a?.payload?.host && a?.payload?.port ){
          ws.client=new net.Socket();
          ws.client.connect(a?.payload?.port, a?.payload?.host, function() {
          });
          ws.client.on('data', function(data) {
            ws.send(data);
          });
          
          ws.client.on('close', function() {
            ws.client.destroy(); // kill client after server's response
          });
        }
        
    } catch (e) {
        return console.error(e); // error in the above string (in this case, yes)!
    }
  });
});

@kiliansinger How did you get this to work? the client sends json which its not meant to.

@LabyStudio could you please help? i really want to improve this repo a lot I've already improved speeds. Would i be able to get a working Minecraft proxy

CrazyH2 avatar Dec 13 '23 07:12 CrazyH2

the code that forwards the websocket looks like this (run with: "npm init -y","npm i ws net" and "node proxy.js") proxy.js:

//Simple local Websocket server for forwarding to
//minecraft server
import { WebSocketServer } from 'ws';
import * as net from "net";
const wss = new WebSocketServer({ port: 30023 });

wss.on('connection', function connection(ws) {
  ws.on('message', function message(data) {
    let a;
  
    try {
        if(ws.client) {
          ws.client.write(data);
          return;
        }
      
        a = JSON.parse(data);
      
        if(a?.payload?.host && a?.payload?.port ){
          ws.client=new net.Socket();
          ws.client.connect(a?.payload?.port, a?.payload?.host, function() {
          });
          ws.client.on('data', function(data) {
            ws.send(data);
          });
          
          ws.client.on('close', function() {
            ws.client.destroy(); // kill client after server's response
          });
        }
        
    } catch (e) {
        return console.error(e); // error in the above string (in this case, yes)!
    }
  });
});

@kiliansinger How did you get this to work? the client sends json which its not meant to.

@LabyStudio could you please help? i really want to improve this repo a lot I've already improved speeds. Would i be able to get a working Minecraft proxy

I just published my proxy https://github.com/LabyStudio/mc-websocket-proxy

LabyStudio avatar Jan 26 '24 13:01 LabyStudio

@LabyStudio

Thanks so much for the websocket proxy! I have done a lot of improvements so I'll probably push then soon but i just have to replace all the textures

Here my change list:

  • [x] Fix confirm to exit when in world code
  • [x] Add world selection menu
  • [x] Fix chat scroll back which is infinite
  • [x] Should add own main menu panorama
  • [x] Improve loading splash screen
  • [x] Make join server loading text message actually update states
  • [x] Add change username and skin in settings
  • [x] Add Alex skin
  • [x] Fix kick msg, tabbar colors codes
  • [x] Fix chat colours
  • [x] Add full credits in settings
  • [x] Add button to right click so its easier on touchpad

CrazyH2 avatar Jan 27 '24 07:01 CrazyH2