Пример #1
0
Файл: g28.c Проект: 8l/csolve
void adcons(int s,int g){       /* add connections through a point */
				/* but not to group g */
   int n[4],i,sn,j,k,ldtmp,c,dst;

   k = 0;
   i = fdir[s];
   for(ldtmp = ldir[i]; i != ldtmp; ++i){
      sn = s + nbr[i];
      if(board[sn] != NOGROUP && board[sn] != g)
         n[k++] = board[sn];
      }
   for(i = 0; i < k-1; ++i)
      for(j = i + 1; j != k; ++j)
         if(grcolor[n[i]] == grcolor[n[j]])
            addconn(n[i],n[j],s);
   for(i = 0; i < 4; ++i){
      sn = sqrbrd[s][i];
      dst = dstbrd[s][i];
      if(sn != NOSQUARE && (dst == 1 )){
         c = grcolor[board[sn]];
         for(j = 0; j < k; ++j)
            if(grcolor[n[j]] == c)
               addlink(n[j],board[sn],s);
         }
      if(sn != NOSQUARE && (dst == 2 )){
         c = grcolor[board[sn]];
         for(j = 0; j < k; ++j)
            if(grcolor[n[j]] == c)
               addlkg(n[j],board[sn],s);
         }
      }
   }
Пример #2
0
Файл: g28.c Проект: 8l/csolve
void chkcon(int s,int g){  /* add connections to g at libs next to s */
				/* s has a stone on it for group g */
   int i,sn,sn2,j,cflag,gflag,c;
   int grp[4],k,l,ldtmp,ldtm2;

   for(i = 0; i < 4; i++){
       grp[i] = -1;
       }
   c = grcolor[g];
   i = fdir[s];
   for(ldtmp = ldir[i]; i != ldtmp; ++i){
      sn = s + nbr[i];
      if(board[sn] != NOGROUP)continue;
      for(j = 0; j < 4; ++j){
         if(grcolor[board[sqrbrd[sn][j]]] == c &&
           (dstbrd[sn][j] == 1  ))
            addlink(g,board[sqrbrd[sn][j]],sn);
         if(grcolor[board[sqrbrd[sn][j]]] == c &&
           (dstbrd[sn][j] == 2  ))
            addlkg(g,board[sqrbrd[sn][j]],sn);
	 }
      cflag = FALSE;
      k = 0;
      j = fdir[sn];
      for(ldtm2 = ldir[j]; j != ldtm2; ++j){
         sn2 = sn + nbr[j];
         if(sn2 == s)continue;
         if(board[sn2] == NOGROUP)continue;
         gflag = FALSE;
         for(l = 0; l != k; ++l)
            if(grp[l] == board[sn2])gflag = TRUE;
         if(gflag)continue;
         if(board[sn2] != g){
            grp[k++] = board[sn2];
            }
         else cflag = TRUE;
         }
      if(!cflag)
         for(j = 0; j != k; ++j)
            if(grcolor[grp[j]] == c)addconn(grp[j],g,sn);
      }
   }
Пример #3
0
void portthread (void * port_ptr)
{
 SOCKET s;
 BT_PORT port_info ;

 port_info = *(BT_PORT*) port_ptr ;

 s = bt_listen (port_info.port);

 if (!s)
  _endthread();

 while (1)
 {
  socklen_t addrlen = sizeof(SOCKADDR_IN);
  SOCKADDR_IN addr ; 
  SOCKET client_sock;
  BT_CLIENT * client ;
  char reason, *ip;

  client_sock = accept (s, (SOCKADDR*) &addr, &addrlen);

  if (client_sock == -1)
   continue;

  ip = inet_ntoa (addr.sin_addr);

  if ((reason = allow(ip)) <= 0)
  {
   switch (reason)
   {
   case 0:
	logevent("Refused %s:%i (filter)", 
	 ip,port_info.port);
	break;
   case -1:
	logevent("Refused %s:%i (connection limit)", 
	 ip,port_info.port);
	break;
   case -2:
	logevent("Refused %s:%i (clone limit)", 
	 ip,port_info.port);
	break;
   }
   bt_close(client_sock);
   continue;
  }

  client = addconn(ip,port_info.port);
  client->sock = client_sock;
  client->use_pass = port_info.use_pass ;

  if (client->use_pass)
   bt_cpy (client->password, port_info.password);

  if (_beginthread (proxythread,0,client) == -1)
  {
   logevent ("Could not create proxy thread for %s:%i",
	client->ip,client->port);

   bt_close(client->sock);
   delconn(client);

   _endthread();
  }
 }

 _endthread();
}