예제 #1
0
파일: bbsutl1.cpp 프로젝트: bhaggerty/wwiv
/**
 * Plays a sound definition file (*.sdf) through PC speaker. SDF files
 * should reside in the gfiles dir. The only params passed to function are
 * filename and false if playback is unabortable, true if it is abortable. If no
 * extension then .SDF is appended. A full path to file may be specified to
 * override gfiles dir. Format of file is:
 *
 * <freq> <duration in ms> [pause_delay in ms]
 * 1000 1000 50
 *
 * Returns 1 if sucessful, else returns 0. The pause_delay is optional and
 * is used to insert silences between tones.
 */
bool play_sdf(const std::string soundFileName, bool abortable) {
  WWIV_ASSERT(!soundFileName.empty());

  std::string fullPathName;
  // append gfilesdir if no path specified
  if (soundFileName.find(WWIV_FILE_SEPERATOR_CHAR) == std::string::npos) {
    std::ostringstream ss;
    ss << syscfg.gfilesdir << soundFileName;
    fullPathName = ss.str();
  } else {
    fullPathName = soundFileName;
  }

  // append .SDF if no extension specified
  if (fullPathName.find('.') == std::string::npos) {
    fullPathName += ".sdf";
  }

  // Must Exist
  if (!WFile::Exists(fullPathName)) {
    return false;
  }

  // must be able to open read-only
  WTextFile soundFile(fullPathName, "rt");
  if (!soundFile.IsOpen()) {
    return false;
  }

  // scan each line, ignore lines with words<2
  std::string soundLine;
  while (soundFile.ReadLine(&soundLine)) {
    if (abortable && bkbhit()) {
      break;
    }
    int nw = wordcount(soundLine.c_str(), DELIMS_WHITE);
    if (nw >= 2) {
      int freq = atoi(extractword(1, soundLine, DELIMS_WHITE));
      int dur = atoi(extractword(2, soundLine, DELIMS_WHITE));

      // only play if freq and duration > 0
      if (freq > 0 && dur > 0) {
        int nPauseDelay = 0;
        if (nw > 2) {
          nPauseDelay = atoi(extractword(3, soundLine, DELIMS_WHITE));
        }
        WWIV_Sound(freq, dur);
        if (nPauseDelay > 0) {
          WWIV_Delay(nPauseDelay);
        }
      }
    }
  }

  soundFile.Close();
  return true;
}
예제 #2
0
char *StringRemoveWhitespace(char *str) {
  WWIV_ASSERT(str);

  if (str) {
    char *obuf, *nbuf;
    for (obuf = str, nbuf = str; *obuf; ++obuf) {
      if (!isspace(*obuf)) {
        *nbuf++ = *obuf;
      }
    }
    *nbuf = '\0';
  }
  return str;
}
예제 #3
0
char *StringRemoveChar(const char *pszString, char ch) {
  static char s_strip_string[ 255 ];

  WWIV_ASSERT(pszString);
  strcpy(s_strip_string, "");

  int i1 = 0;
  for (int i = 0; i < wwiv::strings::GetStringLength(pszString); i++) {
    if (pszString[i] != ch) {
      s_strip_string[i1] = pszString[i];
      i1++;
    } else {
      s_strip_string[i1] = '\0';
      break;
    }
  }

  //if last char is a space, remove it too.
  if (s_strip_string[i1 - 1] == ' ') {
    i1--;
  }
  s_strip_string[i1] = '\0';
  return s_strip_string;
}
예제 #4
0
파일: chains.cpp 프로젝트: bhaggerty/wwiv
void do_chains() {
  int *map = static_cast<int*>(BbsAllocA(GetSession()->max_chains * sizeof(int)));
  WWIV_ASSERT(map != NULL);
  if (!map) {
    return;
  }

  GetSession()->localIO()->tleft(true);
  int mapp = 0;
  memset(odc, 0, sizeof(odc));
  for (int i = 0; i < GetSession()->GetNumberOfChains(); i++) {
    bool ok = true;
    chainfilerec c = chains[i];
    if ((c.ansir & ansir_ansi) && !okansi()) {
      ok = false;
    }
    if ((c.ansir & ansir_local_only) && GetSession()->using_modem) {
      ok = false;
    }
    if (c.sl > GetSession()->GetEffectiveSl()) {
      ok = false;
    }
    if (c.ar && !GetSession()->GetCurrentUser()->HasArFlag(c.ar)) {
      ok = false;
    }
    if (GetApplication()->HasConfigFlag(OP_FLAGS_CHAIN_REG) && chains_reg && (GetSession()->GetEffectiveSl() < 255)) {
      chainregrec r = chains_reg[ i ];
      if (r.maxage) {
        if (r.minage > GetSession()->GetCurrentUser()->GetAge() || r.maxage < GetSession()->GetCurrentUser()->GetAge()) {
          ok = false;
        }
      }
    }
    if (ok) {
      map[ mapp++ ] = i;
      if (mapp < 100) {
        if ((mapp % 10) == 0) {
          odc[mapp / 10 - 1] = static_cast< char >('0' + (mapp / 10));
        }
      }
    }
  }
  if (mapp == 0) {
    GetSession()->bout << "\r\n\n|#5Sorry, no external programs available.\r\n";
    free(map);
    GetSession()->SetMMKeyArea(WSession::mmkeyMessageAreas);
    return;
  }
  show_chains(&mapp, map);

  bool done   = false;
  GetSession()->SetMMKeyArea(WSession::mmkeyMessageAreas);
  int start   = 0;
  char *ss    = NULL;

  do {
    GetSession()->SetMMKeyArea(WSession::mmkeyChains);
    GetSession()->localIO()->tleft(true);
    GetSession()->bout.NewLine();
    GetSession()->bout << "|#7Which chain (1-" << mapp << ", Q=Quit, ?=List): ";

    int nChainNumber = -1;
    if (mapp < 100) {
      ss = mmkey(2);
      nChainNumber = atoi(ss);
    } else {
      char szChainNumber[ 11 ];
      input(szChainNumber, 3);
      nChainNumber = atoi(szChainNumber);
    }
    if (nChainNumber > 0 && nChainNumber <= mapp) {
      done = true;
      GetSession()->SetMMKeyArea(WSession::mmkeyChains);
      GetSession()->bout << "\r\n|#6Please wait...\r\n";
      run_chain(map[ nChainNumber - 1 ]);
    } else if (wwiv::strings::IsEquals(ss, "Q")) {
      GetSession()->SetMMKeyArea(WSession::mmkeyMessageAreas);
      done = true;
    } else if (wwiv::strings::IsEquals(ss, "?")) {
      show_chains(&mapp, map);
    } else if (wwiv::strings::IsEquals(ss, "P")) {
      if (start > 0) {
        start -= 14;
      }
      start = std::max<int>(start, 0);
    } else if (wwiv::strings::IsEquals(ss, "N")) {
      if (start + 14 < mapp) {
        start += 14;
      }
    }
  } while (!hangup  && !done);

  free(map);
}
예제 #5
0
/**
 * Compares the strings
 * @param pszString1 string to compare
 * @param pszString1 other string to compare
 * @return true of the strings contain the same contents
 */
