Beispiel #1
0
void GuoZhanLayer::_onBtnSelected(int idx) {
    unsigned int cityId = 0;
    switch (idx) {
        case 1:
        {
            cityId = 1;
            m_pBattle->setSelectCity(1);
        }
            break;
        case 2:
        {
            cityId = 2;
            m_pBattle->setSelectCity(2);
        }
            break;
        case 3:
        {
            cityId = 3;
            m_pBattle->setSelectCity(3);
        }
            break;
        default:
            break;
    }
    
    if (cityId > 0) {
        NetConnection* pNetConnection = NetConnection::getInstance();
        char szPostBuffer[MAX_POSTTO_SERVER_BUFFER_SIZE];
        memset(szPostBuffer, '\0', MAX_POSTTO_SERVER_BUFFER_SIZE);
        
        sprintf(szPostBuffer, "c=cwar&a=city&city=%d&uid=%s", cityId,
                GamePlayer::getInstance()->getUid().c_str());
        char szHttpTag[] = HTTP_REQUEST_ENTERCITY_TAG;
        CCLog("post 进入城池 = %s", szPostBuffer);
        pNetConnection->commitPostRequestData(szPostBuffer, szHttpTag);
    }
}
Beispiel #2
0
void LoginLayer::gameInit() {
    NetConnection* pNetConnection = NetConnection::getInstance();
    char szPostBuffer[MAX_POSTTO_SERVER_BUFFER_SIZE];
    memset(szPostBuffer, '\0', MAX_POSTTO_SERVER_BUFFER_SIZE);
    strcpy(szPostBuffer, "c=index&a=index&uid=");
    
    LoginBox* l = (LoginBox*)this->getChildByTag(LOGIN_ID_TAG);
    if (l->getContent() == "") {
        strcat(szPostBuffer, "1");
    } else {
        strcat(szPostBuffer, l->getContent().c_str());
        
        CCUserDefault::sharedUserDefault()->setStringForKey(USER_NAME_KEY, l->getContent().c_str());
        CCUserDefault::sharedUserDefault()->flush();
    }
    
    CCUserDefault::sharedUserDefault()->setIntegerForKey(LOGIN_SERVER_KEY, m_pGameState->getServerId());
    CCUserDefault::sharedUserDefault()->flush();
    
    char szTag[] = HTTP_REQUEST_LOGIN_TAG;
    pNetConnection->commitPostRequestData(szPostBuffer, szTag);
    
    CCNotificationCenter::sharedNotificationCenter()->postNotification(ON_MESSAGE_LOADING_NOW);
}
Beispiel #3
0
/*
 * 处理 web 服务器响应 get 请求回应数据
 */
void LoginLayer::handleWSResponseData(const char *szData, const unsigned int dataSize, char* szTag) {
    CCAssert(szData && dataSize > 0 && szTag, "invalid data");
    
    bool isSuccess = false;
    if (!strcmp(szTag, HTTP_REQUEST_LOGIN_TAG)) /*登录请求*/ {
        isSuccess = ProcessData::processLoginResponseFromServer(szData, dataSize);
        if (isSuccess) {
            // 登陆成功,请求玩家武将信息
            NetConnection* pNetConnection = NetConnection::getInstance();
            
            char szPostBuffer[MAX_POSTTO_SERVER_BUFFER_SIZE];
            memset(szPostBuffer, '\0', MAX_POSTTO_SERVER_BUFFER_SIZE);
            
            sprintf(szPostBuffer, "c=hero&a=hero_list&uid=%s", GamePlayer::getInstance()->getUid().c_str());
            char szTag[] = HTTP_REQUEST_GETHERO_TAG;
            pNetConnection->commitPostRequestData(szPostBuffer, szTag);
        }
    } else if (!strcmp(szTag, HTTP_REQUEST_GETHERO_TAG)) /*武将数据*/ {
        NetConnection* pNetConnection = NetConnection::getInstance();
        do {
            CC_BREAK_IF(!ProcessData::processHerosDataFromServer(szData, dataSize));
            // 还有 “未决” 请求
            CC_BREAK_IF(pNetConnection->isPending());
            
            // 武将管理
            HeroManager* pHeroManager = HeroManager::getInstance();
            // 恢复战队位置
            pHeroManager->restoreBattleTeamPosIndex();
            
            if (m_pGameState->hasEndlessFight()) /* 有未完成战斗 */ {
                Battle* pBattle = Battle::getInstance();
                
                // 恢复副本id
                m_pGameState->setCopyId(m_pGameState->getEndlessFightCopyId());
                // 恢复关卡id
                m_pGameState->setLevId(m_pGameState->getEndlessFightLevelId());
                // 恢复战斗波数
                pBattle->setRoundIndex(m_pGameState->getEndlessFightRoundIndex() - 1);
                
                // 往战场添加本方上阵武将
                unsigned int countOfGotoBattleHeros = pHeroManager->getGoIntoBattleHerosOfPlayerCount();
                for (unsigned int index = 0; index < countOfGotoBattleHeros; index++) {
                    HeroOfPlayerItem* pGotoBattleHeroItem = pHeroManager->getGoIntoBattleHeroDataByIndex(index);
                    CCAssert(pGotoBattleHeroItem, "invalid data");
                    unsigned int posIndexInBattle = m_pGameState->getUfTeamPos(pGotoBattleHeroItem->getUniId());
                    CCAssert(posIndexInBattle > 0, "invalid posIndexInBattle");
                    pGotoBattleHeroItem->setPosInBattle(posIndexInBattle);
                    pBattle->appendInBattleHero(pGotoBattleHeroItem);
                } /*for*/
                pHeroManager->saveBattleTeamPosIndex();
                
                // 提交战斗请求
                pBattle->commitPveFightRequest();
            } else {
                pNetConnection->setHandleNetDataDelegate(NULL);
                /* 设置login调用了主场景 */
                m_pGameState->setTagWhoCallMainScene(1);
                CCDirector::sharedDirector()->replaceScene(MainScene::create());
                CCNotificationCenter::sharedNotificationCenter()->postNotification(ON_MESSAGE_SHUTDOWN_LOADING);
            }
        } while (0);
    } else if (!strcmp(szTag, HTTP_REQUEST_FIGHT_PVE_TAG)) /*战斗请求*/{
        NetConnection* pNetConnection = NetConnection::getInstance();
        bool isSuccess = ProcessData::parseBufferFromSvr(szData, dataSize, szTag);
        if (isSuccess) {
            pNetConnection->setHandleNetDataDelegate(NULL);
            CCDirector::sharedDirector()->replaceScene(BattleScene::create());
        }
    }
}