Mana
Loading...
Searching...
No Matches
messagein.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
25
26#include <cstdint>
27#include <string>
28
29namespace ManaServ {
30
37{
38 public:
39 MessageIn(const char *data, unsigned int length);
40
44 uint16_t getId() const { return mId; }
45
49 unsigned int getLength() const { return mLength; }
50
54 unsigned int getUnreadLength() const
55 {
56 return (mPos < mLength) ? mLength - mPos : 0;
57 }
58
63
67 uint16_t readInt16();
68
73
79 std::string readString(int length = -1);
80
81 private:
83
84 const char *mData;
85 unsigned int mLength;
86 unsigned short mId;
93 unsigned int mPos;
94};
95
96} // namespace ManaServ
Used for parsing an incoming message from manaserv.
Definition messagein.h:37
bool readValueType(ManaServ::ValueType type)
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
Definition messagein.cpp:58
unsigned int mLength
The length of the data.
Definition messagein.h:85
unsigned int getUnreadLength() const
Returns the length of unread data.
Definition messagein.h:54
const char * mData
The message data.
Definition messagein.h:84
unsigned int mPos
Actual position in the packet.
Definition messagein.h:93
std::string readString(int length=-1)
Reads a string.
Definition messagein.cpp:92
unsigned int getLength() const
Returns the message length.
Definition messagein.h:49
uint16_t getId() const
Returns the message ID.
Definition messagein.h:44
bool mDebugMode
Includes debugging information.
Definition messagein.h:87
uint32_t readInt32()
Reads an unsigned 32-bit integer from the message.
Definition messagein.cpp:75
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:43
unsigned short mId
The message ID.
Definition messagein.h:86
ValueType
The type of a value in a message.
unsigned char uint8_t
Definition sha256.cpp:81
unsigned int uint32_t
Definition sha256.cpp:82