* Fixed chat command handling (\list), the user chat input is now escaped to prevent using html tags.

This commit is contained in:
LevelX2 2014-09-26 19:42:58 +02:00
parent 54ec3b658e
commit 0a068e2258
7 changed files with 53 additions and 41 deletions

View file

@ -118,19 +118,6 @@ public class ChatPanel extends javax.swing.JPanel {
DEFAULT, GAME, TABLES, TOURNAMENT DEFAULT, GAME, TABLES, TOURNAMENT
} }
private boolean startMessageDone = false; private boolean startMessageDone = false;
// /**
// * Maps message colors to {@link Color}.
// */
// private static final Map<MessageColor, Color> colorMap = new EnumMap<>(MessageColor.class);
//
// static {
// colorMap.put(MessageColor.BLACK, Color.black);
// colorMap.put(MessageColor.GREEN, Color.green);
// colorMap.put(MessageColor.ORANGE, Color.orange);
// colorMap.put(MessageColor.BLUE, Color.blue);
// colorMap.put(MessageColor.RED, Color.red);
// colorMap.put(MessageColor.YELLOW, Color.YELLOW);
// }
/** /**
* Creates new form ChatPanel * Creates new form ChatPanel
@ -243,11 +230,9 @@ public class ChatPanel extends javax.swing.JPanel {
if (username != null && !username.isEmpty()) { if (username != null && !username.isEmpty()) {
text.append(getColoredText(userColor, username + userSeparator)); text.append(getColoredText(userColor, username + userSeparator));
} }
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.PAY) + "\n")); text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.PAY) + "<br/>"));
this.txtConversation.setEditable(true);
this.txtConversation.append(text.toString()); this.txtConversation.append(text.toString());
this.txtConversation.setEditable(false);
} }
private String getColoredText(String color, String text) { private String getColoredText(String color, String text) {

View file

@ -38,9 +38,13 @@ public class ColorPane extends JTextPane {
public void append(String s) { public void append(String s) {
try { try {
setEditable(true);
kit.insertHTML(doc, doc.getLength(), s, 0, 0, null); kit.insertHTML(doc, doc.getLength(), s, 0, 0, null);
int len = getDocument().getLength();
setCaretPosition(len);
setEditable(false);
// setEditable(true); //
// //
// StyleContext sc = StyleContext.getDefaultStyleContext(); // StyleContext sc = StyleContext.getDefaultStyleContext();
// AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color); // AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
@ -51,7 +55,7 @@ public class ColorPane extends JTextPane {
// setCharacterAttributes(aset, false); // setCharacterAttributes(aset, false);
// replaceSelection(s); // replaceSelection(s);
// //
// setEditable(false); //
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -377,17 +377,17 @@ public class CallbackClientImpl implements CallbackClient {
.append("<br/><b>F5</b> - Skip to next end step of opponent's turn but stop on declare attackers/blockers and something on the stack") .append("<br/><b>F5</b> - Skip to next end step of opponent's turn but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>F9</b> - Skip everything until your next turn") .append("<br/><b>F9</b> - Skip everything until your next turn")
.append("<br/><b>F3</b> - Undo F4/F5/F9").toString(), .append("<br/><b>F3</b> - Undo F4/F5/F9").toString(),
null, MessageType.USER_INFO, ChatMessage.MessageColor.ORANGE); null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break; break;
case TOURNAMENT: case TOURNAMENT:
usedPanel.receiveMessage("", new StringBuilder("On this panel you can see the players, their state and the results of the games of the tournament. Also you can chat with the competitors of the tournament.").toString(), usedPanel.receiveMessage("", new StringBuilder("On this panel you can see the players, their state and the results of the games of the tournament. Also you can chat with the competitors of the tournament.").toString(),
null, MessageType.USER_INFO, ChatMessage.MessageColor.ORANGE); 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 .") usedPanel.receiveMessage("", new StringBuilder("Download card images by using the \"Images\" menu to the top right .")
.append("<br/>Download icons and symbols by using the \"Symbols\" menu to the top right.") .append("<br/>Download icons and symbols by using the \"Symbols\" menu to the top right.")
.append("<br/>\\list - Show a list of available chat commands.").toString(), .append("<br/>\\list - Show a list of available chat commands.").toString(),
null, MessageType.USER_INFO, ChatMessage.MessageColor.ORANGE); null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break; break;
} }

View file

@ -19,6 +19,11 @@
<artifactId>mage</artifactId> <artifactId>mage</artifactId>
<version>${mage-version}</version> <version>${mage-version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>mage-common</artifactId> <artifactId>mage-common</artifactId>

View file

@ -141,21 +141,21 @@ public class ChatManager {
User userTo = UserManager.getInstance().findUser(userToName); User userTo = UserManager.getInstance().findUser(userToName);
if (userTo != null) { if (userTo != null) {
if (!chatSessions.get(chatId).broadcastWhisperToUser(user, userTo, rest)) { if (!chatSessions.get(chatId).broadcastWhisperToUser(user, userTo, rest)) {
message += new StringBuilder("\nUser ").append(userToName).append(" not found").toString(); message += new StringBuilder("<br/>User ").append(userToName).append(" not found").toString();
chatSessions.get(chatId).broadcastInfoToUser(user,message); chatSessions.get(chatId).broadcastInfoToUser(user,message);
} }
} else { } else {
message += new StringBuilder("\nUser ").append(userToName).append(" not found").toString(); message += new StringBuilder("<br/>User ").append(userToName).append(" not found").toString();
chatSessions.get(chatId).broadcastInfoToUser(user,message); chatSessions.get(chatId).broadcastInfoToUser(user,message);
} }
return true; return true;
} }
} }
if (command.equals("L") || command.equals("LIST")) { if (command.equals("L") || command.equals("LIST")) {
message += new StringBuilder("\nList of commands:") message += new StringBuilder("<br/>List of commands:")
.append("\n\\info <text> - set a info text to your player") .append("<br/>\\info [text] - set a info text to your player")
.append("\n\\list - Show a list of commands") .append("<br/>\\list - Show a list of commands")
.append("\n\\whisper <player name> <text> - whisper to the player with the given name").toString(); .append("<br/>\\whisper [player name] [text] - whisper to the player with the given name").toString();
chatSessions.get(chatId).broadcastInfoToUser(user,message); chatSessions.get(chatId).broadcastInfoToUser(user,message);
return true; return true;
} }

View file

@ -118,7 +118,7 @@ public class ChatSession {
public boolean broadcastInfoToUser(User toUser, String message) { public boolean broadcastInfoToUser(User toUser, String message) {
if (clients.containsKey(toUser.getId())) { if (clients.containsKey(toUser.getId())) {
toUser.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(null, message, timeFormatter.format(new Date()), MessageColor.ORANGE, MessageType.USER_INFO, null))); toUser.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(null, message, timeFormatter.format(new Date()), MessageColor.BLUE, MessageType.USER_INFO, null)));
return true; return true;
} }
return false; return false;

View file

@ -28,12 +28,20 @@
package mage.server; package mage.server;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.constants.ManaType;
import mage.constants.PlayerAction;
import mage.constants.TableState;
import mage.game.GameException; import mage.game.GameException;
import mage.game.Table; import mage.game.Table;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
@ -46,7 +54,13 @@ import mage.interfaces.callback.ClientCallback;
import mage.remote.MageVersionException; import mage.remote.MageVersionException;
import mage.server.draft.CubeFactory; import mage.server.draft.CubeFactory;
import mage.server.draft.DraftManager; import mage.server.draft.DraftManager;
import mage.server.game.*; import mage.server.game.DeckValidatorFactory;
import mage.server.game.GameFactory;
import mage.server.game.GameManager;
import mage.server.game.GamesRoom;
import mage.server.game.GamesRoomManager;
import mage.server.game.PlayerFactory;
import mage.server.game.ReplayManager;
import mage.server.services.LogKeys; import mage.server.services.LogKeys;
import mage.server.services.impl.FeedbackServiceImpl; import mage.server.services.impl.FeedbackServiceImpl;
import mage.server.services.impl.LogServiceImpl; import mage.server.services.impl.LogServiceImpl;
@ -55,20 +69,24 @@ import mage.server.tournament.TournamentManager;
import mage.server.util.ConfigSettings; import mage.server.util.ConfigSettings;
import mage.server.util.ServerMessagesUtil; import mage.server.util.ServerMessagesUtil;
import mage.server.util.ThreadExecutor; import mage.server.util.ThreadExecutor;
import mage.utils.*; import mage.utils.ActionWithBooleanResult;
import mage.view.*; import mage.utils.ActionWithNullNegativeResult;
import mage.utils.ActionWithTableViewResult;
import mage.utils.CompressUtil;
import mage.utils.MageVersion;
import mage.view.ChatMessage;
import mage.view.ChatMessage.MessageColor; import mage.view.ChatMessage.MessageColor;
import mage.view.DraftPickView;
import mage.view.GameView;
import mage.view.MatchView;
import mage.view.RoomUsersView;
import mage.view.TableView;
import mage.view.TournamentView;
import mage.view.UserDataView;
import mage.view.UserView;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import mage.constants.ManaType;
import mage.constants.PlayerAction;
import mage.constants.TableState;
/** /**
* *
* @author BetaSteward_at_googlemail.com, noxx * @author BetaSteward_at_googlemail.com, noxx
@ -408,7 +426,7 @@ public class MageServerImpl implements MageServer {
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
ChatManager.getInstance().broadcast(chatId, userName, message, MessageColor.BLUE); ChatManager.getInstance().broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE);
} }
} }
); );