// Poll and notify main thread if responses exists in queue KDvoid CCHttpClient::dispatchResponseCallbacks ( KDfloat fDelta ) { CCHttpResponse* pResponse = KD_NULL; kdThreadMutexLock ( l_pResponseQueueMutex ); if ( l_pResponseQueue->count ( ) ) { pResponse = dynamic_cast<CCHttpResponse*> ( l_pResponseQueue->objectAtIndex ( 0 ) ); l_pResponseQueue->removeObjectAtIndex ( 0 ); } kdThreadMutexUnlock ( l_pResponseQueueMutex ); if ( pResponse ) { --l_uAsyncRequestCount; CCHttpRequest* pRequest = pResponse->getHttpRequest ( ); CCObject* pTarget = pRequest->getTarget ( ); SEL_CallFuncND pSelector = pRequest->getSelector ( ); if ( pTarget && pSelector ) { ( pTarget->*pSelector ) ( (CCNode*) this, pResponse ); } pResponse->release ( ); } if ( 0 == l_uAsyncRequestCount ) { CCDirector::sharedDirector ( )->getScheduler ( )->pauseTarget ( this ); } }
void ParseFile::deleteFileFinished(CCNode* sender, void* param) { bool success = false; ParseError* error = new ParseError(); CCHttpResponse* response = (CCHttpResponse*)param; if (response->getResponseCode() == 200) { success = true; } else { if (strlen(response->getErrorBuffer()) > 0) { error->SetError(response->getErrorBuffer()); } else { std::vector<char>* responseData = response->getResponseData(); responseData->push_back('\0'); error->SetError(&responseData->front()); } } this->deleteFileCompleted(success, error); delete error; }
void DataRequest::onHttpRequestCompleteHandler(cocos2d::CCNode *pSender, void *pObj) { CCHttpResponse *pResponse = (CCHttpResponse* )pObj; if (!pResponse) { return; } if (pResponse->isSucceed()) { std::string responseData; std::vector<char> *buffer = pResponse->getResponseData(); char buff[24]; for (unsigned int i = 0; i < buffer->size(); i ++) { sprintf(buff, "%c", (*buffer)[i]); responseData.append(buff); } //CCLog(responseData.c_str()); if (m_pTarget && m_requestAction) { (m_pTarget->*m_requestAction)(RequestStatusSucceed, responseData); } } else { const char *error = pResponse->getErrorBuffer(); if (m_pTarget && m_requestAction) { (m_pTarget->*m_requestAction)(RequestStatusError, error); } } }
void RankScene::getRankListRequestCompleted(CCNode* sender,void* data){ CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); int counter_name = 0; int counter_winPercent = 0; int counter_weeklywin = 0; for (unsigned int i = 0; i < buffer->size(); i++) { if ((*buffer)[i] == '"' && (*buffer)[i+1] == 'n' && (*buffer)[i+2] == 'i' && (*buffer)[i+3] == 'c' && (*buffer)[i+4] == 'k' && (*buffer)[i+5] == '"') { for (int j = i + 8 ; (*buffer)[j] != '"' ; j++) { nickName_Rank[counter_name] += (*buffer)[j]; } counter_name++; } if((*buffer)[i] == '"' && (*buffer)[i+1] == 'w' && (*buffer)[i+2] == 'e' && (*buffer)[i+3] == 'e' && (*buffer)[i+4] == 'k' && (*buffer)[i+5] == 'l' && (*buffer)[i+19] == '"') { for (int j = i + 21 ; (*buffer)[j] != ',' ; j++) { winPercent_Rank[counter_winPercent] += (*buffer)[j]; } winPercent_Rank[counter_winPercent] = float2string(atof(winPercent_Rank[counter_winPercent].c_str())*100) + "%"; counter_winPercent++; } if((*buffer)[i] == '"' && (*buffer)[i+1] == 'w' && (*buffer)[i+2] == 'e' && (*buffer)[i+3] == 'e' && (*buffer)[i+4] == 'k' && (*buffer)[i+5] == 'l' && (*buffer)[i+11] == '"') { for (int j = i + 13 ; (*buffer)[j] != ',' ; j++) { weeklyWin_Rank[counter_weeklywin] += (*buffer)[j]; } counter_weeklywin++; } } getServerTime(); }
void RankScene::getRankRequestCompleted(CCNode* sender,void* data){ CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); }
void RequestTopaz::onHttpRequestCompleted(CCNode *sender, void *data) { // Loading 창 끄기 ((Loading*)Depth::GetCurPointer())->EndScene(); CCHttpResponse* res = (CCHttpResponse*) data; xml_document xmlDoc; Network::GetXMLFromResponseData(res, xmlDoc); std::string friendKakaoId = res->getHttpRequest()->getTag(); XmlParseResult(&xmlDoc, friendKakaoId); }
void* CCHttpClient::httpThreadEntry(void* arg) { // handler, it is released if init failed or released in dispatchNotification ccHttpContext* ctx = (ccHttpContext*)arg; CURLHandler* curl = ctx->curl; if(!curl->init()) { CC_SAFE_RELEASE_NULL(curl); } if(curl) { // create response CCHttpResponse* response = new CCHttpResponse(curl->m_ctx->request); curl->m_ctx->response = response; // process request bool retValue = false; switch (curl->m_ctx->request->getMethod()) { case CCHttpRequest::kHttpGet: retValue = curl->processGetTask(); break; case CCHttpRequest::kHttpPost: retValue = curl->processPostTask(); break; case CCHttpRequest::kHttpPut: retValue = curl->processPutTask(); break; case CCHttpRequest::kHttpDelete: retValue = curl->processDeleteTask(); break; default: CCAssert(true, "CCHttpClient: unkown request type, only GET and POST are supported"); break; } // save response response->setResponseCode(curl->m_responseCode); if (retValue) { response->setSuccess(true); } else { response->setSuccess(false); response->setErrorData(curl->m_errorBuffer); } // done curl->onRequestDone(); } // exit pthread_exit(NULL); return NULL; }
void ASUser::getHeroInformationRequestCompleted(cocos2d::CCNode *sender, void *data){ for (int i = 0 ; i < 5 ; i++) { HeroLevel[i] = 0; HeroUnLocked[i] = false; } CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); for (unsigned int i = 0; i < buffer->size(); i++) { //1.1 第1个英雄的等级情况 if ((*buffer)[i] == '{' && (*buffer)[i+1] == '"' && (*buffer)[i+2] == 'a' && (*buffer)[i+3] == 'v' && (*buffer)[i+4] == 'a' && (*buffer)[i+13] == '0' && (*buffer)[i+14] == ','){ HeroUnLocked[0] = true; for (int j = i+23;(*buffer)[j] != '}' ; j++) { HeroLevelStr[0] += (*buffer)[j]; } } //1.2 第2个英雄的等级情况 if ((*buffer)[i] == '{' && (*buffer)[i+1] == '"' && (*buffer)[i+2] == 'a' && (*buffer)[i+3] == 'v' && (*buffer)[i+4] == 'a' && (*buffer)[i+13] == '1' && (*buffer)[i+14] == ','){ HeroUnLocked[1] = true; for (int j = i+23;(*buffer)[j] != '}' ; j++) { HeroLevelStr[1] += (*buffer)[j]; } } //1.3 第3个英雄的等级情况 if ((*buffer)[i] == '{' && (*buffer)[i+1] == '"' && (*buffer)[i+2] == 'a' && (*buffer)[i+3] == 'v' && (*buffer)[i+4] == 'a' && (*buffer)[i+13] == '2' && (*buffer)[i+14] == ','){ HeroUnLocked[2] = true; for (int j = i+23;(*buffer)[j] != '}' ; j++) { HeroLevelStr[2] += (*buffer)[j]; } } //1.4 第4个英雄的等级情况 if ((*buffer)[i] == '{' && (*buffer)[i+1] == '"' && (*buffer)[i+2] == 'a' && (*buffer)[i+3] == 'v' && (*buffer)[i+4] == 'a' && (*buffer)[i+13] == '3' && (*buffer)[i+14] == ','){ HeroUnLocked[3] = true; for (int j = i+23;(*buffer)[j] != '}' ; j++) { HeroLevelStr[3] += (*buffer)[j]; } } //1.5 第5个英雄的等级情况 if ((*buffer)[i] == '{' && (*buffer)[i+1] == '"' && (*buffer)[i+2] == 'a' && (*buffer)[i+3] == 'v' && (*buffer)[i+4] == 'a' && (*buffer)[i+13] == '4' && (*buffer)[i+14] == ','){ HeroUnLocked[4] = true; for (int j = i+23;(*buffer)[j] != '}' ; j++) { HeroLevelStr[4] += (*buffer)[j]; } } } for (int i = 0 ; i < 5 ; i++) { HeroLevel[i] = atoi(HeroLevelStr[i].c_str())+1; cout<<HeroLevel[i]<<" "; } cout<<endl; for (int i = 0 ; i < 5 ; i++) { cout<<HeroUnLocked[i]<<" "; } cout<<endl; }
void LogInScene::getUserHistoryGameRequestCompleted(CCNode* sender,void* data){ CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); //1.解析 string boardIdStr,WinTimesStr,LoseTimesStr; for (unsigned int i = 0; i < buffer->size(); i++) { //1.排行榜编号 if ((*buffer)[i] == '"' && (*buffer)[i+1] == 'b' && (*buffer)[i+2] == 'o' && (*buffer)[i+3] == 'a' && (*buffer)[i+4] == 'r') { for (int j = i + 11; (*buffer)[j] != ','; j++) { boardIdStr += (*buffer)[j]; } } //2.历史胜场 else if ((*buffer)[i] == '"' && (*buffer)[i+1] == 'h' && (*buffer)[i+2] == 'i' && (*buffer)[i+3] == 's' && (*buffer)[i+4] == 't' && (*buffer)[i+9] == 'w' && (*buffer)[i+12] == '"') { for (int j = i + 14; (*buffer)[j] != ','; j++) { WinTimesStr += (*buffer)[j]; } } //3.历史败场 else if ((*buffer)[i] == '"' && (*buffer)[i+1] == 'h' && (*buffer)[i+2] == 'i' && (*buffer)[i+3] == 's' && (*buffer)[i+4] == 't' && (*buffer)[i+9] == 'l' && (*buffer)[i+13] == '"') { for (int j = i + 15; (*buffer)[j] != ','; j++) { LoseTimesStr += (*buffer)[j]; } } //4.如果还没玩过这个 if ((*buffer)[i] == '4' && (*buffer)[i+1] == '0' && (*buffer)[i+2] == '4') { boardNotFound = true; break; } } //2.计算rank if (boardNotFound) MainUser->Rank[tmpBoardID] = 0; else{ int _id = atoi(boardIdStr.c_str()); int WinTimes = atoi(WinTimesStr.c_str()); int LoseTimes = atoi(LoseTimesStr.c_str()); MainUser->Rank[tmpBoardID] = MainUser->calculateRank(_id,WinTimes,LoseTimes); cout<<_id<<":胜"<<WinTimes<<" 负"<<LoseTimes<<" Rank为"<<MainUser->Rank[tmpBoardID]<<endl; } //3.继续下一个题的rank if (tmpBoardID < 14) { tmpBoardID++; boardNotFound = false; getUserHistoryGame(tmpBoardID); } else box->closeMessageBox(); }
void InGameScene::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data) { CCHttpResponse *response = (CCHttpResponse*)data; if (!response) { return; } // You can get original request type from: response->request->reqType if (0 != strlen(response->getHttpRequest()->getTag())) { CCLog("%s completed", response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); //m_labelStatusCode->setString(statusString); CCLog("response code: %d", statusCode); if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } // dump data std::vector<char> *buffer = response->getResponseData(); std::string s = ""; bool isDataStarted = false; for (unsigned int i = 0; i < buffer->size(); i++) { if( isDataStarted == false && !isspace((*buffer)[i]) ) isDataStarted = true; if( isDataStarted == false) continue; s += (*buffer)[i]; } CCLog("%s", s.data() ); CCLog("\n"); if( strcmp(response->getHttpRequest()->getTag(), "URL_CREATE_ANIMAL") == 0) { string szAnimalKey = s; CCLog("InGameScene::onHttpRequestCompleted-%s : %s", response->getHttpRequest()->getTag(), szAnimalKey.data() ); } }
void ParseFile::downloadFileFinished(CCNode* sender, void* param) { CCString* savePathName = 0; ParseError* error = new ParseError(); CCHttpResponse* response = (CCHttpResponse*)param; if (response->getResponseCode() == 200) { FILE* file = 0; const char* errorMsg = 0; savePathName = (CCString*)response->getHttpRequest()->getUserData(); std::vector<char>* responseData = response->getResponseData(); do { file = fopen(savePathName->getCString(), "wb"); if (file == 0) { errorMsg = "error open file!"; break; } size_t writeLen = fwrite(&responseData->front(), 1, responseData->size(), file); if (writeLen != responseData->size()) { errorMsg = "error write file!"; break; } }while(0); if (file) { fclose(file); } if (errorMsg) { error->SetError(errorMsg); } } else { if (strlen(response->getErrorBuffer()) > 0) { error->SetError(response->getErrorBuffer()); } else { std::vector<char>* responseData = response->getResponseData(); responseData->push_back('\0'); error->SetError(&responseData->front()); } } this->downloadFileCompleted(savePathName?savePathName->getCString():0, error); savePathName = (CCString*)response->getHttpRequest()->getUserData(); savePathName->release(); delete error; }
void ClientConnect::onHttpRequestRegisterCallBack(cocos2d::CCNode *sender, void *data) { CCHttpResponse *response = (CCHttpResponse*)data; lua_State* ls = CCLuaEngine::defaultEngine()->getLuaStack()->getLuaState(); if (!response->isSucceed())//连接失败 { lua_getglobal(ls, "ConnectErrorBack"); int error = lua_pcall(ls, 0, 0, 0); if(error!=0){ CCLOG("Run Lua Error: %s", lua_tostring(ls, -1)); } return; } std::string bufferStr; std::vector<char> *buffer = response->getResponseData(); for (std::vector<char>::iterator it = buffer->begin(); it != buffer->end(); ++it) { bufferStr.push_back(*it); } Json* jobject=Json_create(bufferStr.c_str()); if ( NULL == jobject ) { CCLog( "[CheckUpdate failed]down version file error." ); } lua_getglobal(ls, "RegisterCallBack"); lua_newtable(ls); lua_pushstring(ls, "isOk"); lua_pushnumber(ls, Json_getInt(jobject,"isOk",0)); lua_settable(ls, -3); lua_pushstring(ls, "accountid"); lua_pushstring(ls, Json_getString(jobject,"accountid","")); lua_settable(ls, -3); lua_pushstring(ls, "account"); lua_pushstring(ls, Json_getString(jobject,"account","")); lua_settable(ls, -3); lua_pushstring(ls, "password"); lua_pushstring(ls, Json_getString(jobject,"password","")); lua_settable(ls, -3); int error = lua_pcall(ls, 1, 0, 0); if(error!=0){ CCLOG("Run Lua Error: %s", lua_tostring(ls, -1)); } }
void S411FeedBack::onPostFinished(CCNode *node,void *data) { AppDelegate::loadingLabel ->setString(""); _menu->setEnabled(true); CCHttpResponse *response = (CCHttpResponse*)data; if (!response) { return; } int s=response->getHttpRequest()->getRequestType(); CCLOG("request type %d",s); if (0 != strlen(response->getHttpRequest()->getTag())) { CCLOG("%s ------>oked", response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); CCLOG("response code: %d", statusCode); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); CCLOG("statusString"); if (!response->isSucceed()) { CCLOG("response failed"); CCLOG("error buffer: %s", response->getErrorBuffer()); AppDelegate::loadingLabel->setString("提交失败"); this->schedule(schedule_selector(S411FeedBack::time),1.0f,false,0.0); return; } //上面这些都是一些判断是否请求成功,下面这个是获得的请求数据 std::vector<char> *buffer = response->getResponseData(); CCLOG("Http Test, dump data: "); for (unsigned int i = 0; i < buffer->size(); i++) { CCLOG("%c", (*buffer)[i]);//这里打印从服务器返回的数据 } CCLOG("\n"); AppDelegate::loadingLabel->setString("提交成功"); this->schedule(schedule_selector(S411FeedBack::time),1.0f,false,0.0); }
void EziSocialObject::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data) { CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { CCLOG("[EziSocial Error]: No Response"); } if (0 != strlen(response->getHttpRequest()->getTag())) { //CCLog("%s completed", response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); if (!response->isSucceed()) { CCLog("[EziSocial Error]: response failed"); CCLog("[EziSocial Error]: error buffer: %s", response->getErrorBuffer()); return; } // Dump the data std::vector<char> *buffer = response->getResponseData(); // Create the CCSprite from data dump... CCImage * img=new CCImage(); img->initWithImageData(&(buffer->front()), buffer->size()); // Save file for resue. std::string writablePath = CCFileUtils::sharedFileUtils()->getWritablePath(); writablePath.append(response->getHttpRequest()->getTag()); img->saveToFile(writablePath.c_str()); delete img; const char* userID = ""; std::string tagString = ""; tagString.append(response->getHttpRequest()->getTag()); std::vector< std::string > strings = EziSocialObject::tokenizeStr(tagString, "_"); userID = strings[0].c_str(); internalUserPhotoCallback(writablePath.c_str(), userID); }
void GameState::onHttpRequestCompleted(CCNode* sender,void *data) { CCHttpResponse *response = (CCHttpResponse*)data; if(!response) return; if( NULL != strlen(response->getHttpRequest()->getTag())) { CCLog("%s complete.",response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); CCLog("response code : %d",statusCode); if(!response->isSucceed()) { CCLog("response failed"); CCLog("errorbuffer: %s",response->getErrorBuffer()); return; } std::vector<char>* buffer = response->getResponseData(); char str[200] = {""}; unsigned int i; for(i=0;i<buffer->size();i++) { str[i] = (*buffer)[i]; } str[i] = '\0'; CCLog("%s",str); }
void LogInScene::LogInRequestCompleted(CCNode* sender,void* data){ CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); if (statusCode == 200) { //1.标记为已经登录 if (!MainUser->hasLogIn) { MainUser->hasLogIn = true; BeginMenuFallDown(); //关闭网络,进入游戏,没有按钮掉下来,再打开网络,重新登录以后,要掉下来 } //2.记录服务器发回的信息 if(!MainUser->initUser(buffer)) MainUser->hasChosenHero = false; else MainUser->hasChosenHero = true; saveLogInInformation(UserNameStr,PassWordStr); //3.初始化rank tmpBoardID = 0; getUserHistoryGame(tmpBoardID); } else{ if(statusCode == 401){ box->closeMessageBox(); box = AsMessageBox::createMessageBox("用户名与密码不匹配", 2, 1); box->setPosition(CCPointZero); addChild(box,100); } else if(statusCode == 404){ box->closeMessageBox(); box = AsMessageBox::createMessageBox("该用户不存在", 2, 1); box->setPosition(CCPointZero); addChild(box,100); } else{ box->closeMessageBox(); box = AsMessageBox::createMessageBox("无法连接,请检查您的网络", 2, 1); box->setPosition(CCPointZero); addChild(box,100); } } }
void ShopItemInfoFromServer::onHttpRequestCompleted(CCNode *node,void *data) { #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID CCHttpResponse *response = (CCHttpResponse*)data; if (!response) { return; } if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } #endif }
// Poll and notify main thread if responses exists in queue void CCHttpClient::dispatchResponseCallbacks(float delta) { // CCLog("CCHttpClient::dispatchResponseCallbacks is running"); CCHttpResponse* response = NULL; pthread_mutex_lock(&s_responseQueueMutex); if (s_responseQueue->count()) { response = dynamic_cast<CCHttpResponse*>(s_responseQueue->objectAtIndex(0)); s_responseQueue->removeObjectAtIndex(0); } pthread_mutex_unlock(&s_responseQueueMutex); if (response) { --s_asyncRequestCount; CCHttpRequest *request = response->getHttpRequest(); CCObject *pTarget = request->getTarget(); SEL_CallFuncND pSelector = request->getSelector(); if (pTarget && pSelector) { (pTarget->*pSelector)((CCNode *)this, response); } if (!request->_jsTarget.IsEmpty() && !request->_jsSelector.IsEmpty()) { response->flushDataToReadBuffer(); response->assignJavaScriptObject(CLS_CCHTTPRESPONSE_ID, false); this->getJSCCallFunc()->callJSFunction(request->_jsTarget, request->_jsSelector, this->getJSObjInstance(), response->getJSObjInstance()); } response->release(); } if (0 == s_asyncRequestCount) { CCDirector::sharedDirector()->getScheduler()->pauseTarget(this); } }
void CLoginScene::urlCallback(CCNode *sender ,void *data) { CSceneManager::sharedSceneManager()->closePopupBox(GETBOX(CLoadingBox)); CCHttpResponse* response = (CCHttpResponse*) data; if (!response) { CSceneManager::sharedSceneManager()->openPopupBox(GETBOX(CMessageBox), (void*)"failure"); return; } int statusCode = response->getResponseCode(); if (response->isSucceed()) { CSceneManager::sharedSceneManager()->openPopupBox(GETBOX(CMessageBox), (void*)"success"); } else { CSceneManager::sharedSceneManager()->openPopupBox(GETBOX(CMessageBox), (void*)"failure"); } }
// Poll and notify main thread if responses exists in queue void CCHttpClient::dispatchResponseCallbacks(float delta) { // CCLog("CCHttpClient::dispatchResponseCallbacks is running"); CCHttpResponse* response = NULL; pthread_mutex_lock(&s_responseQueueMutex); if (s_responseQueue->count()) { response = dynamic_cast<CCHttpResponse*>(s_responseQueue->objectAtIndex(0)); s_responseQueue->removeObjectAtIndex(0); } pthread_mutex_unlock(&s_responseQueueMutex); if (response) { --s_asyncRequestCount; CCHttpRequest *request = response->getHttpRequest(); CCObject *pTarget = request->getTarget(); SEL_CallFuncND pSelector = request->getSelector(); if (pTarget && pSelector) { (pTarget->*pSelector)((CCNode *)this, response); } //lua if( request->getLuaCallback() != 0 ) { ptola::script::CLuaScriptFunctionInvoker::executeHttpResponseCallback(request->getLuaCallback(), response); } response->release(); } if (0 == s_asyncRequestCount) { CCDirector::sharedDirector()->getScheduler()->pauseTarget(this); } }
void RankScene::unlockHeroRequestCompleted(cocos2d::CCNode *sender, void *data){ CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); if (statusCode == 201) { changeGold(-MainUser->HeroUnLockPrice[HeroProcessing]); MainUser->HeroUnLocked[HeroProcessing] = true; UnlockAnimation(HeroProcessing); goldProcessingIndex = 4; updateUserGold(); } else{ MessageBox->closeMessageBox(); MessageBox = AsMessageBox::createMessageBox("与服务器通信失败,\n请检查您的网络", 2, 1); MessageBox->setPosition(CCPointZero); addChild(MessageBox,1000); } }
void ChatLayer::requestFinishedCallback(CCNode* pSender,void *data) { CCHttpResponse *response = (CCHttpResponse*)data; if(response==NULL) { return; } int statusCode = response->getResponseCode(); char statusString[64] = {}; CCLOG(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } std::vector<char> *buffer = response->getResponseData(); std::string content(buffer->begin(),buffer->end()); XMLParser *xmlParser = XMLParser::parseWithString(content.c_str()); CCLOG("%s",xmlParser->getString("content")->getCString()); // parseJson(); }
void RequestTopaz::onHttpRequestCompletedNoEncrypt(CCNode *sender, void *data) { CCHttpResponse* res = (CCHttpResponse*) data; char dumpData[110*110*2]; // 프로필 사진 받아오기 실패 if (!res || !res->isSucceed()) { //CCLog("res failed. error buffer: %s", res->getErrorBuffer()); return; } // dump data std::vector<char> *buffer = res->getResponseData(); for (unsigned int i = 0 ; i < buffer->size() ; i++) dumpData[i] = (*buffer)[i]; dumpData[buffer->size()] = NULL; // make texture2D CCImage* img = new CCImage; img->initWithImageData(dumpData, (int)buffer->size()); CCTexture2D* texture = new CCTexture2D(); texture->initWithImage(img); // set CCSprite (profile 모음 리스트에 갱신) int numOfList = friendList.size(); int index = atoi(res->getHttpRequest()->getTag()); ProfileSprite* psp = ProfileSprite::GetObj(friendList[index]->GetImageUrl()); psp->SetSprite(texture); psp->SetLoadingDone(true); // 화면에 보이는 스프라이트 교체 if (spriteClassScroll == NULL) return; spriteClassScroll->ChangeSprite(-888*(numOfList-index), psp->GetProfile()); ((CCSprite*)spriteClassScroll->FindSpriteByTag(-777*(numOfList-index)))->setOpacity(255); }
void MyHttpRequest::onHttpRequestCompleted(CCNode *sender,void *data) { m_isCompleted=true; CCHttpResponse *response = (CCHttpResponse*)data; if (!response) { return; } int s=response->getHttpRequest()->getRequestType(); CCLog("request type %d",s); if (0 != strlen(response->getHttpRequest()->getTag())) { CCLog("%s ------>oked", response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); CCLog("response code: %d", statusCode); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); CCLog(statusString); if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } std::vector<char> *buffer = response->getResponseData(); printf("Http Test, dump data: "); for (unsigned int i = 0; i < buffer->size(); i++) { //CCLog("%c", (*buffer)[i]);//这里打印从服务器返回的数据 m_responseData.push_back((*buffer)[i]); } CCLog("m_responseData:%s",m_responseData.c_str()); printf("\n"); }
void RankScene::HeroLevelUpRequestCompleted(CCNode* sender,void* data){ CCHttpResponse* response = (CCHttpResponse*)data; if (!response) { return; } int statusCode = response->getResponseCode(); std::vector<char> *buffer = response->getResponseData(); printJson(buffer); if (statusCode == 204) { changeGold(-MainUser->HeroLevelUpGold[MainUser->HeroLevel[roleIndex-1]-1]); MainUser->HeroLevel[roleIndex-1]++; LevelUpAnimation(roleIndex-1); goldProcessingIndex = 4; updateUserGold(); } else{ MessageBox->closeMessageBox(); MessageBox = AsMessageBox::createMessageBox("与服务器通信失败,\n请检查您的网络", 2, 1); MessageBox->setPosition(CCPointZero); addChild(MessageBox,1000); } }
// Poll and notify main thread if responses exists in queue void CCHttpClient::dispatchResponseCallbacks(float delta) { // CCLog("CCHttpClient::dispatchResponseCallbacks is running"); CCHttpResponse* response = NULL; pthread_mutex_lock(&s_responseQueueMutex); if (s_responseQueue->count()) { response = dynamic_cast<CCHttpResponse*>(s_responseQueue->objectAtIndex(0)); s_responseQueue->removeObjectAtIndex(0); } pthread_mutex_unlock(&s_responseQueueMutex); if (response) { --s_asyncRequestCount; CCHttpRequest *request = response->getHttpRequest(); CAObject *pTarget = request->getTarget(); SEL_HttpResponse pSelector = request->getSelector(); if (pTarget && pSelector) { (pTarget->*pSelector)(this, response); } response->release(); } if (0 == s_asyncRequestCount) { CAScheduler::getScheduler()->pauseTarget(this); } }
void MailMainScene::requestFinishedCallback(CCNode* pSender,void *Rspdata) { if (!this->ValidateResponseData(pSender,Rspdata)) { return; } CCHttpResponse *response = (CCHttpResponse*)Rspdata; std::vector<char> *buffer = response->getResponseData(); std::string content(buffer->begin(),buffer->end()); CCLog(content.c_str()); CCDictionary * dictionary = CCJSONConverter::sharedConverter()->dictionaryFrom(content.c_str()); int code = ((CCNumber *)dictionary->objectForKey("code"))->getIntValue(); if (code != 200) { CCMessageBox("invoke web api failed!","ERROR"); return; } std::string requestTag(response->getHttpRequest()->getTag()); if (requestTag == "101") { mFriendList = dynamic_cast<CCArray *>(dictionary->objectForKey("friendList")); if (mFriendList==NULL) { return; } selectedindex = -1; mTableViewFriend->reloadData(); } else if (requestTag == "102"){ this->doSearchFriend(); CCMessageBox("delete friend successfully","Success"); } }
void ParseFile::uploadFileContentFinished(CCNode* sender, void* param) { FileInfo* result = 0; ParseError* error = new ParseError(); CCHttpResponse* response = (CCHttpResponse*)param; if (response->getResponseCode() == 201) { rapidjson::Document retValue; if(ParseJson::FromByteArray(*response->getResponseData(), retValue, error)) { if (retValue.HasMember("url")) { result = new FileInfo(retValue["url"].GetString(), retValue["name"].GetString()); } } if (result == 0) { std::vector<char>* responseData = response->getResponseData(); responseData->push_back('\0'); error->SetError(error->GetError() + "data:" + &responseData->front()); } } else { if (strlen(response->getErrorBuffer()) > 0) { error->SetError(response->getErrorBuffer()); } else { std::vector<char>* responseData = response->getResponseData(); responseData->push_back('\0'); error->SetError(&responseData->front()); } } this->uploadFileContentCompleted(result, error); delete error; }
void HttpClientTest::onHttpRequestCompleted(cocos2d::CCNode *sender, void *data) { CCHttpResponse *response = (CCHttpResponse*)data; if (!response) { return; } // You can get original request type from: response->request->reqType if (0 != strlen(response->getHttpRequest()->getTag())) { CCLog("%s completed", response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); m_labelStatusCode->setString(statusString); CCLog("response code: %d", statusCode); if (!response->isSucceed()) { CCLog("response failed"); CCLog("error buffer: %s", response->getErrorBuffer()); return; } // dump data std::vector<char> *buffer = response->getResponseData(); printf("Http Test, dump data: "); for (unsigned int i = 0; i < buffer->size(); i++) { printf("%c", (*buffer)[i]); } printf("\n"); }
void responseCallback(cocos2d::CCNode *sender, void *data){ CCHttpResponse *response = (CCHttpResponse*)data; if (!response) { CCLog("no response..."); return; } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d", statusCode); CCLOG("response code: %d", statusCode); if (!response->isSucceed()) { CCLOG("response failed"); CCLOG("error buffer: %s", response->getErrorBuffer()); JsonData* msg = new JsonData(); (*msg)["data"] = response->getErrorBuffer(); PROXY_FIRE("error", msg); CC_SAFE_DELETE(msg); return; } // dump data std::vector<char> *buffer = response->getResponseData(); //std::string path = CCFileUtils::sharedFileUtils()->getWriteablePath(); std::string buf(buffer->begin(),buffer->end()); JsonData* msg = new JsonData(); (*msg)["data"] = buf.c_str(); PROXY_FIRE("complete", msg); CC_SAFE_DELETE(msg); };