void testNet::testServerFinished(QNetworkReply* reply) { STOP_TIMER(testNetTimer); QNetworkReply::NetworkError error=reply->error(); if(!error) { QString replybuf(reply->readAll().trimmed()); switch(mode){ case TEST_SERVER_NET: if(replybuf.startsWith(QString("1"))) { SET_RUN_PARAMETER(RUN_PARAMETER_TESTNET_RESULT,TEST_NET_SUCCESS); } break; case TEST_SERVER_VERSION: { qDebug()<<replybuf; QRegExp verre("^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$"); if(verre.exactMatch(replybuf)){ QDEBUG_LINE; QStringList s_version = replybuf.split("."); QStringList l_version = QString(APP_VERSION).split("."); for (int i = 0; i < s_version.size(); ++i) { if(s_version.at(i).toUInt()>l_version.at(i).toUInt()) { SET_RUN_PARAMETER(RUN_PARAMETER_TESTNET_VERSION,1); break; } } } } break; } }else{
bool RequestSessionId( unsigned int& id ) { id = 0u; bf_write buf; byte data[ 2048 ]; buf.StartWriting( data, sizeof( data ) ); BuildMessage( buf, PHONE_MSG_ENGINESTART, NULL, id ); struct sockaddr_in sa; m_cserIP.ToSockadr( (struct sockaddr *)&sa ); for ( int retries = 0; retries < PHONE_HOME_RETRIES; ++retries ) { m_pSocket->SendSocketMessage( sa, (const byte *)buf.GetData(), buf.GetNumBytesWritten() ); //lint !e534 if ( m_pSocket->WaitForMessage( PHONE_HOME_TIMEOUT ) ) { byte readbuf[ 128 ]; bf_read replybuf( readbuf, sizeof( readbuf ) ); struct sockaddr_in replyaddress; uint bytesReceived = m_pSocket->ReceiveSocketMessage( &replyaddress, (byte *)readbuf, sizeof( readbuf ) ); if ( bytesReceived > 0 ) { // Fixup actual size replybuf.StartReading( readbuf, bytesReceived ); // Parse out data byte responseType = (byte)replybuf.ReadByte(); if ( M2C_ACKPHONEHOME == responseType ) { bool allowPlay = replybuf.ReadByte() == 1 ? true : false; if ( allowPlay ) { id = replybuf.ReadLong(); return true; } } break; } } } return false; }
void SendSessionMessage( byte msgtype, char const *mapname ) { if ( m_uSessionID == 0 ) return; bf_write buf; byte data[ 2048 ]; buf.StartWriting( data, sizeof( data ) ); BuildMessage( buf, msgtype, mapname, m_uSessionID ); struct sockaddr_in sa; m_cserIP.ToSockadr( (struct sockaddr *)&sa ); m_pSocket->SendSocketMessage( sa, (const byte *)buf.GetData(), buf.GetNumBytesWritten() ); // If we already have a sessionid, don't wait for the server to give us back a new one... if ( m_uSessionID != 0 ) { return; } if ( m_pSocket->WaitForMessage( PHONE_HOME_TIMEOUT ) ) { byte readbuf[ 128 ]; bf_read replybuf( readbuf, sizeof( readbuf ) ); struct sockaddr_in replyaddress; uint bytesReceived = m_pSocket->ReceiveSocketMessage( &replyaddress, (byte *)readbuf, sizeof( readbuf ) ); if ( bytesReceived > 0 ) { // Fixup actual size replybuf.StartReading( readbuf, bytesReceived ); // Parse out data byte responseType = (byte)replybuf.ReadByte(); if ( M2C_ACKPHONEHOME == responseType ) { bool allowPlay = replybuf.ReadByte() == 1 ? true : false; if ( allowPlay ) { m_uSessionID = replybuf.ReadLong(); } } } } }