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

771 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-2003
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
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2001-08-17 05:46:24 +00:00
#include "../lib/libs.h"
2002-06-30 12:48:44 +00:00
#include "../lib/memwatch.h"
2001-08-17 05:46:24 +00:00
#include "../lib/mbse.h"
#include "../lib/structs.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-08-17 05:46:24 +00:00
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
2002-10-20 20:58:55 +00:00
#include "../lib/mberrors.h"
2001-08-17 05:46:24 +00:00
#include "oneline.h"
#include "mail.h"
#include "bbslist.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"
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;
sprintf(Menus[0], "%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;
char *Input, *Semfile, *sMenuPathFileName;
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));
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
2002-10-20 20:58:55 +00:00
WhosDoingWhat(BROWSING);
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.
*/
sprintf(sMenuPathFileName,"%s/%s", lang.MenuPath, Menus[MenuLevel]);
if ((pMenuFile = fopen(sMenuPathFileName, "r")) == NULL) {
sprintf(sMenuPathFileName,"%s/%s", CFG.bbs_menus, Menus[MenuLevel]);
pMenuFile = fopen(sMenuPathFileName,"r");
if (pMenuFile != NULL)
Syslog('+', "Menu %s (Default)", Menus[MenuLevel]);
} else {
Syslog('+', "Menu %s (%s)", Menus[MenuLevel], lang.Name);
}
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");
printf("Too many menu errors, notifying Sysop\n\n");
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))){
2002-10-20 20:58:55 +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
*/
Semfile = calloc(PATH_MAX, sizeof(char));
sprintf(Semfile, "%s/sema/upsdown", getenv("MBSE_ROOT"));
if (file_exist(Semfile, R_OK) == 0) {
fclose(pMenuFile);
Syslog('+', "Kicking user out, upsdown semafore detected");
printf("System power failure, closing the bbs\n\n");
free(Semfile);
sleep(3);
Good_Bye(MBERR_OK);
}
free(Semfile);
/*
* Check if SysOp wants to chat to user everytime user
* gets prompt. Make sure /tmp/chatdev exists before
* before calling chat(). Make sure if a second user
* logs in, that .BusyChatting does exist.
*/
2003-03-20 22:43:40 +00:00
if (CFG.iChatPromptChk && (access("/tmp/chatdev", R_OK) == 0) && (access("/tmp/.BusyChatting", F_OK) != 0))
Chat(0);
2002-10-20 20:58:55 +00:00
/*
* Check users timeleft
*/
TimeCheck();
alarm_on();
if (exitinfo.HotKeys) {
fflush(stdout);
Key = Getone();
sprintf(Input, "%c", Key);
printf("\n");
} 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))) {
Syslog('b', "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 {
sprintf(temp, "%c", menus.OptionalData[x]);
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) == '#')
sprintf(sPrompt, "%s%s", sPrompt, (char *) GetLocalHM());
else {
sprintf(temp, "%c", *(sPromptBak + x));
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 */
ExtDoor(menus.OptionalData, menus.NoDoorsys, menus.Y2Kdoorsys, menus.Comport, menus.NoSuid, menus.NoPrompt);
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';
printf("%s\n", menus.OptionalData);
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;
2001-08-17 05:46:24 +00:00
case 101:
FileArea_List(menus.OptionalData);
break;
case 102:
File_List();
break;
case 103:
ViewFile();
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 308:
Chg_ScreenLen();
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;
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;
case 501:
BBS_Add();
break;
case 502:
BBS_List();
break;
case 503:
BBS_Show();
break;
case 504:
BBS_Delete();
break;
case 506:
BBS_Search();
break;
default:
Enter(1);
pout(15, 0, (char *) Language(339));
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 {
printf("%c",menus.Display[ dpos ]);
}
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;
printf("%c",menus.Display[ dpos ]);
}
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;
printf("%c",menus.Display[ dpos ]);
}
break;
default: /* all other characters */
printf("%c",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 ) {
printf("\n");
}
2001-09-23 19:09:20 +00:00
}
2003-02-07 20:49:01 +00:00