From 6853eac17709ea7d4694f4a38fcc9e1867f4ce8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 20 Nov 2012 14:35:39 +0000 Subject: xFire: some fix git-svn-id: http://svn.miranda-ng.org/main/trunk@2394 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Xfire/src/Xfire_game.h | 32 +- protocols/Xfire/src/baseProtocol.h | 4 +- protocols/Xfire/src/client.cpp | 552 +++++++++++++++--------------- protocols/Xfire/src/main.cpp | 10 +- protocols/Xfire/src/searching4games.cpp | 2 +- protocols/Xfire/src/sendmessagepacket.cpp | 62 ++-- 6 files changed, 332 insertions(+), 330 deletions(-) (limited to 'protocols/Xfire/src') diff --git a/protocols/Xfire/src/Xfire_game.h b/protocols/Xfire/src/Xfire_game.h index 0d502d121b..56a0e6e6e7 100644 --- a/protocols/Xfire/src/Xfire_game.h +++ b/protocols/Xfire/src/Xfire_game.h @@ -1,21 +1,21 @@ /* * Plugin of miranda IM(ICQ) for Communicating with users of the XFire Network. * - * Copyright (C) 2010 by - * dufte - * - * 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 + * Copyright (C) 2010 by + * dufte + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @@ -37,7 +37,7 @@ using namespace std; //externe funktion die das spielstarten steuern -extern int StartGame(WPARAM wParam,LPARAM lParam,LPARAM fParam); +extern INT_PTR StartGame(WPARAM wParam,LPARAM lParam,LPARAM fParam); class Xfire_game : public Xfire_base { public: diff --git a/protocols/Xfire/src/baseProtocol.h b/protocols/Xfire/src/baseProtocol.h index 98880dc64d..169a41804f 100644 --- a/protocols/Xfire/src/baseProtocol.h +++ b/protocols/Xfire/src/baseProtocol.h @@ -72,9 +72,7 @@ #include #include #include -#include -#include -#include +#include #include #include "services.h" diff --git a/protocols/Xfire/src/client.cpp b/protocols/Xfire/src/client.cpp index 4800482e27..336ab6b720 100644 --- a/protocols/Xfire/src/client.cpp +++ b/protocols/Xfire/src/client.cpp @@ -1,186 +1,186 @@ -/* - * xfirelib - C++ Library for the xfire protocol. - * Copyright (C) 2006 by - * Beat Wolf / http://gfire.sf.net - * Herbert Poul / http://goim.us - * http://xfirelib.sphene.net - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "stdafx.h" -#include "xdebug.h" -#include "client.h" -#include "clientinformationpacket.h" -#include "clientversionpacket.h" -#include "xfirepacket.h" -#include "authpacket.h" -#include "clientloginpacket.h" -#include "buddylistnamespacket.h" -#include "messagepacket.h" -#include "sendmessagepacket.h" -#include "messageackpacket.h" -#include "recvoldversionpacket.h" -#include "sendkeepalivepacket.h" - -#include "baseProtocol.h" - -#include - -//#define XFIRE_HOST "cs.xfire.com" -#define XFIRE_HOST "206.220.42.147" -#define XFIRE_PORT 25999 - -extern BOOL mySleep(int ms,HANDLE evt); -extern HANDLE hConnectionClose; +/* + * xfirelib - C++ Library for the xfire protocol. + * Copyright (C) 2006 by + * Beat Wolf / http://gfire.sf.net + * Herbert Poul / http://goim.us + * http://xfirelib.sphene.net + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "stdafx.h" +#include "xdebug.h" +#include "client.h" +#include "clientinformationpacket.h" +#include "clientversionpacket.h" +#include "xfirepacket.h" +#include "authpacket.h" +#include "clientloginpacket.h" +#include "buddylistnamespacket.h" +#include "messagepacket.h" +#include "sendmessagepacket.h" +#include "messageackpacket.h" +#include "recvoldversionpacket.h" +#include "sendkeepalivepacket.h" + +#include "baseProtocol.h" + +#include + +//#define XFIRE_HOST "cs.xfire.com" +#define XFIRE_HOST "206.220.42.147" +#define XFIRE_PORT 25999 + +extern BOOL mySleep(int ms,HANDLE evt); +extern HANDLE hConnectionClose; extern WINBASEAPI BOOL WINAPI ResetEvent( __in HANDLE hEvent - ); - -//#define UINT_8 unsigned char -//#define UINT_32 unsigned long - -namespace xfirelib { - -using namespace std; - - Client::Client() { - XDEBUG(("Client constructor ...\n")); - gameResolver = NULL; - packetReader = new PacketReader(NULL); - packetReader->addPacketListener( this ); - buddyList = new BuddyList( this ); - socket=NULL; -#ifndef NO_PTHREAD - sendpingthread.p=NULL; - readthread.p=NULL; -#endif - } - - Client::~Client(){ - XDEBUG(("Client destructor ...\n")); - delete username; - delete password; - delete buddyList; - delete packetReader; - delete socket; - } - - void Client::connect( string username, string password, int useproxy, string proxyip, int proxyport) { - try { - this->gotBudduyList=FALSE; - this->username = new string(username); - this->password = new string(password); - socket = new Socket( XFIRE_HOST, XFIRE_PORT,useproxy,proxyip,proxyport ); - - //bevors losgeht, erstmal die localaddr sichern + ); + +//#define UINT_8 unsigned char +//#define UINT_32 unsigned long + +namespace xfirelib { + +using namespace std; + + Client::Client() { + XDEBUG(("Client constructor ...\n")); + gameResolver = NULL; + packetReader = new PacketReader(NULL); + packetReader->addPacketListener( this ); + buddyList = new BuddyList( this ); + socket=NULL; +#ifndef NO_PTHREAD + sendpingthread.p=NULL; + readthread.p=NULL; +#endif + } + + Client::~Client(){ + XDEBUG(("Client destructor ...\n")); + delete username; + delete password; + delete buddyList; + delete packetReader; + delete socket; + } + + void Client::connect( string username, string password, int useproxy, string proxyip, int proxyport) { + try { + this->gotBudduyList=FALSE; + this->username = new string(username); + this->password = new string(password); + socket = new Socket( XFIRE_HOST, XFIRE_PORT,useproxy,proxyip,proxyport ); + + //bevors losgeht, erstmal die localaddr sichern struct sockaddr_in sa; int iLen = sizeof(sa); getsockname(socket->m_sock, (SOCKADDR*)&sa, &iLen); - strcpy(this->localaddr,inet_ntoa(sa.sin_addr)); - this->llocaladdr=inet_addr(this->localaddr); - - packetReader->setSocket(socket); - - ResetEvent(hConnectionClose); - - startThreads(); - //packetReader->startListening(); - - - socket->send("UA01"); - XDEBUG(("Sent UA01\n")); - ClientInformationPacket *infoPacket = new ClientInformationPacket(); - this->send( infoPacket ); - delete infoPacket; - XINFO(("sent ClientInformationPacket\n")); - - ClientVersionPacket *versionPacket = new ClientVersionPacket(); - versionPacket->setProtocolVersion( protocolVersion); - this->send( versionPacket ); - delete versionPacket; - - XINFO(("sent ClientVersionPacket\n")); - this->connected=TRUE; - } catch( SocketException ex ) { - XERROR(("Socket Exception ?! %s \n",ex.description().c_str() )); - this->connected=FALSE; - } - } - XFireGameResolver *Client::getGameResolver() { - return gameResolver; - } - void Client::startThreads() { - XINFO(("About to start thread\n")); -#ifndef NO_PTHREAD - void* (*func)(void*) = &xfirelib::Client::startReadThread; - pthread_create( &readthread, NULL, func, (void*)this ); - void* (*func2)(void*) = &xfirelib::Client::startSendPingThread; - pthread_create( &sendpingthread, NULL, func2, (void*)this ); -#else - //mir_create!!!! - mir_forkthread(xfirelib::Client::startReadThread,(LPVOID)this); - mir_forkthread(xfirelib::Client::startSendPingThread,(LPVOID)this); -#endif - } -#ifndef NO_PTHREAD - void *Client::startReadThread(void *ptr) { -#else - void Client::startReadThread(LPVOID lParam) { - void* ptr=(void*)lParam; -#endif - if(ptr==NULL||((Client*)ptr)->packetReader==NULL) -#ifndef NO_PTHREAD - return NULL; -#else - return; -#endif - try { - ((Client*)ptr)->packetReader->run(); - } catch (SocketException ex) { - XERROR(("Socket Exception ?! %s \n",ex.description().c_str() )); - - //miranda bescheid geben, wir haben verbindung verloren - if(ptr==NULL||((Client*)ptr)->connected) SetStatus(ID_STATUS_OFFLINE,NULL); - - //((Client*)ptr)->disconnect(); - } -#ifndef NO_PTHREAD - return NULL; -#else - return; -#endif - } - -#ifndef NO_PTHREAD - void *Client::startSendPingThread(void *ptr) { - Client *me = (Client*)ptr; -#else - void Client::startSendPingThread(LPVOID lParam) { - Client *me = (Client*)lParam; -#endif - SendKeepAlivePacket packet; - - while(1) { -#ifndef NO_PTHREAD - pthread_testcancel(); -#endif - //Sleep(60000); // Sleep for 40 sek + strcpy(this->localaddr,inet_ntoa(sa.sin_addr)); + this->llocaladdr=inet_addr(this->localaddr); + + packetReader->setSocket(socket); + + ResetEvent(hConnectionClose); + + startThreads(); + //packetReader->startListening(); + + + socket->send("UA01"); + XDEBUG(("Sent UA01\n")); + ClientInformationPacket *infoPacket = new ClientInformationPacket(); + this->send( infoPacket ); + delete infoPacket; + XINFO(("sent ClientInformationPacket\n")); + + ClientVersionPacket *versionPacket = new ClientVersionPacket(); + versionPacket->setProtocolVersion( protocolVersion); + this->send( versionPacket ); + delete versionPacket; + + XINFO(("sent ClientVersionPacket\n")); + this->connected=TRUE; + } catch( SocketException ex ) { + XERROR(("Socket Exception ?! %s \n",ex.description().c_str() )); + this->connected=FALSE; + } + } + XFireGameResolver *Client::getGameResolver() { + return gameResolver; + } + void Client::startThreads() { + XINFO(("About to start thread\n")); +#ifndef NO_PTHREAD + void* (*func)(void*) = &xfirelib::Client::startReadThread; + pthread_create( &readthread, NULL, func, (void*)this ); + void* (*func2)(void*) = &xfirelib::Client::startSendPingThread; + pthread_create( &sendpingthread, NULL, func2, (void*)this ); +#else + //mir_create!!!! + mir_forkthread(xfirelib::Client::startReadThread,(LPVOID)this); + mir_forkthread(xfirelib::Client::startSendPingThread,(LPVOID)this); +#endif + } +#ifndef NO_PTHREAD + void *Client::startReadThread(void *ptr) { +#else + void Client::startReadThread(LPVOID lParam) { + void* ptr=(void*)lParam; +#endif + if(ptr==NULL||((Client*)ptr)->packetReader==NULL) +#ifndef NO_PTHREAD + return NULL; +#else + return; +#endif + try { + ((Client*)ptr)->packetReader->run(); + } catch (SocketException ex) { + XERROR(("Socket Exception ?! %s \n",ex.description().c_str() )); + + //miranda bescheid geben, wir haben verbindung verloren + if(ptr==NULL||((Client*)ptr)->connected) SetStatus(ID_STATUS_OFFLINE,NULL); + + //((Client*)ptr)->disconnect(); + } +#ifndef NO_PTHREAD + return NULL; +#else + return; +#endif + } + +#ifndef NO_PTHREAD + void *Client::startSendPingThread(void *ptr) { + Client *me = (Client*)ptr; +#else + void Client::startSendPingThread(LPVOID lParam) { + Client *me = (Client*)lParam; +#endif + SendKeepAlivePacket packet; + + while(1) { +#ifndef NO_PTHREAD + pthread_testcancel(); +#endif + //Sleep(60000); // Sleep for 40 sek if(mySleep(60000,hConnectionClose)) { #ifndef NO_PTHREAD @@ -188,109 +188,109 @@ using namespace std; #else return; #endif - } -#ifndef NO_PTHREAD - pthread_testcancel(); -#endif - XDEBUG(( "Sending KeepAlivePacket\n" )); - if(!me->send( &packet )) { - XINFO(( "Could not send KeepAlivePacket... exiting thread.\n" )); - break; - } - } + } +#ifndef NO_PTHREAD + pthread_testcancel(); +#endif + XDEBUG(( "Sending KeepAlivePacket\n" )); + if(!me->send( &packet )) { + XINFO(( "Could not send KeepAlivePacket... exiting thread.\n" )); + break; + } + } #ifndef NO_PTHREAD return NULL; #else return; #endif - } - - void Client::disconnect() { - this->connected=FALSE; - - //socket vom packetreader auf NULL, damit die readschleife geschlossen wird - if(this->packetReader!=NULL) - this->packetReader->setSocket(NULL); - - XDEBUG( "cancelling readthread ... \n"); -#ifndef NO_PTHREAD - if(readthread.p!=NULL) pthread_cancel (readthread); - readthread.p=NULL; - - XDEBUG( "cancelling sendpingthread ... \n"); - if(sendpingthread.p!=NULL) pthread_cancel (sendpingthread); - sendpingthread.p=NULL; -#endif - - XDEBUG( "deleting socket ...\n" ); - if(socket){ - delete socket; - socket = NULL; - } - XDEBUG(( "done\n" )); - } - - bool Client::send( XFirePacketContent *content ) { - if(!socket) { - XERROR(( "Trying to send content packet altough socket is NULL ! (ignored)\n" )); - return false; - } - XFirePacket *packet = new XFirePacket(content); - packet->sendPacket( socket ); - delete packet; - return true; - } - - void Client::addPacketListener( PacketListener *listener ) { - packetReader->addPacketListener( listener ); - } - - - void Client::receivedPacket( XFirePacket *packet ) { - XDEBUG(("Client::receivedPacket\n")); - if( packet == NULL ) { - XERROR(("packet is NULL !!!\n")); - return; - } - if( packet->getContent() == NULL ) { - XERROR(("ERRRR getContent() returns null ?!\n")); - return; - } - XFirePacketContent *content = packet->getContent(); - - switch( content->getPacketId() ) { - case XFIRE_PACKET_AUTH_ID: { - XINFO(("Got Auth Packet .. Sending Login\n")); - AuthPacket *authPacket = (AuthPacket*)packet->getContent(); - - ClientLoginPacket *login = new ClientLoginPacket(); - login->setSalt( authPacket->getSalt() ); - login->setUsername( *username ); - login->setPassword( *password ); - send( login ); - delete login; - break; - } - - case XFIRE_MESSAGE_ID: { - XDEBUG(( "Got Message, sending ACK\n" )); - MessagePacket *message = (MessagePacket*)packet->getContent(); - if(message->getMessageType() == 0){ - MessageACKPacket *ack = new MessageACKPacket(); - memcpy(ack->sid,message->getSid(),16); - ack->imindex = message->getImIndex(); - send( ack ); - delete ack; - }else if(message->getMessageType() == 2){ - send(message); - } - break; - } - - default: - //cout << "Nothing here ... " << endl; - break; - } - - } -}; + } + + void Client::disconnect() { + this->connected=FALSE; + + //socket vom packetreader auf NULL, damit die readschleife geschlossen wird + if(this->packetReader!=NULL) + this->packetReader->setSocket(NULL); + + XDEBUG( "cancelling readthread ... \n"); +#ifndef NO_PTHREAD + if(readthread.p!=NULL) pthread_cancel (readthread); + readthread.p=NULL; + + XDEBUG( "cancelling sendpingthread ... \n"); + if(sendpingthread.p!=NULL) pthread_cancel (sendpingthread); + sendpingthread.p=NULL; +#endif + + XDEBUG( "deleting socket ...\n" ); + if(socket){ + delete socket; + socket = NULL; + } + XDEBUG(( "done\n" )); + } + + bool Client::send( XFirePacketContent *content ) { + if(!socket) { + XERROR(( "Trying to send content packet altough socket is NULL ! (ignored)\n" )); + return false; + } + XFirePacket *packet = new XFirePacket(content); + packet->sendPacket( socket ); + delete packet; + return true; + } + + void Client::addPacketListener( PacketListener *listener ) { + packetReader->addPacketListener( listener ); + } + + + void Client::receivedPacket( XFirePacket *packet ) { + XDEBUG(("Client::receivedPacket\n")); + if( packet == NULL ) { + XERROR(("packet is NULL !!!\n")); + return; + } + if( packet->getContent() == NULL ) { + XERROR(("ERRRR getContent() returns null ?!\n")); + return; + } + XFirePacketContent *content = packet->getContent(); + + switch( content->getPacketId() ) { + case XFIRE_PACKET_AUTH_ID: { + XINFO(("Got Auth Packet .. Sending Login\n")); + AuthPacket *authPacket = (AuthPacket*)packet->getContent(); + + ClientLoginPacket *login = new ClientLoginPacket(); + login->setSalt( authPacket->getSalt() ); + login->setUsername( *username ); + login->setPassword( *password ); + send( login ); + delete login; + break; + } + + case XFIRE_MESSAGE_ID: { + XDEBUG(( "Got Message, sending ACK\n" )); + MessagePacket *message = (MessagePacket*)packet->getContent(); + if(message->getMessageType() == 0){ + MessageACKPacket *ack = new MessageACKPacket(); + memcpy(ack->sid,message->getSid(),16); + ack->imindex = message->getImIndex(); + send( ack ); + delete ack; + }else if(message->getMessageType() == 2){ + send(message); + } + break; + } + + default: + //cout << "Nothing here ... " << endl; + break; + } + + } +}; diff --git a/protocols/Xfire/src/main.cpp b/protocols/Xfire/src/main.cpp index a2f8596f6c..45c93e9412 100644 --- a/protocols/Xfire/src/main.cpp +++ b/protocols/Xfire/src/main.cpp @@ -328,8 +328,12 @@ void XFireClient::sendmsg(char*usr,char*cmsg) { if(s.length()>100) { - char* temp=(char*)s.c_str(); - *(temp+100)=0; + s.substr(0, 100); + + // W T F? + ///char* temp=(char*)s.c_str(); + ///*(temp+100)=0; + // W T F? } SendStatusMessagePacket *packet = new SendStatusMessagePacket(); @@ -3567,7 +3571,7 @@ int ContactDeleted(WPARAM wParam,LPARAM lParam) { return 0; } -int StartGame(WPARAM wParam,LPARAM lParam,LPARAM fParam) { +INT_PTR StartGame(WPARAM wParam,LPARAM lParam,LPARAM fParam) { //gamelist blocken xgamelist.Block(TRUE); diff --git a/protocols/Xfire/src/searching4games.cpp b/protocols/Xfire/src/searching4games.cpp index abdb9c7b8e..b40a607990 100644 --- a/protocols/Xfire/src/searching4games.cpp +++ b/protocols/Xfire/src/searching4games.cpp @@ -34,7 +34,7 @@ using std::string; extern int foundgames; extern HANDLE XFireAvatarFolder; extern HANDLE XFireWorkingFolder; -extern int StartGame(WPARAM wParam,LPARAM lParam,LPARAM fParam); +extern INT_PTR StartGame(WPARAM wParam,LPARAM lParam,LPARAM fParam); extern Xfire_gamelist xgamelist; //versucht die * in den pfaden der ini mit dem korrekten eintrag zu ersetzen diff --git a/protocols/Xfire/src/sendmessagepacket.cpp b/protocols/Xfire/src/sendmessagepacket.cpp index a0f7e4e3d0..4559b7609c 100644 --- a/protocols/Xfire/src/sendmessagepacket.cpp +++ b/protocols/Xfire/src/sendmessagepacket.cpp @@ -1,33 +1,33 @@ -/* - * xfirelib - C++ Library for the xfire protocol. - * Copyright (C) 2006 by - * Beat Wolf / http://gfire.sf.net - * Herbert Poul / http://goim.us - * http://xfirelib.sphene.net - * - * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "stdafx.h" - -#include "sendmessagepacket.h" -#include "xfireutils.h" -#include -#include -#include "xdebug.h" - +/* + * xfirelib - C++ Library for the xfire protocol. + * Copyright (C) 2006 by + * Beat Wolf / http://gfire.sf.net + * Herbert Poul / http://goim.us + * http://xfirelib.sphene.net + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "stdafx.h" + +#include "sendmessagepacket.h" +#include "xfireutils.h" +#include +#include +#include "xdebug.h" + #include "sendmessagepacket.h" #include "xfireutils.h" #include @@ -100,4 +100,4 @@ namespace xfirelib { return index; } -} +} -- cgit v1.2.3