Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.evilOrion;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.Socket;
- import java.util.ArrayList;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import android.R;
- import android.app.Activity;
- import android.app.Service;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.IBinder;
- import android.os.RemoteException;
- import android.util.Log;
- import android.widget.Toast;
- /**
- *
- * @author tsama
- */
- public class IrcConnect extends Service implements Runnable{
- BufferedReader readIn = null;
- BufferedWriter writeOut = null;
- Socket irc = null;
- String server = "irc.unerror.com";
- int port = 6667;
- String nick = "javabot";
- String channel = "#java";
- static String str = "apples";
- private message service;
- String presentMessage = null;
- ArrayList<String>channelNames = null;
- Context context = null;
- class myThread extends Thread{
- public void run(){
- IrcConnection();
- }
- }
- public void onCreate(){
- super.onCreate();
- //Toast.makeText(this, "If this prints I will shit!!!", Toast.LENGTH_LONG).show();
- log("At onCreate Start: ");
- createConnect();
- Thread d = new myThread();
- d.start();
- }
- public void onResume(Bundle savedInstance){
- run();
- }
- //This is the message.Stub from the .aidl
- private final message.Stub binder = new
- message.Stub() {
- @Override
- public String echo() throws RemoteException {
- // TODO Auto-generated method stub
- return str;
- }
- };
- public IBinder onBind(Intent it){
- //createConnect();
- return binder;
- }
- public void createConnect(){
- try{
- log("tell me why can't i see thig");
- irc = new Socket(server, port);
- log("made it after socket");
- readIn = new BufferedReader(new InputStreamReader(irc.getInputStream()));
- log("made it after BufferedReader in onCreate");
- writeOut = new BufferedWriter(new OutputStreamWriter(irc.getOutputStream()));
- log("a;lskdjf;alkdsjf");
- }catch(IOException e){
- log("Exception!!! " );
- log(e.getMessage()+ " 1");
- log(e.toString() + " 2");
- e.printStackTrace();
- }
- }
- public void log (String input){
- Log.i("IrcConnect: ", input);
- }
- public void IrcConnection(){
- try{
- writeOut.write("NICK " + nick + "\r\n");
- writeOut.write("USER " + "javab" + " evilOrion.com JB: Java Bot \r\n");
- log("made it after writeOut to server");
- writeOut.flush();
- String lastMessage = null;
- //&& (!str.equals(lastMessage)
- while(((str = readIn.readLine())!= null)){
- lastMessage = str;
- presentMessage = lastMessage;
- log(presentMessage);
- pingCheck();
- nickServCheck();//ghost anyone on your name
- nickServ();//indentify with nickserv
- // Log.i("Blah", "ohhh oh ohhhhhh");
- returnMessage();
- //add message send back to mainUI
- Thread.sleep(200);
- }
- }catch(IOException e){
- log("Exception!!!-IrcConnection " );
- log(e.getMessage()+ " 1");
- log(e.toString() + " 2");
- e.printStackTrace();
- }
- catch(InterruptedException e){
- log("Exception!!! " );
- log(e.getMessage()+ " 1");
- log(e.toString() + " 2");
- e.printStackTrace();
- }
- }
- public String returnMessage(){
- return presentMessage;
- }
- public void pingCheck(){
- Pattern ping = Pattern.compile("PING");
- Matcher pingRep = ping.matcher(str);
- if(pingRep.find()){
- try{
- writeOut.write("PONG " + server + "\r\n");
- writeOut.flush();
- writeOut.write("JOIN " + channel + "\r\n");
- writeOut.flush();
- }catch(IOException e){
- log("Exception!!! " );
- log(e.getMessage()+ " 1");
- log(e.toString() + " 2");
- e.printStackTrace();
- }
- }
- }
- public void nickServCheck(){
- Pattern nameChange = Pattern.compile("Nickname is already in use");
- Matcher nameChangeRep = nameChange.matcher(str);
- if(nameChangeRep.find()){
- try{
- writeOut.write("NICK " + "Terrybillthebob\r\n");
- writeOut.flush();
- writeOut.write("PRIVMSG " + "NickServ" + " :" + "GHOST javabot 9jGB,H2*S\r\n");
- writeOut.flush();
- writeOut.write("NICK " + "javabot\r\n");
- writeOut.flush();
- }catch(IOException e){
- System.out.println("EXCEPTION! :" + e.getMessage() + " " + e.getCause());
- log("Exception!!! " );
- log(e.getMessage()+ " 1");
- log(e.toString() + " 2");
- e.printStackTrace();
- }
- }
- }
- public void nickServ (){
- Pattern nick2 = Pattern.compile("NickServ");
- Matcher nickRep = nick2.matcher(str);
- if(nickRep.find()){
- Pattern register = Pattern.compile("registered");
- Matcher registerRep = register.matcher(str);
- if(registerRep.find()){
- try{
- writeOut.write("PRIVMSG "+ "NickServ" + " :" + "IDENTIFY 9jGB,H2*S\r\n");
- writeOut.flush();
- }catch(IOException e){
- System.out.println("Exception: " + e.getMessage());
- log("Exception!!! " );
- log(e.getMessage()+ " 1");
- log(e.toString() + " 2");
- e.printStackTrace();
- }
- }
- }
- }
- public BufferedWriter retWriter(){
- return writeOut;
- }
- public void run(){
- IrcConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement