⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scmds.c

📁 P2P NAP的C实现 P2P在网络应用中越来越流行
💻 C
📖 第 1 页 / 共 4 页
字号:
    wp(win, ""BOLD"%s<%s%s"BOLD"%s>%s %s\n", hilit, WHITE, tok[1], hilit, WHITE, str+strlen(tok[1])+strlen(tok[0])+2);  }  else  {    wp(win, "%s<%s%s%s:%s%s%s>%s %s\n", hilit, WHITE, tok[1], DARK, WHITE, tok[0], hilit, WHITE, str+strlen(tok[1])+strlen(tok[0])+2);  }  drw(win);  recent = NULL;    return(1);}I_NAP_FUNC(stell){  char *autoreply;  static char *lastreply = NULL;  /* nick of last user we autoreplied to */  recent = findquery(chanl, tok[0]);  wp(win, "%s* [%s%s%s]%s %s\n", BRIGHT(GREEN), WHITE, tok[0], BRIGHT(GREEN), WHITE, str+strlen(tok[0])+1);  drw(win);  recent = NULL;      if ((autoreply = getval("autoreply")) != NULL) {    /* do not autoreply to the same user twice in a row, to discourage       infinite chats between two autoreplying clients */    if (!(lastreply && !strcmp(lastreply, tok[0]))) {      autoreply = strdup(autoreply);      sendpack(s, NAP_TELL, "%s %s", tok[0], fixquotes(autoreply));      wp(win, "%s* --> (%s%s%s)%s %s\n", GREEN, WHITE, tok[0], GREEN, WHITE, autoreply);      drw(win);      free(autoreply);      free(lastreply);      lastreply = strdup(tok[0]);    }  }  return(1);}/* 406 (0x196) join message (user has joined channel) [SERVER]   <channel> <user> <sharing> <link-type> */I_NAP_FUNC(sjoin){  if (!(recent = findchan(chanl, tok[0])))    return(1);  if (!strcasecmp(tok[1], info.user))    wp(win, "\n");  wp(win, "%s* %s (%s%s%s) [%ssharing %i songs%s] has joined %s.%s\n", BRIGHT(GREEN), tok[1], WHITE, atoi(tok[3])>10?"Unknown":conns[atoi(tok[3])], BRIGHT(GREEN), WHITE, atoi(tok[2]), BRIGHT(GREEN), tok[0], WHITE);  drw(win);  adduser(recent, tok[1], atoi(tok[2]), atoi(tok[3]));  recent = NULL;    return(1);}/* 407 (0x197)     user parted channel [SERVER]   <channel> <nick> <sharing> <linespeed>  */I_NAP_FUNC(spart){  if (!(recent = findchan(chanl, tok[0])))    return(1);  wp(win, "%s* %s (%s%s%s) [%ssharing %i songs%s] has left %s.%s\n", GREEN, tok[1], WHITE, conns[atoi(tok[3])], GREEN, WHITE, atoi(tok[2]), GREEN, tok[0], WHITE);  drw(win);  deluser(recent, tok[1]);  recent = NULL;    return(1);}I_NAP_FUNC(stopic){  if (!(recent = findchan(chanl, tok[0])))    return(1);  wp(win, "%s* Topic for %s: %s%s\n", YELLOW, tok[0], str+strlen(tok[0])+1, WHITE);  drw(win);    if (recent->topic)    free(recent->topic);  recent->topic = strdup(str+strlen(tok[0])+1);  if (recent == curchan)    tind = 0;  recent = NULL;    return(1);}I_NAP_FUNC(sjchan){  chans_t *cur;  cur = findchan(chanl, tok[0]);  if (cur) {    wp(win, ""RED"* Error: Duplicate channel join!"WHITE"\n");    drw(win);    return 1;  }  cur = (chans_t *)malloc(sizeof(chans_t));  cur->nm = strdup(tok[0]);  cur->users = NULL;  cur->q = 0;  cur->topic = NULL;  cur->l = 0;  cur->flag = 0;  cur->key = NULL;  cur->p = 0;  cur->next = NULL;  list_append(chans_t, chanl, cur);  curchan = cur;  indraw();    /* update command line with new channel */    tin = -1;  return(1);}/* 0x194 (404) server error message */I_NAP_FUNC(snchan){  if (dwi && ((!strcasecmp(tok[0], "information") && !strcasecmp(tok[2], dwi)) || (!strcasecmp(tok[0], "user") && !strcasecmp(tok[1], dwi))))  {    wp(win, "* Unable to resolve %s\n", dwi);    drw(win);    free(dwi);    dwi = NULL;  }  wp(win, "%s* Server: %s%s\n", RED, str, WHITE);  drw(win);    if (!strcmp(str, "You are now cloaked.") || !strcmp(str, "You are cloaked."))    cloaked = 1;  else if (!strcmp(str, "You are no longer cloaked."))    cloaked = 0;  return(1);}I_NAP_FUNC(snotice){  wp(win, "%s* %s%s\n", YELLOW, (str)?str:"", WHITE);  drw(win);  return(1);}I_NAP_FUNC(sscount){  scount.libraries = atoi(tok[0]);  scount.songs = atoi(tok[1]);  scount.gigs = atoi(tok[2]);  return(1);}/* 604 (0x25c)	whois response [SERVER] * *	<nick> "<user-level>" <time> "<channels>" "<status>" <shared> *	<downloads> <uploads> <link-type> "<client-info>" [ <total *	downloads> <total_uploads> <ip> <connecting port> <data port> *	<email> ]  */I_NAP_FUNC(swhois){  int hr, min, sec, t;  struct hostent *d1, *d2;  struct sockaddr_in in;    if (dwi && !strcasecmp(dwi, tok[0]))  {    free(dwi);    dwi = NULL;    if (num < 13)      return(1);    if (fork())      return(1);          d1 = gethostbyname(tok[12]);    if (!d1)    {      ssock(ipcs[1], "* Unable to resolve %s\n", tok[0]);      exit(1);    }        memcpy(&in.sin_addr, d1->h_addr, d1->h_length);    d2 = gethostbyaddr((char *)&in.sin_addr, d1->h_length, AF_INET);    if (!d2)    {      ssock(ipcs[1], "* %s is %s\n", tok[0], inet_ntoa(in.sin_addr));      exit(1);    }         ssock(ipcs[1], "* %s is %s [%s]\n", tok[0], d2->h_name, inet_ntoa(in.sin_addr));        exit(1);  }    t = atoi(tok[2]);  min = t/60;  hr = min/60;  sec = t%60;    while (min >= 60)    min-=60;  wp(win, "%s ______________________%s\n", DARK, WHITE);  wp(win, "%s|%s User: %s\n", DARK, WHITE, tok[0]);  if (!strcasecmp(tok[0], "Ignitor"))    wp(win, "%s|%s Class: Coder (%s)\n", DARK, WHITE, tok[1]);  else if (!strcasecmp(tok[0], "nYtr0"))    wp(win, "%s|%s Class: MoM (%s)\n", DARK, WHITE, tok[1]);  else    wp(win, "%s|%s Class: %s\n", DARK, WHITE, tok[1]);  wp(win, "%s|%s Line: %s\n", DARK, WHITE, conns[atoi(tok[8])]);  wp(win, "%s|%s Time: %i h %i m %i s\n", DARK, WHITE, hr, min, sec);  wp(win, "%s|%s Channels: %s\n", DARK, WHITE, tok[3]);  wp(win, "%s|%s Status: %s\n", DARK, WHITE, tok[4]);  wp(win, "%s|%s Shared: %s\n", DARK, WHITE, tok[5]);  wp(win, "%s|%s Client: %s\n", DARK, WHITE, tok[9]);  wp(win, "%s|%s %s Downloading, %s Uploading\n", DARK, WHITE, tok[6], tok[7]);  if (num > 10)  {    wp(win, "%s|%s %s Downloads, %s Uploads\n", DARK, WHITE, tok[10], tok[11]);    wp(win, "%s|%s Address: %s\n", DARK, WHITE, tok[12]);    wp(win, "%s|%s Data port: %s\n", DARK, WHITE, tok[14]);  }  drw(win);    return(1);}I_NAP_FUNC(soff){  time_t pt;  char *t;    if (dwi && !strcasecmp(dwi, tok[0]))  {    wp(win, "* Unable to resolve %s\n", tok[0]);    drw(win);    free(dwi);    dwi = NULL;  }    pt = atol(tok[2]);  t = ctime(&pt);  t[strlen(t)-1] = '\0';  t[strlen(t)] = 0;    wp(win, "%s ______________________%s\n", DARK, WHITE);  wp(win, "%s|%s User: %s\n", DARK, WHITE, tok[0]);  if (!strcasecmp(tok[0], "Ignitor"))    wp(win, "%s|%s Class: Coder (%s)\n", DARK, WHITE, tok[1]);  else if (!strcasecmp(tok[0], "nYtr0"))    wp(win, "%s|%s Class: MoM (%s)\n", DARK, WHITE, tok[1]);  else    wp(win, "%s|%s Class: %s\n", DARK, WHITE, tok[1]);  wp(win, "%s|%s Last On: %s\n", DARK, WHITE, t);  wp(win, "%s|%s Status: Offline\n", DARK, WHITE);  drw(win);    return(1);}/* 620 (0x26c) remote client queue limit reached: * <nick> "<filename>" <filesize> <digit> */I_NAP_FUNC(sqlimit){  download_t *task;  int max;  /* find matching REQUESTED or RRQUEUED item in the download list */  list_find(task, down, !strcasecmp(task->nick, tok[0]) && !strcasecmp(task->rfn, tok[1]) && (task->state == REQUESTED || task->state == RRQUEUED));  if (!task) {  /* we didn't request this item, so we don't care */    return(1);  }  max = atoi(tok[3]);  /* maximal number of uploads the remote client allows */  /* if max<=0, the remote client allows 0 uploads, and we may as well     not bother queueing it. This is what we did in nap 1.4.8. Alas,     the stupid WinMX client *always* sends max=0, even when it is     not. Thus, we are essentially forced to ignore this value. */  if (task->state == REQUESTED) {    wp(win, "* Remotely queued \"%s\" from %s.\n", task->fn, task->nick);    drw(win);  }  task->state = RQUEUED;  task->r_time = time(0);  return(1);}/* 206 (0xce) get error: <nick> "<filename>"  */I_NAP_FUNC(snget){  download_t *task;  /* find matching REQUESTED or RRQUEUED item in the download list */  list_find(task, down, !strcasecmp(task->nick, tok[0]) && !strcasecmp(task->rfn, tok[1]) && (task->state == REQUESTED || task->state == RRQUEUED));  if (!task) {  /* we didn't request this item, so we don't care */    return(1);  }  wp(win, "%s* Unable to get \"%s\" from %s (206 get error)%s\n", RED, \     task->fn, tok[0], WHITE);  drw(win);    task->state = FAILED;  task->d_time = time(0);  return(1);}/* 609 (0x261) accept failed: <nick> "<filename>" */I_NAP_FUNC(snacc){  download_t *task;  /* find matching REQUESTED or RRQUEUED item in the download list */  list_find(task, down, !strcasecmp(task->nick, tok[0]) && !strcasecmp(task->rfn, tok[1]) && (task->state == REQUESTED || task->state == RRQUEUED));  if (!task) {  /* we didn't request this item, so we don't care */    return(1);  }  wp(win, "%s* Unable to get \"%s\" from %s (609 accept failed)%s\n", RED, \      task->fn, tok[0], WHITE);  drw(win);    task->state = FAILED;  task->d_time = time(0);  return(1);}I_NAP_FUNC(nothing){  return(1);}/* 401 (0x191)	part channel [CLIENT, SERVER]   <channel-name> */I_NAP_FUNC(smpart){  chans_t *pt;  pt = findchan(chanl, tok[0]);    if (!pt)    return(1);    wp(win, "%s* Left channel %s%s\n", GREEN, pt->nm, WHITE);  drw(win);    delchan(pt);  indraw();  if (wmode)  {    dscr(win);    drw(win);  }    return(1);}/* 408 (0x198)    channel user list entry [SERVER]    <channel> <user> <sharing> <link-type> *//* 825 (0x339) user list entry [SERVER]   <channel> <user> <files shared> <speed> */I_NAP_FUNC(suser){  int n, sp;  const char *c;    if (num < 4)    return(1);    n = 16-strlen(tok[1]);  sp = atoi(tok[3]);    if (sp <= 3)    c = RED;  else if (sp <= 6)    c = BRIGHT(YELLOW);  else    c = GREEN;    recent = findchan(chanl, tok[0]);    adduser(recent, tok[1], atoi(tok[2]), sp);    if (tin == -1)  {    tin = 0;    wp(win, "%s* Users:%s\n", YELLOW, WHITE);  }  if (tin == 4)  {    tin = 0;    wp(win, "\n");  }  wp(win, "%s[%s%s", c, WHITE, tok[1]);  for (;n>=0;n--)    wp(win, " ");  wp(win, "%s]%s", c, WHITE);    recent = NULL;    tin++;    return(1);}/* server sends a 0x33e packet to end a list of users in a channel */I_NAP_FUNC(snend){  tin = -1;  wp(win, "\n");  drw(win);    return(1);}/* 607 (0x25f) upload request: <nick> "<filename>" <speed>. Note: not   all servers send the <speed>.  */I_NAP_FUNC(sfreq){  char *lfn, *vfn, *fn, *libraryfile;  upload_t *task;  int i, r;  /* replace backslashes by forward slashes */  vfn = strdup(tok[1]);  for (i=0; i<strlen(vfn); i++) {    if (vfn[i] == '\\') {      vfn[i] = '/';    }  }  /* unmasquerade filename - note: here we do not check the "nomasq"     user variable; thus, if masquerading went from "on" to "off"     during a single session, we still do the right thing. */  lfn = unmasquerade(vfn);    free(vfn);  /* calculate short name without directory components */  fn = ud_basename(lfn);    /* check all the different reasons we might reject this upload */  /* first check that we are really sharing the requested file. This     check was missing from previous versions of nap (pre 1.4.4-ps5).     This was a major security hole, since it would allow a remote     client to download any file, whether it was shared or not */  if (info.shared_filename) {    libraryfile = strdup(info.shared_filename);  } else {    libraryfile = home_file(LIBRARYFILE);  }  if (!isshared(lfn, libraryfile)) {    sendpack(s, NAP_GFR, "%s", str);  /* see comment below */    wp(win, "%s* File \"%s\" was requested by %s, but is not shared!%s\n", RED, lfn, tok[0], WHITE);    drw(win);    free(lfn);    free(libraryfile);    return(1);  }  free(libraryfile);  /* if /tquit is in effect, don't accept any new uploads */  if (quit_after_transfers) {    sendpack(s, NAP_GFR, "%s", str);    wp(win, ""RED"* Not accepting new upload of \"%s\" to %s because /tquit is in effect"WHITE"\n", fn, tok[0]);    drw(win);    free(lfn);    return(1);  }  list_find(task, up, !strcasecmp(task->nick, tok[0]) && !strcasecmp(task->rfn, tok[1]) && !STOPPED(task->state));  if (task != NULL)  {    /* we are already uploading the file to nick */    /* send a NAP_QLIMIT or send nothing ? NAP_QLIMIT would be     * inappropriate.  If the download is not yet IN_PROGRESS, there     * is no harm in sending an accept to the server (but not adding a     * duplicate to the list) - maybe the remote user already deleted     * the first download (which we would not know). -PS */    if (task->state != IN_PROGRESS) {      sendpack(s, NAP_GFR, "%s", str);    } else {      wp(win, ""RED"* Already uploading \"%s\" to %s (duplicate request)"WHITE"\n", fn, tok[0]);      drw(win);    }    free(lfn);    return(1);  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -