123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include "common/won.h"
- #include "msg/TMessage.h"
- #include "msg/BadMsgException.h"
- #include "TitanPacketMsg.h"
- #include "TitanInterfaceC.h"
- using WONMsg::MiniMessage;
- // ** TitanPacketMsg **
- // ** Constructors / Destructor
- // Default ctor
- TitanPacketMsg::TitanPacketMsg(unsigned char theType, bool encrypted) :
- mBlob(NULL),
- mBlobLen(0),
- mIncludeGameName(theType != TITANMSGTYPE_GAME)
- {
- SetServiceType(encrypted ? MyEncryptServiceType : MyServiceType);
- SetMessageType(theType);
- }
- // TMessage ctor
- TitanPacketMsg::TitanPacketMsg(const MiniMessage& theMsgR) :
- MiniMessage(theMsgR),
- mIncludeGameName(true),
- mBlob(NULL),
- mBlobLen(0)
- {
- Unpack();
- }
- // Copy ctor
- TitanPacketMsg::TitanPacketMsg(const TitanPacketMsg& theMsgR) :
- MiniMessage(theMsgR),
- mIncludeGameName(theMsgR.mIncludeGameName),
- mGameName(theMsgR.mGameName),
- mBlob(theMsgR.mBlob),
- mBlobLen(theMsgR.mBlobLen)
- {
- SetBlob(theMsgR.GetBlob(), theMsgR.GetBlobLen());
- }
- // Destructor
- TitanPacketMsg::~TitanPacketMsg(void)
- {}
- // ** Public Methods
- // Assignment operator
- TitanPacketMsg&
- TitanPacketMsg::operator=(const TitanPacketMsg& theMsgR)
- {
- if (this != &theMsgR)
- {
- MiniMessage::operator=(theMsgR);
- mIncludeGameName = theMsgR.mIncludeGameName;
- mGameName = theMsgR.mGameName;
- mBlob = theMsgR.mBlob;
- mBlobLen = theMsgR.mBlobLen;
- }
- return *this;
- }
- // TitanPacketMsg::Pack
- // Virtual method from MiniMessage. Packs data into message buffer and
- // sets the new message length.
- void*
- TitanPacketMsg::Pack(void)
- {
- MiniMessage::Pack();
-
- // append game name if required
- if (mIncludeGameName)
- Append_PW_STRING(mGameName);
-
- // append data
- AppendBytes(mBlobLen, mBlob);
- return GetDataPtr();
- }
- // TitanPacketMsg::Unpack
- // Virtual method from MiniMessage. Extracts data from message buffer.
- void
- TitanPacketMsg::Unpack(void)
- {
- MiniMessage::Unpack();
- if ((GetServiceType() != MyEncryptServiceType) &&
- (GetServiceType() != MyServiceType))
- {
- throw WONMsg::BadMsgException(*this, __LINE__, __FILE__,
- "Not a TitanPacketMsg message.");
- }
- mIncludeGameName = (GetMessageType() != TITANMSGTYPE_GAME);
- if (mIncludeGameName)
- ReadWString(mGameName);
-
- mBlobLen = BytesLeftToRead();
- mBlob = ReadBytes(BytesLeftToRead());
- }
|