feat: update to ms4

This commit is contained in:
Niklas 2023-03-13 23:22:46 +01:00
parent 1a685d3dba
commit 10aeca2880
9 changed files with 100 additions and 142 deletions

View File

@ -1,5 +1,9 @@
# Apollyon #
## Changes ##
Because Arcturus Morningstar 3 is deprecated, Apollyon must be changed. Overall FTP support was removed, because the protocol shouldn't be used in 2023 in my opinion and if so at least SFTP should be used.
Also the dependency changed to the current Morningstar ms4 Version. `onEnable()` can't throw any Exception and updated Incoming packet ids.
## What is Apollyon? ##
Apollyon is a Camera Plugin for Arcturus Morningstar

11
pom.xml
View File

@ -6,15 +6,16 @@
<groupId>com.eu.habbo</groupId>
<artifactId>Apollyon</artifactId>
<version>1</version>
<version>2.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
</plugins>
@ -23,8 +24,8 @@
<dependencies>
<dependency>
<groupId>com.eu.habbo</groupId>
<artifactId>Habbo</artifactId>
<version>3.0.0</version>
<artifactId>Morningstar</artifactId>
<version>4.0-DEVPREVIEW</version>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,5 @@
package org.krews.apollyon;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.PacketManager;
@ -22,16 +23,18 @@ import java.lang.reflect.Field;
/**
* Apollyon
* The Official Camera Plugin for Morningstar. Credits to John, Beny, Ovflowd, and Alejandro
*
* @author Krews.org
*/
public class Main extends HabboPlugin implements EventListener {
private static final Logger LOGGER = LoggerFactory.getLogger(Emulator.class);
@Override
public void onEnable() throws Exception {
public void onEnable() {
Emulator.getPluginManager().registerEvents(this, this);
if(Emulator.isReady && !Emulator.isShuttingDown) {
if (Emulator.isReady && !Emulator.isShuttingDown) {
this.onEmulatorLoadedEvent(null);
}
}
@ -42,51 +45,54 @@ public class Main extends HabboPlugin implements EventListener {
}
@Override
public void onDisable() throws Exception {
// put the original packets back
PacketManager packetManager = Emulator.getGameServer().getPacketManager();
Field f = PacketManager.class.getDeclaredField("incoming");
f.setAccessible(true);
THashMap<Integer, Class<? extends MessageHandler>> incoming = (THashMap<Integer, Class<? extends MessageHandler>>)f.get(packetManager);
incoming.remove(Incoming.CameraRoomPictureEvent, CameraRoomPictureEvent.class);
incoming.remove(Incoming.CameraPublishToWebEvent, CameraPublishToWebEvent.class);
incoming.remove(Incoming.CameraPurchaseEvent, CameraPurchaseEvent.class);
incoming.remove(Incoming.CameraRoomThumbnailEvent, CameraRoomThumbnailEvent.class);
public void onDisable() {
try {
// put the original packets back
PacketManager packetManager = Emulator.getGameServer().getPacketManager();
Field f = PacketManager.class.getDeclaredField("incoming");
f.setAccessible(true);
THashMap<Integer, Class<? extends MessageHandler>> incoming = (THashMap<Integer, Class<? extends MessageHandler>>) f.get(packetManager);
incoming.remove(Incoming.renderRoomEvent, CameraRoomPictureEvent.class);
incoming.remove(Incoming.publishPhotoEvent, CameraPublishToWebEvent.class);
incoming.remove(Incoming.purchasePhotoEvent, CameraPurchaseEvent.class);
incoming.remove(Incoming.renderRoomThumbnailEvent, CameraRoomThumbnailEvent.class);
} catch (Exception ex) {
LOGGER.error("Apollyon failed to disable!");
throw new RuntimeException(ex);
}
}
@EventHandler
public void onEmulatorLoadedEvent(EmulatorLoadedEvent e) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, Exception {
public void onEmulatorLoadedEvent(EmulatorLoadedEvent e) {
try {
// Adds missing sqls if they are not found.
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_");
// Adds missing sqls if they are not found.
Emulator.getConfig().register("apollyon.cooldown.amount", "250");
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_");
PacketManager packetManager = Emulator.getGameServer().getPacketManager();
Field f = PacketManager.class.getDeclaredField("incoming");
f.setAccessible(true);
THashMap<Integer, Class<? extends MessageHandler>> incoming = (THashMap<Integer, Class<? extends MessageHandler>>) f.get(packetManager);
PacketManager packetManager = Emulator.getGameServer().getPacketManager();
Field f = PacketManager.class.getDeclaredField("incoming");
f.setAccessible(true);
THashMap<Integer, Class<? extends MessageHandler>> incoming = (THashMap<Integer, Class<? extends MessageHandler>>)f.get(packetManager);
// Removes the current arcturus handlers for these packets
incoming.remove(Incoming.renderRoomEvent);
incoming.remove(Incoming.publishPhotoEvent);
incoming.remove(Incoming.purchasePhotoEvent);
incoming.remove(Incoming.renderRoomThumbnailEvent);
// Removes the current arcturus handlers for these packets
incoming.remove(Incoming.CameraRoomPictureEvent);
incoming.remove(Incoming.CameraPublishToWebEvent);
incoming.remove(Incoming.CameraPurchaseEvent);
incoming.remove(Incoming.CameraRoomThumbnailEvent);
// Adds the PNGCamera Packet Handlers
packetManager.registerHandler(Incoming.renderRoomEvent, CameraRoomPictureEvent.class);
packetManager.registerHandler(Incoming.publishPhotoEvent, CameraPublishToWebEvent.class);
packetManager.registerHandler(Incoming.purchasePhotoEvent, CameraPurchaseEvent.class);
packetManager.registerHandler(Incoming.renderRoomThumbnailEvent, CameraRoomThumbnailEvent.class);
// Adds the PNGCamera Packet Handlers
packetManager.registerHandler(Incoming.CameraRoomPictureEvent, CameraRoomPictureEvent.class);
packetManager.registerHandler(Incoming.CameraPublishToWebEvent, CameraPublishToWebEvent.class);
packetManager.registerHandler(Incoming.CameraPurchaseEvent, CameraPurchaseEvent.class);
packetManager.registerHandler(Incoming.CameraRoomThumbnailEvent, CameraRoomThumbnailEvent.class);
// Send the message to the Emulator that PNGCamera has started.
LOGGER.info("Official Plugin - Apollyon 1.0 has loaded!");
// Send the message to the Emulator that PNGCamera has started.
LOGGER.info("OFFICIAL PLUGIN - Apollyon has been loaded!");
} catch (Exception ex) {
LOGGER.error("Apollyon failed to load!");
throw new RuntimeException(ex);
}
}

View File

@ -1,31 +0,0 @@
package org.krews.apollyon.ftp;
import com.eu.habbo.Emulator;
import org.krews.apollyon.utils.PngSignatureChecker;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Arrays;
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 {
if (PngSignatureChecker.isPngFile(image)) {
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, URLEncoder.encode(user, "UTF-8"), URLEncoder.encode(pass, "UTF-8"), 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

@ -2,22 +2,23 @@ package org.krews.apollyon.incoming;
import com.eu.habbo.Emulator;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.camera.CameraPublishWaitMessageComposer;
import com.eu.habbo.messages.outgoing.catalog.NotEnoughPointsTypeComposer;
import com.eu.habbo.messages.outgoing.camera.CameraPublishStatusMessageComposer;
import com.eu.habbo.messages.outgoing.catalog.NotEnoughBalanceMessageComposer;
import com.eu.habbo.plugin.events.users.UserPublishPictureEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class CameraPublishToWebEvent extends MessageHandler
{
public class CameraPublishToWebEvent extends MessageHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(CameraPublishToWebEvent.class);
@Override
public void handle() {
if (this.client.getHabbo().getHabboInfo().getCurrencyAmount(0) < Emulator.getConfig().getInt("camera.price.points.publish")) {
this.client.sendResponse(new NotEnoughPointsTypeComposer(false, true, 0));
this.client.sendResponse(new NotEnoughBalanceMessageComposer(false, true, 0));
return;
}
if (this.client.getHabbo().getHabboInfo().getPhotoTimestamp() != 0) {
@ -30,15 +31,14 @@ public class CameraPublishToWebEvent extends MessageHandler
int wait = 0;
if (timeDiff < Emulator.getConfig().getInt("camera.publish.delay")) {
wait = timeDiff - Emulator.getConfig().getInt("camera.publish.delay");
}
else {
} else {
UserPublishPictureEvent publishPictureEvent = new UserPublishPictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), timestamp, this.client.getHabbo().getHabboInfo().getPhotoRoomId());
if (!Emulator.getPluginManager().fireEvent(publishPictureEvent).isCancelled()) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO camera_web (user_id, room_id, timestamp, url) VALUES (?, ?, ?, ?)")) {
statement.setInt(1, this.client.getHabbo().getHabboInfo().getId());
statement.setInt(2, publishPictureEvent.roomId);
statement.setInt(3, publishPictureEvent.timestamp);
statement.setString(4, publishPictureEvent.URL);
statement.setInt(2, publishPictureEvent.getRoomId());
statement.setInt(3, publishPictureEvent.getTimestamp());
statement.setString(4, publishPictureEvent.getURL());
statement.execute();
this.client.getHabbo().getHabboInfo().setWebPublishTimestamp(timestamp);
this.client.getHabbo().givePixels(-Emulator.getConfig().getInt("camera.price.points.publish"));
@ -47,15 +47,14 @@ public class CameraPublishToWebEvent extends MessageHandler
throwables.printStackTrace();
}
}
else {
} else {
return;
}
}
this.client.sendResponse(new CameraPublishWaitMessageComposer(published, wait, published ? this.client.getHabbo().getHabboInfo().getPhotoURL() : ""));
this.client.sendResponse(new CameraPublishStatusMessageComposer(published, wait, published ? this.client.getHabbo().getHabboInfo().getPhotoURL() : ""));
}
}
}
}
}
}

View File

@ -6,10 +6,10 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.camera.CameraPurchaseSuccesfullComposer;
import com.eu.habbo.messages.outgoing.catalog.NotEnoughPointsTypeComposer;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
import com.eu.habbo.messages.outgoing.camera.CameraPurchaseOKMessageComposer;
import com.eu.habbo.messages.outgoing.catalog.NotEnoughBalanceMessageComposer;
import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer;
import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer;
import com.eu.habbo.plugin.events.users.UserPurchasePictureEvent;
import gnu.trove.map.hash.THashMap;
import org.slf4j.Logger;
@ -20,21 +20,17 @@ public class CameraPurchaseEvent extends MessageHandler {
public static int CAMERA_PURCHASE_CREDITS = Emulator.getConfig().getInt("camera.price.credits");
public static int CAMERA_PURCHASE_POINTS = Emulator.getConfig().getInt("camera.price.points");
public static int CAMERA_PURCHASE_POINTS_TYPE = Emulator.getConfig().getInt("camera.price.points.type");
public THashMap<Habbo, Integer> lastRanTimestamps = new THashMap<Habbo, Integer>();
public int getRatelimit() {
return Emulator.getConfig().getInt("apollyon.cooldown.amount");
}
public THashMap<Habbo, Integer> lastRanTimestamps = new THashMap<>();
@Override
public void handle() {
if (this.client.getHabbo().getHabboInfo().getCredits() < CameraPurchaseEvent.CAMERA_PURCHASE_CREDITS) {
this.client.sendResponse(new NotEnoughPointsTypeComposer(true, false, 0));
this.client.sendResponse(new NotEnoughBalanceMessageComposer(true, false, 0));
return;
}
if (this.client.getHabbo().getHabboInfo().getCurrencyAmount(CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE) < CameraPurchaseEvent.CAMERA_PURCHASE_POINTS) {
this.client.sendResponse(new NotEnoughPointsTypeComposer(false, true, CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE));
this.client.sendResponse(new NotEnoughBalanceMessageComposer(false, true, CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE));
return;
}
@ -71,13 +67,13 @@ public class CameraPurchaseEvent extends MessageHandler {
this.client.getHabbo().getInventory().getItemsComponent().addItem(photoItem);
this.client.sendResponse(new CameraPurchaseSuccesfullComposer());
this.client.sendResponse(new AddHabboItemComposer(photoItem));
this.client.sendResponse(new InventoryRefreshComposer());
this.client.sendResponse(new CameraPurchaseOKMessageComposer());
this.client.sendResponse(new UnseenItemsComposer(photoItem));
this.client.sendResponse(new FurniListInvalidateComposer());
this.client.getHabbo().giveCredits(-CameraPurchaseEvent.CAMERA_PURCHASE_CREDITS);
this.client.getHabbo().givePoints(CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE, -CameraPurchaseEvent.CAMERA_PURCHASE_POINTS);
AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("CameraPhotoCount"));
}
}
}
}

