Beispiel #1
0
function DoInit($inittype = '')
{
    $T = time(true);
    $res = 0;
    Hook('before_load_farm');
    $_SESSION['sequence'] = 0;
    // Create Init request
    $amf = CreateRequestAMF('', 'UserService.initUser');
    $amf->_bodys[0]->_value[1][0]['params'][0] = "";
    $amf->_bodys[0]->_value[1][0]['params'][1] = -1;
    $amf->_bodys[0]->_value[1][0]['params'][2] = true;
    $serializer = new AMFSerializer();
    $result = $serializer->serialize($amf);
    // serialize the data
    $answer = Request('', $result);
    $amf2 = new AMFObject($answer);
    $deserializer2 = new AMFDeserializer($amf2->rawData);
    // deserialize the data
    $deserializer2->deserialize($amf2);
    // run the deserializer
    $res = CheckAMF2Response($amf2);
    if ($res == 'OK') {
        // get flashSessionKey
        //$_SESSION['sequence'] = 1;
        //file_put_contents('all.txt', print_r($amf2,true));
        if (isset($amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['session_key'])) {
            $_SESSION['flashSessionKey'] = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['session_key'];
        }
        $_SESSION['servertime'] = $amf2->_bodys[0]->_value['data'][0]['serverTime'];
        // save to file $flashSessionKey, $xp, $energy
        $xp = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['xp'];
        $energy = $amf2->_bodys[0]->_value['data'][0]['data']['energy'];
        $hlXP = Units_GetFarming('higherLevelXp');
        $hlBegin = Units_GetFarming('higherLevelBegin');
        $hlStep = Units_GetFarming('higherLevelStep');
        // get extra info
        $level = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['level'];
        if (isset($hlXP) && $xp >= $hlXP) {
            $level = @$hlBegin + floor(($xp - @$hlXP) / @$hlStep);
        }
        $gold = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['gold'];
        $cash = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['cash'];
        $sizeX = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['world']['sizeX'];
        $sizeY = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['world']['sizeY'];
        $firstname = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['attr']['name'];
        $locale = $amf2->_bodys[0]->_value['data'][0]['data']['locale'];
        $tileset = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['world']['tileSet'];
        $wither = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['witherOn'];
        // save to file $level, $coins, $cash, $sizex, $sizey
        $uSQL = 'INSERT OR REPLACE INTO datastore(userid, storetype, content) values("' . $_SESSION['userId'] . '",
									"playerinfo", "' . implode(';', array($level, $gold, $cash, $sizeX, $sizeY, $firstname, $locale, $tileset, $wither, $xp, $energy, $_SESSION['flashRevision'])) . '");';
        // save world to file
        save_botarray($amf2->_bodys[0]->_value, F('world.txt'));
        //file_put_contents('world.txt', print_r($amf2->_bodys[0]->_value,true));
        // get objects on farm
        $objects = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['world']['objectsArray'];
        //file_put_contents('world.txt', print_r($objects, true));
        // FarmFIX/object split
        $newobjects = serialize($objects);
        $cleanedobjects = str_replace("'", "''", $newobjects);
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t\t'objects', '" . $cleanedobjects . "');";
        // save collection counters to a file
        $nAQ = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['neighborActionQueue']['m_actionQueue'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'nactionqueue', '" . serialize($nAQ) . "');";
        $nAL = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['neighborActionLimits']['m_neighborActionLimits'][date('ymd', $_SESSION['servertime'])];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'nactionlimit', '" . serialize($nAL) . "');";
        $c_count = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['collectionCounters'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'ccount', '" . serialize($c_count) . "');";
        $c_bushel = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['buffs']['BBushel']['crop'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'cbushel', '" . serialize($c_bushel) . "');";
        $c_busheltime = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['buffs']['BBushel']['time'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'cbusheltime', '" . serialize($c_busheltime) . "');";
        $craftstate = @$amf2->_bodys[0]->_value['data'][0]['data']['craftingState'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'craftstate', '" . serialize($craftstate) . "');";
        // save lonelyanimals to a file
        $animallinks = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['lonelyAnimals'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'ralinks', '" . serialize($animallinks) . "');";
        // save license information
        $licenses = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['licenseManager']['licenses'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'licenses', '" . serialize($licenses) . "');";
        $storagedata = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['storageData'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'storagedata', '" . serialize($storagedata) . "');";
        $incraftbox = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['storageData']['-7'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'craftbox', '" . serialize($incraftbox) . "');";
        // save giftbox info for plugins
        $ingiftbox = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['storageData']['-1'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'giftbox', '" . serialize($ingiftbox) . "');";
        foreach ($ingiftbox as $key => $item) {
            $ingiftbox[$key] = isset($item[0]) ? $item[0] : 0;
        }
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'ingiftbox', '" . serialize($ingiftbox) . "');";
        // save consumable info for plugins
        $inconbox = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['storageData']['-6'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'consumebox', '" . serialize($inconbox) . "');";
        foreach ($inconbox as $key => $item) {
            $uInfo = Units_GetUnitByCode($key);
            if (@$uInfo['className'] == 'CSeedPackage') {
                $inseedbox[$key] = isset($item[0]) ? $item[0] : 0;
                unset($inconbox[$key]);
                continue;
            }
            $inconbox[$key] = isset($item[0]) ? $item[0] : 0;
        }
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'inconbox', '" . serialize($inconbox) . "');";
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'inseedbox', '" . serialize($inseedbox) . "');";
        // save storage info for plugins
        $instorage = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['storageData']['-2'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'storagebox', '" . serialize($instorage) . "');";
        foreach ($instorage as $key => $item) {
            $instorage[$key] = $item[0];
        }
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'instorage', '" . serialize($instorage) . "');";
        // save neighbors list
        $neighbors = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['neighbors'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'neighbors', '" . serialize($neighbors) . "');";
        $bsStats = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['breedingState'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'bsstats', '" . serialize($bsStats) . "');";
        $pneighbors = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['pendingNeighbors'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'pneighbors', '" . serialize($pneighbors) . "');";
        // save crop mastery list
        $cropmastery = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['masteryCounters'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'cropmastery', '" . serialize($cropmastery) . "');";
        $cropmasterycnt = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['mastery'];
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'cropmasterycnt', '" . serialize($cropmasterycnt) . "');";
        if (isset($amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['featureCredits']['farm'])) {
            $featurecred = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['featureCredits']['farm'];
        } else {
            $featurecred = $amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['featureCredits'];
        }
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'featurecred', '" . serialize($featurecred) . "');";
        // save ribbon data
        $achievements = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['achCounters'];
        $earned_ribbons = @$amf2->_bodys[0]->_value['data'][0]['data']['userInfo']['player']['achievements'];
        $ribbon_merge = array();
        foreach ($achievements as $name => $data) {
            $ribbon_merge[$name]['count'] = $data;
        }
        if (@count($earned_ribbons) > 0) {
            foreach ($earned_ribbons as $name => $data) {
                $ribbon_merge[$name]['earned'] = $data;
            }
        }
        $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'ach_count', '" . serialize($ribbon_merge) . "');";
        $_SESSION['vDataStoreDB']->exec($uSQL);
        unset($uSQL, $amf2);
        // save_botarray ($array, $filename);
    }
    if ($inittype == 'full') {
        $amf = CreateRequestAMF('', 'UserService.postInit');
        $serializer = new AMFSerializer();
        $result = $serializer->serialize($amf);
        // serialize the data
        $answer = Request('', $result);
        $amf2 = new AMFObject($answer);
        $deserializer2 = new AMFDeserializer($amf2->rawData);
        // deserialize the data
        $deserializer2->deserialize($amf2);
        // run the deserializer
        $res2 = CheckAMF2Response($amf2);
        if ($res2 == 'OK') {
            file_put_contents('world2.txt', print_r($amf2->_bodys[0]->_value, true));
            $availBushels = @$amf2->_bodys[0]->_value['data'][0]['data']['marketView']['marketStalls'];
            $availGoods = @$amf2->_bodys[0]->_value['data'][0]['data']['marketView']['craftedGoods'];
            $bsInfo = @$amf2->_bodys[0]->_value['data'][0]['data']['breedingState'];
            $uSQL = "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'availbushels', '" . serialize($availBushels) . "');";
            $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'availgoods', '" . serialize($availGoods) . "');";
            $uSQL .= "INSERT OR REPLACE INTO datastore(userid, storetype, content) values('" . $_SESSION['userId'] . "',\n\t\t\t\t'bsinfo', '" . serialize($bsInfo) . "');";
            $_SESSION['vDataStoreDB']->exec($uSQL);
            unset($uSQL, $amf2);
        }
        Hook('after_load_farm');
        $res = $res == 'OK' && $res2 == 'OK' ? 'OK' : 'Init: ' . $res . ' - PostInit: ' . $res2;
    }
    $T2 = time();
    $T2 -= $T;
    if ($res == 'OK') {
        AddLog2("Initialization Took: " . $T2 . " Seconds");
    } else {
        AddLog2("Initialization Failed: " . $res);
    }
    return $res;
}
 function FarmStats($inittype = '')
 {
     list($this->level, $this->gold, $this->coin, $this->wsizeX, $this->wsizeY, $this->uname, $locale, $this->tileset, $this->wither, $this->xp, $this->fuel, $this->flashRevision) = explode(';', fBGetDataStore('playerinfo'));
     $this->userId = $_SESSION['userId'];
     $this->error = '';
     $this->haveWorld = true;
     if (!is_numeric($this->userId)) {
         $this->error = "Farmville Bot Not Initialized/User Unknown";
         return;
     }
     //Open Databases
     $this->_fsManagerDBM = new SQLiteDatabase(FarmStats_Path . PluginF(FarmStats_Main));
     $this->_fsManagerDBW = new SQLiteDatabase(FarmStats_Path . PluginF(FarmStats_World));
     $this->_fsManagerDBM->queryExec('PRAGMA cache_size=20000');
     $this->_fsManagerDBM->queryExec('PRAGMA synchronous=OFF');
     $this->_fsManagerDBM->queryExec('PRAGMA count_changes=OFF');
     $this->_fsManagerDBM->queryExec('PRAGMA journal_mode=MEMORY');
     $this->_fsManagerDBM->queryExec('PRAGMA temp_store=MEMORY');
     $this->_fsManagerDBW->queryExec('PRAGMA cache_size=20000');
     $this->_fsManagerDBW->queryExec('PRAGMA synchronous=OFF');
     $this->_fsManagerDBW->queryExec('PRAGMA count_changes=OFF');
     $this->_fsManagerDBW->queryExec('PRAGMA journal_mode=MEMORY');
     $this->_fsManagerDBW->queryExec('PRAGMA temp_store=MEMORY');
     if (!$this->_fsManagerDBM || !$this->_fsManagerDBW) {
         $this->error = 'FarmStats - Database Error';
         return;
     }
     //Get Settings
     $this->settings = $this->fsGetSettings();
     if ($inittype == 'formload') {
         if (empty($this->settings)) {
             $this->error = 'Please allow FarmStats to run a cycle';
         }
         return;
     }
     //Load the world from Z*
     if ($this->haveWorld === true) {
         if ($this->settings === false) {
             $this->_fsManager_checkDB();
             //Database doesn't exist, create
             $this->_fsUpdateSettings();
             //Insert initial settings
             $this->_fsUpdateWorldDB();
             //Update the World
             $this->_fsGetEmptySpots();
             //Get Empty Spots
             $this->error = 'Please allow FarmStats to run a cycle to update all settings';
             return;
         }
         if ($this->settings['flashRevision'] != $this->flashRevision) {
             $this->settings = $this->fsGetSettings();
         }
         $this->_fsUpdateWorldDB();
         //Update the World
         //Export Files
         $seedinfo = $this->fsGetWorldSeeds();
         save_botarray($seedinfo, F('fs_seedinfo.txt'));
         $this->_fsUpdateSettings();
         //Update the settings
     }
 }
Beispiel #3
0
function TB_renewShed()
{
    $objs = array();
    $shed = array();
    $shed2 = array();
    $objs = TB_loadObjects();
    foreach ($objs as $obj) {
        if ($obj['className'] == 'HarvestStorageBuilding' && $obj['itemName'] == 'flowershed') {
            if ($obj['contents'] > 0) {
                $shed = $obj;
            }
        }
    }
    if (isset($shed['contents'])) {
        foreach ($shed['contents'] as $content) {
            $shed2[$content['itemCode']] = $content['numItem'];
        }
    }
    save_botarray($shed2, $_SESSION['base_path'] . F('inshed.txt'));
}