コード例 #1
0
ファイル: fusb.cpp プロジェクト: 5728136cs/YateBTS
void
fusb_ephandle::reap_complete_writes ()
{
  // take a look at the completed list and xfer to free list after
  // checking for errors.

  libusb_transfer *lut;

  while ((lut = completed_list_get ()) != 0) {

    // Check for any errors or short writes that were reporetd in the transfer.
    // libusb1 sets status, actual_length.

    if (lut->status != LIBUSB_TRANSFER_COMPLETED) {
      LOG(ERR) << "Invalid LUT status " << lut->status;
      check_health (false);
    }
    else if (lut->actual_length != lut->length){
      LOG(ERR) << "Improper write of " << lut->actual_length;
      check_health (false);
    }
    else check_health (true);

    free_list_add (lut);
  }
}
コード例 #2
0
ファイル: fusb.cpp プロジェクト: 5728136cs/YateBTS
bool
fusb_ephandle::reload_read_buffer ()
{
  assert (d_read_buffer >= d_read_buffer_end);

  libusb_transfer *lut;

  if (d_read_work_in_progress) {
    lut = d_read_work_in_progress;
    d_read_work_in_progress = 0;
    d_read_buffer = 0;
    d_read_buffer_end = 0;
    lut->actual_length = 0;
    if (!submit_lut (lut)) {
      LOG(ERR) << "Improper LUT submission";
      return false;
    }
  }

  while (1) {

    while ((lut = completed_list_get ()) == 0 )
      if (!d_devhandle->_reap(true))
        {
 	  LOG(ERR) << "No libusb events";
          check_health (false);
          return false;
        }
    if (lut->status != LIBUSB_TRANSFER_COMPLETED) {
      LOG(ERR) << "Improper read status " << lut->status;
      lut->actual_length = 0;
      free_list_add (lut);
      check_health (false);
      return false;
    }

    d_read_work_in_progress = lut;
    d_read_buffer = (unsigned char *) lut->buffer;
    d_read_buffer_end = d_read_buffer + lut->actual_length;

    check_health (true);
    return true;
  }
}
コード例 #3
0
ファイル: fusb.cpp プロジェクト: 5728136cs/YateBTS
bool
fusb_ephandle::submit_lut (libusb_transfer *lut)
{
  if (!d_devhandle->_submit_lut (lut)) {
    LOG(ERR) << "USB submission failed";
    free_list_add (lut);
    check_health (false);
    return false;
  }
  return true;
}
コード例 #4
0
ファイル: agent.cpp プロジェクト: destrojan/wotwar
void AGENT::update(void)
{
	// move
	if ((!group->is_single_unit() || state == AGENT::READY_FIGHT) && !group->is_building()) {
        update_move();
        collision_check();
	}

	// generic unit status
	check_health();
	if (!has_not_moved()) clear_stuckcounter();
	if (!build_data) updateAnimation();
}
コード例 #5
0
ファイル: police.c プロジェクト: startmenu/ythtbbs
static void
cop_tax()
{
    char uident[IDLEN + 1], buf[256], title[STRLEN];
    time_t currtime;
    mcUserInfo *mcuInfo;
    int num;

    nomoney_show_stat("税局");

    if (clubtest(ROBUNION) || clubtest(BEGGAR)) {
        showAt(12, 4, "《无间道》看多了吧你?", YEA);
        return;
    }

    if (myInfo->robExp < 500 || myInfo->begExp < 500) {
        showAt(12, 4,
               "新警察吧?先去练练基本功,不然就是送死了。党和国家培养你不容易啊!",
               YEA);
        return;
    }
    if (check_health(100, 12, 4, "你没有充沛的体力来执行任务。", YEA))
        return;

    currtime = time(NULL);
    if (myInfo->WorkPoint < 9000) {
        showAt(12, 4, "不要着急,上级还没有行动指示。", YEA);
        return;
    }

    move(4, 4);
    prints("最近偷税漏税严重,需要严厉打击这种抗税风潮。");

    if (!getOkUser("\n请选择你的目标:", uident, 6, 4)) {
        move(8, 4);
        prints("查无此人");
        pressanykey();
        return;
    }
    if (!strcmp(uident, currentuser->userid)) {
        showAt(8, 4, "牛魔王:“老婆~快来看神经病啦~”", YEA);
        return;
    }

    myInfo->Actived += 10;
    move(10, 4);
    prints("你敲开了%s的家门。", uident);
    sleep(1);

    sethomefile(buf, uident, "mc.save");
    if (!file_exist(buf))
        initData(1, buf);
    if((mcuInfo = loadData(buf, sizeof (mcUserInfo))) == (void*)-1)
        return;

    if (mcuInfo->GetLetter == 0) {
        clear();
        showAt(6, 4, "虚拟货币持有者,无法征税", YEA);
        unloadData(mcuInfo, sizeof (mcUserInfo));
        return;
    }

    myInfo->lastActiveTime = currtime;
    myInfo->WorkPoint -= 9000;
    sleep(1);

    if (check_chance
            (myInfo->robExp + myInfo->begExp, mcuInfo->robExp + mcuInfo->begExp,
             myInfo->weapon, mcuInfo->armor, 200, 100)) {
        myInfo->begExp += 20;
        myInfo->robExp += 20;
        num = mcuInfo->credit / 3;
        myInfo->health = 0;
        mcuInfo->credit -= num;
        mcEnv->Treasury += num * 2 / 3;
        myInfo->credit += num / 3;

        myInfo->luck = MIN(100, myInfo->luck + 20);
        prints("\n    %s并不像想象中的那么滑头啊。"
               "\n    他在你的监督下如数缴纳了%d%s的欠税。"
               "\n    你从中获得1/3 的奖励,你的胆识身法上升。", uident,
               num, MONEY_NAME);
        sprintf(title, "【税务】%s缴纳欠税", uident);
        sprintf(buf,
                "在警员%s的监督下,%s如期缴纳了所欠的%d%s税款。特此公告。",
                currentuser->userid, uident, num, MONEY_NAME);
        deliverreport(title, buf);
        sprintf(buf,
                "警员%s陪同税务前来查税,看来是躲不过去了。\n"
                "不得不缴纳了%d%s的税款,心痛啊。",
                currentuser->userid, num, MONEY_NAME);
        if (mcuInfo->GetLetter == 1)
            system_mail_buf(buf, strlen(buf), uident, "你缴纳欠税",
                            currentuser->userid);
    } else {
        myInfo->begExp = MAX(0, myInfo->begExp - 5);
        myInfo->robExp = MAX(0, myInfo->robExp - 5);
        myInfo->health = 0;
        mcuInfo->robExp += 10;
        mcuInfo->begExp += 10;
        prints("\n    %s一副死猪不怕开水烫的样子。"
               "\n    “要钱没有,要命一条”"
               "\n    软硬不吃,你无计可使,不得不狼狈归去。", uident);
    }
    unloadData(mcuInfo, sizeof (mcUserInfo));
    pressanykey();
    return;
}
コード例 #6
0
ファイル: police.c プロジェクト: startmenu/ythtbbs
static void
cop_Arrest(void)
{
    char uident[IDLEN + 1], police[IDLEN + 1], buf[256], title[STRLEN];
    char *CrimeName[] =
    {   "莫须有", "有伤风化", "小偷小摸", "破坏治安", "卖淫嫖娼",
        "杀人放火", "颠覆政府", "反社会反人类", "种族灭绝", NULL
    };
    int CrimeTime[] = { 1, 2, 3, 4, 6, 8, 12, 16, 24 };
    time_t currtime;
    mcUserInfo *mcuInfo;
    int num, tranum, crime = 0, bonus = 100;

    nomoney_show_stat("刑警队");
    if (!seek_in_file(DIR_MC "policemen", currentuser->userid)) {
        showAt(12, 4, "警察执行任务,闲杂人等请回避,以免误伤。", YEA);
        return;
    }
    if (clubtest(ROBUNION) || clubtest(BEGGAR)) {
        showAt(12, 4, "《无间道》看多了吧你?", YEA);
        return;
    }

    if (myInfo->robExp < 50 || myInfo->begExp < 50) {
        showAt(12, 4,
               "新警察吧?先去练练基本功,不然就是送死了。党和国家培养你不容易啊!",
               YEA);
        return;
    }
    if (check_health(100, 12, 4, "你没有充沛的体力来执行任务。", YEA))
        return;

    currtime = time(NULL);
    if (myInfo->WorkPoint < 7200) {
        showAt(12, 4, "不要着急,上级还没有行动指示。", YEA);
        return;
    }

    move(5, 4);
    prints("刚刚接到上级指示,马上要进行一次抓捕行动。");

    if (!getOkUser("\n请选择你的目标:", uident, 6, 4)) {
        move(8, 4);
        prints("查无此人");
        pressanykey();
        return;
    }
    if (!strcmp(uident, currentuser->userid)) {
        showAt(8, 4, "牛魔王:“老婆~快来看神经病啦~”", YEA);
        return;
    }
    if (!seek_in_file(DIR_MC "criminals_list", uident)) {
        showAt(8, 4, "此人不在通缉名单上面。”", YEA);
        return;
    }
    myInfo->Actived += 10;
    move(10, 4);
    prints("你埋伏在大富翁世界的必经之路,等待目标的出现。");
    sleep(1);

    sethomefile(buf, uident, "mc.save");
    if (!file_exist(buf))
        initData(1, buf);
    if((mcuInfo = loadData(buf, sizeof (mcUserInfo))) == (void*)-1)
        return;

    myInfo->lastActiveTime = currtime;
    myInfo->WorkPoint -= 7200;
    sleep(1);
    if (currtime > 3600 + mcuInfo->lastActiveTime) {
        myInfo->health -= 10;
        showAt(12, 4, "你等了整整一天,目标还是没有出现,只好放弃了。",
               YEA);
        return;
    }

    /*	if (!(random() % 3)) {
    		myInfo->health -= 10;
    		showAt(12, 4, "你眼看老远处人影一晃,目标得到风声跑掉了。",
    		       YEA);
    		return;
    	}

    	if ((myInfo->robExp + myInfo->begExp >=
    	     (mcuInfo->robExp + mcuInfo->begExp)
    	     * 5 + 50 || myInfo->luck - mcuInfo->luck >= 100 || (random() % 3))
    	    && !(mcuInfo->robExp + mcuInfo->begExp >= (myInfo->
    						       robExp +
    						       myInfo->begExp) * 5 +
    		 50)) {
    */
    num =
        myInfo->robExp + myInfo->begExp + (mcuInfo->robExp +
                                           mcuInfo->begExp) * 2;
    if (num > 150000)
        crime = 8;
    else if (num > 100000)
        crime = 7;
    else if (num > 50000)
        crime = 6;
    else if (num > 10000)
        crime = 5;
    else if (num > 5000)
        crime = 4;
    else if (num > 2000)
        crime = 3;
    else if (num > 1000)
        crime = 2;
    else if (num > 500)
        crime = 1;
    else
        crime = 0;
    tranum =
        MIN((myInfo->robExp + myInfo->begExp + mcuInfo->robExp +
             mcuInfo->begExp) / 250,
            (mcuInfo->robExp + mcuInfo->begExp) / 50);
    whoTakeCharge(8, police);
    if (!(strcmp(currentuser->userid, police)))
        bonus = 300;
    if (check_chance
            (myInfo->robExp + myInfo->begExp, mcuInfo->robExp + mcuInfo->begExp,
             myInfo->weapon, mcuInfo->armor, 200, bonus)) {
        myInfo->begExp += tranum + 10;
        myInfo->robExp += tranum + 10;
        myInfo->health = 0;
        myInfo->cash += mcuInfo->cash;
        mcuInfo->cash = 0;
        mcuInfo->begExp = MAX(0, mcuInfo->begExp - tranum - 10);
        mcuInfo->robExp = MAX(0, mcuInfo->robExp - tranum - 10);
        mcuInfo->luck = MAX(-100, mcuInfo->luck - 10);
//              mcuInfo->freeTime += (currtime + 10800);
        mcuInfo->freeTime = time(NULL) + CrimeTime[crime] * 3600;

        myInfo->luck = MIN(100, myInfo->luck + 10);
        del_from_file(DIR_MC "criminals_list", uident);
        prints("\n    远处有人走了过来,你定睛一看,正是你要抓的%s。"
               "\n    你跳出来拔出手枪大吼道:“不许动!你被捕了!”"
               "\n    %s目瞪口呆,只好束手就擒。"
               "\n    你的胆识增加了!	你的身法增加了!"
               "\n    你的体力耗尽了!"
               "\n    你的人品增加了!"
               "\n    没收罪犯所有现金做为补助!", uident, uident);
        sprintf(title, "【警署】警方抓获通缉犯%s", uident);
        sprintf(buf,
                "警员%s耐心守候,孤身勇擒在榜通缉犯%s,特此公告,以示表彰。\n\n"
                "经%s法庭判决,被告%s%s罪名成立,判处%d小时有期徒刑。",
                currentuser->userid, uident, CENTER_NAME, uident,
                CrimeName[crime], CrimeTime[crime]);
        deliverreport(title, buf);
        sprintf(buf,
                "你被警员%s设伏抓获,没收所有现金,胆识身法下降。\n"
                "还被法庭判决%s罪,关押%d小时。\n"
                "不报此仇,誓不为人!",
                currentuser->userid, CrimeName[crime],
                CrimeTime[crime]);
        if (mcuInfo->GetLetter == 1)
            system_mail_buf(buf, strlen(buf), uident,
                            "你被警方抓获", currentuser->userid);
        unloadData(mcuInfo, sizeof (mcUserInfo));
    } else {
        myInfo->begExp = MAX(0, myInfo->begExp - tranum / 2);
        myInfo->robExp = MAX(0, myInfo->robExp - tranum / 2);
        myInfo->health = 0;
        mcuInfo->cash += myInfo->cash;
        myInfo->cash = 0;
        mcuInfo->robExp += tranum / 2;
        mcuInfo->begExp += tranum / 2;
        myInfo->freeTime = time(NULL) + CrimeTime[crime] * 1800 + 1800;
        prints("\n    远处有人走了过来,你定睛一看,正是你要抓的%s。"
               "\n    你跳出来拔出手枪大吼道:“不许动!你被捕了!”"
               "\n    正得意时,不料背后有人打了你一个闷棍。"
               "\n    你的胆识减少了!"
               "\n    你的身法减少了!" "\n    你昏了过去!", uident);
        sprintf(title, "【警署】警员%s受伤住院", currentuser->userid);
        sprintf(buf,
                "警员%s在执行任务的时候,被罪犯打伤住院。目前情况稳"
                "定,%d小时以后即可出院。", currentuser->userid,
                (CrimeTime[crime] + 1) / 2);
        deliverreport(title, buf);
        sprintf(buf,
                "条子%s设伏抓你,还好你艺高人胆大将其干掉,自己安然"
                "无恙。\n 顺手捞走了他身上的现金,胆识身法上升,太爽了!",
                currentuser->userid);
        if (mcuInfo->GetLetter == 1)
            system_mail_buf(buf, strlen(buf), uident, "你金蝉脱壳",
                            currentuser->userid);
        unloadData(mcuInfo, sizeof (mcUserInfo));
        unloadData(myInfo, sizeof (mcUserInfo));
        unloadData(mcEnv, sizeof (MC_Env));
        pressreturn();
        Q_Goodbye();
    }

    pressreturn();
//      Q_Goodbye();
    return;

}
コード例 #7
0
ファイル: agent.cpp プロジェクト: destrojan/wotwar
void AGENT::update_building(void)
{
    check_health();
}