2018-07-06 13:30:00 +00:00
|
|
|
package com.eu.habbo.messages.rcon;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.google.gson.Gson;
|
2020-05-04 22:24:09 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public class MuteUser extends RCONMessage<MuteUser.JSON> {
|
2020-05-04 22:24:09 +02:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(MuteUser.class);
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public MuteUser() {
|
2018-12-22 10:39:00 +00:00
|
|
|
super(MuteUser.JSON.class);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 21:14:53 +03:00
|
|
|
public void handle(Gson gson, JSON json) {
|
2018-07-06 13:30:00 +00:00
|
|
|
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(json.user_id);
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (habbo != null) {
|
|
|
|
if (json.duration == 0) {
|
2018-07-06 13:30:00 +00:00
|
|
|
habbo.unMute();
|
2019-05-26 21:14:53 +03:00
|
|
|
} else {
|
2020-01-22 20:56:56 +01:00
|
|
|
habbo.mute(json.duration, false);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
2019-05-26 21:14:53 +03:00
|
|
|
} else {
|
|
|
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET mute_end_timestamp = ? WHERE user_id = ? LIMIT 1")) {
|
2018-07-06 13:30:00 +00:00
|
|
|
statement.setInt(1, Emulator.getIntUnixTimestamp() + json.duration);
|
|
|
|
statement.setInt(2, json.user_id);
|
2019-05-26 21:14:53 +03:00
|
|
|
if (statement.executeUpdate() == 0) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.status = HABBO_NOT_FOUND;
|
|
|
|
}
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (SQLException e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught SQL exception", e);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
static class JSON {
|
2018-10-06 22:28:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public int user_id;
|
2018-10-06 22:28:00 +00:00
|
|
|
|
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public int duration;
|
|
|
|
}
|
|
|
|
}
|