Skip to content

Commit

Permalink
v0.8.3b3, FFZ-WS improvements, other stuff
Browse files Browse the repository at this point in the history
- Change to v0.8.3b3
- Change Helper.toStream() to only remove leading #
- Change Emoticon to be equal only when type/subtype match as well
- Change timeout duration display to use local locale, add hours
- FFZ-WS:
  - Add protocol level ping every 10 minutes (doesn't appear to detect some disconnects otherwise)
  - Measure latency with the ping for fun
  - Slow down reconnecting based on disconnects per hour
  - Improve debug output
  - Add comments to clarify locks
  - Improve locking (hopefully)
  - Reconnect manually, with possible server change, on disconnect as well as on connect failure
  - Remove room when closing channel as well, not just when leaving it in IRC (e.g. closing the tab while disconnected)
- Webserver: Bind to 127.0.0.1 explicitly, because that is what is registered with Twitch
- Some minor refactoring
- Reduce maximum session log file size further, to 20 MB
- Debug Window: Fix selection bug due to using Caret twice, simplify creation of tabs, change font to Monospaced
  • Loading branch information
tduva committed Jun 6, 2016
1 parent 4813c2e commit d3e7b9a
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/chatty/Chatty.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Chatty {
* by points. May contain a single "b" for beta versions, anything following
* it will be ignored for version checking.
*/
public static final String VERSION = "0.8.3b2";
public static final String VERSION = "0.8.3b3";

/**
* Enable Version Checker (if you compile and distribute this yourself, you
Expand Down
16 changes: 12 additions & 4 deletions src/chatty/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static String toChannel(String chan) {
}

/**
* Removes any # from the String.
* Removes a leading # from the channel, if present.
*
* @param channel
* @return
Expand All @@ -164,7 +164,10 @@ public static String toStream(String channel) {
if (channel == null) {
return null;
}
return channel.replace("#", "");
if (channel.startsWith("#")) {
return channel.substring(1);
}
return channel;
}

/**
Expand Down Expand Up @@ -555,9 +558,14 @@ private static String makeBanInfoDuration(long duration) {
if (duration < 120) {
return String.format("%ds", duration);
}
NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(1);
return String.format("%sm", nf.format(Math.round(duration/30.0)*30/60.0));

if (duration < DateTime.HOUR*2) {
return String.format("%sm", nf.format(Math.round(duration/30.0)*30/60.0));
}
duration = duration / 60;
return String.format("%sh", nf.format(Math.round(duration/30.0)*30/60.0));
}


Expand Down
18 changes: 11 additions & 7 deletions src/chatty/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class Logging {
public static final Level USERINFO = new UserinfoLevel();

private static final String LOG_FILE = Chatty.getDebugLogDirectory()+"debug%g.log";
private static final String LOG_FILE2 = Chatty.getDebugLogDirectory()+"debug_session.log";
private static final String LOG_FILE_SESSION = Chatty.getDebugLogDirectory()+"debug_session.log";
private static final String LOG_FILE_IRC = Chatty.getDebugLogDirectory()+"debug_irc%g.log";

/**
* Maximum log file size in bytes.
*/
private static final int MAX_LOG_SIZE = 1024*1024*2;

private static final int MAX_SESSION_LOG_SIZE = 1024*1024*100;
private static final int MAX_SESSION_LOG_SIZE = 1024*1024*20;

/**
* How many log files to rotate through when the file reaches maximum size.
Expand Down Expand Up @@ -60,11 +60,11 @@ public boolean isLoggable(LogRecord record) {
file.setFilter(new FileFilter());
Logger.getLogger("").addHandler(file);

FileHandler file2 = new FileHandler(LOG_FILE2, MAX_SESSION_LOG_SIZE, 1);
file2.setFormatter(new TextFormatter());
file2.setLevel(Level.INFO);
file2.setFilter(new FileFilter());
Logger.getLogger("").addHandler(file2);
FileHandler fileSession = new FileHandler(LOG_FILE_SESSION, MAX_SESSION_LOG_SIZE, 1);
fileSession.setFormatter(new TextFormatter());
fileSession.setLevel(Level.INFO);
fileSession.setFilter(new FileFilter());
Logger.getLogger("").addHandler(fileSession);
} catch (IOException | SecurityException ex) {
Logger.getLogger(Logging.class.getName()).log(Level.WARNING, null, ex);
}
Expand All @@ -76,6 +76,10 @@ public boolean isLoggable(LogRecord record) {
public void publish(LogRecord record) {
if (record.getLevel() != USERINFO) {
client.debug(record.getMessage());
// WebsocketClient/WebsocketManager
if (record.getSourceClassName().startsWith("chatty.util.ffz.Websocket")) {
client.debugFFZ(record.getMessage());
}
}
if (record.getLevel() == Level.SEVERE) {
if (client.g != null) {
Expand Down
22 changes: 20 additions & 2 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ public void closeChannel(String channel) {
else { // Always remove channel (or try to), so it can be closed even if it bugged out
logViewerstats(channel);
c.closeChannel(channel);
frankerFaceZ.left(channel);
g.removeChannel(channel);
chatLog.closeChannel(channel);
}
Expand Down Expand Up @@ -1103,6 +1104,16 @@ else if (command.equals("bantest")) {
frankerFaceZ.connectWs();
} else if (command.equals("wsdisconnect")) {
frankerFaceZ.disconnectWs();
} else if (command.equals("loadsoferrors")) {
for (int i=0;i<10000;i++) {
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
Helper.unhandledException();
}
});
}
}
}

Expand Down Expand Up @@ -1467,6 +1478,13 @@ public void debug(String line) {
}
}

public void debugFFZ(String line) {
if (shuttingDown || g == null) {
return;
}
g.printDebugFFZ(line);
}

/**
* Output a warning.
*
Expand Down Expand Up @@ -1973,14 +1991,14 @@ public void onChannelJoined(String channel) {
// Icons and FFZ/BTTV Emotes
api.requestChatIcons(Helper.toStream(channel), false);
requestChannelEmotes(channel);
frankerFaceZ.joined(Helper.toStream(channel));
frankerFaceZ.joined(channel);
}

@Override
public void onChannelLeft(String channel) {
chatLog.info(channel, "You have left "+channel);
closeChannel(channel);
frankerFaceZ.left(Helper.toStream(channel));
frankerFaceZ.left(channel);
}

@Override
Expand Down
52 changes: 24 additions & 28 deletions src/chatty/gui/components/DebugWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import chatty.util.DateTime;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ItemListener;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -30,38 +31,21 @@ public class DebugWindow extends JFrame {

public DebugWindow(ItemListener listener) {
setTitle("Debug");

// Caret to prevent scrolling
DefaultCaret caret = new DefaultCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);


// Normal log
text = new JTextArea();
text.setCaret(caret);
text.setEditable(false);
JScrollPane scroll = new JScrollPane(text);

// Caret to prevent scrolling
caret = new DefaultCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);

// Irc log
textIrcLog = new JTextArea();
textIrcLog.setEditable(false);
textIrcLog.setCaret(caret);
JScrollPane scrollIrcLog = new JScrollPane(textIrcLog);

text = createLogArea();

// Irc log
textFFZLog = new JTextArea();
textFFZLog.setEditable(false);
textFFZLog.setCaret(caret);
JScrollPane scrollFFZLog = new JScrollPane(textFFZLog);
textIrcLog = createLogArea();

// FFZ WS log
textFFZLog = createLogArea();

// Tabs
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("Log", scroll);
tabs.addTab("Irc log", scrollIrcLog);
tabs.addTab("FFZ-WS", scrollFFZLog);
tabs.addTab("Log", new JScrollPane(text));
tabs.addTab("Irc log", new JScrollPane(textIrcLog));
tabs.addTab("FFZ-WS", new JScrollPane(textFFZLog));

// Settings (Checkboxes)
logIrc.setToolTipText("Logging IRC traffic can reduce performance");
Expand All @@ -80,6 +64,18 @@ public DebugWindow(ItemListener listener) {
setSize(new Dimension(600,500));
}

private static JTextArea createLogArea() {
// Caret to prevent scrolling
DefaultCaret caret = new DefaultCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);

JTextArea text = new JTextArea();
text.setEditable(false);
text.setFont(Font.decode(Font.MONOSPACED));
text.setCaret(caret);
return text;
}

public void printLine(String line) {
printLine(text, line);
}
Expand Down
4 changes: 2 additions & 2 deletions src/chatty/gui/components/help/help-releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<h1><a name="top">Release Information</a></h1>

<p>
<a href="#0.8.1">0.8.3</a> |
<a href="#0.8.1">0.8.2</a> |
<a href="#0.8.3">0.8.3</a> |
<a href="#0.8.2">0.8.2</a> |
<a href="#0.8.1">0.8.1</a> |
<a href="#0.8">0.8</a> |
<a href="#0.7.3">0.7.3</a> |
Expand Down
4 changes: 4 additions & 0 deletions src/chatty/util/TimedCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public TimedCounter(long interval, long accuracy) {
this.accuracy = accuracy;
}

public int getCount() {
return getCount(true);
}

/**
* Gets the current count of elements.
*
Expand Down
7 changes: 5 additions & 2 deletions src/chatty/util/Webserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ private void debug(String message) {
public void run() {
debug("Trying to start webserver at port "+port);
try {
serverSocket = new ServerSocket(port, 0, InetAddress.getLoopbackAddress());
// Since 127.0.0.1 is registered with Twitch, hardcode that instead
// of using InetAddress.getLoopbackAddress() which may also return
// "::1".
serverSocket = new ServerSocket(port, 0, InetAddress.getByName("127.0.0.1"));
} catch (IOException ex) {
debug("Could not listen to port "+port+" ("+ex.getLocalizedMessage()+")");
if (listener != null) {
Expand All @@ -114,7 +117,7 @@ public void run() {
}

while (running) {
debug("Waiting for connections");
debug("Waiting for connections on "+serverSocket.toString());
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
Expand Down
16 changes: 12 additions & 4 deletions src/chatty/util/api/Emoticon.java
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,12 @@ public boolean equals(Object obj) {
return false;
}
final Emoticon other = (Emoticon) obj;
if (this.type != other.type) {
return false;
}
if (this.subType != other.subType) {
return false;
}
if (!Objects.equals(this.code, other.code)) {
return false;
}
Expand All @@ -877,10 +883,12 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + Objects.hashCode(this.code);
hash = 79 * hash + this.emoteSet;
hash = 79 * hash + Objects.hashCode(this.streamRestrictions);
int hash = 3;
hash = 59 * hash + Objects.hashCode(this.type);
hash = 59 * hash + Objects.hashCode(this.subType);
hash = 59 * hash + Objects.hashCode(this.code);
hash = 59 * hash + this.emoteSet;
hash = 59 * hash + Objects.hashCode(this.streamRestrictions);
return hash;
}

Expand Down
2 changes: 2 additions & 0 deletions src/chatty/util/ffz/FrankerFaceZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ public String getWsStatus() {
}

public void joined(String room) {
room = Helper.toStream(room);
ws.addRoom(room);
}

public void left(String room) {
room = Helper.toStream(room);
ws.removeRoom(room);
}

Expand Down
7 changes: 7 additions & 0 deletions src/chatty/util/ffz/FrankerFaceZListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
* @author tduva
*/
public interface FrankerFaceZListener {

/**
* This may be called out of a lock on the WebsocketClient instance, if
* originating from there.
*
* @param emotes
*/
public void channelEmoticonsReceived(EmoticonUpdate emotes);
public void usericonsReceived(List<Usericon> icons);
public void botNamesReceived(Set<String> botNames);
Expand Down
Loading

0 comments on commit d3e7b9a

Please sign in to comment.