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-2018 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 
27 
28 #include <string>
29 
30 #include "localconsts.h"
31 
32 namespace Net
33 {
34 
41 {
42  public:
44 
45  virtual ~MessageIn();
46 
47  uint16_t readId() const;
48 
53  { return mId; }
54 
58  unsigned int getLength() const noexcept2 A_WARN_UNUSED
59  { return mLength; }
60 
65  { return mLength > mPos ? mLength - mPos : 0; }
66 
68  unsigned char readUInt8(const char *const str);
69 
71  signed char readInt8(const char *const str);
72 
74  int16_t readInt16(const char *const str);
75 
76  uint16_t readUInt16(const char *const str);
77 
79  int32_t readInt32(const char *const str);
80 
81  uint32_t readUInt32(const char *const str);
82 
83  int readItemId(const char *const str);
84 
85  int64_t readInt64(const char *const str);
86 
87  BeingId readBeingId(const char *const str);
88 
93  void readCoordinates(uint16_t &restrict x,
94  uint16_t &restrict y,
95  uint8_t &restrict direction,
96  const char *const str);
97 
102  void readCoordinatePair(uint16_t &restrict srcX,
103  uint16_t &restrict srcY,
104  uint16_t &restrict dstX,
105  uint16_t &restrict dstY,
106  const char *const str);
107 
111  void skip(const unsigned int length,
112  const char *const str);
113 
114  void skipToEnd(const char *const str);
115 
121  std::string readString(int length,
122  const char *const dstr);
123 
124  std::string readRawString(int length,
125  const char *const dstr);
126 
127  unsigned char *readBytes(int length,
128  const char *const dstr);
129 
130  static uint8_t fromServerDirection(const uint8_t serverDir)
132 
133  int getVersion() const noexcept2 A_WARN_UNUSED
134  { return mVersion; }
135 
137 
139 
141 
142  protected:
146  MessageIn(const char *const data, const unsigned int length);
147 
148  const char *mData;
149  unsigned int mLength;
156  unsigned int mPos;
157  int mVersion;
158  uint16_t mId;
159  bool mIgnore;
160 };
161 
162 } // namespace Net
163 
164 #endif // NET_MESSAGEIN_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:103
uint16_t readUInt16(const char *const str)
Definition: messagein.cpp:152
int getVersionRe() const
Definition: messagein.cpp:487
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
uint16_t readId() const
Definition: messagein.cpp:86
virtual ~MessageIn()
Definition: messagein.cpp:65
#define A_WARN_UNUSED
Definition: localconsts.h:152
unsigned int getLength() const
Definition: messagein.h:58
int BeingId
Definition: beingid.h:29
unsigned int getUnreadLength() const
Definition: messagein.h:64
uint16_t mId
Definition: messagein.h:158
uint32_t readUInt32(const char *const str)
Definition: messagein.cpp:195
void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction, const char *const str)
Definition: messagein.cpp:279
signed char readInt8(const char *const str)
Definition: messagein.cpp:116
int getId() const
Definition: messagein.h:52
int64_t readInt64(const char *const str)
Definition: messagein.cpp:228
unsigned int mPos
Definition: messagein.h:156
int getVersionMain() const
Definition: messagein.cpp:480
int16_t readInt16(const char *const str)
Definition: messagein.cpp:130
void readCoordinatePair(uint16_t &srcX, uint16_t &srcY, uint16_t &dstX, uint16_t &dstY, const char *const str)
Definition: messagein.cpp:311
uint32_t data
MessageIn(const char *const data, const unsigned int length)
Definition: messagein.cpp:53
std::string readRawString(int length, const char *const dstr)
Definition: messagein.cpp:394
int getVersion() const
Definition: messagein.h:133
void skip(const unsigned int length, const char *const str)
Definition: messagein.cpp:349
const char * mData
Definition: messagein.h:148
#define notfinal
Definition: localconsts.h:252
int readItemId(const char *const str)
Definition: messagein.cpp:216
void skipToEnd(const char *const str)
Definition: messagein.cpp:356
#define restrict
Definition: localconsts.h:156
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:367
static uint8_t fromServerDirection(const uint8_t serverDir)
Definition: messagein.cpp:249
unsigned int mLength
Definition: messagein.h:149
int getVersionZero() const
Definition: messagein.cpp:494
int32_t readInt32(const char *const str)
Definition: messagein.cpp:174
#define noexcept2
Definition: localconsts.h:49
unsigned char * readBytes(int length, const char *const dstr)
Definition: messagein.cpp:437