mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
* UI: ignore list improved:
* Added support of usernames with spaces (#6305); * Increased max limit from 50 to 100; * Added list size info on connection or command usage;
This commit is contained in:
parent
299be53e7a
commit
f50bc8f36f
7 changed files with 62 additions and 47 deletions
|
@ -7,18 +7,25 @@ import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.interfaces.callback.ClientCallbackMethod;
|
import mage.interfaces.callback.ClientCallbackMethod;
|
||||||
import mage.view.ChatMessage;
|
import mage.view.ChatMessage;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class LocalCommands {
|
public final class LocalCommands {
|
||||||
|
|
||||||
|
|
||||||
private LocalCommands(){}
|
private LocalCommands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRemainingTokens(StringTokenizer st) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
while (st.hasMoreTokens()) {
|
||||||
|
list.add(st.nextToken());
|
||||||
|
}
|
||||||
|
return String.join(" ", list);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for commands that do not require server interaction, i.e settings etc
|
* Handler for commands that do not require server interaction, i.e settings etc
|
||||||
|
*
|
||||||
* @param chatId
|
* @param chatId
|
||||||
* @param text
|
* @param text
|
||||||
* @return true if the command was handled locally, else false
|
* @return true if the command was handled locally, else false
|
||||||
|
@ -33,15 +40,16 @@ public final class LocalCommands {
|
||||||
final String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
final String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
||||||
Optional<String> response = Optional.empty();
|
Optional<String> response = Optional.empty();
|
||||||
|
|
||||||
switch (st.nextToken()) {
|
String command = st.nextToken();
|
||||||
|
switch (command) {
|
||||||
case "/ignore":
|
case "/ignore":
|
||||||
case "\\ignore":
|
case "\\ignore":
|
||||||
final String ignoreTarget = tokens > 1 ? st.nextToken() : "";
|
final String ignoreTarget = getRemainingTokens(st);
|
||||||
response = Optional.of(IgnoreList.ignore(serverAddress, ignoreTarget));
|
response = Optional.of(IgnoreList.ignore(serverAddress, ignoreTarget));
|
||||||
break;
|
break;
|
||||||
case "/unignore":
|
case "/unignore":
|
||||||
case "\\unignore":
|
case "\\unignore":
|
||||||
final String unignoreTarget = tokens > 1 ? st.nextToken() : "";
|
final String unignoreTarget = getRemainingTokens(st);
|
||||||
response = Optional.of(IgnoreList.unignore(serverAddress, unignoreTarget));
|
response = Optional.of(IgnoreList.unignore(serverAddress, unignoreTarget));
|
||||||
break;
|
break;
|
||||||
// TODO: move profanity settings to here
|
// TODO: move profanity settings to here
|
||||||
|
|
|
@ -619,7 +619,7 @@ public class NewTableDialog extends MageDialog {
|
||||||
options.setEdhPowerLevel((Integer) this.spnEdhPowerLevel.getValue());
|
options.setEdhPowerLevel((Integer) this.spnEdhPowerLevel.getValue());
|
||||||
options.setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
|
options.setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
|
||||||
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
||||||
options.setBannedUsers(IgnoreList.ignoreList(serverAddress));
|
options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
package mage.client.dialog;
|
package mage.client.dialog;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.swing.*;
|
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.cards.decks.DeckFileFilter;
|
import mage.cards.decks.DeckFileFilter;
|
||||||
import mage.cards.decks.importer.DeckImporter;
|
import mage.cards.decks.importer.DeckImporter;
|
||||||
|
@ -32,6 +26,13 @@ import mage.view.TableView;
|
||||||
import mage.view.TournamentTypeView;
|
import mage.view.TournamentTypeView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com, JayDi85
|
* @author BetaSteward_at_googlemail.com, JayDi85
|
||||||
*/
|
*/
|
||||||
|
@ -1259,7 +1260,7 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
||||||
tOptions.getMatchOptions().setBannedUsers(IgnoreList.ignoreList(serverAddress));
|
tOptions.getMatchOptions().setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
|
||||||
|
|
||||||
tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
|
tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
|
||||||
tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
|
tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
|
||||||
|
|
|
@ -451,10 +451,11 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
|
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
|
||||||
break;
|
break;
|
||||||
case TABLES:
|
case TABLES:
|
||||||
usedPanel.receiveMessage("", new StringBuilder("Download card images by using the \"Images\" menu to the top right .")
|
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
||||||
.append("<br/>Download icons and symbols by using the \"Symbols\" menu to the top right.")
|
usedPanel.receiveMessage("", new StringBuilder("Download card images by using the \"Images\" main menu.")
|
||||||
.append("<br/>\\list - Show a list of available chat commands.")
|
.append("<br/>Download icons and symbols by using the \"Symbols\" main menu.")
|
||||||
.append("<br/>").append(IgnoreList.usage())
|
.append("<br/>\\list - show a list of available chat commands.")
|
||||||
|
.append("<br/>").append(IgnoreList.usage(serverAddress))
|
||||||
.append("<br/>Type <font color=green>\\w yourUserName profanity 0 (or 1 or 2)</font> to turn off/on the profanity filter").toString(),
|
.append("<br/>Type <font color=green>\\w yourUserName profanity 0 (or 1 or 2)</font> to turn off/on the profanity filter").toString(),
|
||||||
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
|
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -871,7 +871,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
// Hide games of ignored players
|
// Hide games of ignored players
|
||||||
java.util.List<RowFilter<Object, Object>> ignoreListFilterList = new ArrayList<>();
|
java.util.List<RowFilter<Object, Object>> ignoreListFilterList = new ArrayList<>();
|
||||||
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
||||||
final Set<String> ignoreListCopy = IgnoreList.ignoreList(serverAddress);
|
final Set<String> ignoreListCopy = IgnoreList.getIgnoredUsers(serverAddress);
|
||||||
if (!ignoreListCopy.isEmpty()) {
|
if (!ignoreListCopy.isEmpty()) {
|
||||||
ignoreListFilterList.add(new RowFilter<Object, Object>() {
|
ignoreListFilterList.add(new RowFilter<Object, Object>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1626,7 +1626,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
options.setQuitRatio(100);
|
options.setQuitRatio(100);
|
||||||
options.setMinimumRating(0);
|
options.setMinimumRating(0);
|
||||||
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
|
||||||
options.setBannedUsers(IgnoreList.ignoreList(serverAddress));
|
options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
|
||||||
table = SessionHandler.createTable(roomId, options);
|
table = SessionHandler.createTable(roomId, options);
|
||||||
|
|
||||||
SessionHandler.joinTable(roomId, table.getTableId(), "Human", PlayerType.HUMAN, 1, testDeck, "");
|
SessionHandler.joinTable(roomId, table.getTableId(), "Human", PlayerType.HUMAN, 1, testDeck, "");
|
||||||
|
|
|
@ -1,46 +1,51 @@
|
||||||
package mage.client.util;
|
package mage.client.util;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Set;
|
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.preference.MagePreferences;
|
import mage.client.preference.MagePreferences;
|
||||||
import mage.view.ChatMessage;
|
import mage.view.ChatMessage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public final class IgnoreList {
|
public final class IgnoreList {
|
||||||
|
|
||||||
private static final String USAGE = "<br/><font color=yellow>\\ignore - shows your ignore list on this server."
|
private static final String USAGE = ""
|
||||||
+ "<br/>\\ignore [username] - add username to ignore list (they won't be able to chat or join to your game)."
|
+ "<br><font color=yellow>\\ignore - shows your ignore list on this server."
|
||||||
+ "<br/>\\unignore [username] - remove a username from your ignore list on this server.</font>";
|
+ "<br>\\ignore username - add username to ignore list (they won't be able to chat or join to your new game)."
|
||||||
|
+ "<br>\\unignore username - remove a username from your ignore list on this server.</font>";
|
||||||
|
|
||||||
public static final int MAX_IGNORE_LIST_SIZE = 50;
|
public static final int MAX_IGNORE_LIST_SIZE = 100;
|
||||||
public static final Set<ChatMessage.MessageType> IGNORED_MESSAGE_TYPES
|
public static final Set<ChatMessage.MessageType> IGNORED_MESSAGE_TYPES
|
||||||
= ImmutableSet.of(ChatMessage.MessageType.TALK,
|
= ImmutableSet.of(ChatMessage.MessageType.TALK,
|
||||||
ChatMessage.MessageType.WHISPER_FROM);
|
ChatMessage.MessageType.WHISPER_FROM);
|
||||||
|
|
||||||
public static String usage() {
|
public static String usage(String serverAddress) {
|
||||||
return USAGE;
|
return "<br>Your ignored list on server " + serverAddress + ": " + getIgnoredUsers(serverAddress).size()
|
||||||
|
+ USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> ignoreList(String serverAddress) {
|
public static Set<String> getIgnoredUsers(String serverAddress) {
|
||||||
return MagePreferences.ignoreList(serverAddress);
|
return MagePreferences.ignoreList(serverAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String ignoreListString(String serverAddress) {
|
public static String getIgnoreListInfo(String serverAddress) {
|
||||||
final String[] list = MagePreferences.ignoreList(serverAddress).toArray(new String[0]);
|
List<String> list = new ArrayList<>(getIgnoredUsers(serverAddress));
|
||||||
Arrays.sort(list);
|
Collections.sort(list);
|
||||||
return "<font color=yellow>Current ignore list on " + serverAddress + ": "
|
return "<font color=yellow>Current ignore list on " + serverAddress + " (" + list.size() + "): "
|
||||||
+ Arrays.toString(list)
|
+ String.join(", ", list)
|
||||||
+ "</font>";
|
+ "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String ignore(String serverAddress, String user) {
|
public static String ignore(String serverAddress, String user) {
|
||||||
if (user == null || user.isEmpty()) {
|
if (user == null || user.isEmpty()) {
|
||||||
return ignoreListString(serverAddress);
|
return getIgnoreListInfo(serverAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MagePreferences.ignoreList(serverAddress).size() >= MAX_IGNORE_LIST_SIZE) {
|
if (MagePreferences.ignoreList(serverAddress).size() >= MAX_IGNORE_LIST_SIZE) {
|
||||||
return "Your ignore list is too big, remove a user to be able to add a new one.";
|
return "Your ignore list is too big (max " + MAX_IGNORE_LIST_SIZE + "), remove a user to be able to add a new one.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userIsIgnored(serverAddress, user)) {
|
if (userIsIgnored(serverAddress, user)) {
|
||||||
|
@ -50,7 +55,7 @@ public final class IgnoreList {
|
||||||
MagePreferences.addIgnoredUser(serverAddress, user);
|
MagePreferences.addIgnoredUser(serverAddress, user);
|
||||||
updateTablesTable();
|
updateTablesTable();
|
||||||
|
|
||||||
return "Added " + user + " to your ignore list on " + serverAddress;
|
return "Added " + user + " to your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateTablesTable() {
|
private static void updateTablesTable() {
|
||||||
|
@ -62,13 +67,13 @@ public final class IgnoreList {
|
||||||
|
|
||||||
public static String unignore(String serverAddress, String user) {
|
public static String unignore(String serverAddress, String user) {
|
||||||
if (user == null || user.isEmpty()) {
|
if (user == null || user.isEmpty()) {
|
||||||
return usage();
|
return usage(serverAddress);
|
||||||
}
|
}
|
||||||
if (MagePreferences.removeIgnoredUser(serverAddress, user)) {
|
if (MagePreferences.removeIgnoredUser(serverAddress, user)) {
|
||||||
updateTablesTable();
|
updateTablesTable();
|
||||||
return "Removed " + user + " from your ignore list on " + serverAddress;
|
return "Removed " + user + " from your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")";
|
||||||
} else {
|
} else {
|
||||||
return "No such user \"" + user + "\" on your ignore list on " + serverAddress;
|
return "No such user \"" + user + "\" on your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,14 @@ public class IgnoreListTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ignoreListEmpty() throws Exception {
|
public void ignoreListEmpty() throws Exception {
|
||||||
assertThat(IgnoreList.ignoreListString("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: []</font>"));
|
assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: []</font>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ignoreList() throws Exception {
|
public void ignoreList() throws Exception {
|
||||||
final String test = IgnoreList.ignore("test.com.xx", "test");
|
final String test = IgnoreList.ignore("test.com.xx", "test");
|
||||||
final String kranken = IgnoreList.ignore("test.com.xx", "kranken");
|
final String kranken = IgnoreList.ignore("test.com.xx", "kranken");
|
||||||
assertThat(IgnoreList.ignoreListString("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: [kranken, test]</font>"));
|
assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: [kranken, test]</font>"));
|
||||||
assertThat(test, is("Added test to your ignore list on test.com.xx"));
|
assertThat(test, is("Added test to your ignore list on test.com.xx"));
|
||||||
assertThat(kranken, is("Added kranken to your ignore list on test.com.xx"));
|
assertThat(kranken, is("Added kranken to your ignore list on test.com.xx"));
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class IgnoreListTest {
|
||||||
public void ignoreDefaultResponse() throws Exception {
|
public void ignoreDefaultResponse() throws Exception {
|
||||||
final String r1 = IgnoreList.ignore("test.com.xx", "");
|
final String r1 = IgnoreList.ignore("test.com.xx", "");
|
||||||
final String r2 = IgnoreList.ignore("test.com.xx", null);
|
final String r2 = IgnoreList.ignore("test.com.xx", null);
|
||||||
assertThat(IgnoreList.ignoreListString("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: []</font>"));
|
assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: []</font>"));
|
||||||
assertEquals(r1, r2);
|
assertEquals(r1, r2);
|
||||||
assertEquals(r2, "<font color=yellow>Current ignore list on test.com.xx: []</font>");
|
assertEquals(r2, "<font color=yellow>Current ignore list on test.com.xx: []</font>");
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class IgnoreListTest {
|
||||||
}
|
}
|
||||||
final String r = IgnoreList.ignore("test.com.xx", "lul");
|
final String r = IgnoreList.ignore("test.com.xx", "lul");
|
||||||
assertEquals(r, "Your ignore list is too big, remove a user to be able to add a new one.");
|
assertEquals(r, "Your ignore list is too big, remove a user to be able to add a new one.");
|
||||||
assertThat(IgnoreList.ignoreListString("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: [0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 6, 7, 8, 9]</font>"));
|
assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("<font color=yellow>Current ignore list on test.com.xx: [0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 6, 7, 8, 9]</font>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue