summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-08-12 21:03:28 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-08-12 21:03:28 +0800
commit2d360031b079b8f6181d1d5e244d617dd47cefe8 (patch)
tree31b390dc08dd62bd7b26ad430a07f23f4f9be511 /util
parent83ded54df48fa434f77831bb8280603973e2e989 (diff)
downloadpttbbs-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
Diffstat (limited to 'util')
-rw-r--r--util/Makefile3
-rw-r--r--util/chesscountry.c183
2 files changed, 185 insertions, 1 deletions
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;
+}