Adding packet class for chat cleaner as separate file.
This commit is contained in:
@@ -99,6 +99,7 @@ HEADERS += \
|
||||
src/net/downloaderthread.h \
|
||||
src/net/downloadhelper.h \
|
||||
src/net/encodedpacket.h \
|
||||
src/net/internalchatcleanerpacket.h \
|
||||
src/third_party/tinyxml/tinystr.h \
|
||||
src/third_party/tinyxml/tinyxml.h \
|
||||
src/third_party/libircclient/include/libircclient.h \
|
||||
@@ -196,6 +197,7 @@ SOURCES += \
|
||||
src/net/common/uploaderthread.cpp \
|
||||
src/net/common/uploadhelper.cpp \
|
||||
src/net/common/encodedpacket.cpp \
|
||||
src/net/common/internalchatcleanerpacket.cpp \
|
||||
src/gui/generic/serverguiwrapper.cpp \
|
||||
src/gui/qttoolsinterface.cpp
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#define CLEANER_PROTOCOL_VERSION 1
|
||||
#define MAX_CLEANER_PACKET_SIZE 384
|
||||
|
||||
class InternalChatCleanerMessage;
|
||||
class InternalChatCleanerPacket;
|
||||
class EncodedPacket;
|
||||
|
||||
class ChatCleanerManager : public boost::enable_shared_from_this<ChatCleanerManager>
|
||||
@@ -47,9 +47,9 @@ protected:
|
||||
void HandleConnect(const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
||||
void HandleWrite(const boost::system::error_code &ec, boost::shared_ptr<EncodedPacket> tmpPacket);
|
||||
void HandleRead(const boost::system::error_code &ec, size_t bytesRead);
|
||||
bool HandleMessage(InternalChatCleanerMessage &msg);
|
||||
bool HandleMessage(InternalChatCleanerPacket &msg);
|
||||
|
||||
void SendMessageToServer(InternalChatCleanerMessage &msg);
|
||||
void SendMessageToServer(InternalChatCleanerPacket &msg);
|
||||
unsigned GetNextRequestId();
|
||||
|
||||
private:
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include <net/chatcleanermanager.h>
|
||||
#include <net/internalchatcleanerpacket.h>
|
||||
#include <net/encodedpacket.h>
|
||||
#include <boost/bind.hpp>
|
||||
#include <core/loghelper.h>
|
||||
@@ -27,35 +28,6 @@
|
||||
using namespace std;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
class InternalChatCleanerMessage
|
||||
{
|
||||
public:
|
||||
InternalChatCleanerMessage()
|
||||
{
|
||||
m_msg = (ChatCleanerMessage_t *)calloc(1, sizeof(ChatCleanerMessage_t));
|
||||
}
|
||||
InternalChatCleanerMessage(ChatCleanerMessage_t *msg)
|
||||
: m_msg(msg)
|
||||
{
|
||||
}
|
||||
~InternalChatCleanerMessage()
|
||||
{
|
||||
if (m_msg)
|
||||
ASN_STRUCT_FREE(asn_DEF_ChatCleanerMessage, m_msg);
|
||||
}
|
||||
ChatCleanerMessage_t *GetMsg()
|
||||
{
|
||||
return m_msg;
|
||||
}
|
||||
ChatCleanerMessage_t **GetMsgPtr()
|
||||
{
|
||||
return &m_msg;
|
||||
}
|
||||
|
||||
private:
|
||||
ChatCleanerMessage_t *m_msg;
|
||||
};
|
||||
|
||||
|
||||
ChatCleanerManager::ChatCleanerManager(boost::shared_ptr<boost::asio::io_service> ioService)
|
||||
: m_ioService(ioService), m_connected(false), m_curRequestId(0), m_recvBufUsed(0)
|
||||
@@ -96,7 +68,7 @@ ChatCleanerManager::HandleChatText(unsigned playerId, const std::string &name, c
|
||||
{
|
||||
if (m_connected)
|
||||
{
|
||||
InternalChatCleanerMessage tmpChat;
|
||||
InternalChatCleanerPacket tmpChat;
|
||||
tmpChat.GetMsg()->present = ChatCleanerMessage_PR_cleanerChatRequestMessage;
|
||||
CleanerChatRequestMessage_t *netRequest = &tmpChat.GetMsg()->choice.cleanerChatRequestMessage;
|
||||
netRequest->requestId = GetNextRequestId();
|
||||
@@ -137,7 +109,7 @@ ChatCleanerManager::HandleConnect(const boost::system::error_code& ec,
|
||||
{
|
||||
if (!ec)
|
||||
{
|
||||
InternalChatCleanerMessage tmpInit;
|
||||
InternalChatCleanerPacket tmpInit;
|
||||
tmpInit.GetMsg()->present = ChatCleanerMessage_PR_cleanerInitMessage;
|
||||
CleanerInitMessage_t *netInit = &tmpInit.GetMsg()->choice.cleanerInitMessage;
|
||||
netInit->requestedVersion = CLEANER_PROTOCOL_VERSION;
|
||||
@@ -194,7 +166,7 @@ ChatCleanerManager::HandleRead(const boost::system::error_code &ec, size_t bytes
|
||||
asn_dec_rval_t retVal;
|
||||
do
|
||||
{
|
||||
InternalChatCleanerMessage recvMsg;
|
||||
InternalChatCleanerPacket recvMsg;
|
||||
retVal = ber_decode(0, &asn_DEF_ChatCleanerMessage, (void **)recvMsg.GetMsgPtr(), m_recvBuf, m_recvBufUsed);
|
||||
if(retVal.code == RC_OK)
|
||||
{
|
||||
@@ -231,7 +203,7 @@ ChatCleanerManager::HandleRead(const boost::system::error_code &ec, size_t bytes
|
||||
}
|
||||
|
||||
bool
|
||||
ChatCleanerManager::HandleMessage(InternalChatCleanerMessage &msg)
|
||||
ChatCleanerManager::HandleMessage(InternalChatCleanerPacket &msg)
|
||||
{
|
||||
bool error = false;
|
||||
if (msg.GetMsg()->present == ChatCleanerMessage_PR_cleanerInitAckMessage)
|
||||
@@ -254,7 +226,7 @@ ChatCleanerManager::HandleMessage(InternalChatCleanerMessage &msg)
|
||||
}
|
||||
|
||||
void
|
||||
ChatCleanerManager::SendMessageToServer(InternalChatCleanerMessage &msg)
|
||||
ChatCleanerManager::SendMessageToServer(InternalChatCleanerPacket &msg)
|
||||
{
|
||||
unsigned char buf[MAX_CLEANER_PACKET_SIZE];
|
||||
asn_enc_rval_t e = der_encode_to_buffer(&asn_DEF_ChatCleanerMessage, msg.GetMsg(), buf, MAX_CLEANER_PACKET_SIZE);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2009 by Lothar May *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <net/internalchatcleanerpacket.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
InternalChatCleanerPacket::InternalChatCleanerPacket()
|
||||
{
|
||||
m_msg = (ChatCleanerMessage_t *)calloc(1, sizeof(ChatCleanerMessage_t));
|
||||
}
|
||||
|
||||
InternalChatCleanerPacket::~InternalChatCleanerPacket()
|
||||
{
|
||||
if (m_msg)
|
||||
ASN_STRUCT_FREE(asn_DEF_ChatCleanerMessage, m_msg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2009 by Lothar May *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
/* PokerTH chat cleaner packet. */
|
||||
|
||||
#ifndef _INTERNALCHATCLEANERPACKET_H_
|
||||
#define _INTERNALCHATCLEANERPACKET_H_
|
||||
|
||||
#include <third_party/asn1/ChatCleanerMessage.h>
|
||||
|
||||
class InternalChatCleanerPacket
|
||||
{
|
||||
public:
|
||||
InternalChatCleanerPacket();
|
||||
|
||||
InternalChatCleanerPacket(ChatCleanerMessage_t *msg)
|
||||
: m_msg(msg)
|
||||
{
|
||||
}
|
||||
~InternalChatCleanerPacket();
|
||||
ChatCleanerMessage_t *GetMsg()
|
||||
{
|
||||
return m_msg;
|
||||
}
|
||||
ChatCleanerMessage_t **GetMsgPtr()
|
||||
{
|
||||
return &m_msg;
|
||||
}
|
||||
|
||||
private:
|
||||
ChatCleanerMessage_t *m_msg;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user