* UI: added turn number and step info in game logs

This commit is contained in:
Oleg Agafonov 2020-02-28 20:27:07 +04:00
parent 190c3ecc00
commit 2e73f9d1c5
21 changed files with 546 additions and 529 deletions

View file

@ -1,424 +1,420 @@
/*
* ChatPanel.java
*
* Created on 15-Dec-2009, 11:04:31 PM
*/
package mage.client.chat;
* ChatPanel.java
*
* Created on 15-Dec-2009, 11:04:31 PM
*/
package mage.client.chat;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JTextField;
import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.GUISizeHelper;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
import org.mage.card.arcane.ManaSymbols;
import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.GUISizeHelper;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
import org.mage.card.arcane.ManaSymbols;
/**
*
* @author BetaSteward_at_googlemail.com, nantuko
*/
public class ChatPanelBasic extends javax.swing.JPanel {
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Time formatter
*/
protected final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
/**
* @author BetaSteward_at_googlemail.com, nantuko
*/
public class ChatPanelBasic extends javax.swing.JPanel {
protected UUID chatId;
/**
* Chat message color for opponents.
*/
protected static final String OPPONENT_COLOR = "#FF7F50";
/**
* Chat message color for client player.
*/
protected static final String MY_COLOR = "#7FFFD4";
/**
* Chat message color for timestamps.
*/
protected static final String TIMESTAMP_COLOR = "#CCCC33";
/**
* Chat message color for messages.
*/
protected static final String MESSAGE_COLOR = "White";
/**
* Chat message color for personal infos.
*/
protected static final String USER_INFO_COLOR = "Yellow";
/**
* Chat message color for status infos.
*/
protected static final String STATUS_COLOR = "#FFCC33";
/**
* Alpha value for transparency (255 = not transparent)
*/
public static final int CHAT_ALPHA = 80;
/**
* This will be a chat that will be connected to {this} and will handle
* redirected messages; Mostly used to redirect user messages to another
* window.
*/
protected ChatPanelBasic connectedChat;
/**
* Parent chat this chat connected to. Used to send messages using parent
* chat as it is the only one connected to server.
*/
protected ChatPanelBasic parentChatRef;
/**
* Selected extended view mode.
*/
protected VIEW_MODE extendedViewMode = VIEW_MODE.NONE;
/**
* Time formatter
*/
protected final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
public enum VIEW_MODE {
protected UUID chatId;
/**
* Chat message color for opponents.
*/
protected static final String OPPONENT_COLOR = "#FF7F50";
/**
* Chat message color for client player.
*/
protected static final String MY_COLOR = "#7FFFD4";
/**
* Chat message color for timestamps.
*/
protected static final String TIMESTAMP_COLOR = "#CCCC33";
/**
* Chat message color for messages.
*/
protected static final String MESSAGE_COLOR = "White";
/**
* Chat message color for personal infos.
*/
protected static final String USER_INFO_COLOR = "Yellow";
/**
* Chat message color for status infos.
*/
protected static final String STATUS_COLOR = "#FFCC33";
/**
* Alpha value for transparency (255 = not transparent)
*/
public static final int CHAT_ALPHA = 80;
/**
* This will be a chat that will be connected to {this} and will handle
* redirected messages; Mostly used to redirect user messages to another
* window.
*/
protected ChatPanelBasic connectedChat;
/**
* Parent chat this chat connected to. Used to send messages using parent
* chat as it is the only one connected to server.
*/
protected ChatPanelBasic parentChatRef;
/**
* Selected extended view mode.
*/
protected VIEW_MODE extendedViewMode = VIEW_MODE.NONE;
NONE, GAME, CHAT
}
/**
* Controls the output start messages as the chat panel is created
*
*/
protected ChatType chatType = ChatType.DEFAULT;
public enum VIEW_MODE {
public enum ChatType {
NONE, GAME, CHAT
}
DEFAULT, GAME, TABLES, TOURNAMENT
}
protected boolean startMessageDone = false;
/**
* Controls the output start messages as the chat panel is created
*/
protected ChatType chatType = ChatType.DEFAULT;
/**
*
* Creates new form ChatPanel
*
*/
public ChatPanelBasic() {
initComponents();
setBackground(new Color(0, 0, 0, CHAT_ALPHA));
changeGUISize(GUISizeHelper.chatFont);
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setBackground(new Color(0, 0, 0, CHAT_ALPHA));
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, CHAT_ALPHA));
jScrollPaneTxt.setViewportBorder(null);
}
}
public enum ChatType {
public void cleanUp() {
DEFAULT, GAME, TABLES, TOURNAMENT
}
}
protected boolean startMessageDone = false;
public void changeGUISize(Font font) {
txtConversation.setFont(font);
txtMessage.setFont(font);
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setFont(font);
jScrollPaneTxt.getVerticalScrollBar().setPreferredSize(new Dimension(GUISizeHelper.scrollBarSize, 0));
jScrollPaneTxt.getHorizontalScrollBar().setPreferredSize(new Dimension(0, GUISizeHelper.scrollBarSize));
}
int height = 30;
if (font.getSize() > 20) {
height = 30 + Math.min(font.getSize() - 10, 30);
}
txtMessage.setMinimumSize(new Dimension(20, height));
txtMessage.setMaximumSize(new Dimension(txtMessage.getWidth(), height));
txtMessage.setPreferredSize(new Dimension(txtMessage.getWidth(), height));
txtMessage.setSize(new Dimension(txtMessage.getWidth(), height));
if (connectedChat != null) {
connectedChat.changeGUISize(font);
}
}
/**
* Creates new form ChatPanel
*/
public ChatPanelBasic() {
initComponents();
setBackground(new Color(0, 0, 0, CHAT_ALPHA));
changeGUISize(GUISizeHelper.chatFont);
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setBackground(new Color(0, 0, 0, CHAT_ALPHA));
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, CHAT_ALPHA));
jScrollPaneTxt.setViewportBorder(null);
}
}
public ChatType getChatType() {
return chatType;
}
public void cleanUp() {
public void setChatType(ChatType chatType) {
this.chatType = chatType;
}
}
public boolean isStartMessageDone() {
return startMessageDone;
}
public void changeGUISize(Font font) {
txtConversation.setFont(font);
txtMessage.setFont(font);
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setFont(font);
jScrollPaneTxt.getVerticalScrollBar().setPreferredSize(new Dimension(GUISizeHelper.scrollBarSize, 0));
jScrollPaneTxt.getHorizontalScrollBar().setPreferredSize(new Dimension(0, GUISizeHelper.scrollBarSize));
}
int height = 30;
if (font.getSize() > 20) {
height = 30 + Math.min(font.getSize() - 10, 30);
}
txtMessage.setMinimumSize(new Dimension(20, height));
txtMessage.setMaximumSize(new Dimension(txtMessage.getWidth(), height));
txtMessage.setPreferredSize(new Dimension(txtMessage.getWidth(), height));
txtMessage.setSize(new Dimension(txtMessage.getWidth(), height));
if (connectedChat != null) {
connectedChat.changeGUISize(font);
}
}
public void setStartMessageDone(boolean startMessageDone) {
this.startMessageDone = startMessageDone;
}
public ChatType getChatType() {
return chatType;
}
public void connect(UUID chatId) {
this.chatId = chatId;
if (SessionHandler.joinChat(chatId)) {
MageFrame.addChat(chatId, this);
}
}
public void setChatType(ChatType chatType) {
this.chatType = chatType;
}
public void disconnect() {
if (SessionHandler.getSession() != null) {
SessionHandler.leaveChat(chatId);
MageFrame.removeChat(chatId);
}
}
public boolean isStartMessageDone() {
return startMessageDone;
}
Pattern profanityPattern = Pattern.compile(".*(1ab1a|1d1ot|13p3r|13sb1ans|13sbo|13s13|13sb1an|13sbo|13sy|1nbr3d|1nc3st|1njun|1ub3|\\Wbj|\\Wcum|\\Wdum|\\Wfag|\\Wfap|\\W[sf]uk|\\Wj1s|\\Wp3do|\\Wp33|\\Wpoo\\W|\\Wt1t|aho13|an1ngu|ana1|anus|ar3o1a|ar3o13|ary1an|axyx|axyxhat|axyxho13|axyxmast3r|axyxmunch|axyxw1p3|b1atch|b1gt1t|b1mbo|b1ow|b1tch|ba1s|bab3|bang|barf|bastard|bawdy|b3an3r|b3ard3dc1am|b3ast1a1ty|b3atch|b3at3r|b3av3r|b3otch|b3yotch|bo1nk|bod1y|bon3d|bon3r|bon3|bob|bot13|boty|bow31|br3ast|bug3r|bukak3|bung|busty|buxyx|c1t|caca|cahon3|cam31to3|carp3tmunch3r|cawk|c3rv1x|ch1nc|ch1nk|chod3|co1ta1|cockb1ock|cockho1st3r|cocknock3r|cocksmok3r|cocksuck3r|cock|condom|corksuck3r|crabs|cums1ut|cumshot|cumsta1n|cnt|cun1ngus|cuntfac3|cunthunt3r|cunt|d1ck|d1k3|d1do|d1mw1t|d1ng13|d1psh1p|dago|dam1t|damn1t|damn3d|damn|dawg13sty13|dog13sty13|dogysty13|dong|dop3y|douch3|drunk|dumb|dumas|dum|dumbas|dumy|dyk3|3jacu1at3|3n1arg3m3nt|3r3ct1on|3r3ct|3rot1c|3xtacy|3xtasy|f.ck|f1osy|f1st3d|f1st1ng|f1sty|fa1gt|fa1g|fack|fag1t|fag3d|fagot|fag|[sf]cuk|f31at1o|f31at3|f31ch1ng|f31ch3r|f31ch|f31tch3r|f31tch|foad|fobar|fond13|for3sk1n|fu.k|fudg3pack3r|[sf]uk|g1ans|g1go1o|ganja|ghay|gh3y|go1d3nshow3r|gonad|gok|gr1ngo|h1t13r|handjob|hardon|hokah|hok3r|homo|honky|hor|hotch|hot3r|horny|hump1ng|hump3d|hump|hym3n|j1sm|j1s3d|j1sm|j1s|jackas|jackho13|jackof|j3rk3d|j3rkof|j3rk|junk13|junky|k1an|k1k3|k1nky|knob3nd|kyk3|mams|masa|mast3rba|masturba|max1|m3ns3s|m3nstruat|m[sf]uck1ng|mofo|moron|moth3rf|mthrf|muf|n1ger|n1ga|n1mrod|n1ny|n1p13|nak3d|napa1m|napy|nas1|n3gro|noky|nympho|op1at3|op1um|ora1y|ora1|org13s|organ|orgasm|orgy|ovary|ovum|p1owb1t3r|p1mp|p1nko|p1s3d|p1sof|p1s|pak1|pant13|panty|past13|pasty|p3ck3r|p3doph1|p3p3|p3n1a1|p3n13|p3n1s|p3n3trat1on|p3n3trat3|p3rv3rs1on|p3yot3|pha1c|phuck|po1ack|po1ock|pontang|pop|pr1ck|pr1g|pron|pub1|pub3|punkas|punky|pus1|pusy|puto|qu1cky|qu1ck13|qu1m|qu3af|qu3ro|qu3rs|qu3r|r1mjob|r1tard|racy|rap1st|rap3d|rap3r|rap3|raunch|r31ch|r3cta1|r3ctum|r3ctus|r3tard|r3tar|rtard|rumpram3r|rump|s1av3|s13as|s1ut|sack|sad1s|scag|sch1ong|sch1so|scr3w|scrog|scrot|scrud|scum|s3aman|s3am3n|s3duc3|s3m3n|s3xua1|sh1t|skag|skank|sm3gma|smut|sn1p3r|snatch|sodom|sp1ck|sp1c|sp1k|sp3rm|spunk|st3amy|stfu|ston3d|str1p|strok3|stup1d|suck|sumofab1atch|t1nk13|t1t[sf]uck|tampon|tard|t3abag1ng|t3at|t3st1|t3st3|t3urd|thrust|tramp|trans|trashy|twat|ug1y|unw3d|ur1n3a|ut3rus|vag1na|vu1gar|vu1va|w1g3r|wang|wank3r|wank|w31n3r|w31rdo|w3dg13|w3n13|w3tback|w3w3|wh1t3y|wh1s|whor3).*");
Pattern profanity2Pattern = Pattern.compile(".*(1ab1a|1d1ot|13p3r|13sb1ans|13sbo|13s13|13sb1an|13sbo|13sy|1nbr3d|1nc3st|1njun|1ub3|\\Wbj|\\Wcum|\\Wdum|\\Wfag|\\Wfap|\\W[sf]uk|\\Wj1s|\\Wp3do|\\Wp3|\\Wpo\\W|\\Wt1t|aho13|an1ngu|ana1|anus|ar3o1a|ar3o13|ary1an|axyx|axyxhat|axyxho13|axyxmast3r|axyxmunch|axyxw1p3|b1atch|b1gt1t|b1mbo|b1ow|b1tch|ba1s|bab3|bang|barf|bastard|bawdy|b3an3r|b3ard3dc1am|b3ast1a1ty|b3atch|b3at3r|b3av3r|b3otch|b3yotch|bo1nk|bod1y|bon3d|bon3r|bon3|bob|bot13|boty|bow31|br3ast|bug3r|bukak3|bung|busty|buxyx|c1t|caca|cahon3|cam31to3|carp3tmunch3r|cawk|c3rv1x|ch1nc|ch1nk|chod3|co1ta1|cockb1ock|cockho1st3r|cocknock3r|cocksmok3r|cocksuck3r|cock|condom|corksuck3r|crabs|cums1ut|cumshot|cumsta1n|cnt|cun1ngus|cuntfac3|cunthunt3r|cunt|d1ck|d1k3|d1do|d1mw1t|d1ng13|d1psh1p|dago|dam1t|damn1t|damn3d|damn|dawg13sty13|dog13sty13|dogysty13|dong|dop3y|douch3|drunk|dumb|dum|dumas|dumbas|dumy|dyk3|3jacu1at3|3n1arg3m3nt|3r3ct1on|3r3ct|3rot1c|3xtacy|3xtasy|f.ck|f1osy|f1st3d|f1st1ng|f1sty|fa1gt|fa1g|fack|fag1t|fag3d|fagot|fag|[sf]cuk|f31at1o|f31at3|f31ch1ng|f31ch3r|f31ch|f31tch3r|f31tch|foad|fobar|fond13|for3sk1n|fu.k|fudg3pack3r|[sf]uk|g1ans|g1go1o|ganja|ghay|gh3y|go1d3nshow3r|gonad|gr1ngo|h1t13r|handjob|hardon|hokah|hok3r|homo|honky|hor|hotch|hot3r|horny|hump1ng|hump3d|hump|hym3n|j1sm|j1s3d|j1sm|j1s|jackas|jackho13|jackof|j3rk3d|j3rkof|j3rk|junk13|junky|k1an|k1k3|k1nky|knob3nd|kyk3|mams|masa|mast3rba|masturba|max1|m3ns3s|m3nstruat|m[sf]uck1ng|mofo|moron|moth3rf|mthrf|muf|n1ga|n1ger|n1mrod|n1ny|n1p13|nak3d|napa1m|napy|nas1|n3gro|noky|nympho|op1at3|op1um|ora1y|ora1|org13s|organ|orgasm|orgy|ovary|ovum|p1owb1t3r|p1mp|p1nko|p1s3d|p1sof|p1s|pak1|pant13|panty|past13|pasty|p3ck3r|p3doph1|p3p3|p3n1a1|p3n13|p3n1s|p3n3trat1on|p3n3trat3|p3rv3rs1on|p3yot3|pha1c|phuck|po1ack|po1ock|pontang|pop|porno|porn|pr1ck|pr1g|pron|pub1|pub3|punkas|punky|pus1|pusy|puto|qu1cky|qu1ck13|qu1m|qu3af|qu3ro|qu3rs|qu3r|r1mjob|r1tard|racy|rap1st|rap3d|rap3r|rap3|raunch|r31ch|r3cta1|r3ctum|r3ctus|r3tard|r3tar|rtard|rumpram3r|rump|s1av3|s13as|s1ut|sack|sad1s|scag|sch1ong|sch1so|scr3w|scrog|scrot|scrud|scum|s3aman|s3am3n|s3duc3|s3m3n|s3xua1|sh1t|skag|skank|sm3gma|smut|sn1p3r|snatch|sodom|sp1ck|sp1c|sp1k|sp3rm|spunk|st3amy|stfu|ston3d|str1p|strok3|stup1d|suck|sumofab1atch|t1nk13|t1t[sf]uck|tampon|tard|t3abag1ng|t3at|t3st1|t3st3|t3urd|thrust|tramp|trans|trashy|twat|ug1y|unw3d|ur1n3a|ut3rus|vag1na|vu1gar|vu1va|w1g3r|wang|wank3r|wank|w31n3r|w31rdo|w3dg13|w3n13|w3tback|w3w3|wh1t3y|wh1s|whor3).*");
public void setStartMessageDone(boolean startMessageDone) {
this.startMessageDone = startMessageDone;
}
private boolean containsSwearing(String message, String level) {
public void connect(UUID chatId) {
this.chatId = chatId;
if (SessionHandler.joinChat(chatId)) {
MageFrame.addChat(chatId, this);
}
}
if (level.equals("0")) {
return false;
}
message = '.' + message + '.';
public void disconnect() {
if (SessionHandler.getSession() != null) {
SessionHandler.leaveChat(chatId);
MageFrame.removeChat(chatId);
}
}
message = message.toLowerCase(Locale.ENGLISH);
message = message.replaceAll("[a@]([s5][s5]+)", "axyx");
message = message.replaceAll("b.([t\\+][t\\+]+)", "buxyx");
message = message.replaceAll("(.)(\\1{1,})", "$1");
message = message.replaceAll("[@]", "a");
message = message.replaceAll("[il]", "1");
message = message.replaceAll("[e]", "3");
message = message.replaceAll("[0]", "o");
message = message.replaceAll("[5z]", "s");
message = message.replaceAll("\\W", ".");
message = message.replaceAll("(.)(\\1{1,})", "$1");
message = message.replaceAll("\\.", "");
Pattern profanityPattern = Pattern.compile(".*(1ab1a|1d1ot|13p3r|13sb1ans|13sbo|13s13|13sb1an|13sbo|13sy|1nbr3d|1nc3st|1njun|1ub3|\\Wbj|\\Wcum|\\Wdum|\\Wfag|\\Wfap|\\W[sf]uk|\\Wj1s|\\Wp3do|\\Wp33|\\Wpoo\\W|\\Wt1t|aho13|an1ngu|ana1|anus|ar3o1a|ar3o13|ary1an|axyx|axyxhat|axyxho13|axyxmast3r|axyxmunch|axyxw1p3|b1atch|b1gt1t|b1mbo|b1ow|b1tch|ba1s|bab3|bang|barf|bastard|bawdy|b3an3r|b3ard3dc1am|b3ast1a1ty|b3atch|b3at3r|b3av3r|b3otch|b3yotch|bo1nk|bod1y|bon3d|bon3r|bon3|bob|bot13|boty|bow31|br3ast|bug3r|bukak3|bung|busty|buxyx|c1t|caca|cahon3|cam31to3|carp3tmunch3r|cawk|c3rv1x|ch1nc|ch1nk|chod3|co1ta1|cockb1ock|cockho1st3r|cocknock3r|cocksmok3r|cocksuck3r|cock|condom|corksuck3r|crabs|cums1ut|cumshot|cumsta1n|cnt|cun1ngus|cuntfac3|cunthunt3r|cunt|d1ck|d1k3|d1do|d1mw1t|d1ng13|d1psh1p|dago|dam1t|damn1t|damn3d|damn|dawg13sty13|dog13sty13|dogysty13|dong|dop3y|douch3|drunk|dumb|dumas|dum|dumbas|dumy|dyk3|3jacu1at3|3n1arg3m3nt|3r3ct1on|3r3ct|3rot1c|3xtacy|3xtasy|f.ck|f1osy|f1st3d|f1st1ng|f1sty|fa1gt|fa1g|fack|fag1t|fag3d|fagot|fag|[sf]cuk|f31at1o|f31at3|f31ch1ng|f31ch3r|f31ch|f31tch3r|f31tch|foad|fobar|fond13|for3sk1n|fu.k|fudg3pack3r|[sf]uk|g1ans|g1go1o|ganja|ghay|gh3y|go1d3nshow3r|gonad|gok|gr1ngo|h1t13r|handjob|hardon|hokah|hok3r|homo|honky|hor|hotch|hot3r|horny|hump1ng|hump3d|hump|hym3n|j1sm|j1s3d|j1sm|j1s|jackas|jackho13|jackof|j3rk3d|j3rkof|j3rk|junk13|junky|k1an|k1k3|k1nky|knob3nd|kyk3|mams|masa|mast3rba|masturba|max1|m3ns3s|m3nstruat|m[sf]uck1ng|mofo|moron|moth3rf|mthrf|muf|n1ger|n1ga|n1mrod|n1ny|n1p13|nak3d|napa1m|napy|nas1|n3gro|noky|nympho|op1at3|op1um|ora1y|ora1|org13s|organ|orgasm|orgy|ovary|ovum|p1owb1t3r|p1mp|p1nko|p1s3d|p1sof|p1s|pak1|pant13|panty|past13|pasty|p3ck3r|p3doph1|p3p3|p3n1a1|p3n13|p3n1s|p3n3trat1on|p3n3trat3|p3rv3rs1on|p3yot3|pha1c|phuck|po1ack|po1ock|pontang|pop|pr1ck|pr1g|pron|pub1|pub3|punkas|punky|pus1|pusy|puto|qu1cky|qu1ck13|qu1m|qu3af|qu3ro|qu3rs|qu3r|r1mjob|r1tard|racy|rap1st|rap3d|rap3r|rap3|raunch|r31ch|r3cta1|r3ctum|r3ctus|r3tard|r3tar|rtard|rumpram3r|rump|s1av3|s13as|s1ut|sack|sad1s|scag|sch1ong|sch1so|scr3w|scrog|scrot|scrud|scum|s3aman|s3am3n|s3duc3|s3m3n|s3xua1|sh1t|skag|skank|sm3gma|smut|sn1p3r|snatch|sodom|sp1ck|sp1c|sp1k|sp3rm|spunk|st3amy|stfu|ston3d|str1p|strok3|stup1d|suck|sumofab1atch|t1nk13|t1t[sf]uck|tampon|tard|t3abag1ng|t3at|t3st1|t3st3|t3urd|thrust|tramp|trans|trashy|twat|ug1y|unw3d|ur1n3a|ut3rus|vag1na|vu1gar|vu1va|w1g3r|wang|wank3r|wank|w31n3r|w31rdo|w3dg13|w3n13|w3tback|w3w3|wh1t3y|wh1s|whor3).*");
Pattern profanity2Pattern = Pattern.compile(".*(1ab1a|1d1ot|13p3r|13sb1ans|13sbo|13s13|13sb1an|13sbo|13sy|1nbr3d|1nc3st|1njun|1ub3|\\Wbj|\\Wcum|\\Wdum|\\Wfag|\\Wfap|\\W[sf]uk|\\Wj1s|\\Wp3do|\\Wp3|\\Wpo\\W|\\Wt1t|aho13|an1ngu|ana1|anus|ar3o1a|ar3o13|ary1an|axyx|axyxhat|axyxho13|axyxmast3r|axyxmunch|axyxw1p3|b1atch|b1gt1t|b1mbo|b1ow|b1tch|ba1s|bab3|bang|barf|bastard|bawdy|b3an3r|b3ard3dc1am|b3ast1a1ty|b3atch|b3at3r|b3av3r|b3otch|b3yotch|bo1nk|bod1y|bon3d|bon3r|bon3|bob|bot13|boty|bow31|br3ast|bug3r|bukak3|bung|busty|buxyx|c1t|caca|cahon3|cam31to3|carp3tmunch3r|cawk|c3rv1x|ch1nc|ch1nk|chod3|co1ta1|cockb1ock|cockho1st3r|cocknock3r|cocksmok3r|cocksuck3r|cock|condom|corksuck3r|crabs|cums1ut|cumshot|cumsta1n|cnt|cun1ngus|cuntfac3|cunthunt3r|cunt|d1ck|d1k3|d1do|d1mw1t|d1ng13|d1psh1p|dago|dam1t|damn1t|damn3d|damn|dawg13sty13|dog13sty13|dogysty13|dong|dop3y|douch3|drunk|dumb|dum|dumas|dumbas|dumy|dyk3|3jacu1at3|3n1arg3m3nt|3r3ct1on|3r3ct|3rot1c|3xtacy|3xtasy|f.ck|f1osy|f1st3d|f1st1ng|f1sty|fa1gt|fa1g|fack|fag1t|fag3d|fagot|fag|[sf]cuk|f31at1o|f31at3|f31ch1ng|f31ch3r|f31ch|f31tch3r|f31tch|foad|fobar|fond13|for3sk1n|fu.k|fudg3pack3r|[sf]uk|g1ans|g1go1o|ganja|ghay|gh3y|go1d3nshow3r|gonad|gr1ngo|h1t13r|handjob|hardon|hokah|hok3r|homo|honky|hor|hotch|hot3r|horny|hump1ng|hump3d|hump|hym3n|j1sm|j1s3d|j1sm|j1s|jackas|jackho13|jackof|j3rk3d|j3rkof|j3rk|junk13|junky|k1an|k1k3|k1nky|knob3nd|kyk3|mams|masa|mast3rba|masturba|max1|m3ns3s|m3nstruat|m[sf]uck1ng|mofo|moron|moth3rf|mthrf|muf|n1ga|n1ger|n1mrod|n1ny|n1p13|nak3d|napa1m|napy|nas1|n3gro|noky|nympho|op1at3|op1um|ora1y|ora1|org13s|organ|orgasm|orgy|ovary|ovum|p1owb1t3r|p1mp|p1nko|p1s3d|p1sof|p1s|pak1|pant13|panty|past13|pasty|p3ck3r|p3doph1|p3p3|p3n1a1|p3n13|p3n1s|p3n3trat1on|p3n3trat3|p3rv3rs1on|p3yot3|pha1c|phuck|po1ack|po1ock|pontang|pop|porno|porn|pr1ck|pr1g|pron|pub1|pub3|punkas|punky|pus1|pusy|puto|qu1cky|qu1ck13|qu1m|qu3af|qu3ro|qu3rs|qu3r|r1mjob|r1tard|racy|rap1st|rap3d|rap3r|rap3|raunch|r31ch|r3cta1|r3ctum|r3ctus|r3tard|r3tar|rtard|rumpram3r|rump|s1av3|s13as|s1ut|sack|sad1s|scag|sch1ong|sch1so|scr3w|scrog|scrot|scrud|scum|s3aman|s3am3n|s3duc3|s3m3n|s3xua1|sh1t|skag|skank|sm3gma|smut|sn1p3r|snatch|sodom|sp1ck|sp1c|sp1k|sp3rm|spunk|st3amy|stfu|ston3d|str1p|strok3|stup1d|suck|sumofab1atch|t1nk13|t1t[sf]uck|tampon|tard|t3abag1ng|t3at|t3st1|t3st3|t3urd|thrust|tramp|trans|trashy|twat|ug1y|unw3d|ur1n3a|ut3rus|vag1na|vu1gar|vu1va|w1g3r|wang|wank3r|wank|w31n3r|w31rdo|w3dg13|w3n13|w3tback|w3w3|wh1t3y|wh1s|whor3).*");
Matcher matchPattern = profanityPattern.matcher(message);
if (matchPattern.find()) {
return true;
}
private boolean containsSwearing(String message, String level) {
if (level.equals("2")) {
message = message.replaceAll("\\.", "");
message = '.' + message + '.';
matchPattern = profanity2Pattern.matcher(message);
if (matchPattern.find()) {
return true;
}
}
return false;
}
if (level.equals("0")) {
return false;
}
message = '.' + message + '.';
/**
* Display message in the chat. Use different colors for timestamp, username
* and message.
*
* @param username message sender
* @param message message itself
* @param time timestamp
* @param messageType
* @param color Preferred color. Not used.
*/
Pattern cardNamePattern = Pattern.compile(".*<font bgcolor=orange.*?</font>.*");
message = message.toLowerCase(Locale.ENGLISH);
message = message.replaceAll("[a@]([s5][s5]+)", "axyx");
message = message.replaceAll("b.([t\\+][t\\+]+)", "buxyx");
message = message.replaceAll("(.)(\\1{1,})", "$1");
message = message.replaceAll("[@]", "a");
message = message.replaceAll("[il]", "1");
message = message.replaceAll("[e]", "3");
message = message.replaceAll("[0]", "o");
message = message.replaceAll("[5z]", "s");
message = message.replaceAll("\\W", ".");
message = message.replaceAll("(.)(\\1{1,})", "$1");
message = message.replaceAll("\\.", "");
public void receiveMessage(String username, String message, Date time, MessageType messageType, MessageColor color) {
StringBuilder text = new StringBuilder();
if (time != null) {
text.append(getColoredText(TIMESTAMP_COLOR, timeFormatter.format(time) + ": "));
}
String userColor;
String textColor;
String userSeparator = " ";
switch (messageType) {
case STATUS: // a message to all chat user
textColor = STATUS_COLOR;
userColor = STATUS_COLOR;
break;
case USER_INFO: // a personal message
textColor = USER_INFO_COLOR;
userColor = USER_INFO_COLOR;
break;
default:
userColor = SessionHandler.getUserName().equals(username) ? MY_COLOR : OPPONENT_COLOR;
textColor = MESSAGE_COLOR;
userSeparator = ": ";
}
if (color == MessageColor.ORANGE) {
textColor = "Orange";
}
if (color == MessageColor.YELLOW) {
textColor = "Yellow";
}
if (messageType == MessageType.WHISPER_FROM) {
if (username.equalsIgnoreCase(SessionHandler.getUserName())) {
if (message.toLowerCase(Locale.ENGLISH).startsWith("profanity 0")) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0");
} else if (message.toLowerCase(Locale.ENGLISH).startsWith("profanity 1")) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "1");
} else if (message.toLowerCase(Locale.ENGLISH).startsWith("profanity 2")) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "2");
}
}
username = "Whisper from " + username;
}
if (messageType == MessageType.WHISPER_TO) {
username = "Whisper to " + username;
}
Matcher matchPattern = profanityPattern.matcher(message);
if (matchPattern.find()) {
return true;
}
Matcher matchPattern = cardNamePattern.matcher(message);
String messageToTest = message;
while (matchPattern.find()) {
messageToTest = message.replaceFirst("<font bgcolor=orange.*?</font>", "");
}
if (level.equals("2")) {
message = message.replaceAll("\\.", "");
message = '.' + message + '.';
matchPattern = profanity2Pattern.matcher(message);
return matchPattern.find();
}
return false;
}
if (messageType == MessageType.USER_INFO || messageType == MessageType.GAME || messageType == MessageType.STATUS
|| PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("0")
|| !PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("0") && !containsSwearing(messageToTest, PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0"))) {
if (username != null && !username.isEmpty()) {
text.append(getColoredText(userColor, username + userSeparator));
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("1")) {
if (username != null && !username.isEmpty()) {
text.append(getColoredText("black", username + userSeparator));
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML("<font color=black size=-2>" + message + "</font> <font size=-2>Profanity detected. Type: <font color=green>/w " + SessionHandler.getUserName() + " profanity 0</font>' to turn the filter off</font></font>", ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("2")) {
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML("<font color=black size=-2>" + username + ": Profanity detected. To make it less strict, type: </font> <font color=green size=-2>/w " + SessionHandler.getUserName() + " profanity 1</font>", ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
}
}
Pattern cardNamePattern = Pattern.compile(".*<font bgcolor=orange.*?</font>.*");
protected String getColoredText(String color, String text) {
return "<font color='" + color + "'>" + text + "</font>";
}
/**
* Display message in the chat. Use different colors for timestamp, username
* and message.
*
* @param username message sender
* @param message message itself
* @param time timestamp
* @param turnInfo game turn info, can be null for non game messages
* @param messageType
* @param color Preferred color. Not used.
*/
public void receiveMessage(String username, String message, Date time, String turnInfo, MessageType messageType, MessageColor color) {
StringBuilder text = new StringBuilder();
if (time != null) {
text.append(getColoredText(TIMESTAMP_COLOR, timeFormatter.format(time) + (turnInfo == null ? "" : ", " + turnInfo) + ": "));
}
String userColor;
String textColor;
String userSeparator = " ";
switch (messageType) {
case STATUS: // a message to all chat user
textColor = STATUS_COLOR;
userColor = STATUS_COLOR;
break;
case USER_INFO: // a personal message
textColor = USER_INFO_COLOR;
userColor = USER_INFO_COLOR;
break;
default:
userColor = SessionHandler.getUserName().equals(username) ? MY_COLOR : OPPONENT_COLOR;
textColor = MESSAGE_COLOR;
userSeparator = ": ";
}
if (color == MessageColor.ORANGE) {
textColor = "Orange";
}
if (color == MessageColor.YELLOW) {
textColor = "Yellow";
}
if (messageType == MessageType.WHISPER_FROM) {
if (username.equalsIgnoreCase(SessionHandler.getUserName())) {
if (message.toLowerCase(Locale.ENGLISH).startsWith("profanity 0")) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0");
} else if (message.toLowerCase(Locale.ENGLISH).startsWith("profanity 1")) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "1");
} else if (message.toLowerCase(Locale.ENGLISH).startsWith("profanity 2")) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "2");
}
}
username = "Whisper from " + username;
}
if (messageType == MessageType.WHISPER_TO) {
username = "Whisper to " + username;
}
public String getText() {
return txtConversation.getText();
}
Matcher matchPattern = cardNamePattern.matcher(message);
String messageToTest = message;
while (matchPattern.find()) {
messageToTest = message.replaceFirst("<font bgcolor=orange.*?</font>", "");
}
public ChatPanelBasic getConnectedChat() {
return connectedChat;
}
if (messageType == MessageType.USER_INFO || messageType == MessageType.GAME || messageType == MessageType.STATUS
|| PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("0")
|| !PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("0") && !containsSwearing(messageToTest, PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0"))) {
if (username != null && !username.isEmpty()) {
text.append(getColoredText(userColor, username + userSeparator));
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("1")) {
if (username != null && !username.isEmpty()) {
text.append(getColoredText("black", username + userSeparator));
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML("<font color=black size=-2>" + message + "</font> <font size=-2>Profanity detected. Type: <font color=green>/w " + SessionHandler.getUserName() + " profanity 0</font>' to turn the filter off</font></font>", ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("2")) {
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML("<font color=black size=-2>" + username + ": Profanity detected. To make it less strict, type: </font> <font color=green size=-2>/w " + SessionHandler.getUserName() + " profanity 1</font>", ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
}
}
public void setConnectedChat(ChatPanelBasic connectedChat) {
this.connectedChat = connectedChat;
}
protected String getColoredText(String color, String text) {
return "<font color='" + color + "'>" + text + "</font>";
}
public void setParentChat(ChatPanelBasic parentChatRef) {
this.parentChatRef = parentChatRef;
}
public String getText() {
return txtConversation.getText();
}
public ChatPanelBasic getParentChatRef() {
return parentChatRef;
}
public ChatPanelBasic getConnectedChat() {
return connectedChat;
}
public void setParentChatRef(ChatPanelBasic parentChatRef) {
this.parentChatRef = parentChatRef;
}
public void setConnectedChat(ChatPanelBasic connectedChat) {
this.connectedChat = connectedChat;
}
public void disableInput() {
this.txtMessage.setVisible(false);
}
public void setParentChat(ChatPanelBasic parentChatRef) {
this.parentChatRef = parentChatRef;
}
public JTextField getTxtMessageInputComponent() {
return this.txtMessage;
}
public ChatPanelBasic getParentChatRef() {
return parentChatRef;
}
public void useExtendedView(VIEW_MODE extendedViewMode) {
this.extendedViewMode = extendedViewMode;
int alpha = 255;
switch (chatType) {
case GAME:
case TABLES:
case DEFAULT:
alpha = CHAT_ALPHA;
}
this.txtConversation.setExtBackgroundColor(new Color(0, 0, 0, alpha)); // Alpha = 255 not transparent
this.txtConversation.setSelectionColor(Color.LIGHT_GRAY);
this.jScrollPaneTxt.setOpaque(alpha == 255);
this.jScrollPaneTxt.getViewport().setOpaque(chatType != ChatType.TABLES);
}
public void setParentChatRef(ChatPanelBasic parentChatRef) {
this.parentChatRef = parentChatRef;
}
public void clear() {
this.txtConversation.setText("");
}
public void disableInput() {
this.txtMessage.setVisible(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
public JTextField getTxtMessageInputComponent() {
return this.txtMessage;
}
jScrollPaneTxt = new javax.swing.JScrollPane();
txtConversation = new mage.client.components.ColorPane();
txtMessage = new javax.swing.JTextField();
public void useExtendedView(VIEW_MODE extendedViewMode) {
this.extendedViewMode = extendedViewMode;
int alpha = 255;
switch (chatType) {
case GAME:
case TABLES:
case DEFAULT:
alpha = CHAT_ALPHA;
}
this.txtConversation.setExtBackgroundColor(new Color(0, 0, 0, alpha)); // Alpha = 255 not transparent
this.txtConversation.setSelectionColor(Color.LIGHT_GRAY);
this.jScrollPaneTxt.setOpaque(alpha == 255);
this.jScrollPaneTxt.getViewport().setOpaque(chatType != ChatType.TABLES);
}
jScrollPaneTxt.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jScrollPaneTxt.setPreferredSize(new java.awt.Dimension(32767, 32767));
public void clear() {
this.txtConversation.setText("");
}
txtConversation.setEditable(false);
txtConversation.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
txtConversation.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
txtConversation.setFocusCycleRoot(false);
txtConversation.setMargin(new java.awt.Insets(2, 2, 2, 2));
txtConversation.setOpaque(false);
jScrollPaneTxt.setViewportView(txtConversation);
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
txtMessage.setMaximumSize(new java.awt.Dimension(5000, 70));
txtMessage.setMinimumSize(new java.awt.Dimension(6, 70));
txtMessage.setName(""); // NOI18N
txtMessage.setPreferredSize(new java.awt.Dimension(6, 70));
txtMessage.addKeyListener(new java.awt.event.KeyAdapter() {
@Override
public void keyTyped(java.awt.event.KeyEvent evt) {
txtMessageKeyTyped(evt);
}
});
jScrollPaneTxt = new javax.swing.JScrollPane();
txtConversation = new mage.client.components.ColorPane();
txtMessage = new javax.swing.JTextField();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPaneTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(txtMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPaneTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
.addGap(0, 0, 0)
.addComponent(txtMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
}// </editor-fold>//GEN-END:initComponents
jScrollPaneTxt.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jScrollPaneTxt.setPreferredSize(new java.awt.Dimension(32767, 32767));
public void handleKeyTyped(java.awt.event.KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
if (parentChatRef != null) {
SessionHandler.sendChatMessage(parentChatRef.chatId, this.txtMessage.getText());
} else {
SessionHandler.sendChatMessage(chatId, this.txtMessage.getText());
}
this.txtMessage.setText("");
this.txtMessage.repaint();
}
}
txtConversation.setEditable(false);
txtConversation.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
txtConversation.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
txtConversation.setFocusCycleRoot(false);
txtConversation.setMargin(new java.awt.Insets(2, 2, 2, 2));
txtConversation.setOpaque(false);
jScrollPaneTxt.setViewportView(txtConversation);
public void enableHyperlinks() {
txtConversation.enableHyperlinks();
}
txtMessage.setMaximumSize(new java.awt.Dimension(5000, 70));
txtMessage.setMinimumSize(new java.awt.Dimension(6, 70));
txtMessage.setName(""); // NOI18N
txtMessage.setPreferredSize(new java.awt.Dimension(6, 70));
txtMessage.addKeyListener(new java.awt.event.KeyAdapter() {
@Override
public void keyTyped(java.awt.event.KeyEvent evt) {
txtMessageKeyTyped(evt);
}
});
private void txtMessageKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMessageKeyTyped
handleKeyTyped(evt);
}//GEN-LAST:event_txtMessageKeyTyped
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPaneTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(txtMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPaneTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
.addGap(0, 0, 0)
.addComponent(txtMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPaneTxt;
private mage.client.components.ColorPane txtConversation;
private javax.swing.JTextField txtMessage;
// End of variables declaration//GEN-END:variables
}
public void handleKeyTyped(java.awt.event.KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
if (parentChatRef != null) {
SessionHandler.sendChatMessage(parentChatRef.chatId, this.txtMessage.getText());
} else {
SessionHandler.sendChatMessage(chatId, this.txtMessage.getText());
}
this.txtMessage.setText("");
this.txtMessage.repaint();
}
}
public void enableHyperlinks() {
txtConversation.enableHyperlinks();
}
private void txtMessageKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMessageKeyTyped
handleKeyTyped(evt);
}//GEN-LAST:event_txtMessageKeyTyped
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPaneTxt;
private mage.client.components.ColorPane txtConversation;
private javax.swing.JTextField txtMessage;
// End of variables declaration//GEN-END:variables
}

View file

@ -1,17 +1,15 @@
package mage.client.chat;
import java.awt.Font;
import java.util.Date;
import mage.client.SessionHandler;
import mage.client.components.ColorPane;
import mage.client.util.GUISizeHelper;
import mage.view.ChatMessage;
import org.mage.card.arcane.ManaSymbols;
import java.awt.*;
import java.util.Date;
/**
*
* @author LevelX2
*/
public class ChatPanelSeparated extends ChatPanelBasic {
@ -22,42 +20,42 @@ public class ChatPanelSeparated extends ChatPanelBasic {
* Display message in the chat. Use different colors for timestamp, username
* and message.
*
* @param username message sender
* @param message message itself
* @param time timestamp
* @param username message sender
* @param message message itself
* @param time timestamp
* @param turnInfo game turn info, can be null for non game messages
* @param messageType
* @param color Preferred color. Not used.
* @param color Preferred color. Not used.
*/
@Override
public void receiveMessage(String username, String message, Date time, ChatMessage.MessageType messageType, ChatMessage.MessageColor color) {
public void receiveMessage(String username, String message, Date time, String turnInfo, ChatMessage.MessageType messageType, ChatMessage.MessageColor color) {
String userColor;
String textColor;
String userSeparator = " ";
StringBuilder text = new StringBuilder();
switch (messageType) {
case TALK:
case WHISPER_TO:
case WHISPER_FROM:
case USER_INFO:
super.receiveMessage(username, message, time, messageType, color);
// message in main chat
super.receiveMessage(username, message, time, turnInfo, messageType, color);
return;
}
StringBuilder text = new StringBuilder();
if (time != null) {
text.append(getColoredText(TIMESTAMP_COLOR, timeFormatter.format(time) + ": "));
}
String userColor;
String textColor;
String userSeparator = " ";
switch (messageType) {
case STATUS: // a message to all chat user
case STATUS:
textColor = STATUS_COLOR;
userColor = STATUS_COLOR;
break;
case USER_INFO: // a personal message
textColor = USER_INFO_COLOR;
userColor = USER_INFO_COLOR;
break;
default:
case GAME:
userColor = SessionHandler.getUserName().equals(username) ? MY_COLOR : OPPONENT_COLOR;
textColor = MESSAGE_COLOR;
userSeparator = ": ";
break;
}
// message in game log
if (time != null) {
text.append(getColoredText(TIMESTAMP_COLOR, timeFormatter.format(time) + (turnInfo == null ? "" : ", " + turnInfo) + ": "));
}
if (color == ChatMessage.MessageColor.ORANGE) {
textColor = "Orange";

View file

@ -68,7 +68,7 @@ public final class LocalCommands {
private static void displayLocalCommandResponse(UUID chatId, String response) {
final String text = new StringBuilder().append("<font color=yellow>").append(response).append("</font>").toString();
ClientCallback chatMessage = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
new ChatMessage("", text, new Date(), ChatMessage.MessageColor.BLUE));
new ChatMessage("", text, new Date(), null, ChatMessage.MessageColor.BLUE));
MageFrame.getInstance().processCallback(chatMessage);
}
}

View file

@ -3826,7 +3826,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
addAvatar(jPanel32, 32, false, false);
} catch (Exception e) {
logger.error(e, e);
logger.error(e.getMessage(), e);
}
}

View file

@ -109,9 +109,9 @@ public class CallbackClientImpl implements CallbackClient {
}
// send the message to subchat if exists and it's not a game message
if (message.getMessageType() != MessageType.GAME && panel.getConnectedChat() != null) {
panel.getConnectedChat().receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getMessageType(), ChatMessage.MessageColor.BLACK);
panel.getConnectedChat().receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getTurnInfo(), message.getMessageType(), ChatMessage.MessageColor.BLACK);
} else {
panel.receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getMessageType(), message.getColor());
panel.receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getTurnInfo(), message.getMessageType(), message.getColor());
}
}
@ -444,11 +444,11 @@ public class CallbackClientImpl implements CallbackClient {
.append("<br/>").append("<b>/pings</b> - show players and watchers ping")
.append("<br/>").append("<b>/fix</b> - fix freezed game")
.toString(),
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
null, null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break;
case TOURNAMENT:
usedPanel.receiveMessage("", "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.",
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
null, null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break;
case TABLES:
String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> "");
@ -457,7 +457,7 @@ public class CallbackClientImpl implements CallbackClient {
.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(),
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
null, null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break;
default:
break;

View file

@ -470,7 +470,7 @@ public final class ImageCache {
image = ImageIO.read(inputStream);
}
} catch (Exception e) {
LOGGER.error(e, e);
LOGGER.error(e.getMessage(), e);
}
return image;
@ -488,7 +488,7 @@ public final class ImageCache {
ImageIO.write(image, format, outputStream);
}
} catch (IOException e) {
LOGGER.error(e, e);
LOGGER.error(e.getMessage(), e);
imageFile.delete();
}
return image;

