| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by The qGo Project * |
| 3 | * * |
| 4 | * This file is part of qGo. * |
| 5 | * * |
| 6 | * qGo is free software: you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 18 | * or write to the Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | |
| 23 | #include "quickconnection.h"cxx . . $ `<file>/src/network/quickconnection.h`/ |
| 24 | #include "networkconnection.h"cxx . . $ `<file>/src/network/networkconnection.h`/ |
| 25 | |
| 26 | QuickConnectioncxx . . $ QuickConnection#::QuickConnectioncxx . . $ QuickConnection#QuickConnection(2e604933bf3a85e).(QStringcxx . . $ QString# hostname, qint16cxx . . $ qint16# port, void * m, NetworkConnectioncxx . . $ NetworkConnection# * c, QuickConnectionTypecxx . . $ QuickConnection#QuickConnectionType# t) : |
| 27 | msginfocxx . . $ QuickConnection#msginfo.(m), connectioncxx . . $ QuickConnection#connection.(c), typecxx . . $ QuickConnection#type.(t) |
| 28 | { |
| 29 | qsocketcxx . . $ QuickConnection#qsocket. = new QTcpSocketcxx . . $ QTcpSocket#(); //try with no parent passed for now |
| 30 | if(!qsocketcxx . . $ QuickConnection#qsocket.) |
| 31 | { |
| 32 | successcxx . . $ QuickConnection#success. = 0; |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | connectcxx . . $ QObject#connect(835f87066c895669).(qsocketcxx . . $ QuickConnection#qsocket., &QTcpSocketcxx . . $ QTcpSocket#::connectedcxx . . $ QAbstractSocket#connected(49f6e7a06ebc5aa8)., this, &QuickConnectioncxx . . $ QuickConnection#::OnConnectedcxx . . $ QuickConnection#OnConnected(49f6e7a06ebc5aa8).); |
| 37 | connectcxx . . $ QObject#connect(835f87066c895669).(qsocketcxx . . $ QuickConnection#qsocket., &QTcpSocketcxx . . $ QTcpSocket#::readyReadcxx . . $ QIODevice#readyRead(49f6e7a06ebc5aa8)., this, &QuickConnectioncxx . . $ QuickConnection#::OnReadyReadcxx . . $ QuickConnection#OnReadyRead(49f6e7a06ebc5aa8).); |
| 38 | connectcxx . . $ QObject#connect(835f87066c895669).(qsocketcxx . . $ QuickConnection#qsocket., QOverloadcxx . . $ QOverload#<QAbstractSocket::SocketError>::ofcxx . . $ QOverload#of(b333341f9aaad300).(&QTcpSocketcxx . . $ QTcpSocket#::errorcxx . . $ QAbstractSocket#error(c866838463bd22b).), this, &QuickConnectioncxx . . $ QuickConnection#::OnErrorcxx . . $ QuickConnection#OnError(c866838463bd22b).); |
| 39 | |
| 40 | qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). QStringcxx . . $ QString#QString(85c52e162fed56f9).("QuickConnection::QuickConnection : Connecting to") <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). hostname <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). ":" <<cxx . . $ QDebug#`operator<<`(8e4fad792f997cff). port; |
| 41 | |
| 42 | qsocketcxx . . $ QuickConnection#qsocket.->connectToHostcxx . . $ QAbstractSocket#connectToHost(778a8a9f30152020).(hostname, port); |
| 43 | |
| 44 | successcxx . . $ QuickConnection#success. = !(qsocketcxx . . $ QuickConnection#qsocket.->statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QTcpSocketcxx . . $ QTcpSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.); |
| 45 | } |
| 46 | |
| 47 | QuickConnectioncxx . . $ QuickConnection#::QuickConnectioncxx . . $ QuickConnection#QuickConnection(32b9642e6777eace).(QTcpSocketcxx . . $ QTcpSocket# * q, void * m, NetworkConnectioncxx . . $ NetworkConnection# * c, QuickConnectionTypecxx . . $ QuickConnection#QuickConnectionType# t) : |
| 48 | qsocketcxx . . $ QuickConnection#qsocket.(q), msginfocxx . . $ QuickConnection#msginfo.(m), connectioncxx . . $ QuickConnection#connection.(c), typecxx . . $ QuickConnection#type.(t) |
| 49 | { |
| 50 | disconnectcxx . . $ QObject#disconnect(cc30ff19c637f8ed).(qsocketcxx . . $ QuickConnection#qsocket., 0, connectioncxx . . $ QuickConnection#connection., 0); |
| 51 | |
| 52 | connectcxx . . $ QObject#connect(835f87066c895669).(qsocketcxx . . $ QuickConnection#qsocket., &QTcpSocketcxx . . $ QTcpSocket#::connectedcxx . . $ QAbstractSocket#connected(49f6e7a06ebc5aa8)., this, &QuickConnectioncxx . . $ QuickConnection#::OnConnectedcxx . . $ QuickConnection#OnConnected(49f6e7a06ebc5aa8).); |
| 53 | connectcxx . . $ QObject#connect(835f87066c895669).(qsocketcxx . . $ QuickConnection#qsocket., &QTcpSocketcxx . . $ QTcpSocket#::readyReadcxx . . $ QIODevice#readyRead(49f6e7a06ebc5aa8)., this, &QuickConnectioncxx . . $ QuickConnection#::OnReadyReadcxx . . $ QuickConnection#OnReadyRead(49f6e7a06ebc5aa8).); |
| 54 | connectcxx . . $ QObject#connect(835f87066c895669).(qsocketcxx . . $ QuickConnection#qsocket., QOverloadcxx . . $ QOverload#<QAbstractSocket::SocketError>::ofcxx . . $ QOverload#of(b333341f9aaad300).(&QTcpSocketcxx . . $ QTcpSocket#::errorcxx . . $ QAbstractSocket#error(c866838463bd22b).), this, &QuickConnectioncxx . . $ QuickConnection#::OnErrorcxx . . $ QuickConnection#OnError(c866838463bd22b).); |
| 55 | |
| 56 | successcxx . . $ QuickConnection#success. = !(qsocketcxx . . $ QuickConnection#qsocket.->statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QTcpSocketcxx . . $ QTcpSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.); |
| 57 | if(successcxx . . $ QuickConnection#success. != 0) |
| 58 | { |
| 59 | qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QC passed bad connection"); |
| 60 | return; |
| 61 | } |
| 62 | OnConnectedcxx . . $ QuickConnection#OnConnected(49f6e7a06ebc5aa8).(); |
| 63 | } |
| 64 | |
| 65 | int QuickConnectioncxx . . $ QuickConnection#::checkSuccesscxx . . $ QuickConnection#checkSuccess(b126dc7c1de90089).(void) |
| 66 | { |
| 67 | return successcxx . . $ QuickConnection#success.; |
| 68 | } |
| 69 | |
| 70 | void QuickConnectioncxx . . $ QuickConnection#::OnConnectedcxx . . $ QuickConnection#OnConnected(49f6e7a06ebc5aa8).(void) |
| 71 | { |
| 72 | int size; |
| 73 | char * packet = 0; |
| 74 | //qDebug("QC: OnConnected()"); |
| 75 | switch(typecxx . . $ QuickConnection#type.) |
| 76 | { |
| 77 | case sendRequestAccountInfocxx . . $ QuickConnection#sendRequestAccountInfo.: |
| 78 | packet = connectioncxx . . $ QuickConnection#connection.->sendRequestAccountInfocxx . . $ NetworkConnection#sendRequestAccountInfo(f967802dd305bc07).(&size, msginfocxx . . $ QuickConnection#msginfo.); |
| 79 | break; |
| 80 | case sendAddFriendcxx . . $ QuickConnection#sendAddFriend.: |
| 81 | packet = connectioncxx . . $ QuickConnection#connection.->sendAddFriendcxx . . $ NetworkConnection#sendAddFriend(f967802dd305bc07).(&size, msginfocxx . . $ QuickConnection#msginfo.); |
| 82 | break; |
| 83 | case sendRemoveFriendcxx . . $ QuickConnection#sendRemoveFriend.: |
| 84 | packet = connectioncxx . . $ QuickConnection#connection.->sendRemoveFriendcxx . . $ NetworkConnection#sendRemoveFriend(f967802dd305bc07).(&size, msginfocxx . . $ QuickConnection#msginfo.); |
| 85 | break; |
| 86 | case sendAddBlockcxx . . $ QuickConnection#sendAddBlock.: |
| 87 | packet = connectioncxx . . $ QuickConnection#connection.->sendAddFriendcxx . . $ NetworkConnection#sendAddFriend(f967802dd305bc07).(&size, msginfocxx . . $ QuickConnection#msginfo.); |
| 88 | break; |
| 89 | case sendRemoveBlockcxx . . $ QuickConnection#sendRemoveBlock.: |
| 90 | packet = connectioncxx . . $ QuickConnection#connection.->sendRemoveFriendcxx . . $ NetworkConnection#sendRemoveFriend(f967802dd305bc07).(&size, msginfocxx . . $ QuickConnection#msginfo.); |
| 91 | break; |
| 92 | } |
| 93 | if (qsocketcxx . . $ QuickConnection#qsocket.->writecxx . . $ QIODevice#write(93d4069f65218ea4).(packet, size) < 0) |
| 94 | qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QuickConnection write failed"); |
| 95 | delete[] packet; |
| 96 | } |
| 97 | |
| 98 | void QuickConnectioncxx . . $ QuickConnection#::OnReadyReadcxx . . $ QuickConnection#OnReadyRead(49f6e7a06ebc5aa8).(void) |
| 99 | { |
| 100 | int bytes = qsocketcxx . . $ QuickConnection#qsocket.->bytesAvailablecxx . . $ QAbstractSocket#bytesAvailable(98833e9ab7de59a4).(); |
| 101 | if(bytes > 1) |
| 102 | { |
| 103 | char * packet = new char[bytes]; |
| 104 | qsocketcxx . . $ QuickConnection#qsocket.->readcxx . . $ QIODevice#read(2e638bc8ed65be6c).(packet, bytes); |
| 105 | switch(typecxx . . $ QuickConnection#type.) |
| 106 | { |
| 107 | case sendRequestAccountInfocxx . . $ QuickConnection#sendRequestAccountInfo.: |
| 108 | connectioncxx . . $ QuickConnection#connection.->handleAccountInfoMsgcxx . . $ NetworkConnection#handleAccountInfoMsg(577809987ad7a468).(bytes, packet); |
| 109 | break; |
| 110 | case sendAddFriendcxx . . $ QuickConnection#sendAddFriend.: |
| 111 | case sendRemoveFriendcxx . . $ QuickConnection#sendRemoveFriend.: |
| 112 | case sendAddBlockcxx . . $ QuickConnection#sendAddBlock.: |
| 113 | case sendRemoveBlockcxx . . $ QuickConnection#sendRemoveBlock.: |
| 114 | connectioncxx . . $ QuickConnection#connection.->recvFriendResponsecxx . . $ NetworkConnection#recvFriendResponse(577809987ad7a468).(bytes, packet); |
| 115 | break; |
| 116 | } |
| 117 | delete[] packet; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void QuickConnectioncxx . . $ QuickConnection#::OnErrorcxx . . $ QuickConnection#OnError(c866838463bd22b).(QAbstractSocketcxx . . $ QAbstractSocket#::SocketErrorcxx . . $ QAbstractSocket#SocketError# err) |
| 122 | { |
| 123 | switch(err) |
| 124 | { |
| 125 | case QTcpSocketcxx . . $ QTcpSocket#::ConnectionRefusedErrorcxx . . $ QAbstractSocket#ConnectionRefusedError.: qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QuickConnection::OnError : connection refused"); |
| 126 | break; |
| 127 | case QTcpSocketcxx . . $ QTcpSocket#::HostNotFoundErrorcxx . . $ QAbstractSocket#HostNotFoundError.: qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QuickConnection::OnError : host not found"); |
| 128 | break; |
| 129 | case QTcpSocketcxx . . $ QTcpSocket#::SocketTimeoutErrorcxx . . $ QAbstractSocket#SocketTimeoutError.: qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QuickConnection::OnError : socket time out"); |
| 130 | break; |
| 131 | case QTcpSocketcxx . . $ QTcpSocket#::RemoteHostClosedErrorcxx . . $ QAbstractSocket#RemoteHostClosedError.: qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QuickConnection::OnError : connection closed by host"); |
| 132 | break; |
| 133 | default: qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("QuickConnection::OnError : unknown error"); |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | QuickConnectioncxx . . $ QuickConnection#::~cxx . . $ QuickConnection#`~QuickConnection`(ced63f7c635d850d).QuickConnectioncxx . . $ QuickConnection#() |
| 139 | { |
| 140 | if(qsocketcxx . . $ QuickConnection#qsocket.) |
| 141 | { |
| 142 | qsocketcxx . . $ QuickConnection#qsocket.->closecxx . . $ QAbstractSocket#close(49f6e7a06ebc5aa8).(); |
| 143 | qsocketcxx . . $ QuickConnection#qsocket.->deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).(); |
| 144 | } |
| 145 | } |