bool IsEquals(const char* pszString1, const char* pszString2) {
  WWIV_ASSERT(pszString1);
  WWIV_ASSERT(pszString2);

  return (strcmp(pszString1, pszString2) == 0) ? true : false;
}
예제 #6
0
/**
 * Gets the length of the C style string.  This function returns an int
 * instead of a size_t, so using this function can avoid warnings of
 * signed vs. unsigned comparasons.
 *
 * @param pszString the C style string
 * @return The length as an integer
 */
int GetStringLength(const char* pszString) {
  WWIV_ASSERT(pszString);
  return static_cast<int>(strlen(pszString));
}
예제 #7
0
int StringCompare(const char *pszString1, const char *pszString2) {
  WWIV_ASSERT(pszString1);
  WWIV_ASSERT(pszString2);

  return strcmp(pszString1, pszString2);
}
예제 #8
0
/**
 * Compares the strings, ignoring case
 * @param pszString1 string to compare
 * @param pszString1 other string to compare
 * @return true of the strings contain the same contents ignoring case
 */
bool IsEqualsIgnoreCase(const char *pszString1, const char *pszString2) {
  WWIV_ASSERT(pszString1);
  WWIV_ASSERT(pszString2);

  return (StringCompareIgnoreCase(pszString1, pszString2) == 0) ? true : false;
}
예제 #9
0
파일: bbsutl1.cpp 프로젝트: bhaggerty/wwiv
/**
 * Finds GetSession()->usernum and system number from emailAddress, sets network number as
 * appropriate.
 * @param emailAddress The text of the email address.
 * @param pUserNumber OUT The User Number
 * @param pSystemmNumber OUT The System Number
 */