View file

@ -1,12 +1,11 @@
package mage.view;
import mage.game.Game;
import java.io.Serializable;
import java.util.Date;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ChatMessage implements Serializable {
@ -14,6 +13,7 @@ public class ChatMessage implements Serializable {
private String username;
private Date time;
private String turnInfo;
private String message;
private MessageColor color;
private SoundToPlay soundToPlay;
@ -31,23 +31,39 @@ public class ChatMessage implements Serializable {
PlayerLeft, PlayerQuitTournament, PlayerSubmittedDeck, PlayerWhispered
}
public ChatMessage(String username, String message, Date time, MessageColor color) {
this(username, message, time, color, null);
public ChatMessage(String username, String message, Date time, Game game, MessageColor color) {
this(username, message, time, game, color, null);
}
public ChatMessage(String username, String message, Date time, MessageColor color, SoundToPlay soundToPlay) {
this(username, message, time, color, MessageType.TALK, soundToPlay);
public ChatMessage(String username, String message, Date time, Game game, MessageColor color, SoundToPlay soundToPlay) {
this(username, message, time, null, color, MessageType.TALK, soundToPlay);
}
public ChatMessage(String username, String message, Date time, MessageColor color, MessageType messageType, SoundToPlay soundToPlay) {
public ChatMessage(String username, String message, Date time, Game game, MessageColor color, MessageType messageType, SoundToPlay soundToPlay) {
this.username = username;
this.message = message;
this.time = time;
this.turnInfo = prepareTurnInfo(game);
this.color = color;
this.messageType = messageType;
this.soundToPlay = soundToPlay;
}
private String prepareTurnInfo(Game game) {
// no turn info
if (game == null) {
return null;
}
// not started game
if (game.getStep() == null) {
return "T0";
}
// normal game
return "T" + game.getTurnNum() + "." + game.getStep().getType().getStepShortText();
}
public String getMessage() {
return message;
}
@ -57,11 +73,11 @@ public class ChatMessage implements Serializable {
}
public boolean isUserMessage() {
return color != null && (color==MessageColor.BLUE || color==MessageColor.YELLOW);
return color != null && (color == MessageColor.BLUE || color == MessageColor.YELLOW);
}
public boolean isStatusMessage() {
return color != null && color== MessageColor.ORANGE;
return color != null && color == MessageColor.ORANGE;
}
public String getUsername() {
@ -72,6 +88,10 @@ public class ChatMessage implements Serializable {
return time;
}
public String getTurnInfo() {
return turnInfo;
}
public SoundToPlay getSoundToPlay() {
return soundToPlay;
}

View file

@ -2,6 +2,7 @@ package mage.server;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.game.Game;
import mage.server.exceptions.UserNotFoundException;
import mage.server.game.GameController;
import mage.server.game.GameManager;
@ -81,17 +82,9 @@ public enum ChatManager {
}
}
public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime) {
this.broadcast(chatId, userName, message, color, withTime, MessageType.TALK);
}
public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime, MessageType messageType) {
this.broadcast(chatId, userName, message, color, withTime, messageType, null);
}
final Pattern cardNamePattern = Pattern.compile("\\[(.*?)\\]");
public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime, Game game, MessageType messageType, SoundToPlay soundToPlay) {
ChatSession chatSession = chatSessions.get(chatId);
if (chatSession != null) {
if (message.startsWith("\\") || message.startsWith("/")) {
@ -163,7 +156,7 @@ public enum ChatManager {
}
}
chatSession.broadcast(userName, message, color, withTime, messageType, soundToPlay);
chatSession.broadcast(userName, message, color, withTime, game, messageType, soundToPlay);
}
}
@ -324,7 +317,7 @@ public enum ChatManager {
getChatSessions()
.stream()
.filter(chat -> chat.hasUser(userId))
.forEach(session -> session.broadcast(user.getName(), message, color, true, MessageType.TALK, null));
.forEach(session -> session.broadcast(user.getName(), message, color, true, null, MessageType.TALK, null));
});
}
@ -334,7 +327,7 @@ public enum ChatManager {
-> getChatSessions()
.stream()
.filter(chat -> chat.hasUser(userId))
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + " has reconnected", MessageColor.BLUE, true, MessageType.STATUS, null)));
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + " has reconnected", MessageColor.BLUE, true, null, MessageType.STATUS, null)));
}
@ -357,7 +350,7 @@ public enum ChatManager {
if (chatSessions.size() > 0) {
logger.info("INFORM OPPONENTS by " + user.getName() + ": " + message);
chatSessions.forEach(chatSession -> chatSession.broadcast(null, message, MessageColor.BLUE, true, MessageType.STATUS, null));
chatSessions.forEach(chatSession -> chatSession.broadcast(null, message, MessageColor.BLUE, true, null, MessageType.STATUS, null));
}
});
}

View file

@ -1,6 +1,14 @@
package mage.server;
import mage.game.Game;
import mage.interfaces.callback.ClientCallback;
import mage.interfaces.callback.ClientCallbackMethod;
import mage.view.ChatMessage;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
import mage.view.ChatMessage.SoundToPlay;
import org.apache.log4j.Logger;
import java.text.DateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -8,13 +16,6 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import mage.interfaces.callback.ClientCallback;
import mage.interfaces.callback.ClientCallbackMethod;
import mage.view.ChatMessage;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
import mage.view.ChatMessage.SoundToPlay;
import org.apache.log4j.Logger;
/**
* @author BetaSteward_at_googlemail.com
@ -48,7 +49,7 @@ public class ChatSession {
} finally {
w.unlock();
}
broadcast(null, userName + " has joined (" + user.getClientVersion() + ')', MessageColor.BLUE, true, MessageType.STATUS, null);
broadcast(null, userName + " has joined (" + user.getClientVersion() + ')', MessageColor.BLUE, true, null, MessageType.STATUS, null);
logger.trace(userName + " joined chat " + chatId);
}
});
@ -76,7 +77,7 @@ public class ChatSession {
String message = reason.getMessage();
if (!message.isEmpty()) {
broadcast(null, userName + message, MessageColor.BLUE, true, MessageType.STATUS, null);
broadcast(null, userName + message, MessageColor.BLUE, true, null, MessageType.STATUS, null);
}
}
} catch (Exception ex) {
@ -86,7 +87,8 @@ public class ChatSession {
public boolean broadcastInfoToUser(User toUser, String message) {
if (clients.containsKey(toUser.getId())) {
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(null, message, new Date(), MessageColor.BLUE, MessageType.USER_INFO, null)));
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
new ChatMessage(null, message, new Date(), null, MessageColor.BLUE, MessageType.USER_INFO, null)));
return true;
}
return false;
@ -95,20 +97,21 @@ public class ChatSession {
public boolean broadcastWhisperToUser(User fromUser, User toUser, String message) {
if (clients.containsKey(toUser.getId())) {
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
new ChatMessage(fromUser.getName(), message, new Date(), MessageColor.YELLOW, MessageType.WHISPER_FROM, SoundToPlay.PlayerWhispered)));
new ChatMessage(fromUser.getName(), message, new Date(), null, MessageColor.YELLOW, MessageType.WHISPER_FROM, SoundToPlay.PlayerWhispered)));
if (clients.containsKey(fromUser.getId())) {
fromUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
new ChatMessage(toUser.getName(), message, new Date(), MessageColor.YELLOW, MessageType.WHISPER_TO, null)));
new ChatMessage(toUser.getName(), message, new Date(), null, MessageColor.YELLOW, MessageType.WHISPER_TO, null)));
return true;
}
}
return false;
}
public void broadcast(String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
public void broadcast(String userName, String message, MessageColor color, boolean withTime, Game game, MessageType messageType, SoundToPlay soundToPlay) {
if (!message.isEmpty()) {
Set<UUID> clientsToRemove = new HashSet<>();
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? new Date() : null), color, messageType, soundToPlay));
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
new ChatMessage(userName, message, (withTime ? new Date() : null), game, color, messageType, soundToPlay));
List<UUID> chatUserIds = new ArrayList<>();
final Lock r = lock.readLock();
r.lock();

View file

@ -10,7 +10,6 @@ import mage.cards.repository.ExpansionRepository;
import mage.constants.ManaType;
import mage.constants.PlayerAction;
import mage.constants.TableState;
import mage.game.GameException;
import mage.game.Table;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
@ -494,7 +493,7 @@ public class MageServerImpl implements MageServer {
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
try {
callExecutor.execute(
() -> ChatManager.instance.broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE, true, ChatMessage.MessageType.TALK, null)
() -> ChatManager.instance.broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE, true, null, ChatMessage.MessageType.TALK, null)
);
} catch (Exception ex) {
handleException(ex);
@ -1129,9 +1128,9 @@ public class MageServerImpl implements MageServer {
execute("sendBroadcastMessage", sessionId, () -> {
for (User user : UserManager.instance.getUsers()) {
if (message.toLowerCase(Locale.ENGLISH).startsWith("warn")) {
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, MessageColor.RED)));
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, null, MessageColor.RED)));
} else {
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, MessageColor.BLUE)));
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, null, MessageColor.BLUE)));
}
}
}, true);

View file

@ -545,7 +545,7 @@ public class TableController {
}
Optional<User> user = UserManager.instance.getUser(userId);
if (user.isPresent()) {
ChatManager.instance.broadcast(chatId, user.get().getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft);
ChatManager.instance.broadcast(chatId, user.get().getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, null, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft);
if (!table.isTournamentSubTable()) {
user.get().removeTable(playerId);
}

View file

@ -120,11 +120,11 @@ public class GameController implements GameCallback {
updateGame();
break;
case INFO:
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.GAME, null);
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, event.getGame(), MessageType.GAME, null);
logger.trace(game.getId() + " " + event.getMessage());
break;
case STATUS:
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.ORANGE, event.getWithTime(), MessageType.GAME, null);
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.ORANGE, event.getWithTime(), event.getWithTurnInfo() ? event.getGame() : null, MessageType.GAME, null);
logger.trace(game.getId() + " " + event.getMessage());
break;
case ERROR:
@ -300,7 +300,7 @@ public class GameController implements GameCallback {
}
user.get().addGame(playerId, gameSession);
logger.debug("Player " + player.getName() + ' ' + playerId + " has " + joinType + " gameId: " + game.getId());
ChatManager.instance.broadcast(chatId, "", game.getPlayer(playerId).getLogName() + " has " + joinType + " the game", MessageColor.ORANGE, true, MessageType.GAME, null);
ChatManager.instance.broadcast(chatId, "", game.getPlayer(playerId).getLogName() + " has " + joinType + " the game", MessageColor.ORANGE, true, game, MessageType.GAME, null);
checkStart();
}
@ -361,7 +361,7 @@ public class GameController implements GameCallback {
+ " is forced to join the game (waiting ends after "
+ GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS
+ " secs, applied fixes: " + problemPlayerFixes + ")",
MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
MessageColor.BLUE, true, game, ChatMessage.MessageType.STATUS, null);
}
if (!user.isConnected() && user.getSecondsDisconnected() > GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS) {
@ -425,7 +425,7 @@ public class GameController implements GameCallback {
// Dont want people on our ignore list to stalk us
UserManager.instance.getUser(userId).ifPresent(user -> {
user.showUserMessage("Not allowed", "You are banned from watching this game");
ChatManager.instance.broadcast(chatId, user.getName(), " tried to join, but is banned", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, user.getName(), " tried to join, but is banned", MessageColor.BLUE, true, game, ChatMessage.MessageType.STATUS, null);
});
return false;
}
@ -440,7 +440,7 @@ public class GameController implements GameCallback {
}
gameWatcher.init();
user.addGameWatchInfo(game.getId());
ChatManager.instance.broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, game, ChatMessage.MessageType.STATUS, null);
});
return true;
}
@ -454,7 +454,7 @@ public class GameController implements GameCallback {
w.unlock();
}
UserManager.instance.getUser(userId).ifPresent(user -> {
ChatManager.instance.broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, game, ChatMessage.MessageType.STATUS, null);
});
}
@ -699,7 +699,7 @@ public class GameController implements GameCallback {
String sb = player.getLogName()
+ " has timed out (player had priority and was not active for "
+ ConfigSettings.instance.getMaxSecondsIdle() + " seconds ) - Auto concede.";
ChatManager.instance.broadcast(chatId, "", sb, MessageColor.BLACK, true, MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, "", sb, MessageColor.BLACK, true, game, MessageType.STATUS, null);
game.idleTimeout(playerId);
}
}

View file

@ -1,12 +1,5 @@
package mage.server.tournament;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import mage.MageException;
import mage.cards.decks.Deck;
import mage.constants.TableState;
@ -38,6 +31,12 @@ import mage.view.ChatMessage.SoundToPlay;
import mage.view.TournamentView;
import org.apache.log4j.Logger;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -68,7 +67,7 @@ public class TournamentController {
checkPlayersState();
break;
case INFO:
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, null, MessageType.STATUS, null);
logger.debug(tournament.getId() + " " + event.getMessage());
break;
case START_DRAFT:
@ -123,7 +122,7 @@ public class TournamentController {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
}
}
checkStart();
@ -140,7 +139,7 @@ public class TournamentController {
return;
}
if (tournamentSessions.containsKey(playerId)) {
logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
return;
}
// first join of player
@ -153,7 +152,7 @@ public class TournamentController {
TournamentPlayer player = tournament.getPlayer(playerId);
player.setJoined();
logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
checkStart();
} else {
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
@ -320,7 +319,7 @@ public class TournamentController {
TournamentPlayer player = tournament.getPlayer(playerId);
if (player != null && !player.hasQuit()) {
tournamentSessions.get(playerId).submitDeck(deck);
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted their tournament deck", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted their tournament deck", MessageColor.BLACK, true, null, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
}
}
}
@ -405,12 +404,11 @@ public class TournamentController {
tournamentPlayer.setQuit(info, status);
tournament.quit(playerId);
tournamentSession.quit();
ChatManager.instance.broadcast(chatId, "", tournamentPlayer.getPlayer().getLogName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
ChatManager.instance.broadcast(chatId, "", tournamentPlayer.getPlayer().getLogName() + " has quit the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
}
}
private boolean checkToReplaceDraftPlayerByAi(UUID userId, TournamentPlayer leavingPlayer) {
int humans = 0;
for (TournamentPlayer tPlayer : tournament.getPlayers()) {
if (tPlayer.getPlayer().isHuman()) {
@ -432,7 +430,7 @@ public class TournamentController {
user.get().removeTable(leavingPlayer.getPlayer().getId());
user.get().removeTournament(leavingPlayer.getPlayer().getId());
}
ChatManager.instance.broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, MessageType.STATUS, null);
ChatManager.instance.broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, null, MessageType.STATUS, null);
});
return true;
}

View file

@ -1,4 +1,3 @@
package mage.server.util;
import mage.utils.StreamUtils;
@ -122,7 +121,7 @@ public enum ServerMessagesUtil {
}
List<String> newMessages = new ArrayList<>();
try(Scanner scanner = new Scanner(is)) {
try (Scanner scanner = new Scanner(is)) {
while (scanner.hasNextLine()) {
String message = scanner.nextLine();
if (!message.trim().isEmpty()) {
@ -130,7 +129,7 @@ public enum ServerMessagesUtil {
}
}
} catch (Exception e) {
log.error(e, e);
log.error(e.getMessage(), e);
} finally {
StreamUtils.closeQuietly(is);
}

View file

@ -61,8 +61,8 @@ public class MulliganTestBase {
Mulligan mulligan = mulliganType.getMulligan(freeMulligans);
Game game = new TwoPlayerDuel(LEFT, ONE, mulligan, 20) {
@Override
public void fireStatusEvent(String message, boolean withTime) {
super.fireStatusEvent(message, withTime);
public void fireStatusEvent(String message, boolean withTime, boolean withTurnInfo) {
super.fireStatusEvent(message, withTime, withTurnInfo);
}
@Override

View file

@ -1,44 +1,45 @@
package mage.constants;
/**
*
* @author North
*/
public enum PhaseStep {
UNTAP ("Untap", 0, "untap step"),
UPKEEP ("Upkeep", 1, "upkeep"), // card texts don't use the word "step" for this phase step
DRAW ("Draw", 2, "draw step"),
PRECOMBAT_MAIN ("Precombat Main", 3,"precombat main step"),
BEGIN_COMBAT ("Begin Combat", 4, "begin combat step"),
DECLARE_ATTACKERS ("Declare Attackers", 5, "declare attackers step"),
DECLARE_BLOCKERS ("Declare Blockers", 6, "declare blockers step"),
FIRST_COMBAT_DAMAGE ("First Combat Damage", 7, "first combat damage"),
COMBAT_DAMAGE ("Combat Damage", 8, "combat damage step"),
END_COMBAT ("End Combat", 9, "end combat step"),
POSTCOMBAT_MAIN ("Postcombat Main", 10, "postcombat main step"),
END_TURN ("End Turn", 11, "end turn step"),
CLEANUP ("Cleanup", 12, "cleanup step");
UNTAP("Untap", 0, "untap step", "UN"),
UPKEEP("Upkeep", 1, "upkeep", "UP"), // card texts don't use the word "step" for this phase step
DRAW("Draw", 2, "draw step", "DR"),
PRECOMBAT_MAIN("Precombat Main", 3, "precombat main step", "PM"),
BEGIN_COMBAT("Begin Combat", 4, "begin combat step", "BC"),
DECLARE_ATTACKERS("Declare Attackers", 5, "declare attackers step", "DA"),
DECLARE_BLOCKERS("Declare Blockers", 6, "declare blockers step", "DB"),
FIRST_COMBAT_DAMAGE("First Combat Damage", 7, "first combat damage", "FCD"),
COMBAT_DAMAGE("Combat Damage", 8, "combat damage step", "CD"),
END_COMBAT("End Combat", 9, "end combat step", "EC"),
POSTCOMBAT_MAIN("Postcombat Main", 10, "postcombat main step", "PM"),
END_TURN("End Turn", 11, "end turn step", "ET"),
CLEANUP("Cleanup", 12, "cleanup step", "CL");
private final String text;
private final String stepText;
private final String stepShortText; // for chats/logs
/**
* Index is used for game state scoring system.
*/
private final int index;
PhaseStep(String text, int index, String stepText) {
PhaseStep(String text, int index, String stepText, String stepShortText) {
this.text = text;
this.index = index;
this.stepText = stepText;
this.stepShortText = stepShortText;
}
public boolean isBefore(PhaseStep other){
return this.getIndex()<other.getIndex();
public boolean isBefore(PhaseStep other) {
return this.getIndex() < other.getIndex();
}
public boolean isAfter(PhaseStep other){
return this.getIndex()>other.getIndex();
public boolean isAfter(PhaseStep other) {
return this.getIndex() > other.getIndex();
}
public int getIndex() {
@ -54,4 +55,7 @@ public enum PhaseStep {
return stepText;
}
public String getStepShortText() {
return stepShortText;
}
}

View file

@ -1,8 +1,5 @@
package mage.game;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
@ -44,6 +41,10 @@ import mage.players.Players;
import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public interface Game extends MageItem, Serializable {
MatchType getGameType();
@ -266,7 +267,7 @@ public interface Game extends MageItem, Serializable {
void fireInformEvent(String message);
void fireStatusEvent(String message, boolean withTime);
void fireStatusEvent(String message, boolean withTime, boolean withTurnInfo);
void fireUpdatePlayersEvent();
@ -299,9 +300,9 @@ public interface Game extends MageItem, Serializable {
/**
* Creates and fires an damage prevention event
*
* @param damageEvent damage event that will be replaced (instanceof check
* will be done)
* @param source ability that's the source of the prevention effect
* @param damageEvent damage event that will be replaced (instanceof check
* will be done)
* @param source ability that's the source of the prevention effect
* @param game
* @param amountToPrevent max preventable amount
* @return true prevention was successfull / false prevention was replaced
@ -311,12 +312,12 @@ public interface Game extends MageItem, Serializable {
/**
* Creates and fires an damage prevention event
*
* @param event damage event that will be replaced (instanceof check will be
* done)
* @param source ability that's the source of the prevention effect
* @param event damage event that will be replaced (instanceof check will be
* done)
* @param source ability that's the source of the prevention effect
* @param game
* @param preventAllDamage true if there is no limit to the damage that can
* be prevented
* be prevented
* @return true prevention was successfull / false prevention was replaced
*/
PreventionEffectData preventDamage(GameEvent event, Ability source, Game game, boolean preventAllDamage);

View file

@ -921,7 +921,7 @@ public abstract class GameImpl implements Game, Serializable {
if (startMessage == null || startMessage.isEmpty()) {
startMessage = "Game has started";
}
fireStatusEvent(startMessage, false);
fireStatusEvent(startMessage, false, false);
saveState(false);
@ -2369,11 +2369,11 @@ public abstract class GameImpl implements Game, Serializable {
}
@Override
public void fireStatusEvent(String message, boolean withTime) {
public void fireStatusEvent(String message, boolean withTime, boolean withTurnInfo) {
if (simulation) {
return;
}
tableEventSource.fireTableEvent(EventType.STATUS, message, withTime, this);
tableEventSource.fireTableEvent(EventType.STATUS, message, withTime, withTurnInfo, this);
}
@Override

View file

@ -1,10 +1,5 @@
package mage.game.events;
import java.io.Serializable;
import java.util.EventObject;
import java.util.UUID;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.game.Game;
@ -13,8 +8,11 @@ import mage.game.match.MatchOptions;
import mage.game.tournament.MultiplayerRound;
import mage.game.tournament.TournamentPairing;
import java.io.Serializable;
import java.util.EventObject;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableEvent extends EventObject implements ExternalEvent, Serializable {
@ -37,6 +35,7 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
private MatchOptions options;
private int timeout;
private boolean withTime;
private boolean withTurnInfo;
public TableEvent(EventType eventType) {
super(eventType);
@ -48,11 +47,16 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
}
public TableEvent(EventType eventType, String message, boolean withTime, Game game) {
this(eventType, message, withTime, withTime, game); // turn info with time always (exception: start turn message)
}
public TableEvent(EventType eventType, String message, boolean withTime, boolean withTurnInfo, Game game) {
super(game);
this.game = game;
this.message = message;
this.eventType = eventType;
this.withTime = withTime;
this.withTurnInfo = withTurnInfo;
}
public TableEvent(EventType eventType, String message, Cards cards, Game game) {
@ -150,4 +154,8 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
public boolean getWithTime() {
return withTime;
}
public boolean getWithTurnInfo() {
return withTurnInfo;
}
}

View file

@ -1,5 +1,3 @@
package mage.game.events;
import mage.cards.Cards;
@ -8,19 +6,19 @@ import mage.game.Game;
import mage.game.draft.Draft;
import mage.game.events.TableEvent.EventType;
import mage.game.match.MatchOptions;
import mage.game.tournament.MultiplayerRound;
import mage.game.tournament.TournamentPairing;
import java.io.Serializable;
import java.util.UUID;
import mage.game.tournament.MultiplayerRound;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableEventSource implements EventSource<TableEvent>, Serializable {
protected final EventDispatcher<TableEvent> dispatcher = new EventDispatcher<TableEvent>() {};
protected final EventDispatcher<TableEvent> dispatcher = new EventDispatcher<TableEvent>() {
};
@Override
public void addListener(Listener<TableEvent> listener) {
@ -41,8 +39,8 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
dispatcher.fireEvent(new TableEvent(eventType, message, game));
}
public void fireTableEvent(EventType eventType, String message, boolean withTime, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, message, withTime, game));
public void fireTableEvent(EventType eventType, String message, boolean withTime, boolean withTurnInfo, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, message, withTime, withTurnInfo, game));
}
public void fireTableEvent(EventType eventType, UUID playerId, String message, Game game) {

View file

@ -333,6 +333,6 @@ public class Turn implements Serializable {
}
}
sb.append(')');
game.fireStatusEvent(sb.toString(), true);
game.fireStatusEvent(sb.toString(), true, false);
}
}