void shutter_btn_rec_do(int rec)
{
    if (shutter_btn_rec == 1)
    {
        if (rec) gui_uilock(UILOCK_SHUTTER);
        else gui_uilock(UILOCK_NONE);
    }
    else if (shutter_btn_rec == 2)
    {
        if (rec) SW1(1,0);
        else SW1(0,0);
    }
}
Exemple #2
0
int main(void)
{
    unsigned char state = 0x01;                 //Set initial state to 1
    int input;

    DDRB = 0xff;                                //Set PORTB as output
    DDRD = 0x00;                                //Set PORTD as input
    PORTD = 0xff;
    PORTB = state;                              //Set LEDs to initial state
    for(;;) {
        while ((input = input_check()) == 0){}  //Wait for button press
        if (input == 5) {                       //According to the input
            state = SW5(state);                 //do the corresponding job
            PORTB = state;
        } else if (input == 4) {
            state = SW4(state);
            PORTB = state;
        } else if (input == 3) {
            state = SW3(state);
            PORTB = state;
        } else if (input == 2) {
            state = SW2(state);
            PORTB = state;
        } else {
            state = SW1(state);
            PORTB = state;
        }
    }
    return -1;
}
void Handler_PMONSTER_ATTACK_RESULT(int *myID, std::string* str)
{
	SYNCHED_CHARACTER_MAP* chars = SYNCHED_CHARACTER_MAP::getInstance();
	SYNCHED_MONSTER_MAP* mons = SYNCHED_MONSTER_MAP::getInstance();

	MONSTER_ATTACK_RESULT::CONTENTS monsterattackresultContents;
	monsterattackresultContents.ParseFromString(*str);

	Scoped_Wlock SW1(&chars->srw);
	Scoped_Wlock SW2(&mons->srw);
	
	int id_m = monsterattackresultContents.id_m();
	int attackType = monsterattackresultContents.attacktype();

	Monster* atkMon = mons->find(id_m);
	
	for (int i = 0; i < monsterattackresultContents.data_size(); ++i)
	{
		auto monsterattackresult = monsterattackresultContents.data(i);
		int id = monsterattackresult.id();
		int prtHp = monsterattackresult.prthp();

		Character* targetChar = chars->find(id);
		
		if (targetChar == NULL){ printf("@@내가뜨면 안됨. 혹시뜸?\n"); exit(0); }
		else if (atkMon == NULL) { printf("내가 뜨면 안됨ㅇㅇ\n"); exit(0); }
		else
		{
			if (targetChar->getID() == *myID)// 나일때
			{
				int prePrtHp = targetChar->getPrtHp();
				targetChar->setPrtHp(prtHp);
				
				if (prtHp == 0)
				{
					int damage = prePrtHp - prtHp;
					printf("- 몬스터 [ %s(%d) ]가 %d 공격타입으로 %d 만큼 피해를 입혔습니다.\n",
						atkMon->getName().c_str(), atkMon->getID(), attackType, damage);
					printf("- 체력이 모두 소진되었습니다..\n내가...죽다니.. 10초 뒤 리스폰 됩니다..\n");
					chars->clear();
					mons->clear();
					break;
				}
				else
				{
					int damage = prePrtHp - prtHp;
					printf("- 몬스터 [ %s(%d) ]가 %d 공격타입으로 %d 만큼 피해를 입혔습니다.\n",
						atkMon->getName().c_str(), atkMon->getID(), attackType, damage);
				}
			}
			else
			{
				int	prePrtHp = targetChar->getPrtHp();
				targetChar->setPrtHp(prtHp);
				
				int damage = prePrtHp - prtHp;
				printf("※ 유저 %s님이 몬스터 [ %s(%d) ]의 %d 공격타입으로 %d 만큼 피해를 입었습니다.\n",
					targetChar->getName().c_str(), atkMon->getName().c_str(), atkMon->getID(), attackType, damage);

				if (prtHp == 0)
				{
					printf("※ 유저 %s님께서 사망하셨습니다.\n", targetChar->getName().c_str());
		
					chars->erase(targetChar->getID());
				}
			}
		}
	}
}
Exemple #4
0
int main(int argc, char *argv[]) {
	init_signals();

	if(init_terminal(&hContext,&hCard))
		return -1;
    else {
		if(open_tunnel(&tunnel) !=-1) {
			int output_len;
			raw_packet packet;
			short sw = 0x9000 ;

			printf("SCARD host adapter is now ready to accept connections\n");

			/* main loop */
			while((output_len = utun_read(&tunnel, packet.raw, MTU)) >= 0) {
				LONG card_status = 0;
				int select_ret;
				BYTE *packet_ptr;

				if(output_len == 0)
					continue;

				select_ret = utun_select(&tunnel);

				/* send the last tun input to the card */
				printf("send %d bytes\n",output_len);
				packet_ptr = packet.raw;
				do {
					unsigned char curr_len = output_len > 255 ? 255 : output_len;
					sw = send_apdu(hContext,hCard,packet_ptr,curr_len,&card_status,select_ret);
					
					if(SW1(sw) < 0x90) {
						printf("Error: %02x%02x\n",SW1(sw),SW2(sw));
						break;
					}
					
					packet_ptr += curr_len;
					output_len -= curr_len;
				} while(output_len > 0);

				/* if there is something else to send, do it now */
				if(select_ret>0) {
					memset(&packet,0,sizeof(raw_packet)); 
					continue;
				}

				/* receive data from the card (and forward it to the tun) if needed */
				while(SW2(sw)) {
					sw = recv_apdu(hContext,hCard,&tunnel,sw,&card_status);
					if(SW1(sw) < 0x90 ) {
						printf("Error: %02x%02x\n",SW1(sw),SW2(sw));
						break;
					}
				}

				if(card_status) {
					check_terminal_status(hContext,hCard);
				}
				memset(&packet,0,sizeof(raw_packet)); 
			}
		}
	}

	close_tunnel(&tunnel);
	release_terminal(&hContext,&hCard);

	return 0;
} 
void Handler_PUSER_ATTCK_RESULT(int *myID, std::string* str)
{
	SYNCHED_CHARACTER_MAP* chars = SYNCHED_CHARACTER_MAP::getInstance();
	SYNCHED_MONSTER_MAP* mons = SYNCHED_MONSTER_MAP::getInstance();

	USER_ATTACK_RESULT::CONTENTS userattackresultContents;
	userattackresultContents.ParseFromString(*str);

	Scoped_Wlock SW1(&chars->srw);
	Scoped_Wlock SW2(&mons->srw);

	//for문을 한 것은 다중 공격을 하였을 경우를 위해.
	for (int i = 0; i < userattackresultContents.data_size(); ++i)
	{
		auto userattackresult = userattackresultContents.data(i);
		int id = userattackresult.id();
		int attckType = userattackresult.attcktype();
		int id_m = userattackresult.id_m();
		int prtHp_m = userattackresult.prthp_m();

		Monster* targetMon = mons->find(id_m);
				
		int damage = targetMon->getPrtHp() - prtHp_m;
		targetMon->setPrtHp(prtHp_m);
		
		Character* atkChar = chars->find(id);
				
		if (atkChar == NULL)
		{
			printf("나뜨면 안돼는데 뜸?\n");
			exit(0);
		}
	
		if (*myID == id)//공격한것이 나일때
		{
			if (targetMon->getPrtHp() == 0)
			{
				printf("- ☆기술 %d을 사용하여 몬스터%s[%d] (을)를 %d만큼 공격하여 죽였습니다!!\n\n",
					attckType, targetMon->getName().c_str(), targetMon->getID(), damage);
			
				mons->erase(targetMon->getID());	
			}
			else
			{
				printf("- 기술 %d을 이용하여 몬스터 %s[%d] (을)를 %d만큼 공격하였습니다.\n\n",
					attckType, targetMon->getName().c_str(), targetMon->getID(), damage);
			}
		}
		else
		{
			if (targetMon->getPrtHp() == 0)
			{
				printf("※ ☆유저 %s님이 기술 %d을 이용하여 몬스터%s[%d]를 %d만큼 공격하여 죽였습니다!!\n\n",
					atkChar->getName().c_str(), attckType, targetMon->getName().c_str(), targetMon->getID(), damage);
				
				mons->erase(targetMon->getID());
			}
			else
			{
				printf("※ 유저 %s님이 기술 %d을 이용하여 몬스터 %s[%d]를 %d만큼 공격하였습니다.\n\n",
					atkChar->getName().c_str(), attckType, targetMon->getName().c_str(), targetMon->getID(), damage);
			}
		}
		
	}
}