[M3] 俄羅斯方塊(單人版)每周20強更新付程序
說明:為保持俄羅斯方塊單人版前20名的時效性,增加本
      程序,放在 crontab 中每周運行一次,將本周的排行
      紀錄寄回,然後清空。
      crontab文件 增加下兩行:
# 每周日清空 tetirs top
0 0 * * 0 bin/reset_tetris_top
::: src/util/reset_tetris_top.c :::
程序中的 BRD_ACCOUNT 是站內保存記錄的看版。一般為 "Bulletin"
/*-------------------------------------------------------*/
/* reset_tetris_top.c    ( Hightman MapleBBS Ver 3.10 )  */
/*-------------------------------------------------------*/
/* author : hightman.bbs@bbs.hightman.net                */
/* target : Tetris Fight  dynamic link module             */
/* create : 02/09/20                                     */
/* update :   /  /                                       */
/*-------------------------------------------------------*/
#include "bbs.h"
#define FN_TETRIS_REC           "game/tetris.top"
typedef struct {
    char userid[IDLEN + 1];
    int lines;
    int scores;
} TOP_LIST;
int
main()
{
    char folder[128], fpath[128];
    int fd, fe;
    FILE *fp;
    HDR hdr;
    setgid(BBSGID);
    setuid(BBSUID);
    chdir(BBSHOME);
    sprintf(folder, "brd/%s/%s", BRD_ACCOUNT, FN_DIR);
    fd = hdr_stamp(folder, 'A', &hdr, fpath);
    if (fd < 0)
        return;
    fp = fdopen(fd, "w");
    fprintf(fp, "作者: SYSOP (明月使者)\n標題: 本周Tetris 20大高手排行\n時間: %s\n\n", Ctime(&hdr.chrono));
    fprintf(fp, "         \033[1;33;44m == %s 本周俄羅斯方塊高手榜 ==\033[m\n", BOARDNAME);
    if ((fe = open(FN_TETRIS_REC, O_RDONLY)) >= 0)
    {
        TOP_LIST top;
        int i = 0;
        while (read(fe, &top, sizeof(TOP_LIST)) == sizeof(TOP_LIST))
            fprintf(fp, "     %2d  %-14s  %6d 分 %6d 條\n", ++i, top.userid, top.scores, top.lines);
        close(fe);
    }
    fclose(fp);
    close(fd);    
    strcpy(hdr.title, "本周俄羅斯方塊 20大高手排行");
    strcpy(hdr.owner, "SYSOP");
    strcpy(hdr.nick, "明月使者");
    rec_add(folder, &hdr, sizeof(HDR));
    unlink(FN_TETRIS_REC);
    return 0;
}
--
※ 來源:.溫馨小屋 bbs.feeling.smth.org.[FROM: lib.zju.edu.cn]
Maple 近期熱門文章
PTT數位生活區 即時熱門文章