Added ability to upload image using ftp
This commit is contained in:
parent
90a09d0e52
commit
89add83bcd
@ -57,6 +57,10 @@ public class Main extends HabboPlugin implements EventListener {
|
|||||||
public void onEmulatorLoadedEvent(EmulatorLoadedEvent e) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, Exception {
|
public void onEmulatorLoadedEvent(EmulatorLoadedEvent e) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, Exception {
|
||||||
|
|
||||||
// Adds missing sqls if they are not found.
|
// 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("camera.url", "http://yourdomain.com/swfdirectory/camera/");
|
||||||
Emulator.getConfig().register("imager.location.output.camera", "C:\\yourdirectory\\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_");
|
Emulator.getConfig().register("imager.location.output.thumbnail", "C:\\yourdirectory\\swfdirectory\\camera\\thumbnails\\thumbnail_");
|
||||||
|
26
src/main/java/org/krews/apollyon/ftp/FTPUploadService.java
Normal file
26
src/main/java/org/krews/apollyon/ftp/FTPUploadService.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -8,8 +8,11 @@ import com.eu.habbo.messages.outgoing.camera.CameraURLComposer;
|
|||||||
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
|
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufInputStream;
|
import io.netty.buffer.ByteBufInputStream;
|
||||||
|
import org.krews.apollyon.ftp.FTPUploadService;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.DataBufferByte;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.IllegalArgumentException;
|
import java.lang.IllegalArgumentException;
|
||||||
@ -53,8 +56,15 @@ public class CameraRoomPictureEvent extends MessageHandler
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedImage theImage = ImageIO.read(new ByteBufInputStream(image));
|
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));
|
||||||
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.camera") + URL_small));
|
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.camera") + URL_small));
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -7,8 +7,11 @@ import com.eu.habbo.messages.outgoing.camera.CameraRoomThumbnailSavedComposer;
|
|||||||
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
|
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufInputStream;
|
import io.netty.buffer.ByteBufInputStream;
|
||||||
|
import org.krews.apollyon.ftp.FTPUploadService;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.DataBufferByte;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -53,7 +56,13 @@ public class CameraRoomThumbnailEvent extends MessageHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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"));
|
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png"));
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user