Skip to content

Commit

Permalink
8.0.0
Browse files Browse the repository at this point in the history
- Major release due to various breaking changes in protocol (which makes older versions completely incompatible with web), thus all AutoPlug-Web users should update. However no major new features.
- FIX: uploading files causing exceptions, and increased upload limit to 5 terabytes
- FIX: permissions for uploading files checked not for write perms too.
- FIX: /chat users duplicate chat creation
  • Loading branch information
Osiris-Team committed May 6, 2024
1 parent 1964edd commit f3a63ad
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .run/build-run-jar.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<option name="JAR_PATH" value="$PROJECT_DIR$/AP-TEST-SERVER/AutoPlug-Client.jar"/>
<option name="VM_PARAMETERS" value="-Dfile.encoding=UTF-8"/>
<option name="PROGRAM_PARAMETERS" value="test"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/AP-TEST-SERVER"/>
<option name="WORKING_DIRECTORY" value="D:\Coding\JAVA\AutoPlug-Client\AP-TEST-SERVER"/>
<option name="ALTERNATIVE_JRE_PATH"/>
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="autoplug-client [-DskipTests]"
Expand Down
32 changes: 32 additions & 0 deletions .run/gradle-build-example.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
~ Copyright (c) 2024 Osiris-Team.
~ All rights reserved.
~
~ This software is copyrighted work, licensed under the terms
~ of the MIT-License. Consult the "LICENSE" file for details.
-->

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="gradle-build-example" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value="--debug"/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="build"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
</component>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.osiris.autoplug.client</groupId>
<artifactId>autoplug-client</artifactId>
<version>7.5.18</version>
<version>8.0.0</version>
<packaging>jar</packaging>

<name>AutoPlug-Client</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -8,6 +8,7 @@

package com.osiris.autoplug.client.network.online;

import com.osiris.autoplug.client.configs.GeneralConfig;
import com.osiris.autoplug.client.network.online.connections.*;
import com.osiris.jlib.logger.AL;

Expand Down Expand Up @@ -53,7 +54,14 @@ public boolean open() {
} catch (Exception e) {
AL.warn(e);
isDone = true;
return false;
try {
String key = new GeneralConfig().server_key.asString();
if (key == null || key.isEmpty() || key.equals(NO_KEY))
return false;
// else we continue below and retry the connection
} catch (Exception ex) {
return false;
}
}
super.setAndStartAsync(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand Down Expand Up @@ -38,6 +38,7 @@
* Must be extended by each connection.
*/
public class DefaultConnection implements AutoCloseable {
public static final String NO_KEY = "NO_KEY";
public final byte conType;
public byte errorCode = 0;
public Socket socket;
Expand Down Expand Up @@ -116,7 +117,7 @@ private synchronized int _open() throws Exception {
isClosing.set(false);
String serverKey = new GeneralConfig().server_key.asString();
if (serverKey == null || serverKey.equals("INSERT_KEY_HERE") ||
serverKey.equals("NO_KEY"))
serverKey.equals(NO_KEY))
throw new Exception("No valid key provided." +
" Register your server at " + GD.OFFICIAL_WEBSITE + ", get your server-key and add it to the /autoplug/general.yml config file." +
" Enter '.con reload' to retry.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -18,10 +18,7 @@
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.Nullable;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

Expand Down Expand Up @@ -120,29 +117,26 @@ private void doProtocolForCopyOrCutFiles() throws IOException {
}
}
}
dos.writeBoolean(true);
} catch (Exception e) {
AL.warn(e);
dos.writeBoolean(false);
dos.writeLine("Critical error while copying/cutting a file! Check your servers log for further details: " + e.getMessage());
}
dos.writeBoolean(true);
}

private void doProtocolForReceivingUploadedFile() throws IOException {
File file = new File(dis.readLine());
String filePath = dis.readLine();
File file = new File(filePath);
if (!file.exists()) file.createNewFile();
try (BufferedWriter fw = new BufferedWriter(new FileWriter(file))) {
String line;
while ((line = dis.readLine()) != null && !line.equals("\u001a")) {
fw.write(line + "\n");
fw.flush();
}
try (FileOutputStream fw = new FileOutputStream(file)) {
dis.readStream(fw);
dos.writeBoolean(true);
} catch (Exception e) {
AL.warn(e);
dos.writeBoolean(false);
dos.writeLine("Critical error while saving uploaded file! Check your servers log for further details: " + e.getMessage());
}
dos.writeBoolean(true);
}

private void doProtocolForSavingFile() throws IOException {
Expand All @@ -153,12 +147,12 @@ private void doProtocolForSavingFile() throws IOException {
fw.write(line + "\n");
fw.flush();
}
dos.writeBoolean(true);
} catch (Exception e) {
AL.warn(e);
dos.writeBoolean(false);
dos.writeLine("Critical error while saving a file! Check your servers log for further details: " + e.getMessage());
}
dos.writeBoolean(true);
}

