home *** CD-ROM | disk | FTP | other *** search
- /* FILENAME: VPID.C VERSION: Beta 1.00
- **
- ** DESCRIPTION: VGA Planets Interface Door for Bulletin Board Systems.
- ** Compile with OpenDoors BBS door programming toolkit.
- **
- ** AUTHOR: John Kristoff START DATE: 06/07/94
- ** Internet: jkristof@interaccess.com
- ** Internet: jkristof@bsd.meddean.luc.edu
- ** FidoNet: 1:115/743
- ** CompuServe: 74111,3652
- **
- ** VERSION DATE WHO DETAIL
- ** Beta1.00 19May96 JK Initial design and coding
- **
- ** Copyright John Kristoff, 1994-96. All rights reserved.
- ** You may use this program or any part there-of as desired
- ** without restriction.
- */
-
- #include <stdio.h> /* Standard i/o functions */
- #include <stdlib.h> /* Standard library functions */
-
- #include "opendoor.h" /* OpenDoors structures */
- #include "od_error.h" /* Error control */
-
-
- /* --- Standard defs --- */
- #define VERSION "Beta 1.00" /* Program version */
-
- #define MAX_PLAYERS 11 /* Max players allowed in game */
- #define NEW_PLAYER -1 /* New player number */
-
- #define DATA_FILE "VPID.DAT" /* Program data file */
- #define MSGS_FILE "VPID.MSG" /* User messages file */
- #define WELCOME_SCREEN "VPID" /* ASC/ANS/RIP welcome screen */
- #define HELP_FILE "VPIDHELP" /* ASC/ANS/RIP help screen */
- #define SCORE_FILE "VPIDSCOR" /* VGA Planets score file */
-
- #define YES 1 /* Yes answer */
- #define NO 0 /* No answer */
-
- #define UPLOAD 1 /* Upload option */
- #define DOWNLOAD 0 /* Download option */
-
- /* --- typedefs --- */
- typedef struct /* GAME DATA Structure */
- {
- char Username[MAX_PLAYERS][36]; /* - Players in game */
- int Status[MAX_PLAYERS]; /* - Result file D/L status */
- int Reserved[60]; /* - Reserved struct space */
- } GAMEDATA;
-
-
- /* --- Constants --- */
- const char
- RaceName[MAX_PLAYERS][16] = /* Team names */
- {
- "Federation",
- "Lizards",
- "Birdmen",
- "Fascists",
- "Privateers",
- "Cyborgs",
- "Crystal People",
- "Evil Empire",
- "Robotic Empire",
- "Rebels",
- "Colonies of Man"
- };
-
- const int
- RaceChar[MAX_PLAYERS] = /* Team character designator */
- {
- '1','2','3','4','5','6','7','8','9','A','B'
- };
-
- const int
- RaceNum[MAX_PLAYERS] = /* Team number designator */
- {
- '1','2','3','4','5','6','7','8','9','10','11'
- };
-
- /* --- Function declarations --- */
- int main( int argc, char * argv[] );
- void DisplayWelcomeScreen( void );
- void DoMainMenu( void );
- int DisplayMainMenu( void );
- int FindPlayer( void );
- void ShowTurnStatus( int PlayerNum );
- int JoinGame( void );
- void Messages( void );
- void Scores( void );
- void TransferFile( int PlayerNum, int Direction );
- void Help( void );
- void UpdateDlStatus( int PlayerNum );
- int Confirm( void );
- void PressKey( void );
-
-
- /* --- HERE WE GO! --- */
-
- int
- main( int argc, char * argv[] )
- {
- /* --- Setup and initialize OpenDoors environment --- */
-
- strcpy( od_registered_to, "John Kristoff" );
- od_registration_key = 0000000000;
- od_control.od_nocopyright = TRUE;
- od_init(); /* Setup od_control.* struct */
- od_clr_scr(); /* Clear screen if enabled */
-
- DisplayWelcomeScreen();
-
- DoMainMenu();
-
- od_set_colour( D_GREY, D_BLACK ); /* Reset color before exit */
- od_printf( "Returning to BBS\n\r" );
-
- od_exit( EXIT_SUCCESS, FALSE );
- return( EXIT_SUCCESS );
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Display opening program screen upon start-up */
- /* ----------------------------------------------------------------- */
-
- void
- DisplayWelcomeScreen( void )
- {
- if( od_send_file("WELCOME_SCREEN") == 0 )
- {
- od_printf( "`bright cyan`VPID v" VERSION ", " __DATE__ ". " );
- od_printf( "`bright white`The VGA Planets Interface Door.\n\r" );
- od_printf( "`bright blue`Copyright John Kristoff, 1994-96. " );
- od_printf( "All rights reserved.\n\r" );
- od_printf( "\n\r" );
- PressKey();
- }
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* This is the function is the backbone of the program from the */
- /* user's perspective. Every major function is called from here. */
- /* ----------------------------------------------------------------- */
-
- void
- DoMainMenu( void )
- {
- int PlayerNum; /* Number of choosen VGAP race */
- int MenuChoice; /* Main menu selection */
-
- PlayerNum = FindPlayer(); /* Is this a new player? */
-
- do
- {
- if( PlayerNum != NEW_PLAYER )
- {
- ShowTurnStatus( PlayerNum );
- }
-
- MenuChoice = DisplayMainMenu();
- switch( MenuChoice )
- {
- /* --- [D] Download RST file --- */
-
- case 'D' : if( PlayerNum != NEW_PLAYER )
- {
- TransferFile( PlayerNum, DOWNLOAD );
- }
- else
- {
- od_printf( "\n\r" );
- od_printf( "WHAT?!? You're not in this game yet.\n\r" );
- PressKey();
- }
- break;
-
-
- /* --- [J] Join the game --- */
-
- case 'J' : if( PlayerNum == NEW_PLAYER )
- {
- PlayerNum = JoinGame();
- }
- else
- {
- od_printf( "\n\r" );
- od_printf( "WHAT?!? You can't " );
- od_printf( "do that. You're playing The " );
- od_printf( "%s. ", RaceName[PlayerNum] );
- od_printf( "Remeber?\n\r" );
- PressKey();
- }
- break;
-
-
- /* --- [M] Messages by users --- */
-
- case 'M' : Messages();
- break;
-
-
- /* --- [S] Scores display --- */
-
- case 'S' : Scores();
- break;
-
-
- /* --- [U] Upload TRN file --- */
-
- case 'U' : if( PlayerNum != NEW_PLAYER )
- {
- TransferFile( PlayerNum, UPLOAD );
- }
- else
- {
- od_printf( "\n\r" );
- od_printf( "WHAT?!? You're not in this game yet.\n\r" );
- PressKey();
- }
- break;
-
-
- /* --- [H] Help file display --- */
-
- case '?' : Help();
- break;
-
-
- /* --- [Q] Quit to BBS --- */
-
- case 'Q' : break;
- }
- od_printf( "\n\r" ); /* Blank line after selection */
- }
- while( MenuChoice != 'Q' ); /* Until user [Q] Quits to BBS */
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* First check to see if DATA_FILE can be opened. If it can, check */
- /* to see if the player is in the current game. If it can't be */
- /* opened, assuse the file doesn't exist and assume a new game. */
- /* ----------------------------------------------------------------- */
-
- int
- FindPlayer( void )
- {
- int PlayerNum = NEW_PLAYER; /* Number of choosen VGAP team */
- int Counter = 0; /* Loop counter */
-
- GAMEDATA * GameData = NULL; /* Point to GAME DATA struct */
- FILE * fp = NULL; /* File pointer to DATA_FILE */
-
-
- /* --- Open DATA_FILE. If can't be opened, new game assumed. --- */
-
- if( (fp = fopen(DATA_FILE, "rb")) != NULL )
- {
- GameData = (GAMEDATA *) calloc( 1, sizeof(GAMEDATA) );
- if( GameData == NULL )
- {
- Error( MEM, __LINE__, NULL );
- }
-
- if( fread( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( READ, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, DATA_FILE );
- }
-
-
- /* --- Search for user in GAME DATA struct --- */
-
- for( Counter = 0; Counter < MAX_PLAYERS; Counter++ )
- {
- if( strcmp(GameData->Username[Counter], od_control.user_name) == 0 )
- {
- PlayerNum = Counter; /* Found! */
- break;
- }
- }
- }
- return( PlayerNum );
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Check to see if this player has uploaded his PLAYERx.TRN yet. If */
- /* not, see if he/she has downloaded the latest PLAYER.RST file. */
- /* A message is displayed to the user depending on the status of */
- /* his/her turn. */
- /* ----------------------------------------------------------------- */
-
- void
- ShowTurnStatus( int PlayerNum )
- {
- char TurnFile[13] = ""; /* PLAYERx.TRN filename */
- char ResultFile[13] = ""; /* PLAYERx.RST filename */
- GAMEDATA * GameData = NULL; /* Point to GAME DATA struct */
- FILE * fp = NULL; /* File pointer to PLAYERx.TRN */
-
-
- od_printf( "Your team: The %s. Good luck!\n\r", RaceName[PlayerNum] );
-
-
- /* --- Build turn filename --- */
-
- sprintf( TurnFile, "PLAYER%d.TRN", RaceNum[PlayerNum] );
-
-
- /* --- Let's see if this player has uploaded their turn file --- */
-
- fp = fopen( TurnFile, "rb" );
- if( fp != NULL )
- {
- od_printf( "`bright white`You have uploaded your .TRN file " );
- od_printf( "and are awaiting HOST to be run.\n\r" );
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, TurnFile );
- }
- }
- else
- {
- /* --- Didn't upload yet, has result file been downloaded? --- */
-
- GameData = (GAMEDATA *) calloc( 1, sizeof(GAMEDATA) );
- if( GameData == NULL )
- {
- Error( MEM, __LINE__, NULL );
- }
-
- /* --- Build result filename --- */
-
- sprintf( ResultFile, "PLAYER%d.RST", RaceNum[PlayerNum] );
-
- fp = fopen( ResultFile, "rb" );
- if( fp != NULL )
- {
- if( fread( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( READ, __LINE__, DATA_FILE );
- }
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, TurnFile );
- }
- }
-
- if( GameData->Status[PlayerNum] == FALSE )
- {
- od_printf( "`bright green`We've got a new RST file for you.\n\r" );
- }
- else
- {
- od_printf( "`bright green`We're waiting for your TRN file.\n\r" );
- }
- }
- od_printf( "\n\r" );
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Display .ASC/.ANS/.RIP menu if it exists, else display internally */
- /* created menu. Send back the menu option user selected. */
- /* ----------------------------------------------------------------- */
-
- int
- DisplayMainMenu( void )
- {
- int MenuChoice = 0;
-
- od_set_colour( D_GREY, D_BLACK );
- od_printf( "\n\r" );
-
- MenuChoice = od_hotkey_menu( "MAINMENU", "DJMSU?Q", TRUE );
-
- /* --- If menu file didn't exist, display a basic one now --- */
- if( MenuChoice == 0 )
- {
- /* Download */
- od_printf( " `dark blue`[`bright cyan`D`dark blue`] " );
- od_printf( "`bright blue`Download RST File\n\r" );
-
- /* Upload */
- od_printf( " `dark blue`[`bright cyan`U`dark blue`] " );
- od_printf( "`bright blue`Upload RST File\n\r" );
-
- /* Join */
- od_printf( " `dark blue`[`bright cyan`J`dark blue`] " );
- od_printf( "`bright blue`Join the Game\n\r" );
-
- /* Messages */
- od_printf( " `dark blue`[`bright cyan`M`dark blue`] " );
- od_printf("`bright blue`Messages\n\r" );
-
- /* Scores */
- od_printf( " `dark blue`[`bright cyan`S`dark blue`] " );
- od_printf( "`bright blue`Scores\n\r" );
-
- /* Help */
- od_printf( " `dark blue`[`bright cyan`?`dark blue`] " );
- od_printf( "`bright blue`Help\n\r" );
-
- /* Quit */
- od_printf( " `dark blue`[`bright cyan`Q`dark blue`] " );
- od_printf( "`bright blue`Quit to BBS\n\r" );
-
- od_printf( "\n\r" );
- od_set_colour( L_BLUE, D_BLACK );
- od_printf( "Command:" );
- od_set_colour( D_GREY, D_BLACK );
-
- MenuChoice = od_get_answer( "DJMSU?Q" );
-
- od_printf( "\n\r" );
- }
- return( MenuChoice );
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Transfer the file based on user's selected protocol. */
- /* ----------------------------------------------------------------- */
-
- void
- TransferFile( int PlayerNum, int Direction )
- {
- char Protocol; /* Protocol selected by user */
- char CommandLine[256]; /* Complete protocol commandline */
- char * SpawnArgs[3]; /* ...spawn..() arguments */
-
- SpawnArgs[0] = "DSZ"; /* Protocol program filename */
- SpawnArgs[1] = CommandLine; /* Complete commandline */
- SpawnArgs[2] = NULL; /* NULL terminate arg string */
-
- od_printf( "Select a protocol\n\r" );
- od_printf( "\n\r" );
- od_printf( "`dark blue`[`bright cyan`X`dark blue`] `bright blue`Xmodem\n\r" );
- od_printf( "`dark blue`[`bright cyan`Y`dark blue`] `bright blue`Ymodem\n\r" );
- od_printf( "`dark blue`[`bright cyan`Z`dark blue`] `bright blue`Zmodem\n\r" );
- od_printf( "`dark blue`[`bright red`A`dark blue`] `bright red`Abort\n\r" );
- od_printf( "\n\r" );
- od_printf( "`bright blue`Command:" );
-
- Protocol = od_get_answer( "xyza" );
- if( Protocol != 'a' )
- {
- if( Direction == DOWNLOAD )
- {
- sprintf( CommandLine,
- "%s port %d s%c PLAYER%c.RST",
- SpawnArgs[0],
- od_control.port+1,
- Protocol,
- RaceNum[PlayerNum]
- );
- }
- else
- {
- sprintf( CommandLine,
- "%s port %d r%c PLAYER%c.TRN",
- SpawnArgs[0],
- od_control.port+1,
- Protocol,
- RaceNum[PlayerNum]
- );
- }
-
-
- od_printf( "Start your transfer...\n\r" );
-
- if( od_spawnvpe(P_WAIT, SpawnArgs[0], SpawnArgs, NULL) == 0 )
- {
- od_printf( "`bright green`Transfer successful!\n\r" );
- UpdateDlStatus( PlayerNum );
- }
- else
- {
- od_printf( "`bright red`ERROR: Transfer failed!\n\r" );
- }
- PressKey();
- }
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Find the available teams and allow user to select one. When they */
- /* do, write that info to the data file. Otherwise, exit back to */
- /* the main menu. */
- /* ----------------------------------------------------------------- */
-
- int
- JoinGame( void )
- {
- int PlayerNum = NEW_PLAYER;
- int Available = 0;
- int Counter = 0;
-
- int MenuChoice;
- char ValidMenuChoices[MAX_PLAYERS + 2] = "";
-
- GAMEDATA * GameData = NULL;
-
- FILE * fp;
-
- /* Allocate memory for game data */
-
- GameData = (GAMEDATA *) calloc( 1, sizeof(GAMEDATA) );
- if( GameData == NULL )
- {
- Error( MEM, __LINE__, NULL );
- }
-
-
- /* Read game data into struct */
-
- fp = fopen( DATA_FILE, "rb" );
- if( fp != NULL )
- {
- if( fread( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( READ, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, DATA_FILE );
- }
- }
-
-
- /* Look for openings in the game */
-
- for( Counter = 0; Counter < MAX_PLAYERS; Counter++ )
- {
- if( GameData->Username[Counter][0] == '\0' )
- {
- od_printf( "`bright blue`[`bright white`%c`bright blue`]",
- RaceChar[Counter] );
- od_printf( " `bright cyan`%-20s", RaceName[Counter] );
- od_printf( " `bright yellow`AVAILABLE\n\r" );
- ValidMenuChoices[Available++] = RaceChar[Counter];
- }
- else
- {
- od_printf( "`white`[%c]",RaceChar[Counter] );
- od_printf( " %-20s", RaceName[Counter] );
- od_printf( " Assigned to %s\n\r",GameData->Username[Counter] );
- }
- }
-
- od_disp_str( "\n\r" );
-
- if( Available == 0 )
- {
- od_printf( "`bright red`No teams Available!\n\r" );
- od_disp_str( "\n\r" );
- }
-
- od_printf( "`bright blue`[`bright white`Q`bright blue`]" );
- od_printf( " `bright cyan`Abort\n\r" );
- od_disp_str( "\n\r" );
- od_printf( "`bright blue`Choose A Team:`bright cyan`" );
-
- strcat( ValidMenuChoices, "Q" );
- MenuChoice = od_get_answer( ValidMenuChoices );
-
- od_printf( "\n\r" );
-
- if( MenuChoice != 'Q' )
- {
- /* Find which team the player selected */
-
- for( Counter = 0; Counter < MAX_PLAYERS; Counter++ )
- {
- if( RaceChar[Counter] == MenuChoice )
- {
- PlayerNum = Counter;
-
- fp = fopen( DATA_FILE, "rb" );
- if( fp != NULL )
- {
- if( fread( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( READ, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, DATA_FILE );
- }
- }
-
- strcpy( GameData->Username[Counter], od_control.user_name );
-
- fp = fopen( DATA_FILE, "wb" );
- if( fp != NULL )
- {
- if( fwrite( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( WRITE, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, DATA_FILE );
- }
- }
-
- break;
- }
- }
- }
- return( PlayerNum );
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* User messages function. */
- /* ----------------------------------------------------------------- */
-
- void
- Messages( void )
- {
- char MessageText[76] = "";
-
- FILE * fp;
-
- od_printf( "\n\r" );
- od_printf( "Babblings of the races...\n\r" );
- od_repeat( '-', 78 );
- od_printf( "\n\r" );
- od_send_file( MSGS_FILE );
- od_printf( "\n\r" );
- od_printf( "Would you like to add to the conversation? [Y/N]" );
-
- if( od_get_answer("YN") == 'Y' )
- {
- od_printf( "\n\r" );
- od_printf( "Enter a one line message. Max 75 characters.\n\r" );
- od_printf( "Hit <Enter> when done.\n\r" );
- od_printf( ":" );
- od_input_str( MessageText, 75, 32, 127 );
- od_printf( "\n\r" );
-
- if( MessageText[0] != '\0' )
- {
- fp = fopen( MSGS_FILE, "a" );
- if( fp != NULL )
- {
- if( fprintf(fp, "%s:\n", od_control.user_name) == NULL )
- {
- Error( WRITE, __LINE__, MSGS_FILE );
- }
-
- if( fprintf(fp, " %s\n", MessageText) == NULL )
- {
- Error( WRITE, __LINE__, MSGS_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, MSGS_FILE );
- }
- }
- PressKey();
- }
- }
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Display scores file. Simple and incomplete. */
- /* ----------------------------------------------------------------- */
-
- void
- Scores( void )
- {
- od_set_colour( D_GREY, D_BLACK );
- od_printf( "\n\r" );
-
- if( od_send_file(SCORE_FILE) == 0 )
- {
- if( od_send_file("SCORE.LOG") == 0 )
- {
- od_printf( "Couldn't find a score file!\n\r" );
- PressKey();
- }
- }
-
- od_printf( "\n\r" );
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Display program help. */
- /* ----------------------------------------------------------------- */
-
- void
- Help( void )
- {
- od_printf( "\n\r" );
-
- if( od_send_file(HELP_FILE) == 0 )
- {
- od_printf( "Sorry, no help is available\n\r" );
- PressKey();
- }
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* If user downloaded the latest .RST file, change data file to */
- /* reflect the change. */
- /* ----------------------------------------------------------------- */
-
- void
- UpdateDlStatus( int RaceNum )
- {
- GAMEDATA * GameData = NULL;
-
- FILE * fp;
-
- GameData = (GAMEDATA *) calloc( 1, sizeof(GAMEDATA) );
- if( GameData == NULL )
- {
- Error( MEM, __LINE__, NULL );
- }
-
- fp = fopen( DATA_FILE, "rb" );
- if( fp != NULL )
- {
- if( fread( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( READ, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, DATA_FILE );
- }
- }
-
- GameData->Status[RaceNum] = TRUE;
-
- fp = fopen( DATA_FILE, "wb" );
- if( fp != NULL )
- {
- if( fwrite( GameData, sizeof(GAMEDATA), 1, fp) == NULL )
- {
- Error( WRITE, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- if( ferror(fp) )
- {
- Error( CLOSE, __LINE__, DATA_FILE );
- }
- }
- }
-
-
-
-
- /* ----------------------------------------------------------------- */
- /* Ask a yes/no question and send result back. */
- /* ----------------------------------------------------------------- */
-
- int
- Confirm( void )
- {
- od_printf( "`bright yellow`Are you sure? (Y/n):" );
- if( od_get_answer("YN") == 'Y' )
- {
- return( YES );
- }
- else
- {
- return( NO );
- }
- }
-
-
-
- /* ----------------------------------------------------------------- */
- /* Pause and wait for a key press before continuing. */
- /* ----------------------------------------------------------------- */
-
- void
- PressKey( void )
- {
- od_set_colour( L_BLUE, D_BLUE );
- od_printf( "░▒▓" );
- od_set_colour( L_WHITE, D_BLUE );
- od_printf( "PAUSED" );
- od_set_colour( L_BLUE, D_BLUE );
- od_printf( "░▒▓" );
- od_set_colour( D_GREY, D_BLACK );
- od_get_key( TRUE );
- od_repeat( '\b', 26 );
- od_repeat ( ' ', 26 );
- od_repeat( '\b', 26 );
- }
-