std::string GameWin::updateFlow() { AppDelegate *app = (AppDelegate*)Application::getInstance(); std::string strLocal=DataAccess::getParamValue("LocalFlow"); if (strLocal.length() > 0) { strLocal = app->base64_xxtea_decode(strLocal);//format:x,x,x,x,x,x, string::size_type pos; string sSub; for (int i = 0; i < 6; i++) { pos = strLocal.find(","); if (pos != string::npos)//found { sSub = strLocal.substr(0, pos); strLocal = strLocal.substr(pos + 1, strLocal.size() - 1); m_iLocal[i] = atoi(sSub.c_str()); } else return "\0";//wrong } m_iLocal[m_iCurrentGameID - 1] += iReward; } else m_iLocal[m_iCurrentGameID - 1] = iReward; char cFlow[20] = "\0"; std::string strFlow = ""; for (int i = 0; i < 6; i++) { if (m_iLocal[i]>0) { sprintf(cFlow, "%d:%d,\0", i + 1, m_iLocal[i]); strFlow += cFlow; } } return strFlow; }
void RegisterView::onHttpRequestCompleted(HttpClient *sender, HttpResponse *response) { std::string title = "\0"; std::string msg = "\0"; if (!response) { title = "Register Error\0"; msg = "Register Error.\0"; ShowMsg(title, msg); return; } // You can get original request type from: response->request->reqType if (0 != strlen(response->getHttpRequest()->getTag())) { log("%s completed", response->getHttpRequest()->getTag()); } int statusCode = response->getResponseCode(); char statusString[64] = {}; sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); log("response code: %d", statusCode); if (!response->isSucceed()) { log("response failed"); log("error buffer: %s", response->getErrorBuffer()); title = "Register Error\0"; msg = "Register Error.\0"; ShowMsg(title, msg); return; } if (statusCode != 200){ log("response code failed"); log("error buffer: %s", response->getErrorBuffer()); title = "Register Error\0"; msg = "Register Error.\0"; ShowMsg(title, msg); return; } // dump data std::vector<char> *buffer = response->getResponseData(); string sXml(buffer->begin(),buffer->end()); pugi::xml_document doc; pugi::char_t cXml[1024]; strcpy(cXml,sXml.c_str()); pugi::xml_parse_result result = doc.load_string(cXml); pugi::xml_node nodes = doc.child("mobileAppRegister"); std::string strError=nodes.child_value("error"); char p[100]; strcpy(p,strError.c_str()); if(atoi(p)==0) { //get user guid string strUserGuid=nodes.child_value("UserGuid"); /*UserDefault::getInstance()->setStringForKey("UserGuid", strUserGuid); UserDefault::getInstance()->setIntegerForKey("remember_me", 1); UserDefault::getInstance()->setStringForKey("tweebaa_username", sUserName); UserDefault::getInstance()->setStringForKey("tweebaa_Password", sPassword); UserDefault::getInstance()->flush();*/ AppDelegate *app = (AppDelegate*)Application::getInstance(); sUserName = app->base64_xxtea_encode(sUserName); sPassword = app->base64_xxtea_encode(sPassword); string strTool = DataAccess::getParamValue("Total_Tool_Num","\0"); int iTool=0; if (strTool.length() > 0) { iTool = atoi(app->base64_xxtea_decode(strTool).c_str()); } DataAccess::addUser(strUserGuid, sUserName, sPassword); _UserInfo userInfo = DataAccess::getUserInfoByName(sUserName); m_UserID = userInfo.nUserID; UserDefault::getInstance()->setIntegerForKey("CurrentUserId", m_UserID); app->UpdateUserScore(1, 50); char sTool[10]; sprintf(sTool, "%d", iTool + 10); strTool = sTool; strTool = app->base64_xxtea_encode(strTool); DataAccess::setParamValue("Total_Tool_Num", strTool); //get it //string s=CCUserDefault::sharedUserDefault()->getStringForKey("UserGuid"); //auto scene = CollageMainTab::createScene(); /*auto scene = ChooseLayer::createScene(); TransitionScene *transition = TransitionFade::create(1, scene); Director::getInstance()->replaceScene(transition);*/ this->cleanup(); m_Refresh = 1; Director::getInstance()->popScene(); } if(atoi(p)==-1){ title = "Input Error\0"; msg = "E-mail or username already exists, please choose another one.\0"; ShowMsg(title, msg); } if (atoi(p) == -2){ title = "Input Error\0"; msg = "Register Failed, please try another e-mail or username.\0"; ShowMsg(title, msg); } }
void CollageScene::LoadResources(void) { if(!updateMutex.try_lock()) return; //updateMutex.lock(); char filenamebuffer[80], sUrl[256],sSQL[512], *err; string fileName; sctPicList fileInfo; int i; //TEMP_filePath = FileUtils::getInstance()->getWritablePath(); pDB = CollageTemplateList::initDB("Collage.db3"); sqlite3_busy_timeout(pDB,1000); ////////////////////////////////loading design////////// std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Design_Total); fileName = TEMP_filePath + "Design_Total.xml"; auto nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+="Download Designes quantity"; updateMutex.unlock(); return; //MessageBox("Can not download Like_list","Server ERROR"); //exit(0); } HttpConnection::numberOfLoadSprites++; auto sNum = CollageTemplateList::GetElementFromXML(fileName.c_str(),"Total"); std::stringstream ss;int nNum; ss<<sNum; ss>>nNum; strcpy(sSQL,"select * from CollageDesigns"); char **re; int r,c; if (sqlite3_get_table(pDB, sSQL, &re, &r, &c, NULL) != SQLITE_OK) { //sqlite3_close(pDB); log("count table[designs] failure."); r=0; } if(nNum!=r) { std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Design_Template_Time); fileName = TEMP_filePath + "Design_Temp_Time.xml"; //ifstream ifc(fileName); //if(!ifc) nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+="Download Designes List"; updateMutex.unlock(); return; //MessageBox("Can not download Like_list","Server ERROR"); //exit(0); } HttpConnection::numberOfLoadSprites++; //loading image from template pCTL=CollageTemplateList::ParseXMLWithfile(fileName.c_str()); if(!pCTL) { //log("%s file format error",fileName.c_str()); sprintf(filenamebuffer,"%s file format error",fileName.c_str()); nErrorFlag=99; sErrorMsg=filenamebuffer; updateMutex.unlock(); return; } strcpy(sSQL,"delete from CollageDesigns"); if (sqlite3_exec(pDB,sSQL,NULL,NULL,&err) != SQLITE_OK) { //sqlite3_close(pDB); log("truncate table[designs] failure."); } for(auto vT: pCTL->vTemplate ) { auto lt = time(NULL); auto cdate = ctime(<); sprintf(sSQL,"insert into CollageDesigns (id,cdate,image,title,inspiration,user,like_count,personal_flag,share_count) values ('%s','%s','%s','%s','%s','%s','%s','0','%s')" ,vT.uid,cdate,vT.strListImage,vT.sTitle,vT.sFourthEle,vT.sFifthEle,vT.sSixthEle,vT.sEighthEle); //log("insert design %s ",sSQL); if (sqlite3_exec(pDB,sSQL,NULL,NULL,&err) != SQLITE_OK) { //sqlite3_close(pDB); log("%s to table[designs] failure:%s",sSQL,err); } } CC_SAFE_DELETE(pCTL); } else { Number_Resources--; } sqlite3_free_table(re); sqlite3_close(pDB); pCTL = CollageTemplateList::LoadXMLFromDB("Collage.db3","CollageDesigns","share_count"); //set v_design_time_info by order of share_count if(!pCTL) { sprintf(filenamebuffer,"load XML from table[designs] failure."); nErrorFlag=99; sErrorMsg=filenamebuffer; updateMutex.unlock(); return; } Number_Resources+=pCTL->vTemplate.size()>MAX_CacheFile?MAX_CacheFile:pCTL->vTemplate.size(); i=0; for(auto vT: pCTL->vTemplate ) { i++; if(i>=MAX_CacheFile+1) break; //装载的缓冲文件个数 if(!strcmp(vT.strListImage,"None")) { i--; continue; } sprintf(filenamebuffer,"$D_%s",strrchr(vT.strListImage,'/')+1); fileInfo.cache_filename= TEMP_filePath+Cache_Path +filenamebuffer; sprintf(fileInfo.uid,"D_%s",vT.uid); fileInfo._filename=vT.strListImage; fileInfo._objecttitle=vT.sTitle; fileInfo._object4th=vT.sFourthEle; //inspiration fileInfo._object5th=vT.sFifthEle; //username fileInfo._object6th=vT.sSixthEle; //city fileInfo._object7th=vT.sSeventhEle; //country fileInfo._object8th=vT.sEighthEle; //sharecount fileInfo._Cat = kPTypeNone; fileInfo.id=vT.id; HttpConnection::v_design_time_info.push_back(fileInfo); //save info for BrowseLayer //判断文件是否存在 ifstream ifs(fileInfo.cache_filename); if(!ifs) { std::strcpy(sUrl,Design_URL); std::strcat(sUrl,vT.strListImage); http_connect->HttpReqToCache(sUrl,vT.strListImage,fileInfo.cache_filename.c_str()); } else { HttpConnection::numberOfLoadSprites++; } } CC_SAFE_DELETE(pCTL); ////////////////////////////////loading published design////////// std::strcpy(sUrl,Req_URL); fileName = TEMP_filePath + "Design_Like.xml"; //G_UNM = UserDefault::getInstance()->getStringForKey("tweebaa_username"); AppDelegate *app = dynamic_cast<AppDelegate*>(Application::getInstance()); _UserInfo userInfo = DataAccess::getUserInfoByID(m_UserID); G_UID = userInfo.strUserGuid; G_UNM = app->base64_xxtea_decode(userInfo.strUserName); //G_UNM = "dragon2934"; //G_UID = "eff4dca6-fedc-4bd9-bbe5-79dec2bb39d8"; if(G_UID.empty()) { //HttpConnection::numberOfLoadSprites++; HttpConnection::v_design_like_info.clear(); std::remove(fileName.c_str()); } else { //Number_Resources--; //re-caculate with init number temporarily pCTL = CollageTemplateList::LoadXMLFromDB("Collage.db3","CollageDesigns","user",G_UNM.c_str()); if(pCTL) { Number_Resources+=pCTL->vTemplate.size()>MAX_CacheFile?MAX_CacheFile:pCTL->vTemplate.size(); i=0; for(auto vT: pCTL->vTemplate ) { i++; if(i==MAX_CacheFile+1) break; //装载的缓冲文件个数 if(!strcmp(vT.strListImage,"None")) { i--; continue; } sprintf(filenamebuffer,"$D_%s",strrchr(vT.strListImage,'/')+1); fileInfo.cache_filename= TEMP_filePath+Cache_Path +filenamebuffer; sprintf(fileInfo.uid,"D_%s",vT.uid); fileInfo._filename=vT.strListImage; fileInfo._objecttitle=vT.sTitle; fileInfo._object4th=vT.sFourthEle; //inspiration fileInfo._object5th=vT.sFifthEle; //username fileInfo._object6th=vT.sSixthEle; //city fileInfo._object7th=vT.sSeventhEle; //country fileInfo._object8th=vT.sEighthEle; //sharecount fileInfo._Cat = kPTypeNone; fileInfo.id=vT.id; HttpConnection::v_design_like_info.push_back(fileInfo); //save info for FavoritLayer //判断文件是否存在 ifstream ifs(fileInfo.cache_filename); if(!ifs) { std::strcpy(sUrl,Design_URL); std::strcat(sUrl,vT.strListImage); http_connect->HttpReqToCache(sUrl,vT.strListImage,fileInfo.cache_filename.c_str()); } else { HttpConnection::numberOfLoadSprites++; } } } else { HttpConnection::v_design_like_info.clear(); std::remove(fileName.c_str()); } CC_SAFE_DELETE(pCTL); } ////////////////////////////////loading Background_List////////// std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Background_List); fileName = TEMP_filePath + "Background_List.xml"; nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+="Download Background List"; updateMutex.unlock(); return; } HttpConnection::numberOfLoadSprites++; ////////////////////////////////loading Event_List////////// std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Event_List); fileName = TEMP_filePath + "Event_List.xml"; nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+="Download Event List"; updateMutex.unlock(); return; } HttpConnection::numberOfLoadSprites++; ////////////////////////////////loading decoration////////// std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Decoration_List); fileName = TEMP_filePath + "Decoration_List.xml"; nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+="Download Decoration List"; updateMutex.unlock(); return; //MessageBox("Can not download Like_list","Server ERROR"); //exit(0); } HttpConnection::numberOfLoadSprites++; ////////////////////////////////loading articles////////// std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Article_List); fileName = TEMP_filePath + "Articles_List.xml"; nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+="Download Articles List"; updateMutex.unlock(); return; //MessageBox("Can not download Like_list","Server ERROR"); //exit(0); } HttpConnection::numberOfLoadSprites++; ////////////////////////////////loading product xml////////// //log("file:%s ID:%s",HttpConnection::MainCatList[1][0].c_str(),HttpConnection::MainCatList[1][1].c_str()); for(i=0;i<Main_Categories;i++) { fileName = TEMP_filePath + HttpConnection::MainCatList[i][0] + ".xml"; std::strcpy(sUrl,Req_URL); std::strcat(sUrl,Product_List); std::strcat(sUrl,HttpConnection::MainCatList[i][1].c_str()); nReturn = http_connect->CurlReq(sUrl,fileName.c_str()); if(nReturn!=CURLE_OK) { log("get (%s) file from %s error",fileName.c_str(),sUrl); nErrorFlag=nReturn; sErrorMsg=MSG_ERROR_NETWORK; sErrorMsg+=HttpConnection::MainCatList[i][0]; updateMutex.unlock(); return; //MessageBox("Can not download Like_list","Server ERROR"); //exit(0); } HttpConnection::numberOfLoadSprites++; } updateMutex.unlock(); HttpConnection::bTutorialFlag=false; return; }