diff --git a/Makefile b/Makefile index eb25dec..6813e34 100755 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ all: ircd jvm: mkdir jvm-build - javac -cp lib/json-gcj.jar:lib/placebohttp.jar:lib/smack.jar -d jvm-build src/org/openstatic/*.java src/org/openstatic/irc/*.java src/org/openstatic/irc/gateways/*.java src/org/openstatic/irc/middleware/*.java + javac -cp lib/json-gcj.jar:lib/placebohttp.jar:lib/smack.jar -d jvm-build src/org/openstatic/*.java src/org/openstatic/irc/*.java src/org/openstatic/irc/gateways/*.java src/org/openstatic/irc/middleware/*.java src/org/openstatic/irc/client/*.java jar -cvmf res/manifest.mf o5ircd.jar -C jvm-build org -C res www # Executable Rule for GCJ diff --git a/client.sh b/client.sh new file mode 100755 index 0000000..390d6b9 --- /dev/null +++ b/client.sh @@ -0,0 +1,2 @@ +#!/bin/bash +java -cp lib/json-gcj.jar:lib/placebohttp.jar:lib/smack.jar:o5ircd.jar org.openstatic.irc.client.O5Client $@ diff --git a/lib/placebohttp.jar b/lib/placebohttp.jar index 31d9592..990214a 100644 Binary files a/lib/placebohttp.jar and b/lib/placebohttp.jar differ diff --git a/src/org/openstatic/irc/GatewayConnection.java b/src/org/openstatic/irc/GatewayConnection.java index b7082e2..b02e78d 100755 --- a/src/org/openstatic/irc/GatewayConnection.java +++ b/src/org/openstatic/irc/GatewayConnection.java @@ -7,6 +7,6 @@ public interface GatewayConnection public String getServerHostname(); public String getClientHostname(); public void close(); - public void sendCommand(IRCMessage pc); - public void sendResponse(String response, String params); -} \ No newline at end of file + public void sendCommand(IRCMessage message); + public void sendResponse(IRCResponse response); +} diff --git a/src/org/openstatic/irc/IRCMessage.java b/src/org/openstatic/irc/IRCMessage.java index 3b32e68..bb594f2 100755 --- a/src/org/openstatic/irc/IRCMessage.java +++ b/src/org/openstatic/irc/IRCMessage.java @@ -10,6 +10,24 @@ public class IRCMessage protected String source; protected Vector args; protected Vector destination; + protected JSONObject meta; + public static final int PRIVMSG = 100; + public static final int MODE = 101; + public static final int JOIN = 102; + public static final int PART = 103; + public static final int INVITE = 104; + public static final int TOPIC = 105; + public static final int LIST = 106; + public static final int WHOIS = 107; + public static final int USER = 108; + public static final int NICK = 109; + public static final int WHO = 110; + public static final int AWAY = 111; + public static final int QUIT = 112; + public static final int NOTICE = 113; + public static final int PONG = 114; + public static final int ISON = 115; + public static final int PING = 116; // constructor public IRCMessage(String line) @@ -27,15 +45,25 @@ public IRCMessage(String line) this.args = doArgs(cmdArray,1); } } + + public IRCMessage(int command) + { + this.cmd = getCommand(command); + this.args = new Vector(); + this.destination = null; + } public IRCMessage(JSONObject job) throws JSONException { - this.source = job.getString("source"); + if (job.has("source")) + this.source = job.getString("source"); + if (job.has("meta")) + this.meta = job.getJSONObject("meta"); this.cmd = job.getString("command"); this.args = new Vector(); - if (job.has("args")) + if (job.has("data")) { - JSONArray arguments = job.getJSONArray("args"); + JSONArray arguments = job.getJSONArray("data"); for (int a = 0; a < arguments.length(); a++) { String c_arg = arguments.getString(a); @@ -106,6 +134,47 @@ public void clearArgs() this.args = new Vector(); } + public static String getCommand(int command) + { + if (command == PRIVMSG) + { + return "PRIVMSG"; + } else if (command == MODE) { + return "MODE"; + } else if (command == JOIN) { + return "JOIN"; + } else if (command == PART) { + return "PART"; + } else if (command == INVITE) { + return "INVITE"; + } else if (command == TOPIC) { + return "TOPIC"; + } else if (command == LIST) { + return "LIST"; + } else if (command == WHOIS) { + return "WHOIS"; + } else if (command == USER) { + return "USER"; + } else if (command == NICK) { + return "NICK"; + } else if (command == WHO) { + return "WHO"; + } else if (command == AWAY) { + return "AWAY"; + } else if (command == QUIT) { + return "QUIT"; + } else if (command == NOTICE) { + return "NOTICE"; + } else if (command == PONG) { + return "PONG"; + } else if (command == ISON) { + return "ISON"; + } else if (command == PING) { + return "PING"; + } else { + return null; + } + } // process that funny argument layout private Vector doArgs(String[] ary, int start) @@ -245,8 +314,8 @@ public String getEchoResponse() { return this.toString(); } - - public String toString() + + public String getData() { StringBuffer args_string = new StringBuffer(""); for (Enumeration e = args.elements(); e.hasMoreElements(); ) @@ -262,7 +331,12 @@ public String toString() args_string.append(" "); } } - return this.cmd + " " + args_string.toString(); + return args_string.toString(); + } + + public String toString() + { + return this.cmd + " " + this.getData(); } // check to see if a command matches a string @@ -324,7 +398,9 @@ public JSONObject toJSONObject() job.put("destination", this.destination); } job.put("command", this.getCommand()); - job.put("args", this.args); + if (this.meta != null) + job.put("meta", this.meta); + job.put("data", this.args); } catch (Exception e) {} return job; } @@ -335,4 +411,4 @@ public static IRCMessage prepare(String cmd) newm.setCommand(cmd); return newm; } -} \ No newline at end of file +} diff --git a/src/org/openstatic/irc/IRCMessageListener.java b/src/org/openstatic/irc/IRCMessageListener.java new file mode 100755 index 0000000..7801edd --- /dev/null +++ b/src/org/openstatic/irc/IRCMessageListener.java @@ -0,0 +1,7 @@ +package org.openstatic.irc; + +public interface IRCMessageListener +{ + public void onIRCMessage(IRCMessage message, Object source); + public void onIRCResponse(IRCResponse response, Object source); +} diff --git a/src/org/openstatic/irc/IRCResponse.java b/src/org/openstatic/irc/IRCResponse.java new file mode 100644 index 0000000..dbb59f7 --- /dev/null +++ b/src/org/openstatic/irc/IRCResponse.java @@ -0,0 +1,153 @@ +package org.openstatic.irc; + +import java.util.Vector; +import java.util.Enumeration; +import org.json.*; + +public class IRCResponse +{ + private String response_code; + private String server_host; + private String target_nick; + private Vector args; + + public IRCResponse(String line) + { + String[] cmdArray = line.split(" "); + if (cmdArray[0].startsWith(":")) + { + this.server_host = cmdArray[0].substring(1); + this.response_code = cmdArray[1]; + this.args = doArgs(cmdArray,2); + } else { + this.response_code = cmdArray[0]; + this.args = doArgs(cmdArray, 1); + } + } + + public IRCResponse(String resp_code, String data) + { + this.response_code = resp_code; + String[] data_array = data.split(" "); + this.args = doArgs(data_array, 0); + } + + public IRCResponse(JSONObject job) throws JSONException + { + this.args = new Vector(); + this.response_code = job.getString("response"); + if (job.has("data")) + { + JSONArray arguments = job.getJSONArray("data"); + for (int a = 0; a < arguments.length(); a++) + { + String c_arg = arguments.getString(a); + this.args.add(c_arg); + } + } + } + + // add arg for command handler recreation + public void addArg(String value) + { + this.args.add(value); + } + + public void clearArgs() + { + this.args = new Vector(); + } + + + // process that funny argument layout + private Vector doArgs(String[] ary, int start) + { + Vector return_vector = new Vector(); + for (int i = start; i < ary.length; i++) + { + if (ary[i].startsWith(":")) + { + StringBuffer lastarg = new StringBuffer(ary[i].substring(1)); + i++; + while (i < ary.length) + { + lastarg.append(" " + ary[i]); + i++; + } + return_vector.add(lastarg.toString()); + } else { + return_vector.add(ary[i]); + } + } + return return_vector; + } + + // check to see if a command matches a string + public boolean is(String text) + { + if (this.response_code.equals(text)) + { + return true; + } else { + return false; + } + } + + // retrieve the arguments by index to a command + public String getArg(int index) + { + try + { + return this.args.elementAt(index); + } catch (Exception e) { + return null; + } + } + + public Vector getArgs() + { + return this.args; + } + + public String getResponseCode() + { + return this.response_code; + } + + public String getData() + { + StringBuffer args_string = new StringBuffer(); + for (Enumeration e = args.elements(); e.hasMoreElements(); ) + { + String ca = e.nextElement(); + if (ca.contains(" ")) + { + ca = ":" + ca; + } + args_string.append(ca); + if (e.hasMoreElements()) + { + args_string.append(" "); + } + } + return args_string.toString(); + } + + public JSONObject toJSONObject() + { + JSONObject job = new JSONObject(); + try + { + job.put("response", this.response_code); + job.put("data", this.args); + } catch (Exception e) {} + return job; + } + + public String toString() + { + + return this.response_code + " " + this.getData(); + } + +} diff --git a/src/org/openstatic/irc/IrcChannel.java b/src/org/openstatic/irc/IrcChannel.java index 74be708..876fc54 100755 --- a/src/org/openstatic/irc/IrcChannel.java +++ b/src/org/openstatic/irc/IrcChannel.java @@ -358,7 +358,7 @@ public void onCommand(IRCMessage receivedCommand) IRCMessage outbound_message = receivedCommand; if (receivedCommand.getArg(0).equals(this.channel_name)) { - broadcast(outbound_message, false); + broadcast(outbound_message, u.shouldEcho()); } else { IrcUser intended_target = findMember(receivedCommand.getArg(0)); if (intended_target != null) diff --git a/src/org/openstatic/irc/IrcServer.java b/src/org/openstatic/irc/IrcServer.java index cc91c28..ebfdc90 100755 --- a/src/org/openstatic/irc/IrcServer.java +++ b/src/org/openstatic/irc/IrcServer.java @@ -1,5 +1,6 @@ package org.openstatic.irc; +import java.net.InetAddress; import java.util.Date; import java.util.Vector; import java.util.Enumeration; @@ -21,6 +22,7 @@ public class IrcServer extends Thread private int minute_tracker; private Vector motd; private long boot_time; + private String server_name; public IrcServer() { @@ -32,6 +34,13 @@ public IrcServer() this.keep_running = true; this.motd = null; this.boot_time = 0; + try + { + InetAddress addr = InetAddress.getLocalHost(); + this.server_name = addr.getHostName(); + } catch (Exception e) { + this.server_name = "localhost"; + } } public void run() @@ -42,7 +51,7 @@ public void run() Gateway gate = e.nextElement(); gate.initGateway(this); } - log("SERVER", 1, "Completed Init Gateway"); + log(this.server_name, 1, "Completed Init Gateway"); while (this.keep_running) { try @@ -56,22 +65,22 @@ public void run() Thread.sleep(1000); } catch (Exception z) {} } - log("SERVER", 1, "Full Shutdown, killing gateways"); + log(this.server_name, 1, "Full Shutdown, killing gateways"); for(Enumeration e2 = gateways.elements(); e2.hasMoreElements(); ) { Gateway gate = e2.nextElement(); gate.shutdownGateway(); } - log("SERVER", 1, "Gatway Shutdown Complete!"); + log(this.server_name, 1, "Gatway Shutdown Complete!"); - log("SERVER", 1, "Killing User Connections"); + log(this.server_name, 1, "Killing User Connections"); for(Enumeration e3 = users.elements(); e3.hasMoreElements(); ) { IrcUser cu = e3.nextElement(); cu.disconnect(); } - log("SERVER", 1, "Detaching Channels and Shutting Down Middleware"); + log(this.server_name, 1, "Detaching Channels and Shutting Down Middleware"); for(Enumeration e4 = rooms.elements(); e4.hasMoreElements(); ) { IrcChannel cc = e4.nextElement(); @@ -86,7 +95,7 @@ public String getBootTime() public void addGateway(Gateway g) { - log("SERVER", 1, "Gateway Added \"" + g.toString() + "\""); + log(this.server_name, 1, "Gateway Added \"" + g.toString() + "\""); gateways.add(g); } @@ -94,6 +103,11 @@ public void setDebug(int value) { this.debug_mode = value; } + + public void setServerName(String value) + { + this.server_name = value; + } public int getDebug() { @@ -165,7 +179,7 @@ public void removeUser(IrcUser conn) IrcChannel chan = e.nextElement(); chan.removeMember(conn); } - log("SERVER", 1, "Connection Removed \"" + conn.toString() + "\""); + log(this.server_name, 1, "Connection Removed \"" + conn.toString() + "\""); } } @@ -211,7 +225,7 @@ public void removeChannel(IrcChannel chan) if (idx != -1) { rooms.remove(idx); - log("SERVER", 1, "Channel Removed \"" + chan.toString() + "\""); + log(this.server_name, 1, "Channel Removed \"" + chan.toString() + "\""); } } @@ -229,7 +243,7 @@ public void setMotd(File motd_file) br = new BufferedReader(new FileReader(motd_file)); while ((thisLine = br.readLine()) != null) this.motd.add(thisLine); - log("SERVER", 1, "Loaded MOTD from file \"" + motd_file.toString() + "\""); + log(this.server_name, 1, "Loaded MOTD from file \"" + motd_file.toString() + "\""); } catch (Exception ioe) { // who cares } finally { @@ -255,7 +269,7 @@ public Vector getMotd() public void addChannel(IrcChannel chan) { this.rooms.add(chan); - log("SERVER", 1, "Channel Added \"" + chan.getName() + "\""); + log(this.server_name, 1, "Channel Added \"" + chan.getName() + "\""); } public Vector getChannels() @@ -267,9 +281,14 @@ public Vector getUsers() { return this.users; } + + public String getServerName() + { + return this.server_name; + } public void shutdown() { this.keep_running = false; } -} \ No newline at end of file +} diff --git a/src/org/openstatic/irc/IrcUser.java b/src/org/openstatic/irc/IrcUser.java index 37cbb38..c19d96a 100755 --- a/src/org/openstatic/irc/IrcUser.java +++ b/src/org/openstatic/irc/IrcUser.java @@ -15,6 +15,7 @@ public class IrcUser extends Thread private boolean welcomed; private int idle_time; private boolean stay_connected; + private boolean echo_back; private IrcServer server; private GatewayConnection connection; @@ -26,6 +27,7 @@ public IrcUser(IrcServer server) this.away_message = null; this.welcomed = false; this.server = server; + this.echo_back = false; } public void initGatewayConnection(GatewayConnection connection) @@ -50,6 +52,16 @@ public void run() this.server.log(this.connection.getClientHostname(), 1, "IrcUser Class initGatewayConnection()"); } + public void setEcho(boolean echo) + { + this.echo_back = echo; + } + + public boolean shouldEcho() + { + return this.echo_back; + } + public void disconnect() { this.server.log(this.username, 1, "IrcUser Class " + this.nickname + " disconnect()"); @@ -230,7 +242,10 @@ public void onGatewayCommand(IRCMessage cmd) { sendResponse("301", possible_target2.getNick() + " :" + possible_target2.getAway()); } - possible_target2.sendCommand(new IRCMessage(cmd, this)); + IRCMessage out_message = new IRCMessage(cmd, this); + possible_target2.sendCommand(out_message); + if (this.shouldEcho()) + this.sendCommand(out_message); } else { sendResponse("401", cmd.getArg(0) + " :No such nick/channel"); } @@ -350,6 +365,24 @@ public String getNick() { return this.nickname; } + + public String getPassword() + { + return this.password; + } + + public boolean checkPassword(String pass) + { + if (pass != null) + { + if (pass.equals(this.password)) + return true; + else + return false; + } else { + return false; + } + } public String getAway() { @@ -397,10 +430,15 @@ public void sendCommand(IRCMessage pc) { this.connection.sendCommand(pc); } + + public void sendResponse(String resp_code, String data) + { + this.connection.sendResponse(new IRCResponse(resp_code, data)); + } - public void sendResponse(String response, String args) + public void sendResponse(IRCResponse response) { - this.connection.sendResponse(response, args); + this.connection.sendResponse(response); } private void processUser(Vector args) diff --git a/src/org/openstatic/irc/client/O5ChatPanel.java b/src/org/openstatic/irc/client/O5ChatPanel.java new file mode 100644 index 0000000..740c3b6 --- /dev/null +++ b/src/org/openstatic/irc/client/O5ChatPanel.java @@ -0,0 +1,107 @@ +package org.openstatic.irc.client; + +import javax.swing.JPanel; +import javax.swing.JTextPane; +import javax.swing.JTextField; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.text.Document; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.io.PrintStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import java.net.URL; +import java.net.URLEncoder; +import java.net.HttpURLConnection; + +import org.json.*; +import org.openstatic.irc.IRCMessage; + +public class O5ChatPanel extends JPanel implements ActionListener +{ + private JTextPane chat_box; + private JTextField chat_input; + private StringBuffer chat_buffer; + private String nickname; + private O5Connection connection; + + public O5ChatPanel(O5Connection oc, String nickname) + { + super(new BorderLayout()); + this.connection = oc; + this.chat_buffer = new StringBuffer(); + this.nickname = nickname; + chat_box = new JTextPane(); + chat_box.setContentType("text/html"); + chat_box.setEditable(false); + Font font = new Font("Monospaced", Font.BOLD, 14); + chat_box.setBackground(Color.WHITE); + chat_box.setFont(font); + chat_box.setForeground(Color.BLACK); + chat_box.setText(""); + JScrollPane scroller = new JScrollPane(chat_box); + scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + + chat_input = new JTextField(255); + chat_input.setBackground(Color.WHITE); + chat_input.setFont(font); + chat_input.setForeground(Color.BLACK); + chat_input.addActionListener(this); + JPanel page_start = new JPanel(new BorderLayout()); + + this.add(scroller, BorderLayout.CENTER); + this.add(chat_input, BorderLayout.PAGE_END); + } + + public void handleMessage(IRCMessage im) + { + if (im.getSourceNick().equals(nickname)) + addText(im.getSourceNick(), "#880000", im.getArgs().lastElement()); + else + addText(im.getSourceNick(), "#000088", im.getArgs().lastElement()); + } + + public void addText(String user, String color, String message) + { + chat_buffer.append("" + user + ": " + message + "
"); + chat_box.setText("" + chat_buffer.toString() + ""); + Document d = chat_box.getDocument(); + chat_box.select(d.getLength(), d.getLength()); + } + + public void actionPerformed(ActionEvent e) + { + final ActionEvent x = e; + Thread t = new Thread() + { + public void run() + { + try + { + IRCMessage im = new IRCMessage(IRCMessage.PRIVMSG); + im.addArg(O5ChatPanel.this.nickname); + im.addArg(chat_input.getText()); + O5ChatPanel.this.connection.sendIRCMessage(im); + chat_input.setText(""); + } catch (Exception e) { + + } + } + + }; + t.start(); + } +} diff --git a/src/org/openstatic/irc/client/O5Client.java b/src/org/openstatic/irc/client/O5Client.java new file mode 100644 index 0000000..c8ccaa2 --- /dev/null +++ b/src/org/openstatic/irc/client/O5Client.java @@ -0,0 +1,263 @@ +/* + Copyright (C) 2010 Brian Dunigan + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package org.openstatic.irc.client; + +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.DefaultListModel; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JTextField; +import javax.swing.JTextArea; +import javax.swing.JTextPane; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.imageio.ImageIO; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.Toolkit; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; +import javax.swing.JTabbedPane; +import java.awt.Font; +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; + +import java.util.Hashtable; +import java.util.Enumeration; +import java.util.Properties; + +import org.json.*; + +import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; +import org.openstatic.irc.IRCMessageListener; + +public class O5Client extends JFrame implements ActionListener, IRCMessageListener +{ + private JTabbedPane tabbed; + private JTextField server_field; + private JTextField username_field; + private JTextField password_field; + private Hashtable chat_panels; + private Hashtable server_panels; + private JButton login_btn; + private String token_id; + + public static void main(String[] args) + { + O5Client o5 = new O5Client(); + } + + public O5Client() + { + super("O5 IRC"); + this.chat_panels = new Hashtable(); + this.server_panels = new Hashtable(); + this.token_id = null; + this.addWindowListener(new java.awt.event.WindowAdapter() + { + public void windowClosing(WindowEvent winEvt) + { + System.exit(0); + } + }); + this.tabbed = new JTabbedPane(); + + JPanel main_pane = new JPanel(); + main_pane.setLayout(new BorderLayout()); + // Setup tab + JPanel pane = new JPanel(new GridLayout(0,2,6,6)); + pane.setSize(50,100); + + JLabel server_label = new JLabel("Server:", JLabel.TRAILING); + server_field = new JTextField(15); + server_field.setText("127.0.0.1:4050"); + + JLabel username_label = new JLabel("Username:", JLabel.TRAILING); + username_field = new JTextField(15); + + JLabel password_label = new JLabel("Password:", JLabel.TRAILING); + password_field = new JTextField(15); + + login_btn = new JButton("Connect"); + login_btn.setActionCommand("login"); + login_btn.addActionListener(this); + + pane.add(server_label); + pane.add(server_field); + + pane.add(username_label); + pane.add(username_field); + + pane.add(password_label); + pane.add(password_field); + + pane.add(new JLabel("")); + pane.add(login_btn); + + JPanel page_start = new JPanel(new BorderLayout()); + + JLabel page_header = new JLabel("O5 Client"); + page_header.setFont(new Font("Monospaced", Font.BOLD, 36)); + + page_start.add(page_header, BorderLayout.PAGE_START); + page_start.add(pane, BorderLayout.PAGE_END); + + main_pane.add(page_start, BorderLayout.PAGE_START); + + tabbed.addTab("Connect", null, main_pane, ""); + + // finish window + this.add(tabbed); + centerWindow(); + this.setVisible(true); + } + + public void centerWindow() + { + Toolkit tk = Toolkit.getDefaultToolkit(); + Dimension screenSize = tk.getScreenSize(); + final int WIDTH = screenSize.width; + final int HEIGHT = screenSize.height; + this.setSize(520, 340); + this.setLocation(WIDTH / 4 - 260, HEIGHT / 2 - 170); + } + + public boolean isCentered() + { + Toolkit tk = Toolkit.getDefaultToolkit(); + Dimension screenSize = tk.getScreenSize(); + final int WIDTH = screenSize.width; + final int HEIGHT = screenSize.height; + if (this.getX() == ((WIDTH / 2) - (this.getWidth() / 2)) && this.getY() == ((HEIGHT / 2) - (this.getHeight() / 2))) + { + return true; + } else { + return false; + } + } + + public void addPanel(String panel_caption, Component panel) + { + final JPanel plugin_pane = new JPanel(new BorderLayout()); + plugin_pane.add(panel, BorderLayout.CENTER); + plugin_pane.setForeground(Color.WHITE); + plugin_pane.setBackground(Color.GRAY); + JButton close_button = new JButton("Close Tab"); + close_button.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) + { + tabbed.remove(plugin_pane); + } + }); + + + /* + JPanel sub_layout = new JPanel(new BorderLayout()) + { + public void paintComponent(Graphics g) + { + g.drawImage(placebo_icon, 2, 2, 24, 24, null); + } + }; + sub_layout.add(close_button, BorderLayout.EAST); + plugin_pane.add(sub_layout, BorderLayout.PAGE_END); + */ + + tabbed.addTab(panel_caption, null, plugin_pane, ""); + } + + public void onIRCMessage(IRCMessage message, Object source) + { + if (message.is("PRIVMSG")) + { + O5Connection connection = (O5Connection) source; + String source_nick = message.getSourceNick(); + String dest_nick = message.getArgs().firstElement(); + O5ChatPanel p = null; + //System.err.println("{" + connection.getNick() + "} [" + source_nick + "] , [" + dest_nick + "]"); + if (source_nick.equals(connection.getNick())) + { + p = chat_panels.get(dest_nick); + } else { + p = chat_panels.get(source_nick); + } + if (p != null) + { + p.handleMessage(message); + } else { + O5ChatPanel p_new = new O5ChatPanel((O5Connection) source, source_nick); + chat_panels.put(source_nick, p_new); + p_new.handleMessage(message); + tabbed.addTab(source_nick, null, p_new, ""); + } + } + } + + public void onIRCResponse(IRCResponse response, Object source) + { + O5Connection connection = (O5Connection) source; + O5ServerPanel sp = null; + sp = server_panels.get(connection.getServerName()); + sp.handleResponse(response); + } + + private void addServer(O5Connection oc) + { + O5ServerPanel osp = new O5ServerPanel(oc); + oc.startInteractive(this); + server_panels.put(oc.getServerName(), osp); + tabbed.addTab(oc.getServerName(), null, osp, ""); + tabbed.setSelectedIndex(tabbed.getTabCount() - 1); + } + + + public void actionPerformed(ActionEvent e) + { + final ActionEvent x = e; + Thread t = new Thread() + { + public void run() + { + try + { + if ("login".equals(x.getActionCommand())) + { + String server = server_field.getText(); + String username = username_field.getText(); + String password = password_field.getText(); + O5Connection oc = new O5Connection(server); + oc.login(username, password); + addServer(oc); + } + } catch (Exception e) { + + } + } + + }; + t.start(); + } +} diff --git a/src/org/openstatic/irc/client/O5Connection.java b/src/org/openstatic/irc/client/O5Connection.java new file mode 100644 index 0000000..dd7c1d1 --- /dev/null +++ b/src/org/openstatic/irc/client/O5Connection.java @@ -0,0 +1,163 @@ +package org.openstatic.irc.client; + +import java.net.URL; +import java.net.URLEncoder; +import java.net.HttpURLConnection; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.io.PrintStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import org.json.*; + +import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; +import org.openstatic.irc.IRCMessageListener; + + +public class O5Connection +{ + private String token_id; + private String nick; + private String server; + private String server_name; + private PrintStream ips; + + public O5Connection(String server) + { + this.server = server; + } + + public JSONObject login(String nick, String password) + { + try + { + JSONObject login_response = apiCall("http://" + server + "/irc/connect/?nick=" + URLEncoder.encode(nick, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8")); + this.token_id = login_response.getString("token_id"); + this.server_name = login_response.getString("server"); + this.nick = login_response.getString("nick"); + return login_response; + } catch (Exception e) { + return null; + } + } + + public void startInteractive(final IRCMessageListener iml) + { + Thread t = new Thread() + { + public void run() + { + try + { + URL url = new URL("http://" + O5Connection.this.server + "/irc/interactive/?token_id=" + O5Connection.this.token_id); + InputStream is = url.openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String cmd_line; + do + { + try + { + cmd_line = br.readLine(); + } catch (Exception n) { + System.err.println("READLINE: " + n.toString() + " / " + n.getMessage()); + n.printStackTrace(System.err); + cmd_line = null; + } + if (cmd_line != null) + { + System.err.println(cmd_line); + try + { + JSONObject event = new JSONObject(cmd_line); + if (event.has("command")) + iml.onIRCMessage(new IRCMessage(event), O5Connection.this); + if (event.has("response")) + iml.onIRCResponse(new IRCResponse(event), O5Connection.this); + } catch (Exception cmd_exception) { + System.err.println(cmd_exception.toString() + " / " + cmd_exception.getMessage()); + cmd_exception.printStackTrace(System.err); + } + } + } while (cmd_line != null); + } catch (Exception e) { + System.err.println(e.toString() + " / " + e.getMessage()); + e.printStackTrace(System.err); + } + } + }; + t.start(); + } + + public void onIRCMessage(IRCMessage message) + { + // stub for event. + } + + public void sendIRCMessage(IRCMessage message) + { + apiCall("http://" + this.server + "/irc/direct/?token_id=" + this.token_id, message.toJSONObject().toString()); + } + + public String getNick() + { + return this.nick; + } + + public String getServerName() + { + return this.server_name; + } + + public String getServerAddress() + { + return this.server; + } + + public String getTokenId() + { + return this.token_id; + } + + private static JSONObject apiCall(String url_string) + { + return apiCall(url_string, null); + } + + private static JSONObject apiCall(String url_string, String post_data) + { + try + { + URL url = new URL(url_string); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + if (post_data != null) + { + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "text/plain"); + conn.setDoOutput(true); + OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); + wr.write(post_data); + wr.flush(); + wr.close(); + } + InputStream is = conn.getInputStream(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + int inputByte; + while ((inputByte = is.read()) > -1) + { + baos.write(inputByte); + } + is.close(); + String response = new String(baos.toByteArray()); + return new JSONObject(response); + } catch (Exception e) { + e.printStackTrace(System.err); + return null; + } + } + +} diff --git a/src/org/openstatic/irc/client/O5ServerPanel.java b/src/org/openstatic/irc/client/O5ServerPanel.java new file mode 100644 index 0000000..b694f99 --- /dev/null +++ b/src/org/openstatic/irc/client/O5ServerPanel.java @@ -0,0 +1,117 @@ +package org.openstatic.irc.client; + +import javax.swing.JPanel; +import javax.swing.JTextPane; +import javax.swing.JTextField; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.text.Document; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; + +import java.util.StringTokenizer; + +public class O5ServerPanel extends JPanel implements ActionListener +{ + private O5Connection connection; + private JTextPane server_box; + private StringBuffer server_buffer; + private JTextField server_input; + + public O5ServerPanel(O5Connection oc) + { + super(new BorderLayout()); + this.connection = oc; + this.server_buffer = new StringBuffer(); + server_box = new JTextPane(); + server_box.setContentType("text/html"); + server_box.setEditable(false); + Font font = new Font("Monospaced", Font.BOLD, 12); + server_box.setBackground(Color.BLACK); + server_box.setFont(font); + server_box.setForeground(Color.WHITE); + server_box.setText(""); + JScrollPane scroller = new JScrollPane(server_box); + scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + server_input = new JTextField(255); + server_input.setBackground(Color.BLACK); + server_input.setFont(font); + server_input.setForeground(Color.WHITE); + server_input.addActionListener(this); + JPanel page_start = new JPanel(new BorderLayout()); + this.add(scroller, BorderLayout.CENTER); + this.add(server_input, BorderLayout.PAGE_END); + } + + public void addText(String message, String color) + { + server_buffer.append("" + message + "
"); + server_box.setText("" + server_buffer.toString() + ""); + } + + public void handleResponse(IRCResponse response) + { + addText(response.toString(), "white"); + } + + public void serverCommand(String command) + { + StringTokenizer st = new StringTokenizer(command); + String cmd = st.nextToken().toLowerCase(); + if (cmd.equals("/join")) + { + IRCMessage im = new IRCMessage(IRCMessage.JOIN); + im.addArg(st.nextToken()); + this.connection.sendIRCMessage(im); + } + if (cmd.equals("/msg")) + { + IRCMessage im = new IRCMessage(IRCMessage.PRIVMSG); + im.addArg(st.nextToken()); + im.addArg(remainingTokens(st)); + this.connection.sendIRCMessage(im); + } + } + + public String remainingTokens(StringTokenizer st) + { + StringBuffer sb = new StringBuffer(); + while (st.hasMoreTokens()) + { + sb.append(st.nextToken()); + if (st.hasMoreTokens()) + sb.append(" "); + } + return sb.toString(); + } + + public void actionPerformed(ActionEvent e) + { + final ActionEvent x = e; + Thread t = new Thread() + { + public void run() + { + try + { + O5ServerPanel.this.serverCommand(server_input.getText()); + server_input.setText(""); + } catch (Exception e) { + + } + } + + }; + t.start(); + } + +} diff --git a/src/org/openstatic/irc/gateways/APIGateway.java b/src/org/openstatic/irc/gateways/APIGateway.java index 3171be5..73430f7 100755 --- a/src/org/openstatic/irc/gateways/APIGateway.java +++ b/src/org/openstatic/irc/gateways/APIGateway.java @@ -4,6 +4,7 @@ import org.openstatic.irc.IrcUser; import org.openstatic.irc.IrcChannel; import org.openstatic.irc.Gateway; +import org.openstatic.irc.IRCMessage; import org.openstatic.http.*; @@ -64,6 +65,17 @@ public APIGatewayConnection findClient(String token_id) } return null; } + + public APIGatewayConnection findClient(IrcUser u) + { + for(Enumeration e = clients.elements(); e.hasMoreElements(); ) + { + APIGatewayConnection ce = e.nextElement(); + if (ce.getIrcUser() == u) + return ce; + } + return null; + } public void shutdownGateway() { @@ -82,6 +94,7 @@ public void run() if (this.ircServer.getDebug() >= 10) { httpServer.setDebug(true); + httpServer.setShowData(true); } httpServer.setSessionVariable("token_id"); httpServer.setSessionMode(PlaceboHttpServer.GET_SESSION); @@ -121,7 +134,10 @@ public void run() public JSONObject doRequest(HttpRequest request) throws Exception { JSONObject response = new JSONObject(); - String client_ip = request.getHttpHeader("X-Real-IP"); + String client_ip = request.getClientHostname(); + String x_real_ip = request.getHttpHeader("X-Real-IP"); + if (x_real_ip != null) + client_ip = x_real_ip; String token_id = request.getGetValue("token_id"); String timeout_string = request.getGetValue("timeout"); int timeout = 60; @@ -131,6 +147,8 @@ public JSONObject doRequest(HttpRequest request) throws Exception if (token_id != null) { connection = findClient(token_id); + if (connection != null) + connection.resetPingRemaining(); } if (request.getPath().equals("/irc/connect/")) @@ -138,18 +156,49 @@ public JSONObject doRequest(HttpRequest request) throws Exception if (token_id == null) token_id = generateBigAlphaKey(15); String nickname = request.getGetValue("nick"); - if (this.ircServer.findUser(nickname) == null) + String pass = request.getGetValue("password"); + IrcUser existing_user = this.ircServer.findUser(nickname); + if (existing_user == null) { connection = new APIGatewayConnection(this.ircServer, token_id, timeout, client_ip, request.getServerHostname()); + //connection.start(); this.clients.add(connection); - connection.connect(nickname, request.getGetValue("password")); + connection.connect(nickname, pass); response.put("token_id", token_id); } else { - response.put("error", "NICK_IN_USE"); + APIGatewayConnection ec = findClient(existing_user); + if (ec != null) + { + if (existing_user.checkPassword(pass)) + { + response.put("token_id", ec.getTokenId()); + } else { + response.put("error", "INVALID_PASSWORD"); + } + + } else { + response.put("error", "NICK_IN_USE"); + } } - } else if (request.getPath().startsWith("/irc/queue/")) { + } else if (request.getPath().equals("/irc/queue/")) { if (connection != null) response.put("events", connection.getMessageQueue()); + } else if (request.getPath().equals("/irc/interactive/")) { + if (connection != null) + { + InteractiveResponse ir = new InteractiveResponse(request); + connection.addInteractiveResponse(ir); + } + } else if (request.getPath().equals("/irc/direct/")) { + if (connection != null) + { + connection.handleMessage(new IRCMessage(request.getJSONObjectPost())); + } + } else if (request.getPath().equals("/irc/raw/")) { + if (connection != null) + { + connection.rawCommand(request.getRawPost()); + } } else if (request.getPath().startsWith("/irc/channel/")) { String channel_name = request.getPathArray()[2]; IrcChannel channel = this.ircServer.findChannel(channel_name); @@ -184,13 +233,13 @@ public JSONObject doRequest(HttpRequest request) throws Exception } } } else { - + response.put("error", "API_NOT_FOUND"); } if (connection != null) { - response.put("ping_remaining", connection.getPingRemaining()); response.put("nick", connection.getIrcUser().getNick()); } + response.put("server", this.ircServer.getServerName()); return response; } diff --git a/src/org/openstatic/irc/gateways/APIGatewayConnection.java b/src/org/openstatic/irc/gateways/APIGatewayConnection.java index 7ec2a71..79dd8f2 100755 --- a/src/org/openstatic/irc/gateways/APIGatewayConnection.java +++ b/src/org/openstatic/irc/gateways/APIGatewayConnection.java @@ -2,17 +2,20 @@ import org.openstatic.irc.GatewayConnection; import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; import org.openstatic.irc.IrcServer; import org.openstatic.irc.IrcUser; import org.openstatic.irc.IrcChannel; import org.openstatic.http.HttpRequest; import org.openstatic.http.HttpResponse; +import org.openstatic.http.InteractiveResponse; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Vector; import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Hashtable; +import java.util.concurrent.LinkedBlockingQueue; import java.net.URLEncoder; import org.json.*; @@ -21,7 +24,8 @@ public class APIGatewayConnection extends Thread implements GatewayConnection private IrcServer ircServer; private IrcUser ircUser; private Hashtable room_timeout; - private Vector message_queue; + private LinkedBlockingQueue message_queue; + private Vector ir_list; private int lastRequestDelay; private int timeout; private String clientHostname; @@ -33,7 +37,9 @@ public APIGatewayConnection(IrcServer ircServer, String token_id, int timeout, S { this.ircServer = ircServer; this.ircUser = new IrcUser(this.ircServer); - this.message_queue = new Vector(); + this.ircUser.setEcho(true); + this.message_queue = new LinkedBlockingQueue(); + this.ir_list = new Vector(); this.ircUser.initGatewayConnection(this); this.ircServer.addUser(this.ircUser); this.clientHostname = client_ip; @@ -43,10 +49,6 @@ public APIGatewayConnection(IrcServer ircServer, String token_id, int timeout, S this.timeout = timeout; this.keep_running = true; this.token_id = token_id; - } - - public void run() - { Thread pingPong = new Thread() { public void run() @@ -66,6 +68,10 @@ public void run() } }; pingPong.start(); + } + + public void run() + { this.ircUser.getIrcServer().log(this.clientHostname, 1, "APIGatewayConnection Thread Exiting!"); } @@ -99,6 +105,19 @@ public void privmsg(String target, String message) this.ircUser.onGatewayCommand(imessage); } + public void handleMessage(IRCMessage imessage) + { + imessage.setSource(this.ircUser); + this.ircUser.onGatewayCommand(imessage); + } + + public void rawCommand(String raw) + { + IRCMessage imessage = new IRCMessage(raw); + imessage.setSource(this.ircUser); + this.ircUser.onGatewayCommand(imessage); + } + public String getTokenId() { return this.token_id; @@ -114,6 +133,11 @@ public int getDelay() return this.lastRequestDelay; } + public void resetPingRemaining() + { + this.lastRequestDelay = 0; + } + public int getPingRemaining() { return this.timeout - this.lastRequestDelay; @@ -139,31 +163,71 @@ public IrcUser getIrcUser() return this.ircUser; } - public void sendResponse(String response, String params) + public void addInteractiveResponse(InteractiveResponse ir) + { + this.ir_list.add(ir); + } + + public void sendResponse(IRCResponse response) { - /* try { - JSONObject resp = new JSONObject(); - resp.put("response", response); - resp.put("data", params); - this.message_queue.add(resp); + this.ircUser.getIrcServer().log(this.clientHostname, 5, "<- " + response.toString()); + if (this.ir_list.size() > 0) + { + resetPingRemaining(); + for (Enumeration e = this.ir_list.elements(); e.hasMoreElements(); ) + { + InteractiveResponse ir = e.nextElement(); + if (ir.isConnected()) + ir.push(response.toJSONObject()); + else + this.ir_list.remove(ir); + } + } else { + this.message_queue.put(response.toJSONObject()); + } } catch (Exception e) { } - */ } - public void sendCommand(IRCMessage pc) + public void sendCommand(IRCMessage message) + { + try + { + this.ircUser.getIrcServer().log(this.clientHostname, 5, "<- " + message.toString()); + if (this.ir_list.size() > 0) + { + resetPingRemaining(); + for (Enumeration e = this.ir_list.elements(); e.hasMoreElements(); ) + { + InteractiveResponse ir = e.nextElement(); + if (ir.isConnected()) + ir.push(message.toJSONObject()); + else + this.ir_list.remove(ir); + } + } else { + this.message_queue.put(message.toJSONObject()); + } + } catch (Exception e) { + System.err.println(e.toString() + " / " + e.getMessage()); + e.printStackTrace(System.err); + } + } + + public JSONObject pollMessageQueue() { - this.ircUser.getIrcServer().log(this.clientHostname, 5, "<- " + pc.toString()); - this.message_queue.add(pc.toJSONObject()); + return this.message_queue.poll(); } public JSONArray getMessageQueue() { JSONArray return_array = new JSONArray(); - for(Enumeration e = this.message_queue.elements(); e.hasMoreElements(); ) + Vector drain_results = new Vector(); + this.message_queue.drainTo(drain_results); + for(Enumeration e = drain_results.elements(); e.hasMoreElements(); ) { JSONObject jo = e.nextElement(); return_array.put(jo); diff --git a/src/org/openstatic/irc/gateways/CLIGatewayConnection.java b/src/org/openstatic/irc/gateways/CLIGatewayConnection.java index e030bd7..2d13263 100755 --- a/src/org/openstatic/irc/gateways/CLIGatewayConnection.java +++ b/src/org/openstatic/irc/gateways/CLIGatewayConnection.java @@ -4,6 +4,7 @@ import org.openstatic.irc.IrcUser; import org.openstatic.irc.IrcChannel; import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; import org.openstatic.irc.IrcServer; import java.net.Socket; import java.io.InputStream; @@ -180,7 +181,7 @@ public void run() this.println("notice [target] [msg] Send a notice to target"); this.println("msg [target] [msg] Send a privmsg to target"); this.println("nick [target] [new nick] Change somebodys nickname"); - this.println("drop [target] Remove target from server"); + this.println("drop [target] Remove target channel/user from server"); this.println("debug [0-10] Set the verbosity"); this.println("motd Show the message of the day"); this.println("inject [cmd] [src] [target] [msg] Inject Irc Packet"); @@ -339,19 +340,19 @@ public void run() } - public void sendResponse(String response, String params) + public void sendResponse(IRCResponse response) { - socketWrite(response + " : " + params + "\r\n"); + socketWrite(response.getResponseCode() + " : " + response.getData() + "\r\n"); } - public void sendCommand(IRCMessage pc) + public void sendCommand(IRCMessage message) { String out = null; - if (pc.getSource() != null) + if (message.getSource() != null) { - out = ":" + pc.getSource() + " " + pc.toString() + "\r\n"; + out = ":" + message.getSource() + " " + message.toString() + "\r\n"; } else { - out = ":" + this.serverHostname + " " + pc.toString() + "\r\n"; + out = ":" + this.serverHostname + " " + message.toString() + "\r\n"; } socketWrite(out); } @@ -374,4 +375,4 @@ public void println(String out) { socketWrite(out + "\n"); } -} \ No newline at end of file +} diff --git a/src/org/openstatic/irc/gateways/IrcGatewayConnection.java b/src/org/openstatic/irc/gateways/IrcGatewayConnection.java index d35eac2..86dd363 100755 --- a/src/org/openstatic/irc/gateways/IrcGatewayConnection.java +++ b/src/org/openstatic/irc/gateways/IrcGatewayConnection.java @@ -3,6 +3,7 @@ import org.openstatic.irc.GatewayConnection; import org.openstatic.irc.IrcUser; import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; import java.net.Socket; import java.io.InputStream; import java.io.OutputStream; @@ -139,19 +140,19 @@ public void run() this.ircUser.getIrcServer().log(this.clientHostname, 1, "IrcGatewayConnection Thread Exiting!"); } - public void sendResponse(String response, String params) + public void sendResponse(IRCResponse response) { - socketWrite(":" + this.serverHostname + " " + response + " " + this.ircUser.getNick() + " " + params + "\r\n"); + socketWrite(":" + this.serverHostname + " " + response.getResponseCode() + " " + this.ircUser.getNick() + " " + response.getData() + "\r\n"); } - public void sendCommand(IRCMessage pc) + public void sendCommand(IRCMessage message) { String out = null; - if (pc.getSource() != null) + if (message.getSource() != null) { - out = ":" + pc.getSource() + " " + pc.toString() + "\r\n"; + out = ":" + message.getSource() + " " + message.toString() + "\r\n"; } else { - out = ":" + this.serverHostname + " " + pc.toString() + "\r\n"; + out = ":" + this.serverHostname + " " + message.toString() + "\r\n"; } socketWrite(out); } diff --git a/src/org/openstatic/irc/gateways/WebGatewayConnection.java b/src/org/openstatic/irc/gateways/WebGatewayConnection.java index 85501a5..3b74de7 100755 --- a/src/org/openstatic/irc/gateways/WebGatewayConnection.java +++ b/src/org/openstatic/irc/gateways/WebGatewayConnection.java @@ -2,6 +2,7 @@ import org.openstatic.irc.GatewayConnection; import org.openstatic.irc.IRCMessage; +import org.openstatic.irc.IRCResponse; import org.openstatic.irc.IrcServer; import org.openstatic.irc.IrcUser; import org.openstatic.irc.IrcChannel; @@ -323,7 +324,7 @@ public void close() this.connection.endSession(); } - public void sendResponse(String response, String params) + public void sendResponse(IRCResponse response) { // Do Nothing } @@ -371,43 +372,43 @@ public byte[] readBuffer(String buffer_name) return return_data; } - public void sendCommand(IRCMessage pc) + public void sendCommand(IRCMessage message) { - this.ircUser.getIrcServer().log(this.clientHostname, 5, "<- " + pc.toString()); - String nc = pc.getSourceNick(); - if (pc.is("PRIVMSG")) + this.ircUser.getIrcServer().log(this.clientHostname, 5, "<- " + message.toString()); + String nc = message.getSourceNick(); + if (message.is("PRIVMSG")) { - if (pc.getArg(0).equals(this.ircUser.getNick())) + if (message.getArg(0).equals(this.ircUser.getNick())) { - writeToBuffer(nc, "" + nc + ": " + pc.getArg(1) + "
"); + writeToBuffer(nc, "" + nc + ": " + message.getArg(1) + "
"); } else { - writeToBuffer(pc.getArg(0), "" + nc + ": " + pc.getArg(1) + "
"); + writeToBuffer(message.getArg(0), "" + nc + ": " + message.getArg(1) + "
"); } } - if (pc.is("NOTICE")) + if (message.is("NOTICE")) { - if (pc.getArg(0).equals(this.ircUser.getNick())) + if (message.getArg(0).equals(this.ircUser.getNick())) { - writeToBuffer(nc, "NOTICE (" + nc + "): " + pc.getArg(1) + "
"); + writeToBuffer(nc, "NOTICE (" + nc + "): " + message.getArg(1) + "
"); } else { - writeToBuffer(pc.getArg(0), "NOTICE (" + nc + "): " + pc.getArg(1) + "
"); + writeToBuffer(message.getArg(0), "NOTICE (" + nc + "): " + message.getArg(1) + "
"); } } - if (pc.is("JOIN")) + if (message.is("JOIN")) { - writeToBuffer(pc.getArg(0), "*** " + nc + " Joined Channel :" + pc.getArg(0) + "
"); + writeToBuffer(message.getArg(0), "*** " + nc + " Joined Channel :" + message.getArg(0) + "
"); } - if (pc.is("PART")) + if (message.is("PART")) { - writeToBuffer(pc.getArg(0), "*** " + nc + " Left Channel :" + pc.getArg(0) + "
"); + writeToBuffer(message.getArg(0), "*** " + nc + " Left Channel :" + message.getArg(0) + "
"); } - if (pc.is("QUIT")) + if (message.is("QUIT")) { - writeToBuffer(pc.getArg(0), "*** " + nc + " QUIT IRC :" + pc.getArg(0) + "
"); + writeToBuffer(message.getArg(0), "*** " + nc + " QUIT IRC :" + message.getArg(0) + "
"); } - if (pc.is("TOPIC")) + if (message.is("TOPIC")) { - writeToBuffer(pc.getArg(0), "*** " + nc + " changed the topic to: " + pc.getArg(1) + "
"); + writeToBuffer(message.getArg(0), "*** " + nc + " changed the topic to: " + message.getArg(1) + "
"); } } }