Skip to content

Commit

Permalink
Suppress login/out messages, skippable message hook (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
conker-rsc authored Dec 24, 2023
1 parent e83298b commit a78f0fe
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 19 deletions.
21 changes: 18 additions & 3 deletions src/Client/ConfigWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public class ConfigWindow {
private JSlider generalPanelFoVSlider;
private JCheckBox generalPanelCustomCursorCheckbox;
private JCheckBox generalPanelCtrlScrollChatCheckbox;
private JCheckBox generalPanelSuppressLoginLogoutMessagesCheckbox;
private JCheckBox generalPanelShiftScrollCameraRotationCheckbox;
private JSlider generalPanelTrackpadRotationSlider;
private JCheckBox generalPanelCustomRandomChatColourCheckbox;
Expand Down Expand Up @@ -1548,6 +1549,11 @@ public void stateChanged(ChangeEvent e) {
generalPanelCtrlScrollChatCheckbox.setToolTipText(
"Holding CTRL allows you to scroll through the currently-selected chat history from anywhere");

generalPanelSuppressLoginLogoutMessagesCheckbox =
addCheckbox("Suppress friend login / logout messages", generalPanel);
generalPanelSuppressLoginLogoutMessagesCheckbox.setToolTipText(
"Private messages indicating when a friend logs in or out will no longer be output");

generalPanelShiftScrollCameraRotationCheckbox =
addCheckbox("Enable camera rotation with compatible trackpads", generalPanel);
generalPanelShiftScrollCameraRotationCheckbox.setToolTipText(
Expand Down Expand Up @@ -4138,6 +4144,12 @@ public void actionPerformed(ActionEvent e) {
"toggle_ctrl_scroll",
KeyModifier.ALT,
KeyEvent.VK_H);
addKeybindSet(
keybindContainerPanel,
"Toggle friend login/logout messages",
"toggle_login_logout_messages",
KeyModifier.ALT,
KeyEvent.VK_L);
addKeybindCategory(keybindContainerPanel, "Overlays");
addKeybindSet(
keybindContainerPanel,
Expand Down Expand Up @@ -4487,10 +4499,9 @@ public void actionPerformed(ActionEvent e) {
"Buttons you can click on to increase speed, decrease speed, restart, play/pause");

replayPanelHidePrivateMessagesCheckbox =
addCheckbox(
"Prevent private messages from being output to the console during replay", replayPanel);
addCheckbox("Prevent private messages from being output during replay", replayPanel);
replayPanelHidePrivateMessagesCheckbox.setToolTipText(
"Message types 1, 2, and 5 will not be output to the console when this is selected"); // TODO: possibly don't show in client either
"Message types 1, 2, and 5 will not be output when this is selected");

replayPanelTriggerAlertsReplayCheckbox =
addCheckbox("Prevent system alerts from triggering during replay", replayPanel);
Expand Down Expand Up @@ -5980,6 +5991,8 @@ private void executeSynchronizeGuiValues() {
Settings.SOFTWARE_CURSOR.get(Settings.currentProfile));
generalPanelCtrlScrollChatCheckbox.setSelected(
Settings.CTRL_SCROLL_CHAT.get(Settings.currentProfile));
generalPanelSuppressLoginLogoutMessagesCheckbox.setSelected(
Settings.SUPPRESS_LOG_IN_OUT_MSGS.get(Settings.currentProfile));
generalPanelShiftScrollCameraRotationCheckbox.setSelected(
Settings.SHIFT_SCROLL_CAMERA_ROTATION.get(Settings.currentProfile));
generalPanelTrackpadRotationSlider.setValue(
Expand Down Expand Up @@ -6488,6 +6501,8 @@ private void saveSettings() {
Settings.currentProfile, generalPanelCustomCursorCheckbox.isSelected());
Settings.CTRL_SCROLL_CHAT.put(
Settings.currentProfile, generalPanelCtrlScrollChatCheckbox.isSelected());
Settings.SUPPRESS_LOG_IN_OUT_MSGS.put(
Settings.currentProfile, generalPanelSuppressLoginLogoutMessagesCheckbox.isSelected());
Settings.SHIFT_SCROLL_CAMERA_ROTATION.put(
Settings.currentProfile, generalPanelShiftScrollCameraRotationCheckbox.isSelected());
Settings.TRACKPAD_ROTATION_SENSITIVITY.put(
Expand Down
7 changes: 6 additions & 1 deletion src/Client/JClassPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2874,6 +2874,8 @@ private void patchClient(ClassNode node) {
"(ZLjava/lang/String;ILjava/lang/String;IILjava/lang/String;Ljava/lang/String;)V")) {
AbstractInsnNode first = methodNode.instructions.getFirst();

LabelNode continueLabel = new LabelNode();

methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 7));
methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 4));
methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ILOAD, 5));
Expand All @@ -2884,7 +2886,10 @@ private void patchClient(ClassNode node) {
Opcodes.INVOKESTATIC,
"Game/Client",
"messageHook",
"(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V"));
"(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)Z"));
methodNode.instructions.insertBefore(first, new JumpInsnNode(Opcodes.IFGT, continueLabel));
methodNode.instructions.insertBefore(first, new InsnNode(Opcodes.RETURN));
methodNode.instructions.insertBefore(first, continueLabel);

