Пример #1
0
void bankMgr::getButton(CharData* pc, json_spirit::Array& blist)
{
    if (pc->isBankOpen())
    {
        int state = 0;
        boost::shared_ptr<char_bank_list> bk = GetCharBankList(pc->m_id);
        if (bk.get())
        {
            state = bankCanGet(*bk);
        }
        json_spirit::Object obj;
        obj.push_back( Pair("type", top_button_bank) );
        obj.push_back( Pair("active", state == 1 ? 1 : 0) );
        blist.push_back(obj);
    }
}
Пример #2
0
json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw std::runtime_error(
            "getconnectioncount\n"
            "\nReturns the number of connections to other nodes.\n"
            "\nbResult:\n"
            "n          (numeric) The connection count\n"
            "\nExamples:\n"
            + HelpExampleCli("getconnectioncount", "")
            + HelpExampleRpc("getconnectioncount", "")
        );

    LOCK(cs_vNodes);
    return (int)vNodes.size();
}
Пример #3
0
json_spirit::Value startservicenodes(const json_spirit::Array& params, bool fHelp)
{
    if (IsControlNode(pNodeMain))
    {
        if (fHelp)
            throw std::runtime_error(
                    "startservicenodes [alias1] [alias2] .. [aliasN] \n"
                    "Start remote service node(s)");

        // check if the wallet is syncing
        if (IsInitialBlockDownload())
            return "Initial block download in progress";

        if(pwalletMain->IsLocked())
            return "Wallet needs to be unlocked";

        CControlNode* node = ((CControlNode*)pNodeMain);

        std::string message = "";

        if (params.size() == 0)
        {
            std::vector<std::string> vAliases = node->GetSlaveAliases();

            if (vAliases.size() == 0)
                message += "no registered slave service nodes";
            else
                BOOST_FOREACH(std::string alias, vAliases)
                    message += startservicenode(node, alias);
        }
        else
        {
            BOOST_FOREACH(json_spirit::Value param, params)
                message += startservicenode(node, param.get_str());
        }

        return message;
    }
    else
    {
        if (fHelp)
            throw std::runtime_error("");

        throw std::runtime_error("generatesharedkey is only available to control nodes");
    }
}
void Simulation::fillTeamResults(json_spirit::Array &teamList, std::string cluster)
{
	for (auto &team : teams)
	{
		json_spirit::Object teamData;
		teamData.push_back(json_spirit::Pair("id", team.id));
		if (cluster == "all")
		{
			teamData.push_back(json_spirit::Pair("ranks", clusterTeamResults[cluster][team.id].rankDataToJSONArray(ranks)));
			teamData.push_back(json_spirit::Pair("avg_place", clusterTeamResults[cluster][team.id].getAvgPlace()));
		}
		teamData.push_back(json_spirit::Pair("match_data", clusterTeamResults[cluster][team.id].toJSONObject()));
		teamData.push_back(json_spirit::Pair("avg_goals", clusterTeamResults[cluster][team.id].getAvgGoals()));
		
		
		teamList.push_back(teamData);
	}
}
Пример #5
0
json_spirit::Value generatesharedkey(const json_spirit::Array& params, bool fHelp)
{
    if (IsControlNode(pNodeMain))
    {
        if ( fHelp || params.size() != 0)
            throw std::runtime_error(
                    "generatesharedkey\n"
                    "Generates a key to be shared between the control node and service node");

        return ((CControlNode*)pNodeMain)->GenerateSharedKey();
    }
    else
    {
        if (fHelp)
            throw std::runtime_error("");

        throw std::runtime_error("generatesharedkey is only available to control nodes");
    }
}
Пример #6
0
//增益信息
int CharBuffs::getBuffInfo(json_spirit::Array& slist)
{
    if (reload)
    {
        load();
        reload = true;
    }
    refresh();
    for (int i = 0; i < 4; ++i)
    {
        json_spirit::Object obj;
        int left_time = buffs[i].m_end_time-time(NULL);
        obj.push_back( Pair("type", buffs[i].m_type) );
        obj.push_back( Pair("effect", int2percent(buffs[i].m_value,100)) );
        obj.push_back( Pair("end_time", left_time > 0 ? left_time : 0) );
        slist.push_back(obj);
    }
    return HC_SUCCESS;
}
Пример #7
0
json_spirit::Value
name_checkdb (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () != 0)
    throw std::runtime_error (
        "name_checkdb\n"
        "\nValidate the name DB's consistency.\n"
        "\nRoughly between blocks 139,000 and 180,000, this call is expected\n"
        "to fail due to the historic 'name stealing' bug.\n"
        "\nResult:\n"
        "xxxxx                        (boolean) whether the state is valid\n"
        "\nExamples:\n"
        + HelpExampleCli ("name_checkdb", "")
        + HelpExampleRpc ("name_checkdb", "")
      );

  LOCK (cs_main);
  pcoinsTip->Flush ();
  return pcoinsTip->ValidateNameDB ();
}
Пример #8
0
json_spirit::Value ping(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw std::runtime_error(
            "ping\n"
            "\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
            "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
            "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n"
            "\nExamples:\n"
            + HelpExampleCli("ping", "")
            + HelpExampleRpc("ping", "")
        );

    // Request that each node send a ping during next message processing pass
    LOCK(cs_vNodes);
    BOOST_FOREACH(CNode* pNode, vNodes) {
        pNode->fPingQueued = true;
    }

    return json_spirit::Value::null;
}
Пример #9
0
json_spirit::Value listservicenodes(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp)
        throw std::runtime_error(
                "listservicenodes [extensive = 0] \n"
                "Lists known service nodes ");

    // check if the wallet is syncing
    if (IsInitialBlockDownload())
        return "Initial block download in progress";

    std::string result;

    bool extensive = false;

    if (params.size() > 0)
        extensive = params[0].get_bool();

    BOOST_FOREACH(boost::shared_ptr<CServiceNodeInfo> node, pNodeMain->GetServiceNodes())
        result += (boost::format("%1%\n") % (node->ToString(extensive))).str();

    return result;
}
Пример #10
0
json_spirit::Value
name_show (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () != 1)
    throw std::runtime_error (
        "name_show \"name\"\n"
        "\nLook up the current data for the given name."
        "  Fails if the name doesn't exist.\n"
        "\nArguments:\n"
        "1. \"name\"          (string, required) the name to query for\n"
        "\nResult:\n"
        + getNameInfoHelp ("", "") +
        "\nExamples:\n"
        + HelpExampleCli ("name_show", "\"myname\"")
        + HelpExampleRpc ("name_show", "\"myname\"")
      );

  if (IsInitialBlockDownload ())
    throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD,
                       "Namecoin is downloading blocks...");

  const std::string nameStr = params[0].get_str ();
  const valtype name = ValtypeFromString (nameStr);

  CNameData data;
  {
    LOCK (cs_main);
    if (!pcoinsTip->GetName (name, data))
      {
        std::ostringstream msg;
        msg << "name not found: '" << nameStr << "'";
        throw JSONRPCError (RPC_WALLET_ERROR, msg.str ());
      }
  }

  return getNameInfo (name, data);
}
Пример #11
0
	bool empty() const { return _array.empty(); }	
