-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.h
More file actions
268 lines (211 loc) · 7.95 KB
/
connection.h
File metadata and controls
268 lines (211 loc) · 7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef CONNECTION_H
#define CONNECTION_H 1
#include <QObject>
#include <QTcpSocket>
#include <QTimer>
#include <QStringList>
#include "ServerInfo"
#include "HostMask"
#include "qirc.h"
namespace QIRC {
/// \brief Connection to an IRC server
///
/// This class maintains a connection to an IRC server.
class Connection : public QObject {
Q_OBJECT
public:
Connection();
Connection(const ServerInfo& si);
Connection(QString h, quint16 p);
virtual ~Connection();
ServerInfo server() const;
void setServer(const ServerInfo& si);
void setServer(QString h, quint16 p);
QString serverPassword() const;
void setServerPassword(QString password);
QString ident() const;
void setIdent(QString ident);
QString nick() const ;
void setNick(QString nick);
QString realName() const;
void setRealName(QString realName);
void connect();
void disconnect();
bool isConnected() const;
void joinChannel(QString channel, QString key="");
void partChannel(QString channel);
void getChannelTopic(QString channel);
void setChannelTopic(QString channel, QString topic);
void getChannelNames(QString channel);
void inviteUser(QString nick, QString channel);
void quit(QString message, bool disconnect=true);
void privmsg(QString target, QString text);
protected:
/// \brief ServerInfo for the currently connected server
ServerInfo m_currentServer;
/// \brief TCP socket for connection to server
QTcpSocket* m_socket;
/// \brief Flag indicating wether we're currently connected
bool m_connected;
/// \brief Server password
QString m_serverPassword;
/// \brief ident username
QString m_ident;
/// \brief Current nickname
QString m_nick;
/// \brief Desired nickname for name changes
QString m_desiredNick;
/// \brief Real name to use on IRC
QString m_realName;
/// \brief Queue for outgoing IRC messages
QStringList m_messageQueue;
/// \brief Timer to send queued messages
QTimer* m_tMessageQueue;
void sendMessage(QString msg, bool queued=true);
bool parseMessage(QString msg);
void authenticate();
void sendPong(QString serverName);
protected slots:
void socket_connected();
void socket_disconnected();
void socket_error(QAbstractSocket::SocketError);
void socket_readyRead();
void timer_messageQueue();
signals:
/// \brief TCP/IP socket error
///
/// This signal gets emitted when the underlying socket for the
/// connection to the IRC server has generated an error.
///
/// \param err Error as received from the socket
/// \param msg Error message in human-readable form
void socketError(QAbstractSocket::SocketError err, QString msg);
/// \brief Connection to IRC server established
///
/// \param si ServerInfo object describing the server to which the
/// connection was established
void connected(QIRC::ServerInfo si);
/// \brief Connection to IRC server dropped
///
/// \param si ServerInfo object with the server that got disconnected
void disconnected(QIRC::ServerInfo si);
/// \brief Got IRC PING message
///
/// This signal gets emitted whenever we receive a PING message from
/// the IRC server.
/// The PONG response to this message is sent automatically.
///
/// \param serverName Server name as sent by the IRC server
void irc_ping(QString serverName);
/// \brief Got NOTICE AUTH message
///
/// This signal gets emitted whenever we receive a NOTICE AUTH message/
/// from the server.
///
/// \param serverName Server name as sent by the server
/// \param message Message contents as string
void irc_notice_auth(QString serverName, QString message);
/// \brief Got NOTICE message
///
/// This signal gets emitted whenever we receive a NOTICE message.
/// A NOTICE can be either sent to a single client or a whole channel
/// which is indicated by the 'target' parameter.
///
/// \param sender Host mask of the NOTICEs sender
/// \param target Nick or channel name that the notice was sent to
/// \param message Message text as string
void irc_notice(QIRC::HostMask sender, QString target, QString message);
/// \brief Got PRIVMSG
///
/// This signal gets emitted whenever we receive a PRIVMSG line from the
/// IRC server. This can be either a private message to the client itself
/// or to a channel.
///
/// \param sender Host mask of the PRIVMSGs sender
/// \param target Nick or channel that the message was directed at
/// \param message Message text as string
void irc_privmsg(QIRC::HostMask sender, QString target, QString message);
void irc_mode(QIRC::HostMask sender, QString target, QString modeString);
/// \brief Successfully changed nickname
///
/// This signal is emitted whenever we receive a NICK message that
/// indicates that we changed our own nickname.
///
/// \param oldNick old nickname as string
/// \param newNick new nickname as string
void nickChanged(QString oldNick, QString newNick);
/// \brief Nickname change
///
/// This signal is emitted whenever another user on IRC changes their
/// nickname.
///
/// \param sender Host mask of the user that changed their nick
/// \param newNick New nickname of the user as string
void irc_nick(QIRC::HostMask sender, QString newNick);
/// \brief Successfully joined channel
///
/// This signal is emitted whenever we successfully joined a channel
/// on IRC.
///
/// \param channel Channel name a string
void joinedChannel(QString channel);
/// \brief Successfully left channel
///
/// This signal is emitted whenever we successfully left a channel
/// on IRC.
///
/// \param channel Channel name as string
void partedChannel(QString channel);
/// \brief User joined channel
///
/// This signal is emitted when another user joined a channel that
/// we're currently listening to.
///
/// \param user Host mask of the newly joined user
/// \param channel Channel name as string
void irc_join(QIRC::HostMask user, QString channel);
/// \brief User left channel
///
/// This signal is emitted when another user left a channel that we're
/// currently listening to.
///
/// \param user Host mask of the user that left
/// \param channel Channel name as string
void irc_part(QIRC::HostMask user, QString channel);
/// \brief Channel creation info
///
/// This signal is emitted whenever we receive a message giving
/// additional information about a channel's creation date etc.
///
/// \attention This is most likely IRCd-specific; currently only
/// tested to work with ircd-hybrid
///
/// \param channel Channel name as string
/// \param creator Host mask of the user that created the channel
/// \param ts Timestamp of channel creation
void irc_channelInfo(QString channel, QIRC::HostMask creator,
quint32 ts);
/// \brief Channel topic changed
///
/// This signal is emitted whenever the topic of an IRC channel gets
/// changed by another user.
///
/// \param sender Host mask of the user that changed the channel's topic
/// \param channel Channel name as string
/// \param newTopic New topic message as string
void irc_topic(QIRC::HostMask sender, QString channel, QString newTopic);
/// \brief Channel invitation
///
/// This signal is emitted whenever we've received an INVITE to a chat
/// channel from another user.
///
/// \param sender Host mask of the user that sent the invite
/// \param target Nickname of the user that got invited
/// \param channel Name of the channel into which we've been invited
void irc_invite(QIRC::HostMask sender, QString target, QString channel);
private:
bool setupSocket();
bool setupMessageQueue();
};
};
#endif