ManaPlus
messagein.h
Go to the documentation of this file.
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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef NET_MESSAGEIN_H
25 #define NET_MESSAGEIN_H
26 
28 
29 #include <string>
30 
31 #include "localconsts.h"
32 
33 namespace Net
34 {
35 
42 {
43  public:
45 
46  virtual ~MessageIn();
47 
48  uint16_t readId() const;
49 
54  { return mId; }
55 
59  unsigned int getLength() const noexcept2 A_WARN_UNUSED
60  { return mLength; }
61 
66  { return mLength > mPos ? mLength - mPos : 0; }
67 
69  unsigned char readUInt8(const char *const str);
70 
72  signed char readInt8(const char *const str);
73 
75  int16_t readInt16(const char *const str);
76 
77  uint16_t readUInt16(const char *const str);
78 
80  int32_t readInt32(const char *const str);
81 
82  uint32_t readUInt32(const char *const str);
83 
84  int readItemId(const char *const str);
85 
86  int64_t readInt64(const char *const str);
87 
88  BeingId readBeingId(const char *const str);
89 
90  float readFloat(const char *const str);
91 
96  void readCoordinates(uint16_t &restrict x,
97  uint16_t &restrict y,
98  uint8_t &restrict direction,
99  const char *const str);
100 
105  void readCoordinatePair(uint16_t &restrict srcX,
106  uint16_t &restrict srcY,
107  uint16_t &restrict dstX,
108  uint16_t &restrict dstY,
109  const char *const str);
110 
114  void skip(const unsigned int length,
115  const char *const str);
116 
117  void skipToEnd(const char *const str);
118 
124  std::string readString(int length,
125  const char *const dstr);
126 
127  std::string readRawString(int length,
128  const char *const dstr);
129 
130  unsigned char *readBytes(int length,
131  const char *const dstr);
132 
133  static uint8_t fromServerDirection(const uint8_t serverDir)
135 
137  { return mVersion; }
138 
140 
142 
144 
145  protected:
149  MessageIn(const char *const data, const unsigned int length);
150 
151  const char *mData;
152  unsigned int mLength;
159  unsigned int mPos;
160  int mVersion;
161  uint16_t mId;
162  bool mIgnore;
163 };
164 
165 } // namespace Net
166 
167 #endif // NET_MESSAGEIN_H
int BeingId
Definition: beingid.h:30
unsigned int mPos
Definition: messagein.h:159
uint32_t readUInt32(const char *const str)
Definition: messagein.cpp:196
uint16_t mId
Definition: messagein.h:161
int getVersion() const
Definition: messagein.h:136
int getVersionZero() const
Definition: messagein.cpp:514
int64_t readInt64(const char *const str)
Definition: messagein.cpp:229
int getVersionRe() const
Definition: messagein.cpp:507
float readFloat(const char *const str)
Definition: messagein.cpp:250
void readCoordinatePair(uint16_t &srcX, uint16_t &srcY, uint16_t &dstX, uint16_t &dstY, const char *const str)
Definition: messagein.cpp:328
int32_t readInt32(const char *const str)
Definition: messagein.cpp:175
signed char readInt8(const char *const str)
Definition: messagein.cpp:117
void skip(const unsigned int length, const char *const str)
Definition: messagein.cpp:366
uint16_t readUInt16(const char *const str)
Definition: messagein.cpp:153
unsigned int mLength
Definition: messagein.h:152
int16_t readInt16(const char *const str)
Definition: messagein.cpp:131
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:224
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:384
int getId() const
Definition: messagein.h:53
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:104
unsigned int getUnreadLength() const
Definition: messagein.h:65
unsigned int getLength() const
Definition: messagein.h:59
static uint8_t fromServerDirection(const uint8_t serverDir)
Definition: messagein.cpp:266
unsigned char * readBytes(int length, const char *const dstr)
Definition: messagein.cpp:454
const char * mData
Definition: messagein.h:151
std::string readRawString(int length, const char *const dstr)
Definition: messagein.cpp:411
uint16_t readId() const
Definition: messagein.cpp:87
void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction, const char *const str)
Definition: messagein.cpp:296
virtual ~MessageIn()
Definition: messagein.cpp:66
int getVersionMain() const
Definition: messagein.cpp:500
int readItemId(const char *const str)
Definition: messagein.cpp:217
void skipToEnd(const char *const str)
Definition: messagein.cpp:373
#define restrict
Definition: localconsts.h:165
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define noexcept2
Definition: localconsts.h:50
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
uint32_t data