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  *
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 
64  unsigned int getUnreadLength() const noexcept2 A_WARN_UNUSED
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 
89  float readFloat(const char *const str);
90 
95  void readCoordinates(uint16_t &restrict x,
96  uint16_t &restrict y,
97  uint8_t &restrict direction,
98  const char *const str);
99 
104  void readCoordinatePair(uint16_t &restrict srcX,
105  uint16_t &restrict srcY,
106  uint16_t &restrict dstX,
107  uint16_t &restrict dstY,
108  const char *const str);
109 
113  void skip(const unsigned int length,
114  const char *const str);
115 
116  void skipToEnd(const char *const str);
117 
123  std::string readString(int length,
124  const char *const dstr);
125 
126  std::string readRawString(int length,
127  const char *const dstr);
128 
129  unsigned char *readBytes(int length,
130  const char *const dstr);
131 
132  static uint8_t fromServerDirection(const uint8_t serverDir)
134 
136  { return mVersion; }
137 
139 
141 
143 
144  protected:
148  MessageIn(const char *const data, const unsigned int length);
149 
150  const char *mData;
151  unsigned int mLength;
158  unsigned int mPos;
159  int mVersion;
160  uint16_t mId;
161  bool mIgnore;
162 };
163 
164 } // namespace Net
165 
166 #endif // NET_MESSAGEIN_H
Net::MessageIn
Definition: messagein.h:40
Net::MessageIn::readRawString
std::string readRawString(int length, const char *const dstr)
Definition: messagein.cpp:410
BeingId
int BeingId
Definition: beingid.h:29
Net::MessageIn::readItemId
int readItemId(const char *const str)
Definition: messagein.cpp:216
A_DELETE_COPY
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
Net::MessageIn::readString
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:383
Net::MessageIn::getVersionZero
int getVersionZero() const
Definition: messagein.cpp:513
notfinal
#define notfinal
Definition: localconsts.h:260
beingid.h
localconsts.h
Net::MessageIn::mLength
unsigned int mLength
Definition: messagein.h:151
Net::MessageIn::skipToEnd
void skipToEnd(const char *const str)
Definition: messagein.cpp:372
Net
Definition: characterdisplay.h:36
noexcept2
#define noexcept2
Definition: localconsts.h:49
Net::MessageIn::readInt32
int32_t readInt32(const char *const str)
Definition: messagein.cpp:174
Net::MessageIn::fromServerDirection
static uint8_t fromServerDirection(const uint8_t serverDir)
Definition: messagein.cpp:265
Net::MessageIn::readBytes
unsigned char * readBytes(int length, const char *const dstr)
Definition: messagein.cpp:453
Net::MessageIn::mVersion
int mVersion
Definition: messagein.h:159
data
uint32_t data
Definition: maptypeproperty2.h:3
Net::MessageIn::readUInt16
uint16_t readUInt16(const char *const str)
Definition: messagein.cpp:152
Net::MessageIn::readFloat
float readFloat(const char *const str)
Definition: messagein.cpp:249
Net::MessageIn::readBeingId
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
x
x
Definition: graphics_calcImageRect.hpp:72
Net::MessageIn::~MessageIn
virtual ~MessageIn()
Definition: messagein.cpp:65
Net::MessageIn::readUInt8
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:103
Net::MessageIn::getVersionRe
int getVersionRe() const
Definition: messagein.cpp:506
Net::MessageIn::readId
uint16_t readId() const
Definition: messagein.cpp:86
Net::MessageIn::getLength
unsigned int getLength() const
Definition: messagein.h:58
Net::MessageIn::mId
uint16_t mId
Definition: messagein.h:160
Net::MessageIn::readUInt32
uint32_t readUInt32(const char *const str)
Definition: messagein.cpp:195
Net::MessageIn::mIgnore
bool mIgnore
Definition: messagein.h:161
restrict
#define restrict
Definition: localconsts.h:164
Net::MessageIn::readInt64
int64_t readInt64(const char *const str)
Definition: messagein.cpp:228
Net::MessageIn::getVersionMain
int getVersionMain() const
Definition: messagein.cpp:499
A_WARN_UNUSED
#define A_WARN_UNUSED
Definition: localconsts.h:160
Net::MessageIn::readInt8
signed char readInt8(const char *const str)
Definition: messagein.cpp:116
Net::MessageIn::getId
int getId() const
Definition: messagein.h:52
Net::MessageIn::readCoordinates
void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction, const char *const str)
Definition: messagein.cpp:295
Net::MessageIn::readInt16
int16_t readInt16(const char *const str)
Definition: messagein.cpp:130
Net::MessageIn::mPos
unsigned int mPos
Definition: messagein.h:158
Net::MessageIn::readCoordinatePair
void readCoordinatePair(uint16_t &srcX, uint16_t &srcY, uint16_t &dstX, uint16_t &dstY, const char *const str)
Definition: messagein.cpp:327
y
y
Definition: graphics_calcImageRect.hpp:72
Net::MessageIn::skip
void skip(const unsigned int length, const char *const str)
Definition: messagein.cpp:365
Net::MessageIn::getVersion
int getVersion() const
Definition: messagein.h:135
Net::MessageIn::mData
const char * mData
Definition: messagein.h:150