Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	struct boardheader fh, newfh;
	int pos;

	if (argc != 3)
	{
		fprintf(stderr, "Usage: %s --force <board>\n", argv[0]);
		exit(-1);
	}
	if (strcmp(argv[1], "--force"))
	{
		fprintf(stderr, "Usage: %s --force <board>\n", argv[0]);
		exit(-1);
	}
	chdir(BBSHOME);
	resolve_boards();

    pos = getboardnum(argv[2], &fh);
	if (pos == 0)
	{
		fprintf(stderr, "%s not found.\n", argv[2]);
		exit(-1);
	}
	memcpy(&newfh, &fh, sizeof(newfh));
	/*newfh.flag |= BOARD_SUPER_CLUB;*/
	set_board(pos, &newfh, &fh);

	return 0;
}
Ejemplo n.º 2
0
GTPResponse GTP::gtp_clearboard(vecstr args){
	hist.clear();
	set_board();
	time_control.new_game();

	return GTPResponse(true);
}
Ejemplo n.º 3
0
void
Puzzle::set_components(const Board &board_arg,
                       const std::vector<Piece> &pieces_arg, bool piece_flip_flag_arg) {
    set_board(board_arg);
    set_pieces(pieces_arg);
    set_piece_flip_flag(piece_flip_flag_arg);
}
Ejemplo n.º 4
0
void
Puzzle::set_components(const Board &board_arg, const Piece *pieces_arg,
                       std::size_t piece_count, bool piece_flip_flag_arg) {
    set_board(board_arg);
    set_pieces(pieces_arg, piece_count);
    set_piece_flip_flag(piece_flip_flag_arg);
}
Ejemplo n.º 5
0
Puzzle::Puzzle(const Board &board_arg, const Piece *pieces_arg,
               std::size_t piece_count, bool piece_flip_flag_arg)
    : board(), pieces(), piece_flip_flag(true) {
    set_board(board_arg);
    set_pieces(pieces_arg, piece_count);
    set_piece_flip_flag(piece_flip_flag_arg);
}
Ejemplo n.º 6
0
Puzzle::Puzzle(const Board &board_arg, std::vector<Piece> &pieces_arg,
               bool piece_flip_flag_arg)
    : board(), pieces(), piece_flip_flag(true) {
    set_board(board_arg);
    set_pieces(pieces_arg);
    set_piece_flip_flag(piece_flip_flag_arg);
}
Ejemplo n.º 7
0
GTPResponse HavannahGTP::gtp_clearboard(vecstr args){
	game.clear();
	set_board();

	time_remain = time.game;

	log("clear_board");
	return GTPResponse(true);
}
Ejemplo n.º 8
0
GTPResponse GTP::gtp_undo(vecstr args){
	int num = (args.size() >= 1 ? from_str<int>(args[0]) : 1);

	while(num--){
		hist.undo();
	}
	set_board(false);
	if(verbose >= 2)
		logerr(hist->to_s(colorboard) + "\n");
	return GTPResponse(true);
}
Ejemplo n.º 9
0
GTPResponse HavannahGTP::gtp_undo(vecstr args){
	int num = 1;
	if(args.size() >= 1)
		num = from_str<int>(args[0]);

	while(num--){
		game.undo();
		log("undo");
	}
	set_board(false);
	if(verbose >= 2)
		logerr(game.getboard().to_s(colorboard) + "\n");
	return GTPResponse(true);
}
Ejemplo n.º 10
0
GTPResponse HavannahGTP::gtp_boardsize(vecstr args){
	if(args.size() != 1)
		return GTPResponse(false, "Current board size: " + to_str(game.getsize()));

	log("boardsize " + args[0]);

	int size = from_str<int>(args[0]);
	if(size < 3 || size > 10)
		return GTPResponse(false, "Size " + to_str(size) + " is out of range.");

	game = HavannahGame(size);
	set_board();

	time_remain = time.game;

	return GTPResponse(true);
}
Ejemplo n.º 11
0
GTPResponse GTP::gtp_load_sgf(vecstr args){
	if(args.size() == 0)
		return GTPResponse(true, "load_sgf <filename>");

	std::ifstream infile(args[0].c_str());

	if(!infile) {
		return GTPResponse(false, "Error opening file " + args[0] + " for reading");
	}

	SGFParser<Move> sgf(infile);
	if(sgf.game() != Board::name){
		infile.close();
		return GTPResponse(false, "File is for the wrong game: " + sgf.game());
	}

	int size = sgf.size();
	if(size != hist->get_size()){
		if(hist.len() == 0){
			hist = History(size);
			set_board();
			time_control.new_game();
		}else{
			infile.close();
			return GTPResponse(false, "File has the wrong boardsize to match the existing game");
		}
	}

	Side s = Side::P1;

	while(sgf.next_node()){
		Move m = sgf.move();
		move(m); // push the game forward
		s = ~s;
	}

	if(sgf.has_children())
		agent->load_sgf(sgf);

	assert(sgf.done_child());
	infile.close();
	return true;
}
Ejemplo n.º 12
0
int main() {
    char line[100];

    while (fgets(line, 100, stdin) != NULL) {
        line[strlen(line) -1] = '\0';

        set_board(line);

        mark_board(line);

        int unoccupied = 0;
        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++){
                unoccupied += !board[i][j];
            }
        }

        printf("%d\n", unoccupied);
    }
    return 0;
}
Ejemplo n.º 13
0
static READ8_HANDLER( supercon_port3_r )
{
	supercon_state *state = space->machine().driver_data<supercon_state>();
	int i;
	UINT8 key_data=0;

	static const char *const status_lines[8] =
			{ "STATUS_1", "STATUS_2", "STATUS_3", "STATUS_4", "STATUS_5", "STATUS_6", "STATUS_7", "STATUS_8" };

	LOG(("Read from %04x \n",0x1E00));

/* remove last bit (only if it was not already set) */

	if ( state->m_data_1F00 & LED_LINE_AH )
	{
		if (state->m_last_LED_value != state->m_LED_AH)
			state->m_LED_AH=state->m_LED_AH & ~state->m_data_1E00;
	}
	else if ( state->m_data_1F00 & LED_LINE_ST)
	{
		if (state->m_last_LED_value != state->m_LED_ST)
			state->m_LED_ST=state->m_LED_ST & ~state->m_data_1E00;
	}
	else if ( state->m_data_1F00 & LED_LINE_18 )
	{
		if (state->m_last_LED_value != state->m_LED_18)
			state->m_LED_18=state->m_LED_18 & ~state->m_data_1E00;
	}


	LOG(("LED_18 from %02x \n",state->m_LED_18));
	LOG(("LED_AH from %02x \n",state->m_LED_AH));
	LOG(("LED_ST from %02x \n",state->m_LED_ST));

	if (state->m_led_update)			/*No LED Update if Port 1C00,1D00 was read */
		update_leds(state);

	state->m_remove_led_flag=TRUE;
	state->m_led_update=TRUE;

	state->m_LED_18=0;
	state->m_LED_AH=0;
	state->m_LED_ST=0;


/* Start */

	if (!state->m_emu_started)
		return 0xbf;
	else
		state->m_timer_update_irq->adjust( attotime::zero, 0, attotime::from_hz(598) );  //HACK adjust timer after start ???


/* Buttons */

	i=get_first_bit(state->m_data_1E00);
	if (i==NOT_VALID)
		return 0xff;

	key_data=input_port_read(space->machine(), status_lines[i]);

	if (key_data != 0xc0)
	{
		LOG(("%s, key_data: %02x \n",status_lines[i],key_data));

/* Button: New Game -> initialize board */

		if (i==0 && key_data==0x80)
		{
			set_board(state);
			set_pieces(state);

			state->m_emu_started=FALSE;
		}

/* Button: Clear Board -> remove all pieces */

		if (i==3 && key_data==0x80)
			clear_pieces(state);

		if (key_data != 0xff )
			return key_data;

	}

	return 0xc0;
}
Ejemplo n.º 14
0
/* Search thread main function */
void *search_loop(void *arg) {
    uint8_t ply;
    move_t mv, mv_tmp;

    SET_BLANK_MOVE(mv);
    SET_BLANK_MOVE(mv_tmp);

    pthread_mutex_lock(&mutex);

    /* Initializations */
    precompute_moves();
    precompute_distances();
    init_zobrist_keys();
    init_history();
    init_transposition_table();
    config_alarm(config->max_seconds);
    max_depth = config->max_depth;

    /* Setup board */
    board = set_board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
    if(board == NULL)
    	quit("Error: Could not setup new board!\n");

    /* ECO = encyclopedia of chess openings */

    if(atoi(config->name) >= 50)
        if(!load_eco(board))
            quit("Error: Could not load Encyclopedia of Chess Openings!\n");

    pthread_mutex_unlock(&mutex);
 
    /* Keep alive until the status changes to QUIT */
    while(status != QUIT) {
    	switch(status) {
    	case NOP:
    	    /* NOP: just wait for a change in status */
    	    pthread_mutex_lock(&mutex);
    	    while(status == NOP)
    	    	pthread_cond_wait(&cond, &mutex);
    	    pthread_mutex_unlock(&mutex);
    	    break;
    	case FORCE:
    	    /* FORCE: wait for a change in status but don't start searches */
    	    pthread_mutex_lock(&mutex);
    	    while(status == FORCE)
    	    	pthread_cond_wait(&cond, &mutex);
    	    pthread_mutex_unlock(&mutex);
    	    break;
    	case SEARCH:
    	    /* Iterative Deepening Search */
    	    /* Save the on-move color */
    	    onmove = board->onmove;
    	    /* Sets as blank the move to be played*/
    	    SET_BLANK_MOVE(mv);
    	    /* Starts counting the time */
    	    start_alarm();
    	    /* For each depth, search with alpha-beta minimax */
    	    for(ply = 2; ply <= max_depth; ply += 2) {
    	    	mv_tmp = alpha_beta(board, -MAX_HEU, MAX_HEU, ply);
    	    	/* Did we run out of time? If so, stops deepening iterations */
    	    	if(get_timeout())
    	    	    break;
    	    	mv = mv_tmp;
    	    }
    	    /* Stops counting the time, if it hasn't already reached limit */
    	    stop_alarm();
    	    /* If the move is still blank, use the partial move found */
    	    if(IS_BLANK_MOVE(mv))
    	    	mv = mv_tmp;
    	    /* Perform the move found in the search */
    	    move(board, mv);
    	    /* Returns to the NOP status */
    	    set_status(NOP);
    	    break;
    	case PONDER:
    	    /* Reserved for future use */
    	    set_status(NOP);
    	    break;
    	default:
    	    quit("Error: Invalid search status!\n");
    	}
    }
    
    /* Clean up memory */
    clear_eco();
    clear_transposition_table();
    clear_history();
    clear_board(board);

    /* Exit Search Thread */
    return NULL;
}
Ejemplo n.º 15
0
static void
user_login()
{
	char		genbuf    [200];
	struct tm      *ptime, *tmp;
	time_t		now = time(0);
	int		a;

	extern struct FROMCACHE *fcache;
	extern int	fcache_semid;

	log_usies("ENTER", fromhost);
	setproctitle("%s: %s", cuser.userid, fromhost);

	/* ------------------------ */
	/* 初始化 uinfo、flag、mode */
	/* ------------------------ */

	setup_utmp(LOGIN);
	currmode = MODE_STARTED;
	enter_uflag = cuser.uflag;

	/* get local time */
	tmp = localtime(&cuser.lastlogin);

	update_data();		/* wildcat: update user data */
	/* Ptt check 同時上線人數 */
	resolve_fcache();
	resolve_utmp();

	if ((a = utmpshm->number) > fcache->max_user) {
		sem_init(FROMSEM_KEY, &fcache_semid);
		sem_lock(SEM_ENTER, fcache_semid);
		fcache->max_user = a;
		fcache->max_time = now;
		sem_lock(SEM_LEAVE, fcache_semid);
	}
#ifdef  INITIAL_SETUP
	if (getbnum(DEFAULT_BOARD) == 0) {
		strcpy(currboard, "尚未選定");
	} else
#endif

	{
		brc_initial(DEFAULT_BOARD);
		set_board();
	}

	/* ------------ */
	/* 畫面處理開始 */
	/* ------------ */

	if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) {
		char		buf       [256];
		time_t		now;

		time(&now);
		sprintf(buf, "<<上站通知>> -- 我來囉! - %s", Etime(&now));
		do_aloha(buf);
	}
	time(&now);
	ptime = localtime(&now);