// Replay seeking don't show messages hook
// LabelNode label = new LabelNode();
Expand Down
30 changes: 30 additions & 0 deletions src/Client/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class Settings {
public static HashMap<String, Integer> FPS_LIMIT = new HashMap<String, Integer>();
public static HashMap<String, Boolean> SOFTWARE_CURSOR = new HashMap<String, Boolean>();
public static HashMap<String, Boolean> CTRL_SCROLL_CHAT = new HashMap<String, Boolean>();
public static HashMap<String, Boolean> SUPPRESS_LOG_IN_OUT_MSGS = new HashMap<String, Boolean>();
public static HashMap<String, Boolean> SHIFT_SCROLL_CAMERA_ROTATION =
new HashMap<String, Boolean>();
public static HashMap<String, Integer> TRACKPAD_ROTATION_SENSITIVITY =
Expand Down Expand Up @@ -866,6 +867,16 @@ public static void definePresets(Properties props) {
CTRL_SCROLL_CHAT.put(
"custom", getPropBoolean(props, "ctrl_scroll_chat", CTRL_SCROLL_CHAT.get("default")));

SUPPRESS_LOG_IN_OUT_MSGS.put("vanilla", false);
SUPPRESS_LOG_IN_OUT_MSGS.put("vanilla_resizable", false);
SUPPRESS_LOG_IN_OUT_MSGS.put("lite", false);
SUPPRESS_LOG_IN_OUT_MSGS.put("default", false);
SUPPRESS_LOG_IN_OUT_MSGS.put("heavy", false);
SUPPRESS_LOG_IN_OUT_MSGS.put("all", true);
SUPPRESS_LOG_IN_OUT_MSGS.put(
"custom",
getPropBoolean(props, "suppress_log_in_out_msg", SUPPRESS_LOG_IN_OUT_MSGS.get("default")));

SHIFT_SCROLL_CAMERA_ROTATION.put("vanilla", false);
SHIFT_SCROLL_CAMERA_ROTATION.put("vanilla_resizable", false);
SHIFT_SCROLL_CAMERA_ROTATION.put("lite", false);
Expand Down Expand Up @@ -3266,6 +3277,8 @@ public static void save(String preset) {
props.setProperty("fps_limit", Integer.toString(FPS_LIMIT.get(preset)));
props.setProperty("software_cursor", Boolean.toString(SOFTWARE_CURSOR.get(preset)));
props.setProperty("ctrl_scroll_chat", Boolean.toString(CTRL_SCROLL_CHAT.get(preset)));
props.setProperty(
"suppress_log_in_out_msg", Boolean.toString(SUPPRESS_LOG_IN_OUT_MSGS.get(preset)));
props.setProperty(
"shift_scroll_camera_rotation",
Boolean.toString(SHIFT_SCROLL_CAMERA_ROTATION.get(preset)));
Expand Down Expand Up @@ -4228,6 +4241,20 @@ public static void toggleCtrlScroll() {
save();
}

public static void toggleSuppressLogInOutMessages() {
SUPPRESS_LOG_IN_OUT_MSGS.put(currentProfile, !SUPPRESS_LOG_IN_OUT_MSGS.get(currentProfile));

if (SUPPRESS_LOG_IN_OUT_MSGS.get(currentProfile)) {
Client.displayMessage(
"@cya@Friend login / logout messages will no longer be shown", Client.CHAT_NONE);
} else {
Client.displayMessage(
"@cya@Friend login / logout messages will now be shown", Client.CHAT_NONE);
}

save();
}

public static void toggleColorTerminal() {
COLORIZE_CONSOLE_TEXT.put(currentProfile, !COLORIZE_CONSOLE_TEXT.get(currentProfile));

Expand Down Expand Up @@ -4553,6 +4580,9 @@ public static boolean processKeybindCommand(String commandName) {
case "toggle_ctrl_scroll":
Settings.toggleCtrlScroll();
return true;
case "toggle_login_logout_messages":
Settings.toggleSuppressLogInOutMessages();
return true;
case "toggle_colorize":
Settings.toggleColorTerminal();
return true;
Expand Down
49 changes: 34 additions & 15 deletions src/Game/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -3059,10 +3059,26 @@ private static void windowedForm(String str) {
* @param username the username that the message originated from
* @param message the content of the message
* @param type the type of message being displayed
* @return {@code boolean} telling mudclient if the message should be printed
*/
public static void messageHook(
public static boolean messageHook(
String username, String message, int type, String colorCodeOverride) {

// Don't output login/logout messages if the setting is enabled
if (type == CHAT_PRIVATE_LOG_IN_OUT
&& Settings.SUPPRESS_LOG_IN_OUT_MSGS.get(Settings.currentProfile)) {
return false;
}

// Don't output private messages if option is turned on and replaying
if (Replay.isPlaying && Settings.HIDE_PRIVATE_MSGS_REPLAY.get(Settings.currentProfile)) {
if (type == CHAT_PRIVATE_LOG_IN_OUT
|| type == CHAT_PRIVATE
|| type == CHAT_PRIVATE_OUTGOING) {
return false;
}
}

// notify if the user set the message as one they wanted to be alerted by
if (Renderer.stringIsWithinList(message, Settings.IMPORTANT_MESSAGES.get("custom"))) {
NotificationsHandler.notify(
Expand All @@ -3085,8 +3101,9 @@ public static void messageHook(
}

if (colorCodeOverride != null) {
if (!((type == CHAT_QUEST || type == CHAT_CHAT) && colorCodeOverride.equals("@yel@")))
if (!((type == CHAT_QUEST || type == CHAT_CHAT) && colorCodeOverride.equals("@yel@"))) {
message = colorCodeOverride + message;
}
}

// Close dialogues when player says something in-game in quest chat
Expand All @@ -3096,22 +3113,25 @@ public static void messageHook(
}
}

if (username != null)
if (username != null) {
// Prevents non-breaking space in colored usernames appearing as an accented 'a' in console
username = username.replace("\u00A0", " ");
if (message != null)
// Prevents non-breaking space in colored usernames appearing as an accented 'a' in console
}

if (message != null) {
// Prevents non-breaking space in colored messages appearing as an accented 'a' in console
message = message.replace("\u00A0", " ");
}

if (message != null && username != null) {
Speedrun.checkMessageCompletions(message);
}

if (type == CHAT_NONE) {
if (username == null && message != null) {
if (message.contains("The spell fails! You may try again in 20 seconds"))
if (message.contains("The spell fails! You may try again in 20 seconds")) {
magic_timer = Renderer.time + 21000L;
else if (Settings.TRAY_NOTIFS.get(Settings.currentProfile)
} else if (Settings.TRAY_NOTIFS.get(Settings.currentProfile)
&& message.contains(
"You have been standing here for 5 mins! Please move to a new area")) {
NotificationsHandler.notify(
Expand Down Expand Up @@ -3141,19 +3161,16 @@ else if (message.contains("poisioned!")) {
NotificationsHandler.notify(
NotifType.TRADE, "Trade Request", username, username + " wishes to trade with you");
} else if (type == CHAT_OTHER) {
if (message.contains(" wishes to duel with you"))
if (message.contains(" wishes to duel with you")) {
NotificationsHandler.notify(
NotifType.DUEL, "Duel Request", username, message.replaceAll("@...@", ""));
}
}

if (type == Client.CHAT_PRIVATE || type == Client.CHAT_PRIVATE_OUTGOING) {
if (username != null) lastpm_username = username;
}

// Don't output private messages if option is turned on and replaying
if (Settings.HIDE_PRIVATE_MSGS_REPLAY.get(Settings.currentProfile) && Replay.isPlaying) {
if (type == CHAT_PRIVATE_LOG_IN_OUT || type == CHAT_PRIVATE || type == CHAT_PRIVATE_OUTGOING)
return;
if (username != null) {
lastpm_username = username;
}
}

String originalLog =
Expand All @@ -3169,6 +3186,8 @@ else if (message.contains("poisioned!")) {
+ ((username == null) ? "" : colorizeUsername(formatUsername(username, type), type))
+ colorizeMessage(message, type);
Logger.Chat(colorizedLog, originalLog);

return true;
}

private static String formatChatType(int type) {
Expand Down

0 comments on commit a78f0fe

Please sign in to comment.