summaryrefslogtreecommitdiff
path: root/protocols/Xfire/src/client.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-08-11 13:33:42 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-08-11 13:33:42 +0000
commit85bd008c039eb1d93894e94fba9d158a42a71a12 (patch)
tree2d72d10759f6928e9e4b960175d2de01b5cf7e12 /protocols/Xfire/src/client.cpp
parent222802c2986dcaf029fdfb828b7679bdabfa7bb2 (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/client.cpp')
-rw-r--r--protocols/Xfire/src/client.cpp417
1 files changed, 216 insertions, 201 deletions
diff --git a/protocols/Xfire/src/client.cpp b/protocols/Xfire/src/client.cpp
index 024cfc16d9..41deafe97d 100644
--- a/protocols/Xfire/src/client.cpp
+++ b/protocols/Xfire/src/client.cpp
@@ -43,254 +43,269 @@
#define XFIRE_HOST "206.220.42.147"
#define XFIRE_PORT 25999
-extern BOOL mySleep(int ms,HANDLE evt);
+extern BOOL mySleep(int ms, HANDLE evt);
extern HANDLE hConnectionClose;
extern WINBASEAPI
BOOL
WINAPI
ResetEvent(
- __in HANDLE hEvent
- );
+__in HANDLE hEvent
+);
//#define UINT_8 unsigned char
//#define UINT_32 unsigned long
-namespace xfirelib {
+namespace xfirelib
+{
-using namespace std;
+ using namespace std;
- Client::Client() {
- XDEBUG(("Client constructor...\n"));
- gameResolver = NULL;
- packetReader = new PacketReader(NULL);
- packetReader->addPacketListener( this );
- buddyList = new BuddyList( this );
- socket=NULL;
+ 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;
+ 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);
- strncpy(this->localaddr,inet_ntoa(sa.sin_addr), sizeof(this->localaddr)-1);
- 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"));
+ }
+
+ 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);
+ strncpy(this->localaddr, inet_ntoa(sa.sin_addr), sizeof(this->localaddr) - 1);
+ 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 );
+ 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);
+ //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) {
+ void *Client::startReadThread(void *ptr) {
#else
- void Client::startReadThread(LPVOID lParam) {
- void* ptr=(void*)lParam;
+ void Client::startReadThread(LPVOID lParam)
+ {
+ void* ptr = (void*)lParam;
#endif
- if (ptr==NULL||((Client*)ptr)->packetReader==NULL)
+ if (ptr == NULL || ((Client*)ptr)->packetReader == NULL)
#ifndef NO_PTHREAD
- return NULL;
+ return NULL;
#else
- return;
+ return;
#endif
- try {
- ((Client*)ptr)->packetReader->run();
- } catch (SocketException ex) {
- XERROR(("Socket Exception ?! %s \n",ex.description().c_str() ));
+ 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);
+ //miranda bescheid geben, wir haben verbindung verloren
+ if (ptr == NULL || ((Client*)ptr)->connected) SetStatus(ID_STATUS_OFFLINE, NULL);
- //((Client*)ptr)->disconnect();
- }
+ //((Client*)ptr)->disconnect();
+ }
#ifndef NO_PTHREAD
- return NULL;
+ return NULL;
#else
- return;
+ return;
#endif
- }
+ }
#ifndef NO_PTHREAD
- void *Client::startSendPingThread(void *ptr) {
- Client *me = (Client*)ptr;
+ void *Client::startSendPingThread(void *ptr) {
+ Client *me = (Client*)ptr;
#else
- void Client::startSendPingThread(LPVOID lParam) {
- Client *me = (Client*)lParam;
+ void Client::startSendPingThread(LPVOID lParam)
+ {
+ Client *me = (Client*)lParam;
#endif
- SendKeepAlivePacket packet;
+ SendKeepAlivePacket packet;
- while(1) {
+ while (1) {
#ifndef NO_PTHREAD
- pthread_testcancel();
+ pthread_testcancel();
#endif
- //Sleep(60000); // Sleep for 40 sek
- if (mySleep(60000,hConnectionClose))
- {
+ //Sleep(60000); // Sleep for 40 sek
+ if (mySleep(60000, hConnectionClose)) {
#ifndef NO_PTHREAD
- return NULL;
+ return NULL;
#else
- return;
+ return;
#endif
- }
+ }
#ifndef NO_PTHREAD
- pthread_testcancel();
+ pthread_testcancel();
#endif
- XDEBUG(( "Sending KeepAlivePacket\n" ));
- if (!me->send( &packet )) {
- XINFO(( "Could not send KeepAlivePacket... exiting thread.\n" ));
- break;
- }
- }
+ XDEBUG(("Sending KeepAlivePacket\n"));
+ if (!me->send(&packet)) {
+ XINFO(("Could not send KeepAlivePacket... exiting thread.\n"));
+ break;
+ }
+ }
#ifndef NO_PTHREAD
- return NULL;
+ return NULL;
#else
- return;
+ return;
#endif
- }
+ }
- void Client::disconnect() {
- this->connected=FALSE;
+ void Client::disconnect()
+ {
+ this->connected = FALSE;
- //socket vom packetreader auf NULL, damit die readschleife geschlossen wird
- if (this->packetReader!=NULL)
- this->packetReader->setSocket(NULL);
+ //socket vom packetreader auf NULL, damit die readschleife geschlossen wird
+ if (this->packetReader != NULL)
+ this->packetReader->setSocket(NULL);
- XDEBUG( "cancelling readthread... \n");
+ XDEBUG("cancelling readthread... \n");
#ifndef NO_PTHREAD
- if (readthread.p!=NULL) pthread_cancel (readthread);
- readthread.p=NULL;
+ if (readthread.p!=NULL) pthread_cancel (readthread);
+ readthread.p=NULL;
- XDEBUG( "cancelling sendpingthread... \n");
- if (sendpingthread.p!=NULL) pthread_cancel (sendpingthread);
- sendpingthread.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;
- }
-
- }
+ 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;
+ }
+ }
};