diff options
author | George Hazan <george.hazan@gmail.com> | 2015-08-11 13:33:42 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-08-11 13:33:42 +0000 |
commit | 85bd008c039eb1d93894e94fba9d158a42a71a12 (patch) | |
tree | 2d72d10759f6928e9e4b960175d2de01b5cf7e12 /protocols/Xfire/src/packetreader.cpp | |
parent | 222802c2986dcaf029fdfb828b7679bdabfa7bb2 (diff) |
massive code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14910 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Xfire/src/packetreader.cpp')
-rw-r--r-- | protocols/Xfire/src/packetreader.cpp | 221 |
1 files changed, 115 insertions, 106 deletions
diff --git a/protocols/Xfire/src/packetreader.cpp b/protocols/Xfire/src/packetreader.cpp index a1b18590e1..866a5acb5d 100644 --- a/protocols/Xfire/src/packetreader.cpp +++ b/protocols/Xfire/src/packetreader.cpp @@ -54,110 +54,119 @@ #include "recvbuddychangednick.h" #include "xdebug.h" -//#include "packetlistener.h" - -namespace xfirelib { - using namespace std; - - PacketReader::PacketReader(Socket *socket) { - this->socket = socket; - this->packetListeners = new vector<PacketListener *>(); - - initPackets(); - } - void PacketReader::setSocket(Socket *socket) { - this->socket = socket; - } - PacketReader::~PacketReader() { - // TODO: delete each packetListener .. - delete packetListeners; - - while(!packets->empty()) { delete packets->at(packets->size()-1); packets->pop_back(); } - delete packets; - } - - void PacketReader::initPackets() { - packets = new vector <XFirePacketContent *>(); - packets->push_back( new ClientInformationPacket() ); - packets->push_back( new AuthPacket() ); - packets->push_back( new LoginFailedPacket() ); - packets->push_back( new LoginSuccessPacket() ); - packets->push_back( new MessagePacket() ); - packets->push_back( new BuddyListOnlinePacket() ); - packets->push_back( new BuddyListNamesPacket() ); - packets->push_back( new BuddyListGamesPacket() ); - packets->push_back( new BuddyListGames2Packet() ); - packets->push_back( new OtherLoginPacket() ); - packets->push_back( new InviteBuddyPacket() ); - packets->push_back( new InviteRequestPacket() ); - packets->push_back( new RecvRemoveBuddyPacket() ); - packets->push_back( new RecvDidPacket() ); - packets->push_back( new RecvStatusMessagePacket() ); - packets->push_back( new RecvOldVersionPacket() ); - packets->push_back( new RecvPrefsPacket() ); - //neue packetklassen hinzugefügt - dufte - packets->push_back( new FriendsBuddyListNamesPacket() ); - packets->push_back( new ClanBuddyListNamesPacket() ); - packets->push_back( new XFireClanPacket() ); - packets->push_back( new GameInfoPacket() ); - packets->push_back( new ClanInvitationPacket() ); - packets->push_back( new XFireFoundBuddys() ); - packets->push_back( new BuddyInfoPacket() ); - packets->push_back( new RecvBuddyChangedNick() ); - } - - - void *muh(void *ptr); - - /* I moved thread starting to Client - - void PacketReader::startListening() { - PacketReader *myself = this; - void* (*func)(void*) = &xfirelib::PacketReader::thread_start; - XINFO(("About to start thread\n")); - int ret = pthread_create( &readthread, NULL, func, (void*)myself ); - XDEBUG(("ret: %d\n",ret)); - } - */ - - void PacketReader::run() { - // start receiving on socket... - XDEBUG(("Starting run() method... \n")); - while(socket != NULL) { - string str; - //int b = socket->recv(str); - XFirePacket *packet = new XFirePacket(this); - XDEBUG(("Waiting for next packet... \n")); - if (packet==NULL) continue; - packet->recvPacket( socket ); - XINFO(("Received packet\n")); - if (packet->getContent() != NULL) { - fireListeners( packet ); - } else { - XDEBUG(("Packet Content was NULL ... Unknown Packet Id ??\n")); - } - XDEBUG(("Notified Listeners\n"));// << b << "bytes: " << str << endl; - delete packet->getContent(); - delete packet; - } - } - - void PacketReader::fireListeners( XFirePacket *packet ) { - for(vector<PacketListener *>::iterator it = packetListeners->begin() ; - it != packetListeners->end() ; ++it) { - (*it)->receivedPacket( packet ); - } - } - - XFirePacketContent *PacketReader::getPacketContentClass(int packetId) { - XDEBUG(("Searching for a content class...\n")); - for(uint i = 0 ; i < packets->size() ; i++) - if (packets->at(i)->getPacketId() == packetId) return packets->at(i); - XDEBUG(("None Found\n")); - return NULL; - } - - void PacketReader::addPacketListener( PacketListener *listener ) { - packetListeners->push_back( listener ); - } + +using namespace std; + +namespace xfirelib +{ + PacketReader::PacketReader(Socket *socket) + { + this->socket = socket; + this->packetListeners = new vector<PacketListener *>(); + + initPackets(); + } + void PacketReader::setSocket(Socket *socket) + { + this->socket = socket; + } + PacketReader::~PacketReader() + { + // TODO: delete each packetListener .. + delete packetListeners; + + while (!packets->empty()) { delete packets->at(packets->size() - 1); packets->pop_back(); } + delete packets; + } + + void PacketReader::initPackets() + { + packets = new vector <XFirePacketContent *>(); + packets->push_back(new ClientInformationPacket()); + packets->push_back(new AuthPacket()); + packets->push_back(new LoginFailedPacket()); + packets->push_back(new LoginSuccessPacket()); + packets->push_back(new MessagePacket()); + packets->push_back(new BuddyListOnlinePacket()); + packets->push_back(new BuddyListNamesPacket()); + packets->push_back(new BuddyListGamesPacket()); + packets->push_back(new BuddyListGames2Packet()); + packets->push_back(new OtherLoginPacket()); + packets->push_back(new InviteBuddyPacket()); + packets->push_back(new InviteRequestPacket()); + packets->push_back(new RecvRemoveBuddyPacket()); + packets->push_back(new RecvDidPacket()); + packets->push_back(new RecvStatusMessagePacket()); + packets->push_back(new RecvOldVersionPacket()); + packets->push_back(new RecvPrefsPacket()); + //neue packetklassen hinzugefügt - dufte + packets->push_back(new FriendsBuddyListNamesPacket()); + packets->push_back(new ClanBuddyListNamesPacket()); + packets->push_back(new XFireClanPacket()); + packets->push_back(new GameInfoPacket()); + packets->push_back(new ClanInvitationPacket()); + packets->push_back(new XFireFoundBuddys()); + packets->push_back(new BuddyInfoPacket()); + packets->push_back(new RecvBuddyChangedNick()); + } + + + void *muh(void *ptr); + + /* I moved thread starting to Client + + void PacketReader::startListening() { + PacketReader *myself = this; + void* (*func)(void*) = &xfirelib::PacketReader::thread_start; + XINFO(("About to start thread\n")); + int ret = pthread_create( &readthread, NULL, func, (void*)myself ); + XDEBUG(("ret: %d\n",ret)); + } + */ + + void PacketReader::run() + { + // start receiving on socket... + XDEBUG(("Starting run() method... \n")); + while (socket != NULL) { + string str; + //int b = socket->recv(str); + XFirePacket *packet = new XFirePacket(this); + XDEBUG(("Waiting for next packet... \n")); + if (packet == NULL) continue; + packet->recvPacket(socket); + XINFO(("Received packet\n")); + if (packet->getContent() != NULL) { + fireListeners(packet); + } + else { + XDEBUG(("Packet Content was NULL ... Unknown Packet Id ??\n")); + } + XDEBUG(("Notified Listeners\n"));// << b << "bytes: " << str << endl; + delete packet->getContent(); + delete packet; + } + } + + void PacketReader::fireListeners(XFirePacket *packet) + { + for (vector<PacketListener *>::iterator it = packetListeners->begin(); + it != packetListeners->end(); ++it) { + (*it)->receivedPacket(packet); + } + } + + XFirePacketContent *PacketReader::getPacketContentClass(int packetId) + { + XDEBUG(("Searching for a content class...\n")); + for (uint i = 0; i < packets->size(); i++) + if (packets->at(i)->getPacketId() == packetId) return packets->at(i); + XDEBUG(("None Found\n")); + return NULL; + } + + void PacketReader::addPacketListener(PacketListener *listener) + { + packetListeners->push_back(listener); + } }; |