]> jfr.im git - irc/borknet/trunk.git/blob - core/modules/q/Hello.java
193ce1ec3471057240cbe61336268a3e1690f3e9
[irc/borknet/trunk.git] / core / modules / q / Hello.java
1 /**
2 #
3 # BorkNet Services Core
4 #
5
6 #
7 # Copyright (C) 2004 Ozafy - ozafy@borknet.org - http://www.borknet.org
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #
23 */
24 import java.io.*;
25 import java.util.*;
26 import java.text.*;
27 import java.util.regex.*;
28 import borknet_services.core.*;
29
30 /**
31 * Class to load configuration files.
32 * @author Ozafy - ozafy@borknet.org - http://www.borknet.org
33 */
34 public class Hello implements Command
35 {
36 /**
37 * Constructs a Loader
38 * @param debug If we're running in debug.
39 */
40 public Hello()
41 {
42 }
43
44 public void parse_command(Core C, Q Bot, DBControl dbc, String numeric, String botnum, String target, String username, String params)
45 {
46 String nick = Bot.get_nick();
47 String host = Bot.get_host();
48 if(Bot.getDefCon() < 5)
49 {
50 C.cmd_notice(numeric, botnum, "Defcon "+Bot.getDefCon()+" enabled: "+nick+" will not accept any new registrations, we apologize for any inconvenience caused.");
51 return;
52 }
53 String[] result = params.split("\\s");
54 try
55 {
56 String mail1 = result[1];
57 String mail2 = result[2];
58 //for typo purposes we check if the user has entered the same mail 2ce
59 if(mail1.equals(mail2))
60 {
61 //retards
62 if (!mail1.contains("@") || !mail1.contains(".") || mail1.startsWith("<"))
63 {
64 C.cmd_notice(numeric, botnum, username, "Invalid address.");
65 return;
66 }
67 if (dbc.isMailBlocked(mail1))
68 {
69 C.cmd_notice(numeric, botnum, username, "This mail has been blocked and cannot be used to register an account with "+nick+".");
70 return;
71 }
72 String userinfo[] = dbc.getUserRow(username);
73 //he's not authed yet, yay
74 if(userinfo[4].equals("0"))
75 {
76 //check for bad chars
77 if(!userinfo[1].matches("[A-Za-z0-9-]*"))
78 {
79 C.cmd_notice(numeric, botnum, username, "Your nick may not contain odd characters like \\ or `");
80 return;
81 }
82 }
83 //he's allready authed, authed people don't need extra accounts >:(
84 else
85 {
86 C.cmd_notice(numeric, botnum, username, "You are allready AUTH'd!");
87 return;
88 }
89 //someone allready holds this authnick
90 if(dbc.authExists(userinfo[1]))
91 {
92 C.cmd_notice(numeric, botnum, username, "Someone allready AUTH'd with that nick");
93 return;
94 }
95 //the chars to be used in password generating
96 String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
97 String userpass = "";
98 //make the password (length 7)
99 for(int i=0 ; i<7 ;i++)
100 {
101 Random generator = new Random();
102 int g = generator.nextInt(60);
103 userpass += chars.substring(g,g+1);
104 }
105 String pass = dbc.encrypt(userpass);
106 //the actual message, you can easely add/change it
107 //use the tag to indicate a space, \n for a newline
108 if(Bot.getSendmail())
109 {
110 String subj = "Your " + nick + " account!";
111 String mesg = "Your login/password is:\n";
112 mesg += "Login: " + userinfo[1] + "\n";
113 mesg += "Password: " + userpass + "\n";
114 mesg += "\n";
115 mesg += "To AUTH yourself type the following command:\n";
116 mesg += "/msg " + nick + "@" + host + " AUTH " + userinfo[1] + " " + userpass + "\n";
117 mesg += "or you can use the challenge-repsonse method\n";
118 mesg += "\n";
119 mesg += "You can use the newpass command to change your password:\n";
120 mesg += "/msg " + nick + " newpass " + userpass + " newpassword newpassword\n";
121 mesg += "would change your password in newpassword.\n";
122 mesg += "\n";
123 mesg += "NB: Save this email for future reference.\n";
124 //call the external thread to send the mail, and not hog recources
125 C.send_mail(subj, mail1, mesg,nick,host);
126 //well, we hope it's sent
127 C.cmd_notice(numeric, botnum, username, "Mail Sent to " + mail1 + "!");
128 }
129 else
130 {
131 C.cmd_notice(numeric, botnum, username, "Account created successfully, your new password is: " + userpass + "!");
132 }
133 //we add his info to the active authed array
134 dbc.addAuth(userinfo[1],pass,mail1,1,false,Long.parseLong(C.get_time()),"0","0","0");
135 return;
136 }
137 //he made a typo in an address, or is retarded
138 else
139 {
140 C.cmd_notice(numeric, botnum, username, "Adresses don't match.");
141 return;
142 }
143 }
144 catch(ArrayIndexOutOfBoundsException e)
145 {
146 C.cmd_notice(numeric, botnum, username, "/msg " + nick + " hello <your@mail.here> <your@mail.here>");
147 return;
148 }
149 }
150
151 public void parse_help(Core C, Q Bot, String numeric, String botnum, String username, int lev)
152 {
153 C.cmd_notice(numeric, botnum, username, "/msg " + Bot.get_nick() + " hello <your@mail.here> <your@mail.here>");
154 C.cmd_notice(numeric, botnum, username, "Will get you an account with your current nick.");
155 C.cmd_notice(numeric, botnum, username, "eg: /msg " + Bot.get_nick() + " hello ozafy@borknet.org ozafy@borknet.org");
156 }
157 public void showcommand(Core C, Q Bot, String numeric, String botnum, String username, int lev)
158 {
159 C.cmd_notice(numeric, botnum, username, "HELLO Creates an account with the bot.");
160 }
161 }