Ejemplo n.º 1
0
int answer_request(int sockfd,char mesg[],User_List play_list[]){
	int i;
	char nick_name[LEN];
	char mesg2[LEN],buff[LEN],buff2[LEN];
	char *pch;
	
	char yes[2];

	strcpy(mesg2,mesg);

	pch= strtok(mesg2,"|");
	pch= strtok(NULL,"|");
	strcpy(nick_name,pch);
	printf("\n@%s muon play voi ban!!",nick_name);
	printf("\nBan co dong y(y/n): ");
	//scanf("%s",yes);
	fgets(yes,3,stdin);
	if(yes[0] == 'y' || yes[0] == 'Y') {
		add_partner(nick_name,play_list);
		strcpy(buff,"4|");
		strcat(buff,nick_name);
		strcat(buff,"|0|0|0|");
		send(sockfd,buff,strlen(buff),0);
		return 1;
	}
	else {
		strcpy(buff,"5|");
		strcat(buff,nick_name);
		strcat(buff,"|0|0|0|");
		send(sockfd,buff,strlen(buff),0);
		return 0;
	}
}
Ejemplo n.º 2
0
void choose_user(int sockfd,User_List play_list[]){
	int i,t,a,x,y;
	User_List user_list[100];
	char mesg[LEN],buff[LEN],buff2[LEN]="0",buff3[LEN];


	strcpy(buff,"2|0|0|0|0");
	send(sockfd,buff,strlen(buff),0);
	strcpy(mesg,"");
	recv(sockfd,mesg,LEN,0);
	t=check_mark(mesg);
	if(t == 2) a = take_user_list(mesg,user_list); //Lay danh sach user tu server 
	if(a==0) {
		printf("\nKhong co user khac online!!");
		return;}
	for ( i = 0; i < a; i++){
		printf("\n%d.@%s",i+1,user_list[i].nick_name);
	}
	while(1){
		printf("\nBan dung quan trang. Chon user de choi. ");
		scanf("%d",&y);
		fgets(buff3,LEN,stdin);
		if(0<y&&y<=a) break;
	}
	strcpy(mesg,"");
	creat_mesg(3,user_list[y-1].nick_name,buff2,buff2,buff2,mesg);
	send(sockfd,mesg,strlen(mesg),0);
	strcpy(mesg,"");
	recv(sockfd,mesg,LEN,0);
	t = check_mark(mesg);
	if(t == 4){
		printf("\n@%s da dong y play\n",user_list[y-1].nick_name);
		add_partner(user_list[y-1].nick_name,play_list);
		// fgets(buff,LEN,stdin);
		playing(sockfd,play_list);
		return;
	}else if(t == 5){
		printf("\nUser khong dong y play!!\n");
		return;
	}
}
Ejemplo n.º 3
0
void auto_exclusion(int distance)
{
  int count, p, i, j, p1, p2, p3, dist1, dist2;
  Bonded_ia_parameters *ia_params;
  Particle *part1;
  /* partners is a list containing the currently found excluded particles for each particle,
     and their distance, as a interleaved list */
  IntList *partners;

  updatePartCfg(WITH_BONDS);

  /* setup bond partners and distance list. Since we need to identify particles via their identity,
     we use a full sized array */
  partners    = (IntList*)malloc((max_seen_particle + 1)*sizeof(IntList));
  for (p = 0; p <= max_seen_particle; p++)
    init_intlist(&partners[p]);

  /* determine initial connectivity */
  for (p = 0; p < n_part; p++) {
    part1 = &partCfg[p];
    p1    = part1->p.identity;
    for (i = 0; i < part1->bl.n;) {
      ia_params = &bonded_ia_params[part1->bl.e[i++]];
      if (ia_params->num == 1) {
	p2 = part1->bl.e[i++];
	/* you never know what the user does, may bond a particle to itself...? */
	if (p2 != p1) {
	  add_partner(&partners[p1], p1, p2, 1);
	  add_partner(&partners[p2], p2, p1, 1);
	}
      }
      else
	i += ia_params->num;
    }
  }

  /* calculate transient connectivity. For each of the current neighbors,
     also exclude their close enough neighbors.
  */
  for (count = 1; count < distance; count++) {
    for (p1 = 0; p1 <= max_seen_particle; p1++) {
      for (i = 0; i < partners[p1].n; i += 2) {
	p2 = partners[p1].e[i];
	dist1 = partners[p1].e[i + 1];
	if (dist1 > distance) continue;
	/* loop over all partners of the partner */
	for (j = 0; j < partners[p2].n; j += 2) {
	  p3 = partners[p2].e[j];
	  dist2 = dist1 + partners[p2].e[j + 1];
	  if (dist2 > distance) continue;
	  add_partner(&partners[p1], p1, p3, dist2);
	  add_partner(&partners[p3], p3, p1, dist2);
	}
      }
    }
  }

  /* setup the exclusions and clear the arrays. We do not setup the exclusions up there,
     since on_part_change clears the partCfg, so that we would have to restore it
     continously. Of course this could be optimized by bundling the exclusions, but this
     is only done once and the overhead is as much as for setting the bonds, which
     the user apparently accepted.
  */
  for (p = 0; p <= max_seen_particle; p++) {
    for (j = 0; j < partners[p].n; j++)
      if (p < partners[p].e[j]) change_exclusion(p, partners[p].e[j], 0);
    realloc_intlist(&partners[p], 0);
  }
  free(partners);
}