mxoemu/Reality/Source/SequencedPacket.cpp

71 lines
2.2 KiB
C++
Raw Permalink Normal View History

// ***************************************************************************
//
// Reality - The Matrix Online Server Emulator
2009-08-11 12:17:38 +00:00
// Copyright (C) 2006-2010 Rajko Stojadinovic
// http://mxoemu.info
2009-08-11 12:17:38 +00:00
//
// ---------------------------------------------------------------------------
2009-08-11 12:17:38 +00:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
2009-08-11 12:17:38 +00:00
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-08-11 12:17:38 +00:00
//
// ---------------------------------------------------------------------------
2009-08-11 12:17:38 +00:00
//
// ***************************************************************************
2009-08-11 12:17:38 +00:00
2009-08-12 19:55:32 +00:00
#include "SequencedPacket.h"
2009-08-11 12:17:38 +00:00
2009-08-16 15:37:27 +00:00
void SequencedPacket::Construct(ByteBuffer withHeader)
2009-08-11 12:17:38 +00:00
{
uint32 packedSeqs; //FL CC CS SS
withHeader.rpos(0);
withHeader >> packedSeqs;
uint32 packed = swap32(packedSeqs);
2009-08-12 19:55:32 +00:00
localSeq = packed&0xFFF;
remoteSeq = (packed>>12)&0xFFF;
ackBits = (packed>>24)&0xFF;
2009-08-11 12:17:38 +00:00
vector<byte> restOfPacket;
restOfPacket.resize(withHeader.size() - withHeader.rpos());
withHeader.read(&restOfPacket[0],restOfPacket.size());
this->clear();
this->append(&restOfPacket[0],restOfPacket.size());
}
2009-08-16 15:37:27 +00:00
SequencedPacket::SequencedPacket( ByteBuffer withHeader )
{
Construct(withHeader);
}
2009-08-12 19:55:32 +00:00
SequencedPacket::SequencedPacket( const string &withHeader )
2009-08-11 12:17:38 +00:00
{
ByteBuffer simulation;
simulation.append((const byte*)withHeader.data(),withHeader.size());
2009-08-16 15:37:27 +00:00
Construct(simulation);
2009-08-11 12:17:38 +00:00
}
2010-09-01 07:36:16 +02:00
ByteBuffer SequencedPacket::getDataWithHeader() const
2009-08-11 12:17:38 +00:00
{
uint32 packedSeqs = swap32((ackBits << 24) | ((remoteSeq & 0xFFF) << 12) | (localSeq & 0xFFF)); // FL CC CS SS
2009-08-11 12:17:38 +00:00
ByteBuffer returnMe;
returnMe << packedSeqs;
2010-09-01 07:36:16 +02:00
returnMe.append(this->contents(),this->count());
2009-08-11 12:17:38 +00:00
return returnMe;
2009-08-16 15:37:27 +00:00
}