Skip to content

Commit

Permalink
Merge pull request #60 from HttpMarco/dev
Browse files Browse the repository at this point in the history
Release of 1.0.8-SNAPSHOT
  • Loading branch information
HttpMarco committed Jun 23, 2024
2 parents 8bc29da + e35f99a commit 7daa667
Show file tree
Hide file tree
Showing 30 changed files with 300 additions and 128 deletions.
14 changes: 2 additions & 12 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@ To install PoloCloud, follow these steps:
java -jar polocloud.jar
```
3. Create a Proxy and Lobby Group using 'group create'
4. Find the 'Lobby.json' file in the 'local/groups' folder and add the 'fallback' property into it
5. Connect to your Server using ip-address:DEFAULT-PROXY-PORT

### Global cluster properties

| id | description | type | default value | implemented |
|-------------------|---------------------------------------------|--------|------------------|-------------|
| prompt | The input prefix of the cloud terminal | Text | '&3cloud &2» &1' | yes |
| server-port-range | The detection range of server ports | Number | 30000 | yes |
| proxy-port-range | The detection range of proxy ports | Number | 25565 | yes |
| maxQueueSize | Maximum value of parallel starting services | Number | -1 | yes |

4. Set lobby as a fallback service with 'group lobby property set fallback true'
5. Connect to your Server using ip-address:DEFAULT-PROXY-PORT

### Cloud group properties
| id | description | type | default value | implemented |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dev.httpmarco.polocloud.api.events.property;

import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.polocloud.api.properties.Property;

public final class GlobalPropertyRemoveEvent implements PropertyEvent{

Expand All @@ -29,5 +30,10 @@ public void read(PacketBuffer buffer) {
public void write(PacketBuffer buffer) {

}

@Override
public Property<?> property() {
return null;
}
//todo: Add changed property
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dev.httpmarco.polocloud.api.events.property;

import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.polocloud.api.properties.Property;

public final class GlobalPropertySetEvent implements PropertyEvent{
@Override
Expand All @@ -28,5 +29,10 @@ public void read(PacketBuffer buffer) {
public void write(PacketBuffer buffer) {

}

@Override
public Property<?> property() {
return null;
}
//todo: Add changed property
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dev.httpmarco.polocloud.api.events.property;

import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.polocloud.api.properties.Property;

public final class GlobalPropertyUpdateEvent implements PropertyEvent{
@Override
Expand All @@ -28,5 +29,10 @@ public void read(PacketBuffer buffer) {
public void write(PacketBuffer buffer) {

}

@Override
public Property<?> property() {
return null;
}
//todo: Add changed property
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package dev.httpmarco.polocloud.api.events.property;

import dev.httpmarco.polocloud.api.events.Event;
import dev.httpmarco.polocloud.api.properties.Property;

public interface PropertyEvent extends Event {
//todo: Add changed property

Property<?> property();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Mirco Lindenau | HttpMarco
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.httpmarco.polocloud.api.events.service;

import dev.httpmarco.osgan.networking.packet.Packet;
import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.polocloud.api.events.property.PropertyEvent;
import dev.httpmarco.polocloud.api.packets.ComponentPacketHelper;
import dev.httpmarco.polocloud.api.properties.Property;
import dev.httpmarco.polocloud.api.services.CloudService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
@AllArgsConstructor
public abstract class AbstractCloudServicePropertyEvent extends Packet implements ServiceEvent, PropertyEvent {

private CloudService cloudService;
private Property<?> property;
private Object value;

@Override
public void read(PacketBuffer packetBuffer) {
this.cloudService = ComponentPacketHelper.readService(packetBuffer);

var propertyData = ComponentPacketHelper.readProperty(packetBuffer);
this.property = propertyData.getKey();
this.value = propertyData.getValue();
}

@Override
public void write(PacketBuffer packetBuffer) {
ComponentPacketHelper.writeService(cloudService, packetBuffer);
ComponentPacketHelper.writeProperty(property, value, packetBuffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@

package dev.httpmarco.polocloud.api.events.service;

import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.polocloud.api.properties.Property;
import dev.httpmarco.polocloud.api.services.CloudService;
import lombok.experimental.Accessors;

@Accessors(fluent = true)
public record CloudServiceRemovePropertyEvent(CloudService cloudService) implements ServiceEvent {

@Override
public void read(PacketBuffer buffer) {
public final class CloudServiceRemovePropertyEvent extends AbstractCloudServicePropertyEvent {

public CloudServiceRemovePropertyEvent(CloudService cloudService, Property<?> property, Object value) {
super(cloudService, property, value);
}

@Override
public void write(PacketBuffer buffer) {

}

//todo: Add changed property
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@

package dev.httpmarco.polocloud.api.events.service;

import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.polocloud.api.properties.Property;
import dev.httpmarco.polocloud.api.services.CloudService;
import lombok.experimental.Accessors;

@Accessors(fluent = true)
public record CloudServiceSetPropertyEvent(CloudService cloudService) implements ServiceEvent {

@Override
public void read(PacketBuffer buffer) {
public final class CloudServiceSetPropertyEvent extends AbstractCloudServicePropertyEvent {

public CloudServiceSetPropertyEvent(CloudService cloudService, Property<?> property, Object value) {
super(cloudService, property, value);
}

@Override
public void write(PacketBuffer buffer) {

}

//todo: Add changed property
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import dev.httpmarco.polocloud.api.properties.PropertiesPool;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.experimental.Accessors;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

@Getter
@Accessors(fluent = true)
@AllArgsConstructor
Expand All @@ -34,7 +38,12 @@ public abstract class CloudGroup {
private int minOnlineService;
private final PropertiesPool<GroupProperties<?>> properties = new PropertiesPool<>();

public abstract int onlineAmount();
@SneakyThrows
public int onlineAmount() {
return this.onlineAmountAsync().get(5, TimeUnit.SECONDS);
}

public abstract CompletableFuture<Integer> onlineAmountAsync();

public void update() {
CloudAPI.instance().groupProvider().update(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package dev.httpmarco.polocloud.api.packets;

import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import dev.httpmarco.osgan.utils.data.Pair;
import dev.httpmarco.polocloud.api.CloudAPI;
import dev.httpmarco.polocloud.api.groups.CloudGroup;
import dev.httpmarco.polocloud.api.player.CloudPlayer;
import dev.httpmarco.polocloud.api.properties.PropertiesPool;
import dev.httpmarco.polocloud.api.properties.Property;
import dev.httpmarco.polocloud.api.services.CloudService;
import dev.httpmarco.polocloud.api.services.ServiceState;

Expand All @@ -37,7 +39,7 @@ public static void writeService(CloudService cloudService, PacketBuffer buffer)
.writeInt(cloudService.memory())
.writeInt(cloudService.maxPlayers());

writeProperty(cloudService.properties(), buffer);
writeProperties(cloudService.properties(), buffer);
}

public static CloudService readService(PacketBuffer buffer) {
Expand All @@ -63,42 +65,48 @@ public static void writeGroup(CloudGroup group, PacketBuffer codecBuffer) {
codecBuffer.writeInt(group.minOnlineService());
codecBuffer.writeInt(group.memory());

writeProperty(group.properties(), codecBuffer);
writeProperties(group.properties(), codecBuffer);
}

private static void writeProperty(PropertiesPool<?> properties, PacketBuffer codecBuffer) {
private static void writeProperties(PropertiesPool<?> properties, PacketBuffer codecBuffer) {
codecBuffer.writeInt(properties.properties().size());
properties.properties().forEach((property, o) -> {
codecBuffer.writeString(property.id());

if (o instanceof Integer intValue) {
codecBuffer.writeInt(intValue);
} else if (o instanceof String stringValue) {
codecBuffer.writeString(stringValue);
} else if (o instanceof Boolean booleanValue) {
codecBuffer.writeBoolean(booleanValue);
}
});
properties.properties().forEach((property, o) -> writeProperty(property, o, codecBuffer));
}

public static void writeProperty(Property<?> property, Object value, PacketBuffer buffer) {
buffer.writeString(property.id());

if (value instanceof Integer intValue) {
buffer.writeInt(intValue);
} else if (value instanceof String stringValue) {
buffer.writeString(stringValue);
} else if (value instanceof Boolean booleanValue) {
buffer.writeBoolean(booleanValue);
}
}

public static Pair<Property<?>, ?> readProperty(PacketBuffer buffer) {
var name = buffer.readString();
var property = PropertiesPool.property(name);

if (property.type().equals(Integer.class) || property.type().equals(int.class)) {
return new Pair<>(property, buffer.readInt());
} else if (property.type().equals(String.class)) {
return new Pair<>(property, buffer.readString());
} else if (property.type().equals(Boolean.class) || property.type().equals(boolean.class)) {
return new Pair<>(property, buffer.readBoolean());
}
return null;
}

public static PropertiesPool<?> readProperties(PacketBuffer buffer) {
var properties = new PropertiesPool<>();
var elementSize = buffer.readInt();

for (int i = 0; i < elementSize; i++) {

var name = buffer.readString();
var property = PropertiesPool.property(name);

if (property.type().equals(Integer.class) || property.type().equals(int.class)) {
properties.putRaw(property, buffer.readInt());
} else if (property.type().equals(String.class)) {
properties.putRaw(property, buffer.readString());
} else if (property.type().equals(Boolean.class) || property.type().equals(boolean.class)) {
properties.putRaw(property, buffer.readBoolean());
}
var property = readProperty(buffer);
properties.putRaw(property.getKey(), property.getValue());
}

return properties;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Mirco Lindenau | HttpMarco
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.httpmarco.polocloud.api.packets.general;

import dev.httpmarco.osgan.networking.packet.Packet;
import dev.httpmarco.osgan.networking.packet.PacketBuffer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
@AllArgsConstructor
public final class OperationDoublePacket extends Packet {

private Double response;

@Override
public void read(PacketBuffer packetBuffer) {
this.response = packetBuffer.readDouble();
}

@Override
public void write(PacketBuffer packetBuffer) {
packetBuffer.writeDouble(this.response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
@AllArgsConstructor
public final class OperationNumberPacket extends Packet {

private Double response;
private int response;

@Override
public void read(PacketBuffer packetBuffer) {
this.response = packetBuffer.readDouble();
this.response = packetBuffer.readInt();
}

@Override
public void write(PacketBuffer packetBuffer) {
packetBuffer.writeDouble(this.response);
packetBuffer.writeInt(this.response);
}
}
Loading

0 comments on commit 7daa667

Please sign in to comment.