]> jfr.im git - irc/rizon/bncbot.git/commitdiff
Finish updating BNC config; check to make sure updating WORKED.
authorN Lum <redacted>
Tue, 4 Aug 2009 04:35:13 +0000 (04:35 +0000)
committerN Lum <redacted>
Tue, 4 Aug 2009 04:35:13 +0000 (04:35 +0000)
--HG--
extra : convert_revision : svn%3Aafccd9b4-69c3-4f67-9d0d-5b27f80d3d7c/trunk%407

src/net/rizon/bncbot/BncControlThread.java
src/net/rizon/bncbot/handler/BncApproveHandler.java
src/net/rizon/bncbot/handler/BncRejectHandler.java
strings.en.properties

index ad9c3d8879bec13bc375c4a9709cfea4c6a0cdb6..d4ea588b553f571690b9b3dff0c36777354d5708 100644 (file)
@@ -2,60 +2,116 @@ package net.rizon.bncbot;
 \r
 import java.io.PrintWriter;\r
 import java.net.Socket;\r
+import java.util.Hashtable;\r
 import java.util.Properties;\r
 import java.util.Scanner;\r
+import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
 import net.rizon.TrustingSSLSocketFactory;\r
 \r
 public class BncControlThread extends Thread {\r
        private Properties config = new Properties();\r
-       \r
+\r
        private PrintWriter netOut;\r
 \r
+       private Hashtable<String, String> results;\r
+\r
        public BncControlThread(Properties props) {\r
                this.config = props;\r
+\r
+               results = new Hashtable<String, String>();\r
        }\r
-       \r
+\r
        public void run() {\r
                try {\r
                        Socket socket = new TrustingSSLSocketFactory().createSocket(config.getProperty("server"), Integer.parseInt(config.getProperty("port")));\r
                        netOut = new PrintWriter(socket.getOutputStream(), true);\r
-                       \r
+\r
                        send("PASS :" + config.getProperty("pass"));\r
                        send("NICK " + config.getProperty("nick"));\r
                        send("USER " + config.getProperty("ident") + " 1 * :" + config.getProperty("gecos"));\r
-                       \r
+\r
                        // TODO - Fix so that scan.nextLine() does not have to return for thread to exit.\r
                        Scanner scan = new Scanner(socket.getInputStream());\r
                        Pattern ccStripper = Pattern.compile("[\u0002\u001F\u000F]");\r
                        Pattern colorStripper = Pattern.compile("\u0003[0-9]{1,2}(,[0-9]{1,2})?");\r
+                       Pattern userAddSuccess = Pattern.compile(":\\*admin!.*@.* PRIVMSG .* :User (.*) added!");\r
+                       Pattern userDelSuccess = Pattern.compile(":\\*admin!.*@.* PRIVMSG .* :User (.*) deleted!");\r
+                       Pattern genericError = Pattern.compile(":\\*admin!.*@.* PRIVMSG .* :Error: (User (.*) .*)");\r
                        String line;\r
                        while (BncBot.running && scan.hasNextLine() && !Thread.interrupted()) {\r
                                line = scan.nextLine();\r
                                line = ccStripper.matcher(line).replaceAll("");\r
                                line = colorStripper.matcher(line).replaceAll("");\r
-                               \r
+\r
                                if (BncBot.debug)\r
                                        System.out.println("BNC<- " + line);\r
-                               \r
+\r
                                // Do stuff with input if necessary.\r
+                               Matcher userAddM = userAddSuccess.matcher(line), userDelM = userDelSuccess.matcher(line), errorM = genericError.matcher(line);\r
+                               if (userAddM.matches()) {\r
+                                       synchronized (this.results) {\r
+                                               this.results.put(userAddM.group(1), "SUCCESS");\r
+                                       }\r
+                               }\r
+                               if (userDelM.matches()) {\r
+                                       synchronized (this.results) {\r
+                                               this.results.put(userDelM.group(1), "SUCCESS");\r
+                                       }\r
+                               }\r
+                               if (errorM.matches()) {\r
+                                       synchronized (this.results) {\r
+                                               this.results.put(errorM.group(2), errorM.group(1));\r
+                                       }\r
+                               }\r
                        }\r
-                       \r
+\r
                        scan.close();\r
                        socket.close();\r
-               } catch(Exception e) {\r
+               } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
        }\r
-       \r
+\r
        public boolean addUser(String user, String password) {\r
                privmsg("*admin", String.format("adduser %s %s irc.rizon.net", user, password));\r
-               \r
-               // TODO - Make this check to see if it succeeded.\r
-               return true;\r
+\r
+               long now = System.currentTimeMillis();\r
+               while (!this.results.containsKey(user) && (now + 1000 > System.currentTimeMillis())) { // One second timeout.\r
+                       try {\r
+                               Thread.sleep(100);\r
+                       } catch (Exception e) {\r
+                       }\r
+               }\r
+\r
+               if (!this.results.containsKey(user))\r
+                       return true;\r
+               else if (this.results.get(user).equals("SUCCESS"))\r
+                       return true;\r
+               else\r
+                       return false;\r
        }\r
        \r
+       public boolean delUser(String user) {\r
+               privmsg("*admin", String.format("deluser %s", user));\r
+\r
+               long now = System.currentTimeMillis();\r
+               while (!this.results.containsKey(user) && (now + 1000 > System.currentTimeMillis())) { // One second timeout.\r
+                       try {\r
+                               Thread.sleep(100);\r
+                       } catch (Exception e) {\r
+                       }\r
+               }\r
+\r
+               if (!this.results.containsKey(user))\r
+                       return true;\r
+               else if (this.results.get(user).equals("SUCCESS"))\r
+                       return true;\r
+               else\r
+                       return false;\r
+       }\r
+\r
        private void privmsg(String target, String msg) {\r
                if (msg.length() > 400) {\r
                        for (int i = 400; i > 0; i--) {\r
index 5c73076ea19f48218b587524305bdf996fdee214..1059e5fb5b572aeef4f5dcd7395970c60476147f 100644 (file)
@@ -38,10 +38,14 @@ public class BncApproveHandler extends AbstractSimpleHandler {
                                ue.approve(args[0].substring(1));\r
                                String pass = randomPass();\r
 \r
-                               // TODO - Actually modify the config file here.\r
+                               boolean result = BncBot.bncControl.addUser(ue.getNick(), pass);\r
 \r
-                               BncBot.privmsg(BncBot.config.getProperty("adminChannel"), String.format(BncBot.getString("adminBncAction"), BncBot.getString("adminApproved")));\r
-                               BncBot.sendMemo(ue.getNick(), String.format(BncBot.getString("approvalMemo"), ue.getNick(), pass));\r
+                               if (result) {\r
+                                       BncBot.privmsg(BncBot.config.getProperty("adminChannel"), String.format(BncBot.getString("adminBncAction"), BncBot.getString("adminApproved")));\r
+                                       BncBot.sendMemo(ue.getNick(), String.format(BncBot.getString("approvalMemo"), ue.getNick(), pass));\r
+                               } else {\r
+                                       BncBot.privmsg(BncBot.config.getProperty("adminChannel"), String.format(BncBot.getString("genericErrorReason"), BncBot.getString("errorConfigFail")));\r
+                               }\r
                        } else {\r
                                BncBot.privmsg(BncBot.config.getProperty("adminChannel"), String.format(BncBot.getString("adminAlreadyProcessed"), BncBot.getString("adminApproved")));\r
                        }\r
@@ -68,7 +72,7 @@ public class BncApproveHandler extends AbstractSimpleHandler {
                                        break;\r
                        }\r
                }\r
-               \r
+\r
                return sb.toString();\r
        }\r
 \r
index 0028fe96fb52800a2f442e53e15fc1295acaa68c..401c17b036ff8580de6f273dd687bdf71455b325 100644 (file)
@@ -34,7 +34,7 @@ public class BncRejectHandler extends AbstractSimpleHandler {
                        if (ue.getApprovalState() == UserDB.UserEntry.ApprovalState.NotProcessed) { // Can only reject non-approved things.\r
                                ue.reject(args[0].substring(1), reason);\r
 \r
-                               // TODO - Actually modify the config file here.\r
+                               BncBot.bncControl.delUser(ue.getNick());\r
 \r
                                BncBot.privmsg(BncBot.config.getProperty("adminChannel"), String.format(BncBot.getString("adminBncAction"), BncBot.getString("adminRejected")));\r
                                BncBot.sendMemo(ue.getNick(), String.format(BncBot.getString("rejectionMemo"), reason, BncBot.getString("userAppeal")));\r
index 6f2e96fb60191cce2d6fc2897ed9d3a878920535..f457e55eb222dfc174aeb50ca4fd1b3ddcefb3b5 100644 (file)
@@ -8,6 +8,11 @@ genericError = An error occurred while processing your request.
 # Generic error with explanation.\r
 genericErrorReason = An error occurred while processing your request: %1$s\r
 \r
+# =======================\r
+# ERROR\r
+# =======================\r
+errorConfigFail = Updating BNC configuration failed.\r
+\r
 # =======================\r
 # Admin Strings\r
 # =======================\r
@@ -36,7 +41,7 @@ adminHelp = To accept the request, type '.bncapprove' followed by either the mai
 # Please wait!\r
 userPleaseWait = Please wait...looking up your details...\r
 # Rejection appeal message.\r
-userAppeal = To appeal the rejection, contact a user with voice (+v) in #RizonBNC.\r
+userAppeal = To appeal the rejection, contact a user with voice (+v) or higher in #RizonBNC.\r
 # Already approved message.\r
 #      - First argument is the nick of the approving user.\r
 #      - Second argument is the hostmask (ident@host) of the approving user.\r
@@ -59,7 +64,7 @@ userErrorTime = The main nick of your group must be registered for at least 7 da
 # Approval memo\r
 #      - First argument is the BNC username.\r
 #      - Second argument is the BNC password.\r
-approvalMemo = It is with great pleasure that we inform you that your BNC application has been APPROVED. To log on to your BNC, connect to bnc.rizon.net with the server password '%1$s:%2$s'. Thank you for flying Rizon!\r
+approvalMemo = It is with great pleasure that we inform you that your BNC application has been APPROVED. To log on to your BNC, connect to rizonbnc.us.rizon.net with the server password '%1$s:%2$s'. Thank you for flying Rizon!\r
 # Rejection memo\r
 #      - First argument is a string containing the reason.\r
 #      - Second argument is the rejection appeal notice above.\r