/* Public data */
public boolean ready = false;
+ public String name = "";
/* Connection data */
private Socket socket;
{
this.nickname = nickname;
this.channel = channel;
+ this.name = nickname;
}
public boolean connect()
Os.debug("Client: connected");
if (this.usesasl)
this.raw("CAP REQ :sasl");
- this.raw("USER "+this.username+" "+this.hostname+" "+this.server+" :"+this.nickname);
- this.raw("NICK "+this.nickname);
+ this.raw("USER "+this.username+" "+this.hostname+" "+this.server+" :"+this.name);
+ this.raw("NICK "+this.name);
return true;
}
public Message send(String txt)
{
- Message msg = new Message(this.channel, this.nickname, txt);
+ Message msg = new Message(this.channel, this.name, txt);
this.raw(msg.line);
return msg;
}
if (line == null)
return null;
Os.debug("> " + line);
- Message msg = new Message(line);
+ Message msg = new Message(line, this.name);
this.process(msg);
if (this.usesasl)
this.dosasl(msg);
this.ready = true;
}
if (msg.cmd.equals("433")) {
- this.raw("NICK "+this.nickname+this.mangle);
- this.mangle++;
+ this.name = this.nickname + this.mangle;
+ this.mangle = this.mangle + 11;
+ this.raw("NICK " + this.name);
}
if (msg.cmd.equals("PING")) {
this.raw("PING " + msg.msg);
import android.os.Bundle;
import android.os.Handler;
import android.os.Messenger;
+import android.text.Html;
import android.text.method.ScrollingMovementMethod;
+import android.text.format.DateFormat;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
-import android.preference.PreferenceActivity;
-
public class Main extends Activity
{
- /* Static data */
+ /* Private data */
private Handler handler;
private Messenger messenger;
-
- /* Private data */
private Task task;
private Toast toast;
private boolean ready;
/* Private helper methods */
private void notice(String text)
{
- this.log.append("*** " + text + "\n");
+ this.log.append(Html.fromHtml("<b>*** " + text + "</b><br />"));
+ }
+
+ private void display(Message msg)
+ {
+ String when = DateFormat.format("hh:mm:ss", msg.time).toString();
+ String from = String.format("<font color=\"#ff88ff\">%s</font>", msg.from);
+ String text = msg.msg;
+ String fmt = null;
+ Os.debug("msg: " + Os.base64(msg.msg));
+
+ // Do IRC Colors
+ // - This doesn't actually work
+ String fg = "<font color=\"<$1>\">";
+ String bg = "<font bgcolor=\"<$2>\">";
+ text = text
+ .replaceAll("&", "&")
+ .replaceAll("<", "<")
+ .replaceAll(">", ">");
+ text = text
+ .replaceAll("\\002", "<b>") // bold
+ .replaceAll("\\011", "<i>") // italic
+ .replaceAll("\\025", "<u>") // underline
+ .replaceAll("\\022", "<b>"); // reverse
+ text = text
+ .replaceAll("\\003(\\d+),(\\d+)", fg + bg) // color
+ .replaceAll("\\013(\\d+),(\\d+)", fg + bg) // color
+ .replaceAll("\\003(\\d+)", fg) // color
+ .replaceAll("\\013(\\d+)", fg); // color
+ text = text
+ .replaceAll("<0?0>", "#000000") // White
+ .replaceAll("<0?1>", "#000000") // Black
+ .replaceAll("<0?2>", "#000080") // Navy Blue
+ .replaceAll("<0?3>", "#008000") // Green
+ .replaceAll("<0?4>", "#FF0000") // Red
+ .replaceAll("<0?5>", "#804040") // Brown
+ .replaceAll("<0?6>", "#8000FF") // Purple
+ .replaceAll("<0?7>", "#808000") // Olive
+ .replaceAll("<0?8>", "#FFFF00") // Yellow
+ .replaceAll("<0?9>", "#00FF00") // Lime Green
+ .replaceAll("<10>", "#008080") // Teal
+ .replaceAll("<11>", "#00FFFF") // Aqua Light
+ .replaceAll("<12>", "#0000FF") // Royal Blue
+ .replaceAll("<13>", "#FF00FF") // Hot Pink
+ .replaceAll("<14>", "#808080") // Dark Gray
+ .replaceAll("<15>", "#C0C0C0"); // Light Gray
+
+ // Message formatting
+ switch (msg.how) {
+ case DIRECT:
+ case MENTION:
+ case PRIVMSG:
+ fmt = "<b>(%s) %s: %s</b>";
+ break;
+ default:
+ fmt = "(%s) %s: %s";
+ break;
+ }
+
+ String html = String.format(fmt, when, from, text);
+ this.log.append(Html.fromHtml(html + "<br />"));
}
/* Private handler methods */
// Chat
switch (msg.type) {
case PRIVMSG:
- this.log.append(msg.from + ": " + msg.msg + "\n");
+ this.display(msg);
break;
case TOPIC:
if (!msg.txt.equals(this.topic))
package org.pileus.spades;
+import java.util.Date;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
{
/* Enumerations */
enum Type {
- OTHER,
- PRIVMSG,
- TOPIC,
- NAMES,
- ERROR,
- CAP,
- AUTH,
- AUTHOK,
- AUTHFAIL,
+ OTHER, // Unknown message type
+ PRIVMSG, // Private message
+ TOPIC, // Display current topic
+ NAMES, // Display user names
+ ERROR, // Error message from server
+ CAP, // Server capabilities
+ AUTH, // Authentication message
+ AUTHOK, // Authentication succeeded
+ AUTHFAIL, // Authentication failed
};
- /* Constnats */
+ enum How {
+ OTHER, // Unknown message type
+ CHANNEL, // Normal message to a channel
+ MENTION, // User was mentioned in message text
+ DIRECT, // Message directed towards user
+ PRIVMSG // Private message to user only
+ };
+
+ /* Constants */
private final String reMsg = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+)[= ]+)?(([^: ]+) *)?(:(.*))?";
private final String reFrom = "([^! ]+)!.*";
private final String reTo = "(([^ :,]*)[:,] *)?(.*)";
private static Pattern ptTo = null;
/* Public data */
+ public Date time = null;
+
public String line = "";
public String src = "";
public String msg = "";
public Type type = Type.OTHER;
+ public How how = How.OTHER;
public String from = "";
public String to = "";
public String txt = "";
this.line = this.cmd + " " + this.dst + " :" + this.msg;
}
- public Message(String line)
+ public Message(String line, String name)
{
// Initialize regexes
if (ptMsg == null) ptMsg = Pattern.compile(reMsg);
if (ptFrom == null) ptFrom = Pattern.compile(reFrom);
if (ptTo == null) ptTo = Pattern.compile(reTo);
+ // Set time stamp
+ this.time = new Date();
+
// Cleanup line
line = line.replaceAll("\\s+", " ");
line = line.replaceAll("^ | $", "");
- line = line.replaceAll("\003[0-9]*", "");
this.line = line;
// Split line into parts
else if (this.cmd.equals("905")) this.type = Type.AUTHFAIL;
else if (this.cmd.equals("906")) this.type = Type.AUTHFAIL;
else if (this.cmd.equals("907")) this.type = Type.AUTHFAIL;
+
+ // Set directed
+ if (this.dst.equals(name)) this.how = How.PRIVMSG;
+ else if (this.to.equals(name)) this.how = How.DIRECT;
+ else if (this.msg.contains(name)) this.how = How.MENTION;
+ else if (this.type == Type.PRIVMSG) this.how = How.CHANNEL;
}
public void debug()