ManaPlus
messageout.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_MESSAGEOUT_H
25 #define NET_MESSAGEOUT_H
26 
28 
29 #include "utils/cast.h"
30 
31 #include <string>
32 
33 #include "localconsts.h"
34 
35 UTILS_CAST_H
36 
37 #define createOutPacket(name) MessageOut outMsg(name); \
38  outMsg.writeInt16(CAST_S16(name), #name)
39 
40 namespace Net
41 {
42 
49 {
50  public:
52 
53 
54  virtual void writeInt8(const int8_t value,
55  const char *const str);
56 
58  void writeInt16(const int16_t value,
59  const char *const str);
60 
62  void writeInt32(const int32_t value,
63  const char *const str);
64 
65  void writeItemId(const int32_t value,
66  const char *const str);
67 
68  void writeInt64(const int64_t value,
69  const char *const str);
70 
71  void writeBeingId(const BeingId value,
72  const char *const str);
73 
74  void writeCoordinates(const uint16_t x,
75  const uint16_t y,
76  unsigned char direction,
77  const char *const str);
78 
83  void writeString(const std::string &string,
84  int length,
85  const char *const str);
86 
91  void writeStringNoLog(const std::string &string,
92  int length,
93  const char *const str);
94 
95  void writeFloat(const float value,
96  const char *const str);
97 
101  const char *getData() const A_WARN_UNUSED;
102 
106  unsigned int getDataSize() const A_WARN_UNUSED;
107 
108  virtual ~MessageOut()
109  { }
110 
111  void resetPos()
112  { mPos = 0; }
113 
114  static unsigned char toServerDirection(unsigned char direction)
115  A_CONST;
116 
117  protected:
121  explicit MessageOut(const int16_t id);
122 
130  virtual void expand(size_t size) const = 0;
131 
132  char *mData;
133  unsigned int mDataSize;
134  unsigned int mPos;
135  uint16_t mId;
136  bool mIgnore;
137 };
138 
139 } // namespace Net
140 
141 #endif // NET_MESSAGEOUT_H
int BeingId
Definition: beingid.h:30
unsigned int getDataSize() const
Definition: messageout.cpp:248
static unsigned char toServerDirection(unsigned char direction) A_CONST
Definition: messageout.cpp:253
const char * getData() const
Definition: messageout.cpp:243
uint16_t mId
Definition: messageout.h:135
void writeInt64(const int64_t value, const char *const str)
Definition: messageout.cpp:113
virtual void expand(size_t size) const =0
virtual ~MessageOut()
Definition: messageout.h:108
unsigned int mDataSize
Definition: messageout.h:133
void writeInt32(const int32_t value, const char *const str)
Definition: messageout.cpp:88
void writeInt16(const int16_t value, const char *const str)
Definition: messageout.cpp:71
virtual void writeInt8(const int8_t value, const char *const str)
Definition: messageout.cpp:61
void writeStringNoLog(const std::string &string, int length, const char *const str)
Definition: messageout.cpp:210
unsigned int mPos
Definition: messageout.h:134
void writeString(const std::string &string, int length, const char *const str)
Definition: messageout.cpp:177
void writeCoordinates(const uint16_t x, const uint16_t y, unsigned char direction, const char *const str)
Definition: messageout.cpp:148
MessageOut(const int16_t id)
Definition: messageout.cpp:49
void writeItemId(const int32_t value, const char *const str)
Definition: messageout.cpp:104
void writeBeingId(const BeingId value, const char *const str)
Definition: messageout.cpp:129
void writeFloat(const float value, const char *const str)
Definition: messageout.cpp:134
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
int size()
Definition: emotedb.cpp:306