Merge branch 'master' into 'master'
Feature: ftp upload functionality See merge request morningstar/apollyon!2
This commit is contained in:
commit
d5d1e4b926
@ -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_");
|
||||
|
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 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;
|
||||
@ -52,9 +55,17 @@ public class CameraRoomPictureEvent extends MessageHandler
|
||||
this.client.getHabbo().getHabboInfo().setPhotoJSON(json);
|
||||
|
||||
try {
|
||||
if(Emulator.getConfig().getInt("ftp.enabled") == 1) {
|
||||
byte[] imageBytes = new byte[image.readableBytes()];
|
||||
image.readBytes(imageBytes);
|
||||
FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.camera") + URL);
|
||||
FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.camera") + URL_small);
|
||||
}
|
||||
else {
|
||||
BufferedImage theImage = ImageIO.read(new ByteBufInputStream(image));
|
||||
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) {
|
||||
|
@ -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;
|
||||
|
||||
@ -45,15 +48,17 @@ public class CameraRoomThumbnailEvent extends MessageHandler
|
||||
this.packet.readInt();
|
||||
this.packet.readInt();
|
||||
|
||||
BufferedImage theImage = null;
|
||||
try {
|
||||
theImage = ImageIO.read(new ByteBufInputStream(image));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
if(Emulator.getConfig().getInt("ftp.enabled") == 1) {
|
||||
byte[] imageBytes = new byte[image.readableBytes()];
|
||||
image.readBytes(imageBytes);
|
||||
FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png");
|
||||
}
|
||||
|
||||
try {
|
||||
else {
|
||||
BufferedImage theImage = null;
|
||||
theImage = ImageIO.read(new ByteBufInputStream(image));
|
||||
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png"));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user