GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/messagein.h Lines: 0 4 0.0 %
Date: 2017-11-29 Branches: 0 4 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef NET_MESSAGEIN_H
24
#define NET_MESSAGEIN_H
25
26
#include "enums/simpletypes/beingid.h"
27
28
#include <string>
29
30
#include "localconsts.h"
31
32
namespace Net
33
{
34
35
/**
36
 * Used for parsing an incoming message.
37
 *
38
 * \ingroup Network
39
 */
40
class MessageIn notfinal
41
{
42
    public:
43
        A_DELETE_COPY(MessageIn)
44
45
        virtual ~MessageIn();
46
47
        /**
48
         * Returns the message ID.
49
         */
50
        int getId() const noexcept2 A_WARN_UNUSED
51
        { return mId; }
52
53
        /**
54
         * Returns the message length.
55
         */
56
        unsigned int getLength() const noexcept2 A_WARN_UNUSED
57
        { return mLength; }
58
59
        /**
60
         * Returns the length of unread data.
61
         */
62
        unsigned int getUnreadLength() const noexcept2 A_WARN_UNUSED
63
        { return mLength > mPos ? mLength - mPos : 0; }
64
65
        /**< Reads a byte. */
66
        virtual unsigned char readUInt8(const char *const str);
67
68
        /**< Reads a byte. */
69
        virtual signed char readInt8(const char *const str);
70
71
        /**< Reads a short. */
72
        virtual int16_t readInt16(const char *const str) = 0;
73
74
        virtual uint16_t readUInt16(const char *const str) = 0;
75
76
        /**< Reads a long. */
77
        virtual int32_t readInt32(const char *const str) = 0;
78
79
        virtual int64_t readInt64(const char *const str) = 0;
80
81
        virtual BeingId readBeingId(const char *const str) = 0;
82
83
        /**
84
         * Reads a special 3 byte block used by eAthena, containing x and y
85
         * coordinates and direction.
86
         */
87
        virtual void readCoordinates(uint16_t &restrict x,
88
                                     uint16_t &restrict y,
89
                                     uint8_t &restrict direction,
90
                                     const char *const str);
91
92
        /**
93
         * Reads a special 5 byte block used by eAthena, containing a source
94
         * and destination coordinate pair.
95
         */
96
        virtual void readCoordinatePair(uint16_t &restrict srcX,
97
                                        uint16_t &restrict srcY,
98
                                        uint16_t &restrict dstX,
99
                                        uint16_t &restrict dstY,
100
                                        const char *const str);
101
102
        /**
103
         * Skips a given number of bytes.
104
         */
105
        virtual void skip(const unsigned int length,
106
                          const char *const str);
107
108
        void skipToEnd(const char *const str);
109
110
        /**
111
         * Reads a string. If a length is not given (-1), it is assumed
112
         * that the length of the string is stored in a short at the
113
         * start of the string.
114
         */
115
        virtual std::string readString(int length,
116
                                       const char *const dstr);
117
118
        virtual std::string readRawString(int length,
119
                                          const char *const dstr);
120
121
        unsigned char *readBytes(int length,
122
                                 const char *const dstr);
123
124
        static uint8_t fromServerDirection(const uint8_t serverDir)
125
                                           A_WARN_UNUSED;
126
127
        unsigned int getVersion() const noexcept2 A_WARN_UNUSED
128
        { return mVersion; }
129
130
    protected:
131
        /**
132
         * Constructor.
133
         */
134
        MessageIn(const char *const data, const unsigned int length);
135
136
        const char *mData;     /**< The message data. */
137
        unsigned int mLength;  /**< The length of the data. */
138
139
        /**
140
         * Actual position in the packet. From 0 to packet->length.
141
         * A value bigger than packet->length means EOP was reached when
142
         * reading it.
143
         */
144
        unsigned int mPos;
145
        unsigned int mVersion;
146
        uint16_t mId;          /**< The message ID. */
147
        bool mIgnore;
148
};
149
150
}  // namespace Net
151
152
#endif  // NET_MESSAGEIN_H