mirror of
https://github.com/Leahnaya/UBFunkeysServer.git
synced 2026-03-29 13:14:48 -05:00
Added FileService and Encrypt SecurityAnswer
This commit is contained in:
parent
1db3d51796
commit
a16f5ada34
6
pom.xml
6
pom.xml
|
|
@ -70,6 +70,12 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 "<p t=\"30\" />";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user