Added ability to upload image using ftp

This commit is contained in:
Dank074 2019-08-08 16:22:35 -05:00
parent 90a09d0e52
commit 89add83bcd
4 changed files with 52 additions and 3 deletions

View File

@ -57,6 +57,10 @@ public class Main extends HabboPlugin implements EventListener {
public void onEmulatorLoadedEvent(EmulatorLoadedEvent e) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, Exception {
// Adds missing sqls if they are not found.
Emulator.getConfig().register("ftp.enabled", "0");
Emulator.getConfig().register("ftp.user", "root");
Emulator.getConfig().register("ftp.password", "password123");
Emulator.getConfig().register("ftp.host", "example.com");
Emulator.getConfig().register("camera.url", "http://yourdomain.com/swfdirectory/camera/");
Emulator.getConfig().register("imager.location.output.camera", "C:\\yourdirectory\\swfdirectory\\camera\\");
Emulator.getConfig().register("imager.location.output.thumbnail", "C:\\yourdirectory\\swfdirectory\\camera\\thumbnails\\thumbnail_");

View File

@ -0,0 +1,26 @@
package org.krews.apollyon.ftp;
import com.eu.habbo.Emulator;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
public class FTPUploadService {
private static final String ftpUrl = "ftp://%s:%s@%s/%s;type=i";
public static void uploadImage(byte[] image, String uploadPath) throws IOException{
String host = Emulator.getConfig().getValue("ftp.host");
String user = Emulator.getConfig().getValue("ftp.user");
String pass = Emulator.getConfig().getValue("ftp.password");
String uploadURL = String.format(ftpUrl, user, pass, host, uploadPath);
URL url = new URL(uploadURL);
URLConnection conn = url.openConnection();
OutputStream outputStream = conn.getOutputStream();
outputStream.write(image, 0, image.length);
outputStream.close();
}
}

View File

@ -8,8 +8,11 @@ import com.eu.habbo.messages.outgoing.camera.CameraURLComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import org.krews.apollyon.ftp.FTPUploadService;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import java.lang.IllegalArgumentException;
@ -53,8 +56,15 @@ public class CameraRoomPictureEvent extends MessageHandler
try {
BufferedImage theImage = ImageIO.read(new ByteBufInputStream(image));
if(Emulator.getConfig().getInt("ftp.enabled") == 1) {
byte[] imageBytes = ((DataBufferByte) theImage.getData().getDataBuffer()).getData();
FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.camera") + URL);
FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.camera") + URL_small);
}
else {
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.camera") + URL));
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.camera") + URL_small));
}
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {

View File

@ -7,8 +7,11 @@ import com.eu.habbo.messages.outgoing.camera.CameraRoomThumbnailSavedComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import org.krews.apollyon.ftp.FTPUploadService;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
@ -53,7 +56,13 @@ public class CameraRoomThumbnailEvent extends MessageHandler
}
try {
if(Emulator.getConfig().getInt("ftp.enabled") == 1) {
byte[] imageBytes = ((DataBufferByte) theImage.getData().getDataBuffer()).getData();
FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png");
}
else {
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png"));
}
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {