Arcturus-Community/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/BotSaveSettingsEvent.java

167 lines
7.1 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.messages.incoming.rooms.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.bots.BotManager;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.permissions.Permission;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.messages.incoming.MessageHandler;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUnitUpdateUsernameComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDanceComposer;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.plugin.events.bots.BotSavedChatEvent;
import com.eu.habbo.plugin.events.bots.BotSavedLookEvent;
import com.eu.habbo.plugin.events.bots.BotSavedNameEvent;
import org.jsoup.Jsoup;
import java.util.ArrayList;
2019-05-26 20:14:53 +02:00
public class BotSaveSettingsEvent extends MessageHandler {
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void handle() throws Exception {
2018-07-06 15:30:00 +02:00
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
2019-05-26 20:14:53 +02:00
if (room == null)
2018-07-06 15:30:00 +02:00
return;
2019-05-26 20:14:53 +02:00
if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)) {
2018-07-06 15:30:00 +02:00
int botId = this.packet.readInt();
Bot bot = room.getBot(Math.abs(botId));
2019-05-26 20:14:53 +02:00
if (bot == null)
2018-07-06 15:30:00 +02:00
return;
int settingId = this.packet.readInt();
2019-05-26 20:14:53 +02:00
switch (settingId) {
2018-07-06 15:30:00 +02:00
case 1:
BotSavedLookEvent lookEvent = new BotSavedLookEvent(bot,
2019-05-26 20:14:53 +02:00
this.client.getHabbo().getHabboInfo().getGender(),
this.client.getHabbo().getHabboInfo().getLook(),
this.client.getHabbo().getRoomUnit().getEffectId());
2018-07-06 15:30:00 +02:00
Emulator.getPluginManager().fireEvent(lookEvent);
2019-05-26 20:14:53 +02:00
if (lookEvent.isCancelled())
2018-07-06 15:30:00 +02:00
break;
bot.setFigure(lookEvent.newLook);
bot.setGender(lookEvent.gender);
2019-03-18 02:22:00 +01:00
bot.setEffect(lookEvent.effect, -1);
2018-07-06 15:30:00 +02:00
bot.needsUpdate(true);
break;
case 2:
String messageString = this.packet.readString();
2019-05-26 20:14:53 +02:00
if (messageString.length() > 5112)
2018-07-06 15:30:00 +02:00
break;
String[] data = messageString.split(";#;");
2018-09-28 21:25:00 +02:00
ArrayList<String> chat = new ArrayList<>();
int totalChatLength = 0;
2019-05-26 20:14:53 +02:00
for (int i = 0; i < data.length - 3 && totalChatLength <= 120; i++) {
for (String s : data[i].split("\r")) {
2018-09-28 21:25:00 +02:00
String filtered = Jsoup.parse(s).text();
int count = 0;
2019-05-26 20:14:53 +02:00
while (!filtered.equalsIgnoreCase(s)) {
if (count >= 5) {
bot.clearChat();
return;
}
2018-09-28 21:25:00 +02:00
s = filtered;
filtered = Jsoup.parse(s).text();
count++;
}
String result = Emulator.getGameEnvironment().getWordFilter().filter(s, null);
2018-09-12 18:45:00 +02:00
2019-05-26 20:14:53 +02:00
if (!result.isEmpty()) {
if (!this.client.getHabbo().hasPermission("acc_chat_no_filter")) {
2018-09-28 21:25:00 +02:00
result = Emulator.getGameEnvironment().getWordFilter().filter(result, this.client.getHabbo());
}
result = result.substring(0, Math.min(BotManager.MAXIMUM_CHAT_LENGTH - totalChatLength, result.length()));
chat.add(result);
totalChatLength += result.length();
2018-09-12 18:45:00 +02:00
}
2018-07-06 15:30:00 +02:00
}
}
2018-09-28 21:25:00 +02:00
int chatSpeed = 7;
2019-05-26 20:14:53 +02:00
try {
2018-09-28 21:25:00 +02:00
chatSpeed = Integer.valueOf(data[data.length - 2]);
2019-05-26 20:14:53 +02:00
if (chatSpeed < BotManager.MINIMUM_CHAT_SPEED) {
2018-09-28 21:25:00 +02:00
chatSpeed = BotManager.MINIMUM_CHAT_SPEED;
}
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2018-09-28 21:25:00 +02:00
//Invalid chatspeed. Use 7.
2018-07-06 15:30:00 +02:00
}
BotSavedChatEvent chatEvent = new BotSavedChatEvent(bot, Boolean.valueOf(data[data.length - 3]), Boolean.valueOf(data[data.length - 1]), chatSpeed, chat);
Emulator.getPluginManager().fireEvent(chatEvent);
2019-05-26 20:14:53 +02:00
if (chatEvent.isCancelled())
2018-07-06 15:30:00 +02:00
break;
bot.setChatAuto(chatEvent.autoChat);
bot.setChatRandom(chatEvent.randomChat);
bot.setChatDelay((short) chatEvent.chatDelay);
bot.clearChat();
bot.addChatLines(chat);
bot.needsUpdate(true);
break;
case 3:
2018-10-07 00:28:00 +02:00
bot.setCanWalk(!bot.canWalk());
2018-07-06 15:30:00 +02:00
bot.needsUpdate(true);
break;
case 4:
2019-05-26 20:14:53 +02:00
bot.getRoomUnit().setDanceType(DanceType.values()[(bot.getRoomUnit().getDanceType().getType() + 1) % DanceType.values().length]);
2018-07-06 15:30:00 +02:00
room.sendComposer(new RoomUserDanceComposer(bot.getRoomUnit()).compose());
bot.needsUpdate(true);
break;
case 5:
2018-09-28 21:25:00 +02:00
String name = this.packet.readString();
boolean invalidName = name.length() > BotManager.MAXIMUM_NAME_LENGTH;
2019-05-26 20:14:53 +02:00
if (!invalidName) {
String filteredName = Emulator.getGameEnvironment().getWordFilter().filter(Jsoup.parse(name).text(), null);
2018-09-28 21:25:00 +02:00
invalidName = !name.equalsIgnoreCase(filteredName);
2019-05-26 20:14:53 +02:00
if (!invalidName) {
2018-09-28 21:25:00 +02:00
BotSavedNameEvent nameEvent = new BotSavedNameEvent(bot, name);
Emulator.getPluginManager().fireEvent(nameEvent);
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
if (nameEvent.isCancelled())
break;
bot.setName(nameEvent.name);
bot.needsUpdate(true);
room.sendComposer(new RoomUnitUpdateUsernameComposer(bot.getRoomUnit(), nameEvent.name).compose());
}
}
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if (invalidName) {
2018-09-28 21:25:00 +02:00
this.client.sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_NAME_NOT_ACCEPT));
2018-07-06 15:30:00 +02:00
}
break;
2018-09-28 21:25:00 +02:00
case 9:
bot.setMotto(this.packet.readString());
bot.needsUpdate(true);
room.sendComposer(new RoomUsersComposer(bot).compose());
break;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
if (bot.needsUpdate()) {
2018-07-06 15:30:00 +02:00
Emulator.getThreading().run(bot);
}
}
}
}