#ifdef CAMERA
	film_out(FILM_LOGIN, 0);
#else
	more("etc/Welcome_login", NA);
#endif

#if 0
	/* wildcat : 搬家通知用 */
	if (belong(BBSHOME "/etc/oldip", fromhost)) {
		more(BBSHOME "/etc/removal");
		abort_bbs();
	}
#endif

	if ((cuser.day == ptime->tm_mday) && (cuser.month == (ptime->tm_mon + 1)))
		currutmp->birth = 1;
	else
		currutmp->birth = 0;

	if (cuser.userlevel) {	/* not guest */
		move(t_lines - 3, 0);
		prints("      歡迎您第 %d 度拜訪本站,\
上次您是從 %s 連往本站,\n\
     我記得那天是 %s。\n",
		       ++cuser.numlogins, cuser.lasthost,
		       Etime(&cuser.lastlogin));
		pressanykey(NULL);


		/* Ptt */
		if (currutmp->birth == 1) {
#ifdef CAMERA
			film_out(FILM_WEL_BIRTH, 0);
#else
			more("etc/Welcome_birth", YEA);
#endif
			brc_initial("Greeting");
			set_board();
			do_post();
		}
		sethomefile(genbuf, cuser.userid, str_badlogin);
		if (more(genbuf, NA) != -1) {
			if (getans2(b_lines, 0, "您要刪除以上錯誤嘗試的記錄嗎?", 0, 2, 'y') != 'n')
				unlink(genbuf);
		}
		check_register();
		strncpy(cuser.lasthost, fromhost, 24);
		substitute_record(fn_passwd, &cuser, sizeof(cuser), usernum);
		cuser.lasthost[23] = '\0';
		restore_backup();
	}