View File

@ -3,12 +3,10 @@ package org.krews.apollyon.incoming;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.camera.CameraURLComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
import com.eu.habbo.messages.outgoing.camera.CameraStorageUrlMessageComposer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.util.ReferenceCountUtil;
import org.krews.apollyon.ftp.FTPUploadService;
import org.krews.apollyon.utils.PngSignatureChecker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,7 +15,6 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.IllegalArgumentException;
public class CameraRoomPictureEvent extends MessageHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(CameraRoomPictureEvent.class);
@ -25,7 +22,7 @@ public class CameraRoomPictureEvent extends MessageHandler {
@Override
public void handle() {
if (!this.client.getHabbo().hasPermission("acc_camera")) {
this.client.sendResponse(new GenericAlertComposer(Emulator.getTexts().getValue("camera.permission")));
this.client.getHabbo().alert(Emulator.getTexts().getValue("camera.permission"));
return;
}
@ -37,11 +34,12 @@ public class CameraRoomPictureEvent extends MessageHandler {
final int count = this.packet.readInt();
ByteBuf image = this.packet.getBuffer().readBytes(count);
ByteBuf imageCopy = image.copy();
if (image == null)
return;
ByteBuf imageCopy = image.copy();
try {
byte[] imageBytes = new byte[image.readableBytes()];
image.readBytes(imageBytes);
@ -67,14 +65,9 @@ public class CameraRoomPictureEvent extends MessageHandler {
lol.lastRanTimestamps.put(this.client.getHabbo(), Emulator.getIntUnixTimestamp());
try {
if (Emulator.getConfig().getInt("ftp.enabled") == 1) {
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(imageCopy));
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));
}
BufferedImage theImage = ImageIO.read(new ByteBufInputStream(imageCopy));
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) {
@ -82,7 +75,7 @@ public class CameraRoomPictureEvent extends MessageHandler {
LOGGER.error("[Apollyon] https://git.krews.org/morningstar/apollyon");
}
this.client.sendResponse(new CameraURLComposer(URL));
this.client.sendResponse(new CameraStorageUrlMessageComposer(URL));
}
} finally {
ReferenceCountUtil.release(image);

View File

@ -3,28 +3,25 @@ package org.krews.apollyon.incoming;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.camera.CameraRoomThumbnailSavedComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
import com.eu.habbo.messages.outgoing.camera.ThumbnailStatusMessageComposer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.util.ReferenceCountUtil;
import org.krews.apollyon.ftp.FTPUploadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
public class CameraRoomThumbnailEvent extends MessageHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(CameraRoomThumbnailEvent.class);
@Override
public void handle() {
if (! this.client.getHabbo().hasPermission("acc_camera")) {
this.client.sendResponse(new GenericAlertComposer(Emulator.getTexts().getValue("camera.permission")));
if (!this.client.getHabbo().hasPermission("acc_camera")) {
this.client.getHabbo().alert(Emulator.getTexts().getValue("camera.permission"));
return;
}
@ -43,7 +40,7 @@ public class CameraRoomThumbnailEvent extends MessageHandler {
ByteBuf image = this.packet.getBuffer().readBytes(count);
if(image == null)
if (image == null)
return;
try {
@ -53,16 +50,9 @@ public class CameraRoomThumbnailEvent extends MessageHandler {
this.packet.readInt();
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.thumbnail") + room.getId() + ".png");
}
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"));
}
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) {
@ -70,9 +60,9 @@ public class CameraRoomThumbnailEvent extends MessageHandler {
LOGGER.error("[Apollyon] https://git.krews.org/morningstar/apollyon");
}
this.client.sendResponse(new CameraRoomThumbnailSavedComposer());
this.client.sendResponse(new ThumbnailStatusMessageComposer());
} finally {
ReferenceCountUtil.release(image);
}
}
}
}

Binary file not shown.