Pārlūkot izejas kodu

Merge pull request #125 from csmith/master

Random minor parser tidying.
pull/126/head
Greg Holmes 8 gadus atpakaļ
vecāks
revīzija
e877a80152
1 mainītis faili ar 22 papildinājumiem un 16 dzēšanām
  1. 22
    16
      irc/src/com/dmdirc/parser/irc/IRCParser.java

+ 22
- 16
irc/src/com/dmdirc/parser/irc/IRCParser.java Parādīt failu

32
 import com.dmdirc.parser.common.SRVRecord;
32
 import com.dmdirc.parser.common.SRVRecord;
33
 import com.dmdirc.parser.common.SystemEncoder;
33
 import com.dmdirc.parser.common.SystemEncoder;
34
 import com.dmdirc.parser.events.ConnectErrorEvent;
34
 import com.dmdirc.parser.events.ConnectErrorEvent;
35
-import com.dmdirc.parser.events.DataInEvent;
36
-import com.dmdirc.parser.events.DataOutEvent;
37
 import com.dmdirc.parser.events.DebugInfoEvent;
35
 import com.dmdirc.parser.events.DebugInfoEvent;
38
 import com.dmdirc.parser.events.ErrorInfoEvent;
36
 import com.dmdirc.parser.events.ErrorInfoEvent;
39
 import com.dmdirc.parser.events.PingFailureEvent;
37
 import com.dmdirc.parser.events.PingFailureEvent;
52
 import com.dmdirc.parser.irc.outputqueue.OutputQueue;
50
 import com.dmdirc.parser.irc.outputqueue.OutputQueue;
53
 
51
 
54
 import java.io.IOException;
52
 import java.io.IOException;
55
-import java.io.PrintWriter;
56
 import java.net.InetAddress;
53
 import java.net.InetAddress;
57
 import java.net.Socket;
54
 import java.net.Socket;
58
 import java.net.URI;
55
 import java.net.URI;
207
     /** Current Socket State. */
204
     /** Current Socket State. */
208
     protected SocketState currentSocketState = SocketState.NULL;
205
     protected SocketState currentSocketState = SocketState.NULL;
209
     /**
206
     /**
210
-     * The underlying socket used for reading/writing to the IRC server.
211
-     * For normal sockets this will be the same as {@link #mySocket} but for SSL
212
-     * connections this will be the underlying {@link Socket} while
213
-     * {@link #mySocket} will be an {@link SSLSocket}.
207
+     * The underlying socket connected to the IRC server. For SSL connections this socket will be
208
+     * wrapped, and should therefore not be used to send or receive data.
214
      */
209
      */
215
     private Socket rawSocket;
210
     private Socket rawSocket;
216
     /** Used for writing to the server. */
211
     /** Used for writing to the server. */
803
      */
798
      */
