diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-06-07 05:35:23 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-06-07 05:35:23 +0800 |
commit | e8fc08b9800ba86163e5bf43469cdc9f4b478b13 (patch) | |
tree | eb2dcd75cad19ac57b7e9d9cc29c63a850d8ad86 /mbbsd | |
parent | c0a6419aeceaeb93d5d9ccde393236d67ff8c72f (diff) | |
download | pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.gz pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.bz2 pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.lz pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.xz pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.tar.zst pttbbs-e8fc08b9800ba86163e5bf43469cdc9f4b478b13.zip |
only one shared memory
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@296 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/admin.c | 10 | ||||
-rw-r--r-- | mbbsd/announce.c | 4 | ||||
-rw-r--r-- | mbbsd/bbs.c | 6 | ||||
-rw-r--r-- | mbbsd/board.c | 70 | ||||
-rw-r--r-- | mbbsd/cache.c | 379 | ||||
-rw-r--r-- | mbbsd/cal.c | 4 | ||||
-rw-r--r-- | mbbsd/chicken.c | 4 | ||||
-rw-r--r-- | mbbsd/kaede.c | 4 | ||||
-rw-r--r-- | mbbsd/mail.c | 12 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 19 | ||||
-rw-r--r-- | mbbsd/menu.c | 19 | ||||
-rw-r--r-- | mbbsd/name.c | 14 | ||||
-rw-r--r-- | mbbsd/talk.c | 63 | ||||
-rw-r--r-- | mbbsd/user.c | 4 | ||||
-rw-r--r-- | mbbsd/var.c | 9 |
15 files changed, 301 insertions, 320 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 9d795f90..48e21777 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.20 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: admin.c,v 1.21 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -368,7 +368,7 @@ int m_board() { char bname[32]; stand_title("看板設定"); - generalnamecomplete(msg_bid, bname, sizeof(bname), brdshm->number, + generalnamecomplete(msg_bid, bname, sizeof(bname), SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); @@ -1053,10 +1053,10 @@ int give_money() { stand_title("發錢中..."); if(to_all) { int i, unum; - for(unum = uhash->number, i=0; i<unum; i++) { - if(bad_user_id(uhash->userid[i])) + for(unum = SHM->number, i=0; i<unum; i++) { + if(bad_user_id(SHM->userid[i])) continue; - id = uhash->userid[i]; + id = SHM->userid[i]; give_id_money(id, money, fp2, tt, now); } // something wrong @_@ diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 3afdbac2..d7fe9cde 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.10 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: announce.c,v 1.11 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static void g_showmenu(gmenu_t *pm) { @@ -472,7 +472,7 @@ static int AnnounceSelect() { clrtoeol(); move(1, 0); generalnamecomplete("選擇精華區看板:", buf, sizeof(buf), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 4b401280..6b08d1db 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.48 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: bbs.c,v 1.49 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -245,7 +245,7 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { move(0, 0); clrtoeol(); generalnamecomplete(MSG_SELECT_BOARD, bname, sizeof(bname), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); @@ -727,7 +727,7 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { if (bp && (bp->brdattr & BRD_VOTEBOARD)) return FULLUPDATE; generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); diff --git a/mbbsd/board.c b/mbbsd/board.c index 15cdee5b..ad19d881 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.34 2002/06/05 03:10:43 ptt Exp $ */ +/* $Id: board.c,v 1.35 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -354,23 +354,21 @@ static void load_uidofgid(const int gid, const int type){ boardheader_t *bptr,*currbptr; int n, childcount=0; currbptr = &bcache[gid-1]; - for(n=0;n<numboards;n++) - { - bptr = brdshm->sorted[type][n]; - if(bptr->brdname[0]=='\0') continue; - if(bptr->gid == gid) - { - if(currbptr == &bcache[gid-1]) - currbptr->firstchild[type]=bptr; - else - { - currbptr->next[type]=bptr; - currbptr->parent=&bcache[gid-1]; + for( n = 0 ; n < numboards ; ++n ){ + bptr = SHM->bsorted[type][n]; + if( bptr->brdname[0] == '\0' ) + continue; + if( bptr->gid == gid ){ + if(currbptr == &bcache[gid-1]) + currbptr->firstchild[type]=bptr; + else{ + currbptr->next[type]=bptr; + currbptr->parent=&bcache[gid-1]; } - childcount++; - currbptr=bptr; - } - } + childcount++; + currbptr=bptr; + } + } bcache[gid-1].childcount=childcount; if(currbptr == &bcache[gid-1]) currbptr->firstchild[type]=(boardheader_t *) ~0; @@ -381,8 +379,8 @@ static boardstat_t * addnewbrdstat(int n, int state) { boardstat_t *ptr=&nbrd[brdnum++]; boardheader_t *bptr = &bcache[n]; - ptr->total = &(brdshm->total[n]); - ptr->lastposttime = &(brdshm->lastposttime[n]); + ptr->total = &(SHM->total[n]); + ptr->lastposttime = &(SHM->lastposttime[n]); ptr->bid = n+1; ptr->myattr=0; ptr->myattr=(favbuf[n]&~BRD_ZAP); @@ -418,7 +416,7 @@ static void load_boards(char *key) { nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); for(i=0 ; i < numboards; i++) { - if( (bptr = brdshm->sorted[type][i]) == NULL ) + if( (bptr = SHM->bsorted[type][i]) == NULL ) continue; n = (int)( bptr - bcache); if(!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || @@ -656,21 +654,23 @@ static void dozap(int num){ void delutmpbid(int bid, userinfo_t *utmp) { userinfo_t *u; - while (brdshm->busystate || now-brdshm->busystate_b[bid-1]<5) - sleep(1); - // Ptt:有問題都是這邊沒有執行到就爛掉了 - - brdshm->busystate_b[bid-1]=now; - u=bcache[bid-1].u; - if(u!=(void*)utmp) - { - for(;u && u->nextbfriend != (void*)utmp; u=u->nextbfriend); - if(u) u->nextbfriend = utmp->nextbfriend; - } - else - bcache[bid-1].u=utmp->nextbfriend; - if(bcache[bid-1].nuser>0) bcache[bid-1].nuser--; - brdshm->busystate_b[bid-1]=0; + while( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 5 ) + sleep(1); + // Ptt:有問題都是這邊沒有執行到就爛掉了 + + SHM->busystate_b[bid-1] = now; + u = bcache[bid - 1].u; + if( u != (void *)utmp ){ + for( ; u && u->nextbfriend != (void*)utmp; u = u->nextbfriend ) + ; + if( u ) + u->nextbfriend = utmp->nextbfriend; + } + else + bcache[bid - 1].u = utmp->nextbfriend; + if( bcache[bid - 1].nuser > 0 ) + bcache[bid - 1].nuser--; + SHM->busystate_b[bid - 1] = 0; } void setutmpbid(int bid) diff --git a/mbbsd/cache.c b/mbbsd/cache.c index ab87c3a0..d2c47fe7 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.31 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: cache.c,v 1.32 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -9,7 +9,6 @@ union semun { struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -int fcache_semid; /* the reason for "safe_sleep" is that we may call sleep during SIGALRM handler routine, while SIGALRM is blocked. @@ -53,7 +52,7 @@ static void attach_err(int shmkey, char *name) { exit(1); } -static void *attach_shm(int shmkey, int shmsize) { +void *attach_shm(int shmkey, int shmsize) { void *shmptr; int shmid; @@ -130,74 +129,86 @@ void sem_lock(int op,int semid) { */ /* attach_uhash should be called before using uhash */ -void attach_uhash() { - uhash = attach_shm(UHASH_KEY, sizeof(*uhash)); - if(!uhash->loaded) /* assume fresh shared memory is zeroed */ + +void attach_SHM(void) +{ + SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); + if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ exit(1); + if( SHM->Btouchtime == 0 ) + SHM->Btouchtime = 1; + bcache = SHM->bcache; + + GLOBALVAR = SHM->GLOBALVAR; + if( SHM->Ptouchtime == 0 ) + SHM->Ptouchtime = 1; + + if( SHM->Ftouchtime == 0 ) + SHM->Ftouchtime = 1; } void add_to_uhash(int n, char *id) { int *p, h = StringHash(id); int times; - strcpy(uhash->userid[n], id); + strcpy(SHM->userid[n], id); - p = &(uhash->hash_head[h]); + p = &(SHM->hash_head[h]); for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times ) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); if( times == MAX_USERS ) abort_bbs(0); - uhash->next_in_hash[*p = n] = -1; + SHM->next_in_hash[*p = n] = -1; } /* note: after remove_from_uhash(), you should add_to_uhash() (likely with a different name) */ void remove_from_uhash(int n) { - int h = StringHash(uhash->userid[n]); - int *p = &(uhash->hash_head[h]); + int h = StringHash(SHM->userid[n]); + int *p = &(SHM->hash_head[h]); int times; for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times ) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); if( times == MAX_USERS ) abort_bbs(0); if(*p == n) - *p = uhash->next_in_hash[n]; + *p = SHM->next_in_hash[n]; } int setumoney(int uid, int money) { - uhash->money[uid-1]=money; + SHM->money[uid-1]=money; passwd_update_money(uid); - return uhash->money[uid-1]; + return SHM->money[uid-1]; } int deumoney(int uid, int money) { - if(money<0 && uhash->money[uid-1]<-money) + if(money<0 && SHM->money[uid-1]<-money) return setumoney(uid,0); else - return setumoney(uid,uhash->money[uid-1]+money); + return setumoney(uid,SHM->money[uid-1]+money); } int demoney(int money) { return deumoney(usernum,money); } int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return uhash->money[uid-1]; + return SHM->money[uid-1]; } int searchuser(char *userid) { int h, p, times; h = StringHash(userid); - p = uhash->hash_head[h]; + p = SHM->hash_head[h]; for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){ - if(strcasecmp(uhash->userid[p],userid) == 0) { - strcpy(userid,uhash->userid[p]); + if(strcasecmp(SHM->userid[p],userid) == 0) { + strcpy(userid,SHM->userid[p]); return p + 1; } - p = uhash->next_in_hash[p]; + p = SHM->next_in_hash[p]; } return 0; @@ -215,14 +226,14 @@ int getuser(char *userid) { char *getuserid(int num) { if(--num >= 0 && num < MAX_USERS) - return ((char *) uhash->userid[num]); + return ((char *) SHM->userid[num]); return NULL; } void setuserid(int num, char *userid) { if(num > 0 && num <= MAX_USERS) { - if(num > uhash->number) - uhash->number = num; + if(num > SHM->number) + SHM->number = num; else remove_from_uhash(num-1); add_to_uhash(num-1,userid); @@ -235,12 +246,12 @@ void setuserid(int num, char *userid) { int searchnewuser(int mode) { register int i, num; - num = uhash->number; + num = SHM->number; i = 0; /* 為什麼這邊不用 hash table 去找而要用 linear search? */ while(i < num) { - if(!uhash->userid[i++][0]) + if(!SHM->userid[i++][0]) return i; } if(mode && (num < MAX_USERS)) @@ -249,24 +260,23 @@ int searchnewuser(int mode) { } char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { - register struct uhash_t *reg_ushm = uhash; register char *ptr, tmp; register int n, total; char tagbuf[STRLEN]; int ch, ch2, num; if(*tag == '\0') { - *pnum = reg_ushm->number; - return reg_ushm->userid[0]; + *pnum = SHM->number; + return SHM->userid[0]; } for(n = 0; tag[n]; n++) tagbuf[n] = chartoupper(tag[n]); tagbuf[n] = '\0'; ch = tagbuf[0]; ch2 = ch - 'A' + 'a'; - total = reg_ushm->number; + total = SHM->number; for(n = num = 0; n < total; n++) { - ptr = reg_ushm->userid[n]; + ptr = SHM->userid[n]; tmp = *ptr; if(tmp == ch || tmp == ch2) { if(chkstr(tag, tagbuf, ptr)) @@ -281,12 +291,6 @@ char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { /*-------------------------------------------------------*/ /* .UTMP cache */ /*-------------------------------------------------------*/ -void resolve_utmp() { - if(utmpshm == NULL) { - utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm)); - } -} - #if !defined(_BBS_UTIL_C_) void setutmpmode(int mode) { if(currstat != mode) @@ -343,50 +347,50 @@ void sort_utmp() int count, i, ns; userinfo_t *uentp; now=time(0); - if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)) - return; /* lazy sort */ - utmpshm->busystate=1; - utmpshm->uptime = now; - ns=(utmpshm->currsorted?0:1); - - for(uentp = &utmpshm->uinfo[0], count=0, i=0; - i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i]) - { - if(uentp->pid) - { - if(uentp->sex<0 || uentp->sex>7) - memset(uentp, 0, sizeof(userinfo_t)); - else - utmpshm->sorted[ns][0][count++]= uentp; + if( now - SHM->UTMPuptime < 60 && + (now == SHM->UTMPuptime || SHM->UTMPbusystate) ) + return; /* lazy sort */ + SHM->UTMPbusystate=1; + SHM->UTMPuptime = now; + ns = (SHM->currsorted ? 0 : 1); + + 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)); + else + SHM->sorted[ns][0][count++]= uentp; } - } - utmpshm->number = count; - qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); + } + SHM->UTMPnumber = count; + qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); for(i=0; i<count; i++) - ((userinfo_t*)utmpshm->sorted[ns][0][i])->idoffset=i; - memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], + ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset=i; + memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); - qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); - qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); - qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); - qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); - qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); - utmpshm->currsorted=ns; - utmpshm->busystate=0; + 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; } // Ptt:這邊加入hash觀念 找空的utmp void getnewutmpent(userinfo_t *up) { @@ -394,7 +398,7 @@ void getnewutmpent(userinfo_t *up) { register userinfo_t *uentp; for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) { if(p==USHM_SIZE) p=0; - uentp = &(utmpshm->uinfo[p]); + uentp = &(SHM->uinfo[p]); if(!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; @@ -410,7 +414,7 @@ int apply_ulist(int (*fptr)(userinfo_t *)) { register int i, state; for(i = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) if((state = (*fptr) (uentp))) return state; @@ -424,11 +428,11 @@ userinfo_t *search_ulist(int uid) { #if !defined(_BBS_UTIL_C_) userinfo_t *search_ulist_pid(int pid) { - register int i=0, j, start = 0, end = utmpshm->number - 1; + register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; if( end == -1 ) return NULL; - ulist=utmpshm->sorted[utmpshm->currsorted][7]; + ulist=SHM->sorted[SHM->currsorted][7]; for(i=((start+end)/2); ;i=(start+end)/2) { j=pid-ulist[i]->pid; @@ -451,11 +455,11 @@ userinfo_t *search_ulist_pid(int pid) { return 0; } userinfo_t *search_ulistn(int uid, int unum) { - register int i=0, j, start = 0, end = utmpshm->number - 1; + register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; if( end == -1 ) return NULL; - ulist=utmpshm->sorted[utmpshm->currsorted][6]; + ulist=SHM->sorted[SHM->currsorted][6]; for(i=((start+end)/2); ;i=(start+end)/2) { j= uid - ulist[i]->uid; @@ -482,11 +486,11 @@ userinfo_t *search_ulistn(int uid, int unum) { } int count_logins(int uid, int show) { - register int i=0, j, start = 0, end = utmpshm->number - 1, count; + register int i=0, j, start = 0, end = SHM->UTMPnumber - 1, count; register userinfo_t **ulist; if( end == -1 ) return NULL; - ulist=utmpshm->sorted[utmpshm->currsorted][6]; + ulist=SHM->sorted[SHM->currsorted][6]; for(i=((start+end)/2); ;i=(start+end)/2) { j = uid-ulist[i]->uid; @@ -530,7 +534,7 @@ void purge_utmp(userinfo_t *uentp) { /*-------------------------------------------------------*/ void touchdircache(int bid) { - int *i= (int *)&brdshm->dircache[bid - 1][0].filename[0]; + int *i= (int *)&SHM->dircache[bid - 1][0].filename[0]; *i=0; } @@ -538,15 +542,15 @@ void load_fileheader_cache(int bid, char *direct) { int num=getbtotal(bid); int n = num-DIRCACHESIZE+1; - if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10 ) - { - brdshm->busystate_b[bid-1] = now; - get_records(direct, brdshm->dircache[bid - 1] , - sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); - brdshm->busystate_b[bid-1] = 0; - } - else - {safe_sleep(1);} + if( SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10 ){ + SHM->busystate_b[bid-1] = now; + get_records(direct, SHM->dircache[bid - 1] , + sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); + SHM->busystate_b[bid-1] = 0; + } + else{ + safe_sleep(1); + } } int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, @@ -560,7 +564,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, n = (num - DIRCACHESIZE+1); - if(brdshm->dircache[bid - 1][0].filename[0]=='\0') + if(SHM->dircache[bid - 1][0].filename[0]=='\0') load_fileheader_cache(bid, direct); if (n<1) n=recbase-1; @@ -568,7 +572,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, n=recbase-n; if(n<0) n=0; if (ret>nlines) ret=nlines; - memcpy(headers, &(brdshm->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); + memcpy(headers, &(SHM->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); return ret; } static int cmpboardname(boardheader_t **brd, boardheader_t **tmp) { @@ -578,72 +582,66 @@ static int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static void sort_bcache(){ - int i;/*critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ - for(i=0;i<brdshm->number;i++) - { - brdshm->sorted[1][i]=brdshm->sorted[0][i]=&bcache[i]; - } - qsort(brdshm->sorted[0], brdshm->number, sizeof(boardheader_t *), +static void sort_bcache() +{ + int i; + /*critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ + for(i=0;i<SHM->Bnumber;i++){ + SHM->bsorted[1][i]=SHM->bsorted[0][i]=&bcache[i]; + } + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), (QCAST)cmpboardname); - qsort(brdshm->sorted[1], brdshm->number, sizeof(boardheader_t *), + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST)cmpboardclass); } static void reload_bcache() { - if(brdshm->busystate) { + if( SHM->Bbusystate ){ safe_sleep(1); } #if !defined(_BBS_UTIL_C_) else { int fd,i; - brdshm->busystate = 1; + SHM->Bbusystate = 1; if((fd = open(fn_board, O_RDONLY)) > 0) { - brdshm->number = + SHM->Bnumber = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / sizeof(boardheader_t); close(fd); } - memset(brdshm->lastposttime, 0, MAX_BOARD * sizeof(time_t)); + memset(SHM->lastposttime, 0, MAX_BOARD * sizeof(time_t)); /* 等所有 boards 資料更新後再設定 uptime */ - brdshm->uptime = brdshm->touchtime; + SHM->Buptime = SHM->Btouchtime; log_usies("CACHE", "reload bcache"); sort_bcache(); - for(i=0;i<brdshm->number;i++) - { - bcache[i].u=NULL; - bcache[i].nuser=0; - bcache[i].firstchild[0]=NULL; - bcache[i].firstchild[1]=NULL; - } - brdshm->busystate = 0; + for( i = 0 ; i < SHM->Bnumber ; ++i ){ + bcache[i].u=NULL; + bcache[i].nuser=0; + bcache[i].firstchild[0]=NULL; + bcache[i].firstchild[1]=NULL; + } + SHM->Bbusystate = 0; } #endif } void resolve_boards() { - if(brdshm == NULL) { - brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); - if(brdshm->touchtime == 0) - brdshm->touchtime = 1; - bcache = brdshm->bcache; + while( SHM->Buptime < SHM->Btouchtime ){ + reload_bcache(); } - - while(brdshm->uptime < brdshm->touchtime) - {reload_bcache();} - numboards = brdshm->number; + numboards = SHM->Bnumber; } void touch_boards() { - brdshm->touchtime=now; + SHM->Btouchtime=now; numboards = -1; resolve_boards(); } void addbrd_touchcache() { - brdshm->number++; - numboards=brdshm->number; - reset_board(numboards); + SHM->Bnumber++; + numboards=SHM->Bnumber; + reset_board(numboards); } #if !defined(_BBS_UTIL_C_) void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ @@ -654,10 +652,10 @@ void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ if(--bid < 0) return; - if(brdshm->busystate || now-brdshm->busystate_b[bid-1]<10 ) { + if( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10 ){ safe_sleep(1); } else { - brdshm->busystate_b[bid-1] = now; + SHM->busystate_b[bid-1] = now; nuser = bcache[bid-1].nuser; u = bcache[bid-1].u; @@ -669,14 +667,14 @@ void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ close(fd); } sort_bcache(); - for(i=0;i<brdshm->number;i++) + for(i=0;i<SHM->Bnumber;i++) { bcache[i].firstchild[0]=NULL; bcache[i].firstchild[1]=NULL; } nuser = bcache[bid-1].nuser; u = bcache[bid-1].u; - brdshm->busystate_b[bid-1] = 0; + SHM->busystate_b[bid-1] = 0; } } @@ -698,7 +696,7 @@ boardheader_t *getbcache(int bid) { /* Ptt改寫 */ } int getbtotal(int bid) { - return brdshm->total[bid - 1]; + return SHM->total[bid - 1]; } void setbtotal(int bid) { boardheader_t *bh = getbcache(bid); @@ -712,34 +710,35 @@ void setbtotal(int bid) { return; /* .DIR掛了 */ fstat(fd, &st); num = st.st_size / sizeof(fileheader_t); - brdshm->total[bid - 1] = num; + SHM->total[bid - 1] = num; if(num>0) { lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); if(read(fd, genbuf, FNLEN)>=0) { - brdshm->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); + SHM->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); } } else - brdshm->lastposttime[bid - 1] = 0; + SHM->lastposttime[bid - 1] = 0; close(fd); if(num) touchdircache(bid); } -void -touchbpostnum(int bid, int delta) { - int *total = &brdshm->total[bid - 1]; - if (*total) *total += delta; +void touchbpostnum(int bid, int delta) +{ + int *total = &SHM->total[bid - 1]; + if (*total) + *total += delta; } int getbnum(char *bname) { - register int i=0, j, start = 0, end = brdshm->number - 1; + register int i=0, j, start = 0, end = SHM->Bnumber - 1; register boardheader_t **bhdr; - bhdr=brdshm->sorted[0]; + bhdr=SHM->bsorted[0]; for(i=((start+end)/2); ;i=(start+end)/2) { if(! (j=strcasecmp(bname,bhdr[i]->brdname))) @@ -799,11 +798,9 @@ int haspostperm(char *bname) { /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor 動態看版 */ -struct pttcache_t *ptt; - static void reload_pttcache() { - if(ptt->busystate) + if( SHM->Pbusystate ) safe_sleep(1); else { /* jochang: temporary workaround */ fileheader_t item, subitem; @@ -811,9 +808,9 @@ static void reload_pttcache() FILE *fp, *fp1, *fp2; int id, section = 0; - ptt->busystate = 1; - ptt->max_film = 0; - bzero(ptt->notes, sizeof ptt->notes); + SHM->Pbusystate = 1; + SHM->max_film = 0; + bzero(SHM->notes, sizeof(SHM->notes)); setapath(pbuf, "Note"); setadir(buf, pbuf); id = 0; @@ -824,15 +821,15 @@ static void reload_pttcache() setadir(buf, buf); if(!(fp1 = fopen(buf, "r"))) continue; - ptt->next_refresh[section] = ptt->n_notes[section] = id; + SHM->next_refresh[section] = SHM->n_notes[section] = id; section ++; while(fread(&subitem, sizeof(subitem), 1, fp1)) { sprintf(buf,"%s/%s/%s", pbuf, item.filename , subitem.filename); if(!(fp2=fopen(buf,"r"))) continue; - fread(ptt->notes[id],sizeof(char), 200*11, fp2); - ptt->notes[id][200*11 - 1]=0; + fread(SHM->notes[id],sizeof(char), 200*11, fp2); + SHM->notes[id][200*11 - 1]=0; id++; fclose(fp2); if(id >= MAX_MOVIE) @@ -845,50 +842,44 @@ static void reload_pttcache() } fclose(fp); } - ptt->next_refresh[section] = -1; - ptt->n_notes[section] = ptt->max_film = id-1; - ptt->max_history = ptt->max_film - 2; - if(ptt->max_history > MAX_HISTORY - 1) - ptt->max_history = MAX_HISTORY - 1; - if(ptt->max_history <0) ptt->max_history=0; + SHM->next_refresh[section] = -1; + SHM->n_notes[section] = SHM->max_film = id-1; + SHM->max_history = SHM->max_film - 2; + if(SHM->max_history > MAX_HISTORY - 1) + SHM->max_history = MAX_HISTORY - 1; + if(SHM->max_history <0) SHM->max_history=0; fp = fopen("etc/today_is","r"); if(fp) { - fgets(ptt->today_is,15,fp); - if((chr = strchr(ptt->today_is,'\n'))) + fgets(SHM->today_is,15,fp); + if((chr = strchr(SHM->today_is,'\n'))) *chr = 0; - ptt->today_is[15] = 0; + SHM->today_is[15] = 0; fclose(fp); } /* 等所有資料更新後再設定 uptime */ - ptt->uptime = ptt->touchtime ; + SHM->Puptime = SHM->Ptouchtime ; #if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload pttcache"); #endif - ptt->busystate = 0; + SHM->Pbusystate = 0; } } void resolve_garbage() { int count=0; - if(ptt == NULL) { - ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); - GLOBALVAR = ptt->GLOBALVAR; - if(ptt->touchtime == 0) - ptt->touchtime = 1; - } - while(ptt->uptime < ptt->touchtime) { /* 不用while等 */ + while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ reload_pttcache(); - if(count ++ > 10 && ptt->busystate) { + if(count ++ > 10 && SHM->Pbusystate) { /* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 這樣會所有prcosee都會在load 動態看板 會造成load大增 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 解開 同樣的問題發生在reload passwd */ - ptt->busystate = 0; + SHM->Pbusystate = 0; #ifndef _BBS_UTIL_C_ log_usies("CACHE", "refork Ptt dead lock"); #endif @@ -901,52 +892,48 @@ void resolve_garbage() { /*-------------------------------------------------------*/ /* cachefor from host 與最多上線人數 */ static void reload_fcache() { - if(fcache->busystate) + if( SHM->Fbusystate ) safe_sleep(1); else { FILE *fp; - fcache->busystate = 1; - bzero(fcache->domain, sizeof fcache->domain); + SHM->Fbusystate = 1; + bzero(SHM->domain, sizeof(SHM->domain)); if((fp = fopen("etc/domain_name_query","r"))) { char buf[256],*po; - fcache->top=0; + SHM->top=0; while(fgets(buf, sizeof(buf),fp)) { if(buf[0] && buf[0] != '#' && buf[0] != ' ' && buf[0] != '\n') { - sscanf(buf,"%s",fcache->domain[fcache->top]); - po = buf + strlen(fcache->domain[fcache->top]); + sscanf(buf,"%s",SHM->domain[SHM->top]); + po = buf + strlen(SHM->domain[SHM->top]); while(*po == ' ') po++; - strncpy(fcache->replace[fcache->top],po,49); - fcache->replace[fcache->top] - [strlen(fcache->replace[fcache->top])-1] = 0; - (fcache->top)++; - if(fcache->top == MAX_FROM) + strncpy(SHM->replace[SHM->top],po,49); + SHM->replace[SHM->top] + [strlen(SHM->replace[SHM->top])-1] = 0; + (SHM->top)++; + if(SHM->top == MAX_FROM) break; } } } - fcache->max_user=0; + SHM->max_user=0; /* 等所有資料更新後再設定 uptime */ - fcache->uptime = fcache->touchtime; + SHM->Fuptime = SHM->Ftouchtime; #if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload fcache"); #endif - fcache->busystate = 0; + SHM->Fbusystate = 0; } } -void resolve_fcache() { - if(fcache == NULL) { - fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache)); - if(fcache->touchtime == 0) - fcache->touchtime = 1; - } - while(fcache->uptime < fcache->touchtime) +void resolve_fcache() +{ + while( SHM->Fuptime < SHM->Ftouchtime ) reload_fcache(); } @@ -977,17 +964,17 @@ void hbflreload(int bid) fclose(fp); } hbfl[0] = now; - memcpy(brdshm->hbfl[bid], hbfl, sizeof(hbfl)); + memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); } int hbflcheck(int bid, int uid) { int i; - if( brdshm->hbfl[bid][0] < login_start_time - HBFLexpire ) + if( SHM->hbfl[bid][0] < login_start_time - HBFLexpire ) hbflreload(bid); - for( i = 1 ; brdshm->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ - if( brdshm->hbfl[bid][i] == uid ) + for( i = 1 ; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ + if( SHM->hbfl[bid][i] == uid ) return 0; } return 1; diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 3b41d279..dbb90c71 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.13 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: cal.c,v 1.14 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -7,7 +7,7 @@ static int count_multiplay(int unmode) { register userinfo_t *uentp; for(i = j = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(uentp->uid == usernum) if(uentp->lockmode == unmode) j++; diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index 9c30deec..0b1c9320 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chicken.c,v 1.5 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -828,7 +828,7 @@ int chickenpk(int fd) { char mateid[IDLEN + 1], data[200], buf[200]; int ch = 0; - userinfo_t *uin = &utmpshm->uinfo[currutmp->destuip]; + userinfo_t *uin = &SHM->uinfo[currutmp->destuip]; userec_t ouser; chicken_t *ochicken = &ouser.mychicken; int r, attmax, i, datac, duid = currutmp->destuid, catched=0, count=0; diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index d9c33589..a3005ad3 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: kaede.c,v 1.4 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" char *Ptt_prints(char *str, int mode) { @@ -20,7 +20,7 @@ char *Ptt_prints(char *str, int mode) { while((po = strstr(str, "\033*u"))) { int attempts; - attempts = utmpshm->number; + attempts = SHM->UTMPnumber; po[0] = 0; sprintf(strbuf, "%s%d%s", str, attempts, po + 3); strcpy(str, strbuf); diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 14325216..8610e5c5 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: mail.c,v 1.12 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -578,11 +578,11 @@ int mail_all() { if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); - for(unum = uhash->number, i = 0; i < unum; i++) { - if(bad_user_id(uhash->userid[i])) + for(unum = SHM->number, i = 0; i < unum; i++) { + if(bad_user_id(SHM->userid[i])) continue; /* Ptt */ - userid = uhash->userid[i]; + userid = SHM->userid[i]; if(strcmp(userid,STR_GUEST) && strcmp(userid, "new") && strcmp(userid, cuser.userid)) { sethomepath(genbuf, userid); @@ -1057,7 +1057,7 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { clrtoeol(); move(1, 0); generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); @@ -1175,7 +1175,7 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { generalnamecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", buf, sizeof(buf), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index a933b6f3..64ab1557 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.33 2002/06/05 02:42:29 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.34 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -250,7 +250,7 @@ talk_request(int sig) time_t now = time (0); sprintf (buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", - utmpshm->uinfo[currutmp->destuip].userid, my_ctime (&now), + SHM->uinfo[currutmp->destuip].userid, my_ctime (&now), (currutmp->sig == 2)? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" : "呼叫、呼叫,聽到請回答"); move (0, 0); @@ -516,11 +516,10 @@ login_query () char uid[IDLEN + 1], passbuf[PASSLEN]; int attempts; char genbuf[200]; - resolve_utmp (); + attach_SHM(); resolve_garbage (); - attach_uhash (); now= time(0); - attempts = utmpshm->number; + attempts = SHM->UTMPnumber; #ifdef DEBUG move(1, 0); prints("debugging mode\ncurrent pid: %d\n", getpid()); @@ -685,8 +684,8 @@ where (char *from) { register int i = 0, count = 0, j; - for (j = 0; j < fcache->top; j++){ - char *token = strtok (fcache->domain[j], "&"); + for (j = 0; j < SHM->top; j++){ + char *token = strtok (SHM->domain[j], "&"); i = 0; count = 0; @@ -790,9 +789,9 @@ user_login () time (&now); ptime = localtime (&now); tmp = localtime (&cuser.lastlogin); - if ((a = utmpshm->number) > fcache->max_user){ - fcache->max_user = a; - fcache->max_time = now; + if ((a = SHM->UTMPnumber) > SHM->max_user){ + SHM->max_user = a; + SHM->max_time = now; } init_brdbuf(); brc_initial (DEFAULT_BOARD); diff --git a/mbbsd/menu.c b/mbbsd/menu.c index cbdb0871..61bf8bda 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.9 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: menu.c,v 1.10 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -97,7 +97,6 @@ static int u_movie() { } void movie(int i) { - extern struct pttcache_t *ptt; static short history[MAX_HISTORY]; static char myweek[] = "天一二三四五六"; const char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; @@ -105,17 +104,17 @@ void movie(int i) { int j; if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && - !ptt->busystate && ptt->max_film > 0) { + !SHM->Pbusystate && SHM->max_film > 0) { if(currstat == PSALE) { i = PSALE; reload_money(); } else { do { if(!i) - i = 1 + (int)(((float)ptt->max_film * + i = 1 + (int)(((float)SHM->max_film * rand()) / (RAND_MAX + 1.0)); - for(j = ptt->max_history; j >= 0; j--) + for(j = SHM->max_history; j >= 0; j--) if(i == history[j]) { i = 0; break; @@ -123,15 +122,15 @@ void movie(int i) { } while(i == 0); } - memcpy(history, &history[1], ptt->max_history * sizeof(short)); - history[ptt->max_history] = j = i; + memcpy(history, &history[1], SHM->max_history * sizeof(short)); + history[SHM->max_history] = j = i; if(i == 999) /* Goodbye my friend */ i = 0; move(1, 0); clrtoline(1 + FILMROW); /* 清掉上次的 */ - Jaky_outs(ptt->notes[i], 11); /* 只印11行就好 */ + Jaky_outs(SHM->notes[i], 11); /* 只印11行就好 */ outs(reset_color); } i = ptime->tm_wday << 1; @@ -140,8 +139,8 @@ void movie(int i) { "\033[30m[扣機]\033[31m%s\033[0m", ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "生日要請客唷" : ptt->today_is, - utmpshm->number, cuser.userid, msgs[currutmp->pager]); + "生日要請客唷" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); outmsg(mystatus); refresh(); } diff --git a/mbbsd/name.c b/mbbsd/name.c index b78b54d1..f2a0f704 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.7 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: name.c,v 1.8 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -637,34 +637,34 @@ int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, /* general complete functions (brdshm) */ int completeboard_compar(int where, char *str, int len) { - return strncasecmp(brdshm->sorted[0][where]->brdname, str, len); + return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); } int completeboard_permission(int where) { - return Ben_Perm(brdshm->sorted[0][where]); + return Ben_Perm(SHM->bsorted[0][where]); } char *completeboard_getname(int where) { - return brdshm->sorted[0][where]->brdname; + return SHM->bsorted[0][where]->brdname; } /* general complete functions (utmpshm) */ int completeutmp_compar(int where, char *str, int len) { - return strncasecmp(utmpshm->sorted[utmpshm->currsorted][0][where]->userid, + return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, str, len); } int completeutmp_permission(int where) { return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || - !utmpshm->sorted[utmpshm->currsorted][0][where]->invisible); + !SHM->sorted[SHM->currsorted][0][where]->invisible); } char *completeutmp_getname(int where) { - return utmpshm->sorted[utmpshm->currsorted][0][where]->userid; + return SHM->sorted[SHM->currsorted][0][where]->userid; } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index e1feac1f..90b39eab 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.68 2002/06/05 03:22:43 ptt Exp $ */ +/* $Id: talk.c,v 1.69 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -215,13 +215,13 @@ int login_friend_online(void) { userinfo_t *uentp; int i, stat, stat1; - int offset=(int) (currutmp - &utmpshm->uinfo[0]); - for (i=0;i<utmpshm->number && currutmp->friendtotal<MAX_FRIEND; i++){ - uentp = (utmpshm->sorted[utmpshm->currsorted][0][i]); + int offset=(int) (currutmp - &SHM->uinfo[0]); + for (i=0;i<SHM->UTMPnumber && currutmp->friendtotal<MAX_FRIEND; i++){ + uentp = (SHM->sorted[SHM->currsorted][0][i]); if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))){ stat1=reverse_friend_stat(stat); stat <<= 24; - stat |= (int) (uentp - &utmpshm->uinfo[0]); + stat |= (int) (uentp - &SHM->uinfo[0]); currutmp->friend_online[currutmp->friendtotal++]=stat; if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND){ stat1 <<= 24; @@ -236,13 +236,13 @@ int login_friend_online(void) int logout_friend_online(userinfo_t *utmp) { int i, j, k; - int offset=(int) (utmp - &utmpshm->uinfo[0]); + int offset=(int) (utmp - &SHM->uinfo[0]); userinfo_t *ui; while( utmp->friendtotal > 0 ){ i = utmp->friendtotal-1; j = (utmp->friend_online[i] & 0xFFFFFF); utmp->friend_online[i]=0; - ui = &utmpshm->uinfo[j]; + ui = &SHM->uinfo[j]; if(ui->pid && ui!=utmp){ for(k=0; k<ui->friendtotal > 0 && k < MAX_FRIEND && (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); @@ -268,7 +268,7 @@ int friend_stat(userinfo_t *me, userinfo_t * ui) } for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){ j = (me->friend_online[i] & 0xFFFFFF); - if( 0 <= j && j < MAX_ACTIVE && ui == &utmpshm->uinfo[j] ){ + if( 0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j] ){ hit |= me->friend_online[i] >>24; break; } @@ -634,7 +634,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) if(flag == 3 && uin->msgcount) { /* 不懂 */ - uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->destuip = currutmp - &SHM->uinfo[0]; uin->sig = 2; if(uin->pid > 0) kill(uin->pid, SIGUSR1); } else if(flag != 2 && @@ -1185,7 +1185,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->sockaddr = server.sin_port; currutmp->destuid = uin->uid; setutmpmode(PAGE); - uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->destuip = currutmp - &SHM->uinfo[0]; if(pid > 0) kill(pid, SIGUSR1); clear(); prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid); @@ -1197,7 +1197,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { if (ch == I_TIMEOUT){ ch = uin->mode; if (!ch && uin->chatid[0] == 1 && - uin->destuip == currutmp - &utmpshm->uinfo[0]){ + uin->destuip == currutmp - &SHM->uinfo[0]){ bell(); outmsg("對方回應中..."); refresh(); @@ -1223,7 +1223,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { outs("再"); bell(); - uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->destuip = currutmp - &SHM->uinfo[0]; if(pid <= 0 || kill(pid, SIGUSR1) == -1){ #ifdef linux add_io(sock, 20); /* added 4 linux... achen */ @@ -1421,8 +1421,7 @@ static char *friend_descript(char *uident) { return space_buf; } -static char *descript(int show_mode, userinfo_t * uentp, time_t diff, - fromcache_t * fcache) +static char *descript(int show_mode, userinfo_t * uentp, time_t diff) { switch (show_mode){ case 1: @@ -1431,7 +1430,7 @@ static char *descript(int show_mode, userinfo_t * uentp, time_t diff, return (((uentp->pager != 2 && uentp->pager != 3 && diff) || HAS_PERM(PERM_SYSOP)) ? #ifdef WHERE - uentp->from_alias ? fcache->replace[uentp->from_alias] : + uentp->from_alias ? SHM->replace[uentp->from_alias] : uentp->from #else uentp->from @@ -1467,7 +1466,7 @@ int pickup_maxpages(int pickupway, int nfriends) if( cuser.uflag & FRIEND_FLAG ) number = nfriends; else - number = utmpshm->number+ + number = SHM->UTMPnumber+ (pickupway == 0 ? nfriends : 0); return (number-1) / MAXPICKUP +1; } @@ -1482,7 +1481,7 @@ static int pickup_myfriend(pickup_t *friends, for( i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ where = currutmp->friend_online[i] & 0xFFFFFF; if( 0 <= where && where < MAX_ACTIVE && - (uentp = &utmpshm->uinfo[where]) && uentp->pid && + (uentp = &SHM->uinfo[where]) && uentp->pid && uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = @@ -1524,8 +1523,8 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int *nfriend, int *myfriend, int *friendme, int *bfriend) { /* avoid race condition */ - int currsorted = utmpshm->currsorted; - int utmpnumber = utmpshm->number; + int currsorted = SHM->currsorted; + int utmpnumber = SHM->UTMPnumber; int friendtotal= currutmp->friendtotal; userinfo_t **utmp; @@ -1564,7 +1563,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); - utmp = utmpshm->sorted[currsorted][sorted_way]; + utmp = SHM->sorted[currsorted][sorted_way]; which = *page * MAXPICKUP-*nfriend; if(which<0) which=0; for(;which < utmpnumber && size < MAXPICKUP;which++) @@ -1648,7 +1647,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" "%-2d\033[m\n", - msg_pickup_way[pickup_way], utmpshm->number, + msg_pickup_way[pickup_way], SHM->UTMPnumber, myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ @@ -1715,7 +1714,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, /* from */ descript(show_mode, uentp, - uentp->pager & !(friend&HRM), fcache), + uentp->pager & !(friend&HRM)), /* board or mode */ #ifdef SHOWBOARD @@ -1944,15 +1943,15 @@ static void userlist(void) char swid[IDLEN + 1]; move(1, 0); si = generalnamecomplete(msg_uid, swid, - sizeof(swid), utmpshm->number, + sizeof(swid), SHM->UTMPnumber, completeutmp_compar, completeutmp_permission, completeutmp_getname); if( si >= 0 ){ pickup_t friends[MAX_FRIEND + 1]; int nGots, i; - fi = utmpshm->sorted[utmpshm->currsorted][0][si] - - &utmpshm->uinfo[0]; + fi = SHM->sorted[SHM->currsorted][0][si] - + &SHM->uinfo[0]; nGots= pickup_myfriend(friends, &myfriend, &friendme); for( i = 0 ; i < nGots ; ++i ) @@ -1987,7 +1986,7 @@ static void userlist(void) case '9': { /* Thor: 可以打數字跳到該人 */ int tmp; - if( (tmp = search_num(ch, utmpshm->number)) >= 0 ){ + if( (tmp = search_num(ch, SHM->UTMPnumber)) >= 0 ){ if( tmp / 20 == page ){ /* in2:目的在目前這一頁, 直接 更新 offset , 不用重畫畫面 */ @@ -2046,8 +2045,8 @@ static void userlist(void) *ans == 'n') break; if( HAS_PERM(PERM_SYSOP) ){ - for( i = 0 ; i < utmpshm->number && i<1000 ; ++i ){ - uentp = utmpshm->sorted[utmpshm->currsorted][0][i]; + for( i = 0 ; i < SHM->UTMPnumber && i<1000 ; ++i ){ + uentp = SHM->sorted[SHM->currsorted][0][i]; if( uentp->pid && kill(uentp->pid, 0) != -1 ) my_write(uentp->pid, genbuf, uentp->userid, 1, NULL); @@ -2060,7 +2059,7 @@ static void userlist(void) i < MAX_FRIEND ; ++i ){ where = currutmp->friend_online[i] & 0xFFFFFF; if( 0 <= where && where < MAX_ACTIVE && - (uentp = &utmpshm->uinfo[where]) && + (uentp = &SHM->uinfo[where]) && uentp->pid && isvisible_stat(currutmp, uentp, frstate = @@ -2376,7 +2375,7 @@ int t_talk() { */ stand_title("打開話匣子"); generalnamecomplete(msg_uid, uident, sizeof(uident), - utmpshm->number, + SHM->UTMPnumber, completeutmp_compar, completeutmp_permission, completeutmp_getname); @@ -2422,7 +2421,7 @@ void talkreply(void) int a, sig = currutmp->sig; talkrequest = NA; - uip = &utmpshm->uinfo[currutmp->destuip]; + uip = &SHM->uinfo[currutmp->destuip]; sprintf(page_requestor, "%s (%s)", uip->userid, uip->username); currutmp->destuid = uip->uid; currstat = XMODE; /* 避免出現動畫 */ @@ -2484,7 +2483,7 @@ void talkreply(void) strcpy(genbuf, "不告訴你咧 !! ^o^"); write(a, genbuf, 60); } - uip->destuip = currutmp - &utmpshm->uinfo[0]; + uip->destuip = currutmp - &SHM->uinfo[0]; if (buf[0] == 'y') switch (sig){ case SIG_DARK: diff --git a/mbbsd/user.c b/mbbsd/user.c index 54a3a515..c7a5e455 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.21 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: user.c,v 1.22 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1107,7 +1107,7 @@ int u_list() { setutmpmode(LAUSERS); showrealname = u_list_special = usercounter = 0; - totalusers = uhash->number; + totalusers = SHM->number; if(HAS_PERM(PERM_SEEULEVELS)) { getdata(b_lines - 1, 0, "觀看 [1]特殊等級 (2)全部?", genbuf, 3, DOECHO); diff --git a/mbbsd/var.c b/mbbsd/var.c index 43dab291..123f7245 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.6 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: var.c,v 1.7 2002/06/06 21:34:11 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -307,12 +307,9 @@ int wmofo = -1; /* cache.c */ int numboards = -1; int *GLOBALVAR; -uhash_t *uhash; -bcache_t *brdshm; -userinfo_t *currutmp; +SHM_t *SHM; boardheader_t *bcache; -struct utmpfile_t *utmpshm; -struct fromcache_t *fcache; +userinfo_t *currutmp; /* board.c */ int class_bid = 0; |