diff --git a/pom.xml b/pom.xml index 90bb7ed..aea6ec8 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,12 @@ org.springframework.boot spring-boot-starter-security + + + org.springframework.boot + spring-boot-configuration-processor + true + diff --git a/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/ArkOneController.java b/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/ArkOneController.java index 8377ea2..dfb3ead 100644 --- a/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/ArkOneController.java +++ b/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/ArkOneController.java @@ -64,6 +64,9 @@ public class ArkOneController implements TcpHandler { case "u_reg": responses.add(userPlugin.RegisterUser(commandInfo)); break; + case "p": + responses.add(userPlugin.Ping()); + break; // Plugin 7 (Galaxy) case "lpv": @@ -92,9 +95,8 @@ public class ArkOneController implements TcpHandler { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(response.getBytes()); outputStream.write((byte)0x00); - byte[] combinedResponse = outputStream.toByteArray(); - connection.send(combinedResponse); + connection.send(outputStream.toByteArray()); System.out.println("[ArkOne] Response: " + response); } catch (IOException e) { diff --git a/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/Plugins/UserPlugin.java b/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/Plugins/UserPlugin.java index 32a7de2..fd62e74 100644 --- a/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/Plugins/UserPlugin.java +++ b/src/main/java/com/icedberries/UBFunkeysServer/ArkOne/Plugins/UserPlugin.java @@ -33,7 +33,7 @@ public class UserPlugin { .username(username) .password(passwordEncoder.encode(password)) .securityQuestion(securityQuestion) - .securityAnswer(securityAnswer) + .securityAnswer(passwordEncoder.encode(securityAnswer)) .build(); // 0 - Successfully registered @@ -70,4 +70,8 @@ public class UserPlugin { return ArkOneParser.RemoveXMLTag(doc); } + + public String Ping() { + return "

"; + } } diff --git a/src/main/java/com/icedberries/UBFunkeysServer/property/FileStorageProperty.java b/src/main/java/com/icedberries/UBFunkeysServer/property/FileStorageProperty.java new file mode 100644 index 0000000..3e02f56 --- /dev/null +++ b/src/main/java/com/icedberries/UBFunkeysServer/property/FileStorageProperty.java @@ -0,0 +1,19 @@ +package com.icedberries.UBFunkeysServer.property; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "file") +public class FileStorageProperty { + + private String profileDirectory; + + public String getProfileDirectory() { + return profileDirectory; + } + + public void setProfileDirectory(String profileDirectory) { + this.profileDirectory = profileDirectory; + } +} diff --git a/src/main/java/com/icedberries/UBFunkeysServer/service/FileService.java b/src/main/java/com/icedberries/UBFunkeysServer/service/FileService.java new file mode 100644 index 0000000..2cc5283 --- /dev/null +++ b/src/main/java/com/icedberries/UBFunkeysServer/service/FileService.java @@ -0,0 +1,11 @@ +package com.icedberries.UBFunkeysServer.service; + +import org.springframework.core.io.Resource; +import org.springframework.web.multipart.MultipartFile; + +public interface FileService { + + void save(MultipartFile file); + + Resource load(String filename); +} diff --git a/src/main/java/com/icedberries/UBFunkeysServer/service/impl/FileServiceImpl.java b/src/main/java/com/icedberries/UBFunkeysServer/service/impl/FileServiceImpl.java new file mode 100644 index 0000000..0f9f9ff --- /dev/null +++ b/src/main/java/com/icedberries/UBFunkeysServer/service/impl/FileServiceImpl.java @@ -0,0 +1,51 @@ +package com.icedberries.UBFunkeysServer.service.impl; + +import com.icedberries.UBFunkeysServer.property.FileStorageProperty; +import com.icedberries.UBFunkeysServer.service.FileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +@Service +public class FileServiceImpl implements FileService { + + private final Path fileStorageLocation; + + @Autowired + public FileServiceImpl(FileStorageProperty fileStorageProperty) throws IOException { + this.fileStorageLocation = Paths.get(fileStorageProperty.getProfileDirectory()).toAbsolutePath().normalize(); + Files.createDirectories(this.fileStorageLocation); + } + + @Override + public void save(MultipartFile file) { + try { + Files.copy(file.getInputStream(), fileStorageLocation.resolve(file.getOriginalFilename())); + } catch(Exception e) { + throw new RuntimeException("Could not store the file. Error: " + e.getMessage()); + } + } + + @Override + public Resource load(String filename) { + try { + Resource resource = new UrlResource(fileStorageLocation.toUri()); + + if (resource.exists() || resource.isReadable()) { + return resource; + } else { + throw new RuntimeException("Could not read the file!"); + } + } catch(MalformedURLException e) { + throw new RuntimeException("Error: " + e.getMessage()); + } + } +}