Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test multiplayer #2

Open
codingwatching opened this issue Sep 11, 2022 · 5 comments
Open

How to test multiplayer #2

codingwatching opened this issue Sep 11, 2022 · 5 comments

Comments

@codingwatching
Copy link

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!

@LabyStudio
Copy link
Owner

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!

@codingwatching
Copy link
Author

Hi @LabyStudio
Thank you so much!

Here is the error log

image

Zoom in

image

@CrazyH2
Copy link

CrazyH2 commented Dec 13, 2023

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

@LabyStudio
Copy link
Owner

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

@CrazyH2
Copy link

CrazyH2 commented Jan 27, 2024

@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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants