home *** CD-ROM | disk | FTP | other *** search
- /* *********************************************************************************
-
- MODULE: Menu Module
-
- DESCRIPTION: This menu module is a simple module for MUBBS, the Multi-User
- Bulliten Board System Software.
-
- AUTHOR: Noam Freedman
-
- Copyright © 1990 by Noam Freedman, All Rights Reserved.
-
- Revision History:
- ============================================================
- 9/23/91 - Started programming the module.
- 9/26/91 - Finished the basic module.
- 9/30/91 - Added some bug fixes.
- 10/3/91 - Finally fixed the menu info loader.
- 10/6/91 - Modified by N Hawthorn for release
- ============================================================
-
- COMMENTS: You MUST RENAME this module for each DIFFERENT menu you
- want.
- Module names are never over 26 characters !!
-
- ********************************************************************************
-
- The code to this Module is being released for the SOLE purpose to be a tutorial
- for programmers trying to program modules for MUBBS. Portions of this code may be
- used for non-commercial, no-cost-to-use modules (ie: You can't charge for any
- module using any part of this code....even shareware) without the consent of
- the author. Any module using this code must give credit to the author,
- Noam Freedman.
-
- ******************************************************************************** */
-
- #define INMAIN
-
- #include <SetUpA4.h>
- #include "MUBBS Module.h"
-
- /* my globals for this module */
-
-
-
- pascal void main (mode1,G1,P1)
- int mode1;
- struct GS *G1;
- Ptr *P1; /* we ignore "P" in this module */
- {
- Handle temph;
- float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
- RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
- asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
-
- G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
- mode[u]=mode1; /* set up our mode so that you can read it anywhere */
-
- switch (mode[u]) { /* any un-handled modes return error from this module */
- case 2:
- domenu();
- G->moduleresult=0;
- break;
- case 98:
- versionck(version); /* just return after this call, don't modify anything */
- break;
- case 0:
- strcpy (G->programmer,"Noam Freedman"); /* show the programmer's name up to 20 chars*/
- G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
- break;
- default:
- G->moduleresult=1; /* return bad code */
- };
-
- HUnlock(temph); /* unlocks this module, do this ! */
- RestoreA4(); /* call this when you are all done */
- }
-
-
- /* DISPLAY THE TEXT, IF ANY, FOR THE MENU */
-
-
- displaymenu()
- {
- char tempstring[100];
- /* Generate the filename */
- strcpy(tempstring,":menus:");
- strcat(tempstring,G->modulename[u]);
- if (G->language[u] == 1)
- strcat(tempstring,".ansi");
- else
- strcat(tempstring,".txt");
-
- /* Display the textfile */
- G->okcancel[u]=TRUE;
- G->nocheck[u]=FALSE; /* check for controls */
- G->cancel[u]=FALSE;
- sendtext(tempstring);
- }
-
- checktime(warned) /* check if they are out of time yet */
- int warned;
- {
-
- if(G->timeon[u] >= G->timeallowed[u]) {
- send("]]YOUR TIME HAS EXPIRED, PLEASE CALL BACK TOMMOROW..]");
- G->online[u]=FALSE; /* log them off now ! */
- return TRUE;
- }
- if(!warned && (G->timeon[u]+5) >= G->timeallowed[u]) {
- send("]LOGOFF WARNING, YOU HAVE 5 MINUTES OF TIME LEFT !]");
- return TRUE;
- }
- return FALSE;
- }
-
-
- /* ASKUSER ASKS THE USER FOR INPUT THEN LAUNCHES THE CORRECT MODULE */
-
- domenu()
- {
- int i,a,num,warned;
- char ch;
- FILE *stream; /* you MUST define this here so that other nodes don't get messed up */
- char tempstring[100];
- char m_realnames[21][30], /* up to 20 menu selections are allowed */
- modulesc[21]; /* in MUBBS we don't use many selections on */
- /* one menu anyway */
-
- if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
-
- /* Generate the filename */
- strcpy(tempstring,":menus:");
- strcat(tempstring,G->modulename[u]);
- strcat(tempstring,".info");
- /* LOAD IN THE INFORMATION FOR THE MENU */
-
- i = 0;
-
- /* Open the file */
- if ((stream = fopen(tempstring, "r")) == NULL) {
- send("]FILE ERROR cannot open %s ", /*its a %d ,errno,*/ tempstring);
- return;
- }
- else /* If no error, read from the file */
- {
- a = 0;
- while (a == 0){
- if(fscanf(stream,"%c\n",&modulesc[i]) != EOF) { /* Read and check for EOF */
- if (fgets(m_realnames[i],30,stream) != NULL) { /* Read and check for EOF */
- remlf(m_realnames[i]); /* take out line feed */
- i++;
- if (i >= 20) a = 1;
- }
- }
- else {
- a = 1;
- }
- }
- fclose(stream);
- }
-
- num=i; /* Loads in the choice of modules from a text file */
- warned=FALSE; /* they havent been warned yet... */
-
- while (TRUE)
- {
- if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
- loguser(G->modulename[u]); /* this tells where you are for remote sysop, or writes to log file */
- print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
- displaymenu(); /* Displays the text, for the menu */
- if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
- warned=checktime(warned);
- if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
-
- if (!(cmd1(""))) goto byebye; /* timeout ? */
- ch = G->input[u];
-
- /* Check to see if the user typed a valid key, and if so, launch the module */
- for (i = 0;i<num;i++)
- if (ch == modulesc[i])
- {
- send (G->CR[u]); /* don't do: send ("]"), you waste data area space */
- if (strcmp(m_realnames[i],"quit") == 0) return; /* If the user hit Quit, then just return */
- if (strcmp(m_realnames[i],"logoff") == 0) goto byebye; /* cause a logoff */
- module(2,m_realnames[i],0L);
- i = 1 + num;
- }
- }
-
- byebye:
- G->online[u]=FALSE; /* show we timed out */
- }
-
- remlf(string)
- char *string;
- {
- int temp,b;
- b = strlen(string);
- for (temp=0; temp<= b; temp++)
- {
- if (string[temp] == 10)
- string[temp] = 0;
- }
-
- }
-