private void doProtocolForRenamingFile() throws IOException {
Expand Down
116 changes: 52 additions & 64 deletions src/main/java/com/osiris/autoplug/client/utils/io/UFDataIn.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Osiris-Team.
* Copyright (c) 2021-2024 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -8,116 +8,104 @@

package com.osiris.autoplug.client.utils.io;

import com.osiris.jlib.logger.AL;

import javax.naming.LimitExceededException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
* ULTRA FAST DATA INPUTSTREAM!
*/
public class UFDataIn {
private final InputStream inputStream;
private final BufferedReader reader;
private final DataInputStream dis;

public UFDataIn(InputStream inputStream) {
this.inputStream = inputStream;
this.reader = new BufferedReader(new InputStreamReader(inputStream));
this.dis = new DataInputStream(inputStream);
}

public String readLine() throws IOException {
return reader.readLine();
return dis.readUTF();
}

public boolean readBoolean() throws IOException {
return reader.read() != 0;
return dis.readBoolean();
}

/**
* Returns a list containing the lines of the file.
*/
public List<String> readFile() throws IOException {
List<String> lines = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null && !line.equals("\u001a")) { // Stop at 10 mb
lines.add(line + "\n");
public void readFile(File file, long maxBytes) throws IOException, LimitExceededException {
try (FileOutputStream out = new FileOutputStream(file)) {
readStream(out, maxBytes);
}
return lines;
}

/**
* Returns a list containing the lines of the file. <br>
*
* @param maxBytes the maximum amount of bytes to read.
* @throws LimitExceededException when the provided maximum bytes amount was read.
* Returns a list containing the lines of the file.
*/
public List<String> readFile(long maxBytes) throws IOException, LimitExceededException {
List<String> lines = new ArrayList<>();
long bytesRead = 0;
String line;
while ((line = reader.readLine()) != null && !line.equals("\u001a")) { // Stop at 10 mb
lines.add(line + "\n");
bytesRead = bytesRead + line.getBytes().length;
if (bytesRead > maxBytes) {
public void readStream(OutputStream out, long maxBytes) throws IOException, LimitExceededException {
long countBytesRead = 0;
int count;
byte[] buffer = new byte[8192]; // or 4096, or more
String buffer_s = "";
while (!(buffer_s = dis.readUTF()).equals(UFDataOut.EOF)) {
buffer = buffer_s.getBytes(StandardCharsets.UTF_8);
count = buffer.length;

countBytesRead += count;
if (countBytesRead > maxBytes) {
throw new LimitExceededException("Exceeded the maximum allowed bytes: " + maxBytes);
}
out.write(buffer, 0, count);
out.flush();
}
return lines;
//read("\u001a") // Not needed here since already read above by read()
}

/**
* Returns a list containing the lines of the file.
*/
public List<String> readStream() throws IOException {
List<String> lines = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null && !line.equals("\u001a")) {
lines.add(line + "\n");
public void readFile(File file) throws IOException {
try (FileOutputStream out = new FileOutputStream(file)) {
readStream(out);
}
return lines;
}

/**
* Returns a list containing the lines of the file. <br>
*
* @param maxBytes the maximum amount of bytes to read.
* @throws LimitExceededException when the provided maximum bytes amount was read.
* Returns a list containing the lines of the file.
*/
public List<String> readStream(long maxBytes) throws IOException, LimitExceededException {
List<String> lines = new ArrayList<>();
long bytesRead = 0;
String line;
while ((line = reader.readLine()) != null && !line.equals("\u001a")) { // Stop at 10 mb
lines.add(line + "\n");
bytesRead = bytesRead + line.getBytes().length;
if (bytesRead > maxBytes) {
throw new LimitExceededException("Exceeded the maximum allowed bytes: " + maxBytes);
}
public void readStream(OutputStream out) throws IOException {
Base64.Decoder decoder = Base64.getDecoder();
long countBytesRead = 0;
int count;
byte[] buffer = new byte[8192]; // or 4096, or more
String buffer_s = "";
while (!(buffer_s = dis.readUTF()).equals(UFDataOut.EOF)) {
buffer = decoder.decode(buffer_s);
count = buffer.length;

countBytesRead += count;
out.write(buffer, 0, count);
out.flush();
}
return lines;
AL.debug(this.getClass(), "BYTES READ: " + countBytesRead);
//read("\u001a") // Not needed here since already read above by read()
}

public byte readByte() throws IOException {
return Byte.parseByte(readLine());
return dis.readByte();
}

public short readShort() throws IOException {
return Short.parseShort(readLine());
return dis.readShort();
}

public int readInt() throws IOException {
return Integer.parseInt(readLine());
return dis.readInt();
}

public long readLong() throws IOException {
return Long.parseLong(readLine());
return dis.readLong();
}

public float readFloat() throws IOException {
return Float.parseFloat(readLine());
return dis.readFloat();
}

}
Loading

0 comments on commit f3a63ad

Please sign in to comment.