summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-01-06 15:54:16 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-01-06 15:54:16 +0800
commit0480bbc1fe207b2d056b522f1e64423dc1dffbad (patch)
tree51d899da96714f0e4a60f81e366b8c0bb956cf94 /mbbsd
parente58484742bc2812a2082cce244ff3bdf3d156d55 (diff)
downloadpttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.tar
pttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.tar.gz
pttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.tar.bz2
pttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.tar.lz
pttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.tar.xz
pttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.tar.zst
pttbbs-0480bbc1fe207b2d056b522f1e64423dc1dffbad.zip
- bbslua: add more API
- cache: add getutmpmode() - othellow: quick exit git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3798 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/bbslua.c59
-rw-r--r--mbbsd/cache.c8
-rw-r--r--mbbsd/othello.c18
3 files changed, 79 insertions, 6 deletions
diff --git a/mbbsd/bbslua.c b/mbbsd/bbslua.c
index 0fb4ac54..09c75dcc 100644
--- a/mbbsd/bbslua.c
+++ b/mbbsd/bbslua.c
@@ -217,6 +217,27 @@ bl_getstr(lua_State* L)
}
BLAPI_PROTO
+bl_kbhit(lua_State *L)
+{
+ int n = lua_gettop(L);
+ double f = 0.1f;
+
+ if (n > 0)
+ f = (double)lua_tonumber(L, 1);
+
+ if (f < 0.1f)
+ f = 0.1f;
+ if (f > 10*60)
+ f = 10*60;
+
+ if (num_in_buf() || wait_input(f, 0))
+ lua_pushboolean(L, 1);
+ else
+ lua_pushboolean(L, 0);
+ return 1;
+}
+
+BLAPI_PROTO
bl_pause(lua_State* L)
{
int n = lua_gettop(L);
@@ -283,6 +304,29 @@ bl_attrset(lua_State *L)
return 0;
}
+BLAPI_PROTO
+bl_time(lua_State *L)
+{
+ syncnow();
+ lua_pushinteger(L, now);
+ return 1;
+}
+
+BLAPI_PROTO
+bl_ctime(lua_State *L)
+{
+ syncnow();
+ lua_pushstring(L, ctime4(&now));
+ return 1;
+}
+
+BLAPI_PROTO
+bl_userid(lua_State *L)
+{
+ lua_pushstring(L, cuser.userid);
+ return 1;
+}
+
//////////////////////////////////////////////////////////////////////////
// BBSLUA LIBRARY
//////////////////////////////////////////////////////////////////////////
@@ -298,17 +342,22 @@ static const struct luaL_reg lib_bbslua [] = {
{ "clrtobot", bl_clrtobot },
{ "refresh", bl_refresh },
{ "redrawwin", bl_redrawwin },
- // { "addch", bl_addstr },
{ "addstr", bl_addstr },
- // { "outc", bl_addstr },
+ { "print", bl_addstr },
{ "outs", bl_addstr },
/* input */
{ "getch", bl_getch },
{ "getdata", bl_getstr },
{ "getstr", bl_getstr },
+ { "kbhit", bl_kbhit },
/* BBS utilities */
{ "pause", bl_pause },
{ "title", bl_title },
+ { "userid", bl_userid },
+ /* time */
+ { "time", bl_time },
+ { "now", bl_time },
+ { "ctime", bl_ctime },
/* ANSI helpers */
{ "ANSI_COLOR", bl_ansi_color },
{ "color", bl_attrset },
@@ -343,6 +392,7 @@ LUALIB_API void myluaL_openlibs (lua_State *L) {
static void
bbsluaRegConst(lua_State *L, const char *globName)
{
+ // section
lua_getglobal(L, globName);
lua_pushstring(L, "ESC"); lua_pushstring(L, ESC_STR);
lua_settable(L, -3);
@@ -351,6 +401,9 @@ bbsluaRegConst(lua_State *L, const char *globName)
lua_pushstring(L, "ANSI_RESET"); lua_pushstring(L, ANSI_RESET);
lua_settable(L, -3);
+ // global
+ lua_pushcfunction(L, bl_addstr);
+ lua_setglobal(L, "print");
}
static void
@@ -467,6 +520,7 @@ bbslua(const char *fpath)
lua_State *L = lua_open();
char *bs, *ps, *pe;
int sz = 0;
+ unsigned int prevmode = getutmpmode();
// detect file
bs = bbslua_attach(fpath, &sz);
@@ -549,6 +603,7 @@ bbslua(const char *fpath)
vmsgf("BBS-Lua 執行結束%s。",
abortBBSLua ? " (使用者中斷)" : r ? " (程式錯誤)" : "");
clear();
+ setutmpmode(prevmode);
return 0;
}
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 5c4cb7af..5f15130a 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -500,6 +500,14 @@ setutmpmode(unsigned int mode)
log_user("setutmpmode to %s(%d)\n", modestring(currutmp, 0), mode);
}
}
+
+unsigned int
+getutmpmode(void)
+{
+ if (currutmp)
+ return currutmp->mode;
+ return currstat;
+}
#endif
/*
diff --git a/mbbsd/othello.c b/mbbsd/othello.c
index 9431e7df..99dd4794 100644
--- a/mbbsd/othello.c
+++ b/mbbsd/othello.c
@@ -494,12 +494,16 @@ choose(void)
move(2, 0);
outs("請選擇難度:");
move(5, 0);
- outs("(1) CD-65\n"); /* 想 1 步 */
+ outs("[0] 離開\n");
+ outs("(1) CD-65\n");/* 想 1 步 */
outs("(2) 嬰兒\n"); /* 想 3 步 */
outs("(3) 小孩\n"); /* 想 4 步 */
do {
- getdata(4, 0, "請選擇一個對象和您對打:(1~3)",
- thinkstep, sizeof(thinkstep), LCECHO);
+ if (getdata(4, 0, "請選擇一個對象和您對打:(1~3)",
+ thinkstep, sizeof(thinkstep), LCECHO) == 0 ||
+ thinkstep[0] == '0')
+ return 0;
+
} while (thinkstep[0] < '1' || thinkstep[0] > '3');
clear();
switch (thinkstep[0]) {
@@ -534,7 +538,13 @@ othello_main(void)
clear();
init(od);
od->think = choose();
- showtitle("黑白棋", BBSName);
+ if (!od->think)
+ {
+ unlockutmpmode();
+ free(od);
+ return 0;
+ }
+ showtitle("單人黑白棋", BBSName);
printboard(od);
od->which_table = random() % NR_TABLE;
while (true) {