home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games (Alt) / INFESPGAMES.iso / os2 / backgam / source / special.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-02  |  3.9 KB  |  119 lines

  1. /*************************************************************
  2.  *    ______                                                 *
  3.  *   /     /\  TinyFugue was derived from a client initially *
  4.  *  /   __/  \ written by Anton Rang (Tarrant) and later     *
  5.  *  |  / /\  | modified by Leo Plotkin (Grod).  The early    *
  6.  *  |  |/    | versions of TinyFugue written by Greg Hudson  *
  7.  *  |  X__/  | (Explorer_Bob).  The current version is       *
  8.  *  \ /      / written and maintained by Ken Keys (Hawkeye), *
  9.  *   \______/  who can be reached at kkeys@ucsd.edu.         *
  10.  *                                                           *
  11.  *             No copyright 1992, no rights reserved.        *
  12.  *             Fugue is in the public domain.                *
  13.  *************************************************************/
  14.  
  15. /**********************************************************************
  16.  * Fugue filtering functions                                          *
  17.  *                                                                    *
  18.  * Written by Greg Hudson and Ken Keys.                               *
  19.  * Triggers, portals, watchdog, and quiet login are all handled here. *
  20.  **********************************************************************/
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include "tf.h"
  25. #include "dstring.h"
  26. #include "util.h"
  27. #include "history.h"
  28. #include "world.h"
  29. #include "socket.h"
  30. #include "macro.h"
  31. #include "output.h"
  32.  
  33. static void FDECL(extract_first_word,(char *what, Stringp str));
  34. static int  FDECL(keep_quiet,(char *what, short *count));
  35. static int  FDECL(handle_portal,(char *what));
  36.  
  37. short FDECL(special_hook,(struct History *q, char *what, short *count));
  38.  
  39. static int keep_quiet(what, count)
  40.     char *what;
  41.     short *count;
  42. {
  43.     if (!*count) return FALSE;
  44.     if (!cstrncmp(what, "Use the WHO command", 19) ||
  45.       !cstrncmp(what, "### end of messages ###", 23)) {
  46.         *count = 0;
  47.     } else (*count)--;
  48.     return TRUE;
  49. }
  50.  
  51. short special_hook(q, what, count)
  52.     struct History *q;
  53.     char *what;
  54.     short *count;
  55. {
  56.     short attr = 0;
  57.     extern Stringp lastname;           /* person who last acted */
  58.     extern int borg, hilite, gag;
  59.  
  60.     if ((borg || hilite || gag) && ((attr = check_trigger(what)) & F_GAG & gag))
  61.         return attr & F_SUPERGAG;
  62.     if (keep_quiet(what, count)) return F_GAG;
  63.     if (is_suppressed(q, what)) return F_GAG;
  64.     if (handle_portal(what)) return F_GAG;
  65.     extract_first_word(what, lastname);
  66.     return attr;
  67. }
  68.  
  69. static void extract_first_word(what, str)
  70.     char *what;
  71.     Stringp str;
  72. {
  73.     char *place;
  74.  
  75.     place = strchr(what, ' ');
  76.     if (place == NULL) place = strchr(what, ',');
  77.     if (place == NULL) place = strchr(what, '(');
  78.     if (place != NULL) Stringncpy(str, what, place - what);
  79.     else Stringcpy(str, what);
  80. }
  81.  
  82. static int handle_portal(what)
  83.     char *what;
  84. {
  85.     smallstr name, address, port;
  86.     char *buffer, *place;
  87.     World *world;
  88.     extern int bamf;
  89.  
  90.     if (!bamf) return(0);
  91.     if (sscanf(what, "#### Please reconnect to %64s (%64[^ )]) port %64s ####",
  92.          name, address, port) != 3) return 0;
  93.  
  94.     place = strchr(name, '@');              /* Get IP address. */
  95.     if (place == NULL) return (0);
  96.     *place++ = '\0';
  97.  
  98.     if (bamf == 1) {
  99.         buffer = MALLOC(strlen(name) + 2);
  100.         *buffer = '@';
  101.         strcpy(buffer + 1, name);
  102.         world = fworld();
  103.         world = new_world(buffer, world->character, world->pass,
  104.             (isdigit(*place) ? place : address), port, world->mfile);
  105.         FREE(buffer);
  106.         world->flags |= WORLD_TEMP;
  107.     } else if (!(world = find_world(name))) {
  108.         world = new_world(name, "", "", isdigit(*place) ? place : address,
  109.             port, "");
  110.         world->flags |= WORLD_TEMP;
  111.     }
  112.  
  113.     do_hook(H_BAMF, "%% Bamfing to %s", "%s", name);
  114.     if (bamf == 1) disconnect("");
  115.     if (!connect_to(world, TRUE))
  116.         oputs("% Connection through portal failed.");
  117.     return 1;
  118. }
  119.