]> Pileus Git - ~andy/spades/commitdiff
Fix .look bugs
authorAndy Spencer <andy753421@gmail.com>
Thu, 12 Nov 2015 06:41:20 +0000 (06:41 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 15 Nov 2015 23:26:11 +0000 (23:26 +0000)
src/Client.java
src/Main.java
src/Message.java
src/Spades.java

index dc7c2dbba04c4106e442191107e03f7de9f1a1f0..d3349f49ead055d787bfb007b6891c85624803ef 100644 (file)
@@ -148,7 +148,9 @@ public class Client
                        this.process(msg);
                        if (this.usesasl)
                                this.dosasl(msg);
-                       return msg;
+                       if (!msg.cmd.equals("PING") &&
+                           !msg.cmd.equals("PONG"))
+                               return msg;
                }
                catch (SocketTimeoutException e) {
                        if (this.pinging) {
index 362af122c04e825127d2bfc822f61e36609b0f42..09c61809e19ae8a63c2588e46a14b4a670d1135a 100644 (file)
@@ -145,6 +145,12 @@ public class Main extends Activity
                this.send.setVisibility(running ? View.VISIBLE : View.GONE);
        }
 
+       private void scroll()
+       {
+               this.dscroll.smoothScrollTo(0, this.debug.getBottom());
+               this.lscroll.smoothScrollTo(0, this.log.getBottom());
+       }
+
        /* Private handler methods */
        private void onRegister(Task task)
        {
@@ -160,13 +166,13 @@ public class Main extends Activity
                        if (Message.class.isInstance(obj))
                                this.onMessage((Message)obj);
                }
+               this.scroll();
        }
 
        private void onMessage(Message msg)
        {
                // Debug
                this.debug.append("> " + msg.line + "\n");
-               this.dscroll.smoothScrollTo(0, this.debug.getBottom());
 
                // Chat
                switch (msg.type) {
@@ -194,7 +200,6 @@ public class Main extends Activity
                                this.notice("Authentication failed: " + msg.txt);
                                break;
                }
-               this.lscroll.smoothScrollTo(0, this.log.getBottom());
 
                // Update title
                if (this.cards.turn  != null && this.cards.turn  != "" &&
@@ -426,6 +431,7 @@ public class Main extends Activity
                                        break;
                                case Task.MESSAGE:
                                        Main.this.onMessage((Message)msg.obj);
+                                       Main.this.scroll();
                                        break;
                                case Task.CONNECT:
                                        Main.this.update(true);
index d12f42fce69e908e8a57ab81c37111cabe69d8e7..8213509ce98251ff2faf25cb968b41799a4f6999 100644 (file)
@@ -118,21 +118,21 @@ public class Message
        private static final Pattern cPtrn  = Pattern.compile(cRegex);
 
        /* Public data */
-       public Date    time = null;
+       public Date    time = null;        // Message delivery time
 
-       public String  line = "";
+       public String  line = "";          // Raw IRC line     -- george@~g@example.com PRIVMSG #chat :larry: hello!
 
-       public String  src  = "";
-       public String  cmd  = "";
-       public String  dst  = "";
-       public String  arg  = "";
-       public String  msg  = "";
+       public String  src  = "";          // IRC Source       -- george!~g@example.com
+       public String  cmd  = "";          // IRC Command      -- PRIVMSG
+       public String  dst  = "";          // IRC Destination  -- #chat
+       public String  arg  = "";          // IRC Arguments    -- #chan in topic msg, etc
+       public String  msg  = "";          // IRC Message text -- larry: Hello!
 
-       public Type    type = Type.OTHER;
-       public How     how  = How.OTHER;
-       public String  from = "";
-       public String  to   = "";
-       public String  txt  = "";
+       public Type    type = Type.OTHER;  // Message Type     -- PRIVMSG
+       public How     how  = How.OTHER;   // How msg relates  -- SENT=geroge, DIRECT=larry, CHANNEL=*
+       public String  from = "";          // Nick of sender   -- george
+       public String  to   = "";          // Addressed name   -- larry
+       public String  txt  = "";          // Text of msg      -- Hello!
 
        public List<Format> parts = new ArrayList<Format>();
 
@@ -350,8 +350,8 @@ public class Message
                // Cleanup extra space
                list.trimToSize();
                this.parts = list;
-               this.msg   = msg.replaceAll(cRegex, "");
-               this.to    = msg.replaceAll(cRegex, "");
-               this.txt   = msg.replaceAll(cRegex, "");
+               this.msg   = this.msg.replaceAll(cRegex, "");
+               this.to    = this.to.replaceAll(cRegex, "");
+               this.txt   = this.txt.replaceAll(cRegex, "");
        }
 }
index b1d9d74979b9137ef435787588b8a6f8ab08863b..770cd1c3c6b9c0dbbea5503241f407a807d7f0ee 100644 (file)
@@ -6,7 +6,7 @@ public class Spades
        public  Task    task;
        public  Cards   cards;
        public  String  admin;
-       public  boolean looked;
+       public  boolean look;
 
        /* Static methods */
        private static String[] getCards(String msg, String regex)
@@ -38,13 +38,14 @@ public class Spades
                        return;
 
                String txt = msg.txt;
-               if (txt.matches(".*turn!.*") && !this.looked) {
+               if (txt.matches(".*turn!.*") && this.look) {
                        this.send(this.admin, ".look");
-                       this.looked = true;
+                       this.look = false;
                }
                if (txt.startsWith("You have: ")) {
                        this.cards.hand = Spades.getCards(txt, "You have: (.*)");
                        this.cards.requestRender();
+                       this.look = false;
                }
                if (txt.matches(".*turn!.*")) {
                        this.cards.pile = Spades.getCards(txt, ".*turn! \\((.*)\\)");
@@ -55,8 +56,9 @@ public class Spades
                        this.cards.state = txt.replaceAll("It is (\\w+)'s (\\w+)!.*", "$2");
                        this.cards.requestRender();
                }
-               if (txt.startsWith("^it is your")) {
-                       this.cards.turn = msg.to;
+               if (txt.startsWith("it is your") && msg.to != "") {
+                       this.cards.turn  = msg.to;
+                       this.cards.state = txt.replaceAll("it is your (\\w+)!", "$1");
                        this.cards.requestRender();
                }
        }
@@ -65,9 +67,9 @@ public class Spades
        public boolean onConnect()
        {
                Os.debug("Spades: onConnect");
-               this.looked = false;
                this.send(this.admin, ".status");
                this.send(this.admin, ".turn");
+               this.look = true;
                return true;
        }