倒數計時器功能 - BBS
By Dora
at 2008-06-13T12:48
at 2008-06-13T12:48
Table of Contents
今天試著把倒數計時器個功能做在BBS裡面 利用控制碼的方式來倒數
修改的code不長 大家可以玩玩看
使用方法為再編輯文章的時候按下Ctrl+Q然後選3
這時會出現**t的控制碼 接著在後面加上倒數的日期 格式為YYYYMMDDHHmm
所以這行會看起來像**t200807311730 代表時間為2008/07/31 17:30的時候
存檔後看到的結果會出現像是 47天 3時29分35秒 這樣的時間
~/src/maple/edit.c
約在2185行的部分 可以尋找
#ifdef SHOW_USER_IN_TEXT
case Ctrl('Q'):
cc = vans("顯示使用者資料(1)id (2)暱稱 (3)Timer?");//多加了Timer選項
if (cc >= '1' && cc <= '3')//改成cc<='3'
{
ve_char(KEY_ESC);
ve_char('*');
ve_char("snt"[cc - '1']);//多加一個字元t
}
ve_mode = mode | VE_FOOTER;
break;
#endif
倒數計時器實作的部分在
~/src/maple/visio.c
約在802行的部分 搜尋SHOW_USER_IN_TEXT
#ifdef SHOW_USER_IN_TEXT
void
outx(str)
uschar *str;
{
int ch;
while (ch = *str)
{
/* itoc.020301: ESC + * + s 等控制碼 */
if (ch == KEY_ESC && str[1] == '*')
{
switch (str[2])
{
case 's': /* **s 顯示 ID */
outs(cuser.userid);
str += 3;
continue;
case 'n': /* **n 顯示暱稱 */
outs(cuser.username);
str += 3;
continue;
//以下是倒數計時的code
case 't': /* **t 顯示Timer */
//Get Date after that
//The format is YYYYMMDDHHmm
if(strlen(str)>=15){
if(str[3] =='2')//Check is start 2XXX year
{
int year,month,day,hour,min;
sscanf(str,"%*c%*ct%4d%2d%2d%2d%2d",&year,&month,&day,&hour,&min);
if(year>=2008 && year<=2038)
if(month>=1 && month <=12)
if(day>=1 && day <= 31)
if(hour >= 0 &&hour <=23)
if(min >=0 && min <= 59)
{
struct tm goal;
goal.tm_year = year-1900;
goal.tm_mon = month -1;
goal.tm_mday = day;
goal.tm_hour = hour;
goal.tm_min = min;
goal.tm_sec = 0;
goal.tm_isdst = 0;
time_t gt = mktime(&goal);
int counter = difftime(gt,time(NULL));
int days = counter / 86400;
counter %= 86400;
int hours = counter / 3600;
counter %= 3600;
int mins = counter / 60;
counter %= 60;
char diff[30];
sprintf(diff,"%3d天%2d時%2d分%2d秒
",days,hours,mins,counter);
outs(diff);
str += 12;// **t200806121700 have 12+3 digit
}
}
}
str += 3;
continue;
}
}
outc(ch);
str++;
}
}
#endif
--
修改的code不長 大家可以玩玩看
使用方法為再編輯文章的時候按下Ctrl+Q然後選3
這時會出現**t的控制碼 接著在後面加上倒數的日期 格式為YYYYMMDDHHmm
所以這行會看起來像**t200807311730 代表時間為2008/07/31 17:30的時候
存檔後看到的結果會出現像是 47天 3時29分35秒 這樣的時間
~/src/maple/edit.c
約在2185行的部分 可以尋找
#ifdef SHOW_USER_IN_TEXT
case Ctrl('Q'):
cc = vans("顯示使用者資料(1)id (2)暱稱 (3)Timer?");//多加了Timer選項
if (cc >= '1' && cc <= '3')//改成cc<='3'
{
ve_char(KEY_ESC);
ve_char('*');
ve_char("snt"[cc - '1']);//多加一個字元t
}
ve_mode = mode | VE_FOOTER;
break;
#endif
倒數計時器實作的部分在
~/src/maple/visio.c
約在802行的部分 搜尋SHOW_USER_IN_TEXT
#ifdef SHOW_USER_IN_TEXT
void
outx(str)
uschar *str;
{
int ch;
while (ch = *str)
{
/* itoc.020301: ESC + * + s 等控制碼 */
if (ch == KEY_ESC && str[1] == '*')
{
switch (str[2])
{
case 's': /* **s 顯示 ID */
outs(cuser.userid);
str += 3;
continue;
case 'n': /* **n 顯示暱稱 */
outs(cuser.username);
str += 3;
continue;
//以下是倒數計時的code
case 't': /* **t 顯示Timer */
//Get Date after that
//The format is YYYYMMDDHHmm
if(strlen(str)>=15){
if(str[3] =='2')//Check is start 2XXX year
{
int year,month,day,hour,min;
sscanf(str,"%*c%*ct%4d%2d%2d%2d%2d",&year,&month,&day,&hour,&min);
if(year>=2008 && year<=2038)
if(month>=1 && month <=12)
if(day>=1 && day <= 31)
if(hour >= 0 &&hour <=23)
if(min >=0 && min <= 59)
{
struct tm goal;
goal.tm_year = year-1900;
goal.tm_mon = month -1;
goal.tm_mday = day;
goal.tm_hour = hour;
goal.tm_min = min;
goal.tm_sec = 0;
goal.tm_isdst = 0;
time_t gt = mktime(&goal);
int counter = difftime(gt,time(NULL));
int days = counter / 86400;
counter %= 86400;
int hours = counter / 3600;
counter %= 3600;
int mins = counter / 60;
counter %= 60;
char diff[30];
sprintf(diff,"%3d天%2d時%2d分%2d秒
",days,hours,mins,counter);
outs(diff);
str += 12;// **t200806121700 have 12+3 digit
}
}
}
str += 3;
continue;
}
}
outc(ch);
str++;
}
}
#endif
--
Tags:
BBS
All Comments
Related Posts
請問joe編譯器要去哪邊下載?
By Wallis
at 2008-05-31T22:54
at 2008-05-31T22:54
請問joe編譯器要去哪邊下載?
By Valerie
at 2008-05-26T17:31
at 2008-05-26T17:31
關於看板屬性
By Christine
at 2008-05-22T15:57
at 2008-05-22T15:57
請問有人門的網站可以參考一下的嗎?
By Zenobia
at 2008-05-22T11:20
at 2008-05-22T11:20
關於動態看板和進站畫面
By Emily
at 2008-05-08T17:56
at 2008-05-08T17:56