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
24#include <cstdint>
25#include <string>
26
27namespace TmwAthena {
28
35{
36 public:
37 MessageIn(const char *data, unsigned int length);
38
42 uint16_t getId() const { return mId; }
43
47 unsigned int getLength() const { return mLength; }
48
52 unsigned int getUnreadLength() const
53 {
54 return (mPos < mLength) ? mLength - mPos : 0;
55 }
56
61
65 uint16_t readInt16();
66
71
76 void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction);
77
82 void readCoordinatePair(uint16_t &srcX, uint16_t &srcY,
83 uint16_t &dstX, uint16_t &dstY);
84
88 void skip(unsigned int length);
89
95 std::string readString(int length = -1);
96
97 private:
98 const char *mData;
99 unsigned int mLength;
100 unsigned short mId;
107 unsigned int mPos;
108};
109
110} // TmwAthena
Used for parsing an incoming message from eAthena.
Definition messagein.h:35
std::string readString(int length=-1)
Reads a string.
void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction)
Reads a special 3 byte block used by eAthena, containing x and y coordinates and direction.
Definition messagein.cpp:81
const char * mData
The message data.
Definition messagein.h:98
void skip(unsigned int length)
Skips a given number of bytes.
unsigned short mId
The message ID.
Definition messagein.h:100
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
Definition messagein.cpp:57
unsigned int getUnreadLength() const
Returns the length of unread data.
Definition messagein.h:52
uint8_t readInt8()
Reads an unsigned 8-bit integer from the message.
Definition messagein.cpp:46
void readCoordinatePair(uint16_t &srcX, uint16_t &srcY, uint16_t &dstX, uint16_t &dstY)
Reads a special 5 byte block used by eAthena, containing a source and destination coordinate pair.
unsigned int mPos
Actual position in the packet.
Definition messagein.h:107
uint16_t getId() const
Returns the message ID.
Definition messagein.h:42
unsigned int mLength
The length of the data.
Definition messagein.h:99
uint32_t readInt32()
Reads an unsigned 32-bit integer from the message.
Definition messagein.cpp:69
unsigned int getLength() const
Returns the message length.
Definition messagein.h:47
Warning: buffers and other variables are shared, so there can be only one connection active at a time...
unsigned char uint8_t
Definition sha256.cpp:81
unsigned int uint32_t
Definition sha256.cpp:82