예제 #1
0
파일: master.c 프로젝트: coyizumi/cs111
/*
 * Remove all the machines from the host table that exist on the given
 * network.  This is called when a master transitions to a slave on a
 * given network.
 */
void
rmnetmachs(struct netinfo *ntp)
{
	struct hosttbl *htp;

	if (trace)
		prthp(CLK_TCK);
	for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
		if (ntp == htp->ntp)
			htp = remmach(htp);
	}
	if (trace)
		prthp(CLK_TCK);
}
예제 #2
0
파일: master.c 프로젝트: coyizumi/cs111
void
traceon(void)
{
	if (!fd) {
		fd = fopen(_PATH_TIMEDLOG, "w");
		if (!fd) {
			trace = 0;
			return;
		}
		fprintf(fd,"Tracing started at %s\n", date());
	}
	trace = 1;
	get_goodgroup(1);
	setstatus();
	prthp(CLK_TCK);
}
예제 #3
0
파일: master.c 프로젝트: coyizumi/cs111
void
traceoff(char *msg)
{
	get_goodgroup(1);
	setstatus();
	prthp(CLK_TCK);
	if (trace) {
		fprintf(fd, msg, date());
		(void)fclose(fd);
		fd = 0;
	}
#ifdef GPROF
	moncontrol(0);
	_mcleanup();
	moncontrol(1);
#endif
	trace = OFF;
}
예제 #4
0
파일: master.c 프로젝트: coyizumi/cs111
void
newslave(struct tsp *msg)
{
	struct hosttbl *htp;
	struct tsp *answer, to;
	struct timeval now, tmptv;

	if (!fromnet || fromnet->status != MASTER)
		return;

	htp = addmach(msg->tsp_name, &from,fromnet);
	htp->seq = msg->tsp_seq;
	if (trace)
		prthp(0);

	/*
	 * If we are stable, send our time to the slave.
	 * Do not go crazy if the date has been changed.
	 */
	(void)gettimeofday(&now, NULL);
	if (now.tv_sec >= fromnet->slvwait.tv_sec+3
	    || now.tv_sec < fromnet->slvwait.tv_sec) {
		to.tsp_type = TSP_SETTIME;
		(void)strcpy(to.tsp_name, hostname);
		(void)gettimeofday(&tmptv, NULL);
		to.tsp_time.tv_sec = tmptv.tv_sec;
		to.tsp_time.tv_usec = tmptv.tv_usec;
		answer = acksend(&to, &htp->addr,
				 htp->name, TSP_ACK,
				 0, htp->noanswer);
		if (answer) {
			htp->need_set = 0;
		} else {
			syslog(LOG_WARNING,
			       "no reply to initial SETTIME from %s",
			       htp->name);
			htp->noanswer = LOSTHOST;
		}
	}
}
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());
				}
			}
		}
	}
}
예제 #6
0
파일: master.c 프로젝트: coyizumi/cs111
/*
 * add a host to the list of controlled machines if not already there
 */
struct hosttbl *
addmach(char *name, struct sockaddr_in *addr, struct netinfo *ntp)
{
	struct hosttbl *ret, *p, *b, *f;

	ret = findhost(name);
	if (ret == 0) {
		if (slvcount >= NHOSTS) {
			if (trace) {
				fprintf(fd, "no more slots in host table\n");
				prthp(CLK_TCK);
			}
			syslog(LOG_ERR, "no more slots in host table");
			Mflag = 0;
			longjmp(jmpenv, 2); /* give up and be a slave */
		}

		/* if our home hash slot is occupied, find a free entry
		 * in the hash table
		 */
		if (newhost_hash->name[0] != '\0') {
			do {
				ret = lasthfree;
				if (++lasthfree > &hosttbl[NHOSTS])
					lasthfree = &hosttbl[1];
			} while (ret->name[0] != '\0');

			if (!newhost_hash->head) {
				/* Move an interloper using our home.  Use
				 * scratch pointers in case the new head is
				 * pointing to itself.
				 */
				f = newhost_hash->h_fwd;
				b = newhost_hash->h_bak;
				f->h_bak = ret;
				b->h_fwd = ret;
				f = newhost_hash->l_fwd;
				b = newhost_hash->l_bak;
				f->l_bak = ret;
				b->l_fwd = ret;
				bcopy(newhost_hash,ret,sizeof(*ret));
				ret = newhost_hash;
				ret->head = 1;
				ret->h_fwd = ret;
				ret->h_bak = ret;
			} else {
				/* link to an existing chain in our home
				 */
				ret->head = 0;
				p = newhost_hash->h_bak;
				ret->h_fwd = newhost_hash;
				ret->h_bak = p;
				p->h_fwd = ret;
				newhost_hash->h_bak = ret;
			}
		} else {
			ret = newhost_hash;
			ret->head = 1;
			ret->h_fwd = ret;
			ret->h_bak = ret;
		}
		ret->addr = *addr;
		ret->ntp = ntp;
		(void)strncpy(ret->name, name, sizeof(ret->name));
		ret->good = good_host_name(name);
		ret->l_fwd = &self;
		ret->l_bak = self.l_bak;
		self.l_bak->l_fwd = ret;
		self.l_bak = ret;
		slvcount++;

		ret->noanswer = 0;
		ret->need_set = 1;

	} else {
		ret->noanswer = (ret->noanswer != 0);
	}

	/* need to clear sequence number anyhow */
	ret->seq = 0;
	return(ret);
}