void
MCBackpack::saveData()
{
    CCUserDefault *userDefault = CCUserDefault::sharedUserDefault();
    
    saveEffectiveItems();
    
    JsonBox::Object backpack;
    
    /* 储存金钱 */
    backpack[kMCMoneyKey] = JsonBox::Value(money_);
    
    JsonBox::Value backpackValue(backpack);
    ostringstream outputStream;
    backpackValue.writeToStream(outputStream);
    string data = outputStream.str();
#if MC_DEBUG_SAVEDATA == 1
    const char *output = data.c_str();
#else
    const char *input = data.c_str();
    char  *output;
    mc_size_t len = strlen(input);
    MCBase64Encode((mc_byte_t *) input, len, (mc_byte_t **) &output);
#endif
    userDefault->setStringForKey(kMCBackpackKey, output);
#if MC_DEBUG_SAVEDATA != 1
    delete []output;
#endif
}
/**
 * 清除数据
 */
void
MCTaskAccessor::erase()
{
    CCUserDefault *userDefault = CCUserDefault::sharedUserDefault();
    
    userDefault->setStringForKey(kMCTasksKey, "");
}
Esempio n. 3
0
void LoginLayer::onClickedLogin(CCObject *sender, TouchEventType event)
{
    if (event == TOUCH_EVENT_ENDED)
    {
        SimpleAudioEngine::sharedEngine()->playEffect(BUTTON_CLICK);
        
        _msg->setText("");
        LoginMeg tmpMeg;
        tmpMeg.name = _account->getText();
        tmpMeg.pwd = _password->getText();
        
        if (tmpMeg.name.empty())
        {
            _msg->setText("请输入联众账号!");
            return;
        }
        
        if (tmpMeg.pwd.empty())
        {
            _msg->setText("请输入账号密码!");
            return;
        }
        
        CCUserDefault* userDefault = CCUserDefault::sharedUserDefault();
        userDefault->setStringForKey(SAVE_H_ACCOUNT, tmpMeg.name);
        userDefault->setStringForKey(SAVE_H_PASSWORD, tmpMeg.pwd);
        userDefault->flush();
        
        CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_LOGIN2MEG, &tmpMeg);
    }
}
KDvoid Ch3_SavingSimpleData::saveDifficulty ( KDvoid )
{
	// Save our difficulty
	CCUserDefault*		pDefaults = CCUserDefault::sharedUserDefault ( );

	pDefaults->setStringForKey ( "simple_data_difficulty", m_sDifficulty.c_str ( ) );
	pDefaults->flush ( );
}
void CCNative::initStore(CCDictionary* dict)
{
	CCArray* keys = dict->allKeys();
	CCObject* key;
	CCUserDefault* userDefault = CCUserDefault::sharedUserDefault();
	CCARRAY_FOREACH(keys, key)
	{
		const char* keyStr = ((CCString*)key)->getCString();
		userDefault->setStringForKey(keyStr, dict->valueForKey(keyStr)->getCString());
	}
}
Esempio n. 6
0
void LocalData::writeRuntimeDataToLocal()
{
	CCUserDefault* userDefault = CCUserDefault::sharedUserDefault();
	userDefault->setBoolForKey("hasmusic", RunTimeData::getInstance()->hasMusic);
	userDefault->setBoolForKey("guiderecord", RunTimeData::getInstance()->isFirstTime);
	userDefault->setStringForKey("levelStarStr", RunTimeData::getInstance()->levelStars);
	userDefault->setIntegerForKey("passedLevelNum", RunTimeData::getInstance()->passedLevel);
	userDefault->setIntegerForKey("totalStarNum", RunTimeData::getInstance()->startNum);
	userDefault->setIntegerForKey("annihilator", RunTimeData::getInstance()->annihilatorNum);
	userDefault->setBoolForKey("isFirstTime", RunTimeData::getInstance()->isFirstTime);
	userDefault->flush();
}
Esempio n. 7
0
void Config::flush() {
	CCUserDefault* ud = CCUserDefault::sharedUserDefault();
	ud->setBoolForKey(CONFIG_KEY_MUTE, m_mute);
	ud->setBoolForKey(CONFIG_KEY_HASSAVEDPUZZLE, m_hasSavedPuzzle);
	ud->setIntegerForKey(CONFIG_KEY_HIGHSCORE, m_highScore);
	ud->setIntegerForKey(CONFIG_KEY_HIGHLEVEL, m_highLevel);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDSCORE, m_savedScore);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDTARGET, m_savedTarget);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDLEVEL, m_savedLevel);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDROW, m_savedRow);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDCOL, m_savedCol);
	ud->setStringForKey(CONFIG_KEY_SAVEDPUZZLE, m_savedPuzzle);
	ud->flush();
}
void
MCBackpack::saveEffectiveItems()
{
    CCUserDefault *userDefault = CCUserDefault::sharedUserDefault();
    JsonBox::Array effectiveItems;
    
    /* 道具 */
    effectiveItems.push_back(JsonBox::Value((int) healthPotion_->count));
    effectiveItems.push_back(JsonBox::Value((int) physicalPotion_->count));
    effectiveItems.push_back(JsonBox::Value((int) fireballTrapWide_->count));
    effectiveItems.push_back(JsonBox::Value((int) fireballTrapDamage_->count));
    effectiveItems.push_back(JsonBox::Value((int) curseTrapWide_->count));
    effectiveItems.push_back(JsonBox::Value((int) curseTrapDamage_->count));
    effectiveItems.push_back(JsonBox::Value((int) paralysisTrapWide_->count));
    effectiveItems.push_back(JsonBox::Value((int) paralysisTrapDamage_->count));
    effectiveItems.push_back(JsonBox::Value((int) fogTrapWide_->count));
    effectiveItems.push_back(JsonBox::Value((int) fogTrapDamage_->count));
    effectiveItems.push_back(JsonBox::Value((int) flashTrapWide_->count));
    effectiveItems.push_back(JsonBox::Value((int) flashTrapDamage_->count));
    JsonBox::Value effectiveItemsValue(effectiveItems);
    ostringstream outputStream;
    effectiveItemsValue.writeToStream(outputStream);
    string data = outputStream.str();
#if MC_DEBUG_SAVEDATA == 1
    const char *output = data.c_str();
#else
    const char *input = data.c_str();
    char  *output;
    mc_size_t len = strlen(input);
    MCBase64Encode((mc_byte_t *) input, len, (mc_byte_t **) &output);
#endif
    userDefault->setStringForKey(kMCEffectiveItemsKey, output);
#if MC_DEBUG_SAVEDATA != 1
    delete []output;
#endif
}
Esempio n. 9
0
void Logic::storeData() {
    CCUserDefault *u = CCUserDefault::sharedUserDefault();
    u->setStringForKey("loginName", loginName);
    u->setStringForKey("nickname", nickname);
    u->setIntegerForKey("uid", uid);
}
Esempio n. 10
0
void SGWelComeLayer::requestFinished(int msgid, CCObject *data)
{
    CCLOG("收到数据");
    switch (msgid)
    {
        case MSG_HTTP_FAST_LOGIN:
        {
            std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
            short serverpost = (short)CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
            
            //记录服务器ip和端口号
            SGMainManager::shareMain()->setServerInfo(CCString::create(serverip.c_str()) , serverpost);
            
            //连接socket
            SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() , serverpost);
            
        }
            break;
        case MSG_HTTP_LOGIN:
        {
            int isLogin = SGMainManager::shareMain()->getIsFBLogin();
            if (isLogin != 1 || !SGMainManager::shareMain()->getIsFbAutologin())
            {
                std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
                int serverpost = CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
                SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() ,(short)serverpost);
            }
            else
            {
                SGMainManager::shareMain()->setIsFbAutologin(false);
            }
        }
            break;
        case MSg_HTTP_SERVERLIST:
        {
            SGServerListLayer *box = SGServerListLayer::create(this, (CCArray *)data, SGServerListLayerComeFromFirst);
            SGMainManager::shareMain()->showBox(box,false);

            
        }
            break;
        case MSG_HTTP_UPDATE_SERVER_STATE:
        {
            CCDictionary *dict = (CCDictionary*)data;
            CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
            CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
            CCString *serverId = (CCString*)dict->objectForKey("serverId");
            CCString *serverShowId = (CCString*)dict->objectForKey("serverShowId");
            CCString* serverName = (CCString*)dict->objectForKey("serverName");
            //保存即将登陆的服务器的描述
            serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
            //save ip and post of server
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverShowId", serverShowId->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            CCUserDefault::sharedUserDefault()->flush();
            
            
            CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
            
            changeServerbtn->setFont(serverName->getCString());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            
            //如果是维护中 则不再登陆。
            short serverState = (short)(  ( (CCString *)dict->objectForKey("serverState") )->intValue() );
            if (1 != serverState)
            {
                ;
            }
            //提示不能登陆的详细信息。
            else
            {
                SGMainManager::shareMain()->showMessage(serverDes.c_str());
            }
            //MM: 即使维护中,也尝试登录,101用户会自动放过。
            this->realLogin();
        }
            break;

        case MSg_HTTP_LASTESTSERVER:
        {
            CCDictionary *dict = (CCDictionary*)data;
            CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
            CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
            CCString *serverId = (CCString*)dict->objectForKey("serverId");
            CCString* serverName = (CCString*)dict->objectForKey("serverName");
            //保存即将登陆的服务器的描述
            serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
            //save ip and post of server
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            CCUserDefault::sharedUserDefault()->flush();
            
            
            CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
            
            changeServerbtn->setFont(serverName->getCString());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            
        }
            break;
        case MSG_HTTP_GET_CHANNEL_USER_ID:
        {
            CCDictionary* dict = (CCDictionary*) data;
            CCUserDefault* ccud = CCUserDefault::sharedUserDefault();
            CCString* actId = (CCString*) dict->objectForKey("sdkAccountId");
            ccud->setStringForKey("userId", actId->m_sString);
            ccud->setStringForKey("username", actId->m_sString);
            ccud->setStringForKey("password", actId->m_sString);
            ccud->setIntegerForKey("channelId", GlobalConfig::gi()->getRealChannelId());
#if (GCCT_CHINA_UC_ADR_THIRD == GAME_CHANNEL_TYPE) //uc adr
            //MM: 将本次s_sid作为loginkey,登入使用。
            ccud->setStringForKey("loginKey", UCSdk::s_sid);
#elif (GCCT_CHINA_KUAIYONG_IOS_THIRD == GAME_CHANNEL_TYPE)
            //MM: 将快用的tokenKey作为loginkey,登入使用。
            ccud->setStringForKey("loginKey", ( (KuaiYongIosImp*) SdkController::gi()->getSdkImp() )->kyToken );
#else
            
#endif
            CCString* nickName = (CCString*) dict->objectForKey("sdkNickName");
            ccud->setStringForKey("sdk_user_nick_name", nickName->m_sString);
            //还有一个"sdkCreator"字段,但是未起作用,所以没有在这里添加。
            registerBtn->setFont(nickName->getCString()); //将按钮文本变为其uc账号昵称。

            ccud->setBoolForKey("isExist", true);
            ccud->setBoolForKey("isAccount", true);
            ccud->flush();
            //MMD: SDKIF SDK登陆成功!仅当21号http消息完成后,才设置SDK登陆成功标志,其他情况一概无视。
            ExtClassOfSDK::sharedSDKInstance()->setIsLoginSDK(true);
            //添加的针对非注册体系下的td数据设置,目前有uc在使用。
            ExtClassOfSDK::sharedSDKInstance()->setTdData(actId->m_sString, nickName->m_sString);
        }
            break;
        default:
            break;
    }
    SGMainManager::shareMain()->getMainScene()->plat->removeConnection();
}