void free(void *ptr) { if(ptr == NULL) return; const int bs = tlsf_block_size(ptr); if(bs >= 65536) { const int p = (intptr_t)ptr; const int np = ROUND_UP(p, 65536); int s = bs - (np - p); if(s > 0) { s &= ~0xffff; if(s > 0) { #if 0 tracelog(TRACE_NO_PROP, TRACE_DEBUG, "MEMORY", "free(%p+%d) == page_free(0x%x+%d)", ptr, bs, np, s); #endif #ifdef USE_VIRTUAL_MEM if(Lv2Syscall2(308, np, s)) // Invalidate tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "Invalidate failed"); if(Lv2Syscall2(310, np, s)) // Sync tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "Sync failed"); #endif } } } hts_lwmutex_lock(&mutex); tlsf_free(gpool, ptr); hts_lwmutex_unlock(&mutex); }
void verify_heap(void) { hts_lwmutex_lock(&mutex); int r = tlsf_check_heap(gpool); hts_lwmutex_unlock(&mutex); if(r) tracelog(TRACE_NO_PROP, TRACE_ERROR, "HEAPCHECK", "Heap check verify failed"); else tracelog(TRACE_NO_PROP, TRACE_DEBUG, "HEAPCHECK", "Heap OK"); }
void hts_thread_create_joinable(const char *title, hts_thread_t *p, void *(*func)(void *), void *aux, int prio) { pthread_attr_t attr; pthread_attr_init(&attr); #if defined(linux) if(prio <= -10 && posix_set_thread_priorities) { pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&attr, SCHED_RR); struct sched_param param = {0}; param.sched_priority = sched_get_priority_max(SCHED_RR); pthread_attr_setschedparam(&attr, ¶m); } #endif pthread_create(p, &attr, thread_trampoline, make_trampoline(title, func, aux, prio)); pthread_attr_destroy(&attr); if(gconf.enable_thread_debug) tracelog(TRACE_NO_PROP, TRACE_DEBUG, "thread", "Created thread: %s", title); }
static void memtrace(void) { memstats_t ms = {0}; hts_lwmutex_lock(&mutex); tlsf_walk_heap(gpool, mywalker, &ms); hts_lwmutex_unlock(&mutex); tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "Memory allocator status -- Used: %d (%d segs) Free: %d (%d segs)", ms.used, ms.used_segs, ms.free, ms.free_segs); for(int i = 0; i < 33; i++) { tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "%2d: %8d %8d", i, ms.hist_used[i], ms.hist_free[i]); } }
LoginSocket::~LoginSocket() { while (true) { Packet *pkt = _data.pop(); if (pkt) delete pkt; else break; tracelog(OPTIMAL, "Clearing request queue... %u req. left", _data.get_size()); } }
int bbsdenyadd_main() { int i; char exp[80], board[80], *userid; int dt; struct userec *x; struct boardmem *x1; html_header(1); check_msg(); if (!loginok || isguest) http_fatal("您尚未登录, 请先登录"); changemode(READING); getparmboard(board, sizeof(board)); strsncpy(exp, getparm("exp"), 30); dt = atoi(getparm("dt")); if (!(x1 = getboard(board))) http_fatal("错误的讨论区"); if (!has_BM_perm(currentuser, x1)) http_fatal("你无权进行本操作"); loaddenyuser(board); userid = getparm("userid"); if (userid[0] == 0) return show_form(board); if (getuser(userid, &x) <= 0) http_fatal("错误的使用者帐号"); if (!has_post_perm(x, x1)) http_fatal("这个人本来就没有post权"); strcpy(userid, x->userid); if (!(currentuser->userlevel & PERM_SYSOP) && (dt > 14)) http_fatal("封禁时间大于14天,超过了权限,若需要,请联系站长"); if (dt < 1 || dt > 99) http_fatal("请输入被封天数(1-99)"); if (exp[0] == 0) http_fatal("请输入封人原因"); for (i = 0; i < denynum; i++) if (!strcasecmp(denyuser[i].id, userid)) http_fatal("此用户已经被封"); if (denynum > 40) http_fatal("太多人被封了"); strsncpy(denyuser[denynum].id, userid, 13); strsncpy(denyuser[denynum].exp, exp, 30); denyuser[denynum].free_time = now_t + dt * 86400; denynum++; savedenyuser(board); printf("封禁 %s 成功<br>\n", userid); tracelog("%s deny %s %s", currentuser->userid, board, userid); inform(board, userid, exp, dt); printf("[<a href=bbsdenyall?B=%d>返回被封帐号名单</a>]", getbnumx(x1)); http_quit(); return 0; }
void * mycalloc(size_t nmemb, size_t bytes) { void *r = mymalloc(bytes * nmemb); memset(r, 0, bytes * nmemb); if(r == NULL) { memtrace(); tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "calloc(%d,%d) failed", (int)nmemb, (int)bytes); errno = ENOMEM; } return r; }
void * myrealloc(void *ptr, size_t bytes) { hts_lwmutex_lock(&mutex); void *r = tlsf_realloc(gpool, ptr, bytes); hts_lwmutex_unlock(&mutex); if(r == NULL) { memtrace(); tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "realloc(%d) failed", (int)bytes); errno = ENOMEM; } return r; }
void hts_thread_create_detached(const char *title, void *(*func)(void *), void *aux, int prio) { pthread_t id; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(&id, &attr, thread_trampoline, make_trampoline(title, func, aux, prio)); pthread_attr_destroy(&attr); if(gconf.enable_thread_debug) tracelog(TRACE_NO_PROP, TRACE_DEBUG, "thread", "Created detached thread: %s", title); }
void *mymemalign(size_t align, size_t bytes) { if(bytes == 0) return NULL; hts_lwmutex_lock(&mutex); void *r = tlsf_memalign(gpool, align, bytes); hts_lwmutex_unlock(&mutex); if(r == NULL) { memtrace(); tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "memalign(%d,%d) failed", (int)align, (int)bytes); errno = ENOMEM; } return r; }
int main(void) { char lttng_version_string[16]; snprintf(lttng_version_string, 16, "%u.%u.%u", LTTNG_UST_MAJOR_VERSION, LTTNG_UST_MINOR_VERSION, LTTNG_UST_PATCHLEVEL_VERSION); assert(!strcmp(lttng_version_string, CMAKE_EXPECTED_LTTNGUST_VERSION)); #ifdef CMAKE_LTTNGUST_HAS_TRACEF tracef("calling tracef()! %d %s", -23, CMAKE_EXPECTED_LTTNGUST_VERSION); #endif #ifdef CMAKE_LTTNGUST_HAS_TRACELOG tracelog(TRACE_WARNING, "calling tracelog()! %d", 17); #endif return 0; }
static void insertToFile(struct edit *edit) { struct textLine *ln; char ans[3], *ptr, filename[STRLEN]; int n, full = 0; FILE *fp; for (ln = edit->firstline; ln && !ln->selected; ln = ln->next) ; if (!ln) { ln = edit->firstline; full = 1; ptr = "把整篇文章写入剪贴簿第几页? (0-7) (Q 取消) [0]: "; } else ptr = "把标记块写入剪贴簿第几页? (0-7) (Q 取消) [0]: "; getdata(t_lines - 1, 0, ptr, ans, 2, DOECHO, YEA); if (ans[0] == 'Q') return; n = atoi(ans); if (n < 0 || n > 7) return; tracelog("user %s ip %s insert to clip %d", currentuser->userid, realfromhost, n); ans[0] = n + '0'; ans[1] = 0; sethomefile(filename, currentuser->userid, "clip_"); strcat(filename, ans); fp = fopen(filename, "w"); if (!fp) { move(t_lines - 1, 0); prints("无法打开剪贴簿第 %s 页!\t\t\t", ans); igetkey(); return; } while (ln && (full || ln->selected)) { fwrite(ln->text, 1, ln->len, fp); if (ln->br) fputc('\n', fp); ln = ln->next; } fclose(fp); move(t_lines - 1, 0); prints("已写入剪贴簿第 %s 页。\t\t\t", ans); igetkey(); }
int bbsinvite_main() { char myname[40], ivemail[60], ivname[40], *note; char tmpfn[256]; int retv; html_header(1); //check_msg(); printf("<body>"); if (!loginok || isguest || (currentuser->userlevel & PERM_DEFAULT) != PERM_DEFAULT) http_fatal("匆匆过客无法发送邀请, 请先登录"); changemode(MMENU); if (atoi(getparm("doit")) == 0) { printInviteForm(); http_quit(); return 0; } strsncpy(myname, getparm("myname"), sizeof (myname)); strsncpy(ivemail, getparm("ivemail"), sizeof (ivemail)); strsncpy(ivname, getparm("ivname"), sizeof (ivname)); note = getparm("note"); if (!*ivemail || !*ivname) http_fatal("被邀请人的 email 和名字都需要填写"); if (!trustEmail(ivemail)) http_fatal("该 email 无效,或者其使用者已经在本站注册"); sprintf(tmpfn, "bbstmpfs/tmp/bbsinvite.%d", getpid()); f_write(tmpfn, note); retv = sendInvitation(currentuser->userid, myname, ivemail, ivname, tmpfn); unlink(tmpfn); if (retv < 0) { http_fatal("发送 email 失败,代码 %d", retv); } tracelog("%s invite %s %s", currentuser->userid, ivemail, ivname); printf("<br>成功给 %s 发送邀请!<br>", ivname); printf("<a href=bbsinvite>再发送几个邀请</a>"); http_quit(); return 0; }
int bbslogin_main() { int n, t, infochanged = 0; time_t dtime; char filename[128], buf[256], id[20], pw[PASSLEN], url[10], *ub = FIRST_PAGE; char *ptr; char md5pass[MD5LEN]; struct userec *x, tmpu; int ipmask; int uid; html_header(3); if (loginok && !isguest) { sprintf(buf, "/" SMAGIC "/?t=%d", (int) now_t); redirect(buf); } strsncpy(id, strtrim(getparm("id")), 13); strsncpy(pw, getparm("pw"), PASSLEN); strsncpy(url, getparm("url"), 3); ipmask = atoi(getparm("ipmask")); if (!id[0]) { strcpy(id, "guest"); ipmask = 8; } if (!strcmp(MY_BBS_ID, "YTHT") && !strcmp(id, "guest")) { http_fatal("请输入用户名和密码以登录。"); } if (strcmp(id, "guest")) { ipmask = extandipmask(ipmask, getparm("lastip1"), realfromhost); ipmask = extandipmask(ipmask, getparm("lastip2"), realfromhost); } if ((uid = getuser(id, &x)) <= 0) { printf("%s<br>", id); http_fatal("错误的使用者帐号"); } strcpy(id, x->userid); if (strcasecmp(id, "guest")) { if (checkbansite(realfromhost)) { http_fatal ("对不起, 本站不欢迎来自 [%s] 的登录. <br>若有疑问, 请与SYSOP联系.", realfromhost); } if (userbansite(x->userid, realfromhost)) http_fatal("本ID已设置禁止从%s登录", realfromhost); if (!checkpasswd(x->passwd, x->salt, pw)) { logattempt(x->userid, realfromhost, "WWW", now_t); http_fatal ("密码错误,如有疑问请联系站务组,提供注册资料找回密码"); } if (!user_perm(x, PERM_BASIC)) http_fatal ("由于本帐号名称不符合帐号管理办法,已经被管理员禁止继续上站。<br>请用其他帐号登录在 <font color=red>" DEFAULTBOARD "</font> 版询问."); if (file_has_word(MY_BBS_HOME "/etc/prisonor", x->userid)) { if (x->inprison == 0) { memcpy(&tmpu, x, sizeof (tmpu)); tmpu.inprison = 1; tmpu.dieday = 2; updateuserec(&tmpu, 0); } http_fatal("安心改造,不要胡闹"); } if (x->dieday) http_fatal("死了?还要做什么? :)"); t = x->lastlogin; memcpy(&tmpu, x, sizeof (tmpu)); if (tmpu.salt == 0) { tmpu.salt = getsalt_md5(); genpasswd(md5pass, tmpu.salt, pw); memcpy(tmpu.passwd, md5pass, MD5LEN); infochanged = 1; } if (count_uindex(uid) == 0) { if (now_t - t > 1800) tmpu.numlogins++; infochanged = 1; tmpu.lastlogin = now_t; dtime = t - 4 * 3600; t = localtime(&dtime)->tm_mday; dtime = now_t - 4 * 3600; if (t < localtime(&dtime)->tm_mday && x->numdays < 60000) { tmpu.numdays++; } } if (abs(t - now_t) < 5) { http_fatal("两次登录间隔过密!"); } if (x->lasthost != from_addr.s_addr) { tmpu.lasthost = from_addr.s_addr; infochanged = 1; } if (infochanged) updateuserec(&tmpu, 0); currentuser = x; } ptr = getsenv("HTTP_X_FORWARDED_FOR"); tracelog("%s enter %s www %d %s", x->userid, realfromhost, infochanged, ptr); n = 0; if (loginok && isguest) { u_info->wwwinfo.iskicked = 1; } if (strcasecmp(id, "guest")) { sethomepath(filename, x->userid); mkdir(filename, 0755); strsncpy(buf, getparm("style"), 3); wwwstylenum = -1; if (isdigit(buf[0])) wwwstylenum = atoi(buf); if ((wwwstylenum > NWWWSTYLE || wwwstylenum < 0)) if (!readuservalue (x->userid, "wwwstyle", buf, sizeof (buf))) wwwstylenum = atoi(buf); if (wwwstylenum < 0 || wwwstylenum >= NWWWSTYLE) wwwstylenum = 1; currstyle = &wwwstyle[wwwstylenum]; } else { wwwstylenum = 1; currstyle = &wwwstyle[wwwstylenum]; } ub = wwwlogin(x, ipmask); #ifdef USESESSIONCOOKIE { extern char sessionCookie[]; printf ("<script>document.cookie='SESSION=%s; path=/';</script>", urlencode(sessionCookie)); } #endif if (!strcmp(url, "1")) { #if 1 printf ("<script>\n" "function URLencode(sStr) {\n" "return escape(sStr).replace(/\\+/g, '%%2C').replace(/\\\"/g,'%%22').replace(/\\'/g, '%%27');\n" "}\n" "a=window.opener.location.href;\n" "l=a.length;\n" "t=a.indexOf('/" SMAGIC "',1);\n" "t=a.indexOf('/',t+1);\n" //"nu=\"%s\"+\"?t=%ld&b=\"+URLencode(a.substring(t+1,l));\n" "nu=\"%s\"+\"?t=%ld&b=\"+a.substring(t+1,l);\n" "opener.top.location.href=nu;window.close();</script>", ub, now_t); #else printf ("<script>opener.top.location.href='%s?t=%d';window.close();</script>", ub, now_t); #endif } else { char buf[256]; if (strcmp(x->userid, "guest") && shouldbroadcast(uid)) sprintf(buf, "%s?t=%d&b=ooo", ub, (int) now_t); else sprintf(buf, "%s?t=%d", ub, (int) now_t); redirect(buf); } http_quit(); return 0; }
void calc_next_move(const struct plane *p, const int srow, const int scol, int *alt, const struct xyz target, int *bearing, const bool cleared_exit, struct frame *frame) { // Avoid obstacles. Obstacles are: The boundary except for the // target exit at alt==9, adjacency with another plane (props have // to check this at t+1 and t+2), within 2 of an exit at alt 6-8 if // it's cleared the exit, the exclusion area of an airport at alt <= 2. // Incur a penalty for matching the bearing/altitude of a // blocking airplane (because it'll just continue to block). struct blp blocking_planes[BLP_MAX]; int n_blp = 0; int nalt; const bool trace = (p->id == 'j' && srow == 1 && scol == 9 && *alt == 9 && bearings[*bearing].aircode == '<' && target.row == 0 && target.col == 29 && target.alt == 9); // If the plane's at the airport, it can only hold or take off. if (*alt == 0) { struct xy rc = apply(srow, scol, *bearing); frame->cand[0].bearing = frame->cand[1].bearing = *bearing; frame->cand[0].alt = 0; frame->cand[1].alt = 1; if (adjacent_another_plane(rc, 1, p->isjet, frame->opc_start).alt > 0) { // Can't take off, can only hold. frame->n_cand = 1; } else { *alt = 1; frame->n_cand = 2; } return; } frame->n_cand = 0; for (int turn = -2; turn <= 2; turn++) { int nb = (*bearing + turn) & 7; struct xy rc = apply(srow, scol, nb); if (rc.row < 0 || rc.col < 0 || rc.row >= board_height || rc.col >= board_width) continue; bool on_boundary = (rc.row == 0 || rc.row == board_height-1 || rc.col == 0 || rc.col == board_width-1); for (nalt = *alt-1; nalt <= *alt+1; nalt++) { if (nalt == 0 || nalt == 10) continue; if (target.alt == 9 && nalt == 9 && rc.row == target.row && rc.col == target.col) { // Reached the proper exit gate. Can't collide here, // planes just immediately disappear. new_cand(frame, nb, nalt, -10*MATCHCOURSE_PENALTY); break; } if (on_boundary) // ... and not at the target exit continue; if (cleared_exit && p->target_airport && in_airport_excl(rc, nalt, p->target_num)) continue; if (nalt == 1 && p->target_airport && rc.row == target.row && rc.col == target.col && in_airport_excl(apply(srow, scol, -1), *alt, p->target_num)) continue; struct blp adjacent_plane = adjacent_another_plane(rc, nalt, p->isjet, frame->opc_start); if (adjacent_plane.alt > 0) { add_blocking_plane(blocking_planes, &n_blp, adjacent_plane); tracelog(trace, "Candidate move to (%d, %d, %d) bearing %s " "blocked by %s plane at altitude %d " "bearing %s\n", rc.row, rc.col, nalt, bearings[nb].shortname, adjacent_plane.isjet ? "jet" : "prop", adjacent_plane.alt, bearings[adjacent_plane.bearing].shortname); continue; } if (cleared_exit && (rc.row <= 2 || rc.row >= board_height - 3 || rc.col <= 2 || rc.col >= board_width - 3) && ((p->target_airport && nalt >= 6) || (!p->target_airport && nalt != 9))) continue; bool aligned = planes_aligned(rc, nalt, p->isjet, frame->opc_start); int penalty = aligned ? MATCHCOURSE_PENALTY/2 : 0; int distance = penalty + cdist(rc.row, rc.col, nalt, target, p, srow, scol); new_cand(frame, nb, nalt, distance); tracelog(trace, "Adding candidate move to (%d, %d, %d) bearing %s " "distance=%d\n", rc.row, rc.col, nalt, bearings[nb].longname, distance); } } assert(frame->n_cand <= 15); if (frame->n_cand == 0) { tracelog(trace, "Warning: Can't find safe path for plane '%c'\n", p->id); *alt = -1; return; } tracelog(trace, "Checking %d candidate moves against %d blocking planes.\n", frame->n_cand, n_blp); for (int i = 0; i < frame->n_cand; i++) { for (int j = 0; j < n_blp; j++) { if (frame->cand[i].bearing != blocking_planes[j].bearing || p->isjet != blocking_planes[j].isjet) { tracelog(trace, "Not applying matchcourse penalty: " "%s c_bearing %s vs. %s b_bearing %s " "(%d/%d vs. %d/%d)\n", p->isjet ? "jet" : "prop", bearings[frame->cand[i].bearing].shortname, blocking_planes[j].isjet ? "jet" : "prop", bearings[blocking_planes[j].bearing].shortname, frame->cand[i].bearing, p->isjet, blocking_planes[j].bearing, blocking_planes[j].isjet); continue; } int da = abs(frame->cand[i].alt - blocking_planes[j].alt); if (da == 0) { tracelog(trace, "Applying matchcourse penalty to plane %c " "bearing %s.\n", p->id, bearings[blocking_planes[j].bearing].longname); frame->cand[i].distance += MATCHCOURSE_PENALTY; } else if (da == 1) { tracelog(trace, "Applying minor matchcourse penalty to " "plane %c bearing %s.\n", p->id, bearings[blocking_planes[j].bearing].longname); frame->cand[i].distance += MATCHCOURSE_PENALTY/10; } else { tracelog(trace, "Not applying matchcourse penalty: " "c_alt %d vs. b_alt %d\n", frame->cand[i].alt, blocking_planes[j].alt); } } } qsort(frame->cand, frame->n_cand, sizeof(*frame->cand), distcmp); int old_dist = cdist(srow, scol, *alt, target, p, srow, scol); if (frame->cand[frame->n_cand-1].distance > old_dist) { // We're being pushed away from the destination. Apply the // alt change bonus and re-sort. for (int i = 0; i < frame->n_cand; i++) { for (int j = 0; j < n_blp; j++) { if (*alt == blocking_planes[j].alt && frame->cand[i].alt != blocking_planes[j].alt) frame->cand[i].distance -= CHANGEALT_BONUS; } } qsort(frame->cand, frame->n_cand, sizeof(*frame->cand), distcmp); } *bearing = frame->cand[frame->n_cand-1].bearing; *alt = frame->cand[frame->n_cand-1].alt; }
void plot_course(struct plane *p, int row, int col, int alt) { const bool trace = (p->id == 'i' && frame_no == 575); struct frame *frstart = malloc(sizeof *frstart); struct frame *frend = frstart; frstart->prev = frstart->next = NULL; frstart->opc_start = NULL; struct op_courses *opc_end = NULL; assert(alt == 7 || alt == 0); int bearing = alt ? calc_bearing(row, col) : get_airport_xy(row, col)->bearing; bool cleared_exit = false; struct xyz target; for (struct plane *pi = plstart; pi; pi = pi->next) { if (pi == p) continue; new_op_course(pi->current, &frstart->opc_start, &opc_end, pi->isjet); } incr_opc(frstart->opc_start); if (p->target_airport) { struct airport *a = get_airport(p->target_num); if (a == NULL) { errexit('u', "Plane '%c' headed to unknown airport %d.", p->id, p->target_num); } target.alt = 1; target.row = a->trow; target.col = a->tcol; } else { struct exitspec *e = get_exit(p->target_num); if (e == NULL) { errexit('u', "Plane '%c' headed to unknown exit %d.", p->id, p->target_num); } target.alt = 9; target.row = e->row; target.col = e->col; } tracelog(trace, "Tracing plane %c's course from %d:(%d, %d, %d)@%d to " "(%d, %d, %d)\n", p->id, frame_no, row, col, alt, bearings[bearing].degree, target.row, target.col, target.alt); p->start = p->current = p->end = NULL; add_course_elem(p, row, col, alt, bearing, false, trace ? frame_no : 0); p->start_tm = p->current_tm = frame_no; int tick = frame_no+1; int steps = 0, moves = 0; /* Operation of the "plotting course" machine: * (A) Get a frame for the current pos'n. * (B) If frame has cands, step ahead to the best cand and return to (A). * (C) If not, step back to parent frame and remove the cand and * return to (B). */ for (;;) { if (++steps > 200) { log_course(p); errexit('8', "Plane %c stuck in an infinite loop.", p->id); } // Plane doesn't move if it's a prop and the tick is odd... // ...except that a prop plane in an exit will pop out of it. if (!p->isjet && tick%2 == 1 && row != 0 && col != 0 && row != board_height-1 && col != board_width-1) { add_course_elem(p, row, col, alt, bearing, cleared_exit, trace ? tick : 0); tick++; frend->n_cand = -3; make_new_fr(&frend); continue; } moves++; calc_next_move(p, row, col, &alt, target, &bearing, cleared_exit, frend); assert((alt < 0) == (frend->n_cand <= 0)); while (frend->n_cand <= 0) { tracelog(trace, "Backtracking at step %d move %d tick %d\n", steps, moves, tick); struct xyz bt_pos = backtrack(&tick, &cleared_exit, &p->end, &frend); moves--; // Check for a prop. plane's non-move. // TODO: Do we have to worry about the "pop out of an exit" move // that props get at their first tick? if (frend->n_cand == -3) { tracelog(trace, "Backtracking over prop's non-move at tick %d\n", tick); assert(!p->isjet); bt_pos = backtrack(&tick, &cleared_exit, &p->end, &frend); assert(frend->n_cand != -3); } row = bt_pos.row; col = bt_pos.col; tracelog(trace, "After backtracking: %d: pos(%d, %d, %d) and %d " "remaining candidates\n", tick, bt_pos.row, bt_pos.col, bt_pos.alt, frend->n_cand - 1); if (--frend->n_cand > 0) { // We've found a new candidate that's available after // backtracking, so stop backtracing and get on with it. alt = frend->cand[frend->n_cand-1].alt; bearing = frend->cand[frend->n_cand-1].bearing; break; } tracelog(trace, "No new candidates found at tick %d. Backtracking " "again.\n", tick); } if (alt) { row += bearings[bearing].drow; col += bearings[bearing].dcol; } add_course_elem(p, row, col, alt, bearing, cleared_exit, trace ? tick : 0); tick++; if (row == target.row && col == target.col && alt == target.alt) { // We've reached the target. Clean-up and return. if (p->target_airport) { if (!p->isjet) { add_course_elem(p, row, col, alt, bearing, cleared_exit, trace ? tick : 0); tick++; } add_course_elem(p, -1, -1, -2, -1, cleared_exit, trace ? tick : 0); p->end_tm = tick; } else { // For an exit, the plane disappears at reaching it. p->end_tm = tick-1; p->end->at_exit = true; } free_framelist(frstart); if (!quiet) { struct record *rec = p->isjet ? &rec_jet : &rec_prop; if (steps > rec->steps || moves > rec->moves) { if (steps > rec->steps) rec->steps = steps; if (moves > rec->moves) rec->moves = moves; fprintf(logff, "New record long route: plane '%c' at time " "%d in %d steps/%d moves.\n", p->id, frame_no, steps, moves); log_course(p); log_all_courses(); } } return; } if (!cleared_exit && alt > 1 && ((row > 2 && row < board_height-3 && col > 2 && col < board_width-3) || alt < 6 || alt == 9)) { cleared_exit = true; } make_new_fr(&frend); } }
int bbslpassport_main() { int uid, infochanged = 0; char id[IDLEN + 1], pw[PASSLEN], site[256], md5pass[MD5LEN], buf[384]; struct userec *x, tmpu; time_t t, dtime; html_header(3); strsncpy(id, strtrim(getparm("id")), IDLEN + 1); strsncpy(pw, getparm("pw"), PASSLEN); strsncpy(site, getparm("site"), 256); if (!id[0]) http_fatal("请输入帐号"); if (!site[0]) http_fatal("no..."); if (key_fail) http_fatal("内部错误, 联系维护!\n"); if ((uid = getuser(id, &x)) <= 0) { printf("%s<br>", id); http_fatal("错误的使用者帐号"); } strcpy(id, x->userid); if (!strcasecmp(id, "guest")) http_fatal("错误的使用者帐号"); if (checkbansite(fromhost)) { http_fatal ("对不起, 本站不欢迎来自 [%s] 的登录. <br>若有疑问, 请与SYSOP联系.", fromhost); } if (userbansite(x->userid, fromhost)) http_fatal("本ID已设置禁止从%s登录", fromhost); if (!checkpasswd(x->passwd, x->salt, pw)) { logattempt(x->userid, fromhost, "PASSPORT", now_t); http_fatal ("密码错误,如有疑问请联系站务组,提供注册资料找回密码"); } #if 0 if (!user_perm(x, PERM_BASIC)) http_fatal ("由于本帐号名称不符合帐号管理办法,已经被管理员禁止继续上站。<br>请用其他帐号登录在 <font color=red>" DEFAULTBOARD "</font> 版询问."); if (file_has_word(MY_BBS_HOME "/etc/prisonor", x->userid)) { if (x->inprison == 0) { memcpy(&tmpu, x, sizeof (tmpu)); tmpu.inprison = 1; tmpu.dieday = 2; updateuserec(&tmpu, 0); } http_fatal("安心改造,不要胡闹"); } if (x->dieday) http_fatal("死了?还要做什么? :)"); #endif t = x->lastlogin; memcpy(&tmpu, x, sizeof (tmpu)); if (tmpu.salt == 0) { tmpu.salt = getsalt_md5(); genpasswd(md5pass, tmpu.salt, pw); memcpy(tmpu.passwd, md5pass, MD5LEN); infochanged = 1; } #if 1 if (count_uindex(uid) == 0) { if (now_t - t > 1800) tmpu.numlogins++; infochanged = 1; tmpu.lastlogin = now_t; dtime = t - 4 * 3600; t = localtime(&dtime)->tm_mday; dtime = now_t - 4 * 3600; if (t < localtime(&dtime)->tm_mday && x->numdays < 60000) { tmpu.numdays++; } } #endif if (abs(t - now_t) < 20) { http_fatal("两次登录间隔过密!"); } if (x->lasthost != from_addr.s_addr) { tmpu.lasthost = from_addr.s_addr; infochanged = 1; } if (infochanged) updateuserec(&tmpu, 0); tracelog("%s enter %s passport %d %s", x->userid, fromhost, infochanged, getsenv("HTTP_X_FORWARDED_FOR")); printf ("<script>exDate = new Date; exDate.setMonth(exDate.getMonth()+9);" "document.cookie='pp=%s;path=/;expires=' + exDate.toGMTString();</script>", des3_encode(id, 0)); snprintf(buf, sizeof (buf), "http://%s?q=%s", site, des3_encode(id, 1)); redirect(buf); http_quit(); return 0; }