diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-08-12 21:03:28 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-08-12 21:03:28 +0800 |
commit | 2d360031b079b8f6181d1d5e244d617dd47cefe8 (patch) | |
tree | 31b390dc08dd62bd7b26ad430a07f23f4f9be511 | |
parent | 83ded54df48fa434f77831bb8280603973e2e989 (diff) | |
download | pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.tar pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.tar.gz pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.tar.bz2 pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.tar.lz pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.tar.xz pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.tar.zst pttbbs-2d360031b079b8f6181d1d5e244d617dd47cefe8.zip |
Chess country basic things constructing.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2162 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | include/pttstruct.h | 7 | ||||
-rw-r--r-- | mbbsd/admin.c | 20 | ||||
-rw-r--r-- | mbbsd/osdep.c | 2 | ||||
-rw-r--r-- | mbbsd/stuff.c | 2 | ||||
-rw-r--r-- | util/Makefile | 3 | ||||
-rw-r--r-- | util/chesscountry.c | 183 |
7 files changed, 215 insertions, 4 deletions
diff --git a/include/proto.h b/include/proto.h index 36f8f59e..905b8502 100644 --- a/include/proto.h +++ b/include/proto.h @@ -476,7 +476,7 @@ int dashf(char *fname); void sethomepath(char *buf, char *userid); void sethomedir(char *buf, char *userid); char *Cdate(time_t *clock); -void sethomefile(char *buf, char *userid, char *fname); +void sethomefile(char *buf, char *userid, const char *fname); int log_file(char *fn, int flag, const char *fmt,...); void str_lower(char *t, char *s); void *strstr_lower(char *str, char *tag); diff --git a/include/pttstruct.h b/include/pttstruct.h index 1134586c..ce58a08e 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -140,6 +140,7 @@ typedef struct boardheader_t { char title[BTLEN + 1]; char BM[IDLEN * 3 + 3]; /* BMs' userid, token '/' */ unsigned int brdattr; /* board的屬性 */ + char chesscountry; char pad[3]; /* 沒用到的 */ time_t bupdate; /* note update time */ char pad2[3]; /* 沒用到的 */ @@ -181,6 +182,12 @@ typedef struct boardheader_t { #define BRD_LINK_TARGET(x) ((x)->postexpire) #define GROUPOP() (currmode & MODE_GROUPOP) +#ifdef CHESSCOUNTRY +#define CHESSCODE_NONE 0 +#define CHESSCODE_FIVE 1 +#define CHESSCODE_CCHESS 2 +#define CHESSCODE_MAX 2 +#endif /* defined(CHESSCOUNTRY) */ #define TTLEN 64 /* Length of title */ diff --git a/mbbsd/admin.c b/mbbsd/admin.c index bfc7f9ea..d193384b 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -492,6 +492,16 @@ m_mod_board(char *bname) trim(genbuf); strlcpy(newbh.BM, genbuf, sizeof(newbh.BM)); } +#ifdef CHESSCOUNTRY + snprintf(genbuf, sizeof(genbuf), "%d", bh.chesscountry); + if (getdata_str(16, 0, "設定棋國 (0)無 (1)五子棋 (2)象棋", ans, + sizeof(ans), LCECHO, genbuf)){ + newbh.chesscountry = atoi(ans); + if (newbh.chesscountry > CHESSCODE_MAX || + newbh.chesscountry < CHESSCODE_NONE) + newbh.chesscountry = bh.chesscountry; + } +#endif /* defined(CHESSCOUNTRY) */ if (HAS_PERM(PERM_SYSOP)) { move(1, 0); clrtobot(); @@ -523,6 +533,7 @@ m_mod_board(char *bname) clear(); } } + getdata(b_lines - 1, 0, "請您確定(Y/N)?[Y]", genbuf, 4, LCECHO); if ((*genbuf != 'n') && memcmp(&newbh, &bh, sizeof(bh))) { @@ -780,6 +791,15 @@ m_newbrd(int recover) newboard.level = 0; getdata(11, 0, "板主名單:", newboard.BM, sizeof(newboard.BM), DOECHO); +#ifdef CHESSCOUNTRY + if (getdata_str(12, 0, "設定棋國 (0)無 (1)五子棋 (2)象棋", ans, + sizeof(ans), LCECHO, "0")){ + newboard.chesscountry = atoi(ans); + if (newboard.chesscountry > CHESSCODE_MAX || + newboard.chesscountry < CHESSCODE_NONE) + newboard.chesscountry = CHESSCODE_NONE; + } +#endif /* defined(CHESSCOUNTRY) */ if (HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, sizeof(ans), LCECHO, "N"); diff --git a/mbbsd/osdep.c b/mbbsd/osdep.c index 4647d198..fb5ce17c 100644 --- a/mbbsd/osdep.c +++ b/mbbsd/osdep.c @@ -228,7 +228,7 @@ swapused(int *total, long *used) if ((fp = fopen("/proc/meminfo", "r"))) { while (fgets(buf, 100, fp) && buf[0] != 'S'); - if (sscanf(buf + 6, "%ld %ld", total, used) == 2) + if (sscanf(buf + 6, "%d %ld", total, used) == 2) if (*total != 0) percent = (double)*used / (double)*total; fclose(fp); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index a369affb..5e2048f5 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -31,7 +31,7 @@ sethomeman(char *buf, char *userid) void -sethomefile(char *buf, char *userid, char *fname) +sethomefile(char *buf, char *userid, const char *fname) { sprintf(buf, str_home_file, userid[0], userid, fname); } diff --git a/util/Makefile b/util/Makefile index 0516fa59..54e26131 100644 --- a/util/Makefile +++ b/util/Makefile @@ -23,7 +23,8 @@ CPROG_WITH_UTIL= \ indexuser yearsold toplazyBM toplazyBBM \ reaper buildAnnounce inndBM shmctl \ outmail chkhbf checkmoney merge_dir \ - transman angel gamblegive checkdir + transman angel gamblegive checkdir \ + chesscountry # 下面這些程式, 會直接被 compile CPROG_WITHOUT_UTIL= \ diff --git a/util/chesscountry.c b/util/chesscountry.c new file mode 100644 index 00000000..c34d549f --- /dev/null +++ b/util/chesscountry.c @@ -0,0 +1,183 @@ +/* $Id$ */ +/*-------------------------------------------------------*/ +/* copied from util/cchess.c ( NTU FPG BBS Ver 1.00 ) */ +/*-------------------------------------------------------*/ +/* target : 棋國設定檔自動更新程式 */ +/*-------------------------------------------------------*/ + +#define CHESSCOUNTRY /* This tool is built with CHESSCOUNTRY defined */ +#include "bbs.h" + +/* Number of minutes of files' mtime before now will be rescanned. */ +#define UPDATE_FREQUENCY (30) + +void +f_suck6(FILE* fp, char* fname) +{ + FILE *sfp; + int count = 0; + + if ((sfp = fopen(fname, "r"))) + { + char inbuf[256]; + + while (fgets(inbuf, sizeof(inbuf), sfp) && count < 6) + { + fputs(inbuf, fp); + count++; + } + fclose(sfp); + } +} + +int +main(void) +{ + FILE *fp, *ftmp; + int i = 0, num; + //char *currboard[3] = {"CCK-CHUHEN", "CCK-GENERAL", "CCK-FREE"}; + //char *kingdom[3] = {"楚漢皇朝", "將帥帝聯", "逍遙王朝"}; + char file1[80], file2[80], str[256]; + struct stat st; + time_t dtime; + boardheader_t brd; + int brdfd; + + setgid(BBSGID); + setuid(BBSUID); + chdir(BBSHOME); + + time(&dtime); + + if ((brdfd = open(BBSHOME "/" FN_BOARD, O_RDONLY)) == -1){ + perror("open " BBSHOME "/" FN_BOARD); + return 0; + } + + while(read(brdfd, &brd, sizeof(brd)) == sizeof(brd)) + { + const char* photo_fname = 0; + const char* chess_name = 0; + char kingdom_name[256]; + int bid; + switch(brd.chesscountry){ + case CHESSCODE_FIVE: + photo_fname = "photo_fivechess"; + chess_name = "五子棋"; + break; + case CHESSCODE_CCHESS: + photo_fname = "photo_cchess"; + chess_name = "象棋"; + break; + default: + continue; + } + bid = getbnum(brd.brdname); + + sprintf(file1, "etc/%s", brd.brdname); + + if (stat(file1, &st) == 0 && st.st_mtime > (dtime - UPDATE_FREQUENCY * 60)) + continue; + + sprintf(file2, "etc/%s.tmp", brd.brdname); + if ((ftmp = fopen(file2, "w")) == NULL) + continue; + + if ((fp = fopen(file1, "r"))) + { + char *p; + char userid[IDLEN + 1], buf[256], name[11]; + char date[11], other[IDLEN + 1]; + + fgets(kingdom_name, 256, fp); + fputs(kingdom_name, ftmp); + kingdom_name[strlen(kingdom_name) - 1] = 0; + while (fgets(buf, sizeof(buf), fp)) + { + i = 0; + strcpy(str, buf); + p = strtok(buf, " "); + if (*p != '#' && searchuser(p)) + { + strlcpy(userid, p, sizeof(userid)); + i = 1; + + if ((p = strtok(NULL, " "))) + strlcpy(name, p, sizeof(name)); + else + i = 0; + + if ((p = strtok(NULL, " "))) + strlcpy(date, p, sizeof(date)); + else + i = 0; + + if ((p = strtok(NULL, " "))) + strlcpy(other, p, sizeof(other)); + else + i = 0; + } + if (!strcmp("除名", name)) + { + sethomefile(buf, userid, photo_fname); + unlink(buf); + continue; + } + if (i == 0) + { + fprintf(ftmp, "%s", str); + continue; + } + fprintf(ftmp, "#%s", str); + + setapath(str, brd.brdname); + sprintf(buf, "%s/photo/.DIR", str); + num = get_num_records(buf, sizeof(fileheader_t)); + for (i = 1; i <= num; i++) + { + fileheader_t item; + if (get_record(buf, &item, sizeof item, i) != -1) + { + FILE *fp1; + if (!strcmp(item.title + 3, name)) + { + sethomefile(buf, userid, photo_fname); + //sprintf(buf, "home/%c/%s/photo_cchess", userid[0], userid); + if ((fp1 = fopen(buf, "w"))) + { + sprintf(buf, "%s/photo/%s", str, item.filename); + f_suck6(fp1, buf); + fprintf(fp1, "%d\n", bid); + if (strcmp("俘虜", name)) + fprintf(fp1, "<所屬王國> %s (%s)\n", kingdom_name, chess_name); + else + fprintf(fp1, "<俘虜王國> %s\n", kingdom_name); + fprintf(fp1, "<現在階級> %s\n", name); + fprintf(fp1, "<加入日期> %s\n", date); + if (strcmp("俘虜", name)) + { + int level; + fprintf(fp1, "<王國等級> "); + level = atoi(other); + for (i = 0; i < level; i++) + fprintf(fp1, "%s", "★"); + } + else + { + other[strlen(other) - 1] = 0; + fprintf(fp1, "<被誰俘虜> %s", other); + } + fprintf(fp1, "\n<自我說明> "); + fclose(fp1); + } + } + } + } + } + fclose(fp); + fclose(ftmp); + rename(file2, file1); + } + } + return 0; +} |