void parse_email_info(const std::string emailAddress, int *pUserNumber, int *pSystemNumber) {
  char *ss1, onx[20], ch, *mmk;
  unsigned nUserNumber, nSystemNumber;
  int i, nv, on, xx, onxi, odci;
  net_system_list_rec *csne;

  char szEmailAddress[ 255 ];
  strcpy(szEmailAddress, emailAddress.c_str());

  *pUserNumber = 0;
  *pSystemNumber = 0;
  net_email_name[0] = '\0';
  char *ss = strrchr(szEmailAddress, '@');
  if (ss == NULL) {
    nUserNumber = finduser1(szEmailAddress);
    if (nUserNumber > 0) {
      *pUserNumber = static_cast< unsigned short >(nUserNumber);
    } else if (wwiv::strings::IsEquals(szEmailAddress, "SYSOP")) {     // Add 4.31 Build3
      *pUserNumber = 1;
    } else {
      GetSession()->bout << "Unknown user.\r\n";
    }
  } else if (atoi(ss + 1) == 0) {
    for (i = 0; i < GetSession()->GetMaxNetworkNumber(); i++) {
      set_net_num(i);
      if ((WWIV_STRNICMP("internet", GetSession()->GetNetworkName(), 8) == 0) ||
          ((WWIV_STRNICMP("filenet", GetSession()->GetNetworkName(), 7) == 0) && (*pSystemNumber == 32767))) {
        strcpy(net_email_name, szEmailAddress);
        for (ss1 = net_email_name; *ss1; ss1++) {
          if ((*ss1 >= 'A') && (*ss1 <= 'Z')) {
            *ss1 += 'a' - 'A';
          }
        }
        *pSystemNumber = 1;
        break;
      }
    }
    if (i >= GetSession()->GetMaxNetworkNumber()) {
      GetSession()->bout << "Unknown user.\r\n";
    }
  } else {
    ss[0] = '\0';
    ss = &(ss[1]);
    i = strlen(szEmailAddress);
    while (i > 0 && szEmailAddress[i - 1] == ' ') {
      --i;
    }
    szEmailAddress[i] = 0;
    nUserNumber = atoi(szEmailAddress);
    if (nUserNumber == 0 && szEmailAddress[0] == '#') {
      nUserNumber = atoi(szEmailAddress + 1);
    }
    if (strchr(szEmailAddress, '@')) {
      nUserNumber = 0;
    }
    nSystemNumber = atoi(ss);
    ss1 = strchr(ss, '.');
    if (ss1) {
      ss1++;
    }
    if (nUserNumber == 0) {
      strcpy(net_email_name, szEmailAddress);
      i = strlen(net_email_name);
      while (i > 0 && net_email_name[i - 1] == ' ') {
        --i;
      }
      net_email_name[i] = '\0';
      if (net_email_name[0]) {
        *pSystemNumber = static_cast< unsigned short >(nSystemNumber);
      } else {
        GetSession()->bout << "Unknown user.\r\n";
      }
    } else {
      *pUserNumber = static_cast< unsigned short >(nUserNumber);
      *pSystemNumber = static_cast< unsigned short >(nSystemNumber);
    }
    if (*pSystemNumber && ss1) {
      for (i = 0; i < GetSession()->GetMaxNetworkNumber(); i++) {
        set_net_num(i);
        if (wwiv::strings::IsEqualsIgnoreCase(ss1, GetSession()->GetNetworkName())) {
          if (!valid_system(*pSystemNumber)) {
            GetSession()->bout.NewLine();
            GetSession()->bout << "There is no " << ss1 << " @" << *pSystemNumber << ".\r\n\n";
            *pSystemNumber = *pUserNumber = 0;
          } else {
            if (*pSystemNumber == net_sysnum) {
              *pSystemNumber = 0;
              if (*pUserNumber == 0) {
                *pUserNumber = static_cast< unsigned short >(finduser(net_email_name));
              }
              if (*pUserNumber == 0 || *pUserNumber > 32767) {
                *pUserNumber = 0;
                GetSession()->bout << "Unknown user.\r\n";
              }
            }
          }
          break;
        }
      }
      if (i >= GetSession()->GetMaxNetworkNumber()) {
        GetSession()->bout.NewLine();
        GetSession()->bout << "This system isn't connected to " << ss1 << "\r\n";
        *pSystemNumber = *pUserNumber = 0;
      }
    } else if (*pSystemNumber && GetSession()->GetMaxNetworkNumber() > 1) {
      odc[0] = '\0';
      odci = 0;
      onx[0] = 'Q';
      onx[1] = '\0';
      onxi = 1;
      nv = 0;
      on = GetSession()->GetNetworkNumber();
      ss = static_cast<char *>(BbsAllocA(GetSession()->GetMaxNetworkNumber()));
      WWIV_ASSERT(ss != NULL);
      xx = -1;
      for (i = 0; i < GetSession()->GetMaxNetworkNumber(); i++) {
        set_net_num(i);
        if (net_sysnum == *pSystemNumber) {
          xx = i;
        } else if (valid_system(*pSystemNumber)) {
          ss[nv++] = static_cast< char >(i);
        }
      }
      set_net_num(on);
      if (nv == 0) {
        if (xx != -1) {
          set_net_num(xx);
          *pSystemNumber = 0;
          if (*pUserNumber == 0) {
            *pUserNumber = static_cast< unsigned short >(finduser(net_email_name));
            if (*pUserNumber == 0 || *pUserNumber > 32767) {
              *pUserNumber = 0;
              GetSession()->bout << "Unknown user.\r\n";
            }
          }
        } else {
          GetSession()->bout.NewLine();
          GetSession()->bout << "Unknown system\r\n";
          *pSystemNumber = *pUserNumber = 0;
        }
      } else if (nv == 1) {
        set_net_num(ss[0]);
      } else {
        GetSession()->bout.NewLine();
        for (i = 0; i < nv; i++) {
          set_net_num(ss[i]);
          csne = next_system(*pSystemNumber);
          if (csne) {
            if (i < 9) {
              onx[onxi++] = static_cast< char >(i + '1');
              onx[onxi] = 0;
            } else {
              odci = static_cast< char >((i + 1) / 10);
              odc[odci - 1] = static_cast< char >(odci + '0');
              odc[odci] = 0;
            }
            GetSession()->bout << i + 1 << ". " << GetSession()->GetNetworkName() << " (" << csne->name << ")\r\n";
          }
        }
        GetSession()->bout << "Q. Quit\r\n\n";
        GetSession()->bout << "|#2Which network (number): ";
        if (nv < 9) {
          ch = onek(onx);
          if (ch == 'Q') {
            i = -1;
          } else {
            i = ch - '1';
          }
        } else {
          mmk = mmkey(2);
          if (*mmk == 'Q') {
            i = -1;
          } else {
            i = atoi(mmk) - 1;
          }
        }
        if (i >= 0 && i < nv) {
          set_net_num(ss[i]);
        } else {
          GetSession()->bout << "\r\n|#6Aborted.\r\n\n";
          *pUserNumber = *pSystemNumber = 0;
        }
      }
      free(ss);
    } else {
      if (*pSystemNumber == net_sysnum) {
        *pSystemNumber = 0;
        if (*pUserNumber == 0) {
          *pUserNumber = static_cast< unsigned short >(finduser(net_email_name));
        }
        if (*pUserNumber == 0 || *pUserNumber > 32767) {
          *pUserNumber = 0;
          GetSession()->bout << "Unknown user.\r\n";
        }
      } else if (!valid_system(*pSystemNumber)) {
        GetSession()->bout << "\r\nUnknown user.\r\n";
        *pSystemNumber = *pUserNumber = 0;
      }
    }
  }
}
예제 #10
0
bool isleap(int nYear) {
  WWIV_ASSERT(nYear >= 0);
  return nYear % 400 == 0 || (nYear % 4 == 0 && nYear % 100 != 0);
}
예제 #11
0
/**
 * Attempts to allocate nbytes (+1) bytes on the heap, returns ptr to memory if successful.
 * @param lNumBytes Number of bytes to allocate
 */
void *BbsAllocA(size_t lNumBytes) {
  void* pBuffer = calloc(lNumBytes + 1, 1);
  WWIV_ASSERT(pBuffer);
  return pBuffer;
}
예제 #12
0
/**
 * Attempts to allocate nbytes (+1) bytes on the heap, returns ptr to memory if successful.
 * @param lNumBytes Number of bytes to allocate
 */
void *BbsAllocA(size_t lNumBytes) {
  void* pBuffer = malloc(lNumBytes + 1);
  WWIV_ASSERT(pBuffer);
  memset(pBuffer, 0, lNumBytes);
  return pBuffer;
}