📄 cmds.c
字号:
rqueued or rrqueued item by this nick. */int retrydownload(int s, download_t *dl) { download_t *elt; int r; /* see if we're already getting this item -- this is possible because a stopped item can occur several times in the download list */ list_find(elt, down, !strcasecmp(elt->nick, dl->nick) && !strcasecmp(elt->fn, dl->fn) && !STOPPED(elt->state)); if (elt) { if (elt->state == QUEUED || elt->state == RQUEUED) return -2; else return -1; } /* check whether we will queue or request this item */ r = download_limit_reached(dl->nick); if (r) { dl->state = QUEUED; return r; } else { /* check whether there is already an RQUEUED or RRQUEUED item by this nick */ list_find(elt, down, !strcasecmp(dl->nick, elt->nick) && (elt->state == RQUEUED || elt->state == RRQUEUED)); if (elt) { dl->state = RQUEUED; dl->r_time = time(0); return 3; } else { sendpack(s, NAP_DGET, "%s \"%s\"", dl->nick, dl->rfn); dl->state = REQUESTED; dl->c_time = time(0); return 0; } }}/* check whether the download limit for this nick is currently reached. Return 0 if not reached, 2 if overall limit reached, 1 if per-user limit reached */int download_limit_reached(char *nick) { download_t *elt; int maxd = nvar("maxdownloads"); int maxdu = nvar("maxdownuser"); int n; /* see if the overall download limit is reached */ list_count(down, n, elt, ACTIVE(elt->state)); if (maxd >= 0 && n >= maxd) { return 2; } /* see if the per-user download limit is reached */ list_count(down, n, elt, !strcasecmp(elt->nick, nick) && ACTIVE(elt->state)); if (maxdu >= 0 && n >= maxdu) { return 1; } return 0;}/* check whether there is an earlier task than dtask in the download queue which belongs to the same nick and is RQUEUED or RRQUEUED, and which is eligible for immediate download. */int nick_has_earlier_rqueued_task(download_t *dtask, time_t t) { download_t *elt; list_forall(elt, down) { if (elt==dtask) return 0; if (!strcasecmp(elt->nick, dtask->nick) && ((elt->state == RQUEUED && t-elt->r_time >= 15) || elt->state == RRQUEUED)) return 1; } return 0;}/* check whether the upload limit for this nick is currently reached. Return 0 if not reached, 2 if overall limit reached, 1 if per-user limit reached */int upload_limit_reached(char *nick) { upload_t *elt; int maxu = nvar("maxuploads"); int maxuu = nvar("maxupuser"); int n; /* see if the overall upload limit is reached */ list_count(up, n, elt, ACTIVE(elt->state)); if (maxu >= 0 && n >= maxu) { return 2; } /* see if the per-user upload limit is reached */ list_count(up, n, elt, !strcasecmp(elt->nick, nick) && ACTIVE(elt->state)); if (maxuu >= 0 && n >= maxuu) { return 1; } return 0;}/* force queued or stopped item to be downloaded, overriding any download limit. Return 0 on success, or -1 if the item was already being downloaded. */int forcedownload(int s, download_t *dl) { if (dl->state == RRQUEUED) { /* we've already requested this item from the server, so this is just a change of label and verbosity */ dl->state = REQUESTED; return 0; } if (ACTIVE(dl->state)) { return -1; } /* otherwise, go ahead request the download */ sendpack(s, NAP_DGET, "%s \"%s\"", dl->nick, dl->rfn); dl->state = REQUESTED; dl->c_time = time(0); return 0;}/* "/force <range>": force queued items to be downloaded, overriding any download limit, or cause a stopped item to be downloaded. */O_NAP_FUNC(dforce){ download_t *dl; int n; int r; if (num < 2) { usage(win, tok[0]); return(-3); } for (n=parse_range(cstr(str, 1)); n!=-1; n=parse_range(NULL)) { /* find the n-th element in the download list */ list_nth(dl, down, n-1); if (!dl) { wp(win, "* Download number %d does not exist\n", n); drw(win); continue; } r = forcedownload(s, dl); switch (r) { case 0: wp(win, "* Getting \"%s\" from %s\n", dl->fn, dl->nick); drw(win); break; case -1: default: wp(win, "* Already getting \"%s\" from %s\n", dl->fn, dl->nick); drw(win); break; } } return(1);}/* "/retry <range>": put stopped items back in the queue. This only applies to items that are FAILED, INCOMPLETE, or TIMED_OUT */O_NAP_FUNC(dretry){ download_t *task; int n; int r; if (num < 2) { usage(win, tok[0]); return(-3); } for (n=parse_range(cstr(str, 1)); n!=-1; n=parse_range(NULL)) { /* find the n-th element in the download list */ list_nth(task, down, n-1); if (!task) { wp(win, "* Download number %d does not exist\n", n); drw(win); continue; } if (task->state == COMPLETE) { wp(win, "* Download \"%s\" from %s is already finished\n", task->fn, task->nick); drw(win); continue; } /* try to re-request the item */ r = retrydownload(s, task); switch(r) { case 0: wp(win, "* Getting \"%s\" from %s\n", task->fn, task->nick); break; case 1: case 2: wp(win, "* Queued download of \"%s\" from %s\n", task->fn, task->nick); break; case 3: wp(win, "* Remotely queued download of \"%s\" from %s\n", task->fn, task->nick); break; case -1: wp(win, "* Already getting \"%s\" from %s\n", task->fn, task->nick); break; case -2: wp(win, "* Download of \"%s\" from %s is already queued\n", task->fn, task->nick); break; default: break; } drw(win); } return(1);}/* "/retryall": put all stopped items back in the queue. This only applies to items that are FAILED, INCOMPLETE, or TIMED_OUT */O_NAP_FUNC(dretryall){ download_t *task; int n=0; int r; list_forall(task, down) { if (ACTIVE(task->state) || task->state == QUEUED || task->state == RQUEUED || task->state == COMPLETE) { continue; } /* try to re-request the item */ r = retrydownload(s, task); switch(r) { case 0: wp(win, "* Getting \"%s\" from %s\n", task->fn, task->nick); n++; break; case 1: case 2: wp(win, "* Queued download of \"%s\" from %s\n", task->fn, task->nick); n++; break; case 3: wp(win, "* Remotely queued download of \"%s\" from %s\n", task->fn, task->nick); n++; break; case -1: case -2: default: break; /* can't get this item - ignore silently */ } drw(win); } if (!n) { wp(win, "* Nothing to retry\n"); drw(win); } return(1);}O_NAP_FUNC(dpup){ int count, c, d, p, max; upload_t *task; float rate; int bytes, togo; time_t tm, eta; wp(win, "* Uploads:\n"); drw(win); count = 0; c = d = 0; list_forall (task, up) { count++; wp(win, ""BOLD"%i."WHITE" ", count); switch (task->state) { case WAITING: c++; wp(win, "Waiting | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); break; case CONNECTING: case CONNECTING1: /* note: this state always firewalled */ c++; wp(win, "Connecting | %s (firewalled) | "BOLD"%s"WHITE"\n", task->nick, task->fn); break; case IN_PROGRESS: c++; p = (int)(100*(float)task->pos/(float)task->size); bytes = task->pos - task->bsz; togo = task->size - task->pos; tm = time(0) - task->p_time; rate = tm ? bytes / 1024.0 / tm : 0.0; eta = bytes > 10000 ? ((double)tm) * togo / bytes : -1; wp(win, "Sending | %s | "BOLD"%s"WHITE" at %.2f k/s (%i%%)", task->nick, task->fn, rate, p); if (eta>=0) { wp(win, " | Left: %s", format_time(eta)); } wp(win, "\n"); break; case FAILED: d++; wp(win, "Failed | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); break; case INCOMPLETE: d++; wp(win, "Interrupted | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); break; case COMPLETE: d++; wp(win, "Finished | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); break; case TIMED_OUT: d++; wp(win, "Timed out | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); break; default: break; } } max = nvar("maxuploads"); if (max>=0) { wp(win, ""BOLD"%i uploading (limit %i), %i stopped"WHITE"\n", c, max, d); } else { wp(win, ""BOLD"%i uploading, %i stopped"WHITE"\n", c, d); } drw(win); return(1);}/* print download list and download queue, numbering the items in the order * they appear in the lists. */O_NAP_FUNC(dpdown){ int count, c, q, d, p, max; download_t *task; float rate; int bytes, togo; time_t tm, eta; char *ch; int sd, sf, ss, sq; if (num == 2) { sd = ss = sq = sf = 0; ch = tok[1]; while (*ch) { switch (*ch) { case 'd': sd = 1; break; case 's': ss = 1; break; case 'q': sq = 1; break; case 'f': sf = 1; break; default: usage(win, tok[0]); return(-3); break; } ch++; } } else if (num == 1) { sd = ss = sq = sf = 1; } else { usage(win, tok[0]); return(-3); } wp(win, "* Downloads:\n"); drw(win); count = 0; c = q = d = 0; list_forall (task, down) { count++; switch (task->state) { case QUEUED: q++; if (sq) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Queued | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; case RQUEUED: case RRQUEUED: q++; if (sq) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Remotely queued | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; case REQUESTED: c++; if (sd) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Requested | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; case WAITING: c++; if (sd) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Waiting | %s%s | "BOLD"%s"WHITE"\n", task->nick, task->addr.sin_port ? "" : " (firewalled)", task->fn); } break; case CONNECTING: c++; if (sd) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Connecting | %s%s | "BOLD"%s"WHITE"\n", task->nick, task->addr.sin_port ? "" : " (firewalled)", task->fn); } break; case IN_PROGRESS: c++; if (sd) { p = (int)(100*(float)task->pos/(float)task->size); bytes = task->pos - task->bsz; togo = task->size - task->pos; tm = time(0) - task->p_time; rate = tm ? bytes / 1024.0 / tm : 0.0; eta = bytes > 10000 ? ((double)tm) * togo / bytes : -1; wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Getting | %s%s | "BOLD"%s"WHITE" at %.2f k/s (%i%%)", task->nick, task->addr.sin_port ? "" : " (firewalled)", task->fn, rate, p); if (eta>=0) { wp(win, " | Left: %s", format_time(eta)); } wp(win, "\n"); } break; case FAILED: d++; if (sf) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Failed | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; case INCOMPLETE: d++; if (sf) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Interrupted | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; case COMPLETE: d++; if (ss) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Finished | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; case TIMED_OUT: d++; if (sf) { wp(win, ""BOLD"%i."WHITE" ", count); wp(win, "Timed out | %s | "BOLD"%s"WHITE"\n", task->nick, task->fn); } break; default: break; } } max = nvar("maxdownloads"); if (max>=0) { wp(win, ""BOLD"%i downloading (limit %i), %i queued, %i stopped"WHITE"\n", c, max, q, d); } else { wp(win, ""BOLD"%i downloading, %i queued, %i stopped"WHITE"\n", c, q, d); } drw(win); return(1);}O_NAP_FUNC(dsearch){ ssearch_t *cur; char *brate, *freq, *speed, *size, *len, *mime, *xclu, *keys; int c, max, l, i; if (s==-1) { wp(win, ""RED"* Not connected to s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -