Skip to content

Commit

Permalink
Add email field
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 30, 2024
1 parent ed4cd46 commit b80f0be
Show file tree
Hide file tree
Showing 25 changed files with 534 additions and 510 deletions.
1 change: 1 addition & 0 deletions proto/src/main/proto/soulfire/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ message ClientDataResponse {
string id = 6;
string username = 1;
UserRole role = 7;
string email = 8;
repeated GlobalPermissionState serverPermissions = 2;
repeated ServerPlugin plugins = 3;
repeated SettingsPage settings = 5;
Expand Down
3 changes: 3 additions & 0 deletions proto/src/main/proto/soulfire/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "soulfire/common.proto";
message UserCreateRequest {
string username = 1;
UserRole role = 2;
string email = 3;
}

message UserCreateResponse {
Expand All @@ -31,6 +32,7 @@ message UserListResponse {
string id = 1;
string username = 2;
UserRole role = 3;
string email = 4;
}

repeated User users = 1;
Expand All @@ -43,6 +45,7 @@ message UserInfoRequest {
message UserInfoResponse {
string username = 1;
UserRole role = 2;
string email = 3;
}

service UserService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,45 @@ public static void injectExceptionHandler() {
});
}

public static void injectMixins(@Nullable PluginManager pluginManager) {
var mixinPaths = new HashSet<String>();
Stream.concat(pluginManager == null ? Stream.empty() : pluginManager
.getExtensions(MixinExtension.class)
.stream(),
Stream.of(new SFDefaultMixinExtension()))
.forEach(
mixinExtension -> {
for (var mixinPath : mixinExtension.getMixinPaths()) {
if (mixinPaths.add(mixinPath)) {
log.info("Added mixin \"{}\"", mixinPath);
} else {
log.warn("Mixin path \"{}\" is already added!", mixinPath);
}
}
});

var classLoaders = new ArrayList<ClassLoader>();
classLoaders.add(SoulFireAbstractBootstrap.class.getClassLoader());
if (pluginManager != null) {
pluginManager
.getPlugins()
.forEach(pluginWrapper -> classLoaders.add(pluginWrapper.getPluginClassLoader()));
}

var classProvider = new CustomClassProvider(classLoaders);
var transformerManager = new TransformerManager(classProvider);
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
mixinPaths.forEach(transformerManager::addTransformer);

try {
transformerManager.hookInstrumentation(Agents.getInstrumentation());
log.info("Used Runtime Agent to inject mixins");
} catch (IOException t) {
log.error("Failed to inject mixins", t);
throw new IllegalStateException("Failed to inject mixins", t);
}
}

private void initPlugins(List<ClassLoader> classLoaders) {
try {
Files.createDirectories(pluginsDirectory);
Expand Down Expand Up @@ -168,45 +207,6 @@ public void injectMixinsAndRun(String[] args) {
this.postMixinMain(args);
}

public static void injectMixins(@Nullable PluginManager pluginManager) {
var mixinPaths = new HashSet<String>();
Stream.concat(pluginManager == null ? Stream.empty() : pluginManager
.getExtensions(MixinExtension.class)
.stream(),
Stream.of(new SFDefaultMixinExtension()))
.forEach(
mixinExtension -> {
for (var mixinPath : mixinExtension.getMixinPaths()) {
if (mixinPaths.add(mixinPath)) {
log.info("Added mixin \"{}\"", mixinPath);
} else {
log.warn("Mixin path \"{}\" is already added!", mixinPath);
}
}
});

var classLoaders = new ArrayList<ClassLoader>();
classLoaders.add(SoulFireAbstractBootstrap.class.getClassLoader());
if (pluginManager != null) {
pluginManager
.getPlugins()
.forEach(pluginWrapper -> classLoaders.add(pluginWrapper.getPluginClassLoader()));
}

var classProvider = new CustomClassProvider(classLoaders);
var transformerManager = new TransformerManager(classProvider);
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
mixinPaths.forEach(transformerManager::addTransformer);

try {
transformerManager.hookInstrumentation(Agents.getInstrumentation());
log.info("Used Runtime Agent to inject mixins");
} catch (IOException t) {
log.error("Failed to inject mixins", t);
throw new IllegalStateException("Failed to inject mixins", t);
}
}

protected abstract void postMixinMain(String[] args);

protected abstract Path getBaseDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public UUID createInstance(String friendlyName, SoulFireUser owner) {

public CompletableFuture<?> shutdownInstances() {
return CompletableFuture.allOf(instances.values().stream()
.map(InstanceManager::shutdownHook)
.toArray(CompletableFuture[]::new));
.map(InstanceManager::shutdownHook)
.toArray(CompletableFuture[]::new));
}

public Optional<CompletableFuture<?>> deleteInstance(UUID id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public static DoubleAxisData readAxis(StringReader reader) throws CommandSyntaxE
return new DoubleAxisData(false, reader.readDouble());
}

public record DoubleAxisData(boolean relative, double value) {
}

public static OptionalInt parseEntityId(BotConnection bot, String input) {
var dataManager = bot.dataManager();

Expand All @@ -78,4 +75,7 @@ public static OptionalInt parseEntityId(BotConnection bot, String input) {

return OptionalInt.empty();
}

public record DoubleAxisData(boolean relative, double value) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.function.Function;

public class GsonDataHelper {
private static final Map<String, JsonArray> LOADED_DATA = new HashMap<>();
public static final TypeAdapter<Key> RESOURCE_KEY_ADAPTER =
new TypeAdapter<>() {
@Override
Expand All @@ -47,7 +46,8 @@ public Key read(JsonReader in) throws IOException {
return Key.key(key);
}
};
private static final Function<Map<Class<?>, Object>, Gson> GSON_FACTORY = (typeAdapters) -> {
private static final Map<String, JsonArray> LOADED_DATA = new HashMap<>();
private static final Function<Map<Class<?>, Object>, Gson> GSON_FACTORY = (typeAdapters) -> {
var builder = new GsonBuilder()
.registerTypeAdapter(Key.class, RESOURCE_KEY_ADAPTER)
.registerTypeAdapter(ByteDataComponents.class, ByteDataComponents.SERIALIZER);
Expand Down Expand Up @@ -88,7 +88,7 @@ public static <T> T fromJson(String dataFile, String dataKey, Class<T> clazz,
throw new RuntimeException("Failed to find data key %s in file %s".formatted(dataKey, dataFile));
}

public static Gson createGson(Map<Class<?>, Object> typeAdapters) {
public static Gson createGson(Map<Class<?>, Object> typeAdapters) {
return GSON_FACTORY.apply(typeAdapters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.soulfiremc.server.api.AttackLifecycle;
import com.soulfiremc.server.settings.lib.InstanceSettingsImpl;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
Expand All @@ -33,33 +34,34 @@
@Entity
@Table(name = "instances")
public class InstanceEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@Column(nullable = false, unique = true, length = 32)
private String friendlyName;
@NotBlank(message = "Friendly name cannot be blank")
@Column(nullable = false, unique = true, length = 32)
private String friendlyName;

@ManyToOne
@JoinColumn(nullable = false)
private UserEntity owner;
@ManyToOne
@JoinColumn(nullable = false)
private UserEntity owner;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private AttackLifecycle attackLifecycle = AttackLifecycle.STOPPED;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private AttackLifecycle attackLifecycle = AttackLifecycle.STOPPED;

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

@CreationTimestamp
@Column(nullable = false, updatable = false)
private Instant createdAt;
@CreationTimestamp
@Column(nullable = false, updatable = false)
private Instant createdAt;

@UpdateTimestamp
@Column(nullable = false)
private Instant updatedAt;
@UpdateTimestamp
@Column(nullable = false)
private Instant updatedAt;

@Version
private long version;
@Version
private long version;
}
56 changes: 32 additions & 24 deletions server/src/main/java/com/soulfiremc/server/database/UserEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package com.soulfiremc.server.database;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
Expand All @@ -31,36 +33,42 @@
@Entity
@Table(name = "users")
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@Column(nullable = false, unique = true, length = 32)
private String username;
@NotBlank(message = "Username cannot be blank")
@Column(nullable = false, unique = true, length = 32)
private String username;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Role role;
@NotBlank(message = "Email cannot be blank")
@Email(message = "Invalid email format")
@Column(nullable = false, unique = true)
private String email;

@CreationTimestamp
@Column(nullable = false, updatable = false)
private Instant createdAt;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Role role;

@UpdateTimestamp
@Column(nullable = false)
private Instant updatedAt;
@CreationTimestamp
@Column(nullable = false, updatable = false)
private Instant createdAt;

private Instant lastLoginAt;
@UpdateTimestamp
@Column(nullable = false)
private Instant updatedAt;

@CreationTimestamp
@Column(nullable = false)
private Instant minIssuedAt;
private Instant lastLoginAt;

@Version
private long version;
@CreationTimestamp
@Column(nullable = false)
private Instant minIssuedAt;

public enum Role {
USER,
ADMIN
}
@Version
private long version;

public enum Role {
USER,
ADMIN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void getClientData(
ClientDataResponse.newBuilder()
.setId(currentUSer.getUniqueId().toString())
.setUsername(currentUSer.getUsername())
.setEmail(currentUSer.getEmail())
.setRole(switch (currentUSer.getRole()) {
case ADMIN -> UserRole.ADMIN;
case USER -> UserRole.USER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void createUser(UserCreateRequest request, StreamObserver<UserCreateRespo
sessionFactory.inTransaction(session -> {
var userEntity = new UserEntity();
userEntity.username(request.getUsername());
userEntity.email(request.getEmail());
userEntity.role(switch (request.getRole()) {
case ADMIN -> UserEntity.Role.ADMIN;
case USER -> UserEntity.Role.USER;
Expand Down Expand Up @@ -92,6 +93,7 @@ public void listUsers(UserListRequest request, StreamObserver<UserListResponse>
.addAllUsers(users.stream().map(user -> UserListResponse.User.newBuilder()
.setId(user.id().toString())
.setUsername(user.username())
.setEmail(user.email())
.setRole(switch (user.role()) {
case ADMIN -> UserRole.ADMIN;
case USER -> UserRole.USER;
Expand All @@ -118,6 +120,7 @@ public void getUserInfo(UserInfoRequest request, StreamObserver<UserInfoResponse

responseObserver.onNext(UserInfoResponse.newBuilder()
.setUsername(user.username())
.setEmail(user.email())
.setRole(switch (user.role()) {
case ADMIN -> UserRole.ADMIN;
case USER -> UserRole.USER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public enum BodyPart {
HEAD {
@Override
public SFVec3i offset(SFVec3i position) {
public SFVec3i offset(SFVec3i position) {
return position.add(0, 1, 0);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.soulfiremc.server.pathfinding.SFVec3i;
import lombok.RequiredArgsConstructor;
import org.cloudburstmc.math.vector.Vector3d;

@RequiredArgsConstructor
public enum MovementModifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ public class Level implements LevelHeightAccessor {
private final boolean debug;
private final int seaLevel;
private final LevelData levelData;

private boolean tickDayTime;
protected float oRainLevel;
protected float rainLevel;
protected float oThunderLevel;
protected float thunderLevel;
private boolean tickDayTime;

public Level(
TagsState tagsState,
Expand Down
Loading

0 comments on commit b80f0be

Please sign in to comment.