author | skyhusker <skyhusker> | 2005-01-23 23:02:00 (UTC) |
---|---|---|
committer | skyhusker <skyhusker> | 2005-01-23 23:02:00 (UTC) |
commit | 42df856b4e4741cf5ebdd267cf370e5a9eaf3dbc (patch) (unidiff) | |
tree | 6536ec388af2314ecfaecdeb923b4c2e76b0de29 | |
parent | 2074382fccea58a55b68c51815abc5df463473aa (diff) | |
download | opie-42df856b4e4741cf5ebdd267cf370e5a9eaf3dbc.zip opie-42df856b4e4741cf5ebdd267cf370e5a9eaf3dbc.tar.gz opie-42df856b4e4741cf5ebdd267cf370e5a9eaf3dbc.tar.bz2 |
Added distinction between CTCP requests and CTCP replies
-rw-r--r-- | noncore/net/opieirc/ircmessage.cpp | 27 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessage.h | 3 |
2 files changed, 24 insertions, 6 deletions
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp index d19e9e6..1b7072e 100644 --- a/noncore/net/opieirc/ircmessage.cpp +++ b/noncore/net/opieirc/ircmessage.cpp | |||
@@ -49,30 +49,37 @@ IRCMessage::IRCMessage(QString line) { | |||
49 | 49 | ||
50 | 50 | ||
51 | m_commandNumber = m_command.toInt(&m_isNumerical); | 51 | m_commandNumber = m_command.toInt(&m_isNumerical); |
52 | /* Is this a CTCP command */ | 52 | /* Is this a CTCP command */ |
53 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { | 53 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { |
54 | m_ctcp = TRUE; | 54 | m_ctcp = TRUE; |
55 | if (m_command == "PRIVMSG") { | ||
56 | m_ctcpRequest = TRUE; | ||
57 | } | ||
58 | else { | ||
59 | m_ctcpRequest = FALSE; | ||
60 | } | ||
61 | |||
55 | /* Strip CTCP \001 characters */ | 62 | /* Strip CTCP \001 characters */ |
56 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); | 63 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); |
57 | QTextIStream ctcpStream(&m_allParameters); | 64 | QTextIStream ctcpStream(&m_allParameters); |
58 | if (m_command == "PRIVMSG") | 65 | ctcpStream >> m_ctcpDestination; |
59 | ctcpStream >> m_ctcpDestination; | ||
60 | ctcpStream >> temp; | 66 | ctcpStream >> temp; |
61 | m_ctcpCommand = temp.upper().right(temp.length()-1); | 67 | m_ctcpCommand = temp.upper().right(temp.length()-1); |
62 | m_parameters.clear(); | 68 | m_parameters.clear(); |
63 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; | 69 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; |
64 | if (m_command == "PRIVMSG") | 70 | length -= m_ctcpDestination.length() + 1; |
65 | length -= m_ctcpDestination.length() + 1; | ||
66 | if (length <= 0) { | 71 | if (length <= 0) { |
67 | m_allParameters = ""; | 72 | m_allParameters = ""; |
68 | } else { | 73 | } |
74 | else { | ||
69 | m_allParameters = m_allParameters.right(length); | 75 | m_allParameters = m_allParameters.right(length); |
70 | m_parameters << m_allParameters; | 76 | m_parameters << m_allParameters; |
71 | } | 77 | } |
72 | } else { | 78 | } |
79 | else { | ||
73 | m_ctcp = FALSE; | 80 | m_ctcp = FALSE; |
74 | } | 81 | } |
75 | 82 | ||
76 | 83 | ||
77 | odebug << "Parsed: " << line << oendl; | 84 | odebug << "Parsed: " << line << oendl; |
78 | odebug << "Prefix: " << m_prefix << oendl; | 85 | odebug << "Prefix: " << m_prefix << oendl; |
@@ -141,12 +148,20 @@ bool IRCMessage::isNumerical() { | |||
141 | } | 148 | } |
142 | 149 | ||
143 | bool IRCMessage::isCTCP() { | 150 | bool IRCMessage::isCTCP() { |
144 | return m_ctcp; | 151 | return m_ctcp; |
145 | } | 152 | } |
146 | 153 | ||
154 | bool IRCMessage::isCTCPRequest() { | ||
155 | return m_ctcpRequest; | ||
156 | } | ||
157 | |||
158 | bool IRCMessage::isCTCPReply() { | ||
159 | return !m_ctcpRequest; | ||
160 | } | ||
161 | |||
147 | QString IRCMessage::trailing() { | 162 | QString IRCMessage::trailing() { |
148 | return m_trailing; | 163 | return m_trailing; |
149 | } | 164 | } |
150 | 165 | ||
151 | QString IRCMessage::allParameters() { | 166 | QString IRCMessage::allParameters() { |
152 | return m_allParameters; | 167 | return m_allParameters; |
diff --git a/noncore/net/opieirc/ircmessage.h b/noncore/net/opieirc/ircmessage.h index 10ba450..40bb210 100644 --- a/noncore/net/opieirc/ircmessage.h +++ b/noncore/net/opieirc/ircmessage.h | |||
@@ -35,12 +35,14 @@ public: | |||
35 | /* Return the IRC message prefix (usually sender etc) */ | 35 | /* Return the IRC message prefix (usually sender etc) */ |
36 | QString prefix(); | 36 | QString prefix(); |
37 | /* Check if this IRCMessage's command is literal or numerical */ | 37 | /* Check if this IRCMessage's command is literal or numerical */ |
38 | bool isNumerical(); | 38 | bool isNumerical(); |
39 | /* CHeck if this IRCMessage is a CTCP message */ | 39 | /* CHeck if this IRCMessage is a CTCP message */ |
40 | bool isCTCP(); | 40 | bool isCTCP(); |
41 | bool isCTCPRequest(); | ||
42 | bool isCTCPReply(); | ||
41 | /* Return the IRC command (literal commands) */ | 43 | /* Return the IRC command (literal commands) */ |
42 | QString command(); | 44 | QString command(); |
43 | /* Return the CTCP command */ | 45 | /* Return the CTCP command */ |
44 | QString ctcpCommand(); | 46 | QString ctcpCommand(); |
45 | /* Return the CTCP destination if applicable (channel/person) */ | 47 | /* Return the CTCP destination if applicable (channel/person) */ |
46 | QString ctcpDestination(); | 48 | QString ctcpDestination(); |
@@ -62,9 +64,10 @@ protected: | |||
62 | unsigned short m_commandNumber; | 64 | unsigned short m_commandNumber; |
63 | QString m_allParameters; | 65 | QString m_allParameters; |
64 | QString m_trailing; | 66 | QString m_trailing; |
65 | QStringList m_parameters; | 67 | QStringList m_parameters; |
66 | bool m_isNumerical; | 68 | bool m_isNumerical; |
67 | bool m_ctcp; | 69 | bool m_ctcp; |
70 | bool m_ctcpRequest; | ||
68 | }; | 71 | }; |
69 | 72 | ||
70 | #endif | 73 | #endif |