diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-04-04 17:48:27 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-04-04 17:48:27 +0800 |
commit | 431ac04533837d4d6bf8d01314f5c3e794e4a2a6 (patch) | |
tree | ea809f1e6a3bfe56fbc4f25d732231e1a6377c81 | |
parent | 911a0f4f78bf10384e32bd96cc2a2742b7005d94 (diff) | |
download | pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.tar pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.tar.gz pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.tar.bz2 pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.tar.lz pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.tar.xz pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.tar.zst pttbbs-431ac04533837d4d6bf8d01314f5c3e794e4a2a6.zip |
completeouttacache
git-svn-id: http://opensvn.csie.org/pttbbs/branches/outtacache@1687 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | cacheserver/Makefile | 6 | ||||
-rw-r--r-- | cacheserver/cacheserver.c | 106 | ||||
-rw-r--r-- | cacheserver/utmpserver.c | 88 | ||||
-rw-r--r-- | cacheserver/utmpsync.c | 2 | ||||
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | include/pttstruct.h | 10 | ||||
-rw-r--r-- | mbbsd/cal.c | 7 | ||||
-rw-r--r-- | mbbsd/talk.c | 17 |
8 files changed, 108 insertions, 130 deletions
diff --git a/cacheserver/Makefile b/cacheserver/Makefile index 2c4f46e5..42b077b4 100644 --- a/cacheserver/Makefile +++ b/cacheserver/Makefile @@ -5,9 +5,6 @@ PROGRAMS= utmpserver utmpsync all: ${PROGRAMS} -#cacheserver: cacheserver.c -# ${CC} ${CFLAGS} ${LDFLAGS} -o cacheserver cacheserver.c avltree.c - .for fn in ${PROGRAMS} ${fn}: ${fn}.c ${CC} ${CFLAGS} ${LDFLAGS} -DPTTBBS_UTIL -o ${fn} ${fn}.c ../util/util_*.o @@ -15,6 +12,3 @@ ${fn}: ${fn}.c clean: rm -f *~ ${PROGRAMS} - -test: utmpserver - ./utmpserver diff --git a/cacheserver/cacheserver.c b/cacheserver/cacheserver.c deleted file mode 100644 index 05b454c0..00000000 --- a/cacheserver/cacheserver.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $Id$ */ -#include "bbs.h" -#include <avltree.h> -#include <err.h> - -AVL_IX_DESC avl; - -typedef struct { - int uid; - unsigned int count; - char key[IDLEN + 1]; -} rectype_t; - -void usage(void) -{ - fprintf(stderr, "usage: cacheserver -f PASSWD -p port\n"); -} - -int loadpasswd(char *pfn) -{ - int fd, i, nUsers = 0; - userec_t u; - rectype_t rec; - - if( pfn == NULL ){ - fprintf(stderr, "no password file!\n"); - return -1; - } - if( (fd = open(pfn, O_RDONLY)) < 0 ){ - perror("open password"); - return -1; - } - - avl_create_index(&avl, AVL_NO_DUP_KEYS, IDLEN + 1); - - for( i = 0 ; read(fd, &u, sizeof(u)) == sizeof(u) ; ++i ) - if( u.userid[0] ){ - ++nUsers; - rec.uid = i; - rec.count = 0; - strlcpy(rec.key, u.userid, sizeof(rec.key)); - avl_add_key((AVL_IX_REC*)&rec, &avl); - } - fprintf(stderr, "%d users added\n", nUsers); - -#if 0 - rec.uid = 0; - rec.count = 0; - strcpy(rec.key, "KTDOG"); - avl_find_key((AVL_IX_REC*)&rec, &avl); - printf("%d\n", rec.uid); -#endif - return 0; -} - -int service(int sfd) -{ - int cfd, len, size; - struct sockaddr_in clientaddr; - - char buf[10240]; - while( 1 ){ - if( (cfd = accept(sfd, (struct sockaddr *)&clientaddr, &len)) < 0 ){ - if( errno != EINTR ) - sleep(1); - continue; - } - - read(cfd, &size, sizeof(size)); - for( len = 0 ; len < size ; - len += read(cfd, &buf[len], sizeof(buf) - len) ) - ; - printf("total %d bytes\n", len); - close(cfd); - } -} - -int main(int argc, char **argv) -{ - int ch, port = 0, sfd; - char *pfn = NULL; - while( (ch = getopt(argc, argv, "f:p:h")) != -1 ) - switch( ch ){ - case 'f': - pfn = strdup(optarg); - break; - - case 'p': - port = atoi(optarg); - break; - - case 'h': - default: - usage(); - return 1; - } - - if( (sfd = tobind(port)) < 0 ) - return 1; - - if( loadpasswd(pfn) < 0 ) - return 1; - - service(sfd); - return 0; -} diff --git a/cacheserver/utmpserver.c b/cacheserver/utmpserver.c index 5826eb59..60cd02ad 100644 --- a/cacheserver/utmpserver.c +++ b/cacheserver/utmpserver.c @@ -4,12 +4,12 @@ struct { int uid; - short nFriends, nRejects; + int nFriends, nRejects; int friend[MAX_FRIEND]; int reject[MAX_REJECT]; -} utmp[MAX_ACTIVE]; +} utmp[USHM_SIZE]; -inline void countarray(int *s, int max) +inline int countarray(int *s, int max) { int i; for( i = 0 ; i < max && s[i] ; ++i ) @@ -17,6 +17,57 @@ inline void countarray(int *s, int max) return i; } +int +reverse_friend_stat(int stat) +{ + int stat1 = 0; + if (stat & IFH) + stat1 |= HFM; + if (stat & IRH) + stat1 |= HRM; + if (stat & HFM) + stat1 |= IFH; + if (stat & HRM) + stat1 |= IRH; + if (stat & IBH) + stat1 |= IBH; + return stat1; +} + +int set_friend_bit(int me, int ui) +{ + int hit = 0; + /* 判斷對方是否為我的朋友 ? */ + if( intbsearch(utmp[ui].uid, utmp[me].friend, utmp[me].nFriends) ) + hit = IFH; + + /* 判斷我是否為對方的朋友 ? */ + if( intbsearch(utmp[me].uid, utmp[ui].friend, utmp[ui].nFriends) ) + hit |= HFM; + + /* 判斷對方是否為我的仇人 ? */ + if( intbsearch(utmp[ui].uid, utmp[me].reject, utmp[me].nRejects) ) + hit |= IRH; + + /* 判斷我是否為對方的仇人 ? */ + if( intbsearch(utmp[me].uid, utmp[ui].reject, utmp[ui].nRejects) ) + hit |= HRM; + + return hit; +} + +void initdata(int index) +{ + utmp[index].nFriends = countarray(utmp[index].friend, MAX_FRIEND); + utmp[index].nRejects = countarray(utmp[index].reject, MAX_REJECT); + if( utmp[index].nFriends > 0 ) + qsort(utmp[index].friend, utmp[index].nFriends, + sizeof(int), qsort_intcompar); + if( utmp[index].nRejects > 0 ) + qsort(utmp[index].reject, utmp[index].nRejects, + sizeof(int), qsort_intcompar); +} + int main(int argc, char **argv) { struct sockaddr_in clientaddr; @@ -47,13 +98,15 @@ int main(int argc, char **argv) toread(cfd, &index, sizeof(index)); if( index == -1 ){ int nSynced = 0; - for( i = 0 ; i < MAX_ACTIVE ; ++i, ++nSynced ) + for( i = 0 ; i < USHM_SIZE ; ++i, ++nSynced ) if( toread(cfd, &utmp[i].uid, sizeof(utmp[i].uid)) > 0 && toread(cfd, utmp[i].friend, sizeof(utmp[i].friend)) > 0 && - toread(cfd, utmp[i].reject, sizeof(utmp[i].reject)) > 0 ) - ; + toread(cfd, utmp[i].reject, sizeof(utmp[i].reject)) > 0 ){ + if( utmp[i].uid ) + initdata(i); + } else - for( ; i < MAX_ACTIVE ; ++i ) + for( ; i < USHM_SIZE ; ++i ) utmp[i].uid = 0; close(cfd); fprintf(stderr, "%d users synced\n", nSynced); @@ -63,11 +116,26 @@ int main(int argc, char **argv) if( toread(cfd, &uid, sizeof(uid)) > 0 && toread(cfd, utmp[index].friend, sizeof(utmp[index].friend)) > 0 && toread(cfd, utmp[index].reject, sizeof(utmp[index].reject)) > 0 ){ - int nFriends = 0, frarray[MAX_FRIEND]; +#define MAX_FS (2 * MAX_FRIEND) + int iu, nFrs, stat, rstat; + ocfs_t fs[MAX_FS]; + utmp[index].uid = uid; - utmp[index].nFriends = countarray(utmp[index].friend, MAX_FRIEND); - utmp[index].nRejects = countarray(utmp[index].reject, MAX_REJECT); + initdata(index); + + for( nFrs = iu = 0 ; iu < USHM_SIZE && nFrs < MAX_FS ; ++iu ) + if( iu != index && utmp[iu].uid ){ + if( (stat = set_friend_bit(index, iu)) ){ + rstat = reverse_friend_stat(stat); + fs[nFrs].index = iu; + fs[nFrs].uid = utmp[iu].uid; + fs[nFrs].friendstat = (stat << 24) + iu; + fs[nFrs].rfriendstat = (rstat << 24) + index; + ++nFrs; + } + } + towrite(cfd, &fs, sizeof(ocfs_t) * nFrs); } close(cfd); } diff --git a/cacheserver/utmpsync.c b/cacheserver/utmpsync.c index bebde137..13ffcf4e 100644 --- a/cacheserver/utmpsync.c +++ b/cacheserver/utmpsync.c @@ -15,7 +15,7 @@ int main(int argc, char **argv) index = -1; towrite(sfd, &index, sizeof(index)); - for( i = 0 ; i < MAX_ACTIVE ; ++i ) + for( i = 0 ; i < USHM_SIZE ; ++i ) if( towrite(sfd, &SHM->uinfo[i].uid, sizeof(SHM->uinfo[i].uid)) < 0 || towrite(sfd, SHM->uinfo[i].friend, sizeof(SHM->uinfo[i].friend)) < 0 || diff --git a/include/proto.h b/include/proto.h index f291f74d..9851a9e0 100644 --- a/include/proto.h +++ b/include/proto.h @@ -565,7 +565,7 @@ int t_talk(); int t_display(); int my_query(char *uident); int logout_friend_online(); -int login_friend_online(); +void login_friend_online(); int isvisible_uid(int tuid); int friend_stat(userinfo_t *me, userinfo_t * ui); int call_in(userinfo_t *uentp, int fri_stat); diff --git a/include/pttstruct.h b/include/pttstruct.h index 9f950c92..5895c31d 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -477,4 +477,14 @@ typedef struct time_t chrono; int recno; } TagItem; + +#ifdef OUTTACACHE +typedef struct { + int index; // 在 SHM->uinfo[index] + int uid; // 避免在 cache server 上不同步, 再確認用. + int friendstat; + int rfriendstat; +} ocfs_t; +#endif + #endif diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 462818de..43c0d2f5 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -431,9 +431,14 @@ p_sysinfo(void) prints("記憶體用量: sbrk: %d KB, idrss: %d KB, isrss: %d KB\n", ((int)sbrk(0) - 0x8048000) / 1024, (int)ru.ru_idrss, (int)ru.ru_isrss); + prints("特別參數:" #ifdef CRITICAL_MEMORY - prints("目前在 CRITICAL_MEMORY 模式下\n"); + " CRITICAL_MEMORY" #endif +#ifdef OUTTACACHE + " OUTTACACHE" +#endif + ); } pressanykey(); return 0; diff --git a/mbbsd/talk.c b/mbbsd/talk.c index b801357b..604f3de8 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -210,20 +210,27 @@ reverse_friend_stat(int stat) return stat1; } -int -login_friend_online(void) +void login_friend_online(void) { userinfo_t *uentp; int i, stat, stat1; int offset = (int)(currutmp - &SHM->uinfo[0]); #ifdef OUTTACACHE int sfd; - - if( (sfd = toconnect(OUTTACACHEHOST, OUTTACACHEPOST)) > 0 ){ + if( (sfd = toconnect(OUTTACACHEHOST, OUTTACACHEPORT)) > 0 ){ if( towrite(sfd, &offset, sizeof(offset)) > 0 && towrite(sfd, &currutmp->uid, sizeof(currutmp->uid)) > 0 && towrite(sfd, currutmp->friend, sizeof(currutmp->friend)) > 0 && towrite(sfd, currutmp->reject, sizeof(currutmp->reject)) > 0 ){ + ocfs_t fs; + while( toread(sfd, &fs, sizeof(fs)) > 0 ) + if( SHM->uinfo[fs.index].uid == fs.uid ){ + currutmp->friend_online[currutmp->friendtotal++] + = fs.friendstat; + SHM->uinfo[fs.index].friend_online[ SHM->uinfo[fs.index].friendtotal++ ] = fs.rfriendstat; + } + close(sfd); + return; } close(sfd); } @@ -242,7 +249,7 @@ login_friend_online(void) } } } - return 0; + return; } int |