Altered /ignore behavior to also include the last 50 banned users, which should cause banned user's chats to disappear from the chat
This commit is contained in:
@@ -3,15 +3,18 @@ package com.gempukku.lotro.chat;
|
||||
import com.gempukku.lotro.PrivateInformationException;
|
||||
import com.gempukku.lotro.SubscriptionExpiredException;
|
||||
import com.gempukku.lotro.db.IgnoreDAO;
|
||||
import com.gempukku.lotro.db.PlayerDAO;
|
||||
import com.gempukku.lotro.game.ChatCommunicationChannel;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class ChatRoomMediator {
|
||||
private IgnoreDAO ignoreDAO;
|
||||
private PlayerDAO playerDAO;
|
||||
private Logger _logger;
|
||||
private ChatRoom _chatRoom;
|
||||
|
||||
@@ -25,14 +28,15 @@ public class ChatRoomMediator {
|
||||
private Map<String, ChatCommandCallback> _chatCommandCallbacks = new HashMap<String, ChatCommandCallback>();
|
||||
private String welcomeMessage;
|
||||
|
||||
public ChatRoomMediator(IgnoreDAO ignoreDAO, String roomName, boolean muteJoinPartMessages, int secondsTimeoutPeriod, boolean allowIncognito, String welcomeMessage) {
|
||||
this(ignoreDAO, roomName, muteJoinPartMessages, secondsTimeoutPeriod, null, allowIncognito);
|
||||
public ChatRoomMediator(IgnoreDAO ignoreDAO, PlayerDAO playerDAO, String roomName, boolean muteJoinPartMessages, int secondsTimeoutPeriod, boolean allowIncognito, String welcomeMessage) {
|
||||
this(ignoreDAO, playerDAO, roomName, muteJoinPartMessages, secondsTimeoutPeriod, null, allowIncognito);
|
||||
this.welcomeMessage = welcomeMessage;
|
||||
}
|
||||
|
||||
public ChatRoomMediator(IgnoreDAO ignoreDAO, String roomName, boolean muteJoinPartMessages, int secondsTimeoutPeriod, Set<String> allowedPlayers,
|
||||
public ChatRoomMediator(IgnoreDAO ignoreDAO, PlayerDAO playerDAO, String roomName, boolean muteJoinPartMessages, int secondsTimeoutPeriod, Set<String> allowedPlayers,
|
||||
boolean allowIncognito) {
|
||||
this.ignoreDAO = ignoreDAO;
|
||||
this.playerDAO = playerDAO;
|
||||
_logger = Logger.getLogger("chat."+roomName);
|
||||
_allowedPlayers = allowedPlayers;
|
||||
_channelInactivityTimeoutPeriod = 1000 * secondsTimeoutPeriod;
|
||||
@@ -43,13 +47,15 @@ public class ChatRoomMediator {
|
||||
_chatCommandCallbacks.put(command.toLowerCase(), callback);
|
||||
}
|
||||
|
||||
public List<ChatMessage> joinUser(String playerId, boolean admin) throws PrivateInformationException {
|
||||
public List<ChatMessage> joinUser(String playerId, boolean admin) throws PrivateInformationException, SQLException {
|
||||
_lock.writeLock().lock();
|
||||
try {
|
||||
if (!admin && _allowedPlayers != null && !_allowedPlayers.contains(playerId))
|
||||
throw new PrivateInformationException();
|
||||
|
||||
ChatCommunicationChannel value = new ChatCommunicationChannel(ignoreDAO.getIgnoredUsers(playerId));
|
||||
Set<String> usersToIgnore = playerDAO.getBannedUsernames();
|
||||
usersToIgnore.addAll(ignoreDAO.getIgnoredUsers(playerId));
|
||||
ChatCommunicationChannel value = new ChatCommunicationChannel(usersToIgnore);
|
||||
_listeners.put(playerId, value);
|
||||
_chatRoom.joinChatRoom(playerId, value);
|
||||
final List<ChatMessage> chatMessages = value.consumeMessages();
|
||||
|
||||
@@ -5,14 +5,13 @@ import com.gempukku.lotro.game.Player;
|
||||
import org.apache.commons.collections.map.LRUMap;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class CachedPlayerDAO implements PlayerDAO, Cached {
|
||||
private PlayerDAO _delegate;
|
||||
private Map<Integer, Player> _playerById = Collections.synchronizedMap(new LRUMap(500));
|
||||
private Map<String, Player> _playerByName = Collections.synchronizedMap(new LRUMap(500));
|
||||
private Set<String> _bannedUsernames = new HashSet<>();
|
||||
|
||||
public CachedPlayerDAO(PlayerDAO delegate) {
|
||||
_delegate = delegate;
|
||||
@@ -22,6 +21,7 @@ public class CachedPlayerDAO implements PlayerDAO, Cached {
|
||||
public void clearCache() {
|
||||
_playerById.clear();
|
||||
_playerByName.clear();
|
||||
_bannedUsernames.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,6 +74,13 @@ public class CachedPlayerDAO implements PlayerDAO, Cached {
|
||||
return _delegate.findSimilarAccounts(login);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getBannedUsernames() throws SQLException {
|
||||
if(_bannedUsernames.isEmpty())
|
||||
_bannedUsernames = _delegate.getBannedUsernames();
|
||||
return _bannedUsernames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer(int id) {
|
||||
Player player = (Player) _playerById.get(id);
|
||||
|
||||
@@ -7,9 +7,7 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class DbPlayerDAO implements PlayerDAO {
|
||||
private final String validLoginChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
||||
@@ -75,6 +73,26 @@ public class DbPlayerDAO implements PlayerDAO {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getBannedUsernames() throws SQLException {
|
||||
try {
|
||||
try (Connection connection = _dbAccess.getDataSource().getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement("SELECT name FROM player WHERE type = '' ORDER BY ID DESC LIMIT 50")) {
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
TreeSet<String> users = new TreeSet<String>();
|
||||
while (resultSet.next()) {
|
||||
users.add(resultSet.getString(1));
|
||||
}
|
||||
return users;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException exp) {
|
||||
throw new RuntimeException("Unable to get banned users", exp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean banPlayerPermanently(String login) throws SQLException {
|
||||
try (Connection conn = _dbAccess.getDataSource().getConnection()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.gempukku.lotro.game.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface PlayerDAO {
|
||||
public Player getPlayer(int id);
|
||||
@@ -20,6 +21,7 @@ public interface PlayerDAO {
|
||||
public boolean removePlayerFlag(String login, String flag) throws SQLException;
|
||||
|
||||
public List<Player> findSimilarAccounts(String login) throws SQLException;
|
||||
public Set<String> getBannedUsernames() throws SQLException;
|
||||
|
||||
public Player loginUser(String login, String password) throws SQLException;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user