home *** CD-ROM | disk | FTP | other *** search
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // chat_mode:
- // this replaces the original chatmode found in original HOST.SLT
- //
- // entry values:
- // local_stat = local_mode (is this a local mode test?)
- // carrier_stat = carrier_counts (should we look out CD line?)
- // capture_fname: capture file name
- //
- // return values:
- // 0: normal exit by pressing F2
- // 1: sysop press HOME to exit HOSTBBS
- // 2: sysop press END to terminate user
- // 3: connection is mysteriously lost
- //
- //////////////////////////////////////////////////////////////////////////////
-
- int local_mode, in_chat_mode;
- int finished_caller, exit_requested, carrier_counts, kill_user;
- str capfname[64];
-
- main(int local_stat, int carrier_stat, str capture_fname)
-
- {
- str trail[85], chat_buffer[85];
- int j, c;
-
- local_mode = local_stat;
- carrier_counts = carrier_stat;
- capfname = capture_fname;
- in_chat_mode = 1;
- finished_caller = 0;
- exit_requested = 0;
- kill_user = 0;
-
- trail = "";
- host_send("^M^J^M^J--- SysOp Initiated Chat ---^M^J^M^J");
- do {
- chat_buffer = ""; // clear chat buffer
- if (strlen(trail) > 0) { // there is word from previous line
- host_send(trail); // display it and copy it to
- substr(trail, 0, strlen(trail), chat_buffer);
- host_input_strn(chat_buffer, 79, strlen(trail));
- trail = "";
- }
- else
- host_input_strn(chat_buffer, 79, 0);
- if (finished_caller) {
- if (exit_requested) // sysop press HOME
- return 1;
- else if (kill_user) // sysop press END
- return 2;
- else // connection lost
- return 3;
- }
- if (!in_chat_mode) { // chat mode terminated by F2
- host_send("^M^J^M^J--- Chat Finished ---^M^J^M^J");
- host_send("Please press <RET> to continue...");
- host_send("^M^J^M^J");
- c = 0;
- do {
- c = host_input();
- } while (c != '^M' && !finished_caller);
- if (finished_caller) {
- if (exit_requested) // sysop press HOME
- return 1;
- else if (kill_user) // sysop press END
- return 2;
- else // connection lost
- return 3;
- }
- else return 0;
- }
- if (strlen(chat_buffer) == 79) { // line buffer is full
- j = strlen(chat_buffer) - 1; // so remove the last word
- while (subchr(chat_buffer, j) != ' ' // move before last word
- && j > 0)
- --j; // point j to the first space just before the last word
- substr(chat_buffer, j + 1, 80, trail); // copy the last word to trail
- while (j < strlen(chat_buffer)){ // erase the last word
- host_send_c(8); // in current line on screen
- ++j;
- }
- host_send("^M^J");
- }
- } while (1);
-
- } // chat_mode
-
- //////////////////////////////////////////////////////////////////////////////
- // host_send sends the specified string through two routes:
- // 1) terminal emulator, so that ANSI codes can be interpreted locally
- // 2) modem port
- //////////////////////////////////////////////////////////////////////////////
-
- host_send(str outstr)
-
- {
-
- if (!local_mode)
- cputs(outstr); // sends to modem port
- printsc_trm(outstr); // sends to screen through terminal emulator
-
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // host_send_c sends the specified character through two routes:
- // 1) screen
- // 2) modem port
- //////////////////////////////////////////////////////////////////////////////
-
- host_send_c(int chr)
-
- {
- str c_str[2];
-
- setchr(c_str, 0, chr);
- setchr(c_str, 1, 0);
- if (!local_mode)
- cputc(chr); // sends to modem port
- printsc_trm(c_str); // sends to terminal emulator of host
-
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // host_input_strn waits the sysop/user to input a string or press <CR>
- // return value = 1 if string is not empty
- // 0 if string is empty
- //////////////////////////////////////////////////////////////////////////////
-
- host_input_strn(str buf, int maximum, int start_point)
-
- {
- int i, j, key;
-
- i = start_point;
- while (1) { // endless loop until... lets see...
- key = host_input(); // key is from host or user
- if (!key) { // timeout or user disconnect
- setchr(buf, 0, 0); // set string to empty
- return 0; // indicate there is a problem
- }
- if (key == '^M') { // Carriage return pressed
- host_send("^J"); // advance one more line
- setchr(buf, 0, 0); // and clear the buffer
- break; // out of the endless loop
- }
- if (key == 127 || key == 8) { // Backspace or Del
- if (i) { // if something has been typed
- --i;
- host_send_c(key); // erase one character backwards
- }
- continue; // continue the endless loop
- } // if Backspace or Del
- if (key == 9) { // Horizontal Tab is converted to up to
- j = 5; // five blanks.
- while (i < maximum && j > 0){
- setchr(buf, i, ' ');// put char into buffer and
- ++i;
- --j;
- host_send_c(' ');
- }
- continue;
- }
- if (key == 24) { // Ctrl-X key pressed by user
- while (i >= 0) { // move cursor to starting point
- host_send_c(8);
- --i;
- }
- i = 0; // reset i
- continue;
- }
- if (i < maximum) { // if not more than buffer size
- setchr(buf, i, key); // put char into buffer and
- ++i; // take a note about number of characters
- }
- if (i == maximum) // if maximum count is reached
- break;
- } // the while endless loop
-
- setchr(buf, i, '^0'); // mark the end of string
-
- if (subchr(buf, 0)) // if this is not an empty string
- return 1; // then return 1
- else // this is an empty string
- return 0; // so return 0
-
- } // host_input_strn
-
- //////////////////////////////////////////////////////////////////////////////
- // host input function does this:
- // it starts up a timer to 5 minutes then enters an endless loop
- // (No time limit if SysOp is calling this board)
- // waiting for character coming from keyboard or comm port.
- // any character presented in the keyboard or comm port will terminate
- // the endless loop by doing the following:
- // Keyboard character (from SysOp, of course):
- // HOME -- sysop wants to exit the session
- // END -- sysop kicks the user out (kill user)
- // F1 -- sysop initiates chat mode
- // F2 -- sysop terminates chat mode
- // F3 -- sysop check incoming user's basic data
- // All other char except BS & Del -- sends to screen & modem
- // Comm port character (from User, of course):
- // All other char except BS & Del -- sends to screen & modem
- // return value = 0 if inactivity is too long or connection is lost
- // return value = ASCII value
- //////////////////////////////////////////////////////////////////////////////
-
- host_input()
-
- {
- int c, t, curt, capst;
-
- while (1) {
-
- if (carrier_counts && !carrier()) {
- prints("^M^JConnection has been lost, call terminated.^M^J");
- finished_caller = 1;
- return 0;
- }
-
- if ((c = inkey()) != 0) { // if keyboard buffer is not empty
-
- if (c <= 255) {
- if (c != 8 && c != 127 && c != 9) // backspace & delete & tab
- host_send_c(c); // sends the character to screen & modem
- return c;
- }
-
- else if (c == 0x4700) { // HOME key, sysop wants to exit
- finished_caller = 1;
- exit_requested = 1;
- return 0;
- }
-
- else if (c == 0x4f00) { // END key, temrinate user
- prints("^M^JUser terminated!");
- ustamp("Terminated by SysOp", 1, 1);
- if (carrier_counts)
- hangup();
- finished_caller = 1;
- kill_user = 1;
- return 0;
- }
- // F1 (sysop initiate chat) is disabled
-
- else if (c == 0x3c00) { // F2 key --> sysop terminate chat
- in_chat_mode = 0;
- return 0;
- }
- // F3 (display user's data) is disabled
-
- else if (c == 0x3e00) { // F4 key --> capture on/off
- capst = capture_stat();
- if (capst == 0) // capture file is currently closed
- capture(capfname); // so open a capture file
- else if (capst == 1 || capst == 2) // capture file is currently open
- capture("*CLOSE*"); // so close it
- update_term();
- }
- else if (c == 0x3f00) { // F5 key --> capture pause/unpause
- capst = capture_stat();
- if (capst == 1) // capture file is currently open
- capture("*PAUSE*"); // so pause it
- else if (capst == 2) // capture file is open and paused
- capture("*UNPAUSE*"); // so unpause it
- update_term();
- }
- // F6 (reset caller's time) is disabled
-
- } // if keyboard buffer is not empty
-
- if (!local_mode) // if this is not a local test
- if (cinp_cnt()) { // and if something is in the comm buffer
- c = cgetc(); // then read that character
- if (c != 8 && c != 127 && c != 9) // backspace & delete & tab
- host_send_c(c); // sends the character to screen & modem (echo)
- return c;
- }
- } // while
- } // host_input
-