예제 #1
0
  @Override
  public void onAuthenticated() {
    relay.addHandler("test", new TestMessageHandler());
    relay.sendMsg("test", "test", "");

    /*
    // Hook a handler for testing hdata functionality
    bufferManager.setOnChangedHandler(this);
    relay.addHandler("listbuffers", bufferManager);
    relay.sendMsg("listbuffers","hdata","buffer:gui_buffers(*) number,full_name,short_name,type,title,nicklist,local_variables");
    // Please view the source for BufferManager to see how this was handled
    // BufferManager also handles a bunch of other special event messages(such as _buffer_opened, or _buffer_closed)

    // Hook for testing nicklists
    NicklistHandler nickHandler = new NicklistHandler(bufferManager);
    relay.addHandler("_nicklist", nickHandler);
    relay.addHandler("nicklist", nickHandler);
    relay.sendMsg("nicklist", "nicklist", "irc.freenode.#weechat");


    // Hook a handler for testing the infolist functionality
    relay.addHandler("infolist-test", new InfolistMessageHandler());
    relay.sendMsg("infolist-test","infolist", "buffer");

    // Hook a handler for testing the "info" functionality
    relay.addHandler("info-test", new InfoMessageHandler());
    relay.sendMsg("info-test", "info", "version");

    // Hook new lines that are received
    LineHandler msgHandler = new LineHandler(bufferManager);
    relay.addHandler("_buffer_line_added", msgHandler);
    // Request a list of last 5 lines from all buffers
    relay.addHandler("listlines_reverse", msgHandler);
    relay.sendMsg("listlines_reverse","hdata", "buffer:gui_buffers(*)/own_lines/last_line(-5)/data date,displayed,prefix,message");



    // Prints the messages for the first buffer
    Buffer b = bufferManager.getBuffer(0);
    LinkedList<BufferLine> lines = b.getLines();
    for(BufferLine bl: lines) {
    	System.out.println(bl.toString());
    }
    //*/

    // Sleep a bit to get our messages, then quit
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    System.out.println("Cleaning up");
    relay.disconnect();
  }
예제 #2
0
  private void demo() throws IOException {
    String server = "127.0.0.1";
    int port = 9001;
    String password = "******";

    System.out.format("Attempting connection to %s:%s with password %s\n", server, port, password);

    // PlainConnection conn = new PlainConnection(server, port);
    SSLConnection conn = new SSLConnection(server, port);

    relay = new RelayConnection(conn, password);
    conn.addConnectionHandler(this);
    relay.connect();
  }