home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (C) 1989 The GAP Development Company
-
- All Rights Reserved
-
-
- CDOOR.C
-
- Demonstration program for GAPCDR
-
- To compile : cl /c cdoor
- To link : link cdoor,,NUL.MAP,+gapcdrs
-
- Program will need access to CDOOR.CNF, DOOR.SYS, GAPBBS.CNF, GAPDOS.DAT
-
- /*
-
-
- #define LINT_ARGS
-
- #pragma check_stack(off) // we dont need stack checking
-
-
- /***********************************************************************/
- /* Before doing ANYTHING else, include the following files. */
- /***********************************************************************/
-
- #include <stdio.h> // C standard header file
-
- #include "gapcdr.h" // header file for GAPCDR
-
-
- /***********************************************************************/
- /* Declare any global variables */
- /***********************************************************************/
-
- char anystring1 [250]; // global garbage collector
- char prompt [80]; // for the prompt line
-
- char *menug [] =
- {
- "C╔══════════════════════════════════════╗",
- " ║CMain MenuC║",
- " ╟──────────────────────────────────────╢",
- " ║C║",
- " ║ [T]op PlayersC[P]age Sysop ║",
- " ║ [H]elpC[U]ser Stats ║",
- " ║ [Q]uitC[G]ambleC║",
- " ╚══════════════════════════════════════╝",
- "\0"
- };
-
-
- char *menua [] =
- {
- " ╔══════════════════════════════════════╗",
- " ║ Main Menu ║",
- " ╟──────────────────────────────────────╢",
- " ║ ║",
- " ║ [T]op Players [P]age Sysop ║",
- " ║ [H]elp [U]ser Stats ║",
- " ║ [Q]uit [G]amble ║",
- " ╚══════════════════════════════════════╝",
- "\0"
- };
-
-
-
- /***********************************************************************/
- /* Begin main line code here */
- /***********************************************************************/
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int bobo; // to keep track of errors
- int oldbell; // status of page bell flag
- char **menu; // pointer to menu arrays
- char response [80]; // for getting responses
-
- FILE *doorcnf; // file pointer for cnf file
-
-
- /***********************************************************************/
- /* Before doing ANYTHING else, initialize the door with the following */
- /* two function calls. */
- /* Then, if you have any configuration options, read them in and then */
- /* close the file. */
- /* Note that we are hardcoding the name of the configuration file. */
- /* Normally, this is passed as a command line parameter so you would */
- /* call read_cnf like this : doorcnf = read_cnf(argv[1]); */
- /***********************************************************************/
-
- doorcnf = read_cnf("CDOOR.CNF"); // read door configuration file
- init_door(); // initialize the door
-
- fclose(doorcnf); // we dont have any configuration
- // options so we will just close
-
-
- /***********************************************************************/
- /* Now, we are going to keep track of the time credit variable that */
- /* is stored in the GAPDOS.DAT file. We are going to do this because */
- /* we are such nice people and we want to credit the caller for the */
- /* time spent during our chat demonstration. Remember, at the */
- /* beginning of the program, after initializing the door, is the */
- /* place to do this because the variable 'timecredit' is initialized */
- /* at doors beginning. */
- /* */
- /* NOTE! This function will fail (the reason for bobo) if GAPDOS.DAT */
- /* does not exist (which it will not unless this program is being */
- /* tested via the BBS door routines. If you need to test this */
- /* feature, you will need to have a backup copy of GAPDOS.DAT that */
- /* can be placed in your BBS default directory prior to running this */
- /* demo! */
- /***********************************************************************/
-
- bobo = read_gapdos(); // read the system file
-
- /***********************************************************************/
- /* show_mess is the major string output function. You have the */
- /* option of ringing the bell (second parameter) and sending a CR/LF */
- /* (third option) after displaying the string. */
- /***********************************************************************/
-
- if (!bobo)
- {
- sprintf(anystring1,"GAPDOS.DAT says you have %d time credits (in minutes).",
- gapdos.timecredit);
- show_mess(anystring1,NO,YES); // display the string
- }
- else
- {
- nl(2); // send a couple of blank lines
- ansi(BRED); // change to bright red
- show_mess("Could Not Open GAPDOS.DAT!",YES,YES); // error message
- }
-
- nl(2); // send a couple of blank lines
-
-
- /***********************************************************************/
- /* Change the color prior to displaying a prompt. Send a prompt to */
- /* the caller and await an answer. */
- /***********************************************************************/
-
- ansi(BGREEN); // set default color to bright Green
-
- show_mess("Please Enter Your Name : ",YES,NO); // main output routine
-
- /***********************************************************************/
- /* get_string is the main input routine. To utilize it, you pass the */
- /* string to "fill" with the user response. The length of the input */
- /* is determined by the length of the string passed. The function */
- /* empty is provided so that you may "empty" a string by filling it */
- /* with spaces. */
- /***********************************************************************/
-
- empty(response,30); // must initialize all variables
- // passed to get_string
- get_string(response); // now get the caller's name
-
- nl(1); // display a blank line
-
-
- /***********************************************************************/
- /* An alternative way to change colors on the fly is to do it */
- /* inline. It is also a bit faster since fewer function calls are */
- /* made. But note that to change colors like this, you have to test */
- /* if the caller is in color mode. */
- /***********************************************************************/
-
- if (color)
- sprintf(anystring1,"%sYour name is : %s%s%s.",BCYAN,BRED,response,BCYAN);
- else
- sprintf(anystring1,"%sYour name is : %s.",response);
-
- /***********************************************************************/
- /* Note that you could also do this but be forwarned that this type */
- /* of coding produces a LOT of assembler code! */
- /* */
- /* sprintf(anystring,"%sYour name is : %s%s%s.", */
- /* color ? BCYAN : "",color ? BRED : "", response, */
- /* color ? BCYAN : ""); */
- /***********************************************************************/
-
- show_mess(anystring1, NO, YES); // tell caller what was entered
-
- nl(1); // display a blank line
-
- ansi(BGREEN); // change colors
-
- show_mess("But on the BBS, your First Name is : ",NO,NO);
- show_mess(fname,NO,YES);
-
- nl(1); // display a blank line
-
- pause(); // wait for a key press before continuing
-
- nl(2); // display a couple of blank lines
-
-
- /***********************************************************************/
- /* The next example is the WRONG way to display a color string since */
- /* it does not bother checking if the user is in color mode. */
- /* The correct way is to check the color variable. If it is a 1 */
- /* then it is safe to send color. This is exactly what ansi() does. */
- /***********************************************************************/
-
- sprintf(anystring1,"%s%s\r\n%s\r\n%s%s",
- BRED,"I'm going to mess up your black & white screen.",
- "Because I'm not checking to see if you have ",
- BWHITE,"Color turned on!!!");
-
- show_mess(anystring1, NO, YES); // show the ugly mess
-
- nl(2); // couple of blank lines
-
-
-
- /***********************************************************************/
- /* It is now time to page the sysop. Just in case the sysop has his */
- /* page bell turned off, we are going to cheat a bit and turn it on. */
- /* For demonstration purposes only, you see! */
- /* We will also demonstrate how to obtain and display the time left. */
- /* */
- /* Note that the 'timeleft' variable is automatically updated by the */
- /* input routines. If you need to make sure that it is current, you */
- /* can always call time_left() prior to using it. */
- /***********************************************************************/
-
- do
- {
- nl(1);
-
- if (color)
- sprintf(anystring1,"%s[%s%d mins%s] To Page the Sysop, type a 'P' : ",
- YELLOW,BRED,timeleft,YELLOW);
- else
- sprintf(anystring1,"[%d mins] To Page the Sysop, type a 'P' : ",
- timeleft);
-
- show_mess(anystring1, NO, NO); // show the prompt
-
- empty(response,1); // must initialize get_string variable
- get_string(response); // get the caller's response
- }
- while (response[0] != 'P'); // loop till valid response
-
-
- /***********************************************************************/
- /* We are going to override the sysop's page bell flag so we can */
- /* hear the bell. This is not a good thing to do as it will tend */
- /* to anger the sysop if a door program does not honor his BBS */
- /* settings. Sorry sysop. We'll put the bell flag back the way it */
- /* was when we are finished. */
- /***********************************************************************/
-
- oldbell = bell; // keep track of old bell setting
- bell = 1; // turn sysop's page bell on
-
- pagesysop(); // now page the sysop
-
- bell = oldbell; // restore old bell setting
-
- /***********************************************************************/
- /* Lets now display a file. We want to display a color version of */
- /* the file if the caller is in color mode and an ascii version of */
- /* the file if the caller is in non-color mode. So, we will ask the */
- /* programmer to supply the name of a BBS welcome file. */
- /* The programmer should supply the name of the non-color version of */
- /* the file (IE, no 'G' at the end of the name). */
- /* */
- /* The show_file() routine makes certain assumptions about the file */
- /* name being passed to it. It assumes that you are calling it with */
- /* a path and file name for a file that you know is or should be */
- /* present. Show_file() will attempt to find the file, but if it */
- /* cannot, it simply returns (no error code). */
- /* If you are gathering input from the user, as this example does, */
- /* you may want to call access to first see if the file exists. */
- /***********************************************************************/
-
- /***********************************************************************/
- /* A word about the Microsoft C access function. In short, it is */
- /* buggy and not 100% reliable. In a multi-user system, the */
- /* function will fail every time if a user on one node is reading */
- /* a file that has been opened with fopen or open, and a user is on */
- /* another node trying to use the access function to see if the file */
- /* exists. The access function returns an error that the file is not */
- /* there, when in fact it IS there. */
- /* Because of this we have supplied (undocumented) a function called */
- /* access1. It works just like the access function except that it */
- /* works on path/filenames only so you dont give it an access mode. */
- /* It checks for the existence of a file the proper way and works */
- /* irregardless of whether or not the file is already in use by */
- /* by another user. */
- /***********************************************************************/
-
- nl(2); // display a couple of blank lines
-
- while (1)
- {
- ansi(YELLOW); // set a default color
-
- show_mess("Enter full path name to your BBS Welcome File : ", NO, NO);
-
- empty(response,65); // must initialize
- get_string(response); // get the path and name of file to show
-
- if ( (access1(response))) // does file exist?
- {
- nl(1);
- ansi(BRED); // no, tell them in RED!
- show_mess("File Not Found!",YES,YES);
- nl(1);
- }
- else // yes, go display it
- break;
- } // till valid file name entered
-
-
- ansi(YELLOW); // reset default color
-
- show_file(response); // now show the file.
-
-
-
- /***********************************************************************/
- /* Lets see what is going on with the time credit variable. */
- /* Depending upon how long the programmer chatted with his/her self, */
- /* or if the up or down arrow keys were pressed at any time, it could */
- /* be quite different from what GAP wrote to the GAPDOS.DAT file! */
- /***********************************************************************/
-
-
- if (!bobo) // only if we could 1st read the file
- {
- nl(2); // display a couple of blank lines
- ansi(BGREEN); // set a default color
-
- sprintf(anystring1,"GAPDOS timecredit was %d mins.",gapdos.timecredit);
- show_mess(anystring1,NO,YES);
-
- ansi(BWHITE);
-
- show_mess("We are going to explicitly ADD 20 minutes.", NO, YES);
-
- timecredit += 20; // add 20 minutes
-
- gapdos.timecredit += timecredit;
-
- bobo = write_gapdos(); // update GAPDOS.DAT
- nl(1); // show a blank line
- ansi(BGREEN);
-
- sprintf(anystring1,"GAPDOS timecredit now equals %d mins.",
- gapdos.timecredit);
-
- show_mess(anystring1, NO, YES);
-
- ansi(YELLOW); // set a default color
-
- show_mess("Any difference came from CHAT or Up/Down Arrow Keys!", YES, NO);
- }
-
- nl(2); // display a couple of blank lines
-
- pause(); // pause before continuing
-
-
- /***********************************************************************/
- /* Lets now build some menus all at once. */
- /* These menus were created with an ANSI editor. This is perhaps the */
- /* fastest and easiest way to create menus. */
- /***********************************************************************/
-
-
- if (color) // set up the prompts
- sprintf(prompt,"\r\n%s[%s%d mins%s] Main Command : ",
- YELLOW,BRED,timeleft,YELLOW);
- else
- sprintf(prompt,"\r\n[%d mins] Main Command : ",timeleft);
-
- do
- {
- clear_scrn(); // first clear the screen
-
- nl(2); // do a couple of blank lines
-
- if (color) // set pointer into menus
- menu = menug;
- else
- menu = menua;
-
- while (**menu) // now show the menu
- show_mess(*menu++,NO,YES);
-
- show_mess(prompt,NO,NO); // show the prompt
-
- empty(response,1); // initialize response
- get_string(response); // get user input
-
- switch (response[0])
- {
- case 'P' : // page the sysop
- pagesysop();
- break;
-
- case 'Q' : // quit
- break;
-
- case 'T' : // show the scoreboard
- read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
- break;
-
- default : // choice no good
- nl(2);
- ansi(BRED);
- show_mess("Only Menu Choices 'Q, P and T' Are Working!",YES,YES);
- nl(1);
- pause();
- }
- }
- while (response[0] != 'Q');
-
- leave(0); // must exit properly!
- }
-
-