Пример #12
0
	iterator begin() { return _array.begin(); }
Пример #13
0
	iterator end() { return _array.end(); }
Пример #14
0
int bossMgr::getAction(CharData* pc, json_spirit::Array& blist)
{
    //等级不足的不显示boss战图标
    if (!pc || (!pc->isBossOpen()))
    {
        return 0;
    }
    //获取当前时间格式匹配
    time_t timep;
    struct tm m_timenow;
    time(&timep);
    localtime_r(&timep, &m_timenow);

    //今天要开放的boss列表
    std::map<int, boost::shared_ptr<Boss> >::iterator it = m_boss_maps.begin();
    while (it != m_boss_maps.end())
    {
        Boss* pb = it->second.get();
        if (pb)
        {
            openRule* pOpenRule = pb->_boss._open_rules.getRule(m_timenow);
            if (pb->_boss._open_state || pOpenRule)
            {
                //cout<<pb->_boss._id<<" boss state "<<pb->_boss._open_state<<",";
                json_spirit::Object obj;
                obj.push_back( Pair("type", action_boss) );
                obj.push_back( Pair("id", pb->_boss._id) );
                obj.push_back( Pair("name", pb->_boss._name) );
                obj.push_back( Pair("level", pb->_boss._level) );
                obj.push_back( Pair("spic", pb->_boss._spic) );
                if (pb->_boss._open_state)
                {
                    obj.push_back( Pair("state", 1) );
                    obj.push_back( Pair("memo", strBossOpening) );
                }
                else
                {
                    if ((pOpenRule->_open_hour > m_timenow.tm_hour
                    || (pOpenRule->_open_hour == m_timenow.tm_hour && pOpenRule->_open_min > m_timenow.tm_min)))
                    {
                        obj.push_back( Pair("state", 0) );
                        std::string memo = strBossWillOpen;
                        if (pOpenRule->_open_hour < 10)
                        {
                            str_replace(memo, "$H", "0" + LEX_CAST_STR(pOpenRule->_open_hour));
                        }
                        else
                        {
                            str_replace(memo, "$H", LEX_CAST_STR(pOpenRule->_open_hour));
                        }
                        if (pOpenRule->_open_min < 10)
                        {
                            str_replace(memo, "$M", "0" + LEX_CAST_STR(pOpenRule->_open_min));
                        }
                        else
                        {
                            str_replace(memo, "$M", LEX_CAST_STR(pOpenRule->_open_min));
                        }
                        obj.push_back( Pair("memo", memo) );
                    }
                    else
                    {
                        //结束了
                        obj.push_back( Pair("state", 2) );
                        obj.push_back( Pair("memo", strBossIsClosed) );
                    }
                }
                if (pOpenRule)
                {
                    std::string startTime = time2string(pOpenRule->_open_hour, pOpenRule->_open_min);
                    obj.push_back( Pair("startTime", startTime) );;
                    int endmin = pOpenRule->_open_min;
                    int endhour = pOpenRule->_open_hour + 2;
                    if (endhour > 23)
                    {
                        endhour -= 24;
                    }
                    std::string endTime = time2string(endhour, endmin);
                    obj.push_back( Pair("endTime", endTime) );
                }
                blist.push_back(obj);
            }
        }
        ++it;
    }
    return 1;
}
Пример #15
0
bool checkMaterial(equipment_scroll* sp, CharData& char_data, Bag& m_bag, json_spirit::Array& mlist, int type = 1)
{
    bool canMake = true;
    for (std::list<std::pair<boost::shared_ptr<baseTreasure>,int> >::iterator it = sp->m_mlist.begin(); it != sp->m_mlist.end(); ++it)
    {
        if (it->first.get())
        {
            json_spirit::Object o;
            o.push_back( Pair("name", it->first->name) );
            int32_t num = m_bag.getGemCount(it->first->id);
            if (num >= it->second)
            {
                num = it->second;
            }
            else
            {
                canMake = false;
            }
            o.push_back( Pair("spic", it->first->spic) );
            o.push_back( Pair("type", iItem_type_gem) );
            o.push_back( Pair("id", it->first->id) );
            o.push_back( Pair("quality", it->first->quality) );
            if (it->first->m_place.get())
            {
                bool can_sweep = false;
                o.push_back( Pair("info", it->first->m_place->info) );
                if (it->first->m_place->type == 1)
                {
                    can_sweep = char_data.m_tempo.check_stronghold_can_sweep(it->first->m_place->mapId,it->first->m_place->stageId,it->first->m_place->pos);
                    boost::shared_ptr<StrongholdData> bstronghold = GeneralDataMgr::getInstance()->GetStrongholdData(it->first->m_place->mapId,it->first->m_place->stageId,it->first->m_place->pos);
                    if (bstronghold.get())
                    {
                        o.push_back( Pair("open_level", bstronghold->m_level) );
                    }
                    o.push_back( Pair("can_sweep", can_sweep) );
                }
                else if (it->first->m_place->type == 2)
                {
                    can_sweep = eliteCombatMgr::getInstance()->check_stronghold_can_attack(char_data.m_id,it->first->m_place->mapId,it->first->m_place->pos);
                    o.push_back( Pair("can_sweep", can_sweep) );
                }
            }

            o.push_back( Pair("num", num) );
            o.push_back( Pair("need", it->second) );
            mlist.push_back(o);
        }
    }
    //卷轴信息
    int32_t gem_num = m_bag.getGemCount(sp->m_gem_id);
    if (gem_num <= 0)
    {
        canMake = false;
    }
    if (type == 2)
    {
        boost::shared_ptr<baseTreasure> bt = GeneralDataMgr::getInstance()->GetBaseTreasure(sp->m_gem_id);
        if (bt.get() && bt->m_place.get())
        {
            json_spirit::Object o;
            o.push_back( Pair("name", bt->name) );
            o.push_back( Pair("spic", bt->spic) );
            o.push_back( Pair("type", iItem_type_gem) );
            o.push_back( Pair("id", bt->id) );
            o.push_back( Pair("quality", bt->quality) );
            o.push_back( Pair("num", gem_num) );
            o.push_back( Pair("need", 1) );
            o.push_back( Pair("info", bt->m_place->info) );
            bool can_sweep = false;
            if (bt->m_place->type == 1)
            {
                can_sweep = char_data.m_tempo.check_stronghold_can_sweep(bt->m_place->mapId,bt->m_place->stageId,bt->m_place->pos);
                o.push_back( Pair("can_sweep", can_sweep) );
            }
            else if (bt->m_place->type == 2)
            {
                can_sweep = eliteCombatMgr::getInstance()->check_stronghold_can_attack(char_data.m_id,bt->m_place->mapId,bt->m_place->pos);
                o.push_back( Pair("can_sweep", can_sweep) );
            }
            mlist.push_back(o);
        }
    }
    return canMake;
}
void Simulation::fillRankResults(json_spirit::Array &ranks)
{
	for (RankData &rankData : this->ranks)
		ranks.push_back(rankData.toJSONObject());
}
Пример #17
0
json_spirit::Value
name_filter (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () > 5)
    throw std::runtime_error (
        "name_filter (\"regexp\" (\"maxage\" (\"from\" (\"nb\" (\"stat\")))))\n"
        "\nScan and list names matching a regular expression.\n"
        "\nArguments:\n"
        "1. \"regexp\"      (string, optional) filter names with this regexp\n"
        "2. \"maxage\"      (numeric, optional, default=36000) only consider names updated in the last \"maxage\" blocks; 0 means all names\n"
        "3. \"from\"        (numeric, optional, default=0) return from this position onward; index starts at 0\n"
        "4. \"nb\"          (numeric, optional, default=0) return only \"nb\" entries; 0 means all\n"
        "5. \"stat\"        (string, optional) if set to the string \"stat\", print statistics instead of returning the names\n"
        "\nResult:\n"
        "[\n"
        + getNameInfoHelp ("  ", ",") +
        "  ...\n"
        "]\n"
        "\nExamples:\n"
        + HelpExampleCli ("name_filter", "\"\" 5")
        + HelpExampleCli ("name_filter", "\"^id/\"")
        + HelpExampleCli ("name_filter", "\"^id/\" 36000 0 0 \"stat\"")
        + HelpExampleRpc ("name_scan", "\"^d/\"")
      );

  if (IsInitialBlockDownload ())
    throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD,
                       "Namecoin is downloading blocks...");

  /* ********************** */
  /* Interpret parameters.  */

  bool haveRegexp(false);
  boost::xpressive::sregex regexp;

  int maxage(36000), from(0), nb(0);
  bool stats(false);

  if (params.size () >= 1)
    {
      haveRegexp = true;
      regexp = boost::xpressive::sregex::compile (params[0].get_str ());
    }

  if (params.size () >= 2)
    maxage = params[1].get_int ();
  if (maxage < 0)
    throw JSONRPCError (RPC_INVALID_PARAMETER,
                        "'maxage' should be non-negative");
  if (params.size () >= 3)
    from = params[2].get_int ();
  if (from < 0)
    throw JSONRPCError (RPC_INVALID_PARAMETER, "'from' should be non-negative");

  if (params.size () >= 4)
    nb = params[3].get_int ();
  if (nb < 0)
    throw JSONRPCError (RPC_INVALID_PARAMETER, "'nb' should be non-negative");

  if (params.size () >= 5)
    {
      if (params[4].get_str () != "stat")
        throw JSONRPCError (RPC_INVALID_PARAMETER,
                            "fifth argument must be the literal string 'stat'");
      stats = true;
    }

  /* ******************************************* */
  /* Iterate over names to build up the result.  */

  json_spirit::Array names;
  unsigned count(0);

  /* The lock must be held throughout the call, since walker.getResult()
     uses chainActive for the block height in stats mode.  */
  LOCK (cs_main);
  pcoinsTip->Flush ();

  std::auto_ptr<CNameIterator> iter(pcoinsTip->IterateNames (valtype ()));
  valtype name;
  CNameData data;
  while (iter->next (name, data))
    {
      const int age = chainActive.Height () - data.getHeight ();
      assert (age >= 0);
      if (maxage != 0 && age >= maxage)
        continue;

      if (haveRegexp)
        {
          const std::string nameStr = ValtypeToString (name);
          boost::xpressive::smatch matches;
          if (!boost::xpressive::regex_search (nameStr, matches, regexp))
            continue;
        }

      if (from > 0)
        {
          --from;
          continue;
        }
      assert (from == 0);

      if (stats)
        ++count;
      else
        names.push_back (getNameInfo (name, data));

      if (nb > 0)
        {
          --nb;
          if (nb == 0)
            break;
        }
    }

  /* ********************************************************** */
  /* Return the correct result (take stats mode into account).  */

  if (stats)
    {
      json_spirit::Object res;
      res.push_back (json_spirit::Pair ("blocks", chainActive.Height ()));
      res.push_back (json_spirit::Pair ("count", static_cast<int> (count)));

      return res;
    }

  return names;
}
Пример #18
0
void DecisionCreationWidget::editArray(json_spirit::Array array)
{
    if (array.size() < 6) {
        return;
    }

    // Load owner address
    json_spirit::Value ownerAddr = array.at(0);
    ui->lineEditOwnerAddr->setText(QString::fromStdString(ownerAddr.get_str()));

    // Load branchID
    json_spirit::Value branch = array.at(1);
    QString branchLabel = "Branch: ";
    QString branchID = QString::fromStdString(branch.get_str());
    branchLabel.append(branchID.left(12));
    branchLabel.append("...");
    ui->labelBranch->setText(branchLabel);
    if (branchID == "0f894a25c5e0318ee148fe54600ebbf50782f0a1df1eb2aab06321a8ccec270d") {
        ui->comboBoxBranch->setCurrentIndex(0); // Main
    } else if (branchID == "419cd87761f45c108a976ca6d93d4929c7c4d1ff4386f5089fc2f7ff7ae21ddf") {
        ui->comboBoxBranch->setCurrentIndex(1); // Sports
    } else if (branchID == "3277b5057ac9cda54e9edfbb45fd8bab38be1b5afc3cd6c587f6d17779f34f74") {
        ui->comboBoxBranch->setCurrentIndex(2); // Econ
    }

    // Load prompt
    json_spirit::Value prompt = array.at(2);
    ui->plainTextEditPrompt->setPlainText(QString::fromStdString(prompt.get_str()));

    // Load event over by
//    TODO: Replace with nLockTime
//    json_spirit::Value eventOverBy = array.at(3);
//    int overBy = eventOverBy.get_int();

    // Load voteMandatory
    json_spirit::Value voteMandatory = array.at(4);
    ui->checkBoxVoteMandatory->setChecked(voteMandatory.get_bool());

    // Load scaled
    json_spirit::Value scaled = array.at(5);
    bool isScaled = scaled.get_bool();
    ui->radioButtonScaled->setChecked(isScaled);
    if (isScaled) {
        // Load scale values
        json_spirit::Value scaledMin = array.at(6);
        ui->doubleSpinBoxScaledMin->setValue(scaledMin.get_real());
        json_spirit::Value scaledMax = array.at(7);
        ui->doubleSpinBoxScaledMax->setValue(scaledMax.get_real());
    }

    // Unhide the scaled spinboxes if the decision is scaled
    on_radioButtonScaled_clicked(isScaled);

    // Check for update index from model
    if (isScaled && array.size() == 10) {
        ui->pushButtonCreateDecision->hide();
        ui->pushButtonUpdateDecision->show();
        updateIndex = array.at(9).get_int();
    } else if (!isScaled && array.size() == 8) {
        ui->pushButtonCreateDecision->hide();
        ui->pushButtonUpdateDecision->show();
        updateIndex = array.at(7).get_int();
    }
}