Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. package com.evilOrion;
  2.  
  3. /*
  4. * To change this template, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7.  
  8.  
  9.  
  10. import java.io.BufferedReader;
  11. import java.io.BufferedWriter;
  12. import java.io.IOException;
  13. import java.io.InputStreamReader;
  14. import java.io.OutputStreamWriter;
  15. import java.net.Socket;
  16. import java.util.ArrayList;
  17. import java.util.regex.Matcher;
  18. import java.util.regex.Pattern;
  19.  
  20. import android.R;
  21. import android.app.Activity;
  22. import android.app.Service;
  23. import android.content.Context;
  24. import android.content.Intent;
  25. import android.os.Bundle;
  26. import android.os.IBinder;
  27. import android.os.RemoteException;
  28. import android.util.Log;
  29. import android.widget.Toast;
  30.  
  31. /**
  32. *
  33. * @author tsama
  34. */
  35. public class IrcConnect extends Service implements Runnable{
  36. BufferedReader readIn = null;
  37. BufferedWriter writeOut = null;
  38.  
  39. Socket irc = null;
  40. String server = "irc.unerror.com";
  41. int port = 6667;
  42. String nick = "javabot";
  43. String channel = "#java";
  44. static String str = "apples";
  45. private message service;
  46. String presentMessage = null;
  47. ArrayList<String>channelNames = null;
  48. Context context = null;
  49.  
  50.  
  51.  
  52. class myThread extends Thread{
  53. public void run(){
  54. IrcConnection();
  55. }
  56. }
  57.  
  58.  
  59. public void onCreate(){
  60. super.onCreate();
  61. //Toast.makeText(this, "If this prints I will shit!!!", Toast.LENGTH_LONG).show();
  62. log("At onCreate Start: ");
  63. createConnect();
  64.  
  65. Thread d = new myThread();
  66. d.start();
  67.  
  68. }
  69. public void onResume(Bundle savedInstance){
  70. run();
  71. }
  72. //This is the message.Stub from the .aidl
  73. private final message.Stub binder = new
  74. message.Stub() {
  75.  
  76. @Override
  77. public String echo() throws RemoteException {
  78. // TODO Auto-generated method stub
  79.  
  80.  
  81. return str;
  82. }
  83. };
  84.  
  85. public IBinder onBind(Intent it){
  86. //createConnect();
  87.  
  88. return binder;
  89. }
  90.  
  91. public void createConnect(){
  92. try{
  93. log("tell me why can't i see thig");
  94. irc = new Socket(server, port);
  95. log("made it after socket");
  96.  
  97. readIn = new BufferedReader(new InputStreamReader(irc.getInputStream()));
  98. log("made it after BufferedReader in onCreate");
  99. writeOut = new BufferedWriter(new OutputStreamWriter(irc.getOutputStream()));
  100. log("a;lskdjf;alkdsjf");
  101. }catch(IOException e){
  102. log("Exception!!! " );
  103. log(e.getMessage()+ " 1");
  104. log(e.toString() + " 2");
  105. e.printStackTrace();
  106.  
  107.  
  108. }
  109. }
  110.  
  111.  
  112. public void log (String input){
  113. Log.i("IrcConnect: ", input);
  114. }
  115. public void IrcConnection(){
  116. try{
  117. writeOut.write("NICK " + nick + "\r\n");
  118. writeOut.write("USER " + "javab" + " evilOrion.com JB: Java Bot \r\n");
  119.  
  120. log("made it after writeOut to server");
  121. writeOut.flush();
  122. String lastMessage = null;
  123. //&& (!str.equals(lastMessage)
  124. while(((str = readIn.readLine())!= null)){
  125. lastMessage = str;
  126.  
  127. presentMessage = lastMessage;
  128. log(presentMessage);
  129. pingCheck();
  130. nickServCheck();//ghost anyone on your name
  131. nickServ();//indentify with nickserv
  132. // Log.i("Blah", "ohhh oh ohhhhhh");
  133. returnMessage();
  134. //add message send back to mainUI
  135.  
  136. Thread.sleep(200);
  137. }
  138.  
  139. }catch(IOException e){
  140. log("Exception!!!-IrcConnection " );
  141. log(e.getMessage()+ " 1");
  142. log(e.toString() + " 2");
  143. e.printStackTrace();
  144. }
  145. catch(InterruptedException e){
  146. log("Exception!!! " );
  147. log(e.getMessage()+ " 1");
  148. log(e.toString() + " 2");
  149. e.printStackTrace();
  150. }
  151.  
  152. }
  153.  
  154. public String returnMessage(){
  155. return presentMessage;
  156. }
  157.  
  158. public void pingCheck(){
  159. Pattern ping = Pattern.compile("PING");
  160. Matcher pingRep = ping.matcher(str);
  161. if(pingRep.find()){
  162. try{
  163. writeOut.write("PONG " + server + "\r\n");
  164. writeOut.flush();
  165.  
  166. writeOut.write("JOIN " + channel + "\r\n");
  167. writeOut.flush();
  168. }catch(IOException e){
  169. log("Exception!!! " );
  170. log(e.getMessage()+ " 1");
  171. log(e.toString() + " 2");
  172. e.printStackTrace();
  173. }
  174. }
  175. }
  176.  
  177. public void nickServCheck(){
  178. Pattern nameChange = Pattern.compile("Nickname is already in use");
  179. Matcher nameChangeRep = nameChange.matcher(str);
  180. if(nameChangeRep.find()){
  181.  
  182. try{
  183. writeOut.write("NICK " + "Terrybillthebob\r\n");
  184. writeOut.flush();
  185.  
  186. writeOut.write("PRIVMSG " + "NickServ" + " :" + "GHOST javabot 9jGB,H2*S\r\n");
  187. writeOut.flush();
  188.  
  189. writeOut.write("NICK " + "javabot\r\n");
  190. writeOut.flush();
  191. }catch(IOException e){
  192. System.out.println("EXCEPTION! :" + e.getMessage() + " " + e.getCause());
  193. log("Exception!!! " );
  194. log(e.getMessage()+ " 1");
  195. log(e.toString() + " 2");
  196. e.printStackTrace();
  197. }
  198.  
  199. }
  200. }
  201.  
  202.  
  203. public void nickServ (){
  204. Pattern nick2 = Pattern.compile("NickServ");
  205. Matcher nickRep = nick2.matcher(str);
  206. if(nickRep.find()){
  207. Pattern register = Pattern.compile("registered");
  208. Matcher registerRep = register.matcher(str);
  209. if(registerRep.find()){
  210. try{
  211. writeOut.write("PRIVMSG "+ "NickServ" + " :" + "IDENTIFY 9jGB,H2*S\r\n");
  212. writeOut.flush();
  213. }catch(IOException e){
  214. System.out.println("Exception: " + e.getMessage());
  215. log("Exception!!! " );
  216. log(e.getMessage()+ " 1");
  217. log(e.toString() + " 2");
  218. e.printStackTrace();
  219. }
  220. }
  221. }
  222.  
  223. }
  224.  
  225. public BufferedWriter retWriter(){
  226. return writeOut;
  227. }
  228. public void run(){
  229. IrcConnection();
  230. }
  231.  
  232.  
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement