示例#1
0
BLAPI_PROTO
bl_clock(lua_State *L)
{
    double d = 0;

#ifdef _WIN32

    // XXX this is a fast hack because we don't want to do 64bit calculation.
    SYSTEMTIME st;
    GetSystemTime(&st);
    syncnow();
    // XXX the may be some latency between our GetSystemTime and syncnow.
    // So build again the "second" part.
    d = (int)((now / 60) * 60);
    d += st.wSecond;
    d += (st.wMilliseconds / 1000.0f);

#else // !_WIN32

    struct timeval tp;
    gettimeofday(&tp, NULL);
    d = bl_tv2double(&tp);

#endif // !_WIN32

    lua_pushnumber(L, d);
    return 1;
}
示例#2
0
BLAPI_PROTO
bl_time(lua_State *L)
{
    syncnow();
    lua_pushinteger(L, now);
    return 1;
}
示例#3
0
BLAPI_PROTO
bl_ctime(lua_State *L)
{
    syncnow();
    lua_pushstring(L, ctime4(&now));
    return 1;
}
示例#4
0
int pwcuPlayAngel       (void)
{
    syncnow();
    PWCU_START();
    u.timeplayangel = cuser.timeplayangel = now;
    PWCU_END();
}
示例#5
0
文件: cal.c 项目: ChunHungLiu/pttbbs
// XXX numposts itself is an integer, but some records (by del post!?) may
// create invalid records as -1... so we'd better make it signed for real
// comparison.
char *get_restriction_reason(
        unsigned int numlogindays,
        unsigned int badpost,

        unsigned int limits_logins,
        unsigned int limits_badpost,

        size_t sz_msg, char *msg) {

    syncnow();
    if (numlogindays / 10 < limits_logins) {
        snprintf(msg, sz_msg,
                 STR_LOGINDAYS "未滿 %d " STR_LOGINDAYS
                 "(目前%d" STR_LOGINDAYS_QTY ") ",
                 limits_logins * 10, numlogindays);
        return msg;
    }
#ifdef ASSESS
    if  (badpost > (255 - limits_badpost)) {
        snprintf(msg, sz_msg, "退文超過 %d 篇(目前%d篇)",
                 255 - limits_badpost, badpost);
        return msg;
    }
#endif
    return NULL;
}
示例#6
0
int pwcuSetMyAngel	(const char *angel_uid)
{
    PWCU_START();
    strlcpy(    u.myangel, angel_uid, sizeof(    u.myangel));
    strlcpy(cuser.myangel, angel_uid, sizeof(cuser.myangel));
    syncnow();
    cuser.timesetangel = u.timesetangel = now;
    PWCU_END();
}
示例#7
0
文件: stuff.c 项目: ptt/pttbbs
void
wait_penalty(int sec)
{
    static time4_t lastWait = 0;

    syncnow();
    if (now - lastWait < sec)
    {
        sec = now - lastWait;
        if (sec < 0 || sec >= 5)
            sec = 5;
        sleep(sec);
        vkey_purge();
    }
    lastWait = now;
}
示例#8
0
static int
dogetch(void)
{
    ssize_t         len;
    static time_t  lastact;
    if (ibufsize <= icurrchar) {

	if (flushf)
	    (*flushf) ();

	refresh();

	if (i_newfd) {

	    struct timeval  timeout;
	    fd_set          readfds;

	    if (i_top)
		timeout = *i_top;	/* copy it because select() might
					 * change it */

	    FD_ZERO(&readfds);
	    FD_SET(0, &readfds);
	    FD_SET(i_newfd, &readfds);

	    /* jochang: modify first argument of select from FD_SETSIZE */
	    /* since we are only waiting input from fd 0 and i_newfd(>0) */

	    while ((len = select(i_newfd + 1, &readfds, NULL, NULL,
			    i_top ? &timeout : NULL)) < 0) {
		if (errno != EINTR)
		    abort_bbs();
		/* raise(SIGHUP); */
	    }

	    if (len == 0){
		syncnow();
		return I_TIMEOUT;
	    }

	    if (i_newfd && FD_ISSET(i_newfd, &readfds)){
		syncnow();
		return I_OTHERDATA;
	    }
	}

	do {
	    len = tty_read(inbuf, IBUFSIZE);
	    /* tty_read will handle abort_bbs.
	     * len <= 0: read more */
#ifdef CONVERT
	    if(len > 0)
		len = input_wrapper(inbuf, len);
#endif
#ifdef DBG_OUTRPT
	    // if (0)
	    {
		static char xbuf[128];
		sprintf(xbuf, ESC_STR "[s" ESC_STR "[2;1H [%ld] " 
			ESC_STR "[u", len);
		write(1, xbuf, strlen(xbuf));
		fsync(1);
	    }
#endif // DBG_OUTRPT

	} while (len <= 0);

	ibufsize = len;
	icurrchar = 0;
    }

    // CRLF Handle:
    //
    // (UNIX) LF
    // (WIN)  CRLF
    // (MAC)  CR
    //
    // to work in a compatible way, (see KEY_ENTER definition)
    // let KEY_ENTER = CR

    {
	unsigned char c = (unsigned char) inbuf[icurrchar++];

	// CR LF are treated as one.
	if (c == KEY_CR)
	{
	    // peak next character.
	    if (icurrchar < ibufsize && inbuf[icurrchar] == KEY_LF)
		icurrchar ++;
	    return KEY_ENTER;
	} 
	else if (c == KEY_LF)
	{
	    // XXX it is reported that still some users
	    // experience double ENTERs. We are not sure if there
	    // are still any stupid clients. But if any, you
	    // can reject the LFs. According the the compatibility
	    // test, most clients send CR only so it should be fine.
#ifdef ACCEPT_LF
	    return KEY_ENTER;
#else
	    return KEY_UNKNOWN;
#endif
	}

	// XXX also treat ^H and 127 (KEY_BS2) the same one?
	// else if (c == KEY_BS2)
	// {
	//   return KEY_BS;
	// }
	
	return c;
    }
}