diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-06-26 09:12:48 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-06-26 09:12:48 +0800 |
commit | 963fef9b70263e62d5e693b5609890a3cec7e31e (patch) | |
tree | 479f7dd02af60ea4afa858a8e98369129da5f48c /mbbsd | |
parent | 8c775648395ae91a9e5d81b6da3ca713085cc321 (diff) | |
download | pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.tar pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.tar.gz pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.tar.bz2 pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.tar.lz pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.tar.xz pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.tar.zst pttbbs-963fef9b70263e62d5e693b5609890a3cec7e31e.zip |
re-format, board friend
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@350 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/board.c | 68 | ||||
-rw-r--r-- | mbbsd/cache.c | 71 | ||||
-rw-r--r-- | mbbsd/talk.c | 107 |
3 files changed, 125 insertions, 121 deletions
diff --git a/mbbsd/board.c b/mbbsd/board.c index 1d19f36b..9b6130b7 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.36 2002/06/19 13:23:54 lwms Exp $ */ +/* $Id: board.c,v 1.37 2002/06/26 01:12:48 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -393,7 +393,7 @@ static boardstat_t * addnewbrdstat(int n, int state) return ptr; } -static int cmpboardname(const void *brd, const void *tmp) +static int cmpboardfriends(const void *brd, const void *tmp) { return ((boardstat_t *)tmp)->bh->nuser - ((boardstat_t *)brd)->bh->nuser; } @@ -411,40 +411,38 @@ static void load_boards(char *key) { load_uidofgid(class_bid,type); } brdnum = 0; - if(class_bid<=0) - { - nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); - for(i=0 ; i < numboards; i++) - { - if( (bptr = SHM->bsorted[type][i]) == NULL ) - continue; - n = (int)( bptr - bcache); - if(!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || - !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || - (yank_flag == 0 && !(favbuf[n]&BRD_FAV)) || - (yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key)) || - (class_bid==-1 && bptr->nuser<5) - ) continue; - addnewbrdstat(n, state); - if(class_bid==-1) - qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardname); + if(class_bid<=0){ + nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); + for(i=0 ; i < numboards; i++){ + if( (bptr = SHM->bsorted[type][i]) == NULL ) + continue; + n = (int)(bptr - bcache); + if( !bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || + (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || + (yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key)) || + (class_bid == -1 && bptr->nuser < 5) ) + continue; + addnewbrdstat(n, state); + + if( class_bid == -1 ) + qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } - } - else - { - nbrd = (boardstat_t *)malloc( bptr->childcount * sizeof(boardstat_t)); - for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; - bptr=bptr->next[type]) - { - n = (int)( bptr - bcache); - if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) - ||(yank_flag == 0 && !(favbuf[n]&BRD_FAV)) - ||(yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key))) continue; - addnewbrdstat(n, state); - } - } + } + else{ + nbrd = (boardstat_t *)malloc(bptr->childcount * sizeof(boardstat_t)); + for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; + bptr=bptr->next[type]) { + n = (int)( bptr - bcache); + if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) + ||(yank_flag == 0 && !(favbuf[n] & BRD_FAV)) + ||(yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key))) + continue; + addnewbrdstat(n, state); + } + } } static int search_board() { diff --git a/mbbsd/cache.c b/mbbsd/cache.c index d73dc0f1..1f67f7e0 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.36 2002/06/19 13:25:05 lwms Exp $ */ +/* $Id: cache.c,v 1.37 2002/06/26 01:12:48 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -330,12 +330,14 @@ static int cmputmpfive(const void *i, const void *j){ return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; } +#if 0 static int cmputmpsex(const void *i, const void *j) { static int ladyfirst[]={1,0,1,0,1,0,3,3}; return ladyfirst[(*(userinfo_t**)i)->sex&07]- ladyfirst[(*(userinfo_t**)j)->sex&07]; } +#endif static int cmputmppid(const void *i, const void *j){ return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; } @@ -344,9 +346,10 @@ static int cmputmpuid(const void *i, const void *j){ } void sort_utmp() { - int count, i, ns; - userinfo_t *uentp; - now=time(0); + userinfo_t *uentp; + int count, i, ns; + short nusers[MAX_BOARD]; + now = time(0); if( now - SHM->UTMPuptime < 60 && (now == SHM->UTMPuptime || SHM->UTMPbusystate) ) return; /* lazy sort */ @@ -357,41 +360,45 @@ void sort_utmp() for( uentp = &SHM->uinfo[0], count = i = 0 ; i < USHM_SIZE ; ++i, uentp = &SHM->uinfo[i] ){ - if(uentp->pid) { - if(uentp->sex<0 || uentp->sex>7) - memset(uentp, 0, sizeof(userinfo_t)); + if( uentp->pid ){ + if( uentp->sex < 0 || uentp->sex > 7 ) + purge_utmp(uentp); else - SHM->sorted[ns][0][count++]= uentp; + SHM->sorted[ns][0][count++] = uentp; } } SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); - for(i=0; i<count; i++) - ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset=i; - memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); - qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); - qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); + qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t*), cmputmpuserid); + for( i = 0 ; i < count ; ++i ) + ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset = i; + memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); + //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex); + qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); + qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); SHM->currsorted=ns; SHM->UTMPbusystate=0; + + memset(nusers, 0, sizeof(nusers)); + for( i = 0 ; i < count ; ++i ){ + uentp = SHM->sorted[ns][0][i]; + if( uentp && uentp->pid && + 0 <= uentp->brc_id && uentp->brc_id < MAX_BOARD ) + ++nusers[ uentp->brc_id - 1 ]; + } + for( i = 0 ; i < MAX_BOARD ; ++i ) + SHM->bcache[i].nuser = nusers[i]; } + // Ptt:這邊加入hash觀念 找空的utmp void getnewutmpent(userinfo_t *up) { register int i, p ; diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 51b318e5..7ff04cb4 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.70 2002/06/07 17:19:47 ptt Exp $ */ +/* $Id: talk.c,v 1.71 2002/06/26 01:12:48 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1504,15 +1504,17 @@ static int pickup_myfriend(pickup_t *friends, static int pickup_bfriend(pickup_t *friends, int base) { - userinfo_t *ptr; - int ngets=0; + userinfo_t *uentp; + int i, ngets = 0; + int currsorted = SHM->currsorted, + number = SHM->UTMPnumber; friends = friends + base; - for( ptr = bcache[currutmp->brc_id - 1].u; - ptr != NULL && ngets < MAX_FRIEND-base ; - ptr = ptr->nextbfriend ){ - if( currutmp != ptr && isvisible(currutmp, ptr) && - (base || !(friend_stat(currutmp,ptr)&(IFH|HFM))) ){ - friends[ngets].ui = ptr; + for( i = 0 ; i < number && ngets < MAX_FRIEND - base ; ++i ){ + uentp = SHM->sorted[currsorted][0][i]; + if( uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && + currutmp != uentp && isvisible(currutmp, uentp) && + (base || !(friend_stat(currutmp, uentp) & (IFH | HFM))) ){ + friends[ngets].ui = uentp; friends[ngets++].friend = IBH; } } @@ -1534,66 +1536,63 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, *myfriend = *friendme = 1; if( cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ) - { + (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ){ /* [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp friend_online), sort, and get pickup from right starting position */ pickup_t friends[MAX_FRIEND]; - + *nfriend = pickup_myfriend(friends, myfriend, friendme); - if( pickup_way == 0 ) - *bfriend=pickup_bfriend(friends,*nfriend); + if( pickup_way == 0 && currutmp->brc_id != 0 ) + *bfriend = pickup_bfriend(friends,*nfriend); else - *bfriend=0; + *bfriend=0; *nfriend += *bfriend; - which = *page * MAXPICKUP; - if(*nfriend>which) // Ptt: 只有在要秀出才有必要 sort - { - qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); - size=*nfriend-which; - if(size>MAXPICKUP) size= MAXPICKUP; - memcpy(currpickup, friends+which, sizeof(pickup_t)*size); - } + which = *page * MAXPICKUP; + if( *nfriend > which ){ // Ptt: 只有在要秀出才有必要 sort + qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); + size = *nfriend - which; + if( size > MAXPICKUP ) + size = MAXPICKUP; + memcpy(currpickup, friends + which, sizeof(pickup_t) * size); + } } else - *nfriend=0; + *nfriend=0; - if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ) - { + if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ){ sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = SHM->sorted[currsorted][sorted_way]; which = *page * MAXPICKUP-*nfriend; - if(which<0) which=0; - for(;which < utmpnumber && size < MAXPICKUP;which++) - { - friend = friend_stat(currutmp,utmp[which]); - if((pickup_way||(currutmp != utmp[which] && - !(friend&ST_FRIEND))) && - isvisible_stat(currutmp, utmp[which], 0)) - { - currpickup[size].ui = utmp[which]; - currpickup[size++].friend = friend; - } - } - } -/* - for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < utmpnumber ; - ++got, ++which ){ - - for( ; which < utmpnumber ; ++which ) - if( currutmp != utmp[which] && - isvisible_stat(currutmp, utmp[which], 0) ) - break; - if( which == utmpnumber ) - break; - currpickup[got].ui = utmp[which]; - currpickup[got].friend = 0; + if( which < 0 ) + which = 0; + for( ; which < utmpnumber && size < MAXPICKUP ; which++ ){ + friend = friend_stat(currutmp, utmp[which]); + if( ( pickup_way || + (currutmp != utmp[which] && !(friend & ST_FRIEND))) && + isvisible_stat(currutmp, utmp[which], 0)){ + currpickup[size].ui = utmp[which]; + currpickup[size++].friend = friend; + } } -*/ - + } + /* + for( which = (which >= 0 ? which : 0) ; + got < MAXPICKUP && which < utmpnumber ; + ++got, ++which ){ + + for( ; which < utmpnumber ; ++which ) + if( currutmp != utmp[which] && + isvisible_stat(currutmp, utmp[which], 0) ) + break; + if( which == utmpnumber ) + break; + currpickup[got].ui = utmp[which]; + currpickup[got].friend = 0; + } + */ + for( ; size < MAXPICKUP ; ++size ) currpickup[size].ui = 0; } |