Skip to content

Commit

Permalink
Prepare new proto endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 29, 2024
1 parent 055805d commit fd3d5d9
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.soulfiremc.server.account.AuthType;
import com.soulfiremc.server.account.MinecraftAccount;
import com.soulfiremc.server.settings.PropertyKey;
import com.soulfiremc.server.settings.lib.SettingsImpl;
import com.soulfiremc.server.settings.lib.InstanceSettingsImpl;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -50,7 +50,7 @@ public class ClientSettingsManager {
private final RPCClient rpcClient;
@Setter
private SFCommandDefinition commandDefinition;
private SettingsImpl settingsSource = SettingsImpl.EMPTY;
private InstanceSettingsImpl settingsSource = InstanceSettingsImpl.EMPTY;

public void registerProvider(PropertyKey property, Provider<JsonElement> provider) {
providers
Expand Down
7 changes: 0 additions & 7 deletions proto/src/main/proto/soulfire/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ message ClientDataResponse {
repeated SettingsPage settings = 5;
}

message ServerUpdateConfigRequest {
repeated SettingsNamespace settings = 1;
}

message ServerUpdateConfigResponse {
}

service ConfigService {
rpc getClientData(ClientDataRequest) returns (ClientDataResponse);
}
23 changes: 23 additions & 0 deletions proto/src/main/proto/soulfire/server.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";

option java_package = "com.soulfiremc.grpc.generated";
option java_multiple_files = true;

package soulfire.v1;

import "soulfire/common.proto";

message ServerConfig {
repeated SettingsNamespace settings = 1;
}

message ServerUpdateConfigRequest {
ServerConfig config = 1;
}

message ServerUpdateConfigResponse {
}

service ServerService {
rpc updateServerConfig(ServerUpdateConfigRequest) returns (ServerUpdateConfigResponse);
}
58 changes: 58 additions & 0 deletions proto/src/main/proto/soulfire/user.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "proto3";

option java_package = "com.soulfiremc.grpc.generated";
option java_multiple_files = true;

package soulfire.v1;

import "soulfire/common.proto";

enum UserRole {
ADMIN = 0;
USER = 1;
}

message UserCreateRequest {
string username = 1;
UserRole role = 2;
}

message UserCreateResponse {
string id = 1;
}

message UserDeleteRequest {
string id = 1;
}

message UserDeleteResponse {
}

message UserListRequest {
}

message UserListResponse {
message User {
string id = 1;
string username = 2;
UserRole role = 3;
}

repeated User users = 1;
}

message UserInfoRequest {
string id = 1;
}

message UserInfoResponse {
string username = 1;
UserRole role = 2;
}

service UserService {
rpc createUser(UserCreateRequest) returns (UserCreateResponse);
rpc deleteUser(UserDeleteRequest) returns (UserDeleteResponse);
rpc listUsers(UserListRequest) returns (UserListResponse);
rpc getUserInfo(UserInfoRequest) returns (UserInfoResponse);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.soulfiremc.server.settings.AccountSettings;
import com.soulfiremc.server.settings.BotSettings;
import com.soulfiremc.server.settings.ProxySettings;
import com.soulfiremc.server.settings.lib.SettingsDelegate;
import com.soulfiremc.server.settings.lib.InstanceSettingsDelegate;
import com.soulfiremc.server.util.MathHelper;
import com.soulfiremc.server.util.TimeUtil;
import com.soulfiremc.server.util.structs.CachedLazyObject;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class InstanceManager {
private final UUID id;
private final Logger logger;
private final SoulFireScheduler scheduler;
private final SettingsDelegate settingsSource;
private final InstanceSettingsDelegate settingsSource;
private final SoulFireServer soulFireServer;
private final SessionFactory sessionFactory;
private AttackLifecycle localAttackLifecycle = AttackLifecycle.STOPPED;
Expand All @@ -75,7 +75,7 @@ public InstanceManager(SoulFireServer soulFireServer, SessionFactory sessionFact
this.scheduler = new SoulFireScheduler(logger);
this.soulFireServer = soulFireServer;
this.sessionFactory = sessionFactory;
this.settingsSource = new SettingsDelegate(new CachedLazyObject<>(() ->
this.settingsSource = new InstanceSettingsDelegate(new CachedLazyObject<>(() ->
sessionFactory.fromTransaction(session -> session.find(InstanceEntity.class, id).settings()), 1, TimeUnit.SECONDS));

this.scheduler.scheduleWithFixedDelay(this::tick, 0, 500, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import com.soulfiremc.server.database.UserEntity;
import com.soulfiremc.server.grpc.RPCServer;
import com.soulfiremc.server.settings.*;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.soulfiremc.server.settings.lib.ServerSettingsRegistry;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.spark.SFSparkPlugin;
import com.soulfiremc.server.user.AuthSystem;
import com.soulfiremc.server.user.SoulFireUser;
Expand Down Expand Up @@ -202,12 +202,12 @@ public SoulFireServer(
"Finished loading! (Took {}ms)", Duration.between(startTime, Instant.now()).toMillis());
}

public static void setupLoggingAndVia(SettingsSource settingsSource) {
public static void setupLoggingAndVia(InstanceSettingsSource settingsSource) {
Via.getManager().debugHandler().setEnabled(settingsSource.get(DevSettings.VIA_DEBUG));
setupLogging(settingsSource);
}

public static void setupLogging(SettingsSource settingsSource) {
public static void setupLogging(InstanceSettingsSource settingsSource) {
Configurator.setRootLevel(settingsSource.get(DevSettings.CORE_DEBUG) ? Level.DEBUG : Level.INFO);
Configurator.setLevel("io.netty", settingsSource.get(DevSettings.NETTY_DEBUG) ? Level.DEBUG : Level.INFO);
Configurator.setLevel("io.grpc", settingsSource.get(DevSettings.GRPC_DEBUG) ? Level.DEBUG : Level.INFO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.soulfiremc.server.database;

import com.soulfiremc.server.api.AttackLifecycle;
import com.soulfiremc.server.settings.lib.SettingsImpl;
import com.soulfiremc.server.settings.lib.InstanceSettingsImpl;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -28,9 +28,10 @@
import java.time.Instant;
import java.util.UUID;

@Entity
@Getter
@Setter
@Entity
@Table(name = "instances")
public class InstanceEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
Expand All @@ -49,7 +50,7 @@ public class InstanceEntity {

@Convert(converter = SettingsConverter.class)
@Column(nullable = false)
private SettingsImpl settings = SettingsImpl.EMPTY;
private InstanceSettingsImpl settings = InstanceSettingsImpl.EMPTY;

@CreationTimestamp
@Column(nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
package com.soulfiremc.server.database;

import com.google.gson.JsonElement;
import com.soulfiremc.server.settings.lib.SettingsImpl;
import com.soulfiremc.server.settings.lib.InstanceSettingsImpl;
import com.soulfiremc.server.util.structs.GsonInstance;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class SettingsConverter implements AttributeConverter<SettingsImpl, String> {
public class SettingsConverter implements AttributeConverter<InstanceSettingsImpl, String> {
@Override
public String convertToDatabaseColumn(SettingsImpl attribute) {
public String convertToDatabaseColumn(InstanceSettingsImpl attribute) {
return GsonInstance.GSON.toJson(attribute.serializeToTree());
}

@Override
public SettingsImpl convertToEntityAttribute(String dbData) {
return SettingsImpl.deserialize(GsonInstance.GSON.fromJson(dbData, JsonElement.class));
public InstanceSettingsImpl convertToEntityAttribute(String dbData) {
return InstanceSettingsImpl.deserialize(GsonInstance.GSON.fromJson(dbData, JsonElement.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import java.time.Instant;
import java.util.UUID;

@Entity
@Getter
@Setter
@Entity
@Table(name = "users")
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.soulfiremc.server.SoulFireServer;
import com.soulfiremc.server.api.AttackLifecycle;
import com.soulfiremc.server.database.InstanceEntity;
import com.soulfiremc.server.settings.lib.SettingsImpl;
import com.soulfiremc.server.settings.lib.InstanceSettingsImpl;
import com.soulfiremc.server.user.PermissionContext;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
Expand Down Expand Up @@ -168,7 +168,7 @@ public void updateInstanceConfig(InstanceUpdateConfigRequest request, StreamObse
throw new StatusRuntimeException(Status.NOT_FOUND.withDescription("Instance '%s' not found".formatted(instanceId)));
}

instanceEntity.settings(SettingsImpl.fromProto(request.getConfig()));
instanceEntity.settings(InstanceSettingsImpl.fromProto(request.getConfig()));

session.merge(instanceEntity);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import com.soulfiremc.server.protocol.bot.state.entity.LocalPlayer;
import com.soulfiremc.server.protocol.bot.state.registry.SFChatType;
import com.soulfiremc.server.settings.BotSettings;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.soulfiremc.server.settings.lib.SettingsObject;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.settings.property.*;
import com.soulfiremc.server.user.PermissionContext;
import com.soulfiremc.server.user.ServerCommandSource;
Expand Down Expand Up @@ -172,7 +172,7 @@ private static GameProfile getFakePlayerListEntry(Component text) {
return new GameProfile(UUID.randomUUID(), LegacyComponentSerializer.legacySection().serialize(text));
}

private static void startPOVServer(SettingsSource settingsSource, int port, InstanceManager instanceManager) {
private static void startPOVServer(InstanceSettingsSource settingsSource, int port, InstanceManager instanceManager) {
var faviconBytes = SFHelpers.getResourceAsBytes("assets/pov_favicon.png");
var server = new TcpServer("0.0.0.0", port, MinecraftProtocol::new);

Expand Down Expand Up @@ -803,7 +803,7 @@ public void onAttackEnded(AttackEndedEvent event) {
@RequiredArgsConstructor
private static class POVClientSessionAdapter extends SessionAdapter {
private final InstanceManager instanceManager;
private final SettingsSource settingsSource;
private final InstanceSettingsSource settingsSource;
private BotConnection botConnection;
private boolean enableForwarding;
private double lastX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.soulfiremc.server.protocol.netty.ResolveUtil;
import com.soulfiremc.server.protocol.netty.ViaClientSession;
import com.soulfiremc.server.proxy.SFProxy;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.soulfiremc.server.util.TimeUtil;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.EventLoopGroup;
Expand Down Expand Up @@ -71,7 +71,7 @@ public final class BotConnection {
private final SoulFireScheduler scheduler;
private final BotConnectionFactory factory;
private final InstanceManager instanceManager;
private final SettingsSource settingsSource;
private final InstanceSettingsSource settingsSource;
private final Logger logger;
private final MinecraftProtocol protocol;
private final ViaClientSession session;
Expand All @@ -91,7 +91,7 @@ public final class BotConnection {
public BotConnection(
BotConnectionFactory factory,
InstanceManager instanceManager,
SettingsSource settingsSource,
InstanceSettingsSource settingsSource,
Logger logger,
MinecraftProtocol protocol,
ResolveUtil.ResolvedAddress resolvedAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.soulfiremc.server.protocol.netty.ResolveUtil;
import com.soulfiremc.server.proxy.SFProxy;
import com.soulfiremc.server.settings.BotSettings;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.EventLoopGroup;
import org.geysermc.mcprotocollib.network.BuiltinFlags;
Expand All @@ -35,7 +35,7 @@
public record BotConnectionFactory(
InstanceManager instanceManager,
ResolveUtil.ResolvedAddress resolvedAddress,
SettingsSource settingsSource,
InstanceSettingsSource settingsSource,
Logger logger,
MinecraftAccount minecraftAccount,
ProtocolVersion protocolVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.soulfiremc.server.protocol.bot.state.registry.Biome;
import com.soulfiremc.server.protocol.bot.state.registry.DimensionType;
import com.soulfiremc.server.protocol.bot.state.registry.SFChatType;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.soulfiremc.server.util.EntityMovement;
import com.soulfiremc.server.util.SFHelpers;
import com.soulfiremc.server.util.mcstructs.LevelLoadStatusManager;
Expand Down Expand Up @@ -110,7 +110,7 @@
@Getter
@ToString
public final class SessionDataManager {
private final SettingsSource settingsSource;
private final InstanceSettingsSource settingsSource;
private final Logger log;
private final MinecraftCodecHelper codecHelper;
private final BotConnection connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.soulfiremc.server.protocol.netty;

import com.soulfiremc.server.settings.BotSettings;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.soulfiremc.server.util.structs.ServerAddress;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -53,7 +53,7 @@ public class ResolveUtil {
private ResolveUtil() {}

public static Optional<ResolvedAddress> resolveAddress(
boolean isBedrock, SettingsSource settingsSource) {
boolean isBedrock, InstanceSettingsSource settingsSource) {
var defaultPort = isBedrock ? MC_BEDROCK_DEFAULT_PORT : MC_JAVA_DEFAULT_PORT;
var serverAddress =
ServerAddress.fromStringDefaultPort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.ClientOptions;
import com.soulfiremc.server.settings.lib.InstanceSettingsSource;
import com.soulfiremc.server.settings.lib.SettingsObject;
import com.soulfiremc.server.settings.lib.SettingsSource;
import com.soulfiremc.server.settings.property.ImmutableIntProperty;
import com.soulfiremc.server.settings.property.ImmutableStringProperty;
import com.soulfiremc.server.settings.property.IntProperty;
Expand Down Expand Up @@ -76,7 +76,7 @@ public class AISettings implements SettingsObject {
.stepValue(1)
.build();

public static OpenAIClient create(SettingsSource source) {
public static OpenAIClient create(InstanceSettingsSource source) {
return OpenAIOkHttpClient.builder()
.baseUrl(source.get(AISettings.API_BASE_URL))
.apiKey(source.get(AISettings.API_KEY))
Expand Down
Loading

0 comments on commit fd3d5d9

Please sign in to comment.