mirror of
https://github.com/Leahnaya/UBFunkeysServer.git
synced 2026-04-26 00:27:23 -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>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ public class ArkOneController implements TcpHandler {
|
||||||
case "u_reg":
|
case "u_reg":
|
||||||
responses.add(userPlugin.RegisterUser(commandInfo));
|
responses.add(userPlugin.RegisterUser(commandInfo));
|
||||||
break;
|
break;
|
||||||
|
case "p":
|
||||||
|
responses.add(userPlugin.Ping());
|
||||||
|
break;
|
||||||
|
|
||||||
// Plugin 7 (Galaxy)
|
// Plugin 7 (Galaxy)
|
||||||
case "lpv":
|
case "lpv":
|
||||||
|
|
@ -92,9 +95,8 @@ public class ArkOneController implements TcpHandler {
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
outputStream.write(response.getBytes());
|
outputStream.write(response.getBytes());
|
||||||
outputStream.write((byte)0x00);
|
outputStream.write((byte)0x00);
|
||||||
byte[] combinedResponse = outputStream.toByteArray();
|
|
||||||
|
|
||||||
connection.send(combinedResponse);
|
connection.send(outputStream.toByteArray());
|
||||||
|
|
||||||
System.out.println("[ArkOne] Response: " + response);
|
System.out.println("[ArkOne] Response: " + response);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public class UserPlugin {
|
||||||
.username(username)
|
.username(username)
|
||||||
.password(passwordEncoder.encode(password))
|
.password(passwordEncoder.encode(password))
|
||||||
.securityQuestion(securityQuestion)
|
.securityQuestion(securityQuestion)
|
||||||
.securityAnswer(securityAnswer)
|
.securityAnswer(passwordEncoder.encode(securityAnswer))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// 0 - Successfully registered
|
// 0 - Successfully registered
|
||||||
|
|
@ -70,4 +70,8 @@ public class UserPlugin {
|
||||||
|
|
||||||
return ArkOneParser.RemoveXMLTag(doc);
|
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