Source code: org/rakiura/mbot/Main.java
1
2 package org.rakiura.mbot;
3
4 /**/
5 import java.util.*;
6 import java.io.*;
7
8 /**
9 * Main, 'starting' class for the entire bot. Main startup for irc bot, eMbot.<br>
10 * <br>Created: Sun Jun 13 18:35:34 1999<br>
11 *
12 *@author Mariusz Nowostawski
13 *@version $Revision: 1.1.1.1 $
14 */
15 public class Main {
16
17 static String VERSION = "1.0beta ($Revision: 1.1.1.1 $)";
18 /* constants and variables */
19 static String sConfigFile = "embot.config";
20 static String sChanFile = "embot.channels";
21 static String sUsersFile = "embot.users";
22
23 public static boolean DCCActive = true;
24 public static String DCCversion = "eMbot ver"+VERSION+" by Marni";
25 public static String DCCuserinfo = "eMbot user, so what?";
26 public static String DCCosversion = "GNU NASA OS 0.127.5334beta by US Navy";
27
28 Vector servers;
29 Vector nicks;
30 Hashtable channels;
31 String host, user, ircname="deep";
32
33 int EDCCport, DCCport, MasterPort=0, ircport = 6667;
34 String EDCCpass, MasterHost="#";
35
36 boolean blind = true;
37 boolean scripts = true;
38
39 /**
40 * Constructs the Engine object, and connect to the IRC server.
41 */
42 public Main() {
43
44 System.out.println("Loading: eMbot version "+VERSION);
45 System.out.println("Copyright (C) 1998-2000 by Mariusz Nowostawski (Marni)");
46 System.out.println(" ");
47
48 nicks = new Vector(2);
49 channels = new Hashtable(5);
50 servers = new Vector(5);
51 ConfigProcess();
52 Engine engine = new Engine(servers, ircport, nicks, channels,
53 DCCport, EDCCport, EDCCpass,
54 user, host, ircname, MasterHost, MasterPort,
55 blind, scripts);
56 engine.rejoinToServer();
57 }
58
59 /**
60 * Process the configuration file.
61 */
62 public void ConfigProcess() {
63
64 boolean koniec = false;
65 BufferedReader in;
66 String s = new String("");
67 String buf_temp = new String ("");
68 String temp;
69 int i;
70
71 try {
72 in = new BufferedReader(new FileReader(Main.sConfigFile));
73 while(!koniec) {//while
74 try{
75 s = in.readLine();
76 if(s == null) koniec = true;
77 }catch(IOException e){
78 e.printStackTrace();
79 koniec = true;
80 }
81 if(s!=null) {
82 if(!s.startsWith("#")) {
83 StringTokenizer tt = new StringTokenizer(s, "\t=\n\r");
84
85 //process 2 tokens options first
86 if(tt.countTokens()==2) {
87 buf_temp = tt.nextToken();
88
89 //////////
90 if(buf_temp.equals("Server")){
91 temp = tt.nextToken();
92 servers.addElement(new String(temp));
93 } else
94 if(buf_temp.equals("Nick")){
95 temp = tt.nextToken();
96 nicks.addElement(new String(temp));
97 } else
98 if(buf_temp.equals("IRCname")){
99 ircname = tt.nextToken();
100 } else
101 if(buf_temp.equals("BlindMODES")){
102 blind = tt.nextToken().trim().toLowerCase().startsWith("true");
103 } else
104 if(buf_temp.equals("SCRIPTS")){
105 scripts = tt.nextToken().trim().toLowerCase().startsWith("true");
106 } else
107 if(buf_temp.equals("EDCCport")){
108 temp = tt.nextToken();
109 EDCCport = Integer.parseInt(temp);
110 } else
111 if(buf_temp.equals("EDCCpass")){
112 temp = tt.nextToken();
113 EDCCpass = temp;
114 } else
115 if(buf_temp.equals("DCCport")){
116 temp = tt.nextToken();
117 DCCport = Integer.parseInt(temp);
118 } else
119 if(buf_temp.equals("IRCport")){
120 temp = tt.nextToken();
121 ircport = Integer.parseInt(temp);
122 } else
123 if(buf_temp.equals("Host")){
124 temp = tt.nextToken();
125 host = new String(temp);
126 } else
127 if(buf_temp.equals("User")){
128 temp = tt.nextToken();
129 user = new String(temp);
130 } else
131 if(buf_temp.equals("MasterHost")){
132 temp = tt.nextToken();
133 MasterHost = new String(temp);
134 }else
135 if(buf_temp.equals("MasterPort")){
136 temp = tt.nextToken();
137 MasterPort = Integer.parseInt(temp);
138 } else
139 if(buf_temp.equals("DCCversion")){
140 temp = tt.nextToken();
141 DCCversion = temp;
142 } else
143 if(buf_temp.equals("DCCuserinfo")){
144 temp = tt.nextToken();
145 DCCuserinfo = temp;
146 } else
147 if(buf_temp.equals("DCCosversion")){
148 temp = tt.nextToken();
149 DCCosversion = temp;
150 } else
151 if(buf_temp.equals("DCCActive")){
152 DCCActive = tt.nextToken().trim().toLowerCase().startsWith("true");
153 }
154 }
155 else
156 //now other options
157 if(tt.countTokens() > 2) {
158 if(buf_temp.equals("IRCname")){
159 temp = tt.nextToken();
160 ircname = new String(temp);
161 while(tt.hasMoreTokens()) ircname = ircname + " "+ tt.nextToken();
162 } else
163 if(buf_temp.equals("DCCversion")){
164 temp = tt.nextToken();
165 DCCversion = new String(temp);
166 while(tt.hasMoreTokens()) DCCversion = DCCversion + " "+ tt.nextToken();
167 } else
168 if(buf_temp.equals("DCCuserinfo")){
169 temp = tt.nextToken();
170 DCCuserinfo = new String(temp);
171 while(tt.hasMoreTokens()) DCCuserinfo = DCCuserinfo + " "+ tt.nextToken();
172 } else
173 if(buf_temp.equals("DCCosversion")){
174 temp = tt.nextToken();
175 DCCosversion = new String(temp);
176 while(tt.hasMoreTokens()) DCCosversion = DCCosversion + " "+ tt.nextToken();
177 }
178 }
179 }
180 }
181 }
182 System.out.println("Engine data read.");
183 in.close();
184 }catch(IOException e){
185 System.out.println("ERROR: Cannot access file with configuration!");
186 System.out.println(" Please create <embot.config> <embot.users> and <embot.channels>");
187 System.out.println(" files and put them in the local directory, for bot to read them.");
188 System.exit(0);
189 }
190
191 try{
192 in = new BufferedReader(new FileReader(Main.sChanFile));
193 boolean ok = true;
194 while(ok) {
195 Channel chan = new Channel();
196 ok = chan.readFromTextData(in);
197 if(ok) channels.put(chan.getName(), chan);
198 }
199 in.close();
200 System.out.println("Channel data read.");
201 }catch(IOException ex){
202 System.out.println("ERROR: Cannot access file with channels!");
203 System.exit(0);
204 }
205 }
206
207 /**
208 * Startup.
209 */
210 public static void main(String[] args) throws IOException {
211 Main agent = new Main();
212 }
213
214 } // eMbot
215
216 /////////////// end of file ///////////////