Giter VIP home page Giter VIP logo

colab-minecraft's Introduction

colab-minecraft

Google Colab offers a ton of processing power for running Jupyter notebooks. Could this be used to run continuously a Minecraft Server and let players connect to it? Spoiler: Yes it can 😎

March 2021-1 Update

💔 Google implemented captcha to prevent automated access to Google Colab. This results in the minecraft server deploy lasting less tan an hour before they get shutdown because of a failed captcha. Well done Google. Deploying a server still works however.

What is this?

colab-minecraft is a set of javascript and bash scripts that allows you to easily mount a minecraft server in a free Google Colab instance. You will be able to connect just like any other server.

Google Colab Free imposes a maximum runtime of 12 hours. To workaround this, there is included a script that will switch your running server to a new Colab Instance every certain amount of hours.

Why?

Mostly Curiosity. It was a fun experiment and surprising to find that there are no major security barriers from Google.

Fair Warning

Using this script is not against Google TOC, however you are getting close to the limits probably. The usage of this software is under your own responsibility. Don't abuse the great service Google Colab is, otherwise, some wise man once said "this is why we can't have nice things"

Requirements

  • A computer running Unix-Like OS (linux, mac os). This will be used as a forwarding server, since you can't open ports on Colab instance.

  • Ability to open ports. At least be able to open 22, 8888, 25565.

  • OpenSSH server installed with GatewayPorts option enabled.

  • Software:

    • Node >= 14
    • python3
    • netstat

Solution

Pseudocode

You can understand better what this script does with some pseudocode of the process

function deploy:
    Open a webserver and prepare endpoint with payload script
    Scrape google colab and press connect button
    Enter command on Colab to download payload script from webserver
    Wait until google collab executes script and crates ssh reverse connection to us
    Upload minecraft server to colab instance trough ssh tunnel
    Reverse forward port 25565 from colab instance to us
    Start minecraft server on instance
    Enjoy()

function switch:
    if time since last deploy < 11 hours: exit
    server = Download minecraft server from previous instance
    deploy(server)
    Enjoy()

Process Diagram

process-diagram

Sidenote: To make it more clear, the "server running colab-minecraft" and "reverse SSH Forward server" are shown as separate, but you should run colab-minecraft in the same forwarding server.

Source

Inside the src directory you will see two dirs:

  • colab-robot: Node + Puppeteer implementation to automate the allocation of a new colab instance + SSH server Setup + Reverse SSh Connection
  • scripts: Set of Bash Scripts to automate the whole process of deploying a new minecraft server in google colab and renewing it before the 12 hour expiration.

How to Run

Make sure to run this on a server meeting the requirements. Clone this repository and then:

  1. Login to your google account and create a Colab Notebook.

  2. Export your cookies using an extension like this one. Colab-robot will use this cookies to request Colab instances using your account. Save the file in cookies/cookies.json

  3. Generate an ssh key with:

    ssh-keygen -b 4096 -t rsa -f ssh-keys/colab_vps -q -N ""
    

    You can then connect to the allocated colab instance with this key.

  4. Edit the example servers/json/example-server.json with your server info. Make sure to read the Server JSON Format.

  5. Edit the example config/config.json with your forwarding server. Make sure to read the Config JSON Format.

  6. Create a .tar.gz of your minecraft server. Make sure that it has the following structure:

    • mc-server/
      • All your server files (world, properties, etc)
      • start.sh

    The start.sh file should be something like

    #!/bin/bash
    java -Xms8G -Xmx8G -jar server.jar nogui

    Notice the 8G heap? Thats Google blessing you with resources.

    Save this file as servers/tar/example-server.tar.gz

  7. Run the script!

    • For deploying a new server, just run
    ./colab-minecraft.sh deploy example-server
    
    • For switching all your already running servers. Remember this a workaround for the 12 hour limit of colab
    ./colab-minecraft.sh switch
    
  8. Connect to your server! 🔥

    • Minecraft: Using your minecraft client, connect to the server_domain you used in the config file.
    • SSH: Run the command using the info you entered on config/config.json
    ssh vps-user@server_domain -p server_ssh_port -i ./ssh_keys/colab_vps
    tmux a # Opening the server console

    Note: If you need root access, replace vps-user with root Note: If you are accessing Minecraft or SSH from the forwarding server, replace server_domain by localhost

Future Work

  • If a minecraft server works, any software can. Generalize to deploy arbitrary software.
  • Try workarounds for the Captcha
  • Automate the google account cookie recollection
  • Use ssh key instead of user + pass to open reverse ssh tunnels from colab instance to forwarding server.

colab-minecraft's People

Contributors

rafafdz avatar

Stargazers

 avatar Dev Goyal avatar Tom avatar Etherealxx avatar  avatar RyShuey avatar Nicolás Acosta avatar Currydedog111 avatar snwlvl avatar Mich avatar Aman Setia avatar Angelos Bouklis avatar  avatar  avatar NickAc avatar Samuel Zúñiga  avatar vinaykumar🍁 avatar  avatar Ali Haider avatar Jerzy Husakowski avatar  avatar DaBoi avatar Jesús Leganés-Combarro avatar White_cola avatar  avatar Z.E. Sagata avatar Aliaksei avatar Paul Hendricksen avatar Matt avatar Leet avatar Stephane Mabille avatar  avatar Alomex avatar xrkk avatar Legion avatar 0x0nullian avatar Gabriel Faundez avatar Cortés D. Tomás avatar Manuel Muñoz avatar Finn Lancaster avatar Agustin Berguecio avatar

Watchers

 avatar RyShuey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.