Fix modtool room visit logs for offline users (fixes #308)

This commit is contained in:
Alejandro 2020-01-24 20:41:14 +02:00
parent 1b5517f677
commit 5eca88d501
3 changed files with 15 additions and 13 deletions

View File

@ -278,12 +278,12 @@ public class ModToolManager {
return chatlogs;
}
public THashSet<ModToolRoomVisit> requestUserRoomVisits(Habbo habbo) {
public THashSet<ModToolRoomVisit> getUserRoomVisits(int userId) {
THashSet<ModToolRoomVisit> roomVisits = new THashSet<>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.name, room_enter_log.* FROM room_enter_log INNER JOIN rooms ON rooms.id = room_enter_log.room_id WHERE user_id = ? AND timestamp >= ? ORDER BY timestamp DESC LIMIT 50")) {
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(2, Emulator.getIntUnixTimestamp() - 84600);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.name, room_enter_log.* FROM room_enter_log INNER JOIN rooms ON rooms.id = room_enter_log.room_id WHERE user_id = ? ORDER BY timestamp DESC LIMIT 50")) {
statement.setInt(1, userId);
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
roomVisits.add(new ModToolRoomVisit(set));

View File

@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.modtool;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.modtool.ModToolUserRoomVisitsComposer;
@ -12,10 +13,11 @@ public class ModToolRequestRoomVisitsEvent extends MessageHandler {
if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) {
int userId = this.packet.readInt();
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(userId);
if (habbo != null)
this.client.sendResponse(new ModToolUserRoomVisitsComposer(habbo, Emulator.getGameEnvironment().getModToolManager().requestUserRoomVisits(habbo)));
if (habboInfo != null) {
this.client.sendResponse(new ModToolUserRoomVisitsComposer(habboInfo, Emulator.getGameEnvironment().getModToolManager().getUserRoomVisits(userId)));
}
}
}
}

View File

@ -1,7 +1,7 @@
package com.eu.habbo.messages.outgoing.modtool;
import com.eu.habbo.habbohotel.modtool.ModToolRoomVisit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
@ -11,19 +11,19 @@ import java.util.Calendar;
import java.util.TimeZone;
public class ModToolUserRoomVisitsComposer extends MessageComposer {
private final Habbo habbo;
private final HabboInfo habboInfo;
private final THashSet<ModToolRoomVisit> roomVisits;
public ModToolUserRoomVisitsComposer(Habbo habbo, THashSet<ModToolRoomVisit> roomVisits) {
this.habbo = habbo;
public ModToolUserRoomVisitsComposer(HabboInfo habboInfo, THashSet<ModToolRoomVisit> roomVisits) {
this.habboInfo = habboInfo;
this.roomVisits = roomVisits;
}
@Override
public ServerMessage compose() {
this.response.init(Outgoing.ModToolUserRoomVisitsComposer);
this.response.appendInt(this.habbo.getHabboInfo().getId());
this.response.appendString(this.habbo.getHabboInfo().getUsername());
this.response.appendInt(this.habboInfo.getId());
this.response.appendString(this.habboInfo.getUsername());
this.response.appendInt(this.roomVisits.size());
Calendar cal = Calendar.getInstance(TimeZone.getDefault());