summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/bbs.c4
-rw-r--r--mbbsd/board.c63
-rw-r--r--mbbsd/cache.c74
-rw-r--r--mbbsd/name.c16
-rw-r--r--mbbsd/talk.c34
5 files changed, 109 insertions, 82 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 832c6182..a4223151 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -263,8 +263,8 @@ whereami(int ent, fileheader_t * fhdr, char *direct)
bh = getbcache(currutmp->brc_id);
root = getbcache(1);
p[0] = bh;
- for (i = 0; i < WHEREAMI_LEVEL && p[i]->parent != root && p[i]->parent; i++)
- p[i + 1] = p[i]->parent;
+ for (i = 0; i < WHEREAMI_LEVEL && p[i]->parent>1; i++)
+ p[i + 1] = getbcache(p[i]->parent);
j = i;
prints("我在哪?\n%-40.40s %.13s\n", p[j]->title + 7, p[j]->BM);
for (j--; j >= 0; j--)
diff --git a/mbbsd/board.c b/mbbsd/board.c
index 17a36e6f..b798434a 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -40,6 +40,13 @@ inline int getbid(boardheader_t *fh)
{
return (fh - bcache);
}
+inline boardheader_t *getparent(boardheader_t *fh)
+{
+ if(fh->parent>0)
+ return &bcache[fh->parent-1];
+ else
+ return NULL;
+}
void imovefav(int old)
{
@@ -135,28 +142,30 @@ check_newpost(boardstat_t * ptr)
static void
load_uidofgid(const int gid, const int type)
{
- boardheader_t *bptr, *currbptr;
- int n, childcount = 0;
- currbptr = &bcache[gid - 1];
+ boardheader_t *bptr, *currbptr, *parent;
+ int bid, n, childcount = 0;
+ currbptr = parent = &bcache[gid - 1];
for (n = 0; n < numboards; ++n) {
- if( !(bptr = SHM->bsorted[type][n]) || bptr->brdname[0] == '\0' )
+ bid = SHM->bsorted[type][n]+1;
+ if( bid<=0 || !(bptr = &bcache[bid-1])
+ || bptr->brdname[0] == '\0' )
continue;
if (bptr->gid == gid) {
- if (currbptr == &bcache[gid - 1])
- currbptr->firstchild[type] = bptr;
+ if (currbptr == parent)
+ currbptr->firstchild[type] = bid;
else {
- currbptr->next[type] = bptr;
- currbptr->parent = &bcache[gid - 1];
+ currbptr->next[type] = bid;
+ currbptr->parent = gid;
}
childcount++;
currbptr = bptr;
}
}
- bcache[gid - 1].childcount = childcount;
- if (currbptr == &bcache[gid - 1])
- currbptr->firstchild[type] = NULL;
- else
- currbptr->next[type] = NULL;
+ parent->childcount = childcount;
+ if (currbptr == parent) // no child
+ currbptr->firstchild[type] = -1;
+ else // the last child
+ currbptr->next[type] = -1;
}
static boardstat_t *
@@ -193,12 +202,12 @@ load_boards(char *key)
{
boardheader_t *bptr = NULL;
int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0;
- int i, n;
+ int i, n, bid;
int state;
if (class_bid > 0) {
bptr = getbcache(class_bid);
- if (bptr->firstchild[type] == NULL || bptr->childcount <= 0)
+ if (bptr->firstchild[type] == 0 )
load_uidofgid(class_bid, type);
}
brdnum = 0;
@@ -267,16 +276,17 @@ load_boards(char *key)
else if( class_bid == -1 ){
nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * SHM->nHOTs);
for( i = 0 ; i < SHM->nHOTs ; ++i )
- addnewbrdstat(SHM->HBcache[i] - SHM->bcache,
- HasPerm(SHM->HBcache[i]));
+ if(SHM->HBcache[i]==-1) continue;
+ addnewbrdstat(SHM->HBcache[i],
+ HasPerm(bcache[SHM->HBcache[i]]));
}
#endif
else { // general case
nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards);
for (i = 0; i < numboards; i++) {
- if ((bptr = SHM->bsorted[type][i]) == NULL)
+ n = SHM->bsorted[type][i]+1;
+ if (n<0 || (bptr = &bcache[n]) == NULL)
continue;
- n = getbid(bptr);
if (!bptr->brdname[0] ||
(bptr->brdattr & (BRD_GROUPBOARD | BRD_SYMBOLIC)) ||
!((state = HasPerm(bptr)) || GROUPOP()) ||
@@ -294,12 +304,12 @@ load_boards(char *key)
qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends);
#endif
} else { /* load boards of a subclass */
- int childcount = bptr->childcount;
+ int childcount = bptr->childcount;
nbrd = (boardstat_t *) malloc((childcount+2) * sizeof(boardstat_t));
// 預留兩個以免大量開版時掛調
- for (bptr = bptr->firstchild[type]; bptr != NULL &&
- brdnum < childcount+2; bptr = bptr->next[type]) {
- n = getbid(bptr);
+ for (bid = bptr->firstchild[type]; bid > 0 &&
+ brdnum < childcount+2; bid = bptr->next[type]) {
+ bptr = getbcache(bid);
state = HasPerm(bptr);
if ( !(state || GROUPOP()) || TITLE_MATCH(bptr, key) )
continue;
@@ -310,9 +320,9 @@ load_boards(char *key)
if (HAS_PERM(PERM_SYSOP))
state |= NBRD_SYMBOLIC;
else
- n = BRD_LINK_TARGET(bptr) - 1;
+ bid = BRD_LINK_TARGET(bptr);
}
- addnewbrdstat(n, state);
+ addnewbrdstat(bid-1, state);
}
if(childcount < brdnum) //Ptt: dirty fix fix soon
getbcache(class_bid)->childcount = 0;
@@ -766,8 +776,7 @@ choose_board(int newflag)
case 'F':
case 'f':
if (class_bid>0 && HAS_PERM(PERM_SYSOP)) {
- getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0]
- = NULL;
+ getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = 0;
brdnum = -1;
}
break;
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 32cc4a95..09b3feac 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -318,14 +318,16 @@ userinfo_t *
search_ulist_pid(int pid)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1;
- register userinfo_t **ulist;
+ int *ulist;
+ register userinfo_t *u;
if (end == -1)
return NULL;
ulist = SHM->sorted[SHM->currsorted][7];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = pid - ulist[i]->pid;
+ u = &SHM->uinfo[ulist[i]];
+ j = pid - u->pid;
if (!j) {
- return (userinfo_t *) (ulist[i]);
+ return u;
}
if (end == start) {
break;
@@ -344,19 +346,21 @@ userinfo_t *
search_ulistn(int uid, int unum)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1;
- register userinfo_t **ulist;
+ int *ulist;
+ register userinfo_t *u;
if (end == -1)
return NULL;
ulist = SHM->sorted[SHM->currsorted][6];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = uid - ulist[i]->uid;
+ u = &SHM->uinfo[ulist[i]];
+ j = uid - u->uid;
if (j == 0) {
- for (; i > 0 && uid == ulist[i - 1]->uid; --i)
+ for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; --i)
;/* 指到第一筆 */
if ( i + unum - 1 >= 0 &&
- (ulist[i + unum - 1] != NULL &&
- uid == ulist[i + unum - 1]->uid) )
- return (userinfo_t *) (ulist[i + unum - 1]);
+ (ulist[i + unum - 1] >= 0 &&
+ uid == SHM->uinfo[ulist[i + unum - 1]].uid ) )
+ return &SHM->uinfo[ulist[i + unum - 1]];
break; /* 超過範圍 */
}
if (end == start) {
@@ -376,14 +380,16 @@ userinfo_t *
search_ulist_userid(char *userid)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1;
- register userinfo_t **ulist;
+ int *ulist;
+ register userinfo_t * u;
if (end == -1)
return NULL;
ulist = SHM->sorted[SHM->currsorted][0];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = strcasecmp(userid, ulist[i]->userid);
+ u = &SHM->uinfo[ulist[i]];
+ j = strcasecmp(userid, u->userid);
if (!j) {
- return (userinfo_t *) (ulist[i]);
+ return u;
}
if (end == start) {
break;
@@ -403,20 +409,24 @@ int
count_logins(int uid, int show)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count;
- register userinfo_t **ulist;
+ int *ulist;
+ userinfo_t *u;
if (end == -1)
return 0;
ulist = SHM->sorted[SHM->currsorted][6];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = uid - ulist[i]->uid;
+ u = &SHM->uinfo[ulist[i]];
+ j = uid - u->uid;
if (!j) {
- for (; i > 0 && uid == ulist[i - 1]->uid; i--); /* 指到第一筆 */
+ for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; i--);
+ /* 指到第一筆 */
for (count = 0; (ulist[i + count] &&
- uid == ulist[i + count]->uid); count++) {
+ (u = &SHM->uinfo[ulist[i + count]]) &&
+ uid == u->uid); count++) {
if (show)
prints("(%d) 目前狀態為: %-17.16s(來自 %s)\n",
- count + 1, modestring(ulist[i + count], 0),
- ulist[i + count]->from);
+ count + 1, modestring(u, 0),
+ u->from);
}
return count;
}
@@ -488,16 +498,16 @@ void touchbtotal(int bid) {
static int
-cmpboardname(boardheader_t ** brd, boardheader_t ** tmp)
+cmpboardname(const void * i, const void * j)
{
- return strcasecmp((*brd)->brdname, (*tmp)->brdname);
+ return strcasecmp(bcache[*(int*)i].brdname, bcache[*(int*)j].brdname);
}
static int
-cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp)
+cmpboardclass(const void * i, const void * j)
{
- return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) +
- strcasecmp((*brd)->brdname, (*tmp)->brdname);
+ boardheader_t *brd1 = &bcache[*(int*)i], *brd2 = &bcache[*(int*)j];
+ return (strncmp(brd1->title, brd2->title, 4));
}
void
@@ -510,16 +520,17 @@ sort_bcache(void)
{ sleep(1); return; }
SHM->Bbusystate = 1;
for (i = 0; i < SHM->Bnumber; i++) {
- SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i];
+ SHM->bsorted[0][i] = i;
}
- qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *),
+ qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(int),
(QCAST) cmpboardname);
- qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *),
+ memcpy(SHM->bsorted[1], SHM->bsorted[0], sizeof(int)*SHM->Bnumber);
+ qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(int),
(QCAST) cmpboardclass);
for (i = 0; i < SHM->Bnumber; i++) {
- bcache[i].firstchild[0] = NULL;
- bcache[i].firstchild[1] = NULL;
+ bcache[i].firstchild[0] = 0;
+ bcache[i].firstchild[1] = 0;
}
SHM->Bbusystate = 0;
}
@@ -679,11 +690,10 @@ int
getbnum(const char *bname)
{
register int i = 0, j, start = 0, end = SHM->Bnumber - 1;
- register boardheader_t **bhdr;
- bhdr = SHM->bsorted[0];
+ int *blist = SHM->bsorted[0];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- if (!(j = strcasecmp(bname, bhdr[i]->brdname)))
- return (int)(bhdr[i] - bcache + 1);
+ if (!(j = strcasecmp(bname, bcache[blist[i]].brdname)))
+ return (int)(blist[i] + 1);
if (end == start) {
break;
} else if (i == start) {
diff --git a/mbbsd/name.c b/mbbsd/name.c
index 9253a843..0c9009e8 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -661,13 +661,14 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb,
int
completeboard_compar(int where, char *str, int len)
{
- return strncasecmp(SHM->bsorted[0][where]->brdname, str, len);
+ boardheader_t *bh = &bcache[SHM->bsorted[0][where]];
+ return strncasecmp(bh->brdname, str, len);
}
int
completeboard_permission(int where)
{
- boardheader_t *bptr = SHM->bsorted[0][where];
+ boardheader_t *bptr = &bcache[SHM->bsorted[0][where]];
return (!(bptr->brdattr & BRD_SYMBOLIC) &&
(GROUPOP() || HasPerm(bptr)) &&
!(bptr->brdattr & BRD_GROUPBOARD));
@@ -676,28 +677,29 @@ completeboard_permission(int where)
char *
completeboard_getname(int where)
{
- return SHM->bsorted[0][where]->brdname;
+ return bcache[SHM->bsorted[0][where]].brdname;
}
/* general complete functions (utmpshm) */
int
completeutmp_compar(int where, char *str, int len)
{
- return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid,
- str, len);
+ userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]];
+ return strncasecmp(u->userid, str, len);
}
int
completeutmp_permission(int where)
{
+ userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]];
return (unlikely(HAS_PERM(PERM_SYSOP)) ||
unlikely(HAS_PERM(PERM_SEECLOAK)) ||
// !SHM->sorted[SHM->currsorted][0][where]->invisible);
- isvisible(currutmp, SHM->sorted[SHM->currsorted][0][where]));
+ isvisible(currutmp, u));
}
char *
completeutmp_getname(int where)
{
- return SHM->sorted[SHM->currsorted][0][where]->userid;
+ return SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]].userid;
}
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index c8bb5d50..dd1fd3d5 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -243,7 +243,7 @@ void login_friend_online(void)
}
#endif
for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) {
- uentp = (SHM->sorted[SHM->currsorted][0][i]);
+ uentp = (&SHM->uinfo[SHM->sorted[SHM->currsorted][0][i]]);
if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) {
stat1 = reverse_friend_stat(stat);
stat <<= 24;
@@ -1785,7 +1785,7 @@ pickup_bfriend(pickup_t * friends, int base)
int currsorted = SHM->currsorted, number = SHM->UTMPnumber;
friends = friends + base;
for (i = 0; i < number && ngets < MAX_FRIEND - base; ++i) {
- uentp = SHM->sorted[currsorted][0][i];
+ uentp = &SHM->uinfo[SHM->sorted[currsorted][0][i]];
/* TODO isvisible() 重複用到了 friend_stat() */
if (uentp && uentp->pid && uentp->brc_id == currutmp->brc_id &&
currutmp != uentp && isvisible(currutmp, uentp) &&
@@ -1806,7 +1806,8 @@ pickup(pickup_t * currpickup, int pickup_way, int *page,
int utmpnumber = SHM->UTMPnumber;
int friendtotal = currutmp->friendtotal;
- userinfo_t **utmp;
+ int *ulist;
+ userinfo_t *u;
int which, sorted_way, size = 0, friend;
if (friendtotal == 0)
@@ -1850,17 +1851,18 @@ pickup(pickup_t * currpickup, int pickup_way, int *page,
if (!(cuser.uflag & FRIEND_FLAG) && size < nPickups) {
sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1));
- utmp = SHM->sorted[currsorted][sorted_way];
+ ulist = SHM->sorted[currsorted][sorted_way];
which = *page * nPickups - *nfriend;
if (which < 0)
which = 0;
for (; which < utmpnumber && size < nPickups; which++) {
- friend = friend_stat(currutmp, utmp[which]);
+ u = &SHM->uinfo[ulist[which]];
+ friend = friend_stat(currutmp, u);
/* TODO isvisible() 重複用到了 friend_stat() */
if ((pickup_way ||
- (currutmp != utmp[which] && !(friend & ST_FRIEND))) &&
- isvisible(currutmp, utmp[which])) {
- currpickup[size].ui = utmp[which];
+ (currutmp != u && !(friend & ST_FRIEND))) &&
+ isvisible(currutmp, u)) {
+ currpickup[size].ui = u;
currpickup[size++].friend = friend;
}
}
@@ -2267,12 +2269,11 @@ userlist(void)
if (si >= 0) {
pickup_t friends[MAX_FRIEND + 1];
int nGots, i;
- userinfo_t **utmp =
+ int *ulist =
SHM->sorted[SHM->currsorted]
[((pickup_way == 0) ? 0 : (pickup_way - 1))];
- fi = utmp[si] - &SHM->uinfo[0];
-
+ fi = ulist[si];
nGots = pickup_myfriend(friends, &myfriend,
&friendme, &badfriend);
for (i = 0; i < nGots; ++i)
@@ -2294,10 +2295,14 @@ userlist(void)
}
for( ; fi < nPickups && i < SHM->UTMPnumber ; ++i )
- if( isvisible(currutmp, utmp[i]) ){
- currpickup[fi].ui = utmp[i];
+ {
+ userinfo_t *u;
+ u = &SHM->uinfo[ulist[i]];
+ if( isvisible(currutmp, u) ){
+ currpickup[fi].ui = u;
currpickup[fi++].friend = 0;
}
+ }
skippickup = 1;
}
redrawall = redraw = 1;
@@ -2380,7 +2385,8 @@ userlist(void)
break;
}
for (i = 0; i < SHM->UTMPnumber; ++i) {
- uentp = SHM->sorted[SHM->currsorted][0][i];
+ uentp = &SHM->uinfo[
+ SHM->sorted[SHM->currsorted][0][i]];
if (uentp->pid && kill(uentp->pid, 0) != -1)
my_write(uentp->pid, genbuf,
uentp->userid, WATERBALL_PREEDIT, NULL);