~robert-ancell/+junk/chatter

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
/*
 * Copyright (C) 2016 Robert Ancell <robert.ancell@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#ifndef IRC_CLIENT_H
#define IRC_CLIENT_H

#include <QObject>
#include <QTcpSocket>

enum UserMode
{
    Away              = 1 << 0,
    Present           = 1 << 1,
    Invisible         = 1 << 2,
    Visible           = 1 << 3,
    ReceiveWallops    = 1 << 4,
    IgnoreWallops     = 1 << 5,
    DropOperator      = 1 << 6,
    DropLocalOperator = 1 << 7,
};

class IRCClient: public QObject
{
    Q_OBJECT

public:
    explicit IRCClient (QObject *parent = 0);
    Q_INVOKABLE void connectToServer (const QString &host, quint16 port);
    Q_INVOKABLE void connectToSslServer (const QString &host, quint16 port);
    Q_INVOKABLE void sendPassword (const QString& password);
    Q_INVOKABLE void sendSetNickname (const QString& nickname);
    Q_INVOKABLE void sendUserInformation (const QString& userName, bool receiveWallops, bool isInvisible, const QString& realName);
    Q_INVOKABLE void sendUserInformation (const QString& userName, const QString& realName);
    Q_INVOKABLE void sendSetOperator (const QString& userName, const QString& password);
    Q_INVOKABLE void sendSetUserMode (const QString& nickname, UserMode mode);
    Q_INVOKABLE void sendRegisterService (const QString& nickname, const QString& distribution, const QString& info);
    Q_INVOKABLE void sendQuit (const QString& message);
    Q_INVOKABLE void sendQuit ();  
    Q_INVOKABLE void sendServerQuit (const QString& server, const QString& comment);
    Q_INVOKABLE void sendJoin (const QStringList& channels);
    Q_INVOKABLE void sendJoin (const QString& channel);
    Q_INVOKABLE void sendPart (const QStringList& channels, const QString& message);
    Q_INVOKABLE void sendPart (const QString& channel, const QString& message);
    Q_INVOKABLE void sendPart (const QString& channel);
    Q_INVOKABLE void sendPartAll ();
    Q_INVOKABLE void sendSetChannelMode (const QString& channel);
    Q_INVOKABLE void sendSetTopic (const QString& channel, const QString& topic);
    Q_INVOKABLE void sendGetTopic (const QString& channel);
    Q_INVOKABLE void sendGetNames (const QStringList& channels, const QString& target);
    Q_INVOKABLE void sendGetNames (const QStringList& channels);
    Q_INVOKABLE void sendListChannels (const QStringList& channels, const QString& target);
    Q_INVOKABLE void sendListChannels (const QStringList& channels);  
    Q_INVOKABLE void sendListChannels ();
    Q_INVOKABLE void sendListChannel (const QString& channel, const QString& target);
    Q_INVOKABLE void sendListChannel (const QString& channel);
    Q_INVOKABLE void sendInvite (const QString& nickname, const QString& channel);
    Q_INVOKABLE void sendKick (const QStringList& channels, const QStringList& usernames, const QString& comment);
    Q_INVOKABLE void sendKick (const QString& channel, const QString& username, const QString& comment);
    Q_INVOKABLE void sendKick (const QString& channel, const QStringList& usernames, const QString& comment);
    Q_INVOKABLE void sendMessage (const QString& target, const QString& text);
    Q_INVOKABLE void sendNotice (const QString& target, const QString& text);
    Q_INVOKABLE void sendGetMOTD (const QString& target);
    Q_INVOKABLE void sendGetMOTD ();
    Q_INVOKABLE void sendListUsers ();
    Q_INVOKABLE void sendGetVersion (const QString& target);
    Q_INVOKABLE void sendGetVersion ();
    Q_INVOKABLE void sendGetStats ();
    Q_INVOKABLE void sendGetLinks ();
    Q_INVOKABLE void sendGetTime (const QString& target);
    Q_INVOKABLE void sendGetTime ();
    Q_INVOKABLE void sendConnect (const QString& targetServer, quint32 port, const QString& remoteServer);
    Q_INVOKABLE void sendTrace (const QString& target);
    Q_INVOKABLE void sendTrace ();
    Q_INVOKABLE void sendGetAdmin (const QString& target);
    Q_INVOKABLE void sendGetAdmin ();
    Q_INVOKABLE void sendGetServerInfo (const QString& target);
    Q_INVOKABLE void sendGetServerInfo ();
    Q_INVOKABLE void sendPing (const QString& server1, const QString& server2);
    Q_INVOKABLE void sendPing (const QString& server);
    Q_INVOKABLE void sendPong (const QString& server1, const QString& server2);
    Q_INVOKABLE void sendPong (const QString& server);
    Q_INVOKABLE void sendReloadConfiguration ();
    Q_INVOKABLE void sendShutdownServer ();
    Q_INVOKABLE void sendRestartServer ();
  
signals:
    void commandReceived (const QString& prefix, const QString& command, const QStringList& params);
    void joinReceived (const QString& prefix, const QString& channel);
    void partReceived (const QString& prefix, const QString& channel, const QString& message);
    void setTopicReceived (const QString& prefix, const QString& channel, const QString& topic);
    void messageReceived (const QString& prefix, const QString& target, const QString& text);
    void pingReceived (const QString& prefix, const QString& server1, const QString& server2);
    void getTopicReplyReceived (const QString& prefix, const QString& channel, const QString& topic);
    void getNamesReplyReceived (const QString& prefix, const QString& channel, const QStringList& nicknames);

private slots:
    void readData ();

private:
    QTcpSocket *socket;
    QByteArray read_buffer;
    void sendCommand (const QString& command, const QStringList& parameters);
    void sendCommand (const QString& command, const QString& parameter);
    void sendCommand (const QString& command);
};

#endif