804
     private void handleConnectException(final Exception e, final boolean isUserError) {
799
     private void handleConnectException(final Exception e, final boolean isUserError) {
805
         callDebugInfo(DEBUG_SOCKET, "Error Connecting (" + e.getMessage() + "), Aborted");
800
         callDebugInfo(DEBUG_SOCKET, "Error Connecting (" + e.getMessage() + "), Aborted");
806
-        final ParserError ei = new ParserError(ParserError.ERROR_ERROR + (isUserError ? ParserError.ERROR_USER : 0), "Exception with server socket", getLastLine());
801
+        final ParserError ei = new ParserError(
802
+                ParserError.ERROR_ERROR + (isUserError ? ParserError.ERROR_USER : 0),
803
+                "Exception with server socket", getLastLine());
807
         ei.setException(e);
804
         ei.setException(e);
808
         callConnectError(ei);
805
         callConnectError(ei);
809
 
806
 
978
 
975
 
979
     @Override
976
     @Override
980
     public void sendRawMessage(final String message) {
977
     public void sendRawMessage(final String message) {
981
-        doSendString(message, QueuePriority.NORMAL, false);
978
+        sendString(message, QueuePriority.NORMAL, false);
982
     }
979
     }
983
 
980
 
984
     @Override
981
     @Override
985
     public void sendRawMessage(final String message, final QueuePriority priority) {
982
     public void sendRawMessage(final String message, final QueuePriority priority) {
986
-        doSendString(message, priority, false);
983
+        sendString(message, priority, false);
987
     }
984
     }
988
 
985
 
989
     /**
986
     /**
993
      * @return True if line was sent, else false.
990
      * @return True if line was sent, else false.
994
      */
991
      */
995
     public boolean sendString(final String line) {
992
     public boolean sendString(final String line) {
996
-        return doSendString(line, QueuePriority.NORMAL, true);
993
+        return sendString(line, QueuePriority.NORMAL, true);
997
     }
994
     }
998
 
995
 
999
     /**
996
     /**
1017
      * @return True if line was sent, else false.
1014
      * @return True if line was sent, else false.
1018
      */
1015
      */
1019
     public boolean sendString(final String line, final QueuePriority priority) {
1016
     public boolean sendString(final String line, final QueuePriority priority) {
1020
-        return doSendString(line, priority, true);
1017
+        return sendString(line, priority, true);
1021
     }
1018
     }
1022
 
1019
 
1023
     /**
1020
     /**
1028
      * @param fromParser is this line from the parser? (used for callDataOut)
1025
      * @param fromParser is this line from the parser? (used for callDataOut)
1029
      * @return True if line was sent, else false.
1026
      * @return True if line was sent, else false.
1030
      */
1027
      */
1031
-    protected boolean doSendString(final String line, final QueuePriority priority, final boolean fromParser) {
1028
+    protected boolean sendString(final String line, final QueuePriority priority, final boolean fromParser) {
1032
         if (out == null || getSocketState() != SocketState.OPEN) {
1029
         if (out == null || getSocketState() != SocketState.OPEN) {
1033
             return false;
1030
             return false;
1034
         }
1031
         }
1035
         callDataOut(line, fromParser);
1032
         callDataOut(line, fromParser);
1036
         out.sendLine(line, priority);
1033
         out.sendLine(line, priority);
1034
+        parseOutgoingLine(line);
1035
+
1036
+        return true;
1037
+    }
1038
+
1039
+    /**
1040
+     * Parses a line that has been sent to the server in order to track state.
1041
+     *
1042
+     * @param line The line to be parsed.
1043
+     */
1044
+    private void parseOutgoingLine(final String line) {
1037
         final String[] newLine = tokeniseLine(line);
1045
         final String[] newLine = tokeniseLine(line);
1038
         if ("away".equalsIgnoreCase(newLine[0]) && newLine.length > 1) {
1046
         if ("away".equalsIgnoreCase(newLine[0]) && newLine.length > 1) {
1039
             myself.setAwayReason(newLine[newLine.length - 1]);
1047
             myself.setAwayReason(newLine[newLine.length - 1]);
1059
                 }
1067
                 }
1060
             }
1068
             }
1061
         }
1069
         }
1062
-
1063
-        return true;
1064
     }
1070
     }
1065
 
1071
 
1066
     @Override
1072
     @Override
1728
         // Don't attempt to send anything further.
1734
         // Don't attempt to send anything further.
1729
         getOutputQueue().clearQueue();
1735
         getOutputQueue().clearQueue();
1730
         final String output = (reason == null || reason.isEmpty()) ? "QUIT" : "QUIT :" + reason;
1736
         final String output = (reason == null || reason.isEmpty()) ? "QUIT" : "QUIT :" + reason;
1731
-        doSendString(output, QueuePriority.IMMEDIATE, true);
1737
+        sendString(output, QueuePriority.IMMEDIATE, true);
1732
         // Don't bother queueing anything else.
1738
         // Don't bother queueing anything else.
1733
         getOutputQueue().setDiscarding(true);
1739
         getOutputQueue().setDiscarding(true);
1734
     }
1740
     }

Notiek ielāde…
Atcelt
Saglabāt