summaryrefslogtreecommitdiffstats
path: root/signet/protocol/Packet.h
blob: 1f426e16798e8679cf75ece798d30e44f9fdc89f (plain)
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
/*
 * Copyright 2008 Ben Boeckel <MathStuf@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.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SIGNET_PROTOCOL_PACKET
#define SIGNET_PROTOCOL_PACKET

// Signet includes
#include "../Global.h"

// Qt includes
#include <QtCore/QByteArray>
#include <QtCore/QStringList>

// Forward declarations
class QIODevice;

namespace Signet
{
namespace Protocol
{
class SIGNET_IMPORT Packet
{
    public:
        enum Type
        {
            // Errors
            UnknownReceiver     = 0x4000,
            UnhandledPacket     = 0x4001,
            LimitedPermissions  = 0x4002,
            Invalid             = 0x40FF,
            // Requests
            ConnectRequest      = 0x0100,
            DisconnectRequest   = 0x0101,
            ChallengeRequest    = 0x0102,
            UserListRequest     = 0x0103,
            ServerListRequest   = 0x0104,
            RoomListRequest     = 0x0105,
            TableListRequest    = 0x0106,
            SigmodListRequest   = 0x0107,
            SigmodRequest       = 0x0108,
            TableState          = 0x0109,
            DecisionRequest     = 0x010A,
            // Data
            RawData             = 0x0200,
            Acceptance          = 0x0201,
            Denial              = 0x0202,
            Acknowledge         = 0x0203,
            ChallengeKey        = 0x0204,
            ChallengeResponse   = 0x0205,
            Message             = 0x0206,
            ServerList          = 0x0207,
            UserList            = 0x0208,
            RoomList            = 0x0209,
            SigmodList          = 0x020A,
            Sigmod              = 0x020B,
            BattleState         = 0x020C,
            MapState            = 0x020D,
            Decision            = 0x020E,
            // Updates
        };
        
        enum SectionType
        {
            Receiver    = 0,
            Payload     = 1
        };
        
        Packet(const qint16 type = Invalid, const QStringList& receivers = QStringList());
        
        qint16 type() const;
        QStringList receivers() const;
        bool isValid() const;
        
        QString received();
        
        void write(const QByteArray& data);
        void rawDump(QIODevice* device) const;
        void dump(QIODevice* device) const;
    private:
        qint16 m_type;
        QStringList m_receivers;
        QByteArray m_rawData;
};
}
}

#endif