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/menu.c

770 lines
14 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-11-09 15:19:00 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Display and handle the menus.
*
*****************************************************************************
* Copyright (C) 1997-2007
2001-08-17 05:46:24 +00:00
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 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 "oneline.h"
#include "mail.h"
#include "change.h"
#include "chat.h"
#include "file.h"
#include "funcs.h"
#include "input.h"
2001-08-17 05:46:24 +00:00
#include "misc.h"
#include "timeout.h"
#include "menu.h"
#include "page.h"
#include "pinfo.h"
#include "bye.h"
#include "timecheck.h"
#include "whoson.h"
2001-08-17 05:46:24 +00:00
#include "language.h"
#include "offline.h"
#include "email.h"
#include "door.h"
#include "dispfile.h"
2001-11-12 21:42:17 +00:00
#include "userlist.h"
#include "timestats.h"
#include "logentry.h"
#include "morefile.h"
#include "lastcallers.h"
#include "signature.h"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "ttyio.h"
2001-08-17 05:46:24 +00:00
2003-04-01 21:41:36 +00:00
extern pid_t mypid;
2001-08-17 05:46:24 +00:00
/*
* Menu stack, 50 levels deep.
*/
char Menus[50][15];
int MenuLevel;
int MenuError;
void InitMenu()
{
2003-02-07 20:49:01 +00:00
int i;
2001-08-17 05:46:24 +00:00
2003-02-07 20:49:01 +00:00
for (i = 0; i < 50; i++)
memset(Menus[i], 0, 51);
MenuLevel = 0;
MenuError = 0;
2005-08-29 10:59:47 +00:00
snprintf(Menus[0], 15, "%s", CFG.default_menu);
2001-08-17 05:46:24 +00:00
}
void menu()
{
2002-10-20 20:58:55 +00:00
FILE *pMenuFile;
int iFoundKey = FALSE, Key, IsANSI;
2004-11-03 20:48:45 +00:00
char temp[81], *Input, *sMenuPathFileName, buf[81];
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
Input = calloc(PATH_MAX, sizeof(char));
sMenuPathFileName = calloc(PATH_MAX, sizeof(char));
2004-08-07 15:11:05 +00:00
Syslog('+', "Starting menu loop");
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
/*
* Loop forever, this is what a BBS should do until a user logs out.
*/
while (TRUE) {
2001-08-17 05:46:24 +00:00
2003-10-11 21:22:16 +00:00
WhosDoingWhat(BROWSING, NULL);
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
/*
* Open menufile, first users language menu, if it fails
* try to open the default menu.
*/
snprintf(sMenuPathFileName, PATH_MAX, "%s/share/int/menus/%s/%s", getenv("MBSE_ROOT"), lang.lc, Menus[MenuLevel]);
2002-10-20 20:58:55 +00:00
if ((pMenuFile = fopen(sMenuPathFileName, "r")) == NULL) {
snprintf(sMenuPathFileName, PATH_MAX, "%s/share/int/menus/%s/%s", getenv("MBSE_ROOT"), CFG.deflang, Menus[MenuLevel]);
2002-10-20 20:58:55 +00:00
pMenuFile = fopen(sMenuPathFileName,"r");
if (pMenuFile != NULL)
2004-08-07 15:11:05 +00:00
Syslog('b', "Menu %s (Default)", Menus[MenuLevel]);
2002-10-20 20:58:55 +00:00
} else {
2004-08-07 15:11:05 +00:00
Syslog('b', "Menu %s (%s)", Menus[MenuLevel], lang.Name);
2002-10-20 20:58:55 +00:00
}
if (pMenuFile == NULL) {
clear();
WriteError("Can't open menu file: %s", sMenuPathFileName);
MenuError++;
/*
* Is this the last attempt to open the default menu?
*/
if (MenuError == 10) {
WriteError("FATAL ERROR: Too many menu errors");
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "Too many menu errors, notifying Sysop\r\n\r\n");
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
2002-10-20 20:58:55 +00:00
sleep(3);
die(MBERR_CONFIG_ERROR);
}
/*
* Switch back to the default menu
*/
MenuLevel = 0;
strcpy(Menus[0], CFG.default_menu);
} else {
/*
* Display Menu Text Fields and Perform all autoexec menus in order of menu file.
* First check if there are any ANSI menus, if not, send a clearscreen first.
*/
IsANSI = FALSE;
while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) {
if ( Le_Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= le_int(menus.Age))){
if ((le_int(menus.MenuType) == 5) || (le_int(menus.MenuType) == 19) || (le_int(menus.MenuType) == 20))
2002-10-20 20:58:55 +00:00
IsANSI = TRUE;
}
}
fseek(pMenuFile, 0, SEEK_SET);
if (! IsANSI)
clear();
while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) {
if ( Le_Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= le_int(menus.Age))){
2003-09-20 09:23:28 +00:00
if (menus.AutoExec) {
DoMenu( le_int(menus.MenuType) );
2002-10-20 20:58:55 +00:00
}
DisplayMenu( );
}
}
/*
* Check if the BBS closed down for Zone Mail Hour or
* system shutdown. If so, we run the Goodbye show.
*/
if (CheckStatus() == FALSE) {
fclose(pMenuFile);
Syslog('+', "Kicking user out, the BBS is closed.");
sleep(3);
Good_Bye(MBERR_OK);
}
/*
* Check the upsdown semafore
*/
2004-09-14 20:37:57 +00:00
if (IsSema((char *)"upsdown")) {
2002-10-20 20:58:55 +00:00
fclose(pMenuFile);
Syslog('+', "Kicking user out, upsdown semafore detected");
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "System power failure, closing the bbs");
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
Enter(2);
2002-10-20 20:58:55 +00:00
sleep(3);
Good_Bye(MBERR_OK);
}
/*
2003-04-01 21:41:36 +00:00
* Check if SysOp wants to chat to user everytime user gets prompt.
2002-10-20 20:58:55 +00:00
*/
2003-04-01 21:41:36 +00:00
if (CFG.iChatPromptChk) {
2005-08-29 10:59:47 +00:00
snprintf(buf, 81, "CISC:1,%d", mypid);
2003-04-01 21:41:36 +00:00
if (socket_send(buf) == 0) {
strcpy(buf, socket_receive());
if (strcmp(buf, "100:1,1;") == 0) {
Syslog('+', "Forced sysop/user chat");
Chat(exitinfo.Name, (char *)"#sysop");
2004-11-03 22:45:41 +00:00
continue;
2003-04-01 21:41:36 +00:00
}
}
}
2002-10-20 20:58:55 +00:00
/*
* Check users timeleft
*/
TimeCheck();
alarm_on();
if (exitinfo.HotKeys) {
2004-11-03 20:48:45 +00:00
Key = Readkey();
2005-08-29 10:59:47 +00:00
snprintf(Input, 81, "%c", Key);
2004-11-03 20:48:45 +00:00
Enter(1);
2002-10-20 20:58:55 +00:00
} else {
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(Input, 80);
}
if ((strcmp(Input, "")) != 0) {
fseek(pMenuFile, 0, SEEK_SET);
while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) {
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
if ((strcmp(tu(Input), menus.MenuKey)) == 0) {
if ((Le_Access(exitinfo.Security, menus.MenuSecurity)) && (UserAge >= le_int(menus.Age))) {
2004-08-07 15:11:05 +00:00
Syslog('+', "Menu[%d] %d=(%s), Opt: '%s'", MenuLevel, le_int(menus.MenuType),
2002-10-20 20:58:55 +00:00
menus.TypeDesc, menus.OptionalData);
if (le_int(menus.MenuType) == 13) {
2002-10-20 20:58:55 +00:00
/*
* Terminate call, cleanup here
*/
free(Input);
free(sMenuPathFileName);
fclose(pMenuFile);
}
DoMenu(le_int(menus.MenuType));
2002-10-20 20:58:55 +00:00
iFoundKey = TRUE;
break;
2001-08-17 05:46:24 +00:00
}
2002-10-20 20:58:55 +00:00
}
}
}
fclose(pMenuFile);
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
} /* If menu open */
} /* while true */
2001-08-17 05:46:24 +00:00
}
void DoMenu(int Type)
{
2003-02-07 20:49:01 +00:00
int Strlen, i, x;
char *sPrompt, *sPromptBak, *temp;
2001-08-17 05:46:24 +00:00
2003-02-07 20:49:01 +00:00
sPrompt = calloc(81, sizeof(char));
sPromptBak = calloc(81, sizeof(char));
temp = calloc(81, sizeof(char));
2001-08-17 05:46:24 +00:00
2003-02-07 20:49:01 +00:00
TimeCheck();
2001-08-17 05:46:24 +00:00
2003-02-07 20:49:01 +00:00
switch(Type) {
2001-09-23 19:09:20 +00:00
case 0: /* Display Prompt Line Only */
break;
2001-08-17 05:46:24 +00:00
case 1:
/* Goto another menu */
strncpy(Menus[MenuLevel], menus.OptionalData, 14);
break;
case 2:
/* Gosub another menu */
if (MenuLevel < 49) {
2003-02-07 20:49:01 +00:00
MenuLevel++;
strncpy(Menus[MenuLevel], menus.OptionalData, 14);
2001-08-17 05:46:24 +00:00
} else
2003-02-07 20:49:01 +00:00
Syslog('?', "More than 50 menu levels");
2001-08-17 05:46:24 +00:00
break;
case 3:
/* Return from gosub */
if (MenuLevel > 0)
2003-02-07 20:49:01 +00:00
MenuLevel--;
2001-08-17 05:46:24 +00:00
break;
case 4:
/* Return to top menu */
MenuLevel = 0;
break;
case 5:
/* Display .a?? file with controlcodes */
DisplayFile(menus.OptionalData);
break;
case 6:
/* Show menu prompt */
Strlen = strlen(menus.OptionalData);
2003-02-07 20:49:01 +00:00
for (x = 0; x < Strlen; x++) {
if (menus.OptionalData[x] == '~') {
strcat(sPrompt, sUserTimeleft);
} else {
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%c", menus.OptionalData[x]);
2003-02-07 20:49:01 +00:00
strcat(sPrompt, temp);
}
2001-08-17 05:46:24 +00:00
}
strcpy(sPromptBak, sPrompt);
strcpy(sPrompt, "");
Strlen = strlen(sPromptBak);
2003-02-07 20:49:01 +00:00
for (x = 0; x < Strlen; x++) {
if (*(sPromptBak + x) == '@')
strcat(sPrompt, sAreaDesc);
else if (*(sPromptBak + x) == '^')
strcat(sPrompt, sMsgAreaDesc);
else if (*(sPromptBak + x) == '#')
2005-08-29 10:59:47 +00:00
snprintf(sPrompt, 81, "%s%s", sPrompt, (char *) GetLocalHM());
2003-02-07 20:49:01 +00:00
else {
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%c", *(sPromptBak + x));
2003-02-07 20:49:01 +00:00
strcat(sPrompt, temp);
}
2001-08-17 05:46:24 +00:00
}
if (le_int(menus.ForeGnd) || le_int(menus.BackGnd))
pout(le_int(menus.ForeGnd), le_int(menus.BackGnd), sPrompt);
2001-11-09 15:19:00 +00:00
else
2003-02-07 20:49:01 +00:00
pout(WHITE, BLACK, sPrompt);
2001-08-17 05:46:24 +00:00
break;
case 7:
/* Run external program */
2003-10-11 21:22:16 +00:00
if (strlen(menus.DoorName) && !menus.HideDoor) {
memset(temp, 0, sizeof(temp));
strcpy(temp, menus.DoorName);
ExtDoor(menus.OptionalData, menus.NoDoorsys, menus.Y2Kdoorsys, menus.Comport,
menus.NoSuid, menus.NoPrompt, menus.SingleUser, temp);
} else {
ExtDoor(menus.OptionalData, menus.NoDoorsys, menus.Y2Kdoorsys, menus.Comport,
menus.NoSuid, menus.NoPrompt, menus.SingleUser, NULL);
}
2001-08-17 05:46:24 +00:00
break;
case 8:
/* Show product information */
cr();
break;
case 9:
/* display todays callers */
LastCallers(menus.OptionalData);
break;
case 10:
/* display userlist */
UserList(menus.OptionalData);
break;
case 11:
/* display time statistics */
TimeStats();
break;
case 12:
/* page sysop for chat */
Page_Sysop(menus.OptionalData);
break;
case 13:
/* terminate call */
free(sPrompt);
free(sPromptBak);
free(temp);
2002-10-20 20:58:55 +00:00
Good_Bye(MBERR_OK);
2001-08-17 05:46:24 +00:00
break;
case 14:
/* make a log entry */
LogEntry(menus.OptionalData);
break;
case 15:
/* print text to screen */
if (exitinfo.Security.level >= le_int(menus.MenuSecurity.level)) {
2003-02-07 20:49:01 +00:00
for (i = 0; i < strlen(menus.OptionalData); i++)
if (*(menus.OptionalData + i) == '@')
*(menus.OptionalData + i) = '\n';
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%s\r\n", menus.OptionalData);
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
2001-08-17 05:46:24 +00:00
}
break;
case 16:
/* who's currently online */
WhosOn(menus.OptionalData);
Pause();
break;
case 17:
/* comment to sysop */
SysopComment((char *)"Comment to Sysop");
break;
case 18:
/* send on-line message */
SendOnlineMsg(menus.OptionalData);
break;
case 19:
/* display Textfile with more */
MoreFile(menus.OptionalData);
break;
case 20:
/* display a?? file with controlcode and wait for enter */
DisplayFileEnter(menus.OptionalData);
break;
case 21:
/* display menuline only */
break;
2003-04-01 21:41:36 +00:00
case 22:
/* Chat with any user */
Chat(NULL, NULL);
break;
2001-08-17 05:46:24 +00:00
case 101:
FileArea_List(menus.OptionalData);
break;
case 102:
File_List();
break;
case 103:
2003-04-12 11:12:26 +00:00
ViewFile(NULL);
2001-08-17 05:46:24 +00:00
break;
case 104:
Download();
break;
case 105:
File_RawDir(menus.OptionalData);
break;
case 106:
KeywordScan();
break;
case 107:
FilenameScan();
break;
case 108:
NewfileScan(TRUE);
break;
case 109:
Upload();
break;
case 110:
EditTaglist();
break;
case 111: /* View file in homedir */
break;
case 112:
DownloadDirect(menus.OptionalData, TRUE);
break;
case 113:
Copy_Home();
break;
case 114:
List_Home();
break;
case 115:
Delete_Home();
break;
/* 116 Unpack file in homedir */
/* 117 Pack files in homedir */
case 118:
Download_Home();
break;
case 119:
Upload_Home();
break;
case 201:
MsgArea_List(menus.OptionalData);
break;
case 202:
Post_Msg();
break;
case 203:
Read_Msgs();
break;
case 204:
CheckMail();
break;
case 205:
QuickScan_Msgs();
break;
case 206:
Delete_Msg();
break;
case 207:
MailStatus();
break;
case 208:
OLR_TagArea();
break;
case 209:
OLR_UntagArea();
break;
case 210:
OLR_ViewTags();
break;
case 211:
OLR_RestrictDate();
break;
case 212:
OLR_Upload();
break;
case 213:
OLR_DownBW();
break;
case 214:
OLR_DownQWK();
break;
case 215:
OLR_DownASCII();
break;
case 216:
Read_Email();
break;
case 217:
Write_Email();
break;
case 218:
Trash_Email();
break;
case 219:
Choose_Mailbox(menus.OptionalData);
break;
case 220:
QuickScan_Email();
break;
2003-02-07 20:49:01 +00:00
case 221:
DisplayRules();
break;
2001-08-17 05:46:24 +00:00
case 301:
Chg_Protocol();
break;
case 302:
Chg_Password();
break;
case 303:
Chg_Location();
break;
case 304:
Chg_Graphics();
break;
case 305:
Chg_VoicePhone();
break;
case 306:
Chg_DataPhone();
break;
case 307:
Chg_News();
break;
case 309:
Chg_DOB();
break;
case 310:
Chg_Language(FALSE);
break;
case 311:
Chg_Hotkeys();
break;
case 312:
Chg_Handle();
break;
case 313:
Chg_MailCheck();
break;
case 314:
Chg_Disturb();
break;
case 315:
Chg_FileCheck();
break;
case 316:
Chg_FsMsged();
break;
case 317:
Chg_FsMsgedKeys();
break;
case 318:
Chg_Address();
break;
case 319:
signature();
break;
2003-03-02 13:29:33 +00:00
case 320:
Chg_OLR_ExtInfo();
break;
2004-02-24 22:09:27 +00:00
case 321:
Chg_Charset();
break;
2006-03-05 12:57:50 +00:00
case 322:
Chg_Archiver();
break;
2001-08-17 05:46:24 +00:00
case 401:
Oneliner_Add();
break;
case 402:
Oneliner_List();
break;
case 403:
Oneliner_Show();
break;
case 404:
Oneliner_Delete();
break;
case 405:
Oneliner_Print();
break;
default:
Enter(1);
2005-08-20 12:27:08 +00:00
pout(WHITE, BLACK, (char *) Language(339));
2001-08-17 05:46:24 +00:00
Enter(2);
Syslog('?', "Option: %s -> Unknown Menu Type: %d on %s", menus.MenuKey, Type, Menus[MenuLevel]);
Pause();
}
free(sPrompt);
free(sPromptBak);
free(temp);
}
2003-02-07 20:49:01 +00:00
2001-09-23 19:09:20 +00:00
2003-02-07 20:49:01 +00:00
/*
* Display the Menu Display Text to the User,
* if the sysop puts a ';' (semicolon) at the end of the menu prompt,
* the CR/LR combination will not be sent
*/
void DisplayMenu(void)
{
int maxdpos, dpos, escaped, skipCRLF, highlight;
/* Anything to process, if not; save CPU time, return */
if (( strlen( menus.Display ) == 0 ) && (le_int(menus.MenuType) != 21)) {
2003-02-07 20:49:01 +00:00
return;
}
/* Send Display string, formated with ANSI codes as required */
/* --- basically this with brains: printf("%s\n", menus.Display); */
maxdpos = strlen(menus.Display);
escaped = 0;
skipCRLF = 0;
highlight = 0;
colour( le_int(menus.ForeGnd), le_int(menus.BackGnd) );
2003-02-07 20:49:01 +00:00
for ( dpos = 0; dpos < maxdpos ; dpos++ ){
switch ( menus.Display[ dpos ] ) {
case ';': /* Semicolon, if not escaped and last char, not CRLF at end of line */
if ( ( dpos + 1 ) == maxdpos ) {
skipCRLF=1;
} else {
2004-11-03 20:48:45 +00:00
PUTCHAR(menus.Display[ dpos ]);
2003-02-07 20:49:01 +00:00
}
break;
2001-09-23 19:09:20 +00:00
2003-02-07 20:49:01 +00:00
case '\\': if ( !escaped ) {
escaped = 1;
} else {
escaped = 0;
2004-11-03 20:48:45 +00:00
PUTCHAR(menus.Display[ dpos ]);
2003-02-07 20:49:01 +00:00
}
break;
2001-09-23 19:09:20 +00:00
2003-02-07 20:49:01 +00:00
case '^': /* Highlight Toggle */
2001-09-23 19:09:20 +00:00
2003-02-07 20:49:01 +00:00
if ( !escaped ) {
if ( highlight == 0 ) {
highlight = 1;
colour( le_int(menus.HiForeGnd), le_int(menus.HiBackGnd));
2003-02-07 20:49:01 +00:00
} else {
highlight = 0 ;
colour( le_int(menus.ForeGnd), le_int(menus.BackGnd) );
2003-02-07 20:49:01 +00:00
}
} else {
escaped=0;
2004-11-03 20:48:45 +00:00
PUTCHAR(menus.Display[ dpos ]);
2003-02-07 20:49:01 +00:00
}
break;
default: /* all other characters */
2004-11-03 20:48:45 +00:00
PUTCHAR(menus.Display[ dpos ]);
2001-09-23 19:09:20 +00:00
}
2003-02-07 20:49:01 +00:00
}
2001-09-23 19:09:20 +00:00
2003-02-07 20:49:01 +00:00
if ( !skipCRLF ) {
2004-11-03 20:48:45 +00:00
Enter(1);
2003-02-07 20:49:01 +00:00
}
2001-09-23 19:09:20 +00:00
}
2003-02-07 20:49:01 +00:00