private void connect() throws UnknownHostException, IOException { IrcServer = new Socket(serverName, 6667); BufferedReader br = new BufferedReader( new InputStreamReader(IrcServer.getInputStream(), BotStats.getInstance().getCharset())); PrintWriter pw = new PrintWriter( new OutputStreamWriter( IrcServer.getOutputStream(), BotStats.getInstance().getCharset()), true); ih = new InputHandler(br); oh = new OutputHandler(pw); ih.start(); oh.start(); new Message("", "NICK", BotStats.getInstance().getBotname(), "").send(); new Message( "", "USER", "goat" + " nowhere.com " + serverName, BotStats.getInstance().getVersion()) .send(); // we sleep until we are connected, don't want to send these next messages too soon while (!connected) { try { sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } joinChannels(); }
public static boolean exec(String cmd) throws Exception { int exitVal = -1; try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(new String[] {"/bin/bash", "-c", cmd}); OutputHandler err = new OutputHandler(proc.getErrorStream(), cmd); err.start(); OutputHandler out = new OutputHandler(proc.getInputStream(), cmd); out.start(); exitVal = proc.waitFor(); } catch (Throwable t) { t.printStackTrace(); } return (exitVal == 0); }
protected void setCharset(Charset cs) { try { BufferedReader br = new BufferedReader(new InputStreamReader(IrcServer.getInputStream(), cs)); PrintWriter pw = new PrintWriter(new OutputStreamWriter(IrcServer.getOutputStream(), cs), true); ih.setBR(br); oh.setOSW(pw); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { System.err.println("Unexpected exception in setCharset :"); e.printStackTrace(); } }