home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OP2DEV.ZIP / BBSGLOB.C < prev    next >
C/C++ Source or Header  |  1991-03-31  |  7KB  |  234 lines

  1. //
  2. //  BBSAPI.C
  3. //  BBS Applications Programming Interface
  4. //
  5. //  Chris Boaro    10/13/89
  6. //
  7.  
  8. #define  INCL_DOS
  9. #define  INCL_SUB
  10. #include <os2.h>
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include <time.h>
  17.  
  18. #define EXPAN
  19. #include "os2bbs.h"        /* need the port_rec definition */
  20. #include "bbsapi.h"
  21. #include "bbsutil.h"
  22. #include "bbsglob.h"
  23.  
  24. //
  25. //  GloProcess()
  26. //
  27. //  Parses and processes a potential global command. If 'cmd'
  28. //  represents a valid global command, the appropriate
  29. //  routines is called and 1 is returned. Otherwise, 0 is
  30. //  returned. If 0 is returned, 'cmd' is a valid command
  31. //  and can be processed normally by the application.
  32. //
  33. DSDLL GloProcess(char *cmd, PORT_REC *unhand)
  34. {
  35.    short r = 0;
  36.  
  37.    if( (unhand->v_usron >= 2) && (cmd[0] == '/') ) {
  38.       if( strnicmp(&cmd[1],"w",1) == 0 ) {
  39.          GloUsersOn(unhand-(unhand->recnum),unhand);
  40.          r = 1;
  41.       }
  42.       else if( strnicmp(&cmd[1],"p",1) == 0 ) {
  43.          GloPageUser(unhand-(unhand->recnum),unhand);
  44.          r = 1;
  45.       }
  46.       else if( strnicmp(&cmd[1],"t",1) == 0 ) {
  47.          GloTimeLeft(unhand-(unhand->recnum),unhand);
  48.          r = 1;
  49.       }
  50.       else if( strnicmp(&cmd[1],"off",3) == 0 ) {
  51.          GloLogOff(unhand-(unhand->recnum),unhand);
  52.          r = 1;
  53.       }
  54.    }
  55.    return(r);
  56. }
  57.  
  58. //
  59. //  GloLogOff()
  60. //
  61. //  Log off quickly
  62. //
  63. DSDLL GloLogoff(PORT_REC *bport, PORT_REC *unhand)
  64. {
  65.    unhand->v_usron = 0;
  66.    DosSemClear((void far *) &(unhand->AbortRead) );
  67.    return(1);
  68. }
  69.  
  70. //
  71. //  GloTimeLeft()
  72. //
  73. //  Prints statistics about time online and time remaining
  74. //
  75. DSDLL GloTimeLeft(PORT_REC *bport, PORT_REC *unhand)
  76. {
  77.    char temp1[30], temp2[30], temp3[10];
  78.    long tm, call, today, tlong;
  79.    short col1 = GREEN;
  80.    short col2 = WHITE;
  81.  
  82.    time(&tm);
  83.    TimeString(temp1,tm,1);                  // time now
  84.    TimeString(temp2,unhand->t_login,1);  // time logged in
  85.    tlong = (tm - (unhand->t_login)) / 60L;
  86.    ltoa(tlong+1L,temp3,10);                 // minutes on
  87.  
  88.    call = (((unhand->t_offby - tm) / 60L) + (T_CREDIT/60L) + 1L);
  89.    if( unhand->gis->gisBillCode == 0 )
  90.       today = unhand->p_user->u_time_day - unhand->p_user->u_day_use - ((tm-T_LOGIN)/60L) + (T_CREDIT/60L);
  91.    else
  92.       today = unhand->p_user->u_time_month - unhand->p_user->u_mon_use - ((tm-T_LOGIN)/60L) + (T_CREDIT/60L);
  93.    if( today < 0 ) today = 0;
  94.  
  95.    SerColorWrite("\n\r         Current Time: ",col1,unhand);
  96.    SerColorWrite(temp1[0] == ' ' ? &temp1[1] : temp1,col2,unhand);
  97.    SerColorWrite("\n\r       Time Logged In: ",col1,unhand);
  98.    SerColorWrite(temp2[0] == ' ' ? &temp2[1] : temp2,col2,unhand);
  99.    SerColorWrite("\n\r       Minutes Online: ",col1,unhand);
  100.    SerColorWrite(temp3,col2,unhand);
  101.    SerColorWrite("\n\r  Time Left This Call: ",col1,unhand);
  102.    SerColorWrite(ltoa(call,temp1,10),col2,unhand);
  103.    if( unhand->gis->gisBillCode == 0 )
  104.       SerColorWrite("\n\r      Time Left Today: ",col1,unhand);
  105.    else
  106.       SerColorWrite("\n\r Time Left This Month: ",col1,unhand);
  107.    SerColorWrite(ltoa(today,temp2,10),col2,unhand);
  108.    SerColorWrite("\n\r",CREGCOL,unhand);
  109.    return(1);
  110. }
  111.  
  112. //
  113. //  GloPageUser()
  114. //
  115. //  Sends a page to a user
  116. //
  117. DSDLL GloPageUser(PORT_REC *bport, PORT_REC *unhand)
  118. {
  119.    char name[30], pg[PGSIZE];
  120.    short lnum, rc;
  121.  
  122.    while( LOGGED_IN ) {
  123.       SerPrompt("\n\rUser to Page: ",BRGREEN,unhand);
  124.       COLOR(CREGCOL);
  125.       if( SerGetCmd(name,12,unhand) >= 0 ) 
  126.          break;
  127.    }
  128.    if( LOGGED_IN && ((lnum=UseLocateClosest(name,bport)) == -1) ) {
  129.       sprintf(pg,"\n\r{%s} is not currently logged in!\n\r",name);
  130.       SerMultiColWrite(pg,'{','}',BRYELLOW,BRWHITE,unhand);
  131.       if( CMDWAIT )
  132.          SerGetStr(pg,PGSIZE-5,unhand);       // read waiting but bogus command
  133.    }
  134.    else {
  135.       while( LOGGED_IN ) {
  136.          SerPrompt("\n\rEnter Message: ",BRGREEN,unhand);
  137.          COLOR(CREGCOL);
  138.          if( SerGetStr(pg,PGSIZE-1,unhand) >= 0 )
  139.             break;
  140.       }
  141.       if( LOGGED_IN && pg[0] ) {
  142.          rc = UseAddPage(pg,lnum,PAGE_REGULAR,unhand,bport);
  143.          if( rc == PERR_OK ) {
  144.             sprintf(pg,"\n\rPage sent to {%s} on line {%d\n\r",(bport+lnum)->p_user->u_handle,lnum);
  145.          }
  146.          else {
  147.             switch( rc ) {
  148.                case PERR_FULL:
  149.                   sprintf(pg,"\n\r{%s} can not receive pages right now, try again shortly\n\r",(bport+lnum)->p_user->u_handle);
  150.                   break;
  151.                case PERR_FORGET:
  152.                   sprintf(pg,"\n\r{%s} has chosen to forget you\n\r",(bport+lnum)->p_user->u_handle);
  153.                   break;
  154.                default:
  155.                   strcpy(pg,"\n\rYour page could not be sent\n\r");
  156.                   break;
  157.             }
  158.          }
  159.          SerMultiColWrite(pg,'{','}',BRWHITE,BRMAGENTA,unhand);
  160.       }
  161.    }
  162.    return(1);
  163. }
  164.  
  165.  
  166.  
  167. //
  168. //  GloUsersOn()
  169. //
  170. //  Displays the users currently logged on
  171. //
  172. //
  173. DSDLL GloUsersOn(PORT_REC *bport, PORT_REC *unhand)
  174. {
  175.    short i, on=0;
  176.    short newuser = 0;
  177.    char dstr[20], citystate[60];
  178.    char *str;
  179.    char flag;
  180.  
  181.    if( (str=malloc(512)) == NULL )
  182.       return(0);
  183.    for(i=0;i<(unhand->gis->gisMaxusers);i++) {
  184.       if( ((bport+i)->inviso != 2) && ((bport+i)->v_usron == 2) && ( (bport+i)->inviso == 0 || P_USER->u_access == GODLEVEL ) ) {
  185.          if( (bport+i)->p_user->u_access < bport->gis->gisVerLevel ) 
  186.             newuser = 1;
  187.          else
  188.             newuser = 0;
  189.          if( !on ) {
  190.             COLOR(BRWHITE);
  191.             SerWrite("\n\rUsers Online:\n\r",unhand);
  192.             COLOR(BRGREEN);
  193.             SerWrite("\n\rLine  User           Location         Calling From            Age S  Log on",unhand);
  194.             COLOR(BRBLUE);
  195.             SerWrite("\n\r----  -------------  ---------------  ----------------------  --- -  -------\n\r",unhand);
  196.             COLOR(BRWHITE);
  197.          }
  198.          on++;
  199.          TimeString(dstr,(bport+i)->t_login,1);
  200.          strcpy(citystate,(bport+i)->p_user->u_city);
  201.          strcat(citystate,", ");
  202.          if( (bport+i)->p_user->u_country[0] )
  203.             strcat(citystate,(bport+i)->p_user->u_country);
  204.          else
  205.             strcat(citystate,(bport+i)->p_user->u_state);
  206.  
  207.          if( (bport+i)->inviso )
  208.             flag = 'i';
  209.          else if( (bport+i)->sysopflag )
  210.             flag = '!';
  211.          else if( Forgotten(i,unhand) )
  212.             flag = 'f';
  213.          else if( newuser && unhand->p_user->u_access == GODLEVEL )
  214.             flag = 'n';
  215.          else 
  216.             flag = ' ';
  217.  
  218.          if( newuser && unhand->p_user->u_access != GODLEVEL )
  219.             sprintf(str," %2d   -Newuser-\n\r",i);
  220.          else
  221.             sprintf(str," %2d   %-12.12s %c %-15.15s  %-22.22s  %3d %c  %s\n\r",i,(bport+i)->p_user->u_handle,flag,(bport+i)->locstr,citystate,
  222.                    (bport+i)->p_user->u_age,(bport+i)->p_user->u_sex ? 'M' : 'F',dstr);
  223.  
  224.          SerWrite(str,unhand);
  225.       } /* if user logged on */
  226.    } /* for */
  227.    if( on == 0 )         // only hapens when all users on are invisable
  228.       SerColorWrite("\n\rSorry, there are no users logged in right now\n\r",BRYELLOW,unhand);
  229.    free(str);
  230.    COLOR(CREGCOL);
  231.    return(1);
  232. }
  233.  
  234.