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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"attachments": {},
|
5 |
+
"cell_type": "markdown",
|
6 |
+
"metadata": {
|
7 |
+
"id": "ZktjRJuZp1h6"
|
8 |
+
},
|
9 |
+
"source": [
|
10 |
+
"\n",
|
11 |
+
"```\n",
|
12 |
+
"███╗ ███╗██╗███╗ ██╗███████╗ ██████╗ ██████╗ ██╗ █████╗ ██████╗ \n",
|
13 |
+
"████╗ ████║██║████╗ ██║██╔════╝██╔════╝██╔═══██╗██║ ██╔══██╗██╔══██╗\n",
|
14 |
+
"██╔████╔██║██║██╔██╗ ██║█████╗ ██║ ██║ ██║██║ ███████║██████╔╝\n",
|
15 |
+
"██║╚██╔╝██║██║██║╚██╗██║██╔══╝ ██║ ██║ ██║██║ ██╔══██║██╔══██╗\n",
|
16 |
+
"██║ ╚═╝ ██║██║██║ ╚████║███████╗╚██████╗╚██████╔╝███████╗██║ ██║██████╔╝\n",
|
17 |
+
"╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═════╝ \n",
|
18 |
+
"```\n",
|
19 |
+
"**Run a Minecraft Server on Google Colab!**\n",
|
20 |
+
"\n",
|
21 |
+
"---\n",
|
22 |
+
"\n",
|
23 |
+
"The script below will run your server. You'll have to create a server first to be able to use it - don't worry, the scripts below will do the majority of the work for you. You might also want to change the default region to your region, check below."
|
24 |
+
]
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"cell_type": "code",
|
28 |
+
"execution_count": null,
|
29 |
+
"metadata": {
|
30 |
+
"id": "lqtMoYg0dUmu"
|
31 |
+
},
|
32 |
+
"outputs": [],
|
33 |
+
"source": [
|
34 |
+
"import os\n",
|
35 |
+
"import re\n",
|
36 |
+
"import json\n",
|
37 |
+
"\n",
|
38 |
+
"# Update the package lists\n",
|
39 |
+
"!sudo apt update &>/dev/null && echo \"apt cache successfully updated\" || echo \"apt cache update failed, you might receive stale packages\"\n",
|
40 |
+
"# Install OpenJDK 17\n",
|
41 |
+
"# !wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -\n",
|
42 |
+
"# !sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ &>/dev/null || echo \"Failed to add repo. Still can be ignored if openjdk17 gets installed.\"\n",
|
43 |
+
"!sudo apt-get install openjdk-17-jre-headless &>/dev/null && echo \"Yay! Openjdk17 has been successfully installed.\" || echo \"Failed to install OpenJdk17.\"\n",
|
44 |
+
"#Perform java version check\n",
|
45 |
+
"java_ver = !java -version 2>&1 | awk -F[\\\"\\.] -v OFS=. 'NR==1{print $2}'\n",
|
46 |
+
"if java_ver[0] == \"17\" :\n",
|
47 |
+
" print(\"Openjdk17 is working correctly, you are good to go.\")\n",
|
48 |
+
"else:\n",
|
49 |
+
" print(\"Openjdk17 doesn't seems to be installed or isn't working, falling back to java\", java_ver[0], \". You might experience reduced performance. Minecraft 1.17 and above might fail to launch.\")\n",
|
50 |
+
"\n",
|
51 |
+
"# Mount Google Drive\n",
|
52 |
+
"from google.colab import drive\n",
|
53 |
+
"drive.mount('/content/drive')\n",
|
54 |
+
"# Change directory to the Minecraft server folder on Google Drive\n",
|
55 |
+
"%cd \"/content/drive/My Drive/Minecraft-server\"\n",
|
56 |
+
"!ls #list the directory contents (to verify that working directory was changed)\n",
|
57 |
+
"\n",
|
58 |
+
"# Import config file.\n",
|
59 |
+
"if os.path.isfile(\"colabconfig.json\"):\n",
|
60 |
+
" colabconfig = json.load(open(\"colabconfig.json\"))\n",
|
61 |
+
"else:\n",
|
62 |
+
" colabconfig = {\"server_type\": \"generic\"} # using default, if config doesn't exists.\n",
|
63 |
+
" json.dump(colabconfig, open(\"colabconfig.json\",'w'))\n",
|
64 |
+
"\n",
|
65 |
+
"# Server jar names.\n",
|
66 |
+
"jar_list = {'paper': 'server.jar', 'fabric': 'fabric-server-launch.jar', 'generic': 'server.jar', 'forge': 'server.jar'}\n",
|
67 |
+
"jar_name = jar_list[colabconfig[\"server_type\"]]\n",
|
68 |
+
"\n",
|
69 |
+
"# Java arguments.\n",
|
70 |
+
"if colabconfig[\"server_type\"] == \"paper\":\n",
|
71 |
+
" server_flags = \"-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true\"\n",
|
72 |
+
"else:\n",
|
73 |
+
" server_flags = \"\" # aiker's flags might negatively impact performance on non-paper servers.\n",
|
74 |
+
"memory_allocation = \"-Xmx6144M -Xms6144M\"\n",
|
75 |
+
"\n",
|
76 |
+
"# Chose the tunnle service you want to use\n",
|
77 |
+
"# Available options: ngrok, argo, playit\n",
|
78 |
+
"tunnel_service = \"argo\"\n",
|
79 |
+
"print(\"Procedding to use\", tunnel_service)\n",
|
80 |
+
" \n",
|
81 |
+
"\n",
|
82 |
+
"if tunnel_service == \"ngrok\":\n",
|
83 |
+
" !pip -q install pyngrok\n",
|
84 |
+
" from pyngrok import conf, ngrok\n",
|
85 |
+
" \n",
|
86 |
+
" # Ask for the ngrok authtoken\n",
|
87 |
+
" print(\"Get your authtoken from https://dashboard.ngrok.com/auth\")\n",
|
88 |
+
" import getpass\n",
|
89 |
+
" authtoken = getpass.getpass() # input your Ngrok auth token everytime you run the cell or simply replace \"getpass.getpass()\" with your token in \"double quotes\"\n",
|
90 |
+
" ! ngrok authtoken $authtoken # login to ngrok\n",
|
91 |
+
"\n",
|
92 |
+
" # Sets default ngrok region\n",
|
93 |
+
" conf.get_default().region = 'us' # Change this to whichever region you want\n",
|
94 |
+
"\n",
|
95 |
+
" # Connect to ngrok\n",
|
96 |
+
" url = ngrok.connect(25565, 'tcp')\n",
|
97 |
+
" print('Your server address is ' + ((str(url).split('\"')[1::2])[0]).replace('tcp://', ''))\n",
|
98 |
+
"\n",
|
99 |
+
" print('Starting server...')\n",
|
100 |
+
" !java $memory_allocation $server_flags -jar $jar_name nogui\n",
|
101 |
+
"\n",
|
102 |
+
"elif tunnel_service == \"playit\":\n",
|
103 |
+
" ! curl -SsL https://playit-cloud.github.io/ppa/key.gpg | sudo apt-key add -\n",
|
104 |
+
" ! sudo curl -SsL -o /etc/apt/sources.list.d/playit-cloud.list https://playit-cloud.github.io/ppa/playit-cloud.list\n",
|
105 |
+
" ! sudo apt update &>/dev/null && sudo apt install playit &>/dev/null && echo \"Playit.gg installed\" || echo \"Failed to install playit\"\n",
|
106 |
+
" print('Starting server...')\n",
|
107 |
+
" ! playit & java $memory_allocation $server_flags -jar $jar_name nogui\n",
|
108 |
+
"\n",
|
109 |
+
"else:\n",
|
110 |
+
" # Download & make argo executable\n",
|
111 |
+
" !wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64\n",
|
112 |
+
" !chmod +x cloudflared-linux-amd64\n",
|
113 |
+
" print('Starting server...')\n",
|
114 |
+
" !./cloudflared-linux-amd64 tunnel --url tcp://127.0.0.1:25565 & java $memory_allocation $server_flags -jar $jar_name nogui\n"
|
115 |
+
]
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"attachments": {},
|
119 |
+
"cell_type": "markdown",
|
120 |
+
"metadata": {
|
121 |
+
"id": "_4IowSDVUZp8"
|
122 |
+
},
|
123 |
+
"source": [
|
124 |
+
"# Make-a-Server\n",
|
125 |
+
"\n",
|
126 |
+
"The code below will download a server for you and accept the EULA. After running these scripts, your server will be ready to run."
|
127 |
+
]
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"attachments": {},
|
131 |
+
"cell_type": "markdown",
|
132 |
+
"metadata": {
|
133 |
+
"id": "7wrNfinQOlWV"
|
134 |
+
},
|
135 |
+
"source": [
|
136 |
+
"**Download the Minecraft server**\n",
|
137 |
+
"\n",
|
138 |
+
"The code below will download Paper, a high-performance fork of the Vanilla server.\n",
|
139 |
+
"Other server platforms can be used by placing the server.jar in the Drive folder manually."
|
140 |
+
]
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"cell_type": "code",
|
144 |
+
"execution_count": null,
|
145 |
+
"metadata": {
|
146 |
+
"id": "Fy5-YjJMPV3S"
|
147 |
+
},
|
148 |
+
"outputs": [],
|
149 |
+
"source": [
|
150 |
+
"# Replace \"1.19.2\" with your desired server version.\n",
|
151 |
+
"# Available versions:\n",
|
152 |
+
"# - 1.19.2\n",
|
153 |
+
"# - 1.19.1\n",
|
154 |
+
"# - 1.19\n",
|
155 |
+
"# - 1.18.2\n",
|
156 |
+
"# - 1.18.1\n",
|
157 |
+
"# - 1.18\n",
|
158 |
+
"# - 1.17.1\n",
|
159 |
+
"# - 1.17\n",
|
160 |
+
"# - 1.16.4\n",
|
161 |
+
"# - 1.16.3\n",
|
162 |
+
"# - 1.15.2\n",
|
163 |
+
"# - 1.14.4\n",
|
164 |
+
"# - 1.13.2\n",
|
165 |
+
"# - 1.12.2\n",
|
166 |
+
"# - 1.11.2\n",
|
167 |
+
"# - 1.10.2\n",
|
168 |
+
"# - 1.9.4\n",
|
169 |
+
"# - 1.8.8\n",
|
170 |
+
"# Newer versions might work too, however this isn't guaranteed.\n",
|
171 |
+
"version = '1.19.2'\n",
|
172 |
+
"forge_version = \"43.2.8\" # If you are going to use forge \n",
|
173 |
+
"\n",
|
174 |
+
"#Chose server type. Currently available versions: fabric, paper, forge\n",
|
175 |
+
"server_type = 'paper'\n",
|
176 |
+
"\n",
|
177 |
+
"from google.colab import drive\n",
|
178 |
+
"import requests\n",
|
179 |
+
"import json\n",
|
180 |
+
"\n",
|
181 |
+
"\n",
|
182 |
+
"drive.mount('/content/drive')\n",
|
183 |
+
"\n",
|
184 |
+
"! mkdir \"/content/drive/My Drive/Minecraft-server\"\n",
|
185 |
+
"%cd \"/content/drive/My Drive/Minecraft-server\"\n",
|
186 |
+
"\n",
|
187 |
+
"if server_type == \"paper\":\n",
|
188 |
+
" a = requests.get(\"https://papermc.io/api/v2/projects/paper/versions/\" + version)\n",
|
189 |
+
" b = requests.get(\"https://papermc.io/api/v2/projects/paper/versions/\" + version + \"/builds/\" + str(a.json()[\"builds\"][-1]))\n",
|
190 |
+
" print(\"https://papermc.io/api/v2/projects/paper/versions/\" + version + \"/builds/\" + str(a.json()[\"builds\"][-1]) + \"/downloads/\" + b.json()[\"downloads\"][\"application\"][\"name\"])\n",
|
191 |
+
"\n",
|
192 |
+
" url = \"https://papermc.io/api/v2/projects/paper/versions/\" + version + \"/builds/\" + str(a.json()[\"builds\"][-1]) + \"/downloads/\" + b.json()[\"downloads\"][\"application\"][\"name\"]\n",
|
193 |
+
"\n",
|
194 |
+
" jar_name = \"server.jar\"\n",
|
195 |
+
"print('Downloading to Google Drive...')\n",
|
196 |
+
"elif server_type == \"fabric\":\n",
|
197 |
+
" url = \"https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.7.4/fabric-installer-0.7.4.jar\"\n",
|
198 |
+
" jar_name = \"fabric-installer.jar\"\n",
|
199 |
+
"elif server_type == \"forge\":\n",
|
200 |
+
" url = f\"https://maven.minecraftforge.net/net/minecraftforge/forge/{version}-{forge_version}/forge-{version}-{forge_version}-installer.jar\"\n",
|
201 |
+
" jar_name = \"server.jar\"\n",
|
202 |
+
"\n",
|
203 |
+
"\n",
|
204 |
+
"r = requests.get(url)\n",
|
205 |
+
"\n",
|
206 |
+
"if r.status_code is 200:\n",
|
207 |
+
" with open('/content/drive/My Drive/Minecraft-server/' + jar_name, 'wb') as f:\n",
|
208 |
+
" f.write(r.content)\n",
|
209 |
+
"else:\n",
|
210 |
+
" print('Error '+ str(r.status_code) + '! Most likely you entered a unsupported version. Try running the code again if you think that shouldn\\'t have happened.')\n",
|
211 |
+
"\n",
|
212 |
+
"# Running specific install path.\n",
|
213 |
+
"if server_type == \"fabric\":\n",
|
214 |
+
" !java -jar fabric-installer.jar server -mcversion $version -downloadMinecraft\n",
|
215 |
+
"elif server_type == \"forge\":\n",
|
216 |
+
" !java -jar server.jar --installServer\n",
|
217 |
+
"\n",
|
218 |
+
"colabconfig = {\"server_type\": server_type}\n",
|
219 |
+
"json.dump(colabconfig, open(\"colabconfig.json\",'w'))\n",
|
220 |
+
"\n",
|
221 |
+
"print('Done!')\n"
|
222 |
+
]
|
223 |
+
},
|
224 |
+
{
|
225 |
+
"attachments": {},
|
226 |
+
"cell_type": "markdown",
|
227 |
+
"metadata": {
|
228 |
+
"id": "vhHYrg6FlbcQ"
|
229 |
+
},
|
230 |
+
"source": [
|
231 |
+
"**Automatically accept the EULA**"
|
232 |
+
]
|
233 |
+
},
|
234 |
+
{
|
235 |
+
"cell_type": "code",
|
236 |
+
"execution_count": null,
|
237 |
+
"metadata": {
|
238 |
+
"id": "aefCB6cFlle8"
|
239 |
+
},
|
240 |
+
"outputs": [],
|
241 |
+
"source": [
|
242 |
+
"# Please read the file stored in your server folder before running this command. \n",
|
243 |
+
"# Also, go to https://www.minecraft.net/en-us/eula to read Minecraft's EULA.\n",
|
244 |
+
"\n",
|
245 |
+
"# Make sure Drive is mounted\n",
|
246 |
+
"from google.colab import drive\n",
|
247 |
+
"drive.mount('/content/drive')\n",
|
248 |
+
"\n",
|
249 |
+
"%cd \"/content/drive/My Drive/Minecraft-server\"\n",
|
250 |
+
"!echo \"eula=true\" >> eula.txt"
|
251 |
+
]
|
252 |
+
},
|
253 |
+
{
|
254 |
+
"attachments": {},
|
255 |
+
"cell_type": "markdown",
|
256 |
+
"metadata": {
|
257 |
+
"id": "FO5S4OHVdV5O"
|
258 |
+
},
|
259 |
+
"source": [
|
260 |
+
"# Debug\n",
|
261 |
+
"SSH access to host OS - Thanks to [colab-ssh](https://github.com/WassimBenzarti/colab-ssh).\n",
|
262 |
+
"\n",
|
263 |
+
"<p style=\"color:red;\">YOU MIGHT GET BANNED</p>"
|
264 |
+
]
|
265 |
+
},
|
266 |
+
{
|
267 |
+
"cell_type": "code",
|
268 |
+
"execution_count": null,
|
269 |
+
"metadata": {
|
270 |
+
"id": "cM7gKp6Yi8Q2"
|
271 |
+
},
|
272 |
+
"outputs": [],
|
273 |
+
"source": [
|
274 |
+
"#@title Colab-ssh tunnel\n",
|
275 |
+
"#@markdown Execute this cell to open the ssh tunnel. Check [colab-ssh documentation](https://github.com/WassimBenzarti/colab-ssh) for more details.\n",
|
276 |
+
"\n",
|
277 |
+
"# Install colab_ssh on google colab\n",
|
278 |
+
"!pip install colab_ssh --upgrade\n",
|
279 |
+
"\n",
|
280 |
+
"from colab_ssh import launch_ssh_cloudflared, init_git_cloudflared\n",
|
281 |
+
"ssh_tunnel_password = \"<PUT_YOUR_PASSWORD_HERE>\" #@param {type: \"string\"}\n",
|
282 |
+
"launch_ssh_cloudflared(password=ssh_tunnel_password)"
|
283 |
+
]
|
284 |
+
},
|
285 |
+
{
|
286 |
+
"cell_type": "code",
|
287 |
+
"execution_count": null,
|
288 |
+
"metadata": {
|
289 |
+
"id": "7kR6rsn7jyxt"
|
290 |
+
},
|
291 |
+
"outputs": [],
|
292 |
+
"source": [
|
293 |
+
"#Get public address (ngrok)\n",
|
294 |
+
"! curl -s http://localhost:4040/api/tunnels | python3 -c \\\n",
|
295 |
+
" \"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])\""
|
296 |
+
]
|
297 |
+
},
|
298 |
+
{
|
299 |
+
"cell_type": "code",
|
300 |
+
"execution_count": null,
|
301 |
+
"metadata": {
|
302 |
+
"id": "Z2rztsCQk0kh"
|
303 |
+
},
|
304 |
+
"outputs": [],
|
305 |
+
"source": [
|
306 |
+
"## For inspecting the minecraft server directory ##\n",
|
307 |
+
"%cd \"/content/drive/My Drive/Minecraft-server\"\n",
|
308 |
+
"!ls\n"
|
309 |
+
]
|
310 |
+
}
|
311 |
+
],
|
312 |
+
"metadata": {
|
313 |
+
"colab": {
|
314 |
+
"collapsed_sections": [],
|
315 |
+
"name": "MineColab",
|
316 |
+
"provenance": []
|
317 |
+
},
|
318 |
+
"kernelspec": {
|
319 |
+
"display_name": "Python 3 (ipykernel)",
|
320 |
+
"language": "python",
|
321 |
+
"name": "python3"
|
322 |
+
},
|
323 |
+
"language_info": {
|
324 |
+
"codemirror_mode": {
|
325 |
+
"name": "ipython",
|
326 |
+
"version": 3
|
327 |
+
},
|
328 |
+
"file_extension": ".py",
|
329 |
+
"mimetype": "text/x-python",
|
330 |
+
"name": "python",
|
331 |
+
"nbconvert_exporter": "python",
|
332 |
+
"pygments_lexer": "ipython3",
|
333 |
+
"version": "3.10.4"
|
334 |
+
}
|
335 |
+
},
|
336 |
+
"nbformat": 4,
|
337 |
+
"nbformat_minor": 0
|
338 |
+
}
|