Ejemplo n.º 16
0
int start_game(){
  char board[ BOARD_HEIGHT ][ BOARD_WIDTH ];
  char mtx_brick[4][4];
  int score = 0;
  int level = 0;
  int lines = 0;
  int tmp_lines = 0;
  char x, y;
  char brick;
  char next_brick;
  int vel = 10;
  timespec req;
  req.tv_sec = 0;
  req.tv_nsec = vel * PULSE;

  srand( time( 0 ) );
  memset( board, 0, BOARD_HEIGHT * BOARD_WIDTH );
  next_brick = rand() % 7 + 1;

  init_screen();

  WINDOW* wboard   = create_wboard();
  WINDOW* wpreview = create_wpreview();
  WINDOW* wscore   = create_wscore();

  show_title();
  show_score( wscore, score, level, lines );

  wait_start( wboard );

  bool play = true;
  while( play ){
    brick = next_brick;
    next_brick = rand() % 7 + 1;

    show_preview( wpreview, next_brick );
    show_score( wscore, score, level, lines );
    show_board( wboard, board );

    x = ( ( BOARD_WIDTH / 3 ) % 2 == 0 ) ? BOARD_WIDTH / 3 : BOARD_WIDTH / 3 + 1;
    y = - 3;
    
    get_brick( brick, mtx_brick );

    bool move = true;
    int delay = 0;
    while( move ){
      switch( getch() ){
      case KEY_UP:
        move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break;
      case 'z':
        move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break;
      case 'x':
        move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_L ); break;
      case KEY_DOWN:
        move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN     ); break;
      case KEY_LEFT:
        move_brick( wboard, board, mtx_brick, brick, &y, &x, LEFT     ); break;
      case KEY_RIGHT:
        move_brick( wboard, board, mtx_brick, brick, &y, &x, RIGHT    ); break;
      case ' ':
        move_brick( wboard, board, mtx_brick, brick, &y, &x, BOTTOM   ); break;
      case 27:  play = move = false; break;
      case 'q': play = move = false; break;
      default: break;
      } // switch( getch() )

      if( ++delay == DELAY_DOWN ){
        move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN    );
      }
      if( delay == DELAY_BOTTOM ){
        delay = 0;
        if( check_brick(mtx_brick, board, y + 1, x ) ){
          move = false;
          if( y < 0 ) play = false;
        }
      }

      nanosleep( &req, 0 );
    } // while( move )

    set_board( board, mtx_brick, brick, y, x );
    tmp_lines += check_lines( board, &score, &lines );

    if( tmp_lines >= CH_LEV ){
      req.tv_nsec = vel * PULSE;
      score += 1;
      level++;
      if( vel > 1 ) vel--;
      tmp_lines = tmp_lines % CH_LEV;
    }

  }   // while( quit )

  delwin( wboard );
  delwin( wpreview );
  delwin( wscore );

  restore_screen();
  return 0;
}
Ejemplo n.º 17
0
int generate_board_title(struct boardheader *bh,void* arg)
{
    int fd2, size = sizeof(fileheader), total, i;
    struct boardheader btmp;
    char olddirect[PATHLEN];
    char *ptr, *t, *t2;
#ifdef GEN_ORIGIN
    FILE *fp=NULL;
    char opath[512];
#endif
    struct fileheader * ptr1;
    struct search_temp {
        bool has_pre;
        int digest;
        int thread_id;
        int id;
        int next;
    } *index=NULL;
    struct stat buf;
    int gen_threadid;
    struct BoardStatus* bs;

#ifdef GEN_ORIGIN
    setbdir(DIR_MODE_ORIGIN, opath, bh->filename);
#endif
    setbdir(DIR_MODE_NORMAL, olddirect, bh->filename);

    gen_threadid=1;
    if ((fd2 = open(olddirect, O_RDWR, 0664)) == -1) {
        perror(olddirect);
        return 0;
    }

    BBS_TRY {
        if (!safe_mmapfile_handle(fd2,PROT_READ|PROT_WRITE,MAP_SHARED,&ptr,&buf.st_size)) {
            close(fd2);
            return 0;
        }
#ifdef GEN_ORIGIN
        fp = fopen(opath, "wb");
#endif
        total = buf.st_size / size;
        index = (struct search_temp *) malloc(sizeof(*index) * total);
        ptr1 = (struct fileheader *) ptr;
        for (i = 0; i < total; i++, ptr1++) {
            int j;

            t2 = ptr1->title;
            if (!strncmp(t2, "Re:", 3)) {
                index[i].has_pre = true;
                t2 += 4;
            } else
                index[i].has_pre = false;
            index[i].thread_id = 0;
            index[i].digest = simple_digest(t2, ARTICLE_TITLE_LEN);
            for (j = i - 1; j >= 0; j--) {
                struct fileheader *tmppost;

                if (index[j].digest != index[i].digest)
                    continue;
                tmppost = ((struct fileheader *)(ptr + j * size));
                t = tmppost->title;
                if (index[j].has_pre)
                    t += 4;
                if (!strcmp(t, t2)) {
                    index[j].next = i;
                    index[i].thread_id = index[j].thread_id;
                    index[i].next = 0;
                    break;
                }
            }
            if (index[i].thread_id == 0) {
                index[i].thread_id = gen_threadid;
                index[i].id = gen_threadid;
                index[i].next = 0;
                gen_threadid++;
            } else {
                index[i].id = gen_threadid;
                gen_threadid++;
            }
        }
        ptr1 = (struct fileheader *) ptr;
        for (i = 0; i < total; i++, ptr1++) {
            ptr1->id = index[i].id;
            ptr1->groupid = index[i].thread_id;
            ptr1->reid = index[i].thread_id;
#ifdef GEN_ORIGIN
            if (index[i].has_pre == false)
                fwrite(ptr1, 1, sizeof(struct fileheader), fp);
#endif
        }
    }
    BBS_CATCH {
    }
    BBS_END;
    free(index);
    end_mmapfile((void *) ptr, buf.st_size, -1);
    close(fd2);
#ifdef GEN_ORIGIN
    fclose(fp);
#endif
    memcpy(&btmp,getbcache(bh->filename),sizeof(btmp));
    bs=getbstatus(getbid(bh->filename,NULL));
    bs->nowid=gen_threadid + 1;
    set_board(getbid(bh->filename,NULL), &btmp,NULL);
    setboardmark(bh->filename, 1);
    setboardtitle(bh->filename, 1);
    setboardorigin(bh->filename, 1);
    return 0;
}
Ejemplo n.º 18
0
char		pose(t_board *board, t_pos *move, char current, char rules)
{
    int		i;
    char		get;
    int		iget;


    /* printf("At %i-%i: ", cor.move->x, cor.move->y); */

    // Pose
    get = get_board(board, move->x, move->y);
    if ((get == EMPTY) &&
            (!(rules & RULE3) || (rule3(board, move->x, move->y, current))))
    {
        set_board(board, move->x, move->y, current);
        printf("Placed a ");
        if (current == BLACK)
        {
            printf("Black");
            current = WHITE;
        }
        else
        {
            printf("White");
            current = BLACK;
        }
        printf(" Stone at %i:%i\n", move->x, move->y);

        // Prise
        iget = getprise(board, move->x, move->y, current);
        if (iget)
        {
            printf("Taken %i ", iget*2);
            if (current == BLACK)
            {
                board->blacks += iget;
                printf("Black Stones (%i total)\n", board->blacks*2);
            }
            else
            {
                board->whites += iget;
                printf("Whites Stones (%i total)\n", board->whites*2);
            }
            prise(board, move->x, move->y, current);
        }

        // Règle de 5
        // (rules & RULE5) &&
        for (i = 0; i < 19*19; i++)
        {
            move->x = i / 19;
            move->y = i % 19; //
            if ((get_board(board, move->x, move->y) == OPPOSITE(current)) && (rule5(board, move->x, move->y, OPPOSITE(current), rules)))
            {
                if (current == WHITE)
                    printf("Blacks wins with a row!\n");
                if (current == BLACK)
                    printf("Whites wins with a row!\n");
                return (OPPOSITE(current) + 10);
            }
        }

    }
    else
    {
        printf("There's ");
        switch (get)
        {
        case BLACK:
            printf("a Black Stone");
            break;
        case WHITE:
            printf("a White Stone");
            break;
        case EMPTY:
            printf("nothing");
            break;
        }
        printf(" at %i:%i\n", move->x, move->y);
    }


    return (current);
}
Ejemplo n.º 19
0
/*主函数*/
int main(int argc,char **argv)
{
    FILE *fp;
    struct stat st;
    struct fileheader *dir1,*dir2,*dir;
    struct boardheader bh;
    struct BoardStatus *bs;
    char path1[512],path2[512],path[512],buf[512],*p1,*p2,*p;
    int ret;
    unsigned int size1,size2,pos1,pos2,pos,*offset1,*offset2;
    //初始化及错误检测
    if (argc!=4) {
        printf("[%s] 错误的参数结构...\nUSAGE: %s <srcboard1> <srcboard2> <dstdir>\n",argv[0],argv[0]);
        return 0x11;
    }
    if (chdir(BBSHOME)) {
        printf("[%s] 切换到 BBS 主目录 %s 错误...\n",argv[0],BBSHOME);
        return 0x12;
    }
    /*初始化源版面数据*/
    if ((ret=initdir(argv[0],path1,argv[1],&offset1,&size1,&dir1,&p1))!=0)
        return ret;
    if ((ret=initdir(argv[0],path2,argv[2],&offset2,&size2,&dir2,&p2))!=0)
        return ret;
    /*检测顺序并进行可能必要的顺序化*/
    if (!checkseq(dir1,size1)&&!seqdir(dir1,size1)) {
        printf("[%s] 版面 %s .DIR 结构错误, 修复失败...\n",argv[0],argv[1]);
        return 0x51;
    }
    if (!checkseq(dir2,size2)&&!seqdir(dir2,size2)) {
        printf("[%s] 版面 %s .DIR 结构错误, 修复失败...\n",argv[0],argv[2]);
        return 0x51;
    }
    /*创建目标目录,用pid进行标识区分*/
    sprintf(path,"boards/%s",argv[3]);
    sprintf(buf,"boards/%s_%d",argv[3], (int)getpid());
    if (!stat(path,&st)&&S_ISDIR(st.st_mode))
        rename(path,buf);
    else
        unlink(path);
    if (mkdir(path,(S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH))) {
        printf("[%s] 创建版面目录 %s 错误...\n",argv[0],path);
        return 0x31;
    }
    build_board_structure(argv[3]);
    p=path+strlen(path);*p++='/';
    sprintf(p,".DIR");
    /*准备目标.DIR文件的写操作*/
    if (!(fp=fopen(path,"wb"))) {
        printf("[%s] 创建 %s 错误...\n",argv[0],path);
        return 0x32;
    }
    /*申请目标.DIR结构需要的内存空间*/
    if (!(dir=(struct fileheader*)malloc((size1+size2)*sizeof(struct fileheader)))) {
        printf("[%s] 申请内存空间失败...\n",argv[0]);
        return 0x33;
    }
    //主处理
    pos1=0;pos2=0;pos=0;
    while (true) {
        /*比较时间戳*/
        if (pos1<size1&&pos2<size2) {
            //ret=strcmp(&dir1[pos1].filename[2],&dir2[pos2].filename[2]);
            ret = get_posttime(&dir1[pos1]) - get_posttime(&dir2[pos2]);
        } else if (pos1<size1)/*源版面2已经处理完成*/
            ret=-1;
        else if (pos2<size2)/*源版面1已经处理完成*/
            ret=1;
        else/*done*/
            break;
        /*处理当前fileheader*/
        if (!(ret>0)) {/*源版面1*/
            process(argv[0],dir,dir1,offset1,pos,pos1,path,p,path1,p1);
            pos1++;pos++;
        } else {/*源版面2*/
            process(argv[0],dir,dir2,offset2,pos,pos2,path,p,path2,p2);
            pos2++;pos++;
        }
    }
    /*写回目的.DIR*/
    if (fwrite(dir,sizeof(struct fileheader),(size1+size2),fp)!=(size1+size2)) {
        printf("[%s] 写入文件错误...\n",argv[0]);
        return 0x41;
    }
    /*设定未读标记*/
    resolve_boards();
    ret=getboardnum(argv[3],&bh);
    if (ret) {
        bh.idseq=size1+size2;
        set_board(ret,&bh,NULL);
        bs=getbstatus(ret);
        bs->total=size1+size2;
        bs->lastpost=size1+size2;
        bs->updatemark=true;
        bs->updatetitle=true;
        bs->updateorigin=true;
        bs->nowid=size1+size2;
        bs->toptitle=0;
    }
    /*清理*/
    fclose(fp);
    munmap(dir1,size1*sizeof(struct fileheader));
    if (size1)
        free(offset1);
    munmap(dir2,size2*sizeof(struct fileheader));
    if (size2)
        free(offset2);
    free(dir);
    return 0;
}
Ejemplo n.º 20
0
static void user_login() {
    char ans[4], i;
    char genbuf[200];
    struct tm *ptime, *tmp;
    time_t now;
    int a;
    /*** Heat:廣告詞
	 char *ADV[17] = {
	 "記得唷!! 5/12在台大二活地下室見~~~",
	 "你知道Ptt之夜是什麼嗎? 5/12號就要上演耶 快去問吧!",
	 "5/12 Ptt之夜即將引爆 能不去嗎? 在台大二活地下室咩",
	 "不來就落伍了 啥? 就Ptt之夜啊 很棒的晚會唷 時間:5/12",
	 "差點忘了提醒你 5/12我們有約 就台大二活地下室咩!!",
	 "Ptt是啥 想知嗎? 5/12在台大二活地下室告訴你唷",
	 "來來來....5/12快到台大二活地下室去拿獎品吧~~",
	 "去去去...到台大二活地下室去 就5/12麻 有粉多獎品耶",
	 "喂喂喂 怎還楞在這!!快呼朋引伴大鬧ptt",
	 "Ptt最佳豬腳 換你幹幹看 5/12來吧....*^_^*",
	 "幹什麼幹什麼?? 你怎麼不曉得啥是Ptt之夜..老土唷",
	 "累了嗎? 讓我們來為你來一段精采表演吧.. 5/12 Ptt之夜",
	 "世紀末最屁力的晚會 就在台大二活地下室 5/12不見不散 gogo",
	 "到底誰比較帥(美) 來比比吧 5/12Ptt之夜 一較高下",       
	 "台大二活地下室 5/12 聽說會有一場很棒的晚會唷 Ptt之夜",
	 "台大二活地下室 5/12 你能不來嗎?粉多網友等著你耶",
	 "5/12 台大二活地下室 是各約網友見面的好地方呢",
	 }; 
	 char *ADV[] = {
	 "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!",
	 "欲知詳情請看 PttAct 板!!",
	 }; ***/

    log_usies("ENTER", getenv("RFC931") /* fromhost */ );
    setproctitle("%s: %s", margs, cuser.userid);
    
    /* resolve all cache */
    resolve_garbage();	/* get ptt cache */
    resolve_fcache();
    resolve_boards();
    
    /* 初始化 uinfo、flag、mode */
    setup_utmp(LOGIN);
    mysrand();		/* 初始化: random number 增加user跟時間的差異 */
    currmode = MODE_STARTED;
    enter_uflag = cuser.uflag;

    /* get local time */
    time(&now);
    ptime = localtime(&now);
    tmp = localtime(&cuser.lastlogin);
    
    if((a = utmpshm->number) > fcache->max_user) {
	sem_init(FROMSEM_KEY, &fcache_semid);
	sem_lock(SEM_ENTER, fcache_semid);
	fcache->max_user = a;
	fcache->max_time = now;
	sem_lock(SEM_LEAVE, fcache_semid);
    }
#ifdef INITIAL_SETUP
    if(!getbnum(DEFAULT_BOARD)) {
	strcpy(currboard, "尚未選定");
    } else
#endif
    {
	brc_initial(DEFAULT_BOARD);
	set_board();
    }

    /* 畫面處理開始 */
    if(!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)))
	do_aloha("<<上站通知>> -- 我來啦!");
    if(ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) {
	more("etc/Welcome_birth", NA);
	currutmp->birth = 1;
    } else {
	more("etc/Welcome_login", NA);
//	pressanykey();
//    more("etc/CSIE_Week", NA);
	currutmp->birth = 0;
    }
    
    if(cuser.userlevel) {	/* not guest */
	move(t_lines - 4, 0);
	prints("      歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站,"
	       "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n"
	       "     我記得那天是 \033[1;33m%s\033[0;37m。\n",
	       ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin));
	currutmp->mind=rand()%8;  /* 初始心情 */
	pressanykey();
 	
	if(currutmp->birth && tmp->tm_mday != ptime->tm_mday) {
	    more("etc/birth.post", YEA);
	    brc_initial("WhoAmI");
	    set_board();
	    do_post();
	}
	setuserfile(genbuf, str_badlogin);
	if(more(genbuf, NA) != -1) {
	    getdata(b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]",
		    ans, 3, LCECHO);
	    if(*ans != 'n')
		unlink(genbuf);
	}
	check_register();
	strncpy(cuser.lasthost, fromhost, 16);
	cuser.lasthost[15] = '\0';
	restore_backup();
    } else if(!strcmp(cuser.userid, STR_GUEST)) {
	char *nick[13] = {
	    "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚",
	    "樹葉", "浮萍", "鞋子", "潛水艇", "魔王",
	    "鐵罐", "考卷", "大美女"};
	char *name[13] = {
	    "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚",
	    "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢",
	    "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲"};
	char *addr[13] = {
	    "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁",
	    "遠方", "原本海", "NIKE", "蘇聯", "男八618室",
	    "愛之味", "天上", "藍色珊瑚礁"};
	i = login_start_time % 13;
	sprintf(cuser.username, "海邊漂來的%s", nick[(int)i]);
	sprintf(currutmp->username, cuser.username);
	sprintf(cuser.realname, name[(int)i]);
	sprintf(currutmp->realname, cuser.realname);
	sprintf(cuser.address, addr[(int)i]);
	cuser.sex = i % 8;
	currutmp->pager = 2;
	pressanykey();
    } else
	pressanykey();
    
    if(!PERM_HIDE(currutmp))
	cuser.lastlogin = login_start_time;
    
    reload_money();
    passwd_update(usernum, &cuser);
    
    for(i = 0; i < NUMVIEWFILE; i++)
	if((cuser.loginview >> i) & 1)
	    more(loginview_file[(int)i][0], YEA);
	
	
}