Source code: org/rakiura/mbot/PingThread.java
1
2 package org.rakiura.mbot;
3
4 /**/
5 import java.io.*;
6 import java.net.*;
7 import java.util.*;
8
9 /**
10 * PingThread.java
11 * Created: Wed Jul 14 19:38:55 1999
12 *
13 *@author Mariusz Nowostawski
14 *@version 0.3 $Revision: 1.1.1.1 $
15 */
16 public class PingThread extends Thread {
17
18 Engine engine;
19
20 PingThread(Engine f){
21 engine = f;
22 }
23
24 public void run() {
25 try{
26 String line, buf;
27 int index;
28 try{ Thread.sleep(10000); } catch(InterruptedException e){ e.printStackTrace(); }
29 synchronized(engine){
30 line = engine.readLine();
31 // DEBUG System.out.println(line);
32 }
33 while(true) { //while true
34 while(line!=null) { //while line != null
35 if(line.startsWith(":"))
36 line = line.substring(1);
37
38 ///////////////////////// Parsing Server lines
39 /// DEBUG ONLY ......
40 /*DEBUG*/ System.out.println(line);
41
42 StringTokenizer st = new StringTokenizer(line, " ");
43 if(st.hasMoreTokens()) {
44 buf = st.nextToken().trim();
45 if(buf.equals("PING")) {
46 String t = st.nextToken();
47 engine.out.println("PONG "+t);
48 } else
49 if(buf.equals("ERROR") || (buf.equals("NOTICE")))
50 System.out.println(line);
51 else
52 if(buf.equals(engine.getNick()))
53 System.out.println("*"+line);
54 else
55 if(buf.indexOf("!") == -1){//server data
56 String swhat;
57 if(st.hasMoreTokens())
58 swhat = st.nextToken();
59 else swhat = "0";
60 swhat = swhat.trim();
61 int what;
62 try{
63 what = Integer.parseInt(swhat);
64 }catch(NumberFormatException e){
65 what = 0;
66 if(line.toLowerCase().indexOf(" mode ")!=-1) {//we have mode hack
67 engine.modeHackVector.addString(line);
68 }
69 }
70 switch(what){
71 case 321 :
72 case 322 :
73 case 323 : engine.listLineVector.addString(line);
74 break;
75 case 432:
76 case 433:
77 case 436: engine.nextNick();
78 break;
79 case 346:
80 case 347: engine.chanInvitationLineVector.addString(line);
81 break;
82 case 348:
83 case 349: engine.chanExceptionLineVector.addString(line);
84 break;
85 case 352:
86 case 315: engine.whoLineVector.addString(line);
87 break;
88 case 451: engine.nextNick();
89 break;
90 case 471:
91 case 473:
92 case 474:
93 case 475: engine.joinRejectLineVector.addString(line);
94 case 482 : if(!engine.BlindMODES) engine.IamOP.remove(engine.LastMode_chan.toLowerCase());
95 break;
96 default : //DEBUG System.out.println("??: "+line);
97 break;
98 }
99 } else { //user data
100 String what = st.nextToken().trim();
101 if(what.toLowerCase().equals("notice") ||
102 what.trim().toLowerCase().equals("privmsg"))
103 engine.msgLineVector.addString(line);
104 else
105 if(what.toLowerCase().equals("kick"))
106 engine.kickLineVector.addString(line);
107 else
108 if(what.toLowerCase().equals("join"))
109 engine.joinLineVector.addString(line);
110 else
111 if(what.toLowerCase().equals("part") ||
112 what.toLowerCase().equals("quit"))
113 engine.partLineVector.addString(line);
114 else
115 if(what.toLowerCase().equals("mode"))
116 engine.modeLineVector.addString(line);
117 else
118 if(what.toLowerCase().equals("nick"))
119 engine.nickLineVector.addString(line);
120 else
121 ; //DEBUG System.out.println("Uknown message: "+line);
122 }
123 }
124 line = engine.readLine();
125 while(line != null && line.startsWith(engine.getNick())) line = engine.readLine();
126 }
127
128 engine.rejoinToServer();
129 try{ Thread.sleep(10000); } catch(InterruptedException e){ e.printStackTrace(); }
130 line = "REJOIN... ";
131 }
132 }catch(Exception e){
133 System.out.println("Very BAD ERROR --- quiting..... \n Report this bug to the author, please!");
134 e.printStackTrace();
135 System.exit(0);
136 }
137 }
138
139
140 /*********/
141
142 public final static int RPL_LISTSTART = 321; // Channel :Users Name
143 public final static int RPL_LIST = 322; // <channel> <# visible> :<topic>
144 public final static int RPL_LISTEND = 323; // :End of /LIST
145
146 public final static int RPL_WHOREPLY = 352;// "<channel> <user> <host> <server> <nick> <H|G>[*][@|+] :<hopcount> <real name>"
147 public final static int RPL_ENDOFWHO = 315;// "<name> :End of /WHO list"
148
149 public final static int RPL_EXPNSTART = 346; // mask
150 public final static int RPL_EXPNEND = 347; // :End of Invitation
151 public final static int RPL_INVSTART = 348; //
152 public final static int RPL_INVEND = 349; // :End of Exception
153
154 public final static int ERR_ERRONEUSNICKNAME = 432; // "<nick> :Erroneus nickname"
155 public final static int ERR_NICKNAMEINUSE = 433; // "<nick> :Nickname is already in use"
156 public final static int ERR_NICKCOLLISION = 436; // "<nick> :Nickname collision KILL"
157
158 public final static int ERR_CHANNELISFULL = 471; // "<channel> :Cannot join channel (+l)"
159 public final static int ERR_INVITEONLYCHAN = 473; // "<channel> :Cannot join channel (+i)"
160 public final static int ERR_BANNEDFROMCHAN = 474; // "<channel> :Cannot join channel (+b)"
161 public final static int ERR_BADCHANNELKEY = 475; // "<channel> :Cannot join channel (+k)"
162
163 public final static int ERR_CHANOPRIVSNEEDED =482; // "<channel> :You're not channel operator"
164
165
166 } // PingThread
167 //////////////////// end of file ////////////////////
168
169