This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbsebbs/timecheck.c

134 lines
3.4 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-11-12 21:42:17 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Timecheck functions
*
*****************************************************************************
2004-02-21 17:22:00 +00:00
* Copyright (C) 1997-2004
2001-08-17 05:46:24 +00:00
*
* Michiel Broek FIDO: 2:280/2802
2003-09-02 18:29:19 +00:00
* Beekmansbos 10
2001-08-17 05:46:24 +00:00
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbselib.h"
2001-08-17 05:46:24 +00:00
#include "../lib/mbse.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-08-17 05:46:24 +00:00
#include "timecheck.h"
#include "funcs.h"
#include "bye.h"
#include "exitinfo.h"
#include "language.h"
2001-11-12 21:42:17 +00:00
#include "input.h"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "ttyio.h"
2001-11-12 21:42:17 +00:00
2003-04-01 21:41:36 +00:00
extern pid_t mypid; /* Pid of this program */
extern int chat_with_sysop; /* True if chatting with sysop */
2001-11-12 21:42:17 +00:00
2003-04-01 21:41:36 +00:00
/*
2001-11-12 21:42:17 +00:00
* Check for a personal message, this will go via mbsed. If there
* is a message, it will be displayed, else nothing happens.
*/
void Check_PM(void);
void Check_PM(void)
{
2003-03-24 19:44:38 +00:00
static char buf[200];
2004-11-03 20:48:45 +00:00
char resp[128], msg[81];
2005-08-28 17:35:28 +00:00
snprintf(buf, 200, "CIPM:1,%d;", mypid);
if (socket_send(buf) == 0) {
strcpy(buf, socket_receive());
if (strncmp(buf, "100:0;", 6) == 0)
return;
2003-03-24 19:44:38 +00:00
strncpy(resp, strtok(buf, ":"), 5); /* Should be 100 */
strncpy(resp, strtok(NULL, ","), 3); /* Should be 2 */
strncpy(resp, strtok(NULL, ","), 36); /* From Name */
2004-11-03 20:48:45 +00:00
Enter(2);
PUTCHAR('\007');
colour(CYAN, BLACK);
/* ** Message ** from */
2005-08-28 17:35:28 +00:00
snprintf(msg, 81, "%s %s:", (char *)Language(434), resp);
2004-11-03 20:48:45 +00:00
poutCR(CYAN, BLACK, msg);
strncpy(resp, strtok(NULL, "\0"), 80); /* The real message */
resp[strlen(resp)-1] = '\0';
2004-11-03 20:48:45 +00:00
PUTSTR(resp);
Enter(1);
Pause();
}
2001-11-12 21:42:17 +00:00
}
2001-08-17 05:46:24 +00:00
/*
2003-04-02 21:36:47 +00:00
* This is the users onlinetime check.
2001-08-17 05:46:24 +00:00
*/
void TimeCheck(void)
{
2003-04-02 21:36:47 +00:00
time_t Now;
int Elapsed;
2001-08-17 05:46:24 +00:00
2003-04-02 21:36:47 +00:00
Now = time(NULL);
/*
* Update the global string for the menu prompt
*/
2005-08-28 17:35:28 +00:00
snprintf(sUserTimeleft, 7, "%d", iUserTimeLeft);
2003-04-02 21:36:47 +00:00
ReadExitinfo();
if (iUserTimeLeft != ((Time2Go - Now) / 60)) {
Elapsed = iUserTimeLeft - ((Time2Go - Now) / 60);
iUserTimeLeft -= Elapsed;
2005-08-28 17:35:28 +00:00
snprintf(sUserTimeleft, 7, "%d", iUserTimeLeft);
2001-08-17 05:46:24 +00:00
/*
2003-04-02 21:36:47 +00:00
* Update users counter if not chatting
2001-08-17 05:46:24 +00:00
*/
2003-04-02 21:36:47 +00:00
if (!CFG.iStopChatTime || (! chat_with_sysop)) {
exitinfo.iTimeLeft -= Elapsed;
exitinfo.iConnectTime += Elapsed;
exitinfo.iTimeUsed += Elapsed;
WriteExitinfo();
2001-08-17 05:46:24 +00:00
}
2003-04-02 21:36:47 +00:00
}
2001-08-17 05:46:24 +00:00
2003-04-02 21:36:47 +00:00
if (exitinfo.iTimeLeft <= 0) {
2004-11-03 20:48:45 +00:00
Enter(1);
poutCR(YELLOW, BLACK, (char *) Language(130));
2003-04-02 21:36:47 +00:00
sleep(3);
Syslog('!', "Users time limit exceeded ... user disconnected!");
iExpired = TRUE;
Good_Bye(MBERR_TIMEOUT);
}
2001-08-17 05:46:24 +00:00
2003-04-02 21:36:47 +00:00
/*
* Check for a personal message
*/
Check_PM();
2001-08-17 05:46:24 +00:00
}