Compare commits
10 commits
547d314b4d
...
c1069bd9d4
Author | SHA1 | Date | |
---|---|---|---|
c1069bd9d4 | |||
725f3a1b6f | |||
d78e9d23a1 | |||
15e2685040 | |||
76d0b60eb1 | |||
8350b179ee | |||
9ae7532ad2 | |||
1d0eb37077 | |||
1b034282b5 | |||
fe7a430aa4 |
5 changed files with 137 additions and 57 deletions
|
@ -1,9 +1,5 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.5/userguide/building_java_projects.html in the Gradle documentation.
|
||||
*/
|
||||
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
|
@ -12,6 +8,31 @@ plugins {
|
|||
id 'java'
|
||||
}
|
||||
|
||||
project.ext.lwjglVersion = "2.9.3"
|
||||
project.ext.set('nativeLibsDir', "$buildDir/libs/natives")
|
||||
|
||||
|
||||
switch (OperatingSystem.current()) {
|
||||
case OperatingSystem.LINUX:
|
||||
project.ext.lwjglNatives = "natives-linux"
|
||||
def osArch = System.getProperty("os.arch")
|
||||
if (osArch.startsWith("arm") || osArch.startsWith("aarch64")) {
|
||||
project.ext.lwjglNatives += osArch.contains("64") || osArch.startsWith("armv8") ? "-arm64" : "-arm32"
|
||||
} else if (osArch.startsWith("ppc")) {
|
||||
project.ext.lwjglNatives += "-ppc64le"
|
||||
} else if (osArch.startsWith("riscv")) {
|
||||
project.ext.lwjglNatives += "-riscv64"
|
||||
}
|
||||
break
|
||||
case OperatingSystem.MAC_OS:
|
||||
project.ext.lwjglNatives = "natives-macos"
|
||||
break
|
||||
case OperatingSystem.WINDOWS:
|
||||
project.ext.lwjglNatives = "natives-windows"
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
configurations {
|
||||
provided
|
||||
natives
|
||||
|
@ -27,21 +48,26 @@ configurations {
|
|||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
maven {
|
||||
url = "https://maven.zontreck.dev/repository/internal"
|
||||
url = "https://maven.zontreck.com/repository/internal"
|
||||
name = "Aria's Creations Caches"
|
||||
}
|
||||
maven {
|
||||
url = "https://maven.zontreck.dev/repository/zontreck"
|
||||
url = "https://maven.zontreck.com/repository/zontreck"
|
||||
name = "Aria's Creations"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
provided ("net.java.jinput:jinput-platform:2.0.7")
|
||||
provided platform("net.java.jinput:jinput-platform:2.0.7")
|
||||
provided ("net.java.jutils:jutils:1.0.0")
|
||||
provided ("org.lwjgl.lwjgl:lwjgl:2.9.3")
|
||||
provided ("org.lwjgl.lwjgl:lwjgl_util:2.9.3")
|
||||
provided ("org.lwjgl.lwjgl:lwjgl-platform:2.9.3")
|
||||
|
||||
|
||||
provided "org.lwjgl.lwjgl:lwjgl:$lwjglVersion"
|
||||
provided "org.lwjgl.lwjgl:lwjgl_util:$lwjglVersion"
|
||||
provided platform("org.lwjgl.lwjgl:lwjgl-platform:$lwjglVersion-$lwjglNatives")
|
||||
|
||||
|
||||
provided 'org.mcphackers:launchwrapper:1.0'
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
|
@ -53,16 +79,18 @@ java {
|
|||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = 'com.mojang.minecraft.Minecraft'
|
||||
mainClass = 'org.mcphackers.launchwrapper.Launch'
|
||||
}
|
||||
|
||||
jar {
|
||||
duplicatesStrategy = "exclude"
|
||||
manifest {
|
||||
attributes (
|
||||
'Main-Class': application.mainClass,
|
||||
'Multi-Release': 'true',
|
||||
'Class-Path': configurations.provided.files.collect{"lib/${it.name}"}.join(' ')
|
||||
'Multi-Release': 'true'
|
||||
)
|
||||
}from {
|
||||
configurations.provided.collect { it.isDirectory() ? it : zipTree(it)}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +101,7 @@ task copyToLib(type: Copy) {
|
|||
}
|
||||
|
||||
task copyNatives(type: Copy) {
|
||||
into "${buildDir}/libs/natives"
|
||||
into project.nativeLibsDir
|
||||
duplicatesStrategy = "exclude"
|
||||
configurations.provided.asFileTree.each {
|
||||
if(it.isFile())
|
||||
|
@ -86,13 +114,13 @@ task jarjar(type: Jar) {
|
|||
'Main-Class': application.mainClass,
|
||||
'Multi-Release': 'true'
|
||||
)
|
||||
}from {
|
||||
configurations.provided.collect { it.isDirectory() ? it : zipTree(it)}
|
||||
}
|
||||
archiveClassifier = "AIO"
|
||||
duplicatesStrategy = "exclude"
|
||||
from { configurations.provided.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
|
||||
exclude 'META-INF/*'
|
||||
exclude 'META-INF/*'
|
||||
exclude 'META-INF/*'
|
||||
|
||||
with jar
|
||||
|
@ -100,6 +128,11 @@ task jarjar(type: Jar) {
|
|||
with copyNatives
|
||||
}
|
||||
|
||||
|
||||
run {
|
||||
jvmArgs ["-Djava.library.path=${project.nativeLibsDir}",]
|
||||
}
|
||||
|
||||
jar.finalizedBy(jarjar)
|
||||
jar.finalizedBy(copyToLib)
|
||||
jar.finalizedBy(copyNatives)
|
|
@ -35,13 +35,14 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Controllers;
|
||||
|
@ -1153,16 +1154,4 @@ public final class Minecraft implements Runnable {
|
|||
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Minecraft minecraft = new Minecraft((Canvas)null, 800, 600, false);
|
||||
|
||||
// Hack: Add back multiplayer support!
|
||||
String username = args[0];
|
||||
minecraft.user = new User(username, args[1]);
|
||||
minecraft.setServer(args[2], Integer.parseInt(args[3]));
|
||||
|
||||
|
||||
new Thread(minecraft).start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ configurations {
|
|||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
maven {
|
||||
url = "https://maven.zontreck.dev/repository/internal"
|
||||
url = "https://maven.zontreck.com/repository/internal"
|
||||
name = "Aria's Creations Caches"
|
||||
}
|
||||
maven {
|
||||
url = "https://maven.zontreck.dev/repository/zontreck"
|
||||
url = "https://maven.zontreck.com/repository/zontreck"
|
||||
name = "Aria's Creations"
|
||||
}
|
||||
}
|
||||
|
@ -86,8 +86,6 @@ task jarjar(type: Jar) {
|
|||
duplicatesStrategy = "exclude"
|
||||
from { configurations.provided.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
|
||||
exclude 'META-INF/*'
|
||||
exclude 'META-INF/*'
|
||||
exclude 'META-INF/*'
|
||||
|
||||
with jar
|
||||
|
|
|
@ -1,25 +1,49 @@
|
|||
package com.mojang.minecraft.server;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class HeartbeatThread extends Thread {
|
||||
private HttpURLConnection urlConnection;
|
||||
private String url;
|
||||
private String args;
|
||||
|
||||
HeartbeatThread(MinecraftServer var1, HttpURLConnection var2, String var3) {
|
||||
this.urlConnection = var2;
|
||||
this.url = var3;
|
||||
HeartbeatThread(MinecraftServer McServer, HttpURLConnection conn, String args) {
|
||||
this.urlConnection = conn;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
try {
|
||||
// Assuming this.urlConnection is already initialized as HttpURLConnection
|
||||
|
||||
// Connect to the URL
|
||||
this.urlConnection.connect();
|
||||
|
||||
// Write the request body, if needed
|
||||
DataOutputStream var1 = new DataOutputStream(this.urlConnection.getOutputStream());
|
||||
var1.writeBytes(this.url);
|
||||
var1.writeBytes(this.args);
|
||||
var1.flush();
|
||||
var1.close();
|
||||
this.urlConnection.getInputStream();
|
||||
|
||||
// Get the response body
|
||||
InputStream inputStream = this.urlConnection.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder response = new StringBuilder();
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
reader.close();
|
||||
inputStream.close();
|
||||
|
||||
String responseBody = response.toString();
|
||||
|
||||
|
||||
MinecraftServer.logger.info("Heartbeat: ID '" + responseBody + "'");
|
||||
|
||||
return;
|
||||
} catch (Exception var4) {
|
||||
MinecraftServer.logger.warning("Failed to send heartbeat: " + var4);
|
||||
|
|
|
@ -18,12 +18,8 @@ import java.net.URLEncoder;
|
|||
import java.nio.channels.SocketChannel;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -42,6 +38,7 @@ public class MinecraftServer implements Runnable {
|
|||
public String serverName;
|
||||
public String motd;
|
||||
private int port;
|
||||
private String id;
|
||||
private PlayerInstance[] playerInstances;
|
||||
public PlayerList admins = new PlayerList("Admins", new File("admins.txt"), false);
|
||||
public PlayerList banned = new PlayerList("Banned", new File("banned.txt"), false);
|
||||
|
@ -55,11 +52,28 @@ public class MinecraftServer implements Runnable {
|
|||
}
|
||||
|
||||
try {
|
||||
Random rng = new Random();
|
||||
rng.setSeed(Instant.now().getEpochSecond());
|
||||
|
||||
int id = 0;
|
||||
while(id <= 0)
|
||||
{
|
||||
id = rng.nextInt();
|
||||
if(("" + id).length() > 5)
|
||||
id = Integer.parseInt(("" + id).substring(0,5));
|
||||
}
|
||||
this.id = "" + id;
|
||||
|
||||
|
||||
this.serverName = this.properties.getProperty("server-name", "Minecraft Server");
|
||||
this.motd = this.properties.getProperty("motd", "Welcome to my Minecraft Server!");
|
||||
this.port = Integer.parseInt(this.properties.getProperty("port", "25565"));
|
||||
this.maxPlayers = Integer.parseInt(this.properties.getProperty("max-players", "16"));
|
||||
this.isPublic = Boolean.parseBoolean(this.properties.getProperty("public", "true"));
|
||||
|
||||
if(!this.isPublic)
|
||||
this.id = "0";
|
||||
|
||||
if(this.maxPlayers < 1) {
|
||||
this.maxPlayers = 1;
|
||||
}
|
||||
|
@ -155,24 +169,46 @@ public class MinecraftServer implements Runnable {
|
|||
for(; System.nanoTime() - var5 > (long)var1; ++var7) {
|
||||
var5 += (long)var1;
|
||||
this.tickLevel();
|
||||
MinecraftServer var8;
|
||||
MinecraftServer McServer;
|
||||
if(var7 % 1200 == 0) {
|
||||
var8 = this;
|
||||
McServer = this;
|
||||
logger.info("Saving level");
|
||||
logger.info("Load: " + this.playerList.size() + "/" + this.maxPlayers);
|
||||
|
||||
try {
|
||||
new LevelIO(var8);
|
||||
LevelIO.save(var8.level, new FileOutputStream("server_level.dat"));
|
||||
new LevelIO(McServer);
|
||||
LevelIO.save(McServer.level, new FileOutputStream("server_level.dat"));
|
||||
} catch (Exception var11) {
|
||||
logger.severe("Failed to save the level! " + var11);
|
||||
}
|
||||
}
|
||||
|
||||
if(var7 % 600 == 0) {
|
||||
var8 = this;
|
||||
McServer = this;
|
||||
logger.info("Sending heartbeat");
|
||||
logger.info("Reminder: Server is up at port " + var8.port);
|
||||
if(this.id == "0")
|
||||
{
|
||||
logger.info("Server ID : 0");
|
||||
}else {
|
||||
|
||||
try {
|
||||
URL server = new URL("https://api.zontreck.com/crafting/yggdrasil/legacy/heartbeat.php");
|
||||
HttpURLConnection conn = (HttpURLConnection)server.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
String args = "name=" + URLEncoder.encode(McServer.serverName, "UTF-8") + "&users=" + URLEncoder.encode("" + McServer.playerList.size(), "UTF-8") + "&max=" + URLEncoder.encode("" + McServer.maxPlayers, "UTF-8") + "&public=" + URLEncoder.encode("" + McServer.isPublic, "UTF-8") + "&port=" + URLEncoder.encode("" + McServer.port, "UTF-8") + "&id=" + URLEncoder.encode("" + McServer.id, "UTF-8");
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
conn.setRequestProperty("Content-Length", "" + Integer.toString(args.getBytes().length));
|
||||
conn.setRequestProperty("Content-Language", "en-US");
|
||||
conn.setUseCaches(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
(new HeartbeatThread(McServer, conn, args)).start();
|
||||
} catch (Exception var12) {
|
||||
logger.severe("Failed to assemble heartbeat: " + var12);
|
||||
var12.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue