home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / rocat / part06 < prev    next >
Encoding:
Internet Message Format  |  1994-08-01  |  96.1 KB

  1. From: shaw@stortek.stortek.com (Greg Shaw)
  2. Newsgroups: comp.sources.misc
  3. Subject: v44i006:  rocat - Roman Catacombs BBS System v.0.75, Part06/09
  4. Date: 1 Aug 1994 12:09:04 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <31ja7g$b17@sparky.sterling.com>
  9. X-Md4-Signature: 9e72c66bc918cf56d90f029d6093e772
  10.  
  11. Submitted-by: shaw@stortek.stortek.com (Greg Shaw)
  12. Posting-number: Volume 44, Issue 6
  13. Archive-name: rocat/part06
  14. Environment: Linux, GNU C++/libg++
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  rocat-0.75/config/bbsinfo rocat-0.75/examples/bbs.crontab
  21. #   rocat-0.75/scripts/login.scr rocat-0.75/src/bbs.C
  22. #   rocat-0.75/src/bbshdr.h rocat-0.75/src/bbsinfo.h
  23. #   rocat-0.75/src/bbsipc.C rocat-0.75/src/errlog.C
  24. #   rocat-0.75/src/errlogd.C rocat-0.75/src/filelock.C
  25. #   rocat-0.75/src/filesupdate.C rocat-0.75/src/menu.C
  26. #   rocat-0.75/src/menu.h rocat-0.75/src/moncon.C
  27. #   rocat-0.75/src/user.h rocat-0.75/text/newuser.msg
  28. # Wrapped by kent@sparky on Mon Jul 11 22:22:52 1994
  29. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  30. echo If this archive is complete, you will see the following message:
  31. echo '          "shar: End of archive 6 (of 9)."'
  32. if test -f 'rocat-0.75/config/bbsinfo' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'rocat-0.75/config/bbsinfo'\"
  34. else
  35.   echo shar: Extracting \"'rocat-0.75/config/bbsinfo'\" \(3899 characters\)
  36.   sed "s/^X//" >'rocat-0.75/config/bbsinfo' <<'END_OF_FILE'
  37. X# this file contains the bbs pathing and machine information
  38. X# setup as you desire
  39. X# it should be in the format: NAME <tab> value
  40. X# blanks and lines starting with # are ignored
  41. X
  42. X# host where error logger is running
  43. X
  44. XLOGHOST    manwe
  45. X
  46. X# host where sysop's watch program is running
  47. X
  48. XWATCHHOST    manwe
  49. X
  50. X# upload to download ratio    (7.0 is 7 downloads for each upload)
  51. X# negative numbers refers to how the ratio is done - if it's 
  52. X# negative, then the ratio is enforced *BEFORE* the user downloads
  53. X# the ratio number of files (in the case of -7.0, he has to upload
  54. X# before he can download the 7 files possible.
  55. X# normal (aka positive) numbers refers to a normal upload ratio.
  56. X# meaning the ratio won't be enforced until after the even number
  57. X# of files has been downloaded (e.g. on the 8th file he wouldn't 
  58. X# be able to download.  
  59. X# set below to 1000 or some such number for no ratio.
  60. X
  61. XRATIO    7.0
  62. X
  63. X# default access level for a new user on the bbs
  64. X
  65. XDEFACL    100
  66. X
  67. X# default terminal type for new user on BBS
  68. X
  69. XDEFTERM    ansi
  70. X
  71. X# time that a user's time limit is good for.
  72. X# this is the amount of time that a user may use his 60 minutes for.
  73. X# ex: if you set it to 24 hours, he gets 60 minutes every 24 hours.
  74. X
  75. XWAITTIME    12    
  76. X
  77. X# credit chat time with sysop?
  78. X# 0 for false, 1 for true
  79. X
  80. XCREDITCHAT    1
  81. X
  82. X# credit upload time?
  83. X
  84. XCREDITUPLOADS    1
  85. X
  86. X# the pager to use on your system (use 'more' or 'less' or whatever 
  87. X# you like.  Note that the default user path must have this command 
  88. X# available for it to be accessible.  (e.g. if you have 'less' in 
  89. X# /usr/local/bin, /usr/local/bin *MUST* be part of the default login path
  90. X# Note:  Fully qualifying the path won't work.  Only 15 chars are allocated
  91. X# to the 'pager' variable.  
  92. X
  93. XSYSTEMPAGER    more
  94. X
  95. X# login name of the sysop
  96. X
  97. XSYSOP    shaw
  98. X
  99. X# the following flags determine whether to show the user the system.X
  100. X# (where X < 4) messages are shown to the user at each logon or only once
  101. X# if 1, message will be shown at initial logon only.  0 for every time
  102. X
  103. XSYSTEM1MSGONCE    0
  104. XSYSTEM2MSGONCE    0
  105. XSYSTEM3MSGONCE    0
  106. X
  107. X# sysop's chat hours.  If the user hits 'chat' outside of these hours, he
  108. X# will be told you are not available and to leave a message.
  109. X# time is in military.  1900 is 7pm, 2200 is 10pm
  110. X
  111. XCHATON    0000
  112. XCHATOFF    2400
  113. X
  114. X# the below are the different things you can put on the command prompt 
  115. X# line when at the end of a menu.
  116. X# turn on SHOWTIMELEFT to show the amount of time the user has left
  117. X# turn on SHOWVALIDKEYS to show the valid hot keys to the user
  118. X# USERPROMPT is the text that will prompt the user to hit a key.
  119. X# ex: with all turned on, 
  120. X#  (15 Minutes left) Command? (a,b,d,i,k,t)  <--- user prompt here 
  121. X
  122. XSHOWTIMELEFT    1
  123. XSHOWVALIDKEYS    1
  124. XUSERPROMPT    Command?
  125. X
  126. X# the following determines the default card type for a new user
  127. XDEFCARD    blue
  128. X
  129. X# the following determine the amount of time and downloads that a user
  130. X# may have for different access levels.  Define as you wish.
  131. X# the format is this: 
  132. X# card color, access level, timelimit, additional flags, amount of downloads per day
  133. X# flags is a hex value that will be added to the user's flags upon logon
  134. X# (e.g. for flag 12 on for additional access, it would be 400)
  135. X# a -1 value in a limit field means 'don't enforce'
  136. XREDCARD        100    20    0    0
  137. XBLUECARD    200    40    0    500    
  138. XGREENCARD    200    40    1    500    
  139. XWHITECARD    400    60    1    -1    
  140. X# I don't use the below.  Use them as you want.
  141. XGREYCARD    500     0    0    -1    
  142. XPINKCARD    600    0    0    0
  143. XYELLOWCARD    700    0    0    0
  144. X# this is the sysop's card
  145. XBLACKCARD    10000    255    0    -1
  146. X
  147. X# location of the mail spool file 
  148. XMAILSPOOL    /usr/spool/mail
  149. X
  150. X# minimum wait time between new mail checks (in seconds)
  151. XMAILCHECK       30
  152. X
  153. X# 'talk' program for chatting with the SysOp
  154. XTALKPROG        talk
  155. X
  156. X# show the user his 'fortune' upon logon?
  157. XSHOWFORTUNE    1
  158. X
  159. X# Number of minutes of inactivity before user logged out
  160. X# 0 for no inactivity
  161. XINACTIVITY    5
  162. X
  163. X# Max number of K the user may download with one batch
  164. XMAXK    2500
  165. X
  166. X# don't delete this line!
  167. END_OF_FILE
  168.   if test 3899 -ne `wc -c <'rocat-0.75/config/bbsinfo'`; then
  169.     echo shar: \"'rocat-0.75/config/bbsinfo'\" unpacked with wrong size!
  170.   fi
  171.   # end of 'rocat-0.75/config/bbsinfo'
  172. fi
  173. if test -f 'rocat-0.75/examples/bbs.crontab' -a "${1}" != "-c" ; then 
  174.   echo shar: Will not clobber existing file \"'rocat-0.75/examples/bbs.crontab'\"
  175. else
  176.   echo shar: Extracting \"'rocat-0.75/examples/bbs.crontab'\" \(365 characters\)
  177.   sed "s/^X//" >'rocat-0.75/examples/bbs.crontab' <<'END_OF_FILE'
  178. X# bbs crontab -- automatic bbs maintenance
  179. X#
  180. X# update file sections for new files
  181. X0 3 * * *       setenv BBSDIR /bbs; /bbs/bin/fileutil -u 
  182. X#
  183. X# update new files listing
  184. X1 3 * * *       setenv BBSDIR /bbs; /bbs/bin/fileutil -n /bbs/text/system2.msg
  185. X#
  186. X# update most popular files listing
  187. X2 3 * * *       setenv BBSDIR /bbs; /bbs/bin/fileutil -m /bbs/text/system3.msg
  188. END_OF_FILE
  189.   if test 365 -ne `wc -c <'rocat-0.75/examples/bbs.crontab'`; then
  190.     echo shar: \"'rocat-0.75/examples/bbs.crontab'\" unpacked with wrong size!
  191.   fi
  192.   # end of 'rocat-0.75/examples/bbs.crontab'
  193. fi
  194. if test -f 'rocat-0.75/scripts/login.scr' -a "${1}" != "-c" ; then 
  195.   echo shar: Will not clobber existing file \"'rocat-0.75/scripts/login.scr'\"
  196. else
  197.   echo shar: Extracting \"'rocat-0.75/scripts/login.scr'\" \(4123 characters\)
  198.   sed "s/^X//" >'rocat-0.75/scripts/login.scr' <<'END_OF_FILE'
  199. X#!/bin/sh
  200. X# this is the login script to be used for new user login
  201. X
  202. X# setup so that interrupt logs user out
  203. X
  204. Xtrap exit 2
  205. Xtrap exit 3
  206. X
  207. Xstty erase 
  208. XBBSDIR=/bbs
  209. XSYSOP="shaw"
  210. X
  211. Xexport BBSDIR SYSOP
  212. X
  213. Xif [ "$BBSDIR" = "" ]
  214. Xthen    echo "BBSDIR environment variable not set."
  215. X    exit
  216. Xfi
  217. X
  218. Xif [ "$SYSOP" = "" ]
  219. Xthen    echo "SYSOP environment variable not set."
  220. X    exit
  221. Xfi
  222. X
  223. Xecho "Welcome to the Roman Catacombs!"
  224. X
  225. X# give them a chance to leave mail to the sysop if they're having problems
  226. X
  227. Xecho "Before we begin, do you already have an account and are calling"
  228. Xecho -n "in due to problems with your account? "
  229. Xread yesno
  230. Xcase $yesno
  231. Xin
  232. X    y|Y|Yes|yes|YES)
  233. X         echo -n "What is your name? "
  234. X         read username
  235. X         echo "Since the SysOp cannot leave you mail that you can read (after all, you can't"
  236. X         echo "log on), please enter a phone number where you may be reached."
  237. X         echo -n "Your phone number? "
  238. X         read phonenum
  239. X         echo "Thank you. "
  240. X         echo "You may enter your message now.  Type a <ctrl-d> on a line by itself"
  241. X         echo "to save the message."
  242. X         /usr/bin/mailx -s "$username $phonenum"  $SYSOP
  243. X         echo "Thank you for calling!  Goodbye!"
  244. X         exit ;;    # send mail and exit
  245. Xesac
  246. X
  247. X# give them the welcome message 
  248. X
  249. Xmore  $BBSDIR/text/bbswelcome
  250. X
  251. Xecho -n "Would you like to become a participant in the Roman Catacombs? "
  252. Xread yesno
  253. Xcase $yesno
  254. Xin
  255. X    y|Y|Yes|yes|YES)
  256. X        /bin/true ;;    # don't do anything
  257. X    *)
  258. X        echo "I'm sorry you chose not to become a participant."
  259. X        echo
  260. X        echo Thank you for calling!  Goodbye! 
  261. X        sleep 2
  262. X        exit ;;
  263. Xesac
  264. X
  265. Xecho "It would be a good idea to turn your caps lock off for the BBS."
  266. Xecho "When you type in your name, if you name should be more than two"
  267. Xecho "words, enter them as two words.  Example: John Von Cantle would"
  268. Xecho "be John VonCantle."
  269. X
  270. Xfound="0"
  271. Xwhile [ "$found" -ne "1" ]
  272. Xdo
  273. X    echo -n "What is your first name? "
  274. X    read firstname
  275. X    if [ "`grep -i "$firstname" $BBSDIR/text/badwords`"  != "" ]
  276. X    then
  277. X        echo -n "You have entered "
  278. X        echo $firstname
  279. X        echo "Which contains a restricted word." 
  280. X        echo "Due to this, you will have to log back in with a different name."
  281. X        echo "Goodbye!  Call back soon!"
  282. X        sleep 2
  283. X        exit
  284. X    fi
  285. X    found="`echo $firstname | wc -w`"
  286. Xdone
  287. X
  288. Xfound="0"
  289. Xwhile [ "$found" -ne "1" ]
  290. Xdo
  291. X    echo -n "What is your last name? "
  292. X    read lastname
  293. X    if [ "`grep -i "$lastname" $BBSDIR/text/badwords`"  != "" ]
  294. X    then
  295. X        echo -n "You have entered "
  296. X        echo $lastname
  297. X        echo "Which contains a restricted word." 
  298. X        echo "Due to this, you will have to log back in with a different name."
  299. X        echo "Goodbye!  Call back soon!"
  300. X        sleep 2
  301. X        exit
  302. X    fi
  303. X    found="`echo $lastname | wc -w`"
  304. Xdone
  305. X
  306. X# now build a user login with parts of the user's name
  307. X
  308. Xnumfchars=1
  309. Xfound="0"
  310. Xwhile [ "$found" != "" ]
  311. Xdo
  312. X    firstinit=`echo $firstname | tr "[A-Z]" "[a-z]" | cut -c1-$numfchars`
  313. X    restname=`echo $lastname | tr "[A-Z]" "[a-z]"`
  314. X    userid=`echo $firstinit$restname`
  315. X    tmp=`echo $userid | cut -c1-8`
  316. X    userid=$tmp
  317. X    found=`grep "^$userid:" /etc/passwd` 
  318. X    tmp=`echo dummy | awk "{ print ++x }" x=$numfchars -`
  319. X    numfchars=$tmp
  320. Xdone
  321. X
  322. Xfullname="$firstname $lastname"
  323. X
  324. Xecho
  325. Xecho "Your login id for the Roman Catacombs will be:"
  326. Xecho 
  327. Xecho "$userid"
  328. Xecho
  329. Xecho "Please write your login id down."
  330. Xecho "Note: it must be typed exactly as shown, in lower case."
  331. Xecho "The next time you log on, instead of typing 'new',"
  332. Xecho "type in your login id."
  333. Xecho
  334. Xecho "Press return when you have written your login down."
  335. Xread dummy
  336. X
  337. X/bbs/scripts/addbbsuser $userid "$fullname" $BBSDIR/bbs
  338. X
  339. Xecho 
  340. Xecho "We will now setup a password for your new account."
  341. Xecho "Please type in your password now."
  342. Xfound="0"
  343. X# passwords will be '!' or a encoded password
  344. X# this assumes that encoded passwords are longer than 1 char
  345. Xwhile [ "$found" -le "2" ]
  346. Xdo 
  347. X    passwd $userid
  348. X    found=`fgrep $userid /etc/passwd | cut -f2 -d":" | wc -c`
  349. Xdone
  350. X
  351. X# now enter the bbs itself
  352. X
  353. Xecho 
  354. Xecho "Now that we have set up your user account, you must"
  355. Xecho "log in with that account for further access to the"
  356. Xecho "Roman Catacombs.  After I hang up, you may call "
  357. Xecho "back immediately to access your new account."
  358. X
  359. Xecho 
  360. Xecho "Goodbye!"
  361. X
  362. X# sleep to allow output to drain
  363. Xsleep 2
  364. X
  365. Xexit
  366. END_OF_FILE
  367.   echo shar: 1 control character may be missing from \"'rocat-0.75/scripts/login.scr'\"
  368.   if test 4123 -ne `wc -c <'rocat-0.75/scripts/login.scr'`; then
  369.     echo shar: \"'rocat-0.75/scripts/login.scr'\" unpacked with wrong size!
  370.   fi
  371.   chmod +x 'rocat-0.75/scripts/login.scr'
  372.   # end of 'rocat-0.75/scripts/login.scr'
  373. fi
  374. if test -f 'rocat-0.75/src/bbs.C' -a "${1}" != "-c" ; then 
  375.   echo shar: Will not clobber existing file \"'rocat-0.75/src/bbs.C'\"
  376. else
  377.   echo shar: Extracting \"'rocat-0.75/src/bbs.C'\" \(10843 characters\)
  378.   sed "s/^X//" >'rocat-0.75/src/bbs.C' <<'END_OF_FILE'
  379. X// Filename:    bbs.C
  380. X// Contents:    the main bbs program (main)
  381. X// Author:    Greg Shaw
  382. X// Created:    7/28/93
  383. X
  384. X/* 
  385. X This file is free software; you can redistribute it and/or modify it
  386. Xunder the terms of the GNU General Public License as published by the
  387. XFree Software Foundation; either version 2, or (at your option) any
  388. Xlater version.
  389. X
  390. XIn addition to the permissions in the GNU General Public License, the
  391. XFree Software Foundation gives you unlimited permission to link the
  392. Xcompiled version of this file with other programs, and to distribute
  393. Xthose programs without any restriction coming from the use of this
  394. Xfile.  (The General Public License restrictions do apply in other
  395. Xrespects; for example, they cover modification of the file, and
  396. Xdistribution when not linked into another program.)
  397. X
  398. XThis file is distributed in the hope that it will be useful, but
  399. XWITHOUT ANY WARRANTY; without even the implied warranty of
  400. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  401. XGeneral Public License for more details.
  402. X
  403. XYou should have received a copy of the GNU General Public License
  404. Xalong with this program; see the file COPYING.  If not, write to
  405. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  406. X
  407. X#ifndef _BBS_C_
  408. X#define _BBS_C_
  409. X
  410. X#include "bbshdr.h"
  411. X
  412. X// the user object is defined globally so that the menu object can access
  413. X// it via extern 
  414. Xmoncon    mon_obj;
  415. XUser    user;
  416. X
  417. X// Function:    getout
  418. X// Purpose:    get out of the bbs system.  Quick and dirty
  419. X// Author:    Greg Shaw
  420. X// Created:    8/16/93
  421. X
  422. Xvoid getout(int sig)
  423. X{
  424. X    char    tmpstr[255];    // temporary string
  425. X    static    int inalready=0;    // if already in, don't do again
  426. X    
  427. X    if (sig == SIGINT)    // don't exit on interrupt
  428. X        return;
  429. X    if (!inalready)
  430. X    {
  431. X        sprintf(tmpstr,"Got signal %d",sig);
  432. X        user.ap_log(tmpstr);
  433. X        inalready++;
  434. X        user.save(NULL);
  435. X        sprintf(tmpstr,"(hangup) Logoff for %s %s",user.fname,user.lname);
  436. X        user.ap_log(tmpstr);
  437. X        if (mon_obj.watching())
  438. X        {
  439. X            sprintf(tmpstr,"Logoff for %s %s.\n",user.fname,user.lname);
  440. X            mon_obj.send(tmpstr);
  441. X        }
  442. X        exit(0);    // exit to OS
  443. X        inalready = 0;
  444. X    }
  445. X}
  446. X
  447. Xmain()        // no command line inputs at this time
  448. X{
  449. X    char    tmpstr[255];    // temporary string
  450. X    char    *bbsdir;    // bbs 'home' directory 
  451. X    char    curmenu[MENU_NAME_LEN];    // current menu 
  452. X    char    prevmenu[MENU_NAME_LEN];    // previous menu (should a menu not be found) 
  453. X    char    menustack[MENU_STACK_SIZE][MENU_NAME_LEN]; 
  454. X    int    stacktop;    // current stack top 
  455. X    int    bootuser;    // kick user out?
  456. X    int    x;        // counter 
  457. X    int    done;        // done inside bbs? 
  458. X    int    newuser;    // is it a the first logon for this user? 
  459. X    int    credit;        // credited minutes for upload
  460. X    float    uldlratio;    // download/upload ratio
  461. X    files    fileobj;    // files upload/download object
  462. X    Menu    menu;
  463. X    Menuitem *result;    // result of menu run
  464. X    time_t    now;        // current time
  465. X    struct tm *tnow;        // current time (structure)
  466. X    User    tmpuser;    // temporary user object for sysop editing
  467. X
  468. X
  469. X    // get the user (or get user's information)
  470. X    stacktop = 0;    // stack empty
  471. X    bootuser = 0;
  472. X    if (newuser = user.get(NULL), newuser == -1)
  473. X    {
  474. X        menu.ap_log("Unable to get user.");
  475. X        return(0);
  476. X    }
  477. X    // turn on signal handlers so that hangup and such caught
  478. X    for (x=1; x<15; x++)
  479. X        signal(x,&getout);
  480. X    if (mon_obj.watching())
  481. X    {
  482. X        sprintf(tmpstr,"Logon for %s %s.\n",user.fname,user.lname);
  483. X        mon_obj.send(tmpstr);
  484. X    }
  485. X    // display welcome text file
  486. X    if (bbsdir = getenv("BBSDIR"), bbsdir == NULL)
  487. X    {
  488. X        printf("BBSDIR environment variable not set.\r\n");
  489. X        return(0);
  490. X    }
  491. X    strcpy(tmpstr,bbsdir);        // get bbsdir
  492. X    strcat(tmpstr,"/text/welcome");    // get 'welcome file path'
  493. X    menu.display_file(tmpstr,0);
  494. X    user.display_info(1);    // display user info with 'Welcome back' msg.
  495. X    if (!newuser)
  496. X    {
  497. X        strcpy(tmpstr,bbsdir);        // get bbsdir
  498. X        strcat(tmpstr,"/text/newuser.msg");// get newuser file path
  499. X        menu.display_file(tmpstr,1); // display newuser file 
  500. X    }        
  501. X    for (x=1; x<4; x++)    // display all system messages if applicable
  502. X    {
  503. X        if (!(user.sys_msg_once(x) && ((1<<x | SYSMSGFLAGS) & user.u_flags())))
  504. X        {    // not sys_msg_once so show him system message
  505. X            sprintf(tmpstr,"%s/text/system%d.msg",bbsdir,x);
  506. X            menu.display_file(tmpstr,1);
  507. X        }
  508. X    }
  509. X    // check for mail
  510. X    if (user.mailavail())
  511. X    {
  512. X        user.cr();
  513. X        user.sstrcr("You have mail.");
  514. X        user.cr();
  515. X        user.waitcr();
  516. X        // add something here for reading mail at logon
  517. X    }
  518. X    strcpy(prevmenu,"main");
  519. X    strcpy(curmenu,"main");
  520. X    if (menu.open("main") != 0)
  521. X    {
  522. X        menu.ap_log("Unable to open main menu.\r\n");
  523. X        return(0);
  524. X    }
  525. X    if (user.showfortune())
  526. X    {
  527. X        user.sysint("fortune");
  528. X        menu.waitcr();
  529. X    }
  530. X    done = 0;
  531. X    while (!done)
  532. X    {
  533. X        if (user.mailavail())// new mail?
  534. X        {
  535. X            user.clear();
  536. X            user.sstrcr("You have mail.");
  537. X            user.cr();
  538. X            user.waitcr();
  539. X            // add something here to read mail
  540. X        }
  541. X        if (user.u_uploads() == 0)
  542. X            uldlratio = (float)user.u_downloads()/(float)-1;
  543. X        else    
  544. X            uldlratio = (float)user.u_downloads()/(float)user.u_uploads();
  545. X        while (result = menu.run(curmenu), result == NULL); // run menu till something selected
  546. X        switch(result->com_type)
  547. X        {
  548. X        default:
  549. X        case -1:    // boot the user due to timeout or out of time
  550. X            done++;
  551. X            bootuser++;
  552. X            break;
  553. X        case 0:    // do nothing
  554. X            break;
  555. X        case 1:    // logout of bbs
  556. X            user.cr();
  557. X            user.sstr("Are you sure you want to log off? ");
  558. X            if (user.yesno())
  559. X                done++;
  560. X            break;
  561. X        case 2:    // branch to (another) menu
  562. X            strcpy(prevmenu,curmenu);
  563. X            strcpy(curmenu,result->misc);    // get new menu name
  564. X            if (menu.open(curmenu) != 0)
  565. X            {
  566. X                sprintf(tmpstr,"Unable to open menu %s.",result->misc);
  567. X                menu.ap_log(tmpstr);
  568. X                strcpy(curmenu,prevmenu);    // get new menu name
  569. X                if (menu.open(curmenu) != 0)
  570. X                {
  571. X                    sprintf(tmpstr,"PANIC: Unable to open menu %s.",prevmenu);
  572. X                    menu.er_log(tmpstr);
  573. X                }
  574. X            }
  575. X            else
  576. X            {
  577. X                strcpy(menustack[stacktop++],prevmenu);// get new menu name
  578. X            }
  579. X            break;
  580. X        case 3:    // exit to previous menu
  581. X            if (stacktop > 0)
  582. X            {
  583. X                strcpy(prevmenu,curmenu);
  584. X                strcpy(curmenu,menustack[--stacktop]);
  585. X                if (menu.open(curmenu) != 0)
  586. X                {
  587. X                    sprintf(tmpstr,"Unable to open menu %s.",result->misc);
  588. X                    menu.ap_log(tmpstr);
  589. X                    strcpy(curmenu,prevmenu);    // get last menu
  590. X                    if (menu.open(curmenu) != 0)
  591. X                    {
  592. X                        sprintf(tmpstr,"PANIC: Unable to open menu %s.",prevmenu);
  593. X                        menu.er_log(tmpstr);
  594. X                    }
  595. X                }
  596. X            }
  597. X            break;
  598. X        case 4:    // search userlog for user information
  599. X            user.list(1,0);
  600. X            break;
  601. X        case 5:    // list users in userlog
  602. X            user.list(0,0);
  603. X            break;
  604. X        case 6:    // display user information and access level
  605. X            user.display_info(0);    // display user info w/o 'Welcome back' msg.
  606. X            break;
  607. X        case 7: // modify user setup
  608. X            user.getinfo(0);
  609. X            break;
  610. X        case 8: // chat with sysop (via talk)
  611. X            user.clear();
  612. X            time(&now);
  613. X            tnow = localtime(&now);
  614. X            x = tnow->tm_hour * 100;
  615. X            x += tnow->tm_min;
  616. X            if (user.chat_avail(x))
  617. X            {
  618. X                user.sstrcr("Attempting to chat...");
  619. X                user.cr();
  620. X                user.sstrcr("Press ctrl-C to exit chat.");
  621. X                user.waitcr();
  622. X                sprintf(tmpstr,"%s %s",user.talkprog(), user.sysop());
  623. X                user.sysint(tmpstr);
  624. X            }
  625. X            else
  626. X            {
  627. X                user.sstrcr("I'm sorry, but the sysop is not available for chat.");
  628. X                user.sstrcr("Please try leaving feedback.");
  629. X                user.waitcr();
  630. X            }
  631. X            break;
  632. X        case 10:    // display file, paged
  633. X            sprintf(tmpstr,"%s/text/%s",bbsdir,result->misc);
  634. X            menu.display_file(tmpstr,1);
  635. X            break;
  636. X        case 11:    // display file, not paged
  637. X            sprintf(tmpstr,"%s/text/%s",bbsdir,result->misc);
  638. X            menu.display_file(tmpstr,0);
  639. X            break;
  640. X        case 21:    // call shell to launch external
  641. X            menu.clear();
  642. X            sprintf(tmpstr,"Executing %s\n",result->misc);
  643. X            mon_obj.send(tmpstr);
  644. X            strcpy(tmpstr,result->misc);
  645. X            user.sysint(tmpstr);
  646. X            break;
  647. X        case 25:    // list new files with option to download
  648. X            fileobj.open(result->misc,user.usercard());
  649. X            x = fileobj.list(1,user.usercard(),&user.kused,user.last_logon(),uldlratio);
  650. X            if (x > 0)
  651. X                user.inc_downloads(x);            
  652. X            break;
  653. X        case 26:    // list new files without option to download
  654. X            fileobj.open(result->misc,user.usercard());
  655. X            fileobj.list(0,user.usercard(),&user.kused,user.last_logon(),uldlratio);
  656. X            break;
  657. X        case 27:    // list all files with option to download 
  658. X            fileobj.open(result->misc,user.usercard());
  659. X            x = fileobj.list(1,user.usercard(),&user.kused,0L,uldlratio);
  660. X            if (x > 0)
  661. X                user.inc_downloads(x);            
  662. X            break;
  663. X        case 28:    // list all files without option to download
  664. X            fileobj.open(result->misc,user.usercard());
  665. X            fileobj.list(0,user.usercard(),&user.kused,0L,uldlratio);
  666. X            break;
  667. X        case 29:    // search for string in files area with option
  668. X            fileobj.open(result->misc,user.usercard());
  669. X            x = fileobj.search(1);
  670. X            if (x > 0)
  671. X                user.inc_downloads(x);            
  672. X            break;
  673. X        case 30:    // search for string in files area w/o option
  674. X            fileobj.open(result->misc,user.usercard());
  675. X            fileobj.search(0);
  676. X            break;
  677. X        case 31:    // view detailed information on file
  678. X            fileobj.open(result->misc,user.usercard());
  679. X            fileobj.info(NULL,NULL,NULL);
  680. X            user.waitcr();
  681. X            break;
  682. X        case 32:    // download files
  683. X            fileobj.open(result->misc,user.usercard());
  684. X            x = fileobj.one_download(&user.kused, uldlratio,NULL,1);
  685. X            if (x > 0)
  686. X                user.inc_downloads(x);            
  687. X            break;
  688. X        case 33:    // upload files
  689. X            fileobj.open(result->misc,user.usercard());
  690. X            x = fileobj.upload(user.logname(),user.editorname(), &credit);
  691. X            if (x > 0)
  692. X                user.inc_uploads(x);            
  693. X            if (credit > 0 && user.credituploads())
  694. X                user.inc_credit(x);
  695. X            break;
  696. X        case 34:    // delete a file (that you uploaded)
  697. X            break;
  698. X        case 35:    // download a particular file (with ratio checking
  699. X            x = fileobj.one_download(&user.kused,uldlratio,result->misc,1);
  700. X            if (x > 0)
  701. X                user.inc_downloads(x);            
  702. X            break;
  703. X        case 36:    // download a particular file (without ratio checking
  704. X            fileobj.one_download(&user.kused,uldlratio,result->misc,0);
  705. X            break;
  706. X        // sysop specific commands follow
  707. X        case 40:    // search for users for edit/delete
  708. X            tmpuser.list(1,1);
  709. X            break;
  710. X        case 41:    // delete inactive users from the BBS
  711. X            tmpuser.inactive_delete();
  712. X            break;
  713. X        case 42:    // list inactive users
  714. X            tmpuser.inactive_list();
  715. X            break;
  716. X        case 43:    // list users for edit/delete
  717. X            tmpuser.list(0,1);
  718. X            break;
  719. X        }
  720. X    }
  721. X    // display logoff message
  722. X    menu.clear();
  723. X    strcpy(tmpstr,bbsdir);        // get bbsdir
  724. X    strcat(tmpstr,"/text/logoff");    // get logoff menu 
  725. X    if (!bootuser)
  726. X        menu.display_file(tmpstr,0);
  727. X    menu.cr();
  728. X    menu.cr();
  729. X    menu.cr();
  730. X    menu.cr();
  731. X    sprintf(tmpstr,"rocat BBS System for Unix(tm) version %s",VERSION);
  732. X    menu.sstrcr(tmpstr);
  733. X    menu.sstrcr("copyright (C) 1994 by Gregory Shaw and fmSoft, Inc.  All Rights Reserved.");
  734. X    menu.sstrcr("rocat BBS support available at The Roman Catacombs (303) 429-8914");
  735. X    user.save(NULL);
  736. X    sprintf(tmpstr,"Logoff for %s %s",user.fname,user.lname);
  737. X    user.ap_log(tmpstr);
  738. X    if (mon_obj.watching())
  739. X    {
  740. X        sprintf(tmpstr,"Logoff for %s %s.\n",user.fname,user.lname);
  741. X        mon_obj.send(tmpstr);
  742. X    }
  743. X    sleep(1);
  744. X    return(0);
  745. X};
  746. X
  747. X#endif // _BBS_C_
  748. END_OF_FILE
  749.   if test 10843 -ne `wc -c <'rocat-0.75/src/bbs.C'`; then
  750.     echo shar: \"'rocat-0.75/src/bbs.C'\" unpacked with wrong size!
  751.   fi
  752.   chmod +x 'rocat-0.75/src/bbs.C'
  753.   # end of 'rocat-0.75/src/bbs.C'
  754. fi
  755. if test -f 'rocat-0.75/src/bbshdr.h' -a "${1}" != "-c" ; then 
  756.   echo shar: Will not clobber existing file \"'rocat-0.75/src/bbshdr.h'\"
  757. else
  758.   echo shar: Extracting \"'rocat-0.75/src/bbshdr.h'\" \(3769 characters\)
  759.   sed "s/^X//" >'rocat-0.75/src/bbshdr.h' <<'END_OF_FILE'
  760. X// Filename:    bbshdr.h
  761. X// Purpose:        a general repository for standard and system includes
  762. X// Author:        Greg Shaw
  763. X// Created:        6/1/93
  764. X
  765. X/*
  766. XThis file is free software; you can redistribute it and/or modify it
  767. Xunder the terms of the GNU General Public License as published by the
  768. XFree Software Foundation; either version 2, or (at your option) any
  769. Xlater version.
  770. X
  771. XIn addition to the permissions in the GNU General Public License, the
  772. XFree Software Foundation gives you unlimited permission to link the
  773. Xcompiled version of this file with other programs, and to distribute
  774. Xthose programs without any restriction coming from the use of this
  775. Xfile.  (The General Public License restrictions do apply in other
  776. Xrespects; for example, they cover modification of the file, and
  777. Xdistribution when not linked into another program.)
  778. X
  779. XThis file is distributed in the hope that it will be useful, but
  780. XWITHOUT ANY WARRANTY; without even the implied warranty of
  781. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  782. XGeneral Public License for more details.
  783. X
  784. XYou should have received a copy of the GNU General Public License
  785. Xalong with this program; see the file COPYING.  If not, write to
  786. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  787. X
  788. X#ifndef _BBSHDR_H_
  789. X#define _BBSHDR_H_
  790. X
  791. X// bbs definitions
  792. X
  793. X
  794. X#define MAX_FILES        20    // maximum open files available
  795. X#define MAX_LOCK_TRIES        3    // try 3 times for file lock
  796. X#define MAX_FILENAMELENGTH    30    // max filename size
  797. X                // most filenames are < 30 chars
  798. X#define MAX_DL_COMMANDS        15    // max number of dl protocols 
  799. X                    // found in $BBSDIR/config/protocols
  800. X#define ERR_LOG_PATH    "/bbs/admin/bbserr"    // error logger file path
  801. X
  802. X// posix doesn't define the u_type shortcuts.  internetworking does.  So ...
  803. X
  804. X#ifndef u_short
  805. X#define u_short unsigned short
  806. X#define u_long  unsigned long
  807. X#define u_char  unsigned char
  808. X#define u_float unsigned float
  809. X#endif
  810. X
  811. X// system includes
  812. X
  813. X#include <stdio.h>        // standard output
  814. X#include <ctype.h>        // standard isxxxx functions
  815. X#include <stdarg.h>        // arguments from command line
  816. X#include <fcntl.h>        // file control
  817. X#include <assert.h>        // assert system call (for sanity checking)
  818. X#include <termio.h>        // non blocking read system calls
  819. X#include <string.h>        // string functions
  820. X#include <limits.h>        // system data limits 
  821. X#include <sys/types.h>        // system types
  822. X#include <sys/time.h>        // time and date
  823. X#include <rpc/types.h>        // system rpc types
  824. X#include <sys/stat.h>        // the stat() (status) system call 
  825. X#include <errno.h>            // standard errors (+ perror)
  826. X#include <signal.h>        // signal handling routines
  827. X#include <sys/socket.h>        // internet socket ipc interface
  828. X#include <stdlib.h>        // standard libraries
  829. X#include <sys/wait.h>        // wait
  830. X#include <sys/utsname.h>    // system name
  831. X#include <netinet/in.h>     // more socket definitions
  832. X#include <netdb.h>        // ??
  833. X#include <unistd.h>        // standard unix (not covered elsewhere)
  834. X#include <pwd.h>        // password file reading routines 
  835. X#include <dirent.h>        // directory reading routines
  836. X#include <math.h>        // math (float) routines
  837. X
  838. X// bbs specific includes
  839. X#include "version.h"        // bbs version
  840. X#include "bbsipc.h"        // bbs ipc object 
  841. X#include "bbsinfo.h"        // generic bbs information
  842. X#include "ports.h"        // port connection definitions
  843. X#include "errlog.h"        // error logger (object and daemon)
  844. X#include "filelock.h"        // automatic file locking
  845. X#ifndef _SERVER_
  846. X#include "sysexec.h"        // sub-process execution
  847. X#include "bbsint.h"        // bbs input/output interface
  848. X#include "user.h"        // user object definitions
  849. X#include "menu.h"        // menu system 
  850. X#include "bbs.h"        // bbs top level definitions
  851. X#include "dllist.h"        // doubly linked list section
  852. X#include "files.h"        // files section
  853. X#endif
  854. X#include "moncon.h"        // monitor connection object
  855. X
  856. X#endif // _BBSHDR_H_
  857. END_OF_FILE
  858.   if test 3769 -ne `wc -c <'rocat-0.75/src/bbshdr.h'`; then
  859.     echo shar: \"'rocat-0.75/src/bbshdr.h'\" unpacked with wrong size!
  860.   fi
  861.   chmod +x 'rocat-0.75/src/bbshdr.h'
  862.   # end of 'rocat-0.75/src/bbshdr.h'
  863. fi
  864. if test -f 'rocat-0.75/src/bbsinfo.h' -a "${1}" != "-c" ; then 
  865.   echo shar: Will not clobber existing file \"'rocat-0.75/src/bbsinfo.h'\"
  866. else
  867.   echo shar: Extracting \"'rocat-0.75/src/bbsinfo.h'\" \(3624 characters\)
  868.   sed "s/^X//" >'rocat-0.75/src/bbsinfo.h' <<'END_OF_FILE'
  869. X// Filename:    bbsinfo.h
  870. X// Contents:    the bbs information object
  871. X// Author:        Greg Shaw
  872. X// Created:        7/11/93
  873. X
  874. X/*
  875. X
  876. XThis file is free software; you can redistribute it and/or modify it
  877. Xunder the terms of the GNU General Public License as published by the
  878. XFree Software Foundation; either version 2, or (at your option) any
  879. Xlater version.
  880. X
  881. XIn addition to the permissions in the GNU General Public License, the
  882. XFree Software Foundation gives you unlimited permission to link the
  883. Xcompiled version of this file with other programs, and to distribute
  884. Xthose programs without any restriction coming from the use of this
  885. Xfile.  (The General Public License restrictions do apply in other
  886. Xrespects; for example, they cover modification of the file, and
  887. Xdistribution when not linked into another program.)
  888. X
  889. XThis file is distributed in the hope that it will be useful, but
  890. XWITHOUT ANY WARRANTY; without even the implied warranty of
  891. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  892. XGeneral Public License for more details.
  893. X
  894. XYou should have received a copy of the GNU General Public License
  895. Xalong with this program; see the file COPYING.  If not, write to
  896. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  897. X
  898. X#ifndef _BBSINFO_H_
  899. X#define _BBSINFO_H_
  900. X
  901. X// Structure:    card_color
  902. X// Contents:    the information that defines a card 'level'
  903. X// Author:        Greg Shaw
  904. X// Created:        7/27/93
  905. X
  906. Xtypedef struct
  907. X{
  908. X    char    colr[10];    // card color
  909. X    int        acl;        // minimum acl for that level
  910. X    int        tl;            // minimume tl for level
  911. X    int        flags;        // additional flags for level (or'd into user flags)
  912. X    int        kbytes;        // how many kbytes per period user may download
  913. X} CardRec;
  914. X
  915. X// Object:        bbsinfo
  916. X// Purpose:        return some information that is setup-specific (and could
  917. X//                change, so hard-coding isn't an option)
  918. X// Attributes:    none
  919. X// Methods:        
  920. X//                loghost - return the name of the loghost
  921. X//                watchost - return the name of the sysop watcher daemon
  922. X//                 ratio - return the required upload/download ratio
  923. X//                def_acl - return the default BBS access level
  924. X//                def_termtype - return the default terminal type
  925. X// Author:        Greg Shaw
  926. X// Created:        7/11/93
  927. X
  928. Xclass bbsinfo
  929. X{
  930. X    int    findline(char *line, char *word);    // find line with keyword
  931. Xpublic:
  932. X    CardRec    *cardinfo(int    type);    // return card info for card type passed in
  933. X    int creditchat(void);    // is chat time credited?
  934. X    int credituploads(void);    // is upload time credited?
  935. X    int    chat_avail(int tim);    // is sysop available for chat?
  936. X    char *loghost(void);    // error logging daemon 
  937. X    int    def_card(void);        // default card color
  938. X    char *def_termtype(void);    // default terminal type
  939. X    float    ratio(void);    // upload to download ratio
  940. X    char *sysop(void);        // return sysop's name
  941. X    int    sys_msg_once(int num);        // display (num) system msg once?
  942. X    char *sys_pager(void);        // default system pager
  943. X    int waittime(void);        // time between logons allowed for users
  944. X    char *watchhost(void);    // sysop watcher daemon
  945. X    char *userprompt(void);        //  the prompt for at the end of a menu
  946. X    char *mailspool(void);        // system mail spool file
  947. X    int showtime(void);        // show user timeleft
  948. X    int showcoms(void);        // show user valid command keys
  949. X    int showfortune(void);        // show user fortune upon logon?
  950. X    int inactivity_timeout(void);    // time before user booted 
  951. X    int maxk(void);            // max # of K user can download at one time
  952. X    int mailchecktime(void);    // minimum # of seconds between new mail checks
  953. X    char *talkprog(void);        // return the system 'talk' program
  954. X    uid_t bbs_uid(void);        // return bbs uid
  955. X    gid_t bbs_gid(void);        // return bbs uid
  956. X    char *username(void);        // return name of current user
  957. X};
  958. X
  959. X#endif // _BBSINFO_H_
  960. END_OF_FILE
  961.   if test 3624 -ne `wc -c <'rocat-0.75/src/bbsinfo.h'`; then
  962.     echo shar: \"'rocat-0.75/src/bbsinfo.h'\" unpacked with wrong size!
  963.   fi
  964.   chmod +x 'rocat-0.75/src/bbsinfo.h'
  965.   # end of 'rocat-0.75/src/bbsinfo.h'
  966. fi
  967. if test -f 'rocat-0.75/src/bbsipc.C' -a "${1}" != "-c" ; then 
  968.   echo shar: Will not clobber existing file \"'rocat-0.75/src/bbsipc.C'\"
  969. else
  970.   echo shar: Extracting \"'rocat-0.75/src/bbsipc.C'\" \(9008 characters\)
  971.   sed "s/^X//" >'rocat-0.75/src/bbsipc.C' <<'END_OF_FILE'
  972. X// Filename:    bbsipc.C
  973. X// Contents:    the bbs IPC object
  974. X// Author:        Greg Shaw
  975. X// Created:        6/13/93
  976. X
  977. X/*
  978. XThis file is free software; you can redistribute it and/or modify it
  979. Xunder the terms of the GNU General Public License as published by the
  980. XFree Software Foundation; either version 2, or (at your option) any
  981. Xlater version.
  982. X
  983. XIn addition to the permissions in the GNU General Public License, the
  984. XFree Software Foundation gives you unlimited permission to link the
  985. Xcompiled version of this file with other programs, and to distribute
  986. Xthose programs without any restriction coming from the use of this
  987. Xfile.  (The General Public License restrictions do apply in other
  988. Xrespects; for example, they cover modification of the file, and
  989. Xdistribution when not linked into another program.)
  990. X
  991. XThis file is distributed in the hope that it will be useful, but
  992. XWITHOUT ANY WARRANTY; without even the implied warranty of
  993. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  994. XGeneral Public License for more details.
  995. X
  996. XYou should have received a copy of the GNU General Public License
  997. Xalong with this program; see the file COPYING.  If not, write to
  998. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  999. X
  1000. X#ifndef _BBSIPC_C_
  1001. X#define _BBSIPC_C_
  1002. X
  1003. X#undef DEBUG
  1004. X
  1005. X#include "bbshdr.h"        // include *EVERYTHING*
  1006. X
  1007. X// Function:    bbsipc constructor
  1008. X// Purpose:    initialize the bbs ipc object.  
  1009. X// Inputs:    none
  1010. X// Outputs:    none - constructor may not return values
  1011. X// Author:    Greg Shaw
  1012. X// Created:    6/13/93
  1013. X
  1014. Xbbsipc::bbsipc()
  1015. X{
  1016. X    server = 0;        // server mode
  1017. X    hostname[0] = 0;    // host name
  1018. X    sock_open = 0;        // open socket
  1019. X    sock_fd = 0;        // socket file descriptor 
  1020. X    serv_sock_fd = 0;    // server socket file descriptor 
  1021. X    sockt = 0;        // socket number
  1022. X    connected = 0;    // not connected
  1023. X}
  1024. X
  1025. X// Function:    bbsipc destructor
  1026. X// Purpose:    clean up the bbsipc object (close socket)
  1027. X// Inputs:    none
  1028. X// Outputs:    none
  1029. X// Author:    Greg Shaw
  1030. X// Created:    6/16/93
  1031. X
  1032. Xbbsipc::~bbsipc()
  1033. X{
  1034. X    close_sock(0);
  1035. X};
  1036. X
  1037. X// Function:    close_sock
  1038. X// Purpose:    close the sockets (if open)
  1039. X// Inputs:    none
  1040. X// Outputs:    none
  1041. X// Author:    Greg Shaw
  1042. X// Created:    6/16/93
  1043. X
  1044. Xint bbsipc::close_sock(int client_only)
  1045. X{
  1046. X    if (sock_open)
  1047. X        close(sock_fd);
  1048. X    if (!client_only)
  1049. X    {
  1050. X        if (server)
  1051. X            close(serv_sock_fd);
  1052. X        server = 0;
  1053. X        sock_open = 0;
  1054. X    }
  1055. X    connected = 0;
  1056. X    return(0);
  1057. X};
  1058. X
  1059. X// Function:    open_sock
  1060. X// Purpose:    open a socket for reading, writing or as a server.
  1061. X// Inputs:    name - name of host to contact (NULL for server mode)
  1062. X//        socknum - the socket number to contact
  1063. X// Outputs:    -1 for error
  1064. X// Author:    Greg Shaw
  1065. X// Created:    6/16/93
  1066. X
  1067. Xint bbsipc::open_sock(char *name, int socknum)
  1068. X{
  1069. X    char macname[MAXHOSTNAMELEN+1];        // system information
  1070. X    struct     sockaddr_in    sa;    // socket information
  1071. X    struct     hostent    *hp;        // host entry information
  1072. X
  1073. X    sockt = socknum;    // save socket number
  1074. X    if (name == NULL)    // server mode?
  1075. X    {
  1076. X#ifdef DEBUG
  1077. X    fprintf(stderr,"creating server socket.\r\n");    
  1078. X#endif
  1079. X        // yup, create socket
  1080. X        server = 1;
  1081. X        memset(&sa, 0, sizeof(struct sockaddr_in));    // nuke sa contents
  1082. X        gethostname(macname,MAXHOSTNAMELEN);    // get this host's name
  1083. X        hp = gethostbyname(macname);        // get host info
  1084. X        if (hp == NULL)        // no info for me?
  1085. X        {
  1086. X            fprintf(stderr,"Unable to get host name.\n");
  1087. X            return(-1);    // get out
  1088. X        }
  1089. X        sa.sin_family = hp->h_addrtype;        // set host address
  1090. X        sa.sin_port= htons(socknum);        // set port number
  1091. X        // create new socket
  1092. X        if ((serv_sock_fd = socket(AF_INET, SOCK_STREAM,0)) < 0) 
  1093. X        {
  1094. X            fprintf(stderr,"Unable to open socket.\n");
  1095. X            return(-1);    // can't create socket
  1096. X        }
  1097. X        if (bind(serv_sock_fd,(struct sockaddr *)&sa,(int)sizeof(sa)) < 0)
  1098. X        {
  1099. X            close(serv_sock_fd);
  1100. X            fprintf(stderr,"Unable to bind socket.\n");
  1101. X            return(-1);
  1102. X        }
  1103. X        listen(serv_sock_fd,5);        // 5 pending connections max
  1104. X        sock_open = 1;
  1105. X    }
  1106. X    else
  1107. X    {    // connect to socket
  1108. X#ifdef DEBUG
  1109. X    printf("attempting to connect client socket.\r\n");    
  1110. X#endif
  1111. X        strcpy(hostname, name);
  1112. X        server = 0;
  1113. X        if ((hp = gethostbyname(hostname)) == NULL) // get host addr
  1114. X        {
  1115. X#ifdef DEBUG
  1116. X    printf("Couldn't get hostname to connect to.\r\n");    
  1117. X#endif
  1118. X            errno = ECONNREFUSED;    // connection refused
  1119. X            return(-1);
  1120. X        }
  1121. X        memset(&sa, 0, sizeof(struct sockaddr_in));    // nuke sa contents
  1122. X        memcpy((char *)&sa.sin_addr, (char *)hp->h_addr, hp->h_length);
  1123. X        sa.sin_family = hp->h_addrtype;
  1124. X        sa.sin_port = htons((unsigned short)socknum);
  1125. X        if ((sock_fd = socket(hp->h_addrtype, SOCK_STREAM,0)) < 0)
  1126. X            return(-1);
  1127. X        if (connect(sock_fd,(struct sockaddr *)&sa,sizeof(sa)) < 0)
  1128. X        {
  1129. X#ifdef DEBUG
  1130. X    printf("client connect failed.\r\n");    
  1131. X#endif
  1132. X            close(sock_fd);
  1133. X            return(-1);
  1134. X        }
  1135. X#ifdef DEBUG
  1136. X    printf("client connect successful.\r\n");    
  1137. X#endif
  1138. X        connected = 1;
  1139. X        sock_open = 1;
  1140. X    }
  1141. X    return(0);        // exit normally
  1142. X};
  1143. X
  1144. X// Function:    connect
  1145. X// Purpose:    connect to another process via server socket
  1146. X// Inputs:    none
  1147. X// Outputs:    returns true if socket connection successful
  1148. X// Author:    Greg Shaw
  1149. X// Created:    6/18/93
  1150. X
  1151. Xint bbsipc::do_connect(void)
  1152. X{
  1153. X    struct sockaddr_in isa;    // socket address info
  1154. X    int    i_size;        // socket address size
  1155. X
  1156. X    i_size = sizeof(isa);
  1157. X    getsockname(serv_sock_fd,(struct sockaddr *)&isa,&i_size);
  1158. X
  1159. X    if ((sock_fd = accept(serv_sock_fd,(struct sockaddr *)&isa,&i_size)) < 0)// accept connection
  1160. X    {
  1161. X#ifdef DEBUG
  1162. X    printf("server: accept failed.\r\n");    
  1163. X#endif
  1164. X        return(-1);
  1165. X    }
  1166. X#ifdef DEBUG
  1167. X    printf("server: accept succeeded.\r\n");    
  1168. X#endif
  1169. X    connected = 1;
  1170. X    return(0);
  1171. X};
  1172. X
  1173. X// Function:    send
  1174. X// Purpose:    send a message via the socket
  1175. X// Inputs:    msg - the message to send (null terminated string)
  1176. X// Outputs:    non-zero for error
  1177. X// Author:    Greg Shaw
  1178. X// Created:    6/16/93
  1179. X
  1180. Xint bbsipc::send(char *msg)
  1181. X{
  1182. X    int    cw;
  1183. X    char eom = ETX;
  1184. X
  1185. X    // send a message
  1186. X#ifdef DEBUG
  1187. X    printf("send: Sending %s.\r\n",msg);    
  1188. X#endif
  1189. X    if (!sock_open && !connected)
  1190. X    {
  1191. X#ifdef DEBUG
  1192. X    printf("send: socket not open.\r\n");    
  1193. X#endif
  1194. X        return(-1);
  1195. X    }
  1196. X    if (cw = write(sock_fd,msg,strlen(msg)), cw != strlen(msg))
  1197. X    {
  1198. X#ifdef DEBUG
  1199. X    printf("Unable to write message!\r\n");
  1200. X#endif
  1201. X        return(-1);
  1202. X    }
  1203. X    if (cw = write(sock_fd,&eom,1), cw != 1)
  1204. X    {
  1205. X#ifdef DEBUG
  1206. X        printf("send: unable to send end of message.\r\n");
  1207. X#endif
  1208. X        return(-1);
  1209. X    }
  1210. X#ifdef DEBUG
  1211. X    printf("send: sent %s.\r\n",msg);    
  1212. X#endif
  1213. X
  1214. X    return(0);
  1215. X};
  1216. X
  1217. X// Function:    receive
  1218. X// Purpose:        receive a message from the other end of the socket
  1219. X// Inputs:        none
  1220. X// Outputs:        msg - the message to be received.
  1221. X// Author:        Greg Shaw
  1222. X// Created:        6/22/93
  1223. X
  1224. Xint bbsipc::receive(char *msg)
  1225. X{
  1226. X    char c;                // character read
  1227. X    char eom;            // end of message found?
  1228. X    int count;            // byte counter
  1229. X    int byr;            // number of bytes read
  1230. X
  1231. X#ifdef DEBUG
  1232. X    printf("receive: start\r\n");    
  1233. X#endif
  1234. X    count = 0;
  1235. X    byr = 0;
  1236. X    eom = 0;
  1237. X    while (!eom)
  1238. X    {           // look for trailing null
  1239. X        if ((byr = read(sock_fd,&c,(unsigned)1)), byr > 0) 
  1240. X        {
  1241. X#ifdef DEBUG
  1242. X    printf("%x char read\r\n",c);    
  1243. X#endif
  1244. X            if (c == ETX)
  1245. X                eom++;
  1246. X            else
  1247. X                msg[count++] = c;    // add to msg
  1248. X        }
  1249. X        else if (byr == 0)    // connection is closed for 0 chars read
  1250. X            return(-1);
  1251. X    }
  1252. X    msg[count] = 0;    /* add terminating null */
  1253. X    return(count);
  1254. X};
  1255. X
  1256. X// Function:    msg_avail
  1257. X// Purpose:    poll the socket to determine whether a message is available
  1258. X//            for reading.
  1259. X// Input:    none
  1260. X// Output:    non-zero for a message available
  1261. X// Author:    Greg Shaw
  1262. X// Created:    6/22/93
  1263. X
  1264. Xint bbsipc::msg_avail(char wait)
  1265. X{
  1266. X    // NOTE: below may be a problem.  In a server, it should not be
  1267. X    // possible for a particular connection to tie up the server.  If the
  1268. X    // below is left as is (wait forever for message), it could happen that
  1269. X    // the calling process might die before sending the message, hence a 
  1270. X    // forever wait for a message that will never come.  This would cause a
  1271. X    // lockup of the server (and that would be a Bad Thing.
  1272. X
  1273. X    fd_set pfd;        // file descriptor set 
  1274. X    FD_ZERO(&pfd);
  1275. X    FD_SET(sock_fd,&pfd);
  1276. X        struct timeval waittime;
  1277. X
  1278. X        waittime.tv_sec = 0; 
  1279. X        waittime.tv_usec = 100; // 100msec
  1280. X    if (!wait)    // wait?
  1281. X    {
  1282. X        select(FD_SETSIZE,&pfd,NULL,NULL,&waittime); 
  1283. X        return(FD_ISSET(sock_fd,&pfd)); 
  1284. X                // don't wait, return immed.
  1285. X    }
  1286. X    else
  1287. X    {
  1288. X        select(FD_SETSIZE,&pfd,NULL,NULL,NULL);  // wait forever
  1289. X        return(FD_ISSET(sock_fd,&pfd)); 
  1290. X    }
  1291. X};
  1292. X
  1293. X
  1294. X// Function:    two_connect
  1295. X// Purpose:    connect to a server master socket, get socket from server, 
  1296. X//            disconnect and connect to new socket number.
  1297. X//            (a two level socket connect)
  1298. X// Inputs:    none
  1299. X// Outputs:    ipc object will connect if possible
  1300. X// Notes:    this is a client version only.  The server version will be 
  1301. X//            much much more complex.
  1302. X// Author:    Greg Shaw
  1303. X// Created:    7/23/93
  1304. X
  1305. Xint bbsipc::two_connect(char *name, int socknum)
  1306. X{
  1307. X    char     tmpstr[50];
  1308. X
  1309. X    // attempt to connect to server to get socket number
  1310. X    if (open_sock(name,socknum)    == 0)
  1311. X    { // gotcha!
  1312. X        if (msg_avail(1) < 0)    // wait for message
  1313. X            return(-1);
  1314. X        // now get new socket number
  1315. X        receive(tmpstr);    // get socket #
  1316. X        if (sscanf(tmpstr,"%d",&sockt) != 1)
  1317. X            return(-1);
  1318. X        else
  1319. X            close_sock(0);    // close current socket
  1320. X        if (open_sock(name,sockt) == 0)
  1321. X        {    // got new socket
  1322. X            return(0);
  1323. X        }
  1324. X    }
  1325. X    return(-1);
  1326. X};
  1327. X#endif // _BBSIPC_C_
  1328. END_OF_FILE
  1329.   if test 9008 -ne `wc -c <'rocat-0.75/src/bbsipc.C'`; then
  1330.     echo shar: \"'rocat-0.75/src/bbsipc.C'\" unpacked with wrong size!
  1331.   fi
  1332.   chmod +x 'rocat-0.75/src/bbsipc.C'
  1333.   # end of 'rocat-0.75/src/bbsipc.C'
  1334. fi
  1335. if test -f 'rocat-0.75/src/errlog.C' -a "${1}" != "-c" ; then 
  1336.   echo shar: Will not clobber existing file \"'rocat-0.75/src/errlog.C'\"
  1337. else
  1338.   echo shar: Extracting \"'rocat-0.75/src/errlog.C'\" \(3345 characters\)
  1339.   sed "s/^X//" >'rocat-0.75/src/errlog.C' <<'END_OF_FILE'
  1340. X// Filename:    errlog.C
  1341. X// Contents:    the error logger interface object (for bbs interface)
  1342. X// Author:        Greg Shaw
  1343. X// Created:        7/11/93
  1344. X
  1345. X/*
  1346. XThis file is free software; you can redistribute it and/or modify it
  1347. Xunder the terms of the GNU General Public License as published by the
  1348. XFree Software Foundation; either version 2, or (at your option) any
  1349. Xlater version.
  1350. X
  1351. XIn addition to the permissions in the GNU General Public License, the
  1352. XFree Software Foundation gives you unlimited permission to link the
  1353. Xcompiled version of this file with other programs, and to distribute
  1354. Xthose programs without any restriction coming from the use of this
  1355. Xfile.  (The General Public License restrictions do apply in other
  1356. Xrespects; for example, they cover modification of the file, and
  1357. Xdistribution when not linked into another program.)
  1358. X
  1359. XThis file is distributed in the hope that it will be useful, but
  1360. XWITHOUT ANY WARRANTY; without even the implied warranty of
  1361. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1362. XGeneral Public License for more details.
  1363. X
  1364. XYou should have received a copy of the GNU General Public License
  1365. Xalong with this program; see the file COPYING.  If not, write to
  1366. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1367. X
  1368. X#ifndef _ERRLOG_C_
  1369. X#define _ERRLOG_C_
  1370. X
  1371. X#include "bbshdr.h"            // the world
  1372. X
  1373. X// Method:        ap_log
  1374. X// Purpose:        send an error message to the error logger daemon
  1375. X// Input:        msg - the message to append to the log file
  1376. X// Output:        the message will be sent to the logger daemon, or, error
  1377. X//                error will be returned
  1378. X// Author:        Greg Shaw
  1379. X// Created:        7/11/93
  1380. X
  1381. Xint errlog::ap_log(char *msg)
  1382. X{
  1383. X    char ttystr[50];
  1384. X    char *u;
  1385. X    char sendstr[255];
  1386. X
  1387. X    if (ipcobj.open_sock(loghost(),ERRLOG_PORT) == 0) // open socket successful? 
  1388. X    {
  1389. X        if (isatty(fileno(stdout)))    // check for valid tty
  1390. X        {
  1391. X            strcpy(ttystr,ttyname(fileno(stdout))); // get ttyname
  1392. X            if (u = strchr(ttystr,'y'), u != NULL)
  1393. X            {                                               // chop off /dev/tty
  1394. X                strcpy(sendstr,++u);     // chop after y
  1395. X                strcpy(ttystr,sendstr);  // copy back
  1396. X            }
  1397. X            sprintf(sendstr,"(%s) %s",ttystr,msg);
  1398. X        }
  1399. X        else
  1400. X            strcpy(sendstr,msg);
  1401. X        if (ipcobj.send(sendstr) == 0)        // send message to error logger            
  1402. X        {
  1403. X            ipcobj.close_sock(0);
  1404. X            return(0);
  1405. X        }
  1406. X        else
  1407. X            ipcobj.close_sock(0);        // close socket
  1408. X    }
  1409. X    return(-1);
  1410. X};
  1411. X
  1412. X// Method:        er_log
  1413. X// Purpose:        send an error message to the error logger daemon then exit
  1414. X// Input:        msg - the message to append to the log file
  1415. X// Output:        the message will be sent to the logger daemon and, the program
  1416. X//                will abort
  1417. X// Author:        Greg Shaw
  1418. X// Created:        7/11/93
  1419. X
  1420. Xint errlog::er_log(char *msg)
  1421. X{
  1422. X    char ttystr[50];
  1423. X    char *u;
  1424. X    char sendstr[255];
  1425. X
  1426. X    if (ipcobj.open_sock(loghost(),ERRLOG_PORT) == 0) // open socket successful? 
  1427. X    {
  1428. X        if (isatty(fileno(stdout)))    // check for valid tty
  1429. X        {
  1430. X            strcpy(ttystr,ttyname(fileno(stdout))); // get ttyname
  1431. X            if (u = strchr(ttystr,'y'), u != NULL)
  1432. X            {                                               // chop off /dev/tty
  1433. X                strcpy(sendstr,++u);     // chop after y
  1434. X                strcpy(ttystr,sendstr);  // copy back
  1435. X            }
  1436. X            sprintf(sendstr,"(%s) %s",ttystr,msg);
  1437. X        }
  1438. X        else
  1439. X            strcpy(sendstr,msg);
  1440. X        if (ipcobj.send(sendstr) == 0)        // send message to error logger            
  1441. X            ipcobj.close_sock(0);
  1442. X    }
  1443. X    exit(0);    // abort program
  1444. X};
  1445. X
  1446. X#endif // _ERRLOG_C_
  1447. END_OF_FILE
  1448.   if test 3345 -ne `wc -c <'rocat-0.75/src/errlog.C'`; then
  1449.     echo shar: \"'rocat-0.75/src/errlog.C'\" unpacked with wrong size!
  1450.   fi
  1451.   chmod +x 'rocat-0.75/src/errlog.C'
  1452.   # end of 'rocat-0.75/src/errlog.C'
  1453. fi
  1454. if test -f 'rocat-0.75/src/errlogd.C' -a "${1}" != "-c" ; then 
  1455.   echo shar: Will not clobber existing file \"'rocat-0.75/src/errlogd.C'\"
  1456. else
  1457.   echo shar: Extracting \"'rocat-0.75/src/errlogd.C'\" \(4957 characters\)
  1458.   sed "s/^X//" >'rocat-0.75/src/errlogd.C' <<'END_OF_FILE'
  1459. X// Filename:    errlogd.C
  1460. X// Contents:    the error logger daemon 
  1461. X// Author:        Greg Shaw
  1462. X// Created:        7/11/93
  1463. X
  1464. X/*
  1465. XThis file is free software; you can redistribute it and/or modify it
  1466. Xunder the terms of the GNU General Public License as published by the
  1467. XFree Software Foundation; either version 2, or (at your option) any
  1468. Xlater version.
  1469. X
  1470. XIn addition to the permissions in the GNU General Public License, the
  1471. XFree Software Foundation gives you unlimited permission to link the
  1472. Xcompiled version of this file with other programs, and to distribute
  1473. Xthose programs without any restriction coming from the use of this
  1474. Xfile.  (The General Public License restrictions do apply in other
  1475. Xrespects; for example, they cover modification of the file, and
  1476. Xdistribution when not linked into another program.)
  1477. X
  1478. XThis file is distributed in the hope that it will be useful, but
  1479. XWITHOUT ANY WARRANTY; without even the implied warranty of
  1480. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1481. XGeneral Public License for more details.
  1482. X
  1483. XYou should have received a copy of the GNU General Public License
  1484. Xalong with this program; see the file COPYING.  If not, write to
  1485. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1486. X
  1487. X#ifndef _ERRLOGD_C_
  1488. X#define _ERRLOGD_C_
  1489. X
  1490. X#include "bbshdr.h"
  1491. X
  1492. X#undef DEBUG
  1493. X
  1494. X// declared global so that the 'getout' function can close the socket
  1495. Xbbsipc    ipcobj;
  1496. X
  1497. X// Function:    getout
  1498. X// Purpose:    get out of the program.  Quick and dirty
  1499. X// Author:    Greg Shaw
  1500. X// Created:    8/16/93
  1501. X
  1502. Xvoid getout(int sig)
  1503. X{
  1504. X    char    tmpstr[255];    // temporary string
  1505. X    char    ttystr[20];    // name of tty
  1506. X    char    *u;        // for strchr
  1507. X    static    int inalready = 0;    // if already in, don't do again
  1508. X    time_t    now;            // current time
  1509. X    struct tm *timeinfo;        // time information (broken down)
  1510. X    char    filestr[255];    // string to output to file
  1511. X    FILE    *outfile;        // file to append to
  1512. X    
  1513. X    if (!inalready)
  1514. X    {
  1515. X        ipcobj.close_sock(1);    // close for exit
  1516. X        ipcobj.close_sock(0);    // close for exit
  1517. X        sprintf(tmpstr,"Errlogd: Got signal %d.  Exiting.",sig);
  1518. X        if (outfile = fopen(ERR_LOG_PATH,"a"), outfile != NULL)
  1519. X        {
  1520. X            time(&now);    // get current time
  1521. X            timeinfo = localtime(&now);
  1522. X            strftime(filestr,50,"%D %T: ",timeinfo); // get formatted time
  1523. X            strcat(filestr,tmpstr); // add message
  1524. X            fprintf(outfile,"%s\n",filestr);// append to file
  1525. X            fclose(outfile);    // close file so that buffers cleared
  1526. X        }
  1527. X        inalready++;
  1528. X        strcpy(ttystr,ttyname(fileno(stdout)));    // get ttyname
  1529. X        if (u = strchr(ttystr,'y'), u != NULL)    
  1530. X        {                        // chop off /dev/tty
  1531. X            strcpy(tmpstr,++u);    // chop after y
  1532. X            strcpy(ttystr,tmpstr);    // copy back
  1533. X        }
  1534. X        exit(0);    // exit to OS
  1535. X    }
  1536. X}
  1537. X
  1538. X
  1539. X// Function:    main
  1540. X// Purpose:        the main calling routine for the error logger daemon
  1541. X// Input:        socket connections will connect with program.  
  1542. X// Output:        all data sent to this daemon will be logged to a generic file
  1543. X// Author:        Greg Shaw
  1544. X// Created:        7/11/93
  1545. X
  1546. Xmain()        // no arguments
  1547. X{
  1548. X        struct timeval waittime;
  1549. X    FILE    *outfile;        // file to append to
  1550. X    char     msg[255];
  1551. X    time_t    now;            // current time
  1552. X    int    ret,x;            // return from ipc
  1553. X    struct tm *timeinfo;        // time information (broken down)
  1554. X    char    filestr[255];    // string to output to file
  1555. X
  1556. X#ifdef DEBUG
  1557. Xprintf("Init...\r\n");
  1558. Xfflush(stdout);
  1559. X#endif
  1560. X        for (x=1; x<15; x++)
  1561. X                signal(x,&getout);
  1562. X    if(ipcobj.open_sock (NULL, ERRLOG_PORT) != 0) // create socket
  1563. X    {
  1564. X        printf("Unable to open server socket.\r\n");
  1565. X        return (0);
  1566. X    }
  1567. X    ipcobj.do_connect();    // wait for connection
  1568. X    waittime.tv_usec = 100; // 100msec
  1569. X    waittime.tv_sec = 0; 
  1570. X    while(1)    // loop forever
  1571. X    {
  1572. X#ifdef DEBUG
  1573. Xprintf("Got connect ... waiting for message.\r\n");
  1574. Xfflush(stdout);
  1575. X#endif
  1576. X        if (ret = ipcobj.msg_avail(1), ret < 0)
  1577. X        {
  1578. X#ifdef DEBUG
  1579. Xprintf("Nothing available.  Closing socket\r\n");
  1580. Xfflush(stdout);
  1581. X#endif
  1582. X            ipcobj.close_sock(1);    // close for exit
  1583. X#ifdef DEBUG
  1584. Xprintf("Disconnect.\r\n");
  1585. Xfflush(stdout);
  1586. X#endif
  1587. X            ipcobj.do_connect();    // wait for connection
  1588. X        }
  1589. X        else if (ret > 0)
  1590. X        {
  1591. X#ifdef DEBUG
  1592. Xprintf("Something available.\r\n");
  1593. Xfflush(stdout);
  1594. X#endif
  1595. X            if (ipcobj.receive(msg)< 0)    // connection closed
  1596. X            {
  1597. X                ipcobj.close_sock(1);    // close for exit
  1598. X#ifdef DEBUG
  1599. Xprintf("Disconnect.\r\n");
  1600. Xfflush(stdout);
  1601. X#endif
  1602. X                ipcobj.do_connect();    // wait for connection
  1603. X            }
  1604. X            else    // append to output file
  1605. X            {
  1606. X                if (outfile = fopen(ERR_LOG_PATH,"a"), outfile != NULL)
  1607. X                {
  1608. X                    time(&now);    // get current time
  1609. X                    timeinfo = localtime(&now);
  1610. X                    strftime(filestr,50,"%D %T: ",timeinfo); // get formatted time
  1611. X                    strcat(filestr,msg); // add message
  1612. X                    fprintf(outfile,"%s\n",filestr);// append to file
  1613. X                    fclose(outfile);    // close file so that buffers cleared
  1614. X#ifdef DEBUG
  1615. Xprintf("appended %s.\r\n",filestr);
  1616. Xfflush(stdout);
  1617. X#endif
  1618. X                }
  1619. X
  1620. X                #ifdef DEBUG
  1621. X                else
  1622. X                {
  1623. X                    printf("Unable to open file.\r\n");
  1624. X                    fflush(stdout);
  1625. X                }
  1626. X                #endif
  1627. X            }
  1628. X        }
  1629. X//        select(0,NULL,NULL,NULL,&waittime);// delay
  1630. X    }
  1631. X    ipcobj.close_sock(0);    // close for exit
  1632. X}
  1633. X    
  1634. X
  1635. X
  1636. X#endif 
  1637. X
  1638. END_OF_FILE
  1639.   if test 4957 -ne `wc -c <'rocat-0.75/src/errlogd.C'`; then
  1640.     echo shar: \"'rocat-0.75/src/errlogd.C'\" unpacked with wrong size!
  1641.   fi
  1642.   chmod +x 'rocat-0.75/src/errlogd.C'
  1643.   # end of 'rocat-0.75/src/errlogd.C'
  1644. fi
  1645. if test -f 'rocat-0.75/src/filelock.C' -a "${1}" != "-c" ; then 
  1646.   echo shar: Will not clobber existing file \"'rocat-0.75/src/filelock.C'\"
  1647. else
  1648.   echo shar: Extracting \"'rocat-0.75/src/filelock.C'\" \(5213 characters\)
  1649.   sed "s/^X//" >'rocat-0.75/src/filelock.C' <<'END_OF_FILE'
  1650. X// Filename:    filelock.C
  1651. X// Contents:    the methods for the filelock (file locking) object
  1652. X// Author:        Greg Shaw
  1653. X// Created:        7/23/93
  1654. X
  1655. X/*
  1656. XThis file is free software; you can redistribute it and/or modify it
  1657. Xunder the terms of the GNU General Public License as published by the
  1658. XFree Software Foundation; either version 2, or (at your option) any
  1659. Xlater version.
  1660. X
  1661. XIn addition to the permissions in the GNU General Public License, the
  1662. XFree Software Foundation gives you unlimited permission to link the
  1663. Xcompiled version of this file with other programs, and to distribute
  1664. Xthose programs without any restriction coming from the use of this
  1665. Xfile.  (The General Public License restrictions do apply in other
  1666. Xrespects; for example, they cover modification of the file, and
  1667. Xdistribution when not linked into another program.)
  1668. X
  1669. XThis file is distributed in the hope that it will be useful, but
  1670. XWITHOUT ANY WARRANTY; without even the implied warranty of
  1671. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1672. XGeneral Public License for more details.
  1673. X
  1674. XYou should have received a copy of the GNU General Public License
  1675. Xalong with this program; see the file COPYING.  If not, write to
  1676. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1677. X
  1678. X#ifndef _FLOCK_C_
  1679. X#define _FLOCK_C_
  1680. X
  1681. X#include "bbshdr.h" 
  1682. X
  1683. X// Function:    set_lock
  1684. X// Purpose:        set a lock on a file 
  1685. X// Inputs:        type - type of file lock.  0 for read, 1 for write
  1686. X//                fptr - the pointer to a file 
  1687. X// Output:        returns non-zero if error
  1688. X// Author:        Greg Shaw
  1689. X// Created:        7/24/93
  1690. X
  1691. Xint filelock::set_lock(char type, int fptr)
  1692. X{
  1693. X    struct flock    flockinfo;
  1694. X    int    tries;
  1695. X
  1696. X    flockinfo.l_start = 0L;        // start at byte 0
  1697. X    flockinfo.l_len = 0L;        // through end of file
  1698. X    flockinfo.l_whence = 0;        // set to start of file
  1699. X
  1700. X    if (type)        
  1701. X    {        // write lock
  1702. X        flockinfo.l_type = F_WRLCK;        // write lock
  1703. X        tries = 0;
  1704. X        while (tries < MAX_LOCK_TRIES)
  1705. X        {
  1706. X            if (fcntl(fptr,F_SETLKW,&flockinfo) != 0)
  1707. X            {
  1708. X                sleep(1);
  1709. X                tries++;
  1710. X                if (tries == MAX_LOCK_TRIES)
  1711. X                    return(-1);
  1712. X            }
  1713. X            else
  1714. X                tries = MAX_LOCK_TRIES;    // worked, exit
  1715. X        }
  1716. X    }
  1717. X    else
  1718. X    {        // read lock
  1719. X        flockinfo.l_type = F_RDLCK;        // read lock
  1720. X        tries = 0;
  1721. X        while (tries < MAX_LOCK_TRIES)
  1722. X        {
  1723. X            if (fcntl(fptr,F_SETLKW,&flockinfo) != 0)
  1724. X            {
  1725. X                sleep(1);
  1726. X                tries++;
  1727. X                if (tries == MAX_LOCK_TRIES)
  1728. X                    return(-1);
  1729. X            }
  1730. X            else
  1731. X                tries = MAX_LOCK_TRIES;    // worked, exit
  1732. X        }
  1733. X    }
  1734. X    return(0);    
  1735. X};
  1736. X
  1737. X// Function:    clear_lock
  1738. X// Purpose:        clear a lock on a file 
  1739. X// Inputs:        fptr - the pointer to a file 
  1740. X// Output:        returns non-zero if error
  1741. X// Author:        Greg Shaw
  1742. X// Created:        7/24/93
  1743. X
  1744. Xint filelock::clear_lock(int fptr)
  1745. X{
  1746. X    struct flock    flockinfo;
  1747. X
  1748. X    flockinfo.l_start = 0;        // start at byte 0
  1749. X    flockinfo.l_len = 0;        // through end of file
  1750. X    flockinfo.l_whence = 0;        // set to start of file
  1751. X
  1752. X    flockinfo.l_type = F_UNLCK;        // read lock
  1753. X    if (fcntl(fptr,F_SETLKW,&flockinfo) != 0)
  1754. X    {
  1755. X        return(-1);
  1756. X    }
  1757. X    return(0);    
  1758. X};
  1759. X
  1760. X// Function:    bopen
  1761. X// Purpose:        open a file, set locks as appropriate for mode
  1762. X// Inputs:        path - path to file
  1763. X//                mode - the mode of the file
  1764. X// Output:        returns valid (open) file descriptor or NULL if error
  1765. X// Author:        Greg Shaw
  1766. X// Created:        7/24/93
  1767. X
  1768. XFILE *filelock::bopen(char *path, char *mode)
  1769. X{
  1770. X    FILE    *fileptr;        // pointer to new opened file
  1771. X    char    tmpstr[255];
  1772. X    int x;
  1773. X
  1774. X    if (fileptr = fopen(path,mode), fileptr == NULL)
  1775. X    {
  1776. X        return(NULL);
  1777. X    }
  1778. X    if (strchr(mode,'w') != NULL || strchr(mode,'a') != NULL)
  1779. X    {
  1780. X        if (set_lock(1,fileno(fileptr)) != 0)
  1781. X        {
  1782. X            sprintf(tmpstr,"bopen: able to open file, but unable to set lock %s",path);
  1783. X            ap_log(tmpstr);
  1784. X            fclose(fileptr);
  1785. X            return(NULL);
  1786. X        }
  1787. X    }
  1788. X    else if (strchr(mode,'r') != NULL)    // read only
  1789. X    {
  1790. X        if (set_lock(0,fileno(fileptr)) != 0)
  1791. X        {
  1792. X            sprintf(tmpstr,"bopen: able to open file, but unable to set lock %s",path);
  1793. X            ap_log(tmpstr);
  1794. X            fclose(fileptr);
  1795. X            return(NULL);
  1796. X        }
  1797. X    }
  1798. X    else
  1799. X    {
  1800. X        sprintf(tmpstr,"filelock: Unable to determine read/write of file %s, mode %s",path,mode);
  1801. X        ap_log(tmpstr);
  1802. X        fclose(fileptr);
  1803. X        return(NULL);
  1804. X    }
  1805. X    x = 0;
  1806. X    while (file_list[x] != NULL && x < MAX_FILES)
  1807. X        x++;
  1808. X    if (x < MAX_FILES)
  1809. X        file_list[x] = fileptr;
  1810. X    else
  1811. X    {
  1812. X        ap_log("filelock: Out of file storage.  Please increase MAX_FILES");
  1813. X    }
  1814. X    return(fileptr);
  1815. X};
  1816. X
  1817. X// Function:    bclose
  1818. X// Purpose:    close a file, clear locks
  1819. X// Inputs:    fptr - the pointer to the file
  1820. X// Output:    returns non zero for failure
  1821. X// Author:    Greg Shaw
  1822. X// Created:    7/24/93
  1823. X
  1824. Xint filelock::bclose(FILE *fptr)
  1825. X{
  1826. X    int x;
  1827. X
  1828. X    clear_lock(fileno(fptr));
  1829. X    x=0;
  1830. X    while (file_list[x] != fptr && x < MAX_FILES)
  1831. X        x++;
  1832. X    if (x < MAX_FILES)
  1833. X        file_list[x] = NULL;
  1834. X    else
  1835. X    {
  1836. X        ap_log("filelock: Unable to find file in open file list.");
  1837. X    }
  1838. X    fclose(fptr);
  1839. X    return(0);
  1840. X};
  1841. X
  1842. X// Function:    constructor
  1843. X// Purpose:    initialize the lists
  1844. X// Inputs:    none
  1845. X// Output:    none
  1846. X// Author:    Greg Shaw
  1847. X// Created:    4/23/94
  1848. X
  1849. Xfilelock::filelock()
  1850. X{
  1851. X    int x;
  1852. X
  1853. X    for (x=0; x<MAX_FILES; x++)
  1854. X        file_list[x] = NULL;
  1855. X};
  1856. X
  1857. X// Function:    destructor
  1858. X// Purpose:    close all open files and clear locks
  1859. X// Inputs:    none
  1860. X// Output:    none
  1861. X// Author:    Greg Shaw
  1862. X// Created:    4/23/94
  1863. X
  1864. Xfilelock::~filelock()
  1865. X{
  1866. X    int x;
  1867. X
  1868. X    for (x = 0; x< MAX_FILES; x++)
  1869. X        if (file_list[x] != NULL)
  1870. X            bclose(file_list[x]);            
  1871. X    
  1872. X};
  1873. X
  1874. X#endif // _FLOCK_C_
  1875. X
  1876. END_OF_FILE
  1877.   if test 5213 -ne `wc -c <'rocat-0.75/src/filelock.C'`; then
  1878.     echo shar: \"'rocat-0.75/src/filelock.C'\" unpacked with wrong size!
  1879.   fi
  1880.   chmod +x 'rocat-0.75/src/filelock.C'
  1881.   # end of 'rocat-0.75/src/filelock.C'
  1882. fi
  1883. if test -f 'rocat-0.75/src/filesupdate.C' -a "${1}" != "-c" ; then 
  1884.   echo shar: Will not clobber existing file \"'rocat-0.75/src/filesupdate.C'\"
  1885. else
  1886.   echo shar: Extracting \"'rocat-0.75/src/filesupdate.C'\" \(4087 characters\)
  1887.   sed "s/^X//" >'rocat-0.75/src/filesupdate.C' <<'END_OF_FILE'
  1888. X// Filename:    filesupdate
  1889. X// Contents:    the conversion program to update the files sections to the
  1890. X//        new format.
  1891. X// Created:    6/17/94
  1892. X// Author:    Greg Shaw
  1893. X
  1894. X#ifndef _FILESUPDATE_C_
  1895. X#define  _FILESUPDATE_C_
  1896. X
  1897. X#include <stdio.h>
  1898. X#include <string.h>
  1899. X#include <unistd.h>
  1900. X#include <stdlib.h>
  1901. X
  1902. X// Function:    convert
  1903. X// Purpose:    convert a files section
  1904. X// Input:    path - the name of the bbs section to read
  1905. X// Output:    none.  setup function only.
  1906. X// Author:    Greg Shaw
  1907. X// Created:    6/17/94
  1908. X
  1909. Xint convert(char *sname)
  1910. X{
  1911. X    FILE    *infile,*outfile;
  1912. X    char    name[100];
  1913. X    char    uploader[100];
  1914. X    int    numdls;
  1915. X    char    tmpstr[255];
  1916. X    char    tmpstr2[255];
  1917. X    int    off;
  1918. X    int    line;
  1919. X    char     *bbsdir;// used for bbsdir environment var
  1920. X    char    c;
  1921. X
  1922. X    if (bbsdir = getenv("BBSDIR"), bbsdir == NULL)
  1923. X    {
  1924. X        printf("Unable to get BBSDIR\r\n");
  1925. X        exit(1);
  1926. X    }     
  1927. X        sprintf(tmpstr,"%s/filehdr/%s",bbsdir,sname);    // tack on files header
  1928. X        if (infile = fopen(tmpstr,"r"), infile == NULL)
  1929. X        {
  1930. X            printf("Unable to open files section %s\r\n",sname);
  1931. X            return(0);// empty files section
  1932. X        }
  1933. X        sprintf(tmpstr,"%s/filehdr/%s.new",bbsdir,sname);    // tack on files header
  1934. X        if (outfile = fopen(tmpstr,"w"), infile == NULL)
  1935. X        {
  1936. X            printf("Unable to open new files header.\r\n");
  1937. X            return(0);
  1938. X        }
  1939. X        // ok.  now read everything into dllist object
  1940. X        line = 0;
  1941. X        while (!feof(infile))
  1942. X        {
  1943. X            while (c=fgetc(infile), c != '[' && !feof(infile));
  1944. X            if (feof(infile))
  1945. X                continue;
  1946. X            switch(line)
  1947. X            {
  1948. X            case 0:    // line 1
  1949. X                if (c = fgetc(infile), c == 'A')
  1950. X                {
  1951. X                    if (fscanf(infile,"%s %*ld %*ld %d %s", name, &numdls,uploader) != 3)
  1952. X                    {
  1953. X                        printf("%s: Error on line A\r\n",sname);
  1954. X                        return(0);
  1955. X                    }
  1956. X                    line++;
  1957. X                    fprintf(outfile,"[A %s %d %s ]\n",uploader, numdls, name);
  1958. X                }
  1959. X                break;
  1960. X            case 1:    // line 2
  1961. X                if (c = fgetc(infile), c == 'B')
  1962. X                {
  1963. X                    off = 0;
  1964. X                    while (c = fgetc(infile), c != '\r' && c != '\n' && !feof(infile))
  1965. X                        tmpstr[off++] = c;
  1966. X                    tmpstr[off] = 0;
  1967. X                    fprintf(outfile,"[B %s\n",tmpstr);
  1968. X                    line++;
  1969. X                }
  1970. X                break;
  1971. X            case 2:    // line 3
  1972. X                if (c = fgetc(infile), c == 'C')
  1973. X                {
  1974. X                    off = 0;
  1975. X                    while (c = fgetc(infile), c != '\r' && c != '\n' && !feof(infile))
  1976. X                        tmpstr[off++] = c;
  1977. X                    tmpstr[off] = 0;
  1978. X                    fprintf(outfile,"[C %s\n",tmpstr);
  1979. X                    line++;
  1980. X                }
  1981. X                break;
  1982. X            case 3:    // line 4
  1983. X                if (c = fgetc(infile), c == 'D')
  1984. X                {
  1985. X                    off = 0;
  1986. X                    while (c = fgetc(infile), c != '\r' && c != '\n' && !feof(infile))
  1987. X                        tmpstr[off++] = c;
  1988. X                    tmpstr[off] = 0;
  1989. X                    fprintf(outfile,"[D %s\n",tmpstr);
  1990. X                    line++;
  1991. X                }
  1992. X                break;
  1993. X            case 4:    // line 5
  1994. X                if (c = fgetc(infile), c == 'E')
  1995. X                {
  1996. X                    off = 0;
  1997. X                    while (c = fgetc(infile), c != '\r' && c != '\n' && !feof(infile))
  1998. X                        tmpstr[off++] = c;
  1999. X                    tmpstr[off] = 0;
  2000. X                    fprintf(outfile,"[E %s\n",tmpstr);
  2001. X                    line++;
  2002. X                }
  2003. X                break;
  2004. X            case 5:    // line 6
  2005. X                if (c = fgetc(infile), c == 'F')
  2006. X                {
  2007. X                    off = 0;
  2008. X                    while (c = fgetc(infile), c != '\r' && c != '\n' && !feof(infile))
  2009. X                        tmpstr[off++] = c;
  2010. X                    tmpstr[off] = 0;
  2011. X                    fprintf(outfile,"[F %s\n",tmpstr);
  2012. X                    line = 0;
  2013. X                }
  2014. X                break;
  2015. X            }
  2016. X        }
  2017. X        fclose(infile);
  2018. X        fclose(outfile);
  2019. X        sprintf(tmpstr,"%s/filehdr/%s",getenv("BBSDIR"),sname);
  2020. X        sprintf(tmpstr2,"%s/filehdr/%s.old",getenv("BBSDIR"),sname);
  2021. X        rename(tmpstr,tmpstr2);    // rename file
  2022. X        sprintf(tmpstr,"%s/filehdr/%s.new",getenv("BBSDIR"),sname);
  2023. X        sprintf(tmpstr2,"%s/filehdr/%s",getenv("BBSDIR"),sname);
  2024. X        rename(tmpstr,tmpstr2);    // rename file
  2025. X    return(0);
  2026. X};
  2027. X
  2028. Xmain()
  2029. X{
  2030. X    char     *bbsdir;// used for bbsdir environment var
  2031. X    char    c;
  2032. X    FILE *hdrfile;
  2033. X    char    tmpstr[120];
  2034. X
  2035. X    if (bbsdir = getenv("BBSDIR"), bbsdir == NULL)
  2036. X    {
  2037. X        printf("Unable to get BBSDIR\r\n");
  2038. X        exit(1);
  2039. X    }     
  2040. X    sprintf(tmpstr,"%s/filehdr/bbs_files_hdr",bbsdir);
  2041. X    if (hdrfile = fopen(tmpstr,"r"), hdrfile == NULL)
  2042. X    {
  2043. X        printf("Unable to open main files header.\r\n");
  2044. X        exit(1);
  2045. X    }
  2046. X    while (!feof(hdrfile))
  2047. X    {
  2048. X        while(c = fgetc(hdrfile), c != '[' && !feof(hdrfile));
  2049. X        if (fscanf(hdrfile,"%s",tmpstr) == 1)
  2050. X        {
  2051. X            printf("Converting %s\r\n",tmpstr);
  2052. X            convert(tmpstr);
  2053. X        }
  2054. X    }
  2055. X    fclose(hdrfile);
  2056. X}
  2057. X
  2058. X#endif  // _FILESUPDATE_C_
  2059. END_OF_FILE
  2060.   if test 4087 -ne `wc -c <'rocat-0.75/src/filesupdate.C'`; then
  2061.     echo shar: \"'rocat-0.75/src/filesupdate.C'\" unpacked with wrong size!
  2062.   fi
  2063.   chmod +x 'rocat-0.75/src/filesupdate.C'
  2064.   # end of 'rocat-0.75/src/filesupdate.C'
  2065. fi
  2066. if test -f 'rocat-0.75/src/menu.C' -a "${1}" != "-c" ; then 
  2067.   echo shar: Will not clobber existing file \"'rocat-0.75/src/menu.C'\"
  2068. else
  2069.   echo shar: Extracting \"'rocat-0.75/src/menu.C'\" \(13516 characters\)
  2070.   sed "s/^X//" >'rocat-0.75/src/menu.C' <<'END_OF_FILE'
  2071. X// Filename:    menu.C
  2072. X// Contents:    the methods for the menu object
  2073. X// Author:    Greg Shaw
  2074. X// Created:    7/22/93
  2075. X
  2076. X/*
  2077. XThis file is free software; you can redistribute it and/or modify it
  2078. Xunder the terms of the GNU General Public License as published by the
  2079. XFree Software Foundation; either version 2, or (at your option) any
  2080. Xlater version.
  2081. X
  2082. XIn addition to the permissions in the GNU General Public License, the
  2083. XFree Software Foundation gives you unlimited permission to link the
  2084. Xcompiled version of this file with other programs, and to distribute
  2085. Xthose programs without any restriction coming from the use of this
  2086. Xfile.  (The General Public License restrictions do apply in other
  2087. Xrespects; for example, they cover modification of the file, and
  2088. Xdistribution when not linked into another program.)
  2089. X
  2090. XThis file is distributed in the hope that it will be useful, but
  2091. XWITHOUT ANY WARRANTY; without even the implied warranty of
  2092. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  2093. XGeneral Public License for more details.
  2094. X
  2095. XYou should have received a copy of the GNU General Public License
  2096. Xalong with this program; see the file COPYING.  If not, write to
  2097. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2098. X
  2099. X#ifndef _MENU_C_
  2100. X#define _MENU_C_
  2101. X
  2102. X#include "bbshdr.h"
  2103. X
  2104. X// Function:    can_view
  2105. X// Purpose:    return true if the user has access based on the information
  2106. X//                passed in
  2107. X// Input:    acl - the access level of the user
  2108. X//            flags - the flags of the user
  2109. X//            am - the access level modifier for the user's acccess level
  2110. X//            fm - the flags modifier
  2111. X// Output:    true if user has access
  2112. X// Author:    Greg Shaw
  2113. X// Created:    7/27/93
  2114. X
  2115. Xint Menu::can_view(int acl, int flags, char am, char fm)
  2116. X{
  2117. X    int    uacl;            // user's acl
  2118. X    int uflags;            // user's flags
  2119. X
  2120. X    uacl = user.u_acl();
  2121. X    uflags = user.u_flags();
  2122. X    if (!((uacl >= acl && am == '>' ) || (uacl < acl && am == '<') ||
  2123. X        (acl == uacl && am == '=')))
  2124. X            return(0);        // no access
  2125. X    if (flags != 0)
  2126. X    {
  2127. X        if ((flags & uflags) && fm == '=')
  2128. X            return(1);    
  2129. X        if (!(flags & uflags) && fm == '!')
  2130. X            return(1);
  2131. X        return(0);
  2132. X    }
  2133. X    return(1);        // access
  2134. X};
  2135. X
  2136. X// Function:    get_chat_msg
  2137. X// Purpose:    get a chat message from the chat object (if connected)
  2138. X// Input:    none
  2139. X// Output:    chat message is read into internal space
  2140. X// Author:    Greg Shaw
  2141. X// Created:    7/22/93
  2142. X
  2143. Xint Menu::get_chat_msg(void)
  2144. X{
  2145. X    int x;
  2146. X    if (x = msg_avail(0), x <0)    // message avail?
  2147. X        connected = 0;
  2148. X    else if (x > 0 && receive(chat_msg) == -1)
  2149. X            connected = 0;
  2150. X    return(0);
  2151. X};
  2152. X
  2153. X// Function:    constructor
  2154. X// Purpose:    initialize values to sane states
  2155. X// Input:    none
  2156. X// Output:    (internal object changes)
  2157. X// Author:    Greg Shaw
  2158. X// Created:    7/22/93
  2159. X
  2160. XMenu::Menu()
  2161. X{
  2162. X    prompt = userprompt();
  2163. X    menu_path[0] = 0;    // erase menu path
  2164. X    numitems = 0;    // no items yet
  2165. X    connected = 0;    // not connected
  2166. X    socknum = 0;    // no socket yet
  2167. X    last_try = 0L;    // haven't tried yet
  2168. X    chat_msg[0] = 0;// no chat message yet
  2169. X};
  2170. X
  2171. X// Function:    open
  2172. X// Purpose:    read the commands for the menu from the menu file
  2173. X// Input:    path - the path to the menu file
  2174. X// Output:    the menu is read into the object or a non-zero result is returned
  2175. X// Author:    Greg Shaw
  2176. X// Created:    7/22/93
  2177. X
  2178. Xint Menu::open(char *path)
  2179. X{
  2180. X    FILE    *infile;    // input file
  2181. X    char    tmpstr[255];    // temporary string
  2182. X    char    state;        // state of input
  2183. X    char    num;        // offset into word
  2184. X    char    comnum;        // command number in array
  2185. X    char    c;            // input char
  2186. X
  2187. X//    open_chat();        // attempt to connect to chat server
  2188. X    if (strcpy(tmpstr,getenv("BBSDIR")), tmpstr == NULL)
  2189. X    {
  2190. X        sprintf(tmpstr,"BBSDIR env var not set for %s",username());
  2191. X        ap_log(tmpstr);
  2192. X        return(-1);
  2193. X    }
  2194. X    strcat(tmpstr,"/menus/");    // add slash
  2195. X    strcat(tmpstr,path);    // add path
  2196. X    if (infile = bopen(tmpstr,"r"), infile == NULL)
  2197. X    {
  2198. X        sprintf(tmpstr,"Unable to open menu file %s",path);
  2199. X        ap_log(tmpstr);
  2200. X        return(-1);
  2201. X    }
  2202. X    comnum = 0;        // start at 0
  2203. X    while (!feof(infile))
  2204. X    {
  2205. X        state = 0;
  2206. X        num = 0;
  2207. X        c = 0;
  2208. X        while (c != '\r' && c != '\n' && !feof(infile))
  2209. X        {
  2210. X            c = fgetc(infile);
  2211. X            if (c != '|' && c != '\r' && c != '\n')
  2212. X                tmpstr[num++] = c;    // add char
  2213. X            else
  2214. X            {
  2215. X                tmpstr[num] = 0;        // add null
  2216. X                state++;
  2217. X                switch(state)
  2218. X                {
  2219. X                    case 1:    // command number
  2220. X                        if (sscanf(tmpstr,"%d",&items[comnum].com_type) != 1 )
  2221. X                            continue;    // we've hit end of menu file
  2222. X                        break;
  2223. X                    case 2: // hot key
  2224. X                        if (num != 0)
  2225. X                        {
  2226. X                            items[comnum].key = tmpstr[0];
  2227. X                        }
  2228. X                        else
  2229. X                            items[comnum].key = 0;
  2230. X                        break;
  2231. X                    case 3:    // access level
  2232. X                        if (num != 0)    // empty?
  2233. X                        {
  2234. X                            if (sscanf(tmpstr,"%d",&items[comnum].acl) != 1)
  2235. X                            {
  2236. X                                sprintf(tmpstr,"menu.acl: %s has an error.",path);
  2237. X                                ap_log(tmpstr);
  2238. X                                bclose(infile);
  2239. X                                return(-1);
  2240. X                            }
  2241. X                        }
  2242. X                        else
  2243. X                            items[comnum].acl = 0;
  2244. X                        break;
  2245. X                    case 4:    // access level modifier
  2246. X                        if (num != 0)    // modifier not null?
  2247. X                        {
  2248. X                            if (tmpstr[0] != '>' && tmpstr[0] != '=' &
  2249. X                                tmpstr[0] != '<')
  2250. X                            {
  2251. X                                sprintf(tmpstr,"menu.aclmo: %s has an error.",path);
  2252. X                                ap_log(tmpstr);
  2253. X                                bclose(infile);
  2254. X                                return(-1);
  2255. X                            }
  2256. X                            else 
  2257. X                                items[comnum].acl_mod = tmpstr[0];
  2258. X                        }
  2259. X                        else
  2260. X                            items[comnum].acl_mod = '>';    // default to 
  2261. X                        break;
  2262. X                    case 5:    // flags
  2263. X                        if (num != 0)    // flags not null?
  2264. X                        {
  2265. X                            if (sscanf(tmpstr,"%d",&items[comnum].flags) != 1)
  2266. X                            {
  2267. X                                sprintf(tmpstr,"menu.flags: %s has an error.",path);
  2268. X                                ap_log(tmpstr);
  2269. X                                bclose(infile);
  2270. X                                return(-1);
  2271. X                            }
  2272. X                        }
  2273. X                        else
  2274. X                            items[comnum].flags = 0;    // no flags is default
  2275. X                        break;
  2276. X                    case 6:    // flags mod
  2277. X                        if (num != 0)    // modifier not null?
  2278. X                        {
  2279. X                            if (tmpstr[0] != '=' && tmpstr[0] != '!')
  2280. X                            {
  2281. X                                sprintf(tmpstr,"menu.flagsmod: %s has an error.",path);
  2282. X                                ap_log(tmpstr);
  2283. X                                bclose(infile);
  2284. X                                return(-1);
  2285. X                            }
  2286. X                            else 
  2287. X                                items[comnum].flags_mod = tmpstr[0];
  2288. X                        }
  2289. X                        else
  2290. X                            items[comnum].flags_mod = '=';    // default to =
  2291. X                        break;
  2292. X                    case 7:    // misc text
  2293. X                        strcpy(items[comnum].misc,tmpstr);
  2294. X                        break;
  2295. X                    case 8:    // command text - skip to end of line
  2296. X                        if (items[comnum].com_type != 0)    // don't care about text out commands
  2297. X                            comnum++;
  2298. X                        if (comnum > 49)    // at the end?
  2299. X                        {
  2300. X                            ap_log("menu: menu has too many items (> 50)");
  2301. X                            bclose(infile);
  2302. X                            return(-1);
  2303. X                        }
  2304. X                        while (c != '\r' && c != '\n' && !feof(infile))
  2305. X                            c = fgetc(infile);
  2306. X                        break;
  2307. X                    default:     // error
  2308. X                        sprintf(tmpstr,"Invalid switch %d in menu open.",state);
  2309. X                        ap_log(tmpstr);
  2310. X                }
  2311. X                num = 0;    // start at next word
  2312. X            }
  2313. X        }
  2314. X    }
  2315. X    numitems = comnum;
  2316. X    bclose(infile);
  2317. X    return(0);
  2318. X};
  2319. X
  2320. X// Function:    open_chat
  2321. X// Purpose:    attempt to open a connection to the chat process 
  2322. X// Inputs:    none
  2323. X// Outputs:    connected changes state if connection successful
  2324. X// Author:    Greg Shaw
  2325. X// Created:    7/23/93
  2326. X
  2327. Xint Menu::open_chat(void)
  2328. X{
  2329. X    time_t     now;        // current time
  2330. X    char    hname[30];    // this host's name (where chat runs)
  2331. X
  2332. X    // attempt to connect to chat object
  2333. X    if (!connected)
  2334. X    {
  2335. X        if (time(&now), now - last_try > 10)    // more than 10 secs?
  2336. X        {
  2337. X            if (gethostname(hname,29), hname == NULL)
  2338. X            {
  2339. X                ap_log("menu.open: Unable to get current host name");
  2340. X            }
  2341. X            else
  2342. X            {
  2343. X                if (two_connect(hname,CHAT_MASTER_PORT) == 0)
  2344. X                {    // got new socket
  2345. X                    connected = 1;
  2346. X                }
  2347. X            }
  2348. X        }
  2349. X    }
  2350. X    return(0);
  2351. X};
  2352. X
  2353. X// Function:    run
  2354. X// Purpose:        run the menu
  2355. X// Input:        (from user)
  2356. X// Output:        the command that has been selected by the user is returned
  2357. X// Author:        Greg Shaw
  2358. X// Created:        7/25/93
  2359. X
  2360. XMenuitem *Menu::run(char *path)
  2361. X{
  2362. X    char c,d;                // dumb char
  2363. X    char line[255];        // line
  2364. X    char valkeys[150];    // valid keys in menu
  2365. X    char timeleft[50];    // amount of time left to user
  2366. X    char offset;        // offset into string
  2367. X    char numbracks;        // number of |'s found
  2368. X    char boogie;        // get out of function -- guy has selected
  2369. X    char tmpstr[255];    // stupid string
  2370. X    FILE    *infile;    // menu file
  2371. X    int  x;                // counter
  2372. X    int     charsfound;    // number of chars found after command info
  2373. X    int     acl;            // acl
  2374. X    int     flags;            // flags
  2375. X    int    inactivity;        // how long to wait before inactivity logoff
  2376. X    char am;            // acl mod
  2377. X    char fm;            // flags mod
  2378. X    unsigned long     tl;        // timeleft
  2379. X    time_t now;            // current time
  2380. X    time_t rightnow;        // current time
  2381. X
  2382. X    clear();            // clear screen if possible
  2383. X//    if (connected)        // connect to chat obj
  2384. X//        get_chat_msg();    // get chat message (if available)
  2385. X//    if (strlen(chat_msg) != 0)    // message not null
  2386. X//        sstrcr(chat_msg);        // send message
  2387. X    if (strcpy(tmpstr,getenv("BBSDIR")), tmpstr == NULL)
  2388. X    {
  2389. X        sprintf(tmpstr,"BBSDIR env var not set for %s",username());
  2390. X        ap_log(tmpstr);
  2391. X        return(NULL);
  2392. X    }
  2393. X    strcat(tmpstr,"/menus/");    // add slash
  2394. X    strcat(tmpstr,path);    // add path
  2395. X    if (infile = bopen(tmpstr,"r"), infile == NULL)
  2396. X    {
  2397. X        sprintf(tmpstr,"Unable to open menu file %s",path);
  2398. X        ap_log(tmpstr);
  2399. X    }
  2400. X    boogie = 0;
  2401. X    while (!feof(infile) && !boogie)
  2402. X    {
  2403. X        numbracks = 0;
  2404. X        offset = 0;    // offset into line
  2405. X        while (numbracks < 7 && !feof(infile))    // nuke all of the command info
  2406. X        {
  2407. X            c = fgetc(infile);
  2408. X            if (c != '|' && c != '\r' && c != '\n')
  2409. X            {
  2410. X                line[offset++] = c;
  2411. X            }
  2412. X            else    // got info.  process
  2413. X            {
  2414. X                line[offset] = 0;
  2415. X                if (c == '|')
  2416. X                {
  2417. X                    numbracks++;
  2418. X                    switch(numbracks)
  2419. X                    {
  2420. X                        case 1:    // command number
  2421. X                            continue;
  2422. X                            break;
  2423. X                        case 2: // hot key
  2424. X                        case 7: // misc text
  2425. X                            break;
  2426. X                        case 3:    // access level
  2427. X                            if (offset != 0)    // empty?
  2428. X                            {
  2429. X                                sscanf(line,"%d",&acl);
  2430. X                            }
  2431. X                            else
  2432. X                                acl = 0;
  2433. X                            break;
  2434. X                        case 4:    // access level modifier
  2435. X                            if (offset != 0)    // modifier not null?
  2436. X                            {
  2437. X                                    am = line[0];
  2438. X                            }
  2439. X                            else
  2440. X                                am = '>';    // default to >
  2441. X                            break;
  2442. X                        case 5:    // flags
  2443. X                            if (offset != 0)    // flags not null?
  2444. X                            {
  2445. X                                sscanf(line,"%d",&flags);
  2446. X                            }
  2447. X                            else
  2448. X                                flags = 0;    // no flags is default
  2449. X                            break;
  2450. X                        case 6:    // flags mod
  2451. X                            if (offset != 0)    // modifier not null?
  2452. X                            {
  2453. X                                    fm = line[0];
  2454. X                            }
  2455. X                            else
  2456. X                                fm = '=';    // default to =
  2457. X                            break;
  2458. X                        default:     // error
  2459. X                            ap_log("Invalid switch in menu run.");
  2460. X                    }
  2461. X                }
  2462. X                offset = 0;
  2463. X            }
  2464. X        }  // ok, that's gone.  Now the meat is left.
  2465. X        if (!can_view(acl, flags, am, fm))    // no access, skip.
  2466. X        {
  2467. X            while (c = fgetc(infile), c != '\r' && c != '\n' && !feof(infile));
  2468. X            acl = 32767;    // avoid lockup if stray \r or \n at end of file
  2469. X            continue;
  2470. X        }
  2471. X        charsfound = 0;
  2472. X        offset=0;
  2473. X        while (d = fgetc(infile), d != '\r' && d != '\n' && !feof(infile))
  2474. X        {
  2475. X            if (offset % 50 == 0 && offset > 0)
  2476. X            {
  2477. X                tmpstr[offset] = 0;
  2478. X                sstr(tmpstr);
  2479. X                offset = 0;
  2480. X                tmpstr[offset++] = d;
  2481. X            }
  2482. X            else
  2483. X                tmpstr[offset++] = d;
  2484. X            charsfound++;
  2485. X        }
  2486. X        if (charsfound > 0)
  2487. X        {
  2488. X            tmpstr[offset] = 0;
  2489. X            sstr(tmpstr);
  2490. X            cr();
  2491. X        }
  2492. X        if (c = valid_char(), c != -1)        // check for char and return true
  2493. X        {
  2494. X            bclose(infile);
  2495. X            if (c == 100)        // 100 means he hit return only (for screen refresh)
  2496. X                return(NULL);
  2497. X            else
  2498. X                return(&items[c]);// if hot key for menu item
  2499. X        }
  2500. X    }
  2501. X    bclose(infile);
  2502. X    // ok, he didn't hit anything.  Give him a prompt.
  2503. X    if (showcoms())        // show command keys?
  2504. X    {        // build string with valid keys
  2505. X        offset = 0;
  2506. X        valkeys[offset++] = '[';
  2507. X        for (x=0; x<numitems; x++)
  2508. X            if (items[x].key != 0 && can_view(items[x].acl,
  2509. X                items[x].flags, items[x].acl_mod, items[x].flags_mod))
  2510. X            {
  2511. X                valkeys[offset++] = items[x].key;
  2512. X                valkeys[offset++] = ',';
  2513. X            }
  2514. X        valkeys[offset-1] = ']';    // add right bracket
  2515. X        valkeys[offset++] = ' ';        // add trailing space
  2516. X        valkeys[offset] = 0;        // add null
  2517. X    }
  2518. X    else
  2519. X        valkeys[0] = 0;
  2520. X    time(&now);
  2521. X    // see how much time he has left
  2522. X    tl = (user.u_timelimit()*60 - (now - user.user_logon()))/60; 
  2523. X    // subtract time used prior to this logon 
  2524. X    tl -= user.prevtimeused();    // subtract previous time used
  2525. X    if (user.credituploads())
  2526. X        tl += user.credit();    // add credited minutes
  2527. X    if (tl <= 0)    // should he be gone?
  2528. X    {
  2529. X        items[0].com_type = -1;    // boot the user
  2530. X        return(&items[0]);
  2531. X    }
  2532. X    if (showtime())    // show time left? 
  2533. X    {
  2534. X        if (tl == 1)
  2535. X            strcpy(timeleft,"[ 1 Minute left ] ");
  2536. X        else if (tl < 1)
  2537. X            strcpy(timeleft,"[ <1 Minute left ] ");
  2538. X        else
  2539. X            sprintf(timeleft,"[%d Minutes left] ",tl);
  2540. X    }
  2541. X    else
  2542. X        timeleft[0] = 0;
  2543. X    sstr(timeleft);
  2544. X    if (prompt != NULL)
  2545. X    {
  2546. X        sstr(prompt);
  2547. X    }
  2548. X    sstr(valkeys);
  2549. X    inactivity = inactivity_timeout();
  2550. X    while (c = valid_char(), c == -1)        // check for char and return true
  2551. X    {
  2552. X        time(&rightnow);    // look for inactivity timeout
  2553. X        if ((rightnow - now) /60 > inactivity)
  2554. X        {
  2555. X            sstrcr("Inactivity timeout ... ");
  2556. X            items[0].com_type = -1;    // boot the user
  2557. X            ap_log("Inactivity timeout.");
  2558. X            return(&items[0]);
  2559. X        }
  2560. X    }
  2561. X    cr();
  2562. X    if (c == 100)        // 100 means he hit return only (for screen refresh)
  2563. X        return(NULL);
  2564. X    else
  2565. X        return(&items[c]);                // if hot key for menu item
  2566. X};
  2567. X
  2568. X// Function:    valid_char
  2569. X// Purpose:        look for a character from the user.  If available, check 
  2570. X//                char against list, return array index into list if found.
  2571. X// Input:        none
  2572. X// Output:        the array index of the matching command record
  2573. X// Author:        Greg Shaw
  2574. X
  2575. Xint Menu::valid_char(void)
  2576. X{
  2577. X    char    c;
  2578. X    char    x;
  2579. X
  2580. X    c  = 0;
  2581. X    if (char_avail(0,0) || char_avail(1,1))
  2582. X        c = gch(0);
  2583. X    if (c > 0)    // error or zero for no char
  2584. X    {
  2585. X        for (x=0; x < numitems; x++)
  2586. X        {
  2587. X            if ( c == items[x].key && can_view(items[x].acl,
  2588. X                items[x].flags, items[x].acl_mod, items[x].flags_mod))
  2589. X                return(x);
  2590. X            else if (c == '\r' || c == '\n')
  2591. X                return(100);
  2592. X        }
  2593. X    }
  2594. X    return(-1);
  2595. X};
  2596. X
  2597. X#endif // _MENU_C_
  2598. END_OF_FILE
  2599.   if test 13516 -ne `wc -c <'rocat-0.75/src/menu.C'`; then
  2600.     echo shar: \"'rocat-0.75/src/menu.C'\" unpacked with wrong size!
  2601.   fi
  2602.   chmod +x 'rocat-0.75/src/menu.C'
  2603.   # end of 'rocat-0.75/src/menu.C'
  2604. fi
  2605. if test -f 'rocat-0.75/src/menu.h' -a "${1}" != "-c" ; then 
  2606.   echo shar: Will not clobber existing file \"'rocat-0.75/src/menu.h'\"
  2607. else
  2608.   echo shar: Extracting \"'rocat-0.75/src/menu.h'\" \(3664 characters\)
  2609.   sed "s/^X//" >'rocat-0.75/src/menu.h' <<'END_OF_FILE'
  2610. X// Filename:    menu.h
  2611. X// Contents:    the menu system object
  2612. X// Author:    Greg Shaw
  2613. X// Created:    7/22/93
  2614. X
  2615. X/*
  2616. XThis file is free software; you can redistribute it and/or modify it
  2617. Xunder the terms of the GNU General Public License as published by the
  2618. XFree Software Foundation; either version 2, or (at your option) any
  2619. Xlater version.
  2620. X
  2621. XIn addition to the permissions in the GNU General Public License, the
  2622. XFree Software Foundation gives you unlimited permission to link the
  2623. Xcompiled version of this file with other programs, and to distribute
  2624. Xthose programs without any restriction coming from the use of this
  2625. Xfile.  (The General Public License restrictions do apply in other
  2626. Xrespects; for example, they cover modification of the file, and
  2627. Xdistribution when not linked into another program.)
  2628. X
  2629. XThis file is distributed in the hope that it will be useful, but
  2630. XWITHOUT ANY WARRANTY; without even the implied warranty of
  2631. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  2632. XGeneral Public License for more details.
  2633. X
  2634. XYou should have received a copy of the GNU General Public License
  2635. Xalong with this program; see the file COPYING.  If not, write to
  2636. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2637. X
  2638. X#ifndef _MENU_H_
  2639. X#define _MENU_H_
  2640. X
  2641. X#include "bbshdr.h"    // file that includes everything
  2642. X
  2643. Xextern User user;    // need this for access level, flags, timelimit, etc.
  2644. X
  2645. X// Structure:    Menuitem
  2646. X// Contents:    the pertinent information for each menu item.
  2647. X//        command type (number)
  2648. X//        misc text
  2649. X//        access level
  2650. X//        access level modifier 
  2651. X//        flags 
  2652. X//        flags modifier
  2653. X// Author:    Greg Shaw
  2654. X// Created:    7/22/93
  2655. X
  2656. Xtypedef struct {
  2657. X    int    com_type;    // command type
  2658. X    char    key;    // hot key
  2659. X    char    misc[91];    // miscellaneous text
  2660. X    int    acl;        // access level of command
  2661. X    char    acl_mod;    // access level modifier
  2662. X    int    flags;        // flags (32)
  2663. X    char    flags_mod;    // flags modifier
  2664. X} Menuitem;
  2665. X
  2666. X// Object:    Menu
  2667. X// Purpose:    Encapsulate the menu operations for the BBS.  Everything
  2668. X//        relating to how the bbs (aka user) operates the menu system
  2669. X//        is contained within this object.
  2670. X// Attributes:    path - path to menu
  2671. X//         1..n of struct item (see above for item description)
  2672. X//        numitems - the number of command items in menu
  2673. X//        connected - has connect to chat object been successful?
  2674. X//        socknum - the socket to connect to chat object (in step 2)
  2675. X//        last_try - the last try (time) to connect to chat object
  2676. X//                (10 seconds between attempts minimum)
  2677. X// Methods:    open - open a menu file (read commands from file)
  2678. X//        run - run the (already read) menu.  Return selected command
  2679. X//            number
  2680. X//        dump - dump contents of menu object to screen (for debugging)
  2681. X//        chat_con - attempt to connect to chat object
  2682. X// Author:    Greg Shaw
  2683. X// Created:    7/22/93
  2684. X
  2685. Xclass Menu:public bbsint    // inherited from bbs interface
  2686. X{
  2687. X    char    *prompt;    // command prompt
  2688. X    char    menu_path[255];    // path to menu
  2689. X    char    numitems;    // number of items in menu
  2690. X    char    chat_msg[81];    // last chat message
  2691. X    time_t     user_logon;        // time of user logon (for timeleft prompt)
  2692. X    Menuitem    items[50];    // 50 menu items at this point
  2693. X    char    connected;    // connected to chat object?
  2694. X    int    socknum;    // socket to use when talking to chat object
  2695. X    time_t    last_try;    // last connected attempt - time 
  2696. X    get_chat_msg(void);    // get chat message (if available)
  2697. Xpublic:
  2698. X    Menu();            // constructor
  2699. X    open_chat(void);        // connect to chat object
  2700. X    open(char *path);    // read commands from menu
  2701. X    Menuitem *run(char *path);        // run the menu
  2702. X    dump(void);        // dump contents of menu object
  2703. X    valid_char(void);    // get char (if available) and check against items
  2704. X    can_view(int acl, int flags, char am, char fm);    // can user view this item?
  2705. X};
  2706. X
  2707. X#endif // _MENU_H_
  2708. END_OF_FILE
  2709.   if test 3664 -ne `wc -c <'rocat-0.75/src/menu.h'`; then
  2710.     echo shar: \"'rocat-0.75/src/menu.h'\" unpacked with wrong size!
  2711.   fi
  2712.   chmod +x 'rocat-0.75/src/menu.h'
  2713.   # end of 'rocat-0.75/src/menu.h'
  2714. fi
  2715. if test -f 'rocat-0.75/src/moncon.C' -a "${1}" != "-c" ; then 
  2716.   echo shar: Will not clobber existing file \"'rocat-0.75/src/moncon.C'\"
  2717. else
  2718.   echo shar: Extracting \"'rocat-0.75/src/moncon.C'\" \(5163 characters\)
  2719.   sed "s/^X//" >'rocat-0.75/src/moncon.C' <<'END_OF_FILE'
  2720. X// Filename:    moncon.C
  2721. X// Contents:    the methods for the monitor connection object
  2722. X// Author:    Greg Shaw
  2723. X// Created:    8/26/93
  2724. X
  2725. X/*
  2726. XThis file is free software; you can redistribute it and/or modify it
  2727. Xunder the terms of the GNU General Public License as published by the
  2728. XFree Software Foundation; either version 2, or (at your option) any
  2729. Xlater version.
  2730. X
  2731. XIn addition to the permissions in the GNU General Public License, the
  2732. XFree Software Foundation gives you unlimited permission to link the
  2733. Xcompiled version of this file with other programs, and to distribute
  2734. Xthose programs without any restriction coming from the use of this
  2735. Xfile.  (The General Public License restrictions do apply in other
  2736. Xrespects; for example, they cover modification of the file, and
  2737. Xdistribution when not linked into another program.)
  2738. X
  2739. XThis file is distributed in the hope that it will be useful, but
  2740. XWITHOUT ANY WARRANTY; without even the implied warranty of
  2741. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  2742. XGeneral Public License for more details.
  2743. X
  2744. XYou should have received a copy of the GNU General Public License
  2745. Xalong with this program; see the file COPYING.  If not, write to
  2746. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2747. X
  2748. X#ifndef _MONCON_C_
  2749. X#define _MONCON_C_
  2750. X
  2751. X#include "bbshdr.h"
  2752. X
  2753. X
  2754. X// Method:    constructor
  2755. X// Purpose:    initialize all variables and attempt to connect to sysop process
  2756. X// Input:    none
  2757. X// Output:    none
  2758. X// Author:    Greg Shaw
  2759. X// Created:    8/26/93
  2760. X
  2761. Xmoncon::moncon()
  2762. X{
  2763. X
  2764. X    cstart = cend = 0;    // setup buffer pointers
  2765. X    costart = coend = 0;
  2766. X    watch_on = 0;        // not watching
  2767. X    mon_connected = 0;
  2768. X    last_attempt = 0L;        // last attempt = 0;
  2769. X};
  2770. X
  2771. X// Method:    connected
  2772. X// Purpose:    return true if monitor connected
  2773. X// Input:    none
  2774. X// Output:    internal object status is updated 
  2775. X// Author:    Greg Shaw
  2776. X// Created:    8/26/93
  2777. X
  2778. Xint moncon::connected(void)
  2779. X{
  2780. X    return(mon_connected);
  2781. X};
  2782. X
  2783. X// Method:    connect_mon
  2784. X// Purpose:    try to connect to the sysop monitor program
  2785. X// Input:    none
  2786. X// Output:    internal object status is updated 
  2787. X// Author:    Greg Shaw
  2788. X// Created:    8/26/93
  2789. X
  2790. Xint moncon::connect_mon(void)
  2791. X{
  2792. X    char    watchname[30];
  2793. X    char    msg[30];
  2794. X    time_t    now;
  2795. X
  2796. X    if (!mon_connected)    // only connect if not connected
  2797. X    {
  2798. X        time(&now);        // set for next attempt
  2799. X        if (abs(now - last_attempt) > 10)// space tries to 10 seconds minimum
  2800. X        {
  2801. X            time(&last_attempt);
  2802. X            if (strcpy(watchname,watchhost()), watchname != NULL)
  2803. X                if (open_sock(watchname,MONITOR_PORT) == 0)// try to open socket
  2804. X                {
  2805. X                    mon_connected = 1;    
  2806. X                    last_attempt = 0;
  2807. X                }
  2808. X        }
  2809. X    }
  2810. X    if (mon_connected)
  2811. X    {
  2812. X        if (receive(msg), strcmp(msg,MONITOR_ON) == 0)
  2813. X        {
  2814. X            watch_on = 1;
  2815. X        }
  2816. X    }
  2817. X    return(0);
  2818. X};
  2819. X
  2820. X// Method:    send_monitor
  2821. X// Purpose:    send a string to the monitor process
  2822. X// Input:    none
  2823. X// Output:    none
  2824. X// Author:    Greg Shaw
  2825. X// Created:    8/26/93
  2826. X
  2827. Xint moncon::send_monitor(char *str)
  2828. X{
  2829. X    if (watch_on)
  2830. X        if (send(str) != 0)    // error? 
  2831. X        {    // yes - close socket
  2832. X            watch_on = 0;
  2833. X            mon_connected = 0;
  2834. X        }
  2835. X    return(0);
  2836. X};
  2837. X
  2838. X// Method:    watching
  2839. X// Purpose:    return true if sysop monitor is watching this BBS process
  2840. X// Input:    none
  2841. X// Output:    none
  2842. X// Author:    Greg Shaw
  2843. X// Created:    8/26/93
  2844. X
  2845. Xint moncon::watching(void)
  2846. X{
  2847. X    return(watch_on);
  2848. X};
  2849. X
  2850. X// Method:    get_command
  2851. X// Purpose:    attempt to get a command from the monitor process
  2852. X// Input:    none
  2853. X// Output:    a character, should one be found
  2854. X// Author:    Greg Shaw
  2855. X// Created:    8/27/93
  2856. X
  2857. Xint moncon::get_command(void)
  2858. X{
  2859. X    char    msg[255];    // message from monitor
  2860. X    int    x;
  2861. X
  2862. X    if (watch_on)
  2863. X    {
  2864. X        if (costart != coend)    // empty buffer first
  2865. X        {
  2866. X            x = costart++;
  2867. X            costart %= COMMANDS_MAX;
  2868. X            return(commands[x]);
  2869. X        }
  2870. X        if (msg_avail(0))
  2871. X        {
  2872. X            // look for command string 
  2873. X            if (receive(msg) == -1)
  2874. X            {    // receive failed - socket closed
  2875. X                mon_connected = 0;
  2876. X                watch_on = 0;
  2877. X            } else
  2878. X            {
  2879. X                if (strstr(msg,COMMAND_MSG) != NULL)
  2880. X                {     // command message
  2881. X                    return(msg[4]);
  2882. X                }
  2883. X                else
  2884. X                {
  2885. X                    for (x=0; x<strlen(msg); x++)
  2886. X                    {
  2887. X                        cbuf[cend++] = msg[x];
  2888. X                        cend %= CBUF_MAX;
  2889. X                        if (cstart == cend)// full?
  2890. X                            break;  // disregard
  2891. X                            //rest of message
  2892. X                    }
  2893. X                }
  2894. X            }
  2895. X        }
  2896. X    }
  2897. X    return(0);
  2898. X};
  2899. X
  2900. X
  2901. X
  2902. X// Method:    get_char
  2903. X// Purpose:    attempt to get a character from the monitor process
  2904. X// Input:    none
  2905. X// Output:    a character, should one be found
  2906. X// Author:    Greg Shaw
  2907. X// Created:    8/27/93
  2908. X
  2909. Xchar moncon::get_char(void)
  2910. X{
  2911. X    char    msg[255];    // message from monitor
  2912. X    int    x;
  2913. X
  2914. X    if (watch_on)
  2915. X    {
  2916. X        if (cstart != cend)    // empty buffer first
  2917. X        {
  2918. X            x = cstart++;
  2919. X            cstart %= CBUF_MAX;
  2920. X            return(cbuf[cstart++]);
  2921. X        }
  2922. X        if (msg_avail(1))
  2923. X        {
  2924. X            // look for command string 
  2925. X            if (receive(msg) == -1)
  2926. X            {    // receive failed - socket closed
  2927. X                mon_connected = 0;
  2928. X                watch_on = 0;
  2929. X            } else
  2930. X            {
  2931. X                if (strstr(msg,COMMAND_MSG) != NULL)
  2932. X                {     // command message
  2933. X                    commands[coend++] = msg[4];// 5th byte
  2934. X                    coend %= COMMANDS_MAX;
  2935. X                }
  2936. X                else
  2937. X                {
  2938. X                    for (x=0; x<strlen(msg); x++)
  2939. X                    {
  2940. X                        cbuf[cend++] = msg[x];
  2941. X                        cend %= CBUF_MAX;
  2942. X                        if (cstart == cend)// full?
  2943. X                            break;  // disregard
  2944. X                            //rest of message
  2945. X                    }
  2946. X                    x = cstart++;
  2947. X                    cstart %= CBUF_MAX;
  2948. X                    return(cbuf[x]);
  2949. X                }
  2950. X            }
  2951. X        }
  2952. X    }
  2953. X    return(0);
  2954. X};
  2955. X
  2956. X
  2957. X
  2958. X#endif // _MONCON_C_
  2959. X
  2960. X
  2961. END_OF_FILE
  2962.   if test 5163 -ne `wc -c <'rocat-0.75/src/moncon.C'`; then
  2963.     echo shar: \"'rocat-0.75/src/moncon.C'\" unpacked with wrong size!
  2964.   fi
  2965.   chmod +x 'rocat-0.75/src/moncon.C'
  2966.   # end of 'rocat-0.75/src/moncon.C'
  2967. fi
  2968. if test -f 'rocat-0.75/src/user.h' -a "${1}" != "-c" ; then 
  2969.   echo shar: Will not clobber existing file \"'rocat-0.75/src/user.h'\"
  2970. else
  2971.   echo shar: Extracting \"'rocat-0.75/src/user.h'\" \(6118 characters\)
  2972.   sed "s/^X//" >'rocat-0.75/src/user.h' <<'END_OF_FILE'
  2973. X// Filename:    user.h
  2974. X// Contents:    the user interface object
  2975. X// Author:        Greg Shaw
  2976. X// Created:        5/30/93
  2977. X
  2978. X/*
  2979. XThis file is free software; you can redistribute it and/or modify it
  2980. Xunder the terms of the GNU General Public License as published by the
  2981. XFree Software Foundation; either version 2, or (at your option) any
  2982. Xlater version.
  2983. X
  2984. XIn addition to the permissions in the GNU General Public License, the
  2985. XFree Software Foundation gives you unlimited permission to link the
  2986. Xcompiled version of this file with other programs, and to distribute
  2987. Xthose programs without any restriction coming from the use of this
  2988. Xfile.  (The General Public License restrictions do apply in other
  2989. Xrespects; for example, they cover modification of the file, and
  2990. Xdistribution when not linked into another program.)
  2991. X
  2992. XThis file is distributed in the hope that it will be useful, but
  2993. XWITHOUT ANY WARRANTY; without even the implied warranty of
  2994. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  2995. XGeneral Public License for more details.
  2996. X
  2997. XYou should have received a copy of the GNU General Public License
  2998. Xalong with this program; see the file COPYING.  If not, write to
  2999. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  3000. X
  3001. X#ifndef _USER_H_
  3002. X#define _USER_H_
  3003. X
  3004. X// Object:    user
  3005. X// Purpose:    encapsulate all of the user funtions into one object.
  3006. X// Attributes:
  3007. X//        fname, lname - the user's name
  3008. X//         login_name - the user's logon
  3009. X//         city - city where user from
  3010. X//         state - two character state
  3011. X//         uterm - terminal type
  3012. X//        last_logon - the last time the user logged on (in seconds)
  3013. X//        logins - the number of times the user has logged on
  3014. X//         downloads - number of downloads by the user
  3015. X//         uploads - the number of uploads by user
  3016. X//         priv_msgs - the number of private messages by user (unused)
  3017. X//        pub_msgs - the  number of public messages by user (unused)
  3018. X//         credited - credited time (for chat or uploads)
  3019. X//        flags - user access flags
  3020. X//        tmpflags - temporary flags (if authorized by sysop)
  3021. X//        acl - the access level of user
  3022. X//        tmpacl - the temporary access level of user
  3023. X//        timelimit - the timelimit for this user
  3024. X//        temptl - temporary timelimit (if authorized by sysop)
  3025. X//        timeused - the amount of time used on last call
  3026. X//        msgflags - flags for when user has seen message (true/false)
  3027. X// Methods:
  3028. X//        get - load the user object with user info, or, get user info from user
  3029. X//        list - list the users in the user list
  3030. X//        change_acl - change the user's access level
  3031. X//        change_tl - change user's timelimit
  3032. X//        change_flags - change user's flags
  3033. X//        u_flags - return user's flags
  3034. X//        u_acl - return user's access level
  3035. X//        u_timelimit - return user's timelimit
  3036. X// Author:    Greg Shaw
  3037. X// Created:    7/13/93
  3038. X
  3039. Xclass User: public bbsint // inherited from user output function
  3040. X{
  3041. X    char    login_name[11];    // login name 
  3042. X    char    alias[21];    // user's alias (for chatting)
  3043. X    char    city[21];    // city 
  3044. X    char    state[15];    // state 
  3045. X    char    uterm[21];    // terminal type 
  3046. X    char    has_color;    // has color?
  3047. X    char    editor[15];    // favorite editor 
  3048. X    char    lines;        // lines on screen
  3049. X    char    cols;        // columns on screen
  3050. X    CardRec    *card;        // card information for user
  3051. X    time_t    last_login;    // last login 
  3052. X    time_t    login_time;    // login time
  3053. X    time_t    anniversary;    // date of first logon (for anniversary calculations)
  3054. X    time_t    mail_check;    // time of last mail check
  3055. X    int        card_color;    // color (ord) of card
  3056. X    int        logins;        // number of logins 
  3057. X    int        downloads;    // number of downloads 
  3058. X    int        uploads;    // number of uploads 
  3059. X    int        priv_msgs;    // private messages 
  3060. X    int        pub_msgs;    // private messages 
  3061. X    int        credited;    // credited time 
  3062. X    unsigned long    mail_size;    // size of mail file on last check
  3063. X    unsigned long    flags;        // flags 
  3064. X    unsigned long    tmpflags;    // temp flags 
  3065. X    unsigned int    acl;        // access level 
  3066. X    unsigned int    tmpacl;        // temp access level 
  3067. X    unsigned int    timelimit;    // time limit 
  3068. X    unsigned int    tmptl;        // temporary time limit 
  3069. X    unsigned int    timeused;    // time used during last call 
  3070. Xpublic:
  3071. X    unsigned int    kused;        // number of kbytes downloaded last call
  3072. X    char    fname[21];    // user's first name
  3073. X    char    lname[21];    // user's last
  3074. X    User();                // constructor 
  3075. X    ~User();            // destructor 
  3076. X    int    append(void);            // append user to userlog
  3077. X    int    check_card(void);    // check card color vs. access level
  3078. X    int    check_info(void);    // ask user about term, lines, cols and such
  3079. X    int    delete_user(char *name); // delete user with login name 
  3080. X    int    sysop_edit(void);    // sysop's editor for users
  3081. X    int    export(void);        // export important variables to environment
  3082. X    int    getinfo(char firsttime);// (re)get user's setup and information
  3083. X    int    get(char *name);    // get user - load user record or create new
  3084. X    int    save(char *name);            // save the current user to the user file
  3085. X    int    list(int search,int sysop);    // generate a list of users 
  3086. X    int    change_acl(int acl, char perm);    // change access level - perm true for perm. 
  3087. X    int    change_tl(int tl, char perm); // change timelimit - perm true for perm.  
  3088. X    int    change_flags(unsigned long fl, char perm, char or); // change flags - perm true for perm.  
  3089. X    int    display_info(int logon);    // display user information
  3090. X    unsigned long u_flags(void)     { if (tmpflags != flags)  return tmpflags; else return flags; };
  3091. X    unsigned int u_acl(void)     { if (tmpacl != acl)  return tmpacl; else return acl;};
  3092. X    unsigned int u_timelimit(void)     { if (tmptl!=timelimit) return tmptl; else return timelimit;};
  3093. X    int    prevtimeused() { return(timeused); };
  3094. X    int    credit() { return(credited); };
  3095. X    time_t    user_logon(void) { return(login_time);};
  3096. X    time_t    last_logon(void) { return(last_login);};
  3097. X    char    *logname(void) { return(login_name); };
  3098. X    char    *editorname(void) { return(editor); };
  3099. X    CardRec    *usercard(void) { return(card); };
  3100. X    int    mailavail(void);    // is mail available?
  3101. X    void    inc_uploads(int num) { uploads += num; }; // increment number of uploads
  3102. X    void    inc_downloads(int num) { downloads += num; }; // increment number of downloads
  3103. X    void    inc_credit(int num) { credited += num; }; // increment credited minutes
  3104. X    int    u_uploads(void) { return(uploads); };
  3105. X    int    u_downloads(void){ return(downloads); };
  3106. X    int    inactive_delete(void);
  3107. X    int    inactive_list(void);
  3108. X};
  3109. X
  3110. X#endif // _USER_H_
  3111. END_OF_FILE
  3112.   if test 6118 -ne `wc -c <'rocat-0.75/src/user.h'`; then
  3113.     echo shar: \"'rocat-0.75/src/user.h'\" unpacked with wrong size!
  3114.   fi
  3115.   chmod +x 'rocat-0.75/src/user.h'
  3116.   # end of 'rocat-0.75/src/user.h'
  3117. fi
  3118. if test -f 'rocat-0.75/text/newuser.msg' -a "${1}" != "-c" ; then 
  3119.   echo shar: Will not clobber existing file \"'rocat-0.75/text/newuser.msg'\"
  3120. else
  3121.   echo shar: Extracting \"'rocat-0.75/text/newuser.msg'\" \(3824 characters\)
  3122.   sed "s/^X//" >'rocat-0.75/text/newuser.msg' <<'END_OF_FILE'
  3123. XWelcome to the Roman Catacombs!
  3124. X
  3125. XYou will see this file only once, so pay attention:
  3126. X
  3127. X(you will be able to view this file later if you wish)
  3128. X
  3129. XThe Roman Catacombs is a new BBS being put together to run under Unix.
  3130. X
  3131. XThe BBS offers the following to its users:
  3132. X
  3133. X    Online multi-person chat.
  3134. X    Batch upload/download of files.
  3135. X    Mac/PC/Unix/Windows/pictures files sections.
  3136. X    Access to unix (but only if you request it).
  3137. X    Access to netnews (usenet) messages.  (~3 meg per day)
  3138. X
  3139. X
  3140. XCurrently, the BBS has the following statistics:
  3141. X
  3142. X    over 1.2 gig of disk space
  3143. X    over 400 meg of adult files
  3144. X    the full Linux Slackware distribution
  3145. X    a partial news feed 
  3146. X
  3147. X*NOTE* TRC does *NOT* have a direct internet connection.  You will NOT be able
  3148. Xto 'ftp' from here to some site on the internet!
  3149. X
  3150. XIn the future, the BBS will be getting more disk space as well as a FIDO
  3151. Xinterface and a CD-ROM system.
  3152. X
  3153. XLet me explain the focus of TRC.  TRC is an 'open' system.  Persons may do
  3154. Xwhat they wish here.  The main focus of the bbs is:
  3155. X
  3156. X    1.  Usenet conversation.
  3157. X    2.  Files areas.
  3158. X    3.  Online games.
  3159. X    3.  Multi-user chat. (not supported as yet)
  3160. X
  3161. XCurrently, we have a partial usenet feed.  This means that we don't get
  3162. Xevery article that comes over the internet.  There is a good reason for
  3163. Xthis:  Currently, a full internet feed is over 50 MEGABYTES per day of
  3164. Xnews.  Because of this (and because we have to pay for transfer time), we
  3165. Xhave a partial feed.  This is being explained to you, a new user, for one 
  3166. Xvery good reason.  That is, we're very flexible about those groups that we
  3167. Xdo get.  We may delete those that we find no interest in, and, we may add
  3168. Xthose that people are interested in.
  3169. X
  3170. XThe partial internet news feed has the following 'groups':
  3171. X
  3172. X    Microsoft Windows groups (comp.os.ms-windows.*)
  3173. X    Macintosh groups (comp.sys.mac.*)
  3174. X    Unix groups (comp.unix.*, comp.os.*)
  3175. X    MS-DOS (pc) groups (comp.sys.ibm.pc.*)
  3176. X    Local groups (miscellaneous discussion)
  3177. X    And MANY MANY more.  (there are over 2000 total groups)
  3178. X
  3179. XThe list of newsgroups is available for public view.  (and download)  You
  3180. Xmay choose any group from that list that you wish.  Report it to the sysop,
  3181. Xand you should see new articles in that group the next day.
  3182. X
  3183. XNow, I would like to explain how new users may access the bbs and how they
  3184. Xmay increase their access.  TRC has the following access levels:
  3185. X
  3186. XCard Type     Timelimit   Downloads per day (kbytes)  card description
  3187. X---------     ---------   --------------------------  ------
  3188. XBlue            40 min         1000K                  TRC Charter Member
  3189. XGreen           60 min         unlimited              TRC Constituent
  3190. XBlack         unlimited        unlimited              Sub-Op or Investor
  3191. X
  3192. XEverybody at TRC has a membership card.  From the above, you can see there
  3193. Xare 3 major colors: Blue, Green and Black.  You start with a Blue card.
  3194. XTo advance to a Green (or higher) card, you must donate to TRC.  Note that
  3195. Xall donations are tax-deductible and will be used in BBS upgrades.  (an
  3196. Xexample would be the purchase of a CD-ROM drive)  The rate schedule is
  3197. Xsuch:
  3198. X
  3199. XCard Type     Donation    Valid Until
  3200. X---------     --------    ---------
  3201. XBlue           none       forever -- or until user account deleted
  3202. XGreen          $20.00     one year from receiving date
  3203. XBlack          $35.00     one year from receiving date
  3204. X
  3205. XNotes:
  3206. X    Adult file section access is $10.00 per year.
  3207. X    User accounts are deleted approximately every 90 days.  If you do 
  3208. X        not log in in 90 days, your account will disappear.
  3209. X
  3210. XFor those interested in Sub-Oping:  TRC is always looking for competent
  3211. Xpersons to sub-operate sections of the BBS.  In particular, each machine
  3212. Xarea needs someone with a compatible machine that can test and maintain
  3213. Xthe files areas.  Please leave a note to the sysop if you're interested.
  3214. XUnix experience prior to sub-oping is recommended.
  3215. X
  3216. END_OF_FILE
  3217.   if test 3824 -ne `wc -c <'rocat-0.75/text/newuser.msg'`; then
  3218.     echo shar: \"'rocat-0.75/text/newuser.msg'\" unpacked with wrong size!
  3219.   fi
  3220.   # end of 'rocat-0.75/text/newuser.msg'
  3221. fi
  3222. echo shar: End of archive 6 \(of 9\).
  3223. cp /dev/null ark6isdone
  3224. MISSING=""
  3225. for I in 1 2 3 4 5 6 7 8 9 ; do
  3226.     if test ! -f ark${I}isdone ; then
  3227.     MISSING="${MISSING} ${I}"
  3228.     fi
  3229. done
  3230. if test "${MISSING}" = "" ; then
  3231.     echo You have unpacked all 9 archives.
  3232.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3233. else
  3234.     echo You still must unpack the following archives:
  3235.     echo "        " ${MISSING}
  3236. fi
  3237. exit 0
  3238. exit 0 # Just in case...
  3239.