Merge branch 'master' into 'master'

Feature: ftp upload functionality

See merge request morningstar/apollyon!2
This commit is contained in:
Harmonic 2019-12-17 08:12:25 -05:00
commit d5d1e4b926
5 changed files with 57 additions and 11 deletions

View File

@ -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_");

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 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;
@ -52,9 +55,17 @@ public class CameraRoomPictureEvent extends MessageHandler
this.client.getHabbo().getHabboInfo().setPhotoJSON(json); this.client.getHabbo().getHabboInfo().setPhotoJSON(json);
try { try {
BufferedImage theImage = ImageIO.read(new ByteBufInputStream(image)); if(Emulator.getConfig().getInt("ftp.enabled") == 1) {
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.camera") + URL)); byte[] imageBytes = new byte[image.readableBytes()];
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.camera") + URL_small)); 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } 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 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;
@ -45,15 +48,17 @@ public class CameraRoomThumbnailEvent extends MessageHandler
this.packet.readInt(); this.packet.readInt();
this.packet.readInt(); this.packet.readInt();
BufferedImage theImage = null;
try { try {
theImage = ImageIO.read(new ByteBufInputStream(image)); if(Emulator.getConfig().getInt("ftp.enabled") == 1) {
} catch (IOException e) { byte[] imageBytes = new byte[image.readableBytes()];
e.printStackTrace(); image.readBytes(imageBytes);
} FTPUploadService.uploadImage(imageBytes, Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png");
}
try { else {
ImageIO.write(theImage, "png", new File(Emulator.getConfig().getValue("imager.location.output.thumbnail") + room.getId() + ".png")); 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {

Binary file not shown.