Iris Syndicate

This commit is contained in:
Daniel Mills 2021-07-20 11:18:35 -04:00
parent 4d965333ef
commit 9833d466c4
15 changed files with 125 additions and 114 deletions

View File

@ -23,27 +23,20 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.pregenerator.PregenListener;
import com.volmit.iris.core.pregenerator.PregenTask;
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
import com.volmit.iris.core.pregenerator.turbo.TurboClient;
import com.volmit.iris.core.pregenerator.turbo.command.*;
import com.volmit.iris.engine.data.mca.NBTWorld;
import com.volmit.iris.engine.headless.HeadlessGenerator;
import com.volmit.iris.engine.headless.HeadlessWorld;
import com.volmit.iris.core.pregenerator.syndicate.SyndicateClient;
import com.volmit.iris.core.pregenerator.syndicate.command.*;
import com.volmit.iris.engine.object.IrisDimension;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.scheduling.J;
import lombok.Getter;
import org.zeroturnaround.zip.ZipUtil;
import javax.management.RuntimeErrorException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
public class SlavePregenMethod implements PregeneratorMethod
public class SyndicatePregenMethod implements PregeneratorMethod
{
@Getter
private String address;
@ -56,7 +49,7 @@ public class SlavePregenMethod implements PregeneratorMethod
private UUID pack = UUID.randomUUID();
private long seed;
public SlavePregenMethod(String nickname, File worldFolder, String address, int port, String password, IrisDimension dimension, long seed)
public SyndicatePregenMethod(String nickname, File worldFolder, String address, int port, String password, IrisDimension dimension, long seed)
{
this.seed = seed;
this.worldFolder = worldFolder;
@ -66,9 +59,9 @@ public class SlavePregenMethod implements PregeneratorMethod
this.dimension = dimension;
}
private TurboClient.TurboClientBuilder connect()
private SyndicateClient.SyndicateClientBuilder connect()
{
return TurboClient.builder().address(address).port(port);
return SyndicateClient.builder().address(address).port(port);
}
public synchronized void setup()
@ -80,7 +73,7 @@ public class SlavePregenMethod implements PregeneratorMethod
ready = false;
try {
connect().command(TurboInstallPack
connect().command(SyndicateInstallPack
.builder()
.dimension(dimension)
.pack(pack)
@ -99,7 +92,7 @@ public class SlavePregenMethod implements PregeneratorMethod
to.deleteOnExit();
})
.build().go((response, data) -> {
if(response instanceof TurboBusy)
if(response instanceof SyndicateBusy)
{
throw new RuntimeException("Service is busy, will try later");
}
@ -139,7 +132,7 @@ public class SlavePregenMethod implements PregeneratorMethod
{
try {
connect()
.command(TurboClose
.command(SyndicateClose
.builder()
.pack(pack)
.build())
@ -163,7 +156,7 @@ public class SlavePregenMethod implements PregeneratorMethod
@Override
public String getMethod(int x, int z) {
return "Remote<" + nickname + ">";
return "Syndicate<" + nickname + ">";
}
private double checkProgress(int x, int z)
@ -171,14 +164,14 @@ public class SlavePregenMethod implements PregeneratorMethod
AtomicDouble progress = new AtomicDouble(-1);
try {
connect()
.command(TurboGetProgress.builder()
.command(SyndicateGetProgress.builder()
.pack(pack).build()).output((i) -> {
}).build().go((response, o) -> {
if(response instanceof TurboSendProgress)
if(response instanceof SyndicateSendProgress)
{
if(((TurboSendProgress) response).isAvailable())
if(((SyndicateSendProgress) response).isAvailable())
{
progress.set(((TurboSendProgress) response).getProgress());
progress.set(((SyndicateSendProgress) response).getProgress());
File f = new File(worldFolder, "region/r." + x + "." + z + ".mca");
try {
f.getParentFile().mkdirs();
@ -205,12 +198,12 @@ public class SlavePregenMethod implements PregeneratorMethod
}
try {
connect().command(TurboGenerate
connect().command(SyndicateGenerate
.builder()
.x(x).z(z).pack(pack)
.build())
.build().go((response, data) -> {
if(response instanceof TurboOK)
if(response instanceof SyndicateOK)
{
listener.onNetworkStarted(x, z);
J.a(() -> {
@ -267,13 +260,13 @@ public class SlavePregenMethod implements PregeneratorMethod
});
}
else if(response instanceof TurboInstallFirst)
else if(response instanceof SyndicateInstallFirst)
{
ready = false;
throw new RuntimeException();
}
else if(response instanceof TurboBusy)
else if(response instanceof SyndicateBusy)
{
throw new RuntimeException();
}

View File

@ -16,33 +16,29 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo;
package com.volmit.iris.core.pregenerator.syndicate;
import com.volmit.iris.core.pregenerator.turbo.command.TurboCommand;
import com.volmit.iris.util.collection.GBiset;
import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateCommand;
import com.volmit.iris.util.function.Consumer2;
import com.volmit.iris.util.scheduling.J;
import lombok.Builder;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.function.Consumer;
import java.util.function.Supplier;
@Builder
public class TurboClient {
public class SyndicateClient {
private String address;
private int port;
private TurboCommand command;
private SyndicateCommand command;
private Consumer<DataOutputStream> output;
public void go(Consumer2<TurboCommand, DataInputStream> handler) throws Throwable {
public void go(Consumer2<SyndicateCommand, DataInputStream> handler) throws Throwable {
Socket socket = new Socket(address, port);
DataInputStream i = new DataInputStream(socket.getInputStream());
DataOutputStream o = new DataOutputStream(socket.getOutputStream());
TurboCommander.write(command, o);
SyndicateCommandIO.write(command, o);
if(output != null)
{
@ -50,7 +46,7 @@ public class TurboClient {
}
o.flush();
handler.accept(TurboCommander.read(i), i);
handler.accept(SyndicateCommandIO.read(i), i);
socket.close();
}
}

View File

@ -16,24 +16,24 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo;
package com.volmit.iris.core.pregenerator.syndicate;
import com.google.gson.Gson;
import com.volmit.iris.core.pregenerator.turbo.command.TurboCommand;
import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateCommand;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class TurboCommander {
public class SyndicateCommandIO {
private static final Gson gson = new Gson();
public static TurboCommand read(DataInputStream in) throws IOException, ClassNotFoundException {
public static SyndicateCommand read(DataInputStream in) throws IOException, ClassNotFoundException {
String clazz = in.readUTF();
return (TurboCommand) gson.fromJson(in.readUTF(), Class.forName(clazz));
return (SyndicateCommand) gson.fromJson(in.readUTF(), Class.forName(clazz));
}
public static void write(TurboCommand c, DataOutputStream out) throws IOException {
public static void write(SyndicateCommand c, DataOutputStream out) throws IOException {
out.writeUTF(c.getClass().getCanonicalName());
out.writeUTF(gson.toJson(c));
}

View File

@ -16,16 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo;
package com.volmit.iris.core.pregenerator.syndicate;
import com.volmit.iris.core.pregenerator.PregenListener;
import com.volmit.iris.core.pregenerator.turbo.command.*;
import com.volmit.iris.core.pregenerator.syndicate.command.*;
import com.volmit.iris.engine.headless.HeadlessGenerator;
import com.volmit.iris.engine.headless.HeadlessWorld;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.scheduling.J;
import org.apache.logging.log4j.core.tools.Generate;
import org.zeroturnaround.zip.ZTFileUtil;
import org.zeroturnaround.zip.ZipUtil;
import java.io.*;
@ -36,7 +34,7 @@ import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class TurboServer extends Thread implements PregenListener {
public class SyndicateServer extends Thread implements PregenListener {
private int port;
private String password;
private boolean busy;
@ -48,7 +46,7 @@ public class TurboServer extends Thread implements PregenListener {
private AtomicInteger g = new AtomicInteger(0);
private File lastGeneratedRegion = null;
public TurboServer(File cache, int port, String password, int tc) throws IOException {
public SyndicateServer(File cache, int port, String password, int tc) throws IOException {
this.port = port;
this.cache = cache;
this.password = password;
@ -83,11 +81,11 @@ public class TurboServer extends Thread implements PregenListener {
private void handle(Socket client, DataInputStream i, DataOutputStream o) throws Throwable
{
TurboCommand cmd = handle(TurboCommander.read(i), i, o);
SyndicateCommand cmd = handle(SyndicateCommandIO.read(i), i, o);
if(cmd != null)
{
TurboCommander.write(cmd, o);
SyndicateCommandIO.write(cmd, o);
}
o.flush();
@ -98,12 +96,12 @@ public class TurboServer extends Thread implements PregenListener {
return new File(cache, id.toString().charAt(2) +"/" + id.toString().substring(0, 4)+ "/" + id);
}
private TurboCommand handle(TurboCommand command, DataInputStream i, DataOutputStream o) throws Throwable {
if(command instanceof TurboInstallPack)
private SyndicateCommand handle(SyndicateCommand command, DataInputStream i, DataOutputStream o) throws Throwable {
if(command instanceof SyndicateInstallPack)
{
if(busy)
{
return new TurboBusy();
return new SyndicateBusy();
}
if(generator != null)
@ -113,7 +111,7 @@ public class TurboServer extends Thread implements PregenListener {
generator = null;
}
UUID id = ((TurboInstallPack) command).getPack();
UUID id = ((SyndicateInstallPack) command).getPack();
File cacheload = new File(cache, id.toString().charAt(2) +"/" + id.toString().substring(0, 4)+ "/" + id + ".zip");
File cachestore = getCachedDim(id);
IO.delete(cachestore);
@ -125,35 +123,35 @@ public class TurboServer extends Thread implements PregenListener {
fos.close();
ZipUtil.unpack(cacheload, cachestore);
cacheload.deleteOnExit();
HeadlessWorld w = new HeadlessWorld("turbo/" + id.toString(), ((TurboInstallPack) command).getDimension(), ((TurboInstallPack) command).getSeed());
HeadlessWorld w = new HeadlessWorld("turbo/" + id.toString(), ((SyndicateInstallPack) command).getDimension(), ((SyndicateInstallPack) command).getSeed());
w.setStudio(true);
generator = w.generate();
return new TurboOK();
return new SyndicateOK();
}
if(command instanceof TurboGenerate)
if(command instanceof SyndicateGenerate)
{
if(busy)
{
return new TurboBusy();
return new SyndicateBusy();
}
if(generator == null || !Objects.equals(currentId, ((TurboGenerate) command).getPack())) {
return new TurboInstallFirst();
if(generator == null || !Objects.equals(currentId, ((SyndicateGenerate) command).getPack())) {
return new SyndicateInstallFirst();
}
g.set(0);
busy = true;
J.a(() -> {
busy = false;
lastGeneratedRegion = generator.generateRegionToFile(((TurboGenerate) command).getX(), ((TurboGenerate) command).getZ(), this);
lastGeneratedRegion = generator.generateRegionToFile(((SyndicateGenerate) command).getX(), ((SyndicateGenerate) command).getZ(), this);
});
return new TurboOK();
return new SyndicateOK();
}
if(command instanceof TurboClose)
if(command instanceof SyndicateClose)
{
if(generator != null && Objects.equals(currentId, ((TurboClose) command).getPack()) && !busy)
if(generator != null && Objects.equals(currentId, ((SyndicateClose) command).getPack()) && !busy)
{
generator.close();
IO.delete(generator.getWorld().getWorld().worldFolder());
@ -162,16 +160,16 @@ public class TurboServer extends Thread implements PregenListener {
}
}
if(command instanceof TurboGetProgress)
if(command instanceof SyndicateGetProgress)
{
if(generator != null && busy && Objects.equals(currentId, ((TurboGetProgress) command).getPack()))
if(generator != null && busy && Objects.equals(currentId, ((SyndicateGetProgress) command).getPack()))
{
return TurboSendProgress.builder().progress((double)g.get() / 1024D).build();
return SyndicateSendProgress.builder().progress((double)g.get() / 1024D).build();
}
else if(generator != null && !busy && Objects.equals(currentId, ((TurboGetProgress) command).getPack()) && lastGeneratedRegion != null && lastGeneratedRegion.exists())
else if(generator != null && !busy && Objects.equals(currentId, ((SyndicateGetProgress) command).getPack()) && lastGeneratedRegion != null && lastGeneratedRegion.exists())
{
TurboCommander.write(TurboSendProgress
SyndicateCommandIO.write(SyndicateSendProgress
.builder()
.progress(1).available(true)
.build(), o);
@ -182,12 +180,12 @@ public class TurboServer extends Thread implements PregenListener {
else if(generator == null)
{
return new TurboInstallFirst();
return new SyndicateInstallFirst();
}
else
{
return new TurboBusy();
return new SyndicateBusy();
}
}
@ -230,6 +228,31 @@ public class TurboServer extends Thread implements PregenListener {
}
@Override
public void onNetworkStarted(int x, int z) {
}
@Override
public void onNetworkFailed(int x, int z) {
}
@Override
public void onNetworkReclaim(int revert) {
}
@Override
public void onNetworkGeneratedChunk(int x, int z) {
}
@Override
public void onNetworkDownloaded(int x, int z) {
}
@Override
public void onClose() {

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
public class TurboInstallFirst implements TurboCommand {
public class SyndicateBusy implements SyndicateCommand {
}

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -25,11 +25,11 @@ import lombok.NoArgsConstructor;
import java.util.UUID;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TurboGetProgress implements TurboCommand {
@Data
public class SyndicateClose implements SyndicateCommand {
@Builder.Default
private UUID pack = UUID.randomUUID();
}

View File

@ -16,9 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
public interface TurboCommand
public interface SyndicateCommand
{
}

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
public class TurboError implements TurboCommand {
public class SyndicateError implements SyndicateCommand {
}

View File

@ -16,9 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
import com.volmit.iris.engine.object.IrisDimension;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -30,7 +29,7 @@ import java.util.UUID;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class TurboGenerate implements TurboCommand {
public class SyndicateGenerate implements SyndicateCommand {
@Builder.Default
private int x = 0;
@Builder.Default

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -25,11 +25,11 @@ import lombok.NoArgsConstructor;
import java.util.UUID;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class TurboClose implements TurboCommand {
public class SyndicateGetProgress implements SyndicateCommand {
@Builder.Default
private UUID pack = UUID.randomUUID();
}

View File

@ -0,0 +1,22 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.syndicate.command;
public class SyndicateInstallFirst implements SyndicateCommand {
}

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
import com.volmit.iris.engine.object.IrisDimension;
import lombok.AllArgsConstructor;
@ -30,7 +30,7 @@ import java.util.UUID;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class TurboInstallPack implements TurboCommand {
public class SyndicateInstallPack implements SyndicateCommand {
@Builder.Default
private UUID pack = UUID.randomUUID();

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
public class TurboBusy implements TurboCommand {
public class SyndicateOK implements SyndicateCommand {
}

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
package com.volmit.iris.core.pregenerator.syndicate.command;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -27,7 +27,7 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TurboSendProgress implements TurboCommand {
public class SyndicateSendProgress implements SyndicateCommand {
@Builder.Default
private double progress = 0;
@Builder.Default

View File

@ -1,22 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.core.pregenerator.turbo.command;
public class TurboOK implements TurboCommand {
}