diff options
-rw-r--r-- | include/proto.h | 4 | ||||
-rw-r--r-- | include/util.h | 3 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 1 | ||||
-rw-r--r-- | mbbsd/passwd.c | 84 | ||||
-rw-r--r-- | mbbsd/user.c | 4 | ||||
-rw-r--r-- | util/reaper.c | 2 |
6 files changed, 68 insertions, 30 deletions
diff --git a/include/proto.h b/include/proto.h index 5c423bbb..25857b96 100644 --- a/include/proto.h +++ b/include/proto.h @@ -644,8 +644,10 @@ unsigned StringHash(unsigned char *s); /* passwd */ int passwd_init(); int passwd_update(int num, userec_t *buf); +int passwd_index_update(int num, userec_t *buf); int passwd_query(int num, userec_t *buf); -int passwd_apply(int (*fptr)(userec_t *)); +int passwd_index_query(int num, userec_t *buf); +int passwd_apply(int (*fptr)(int, userec_t *)); void passwd_lock(); void passwd_unlock(); int passwd_update_money(int num); diff --git a/include/util.h b/include/util.h index d19944cc..44f8ca58 100644 --- a/include/util.h +++ b/include/util.h @@ -1,7 +1,6 @@ #ifndef INCLUDE_UTIL_H #define INCLUDE_UTIL_H int passwd_mmap(void); -int passwd_apply(int (*fptr)(userec_t *)); -int passwd_apply2(int (*fptr)(int, userec_t *)); +int passwd_apply(int (*fptr)(int, userec_t *)); #endif // INCLUDE_UTIL_H diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 5af63c29..9ff9790c 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -178,6 +178,7 @@ u_exit(char *mode) /* Leeym 上站停留時間限制式 */ } passwd_update(usernum, &cuser); + passwd_index_update(usernum, &cuser); log_usies(mode, NULL); } diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 7686e566..67012f99 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -49,22 +49,37 @@ passwd_init() } int -passwd_update_money(int num) +passwd_update_money(int num) /* update money only */ { - userec_t user; - if (num < 1 || num > MAX_USERS) + userec_t user; + int pwdfd, money = moneyof(num); + char path[256]; + + if (num < 1 || num > MAX_USERS) return -1; - passwd_query(num, &user); - if (SHM->loaded) - user.money = moneyof(num); - passwd_update(num, &user); - return 0; + + sethomefile(path, getuserid(num), ".passwd"); + + if ((pwdfd = open(path, O_WRONLY)) < 0) + { + if(passwd_index_query(num, &user)<0) // tempory code, will be removed + exit(1); + user.money=money; + passwd_update(num, &user); + return 0; + } + + if(lseek(pwdfd, (off_t)((int)&user.money - (int)&user), SEEK_SET) >= 0) + write(pwdfd, &money, sizeof(int)); + + close(pwdfd); + return 0; } int -passwd_update(int num, userec_t * buf) +passwd_index_update(int num, userec_t * buf) { - int pwdfd; + int pwdfd; if (num < 1 || num > MAX_USERS) return -1; buf->money = moneyof(num); @@ -77,7 +92,22 @@ passwd_update(int num, userec_t * buf) } int -passwd_query(int num, userec_t * buf) +passwd_update(int num, userec_t * buf) +{ + int pwdfd; + char path[256]; + + sethomefile(path, getuserid(num), ".passwd"); + buf->money = moneyof(num); + if ((pwdfd = open(path, O_RDWR)) < 0) + exit(1); + write(pwdfd, buf, sizeof(userec_t)); + close(pwdfd); + return 0; +} + +int +passwd_index_query(int num, userec_t * buf) { int pwdfd; if (num < 1 || num > MAX_USERS) @@ -91,26 +121,32 @@ passwd_query(int num, userec_t * buf) } int -passwd_apply(int (*fptr) (userec_t *)) +passwd_query(int num, userec_t * buf) { - int i; - userec_t user; - for (i = 0; i < MAX_USERS; i++) { - passwd_query(i + 1, &user); - if ((*fptr) (&user) == QUIT) - return QUIT; - } - return 0; + int pwdfd; + char path[256]; + + sethomefile(path, getuserid(num), ".passwd"); + if((pwdfd = open(path, O_RDONLY)) < 0) + { // copy from index // tempory code, will be removed + if(passwd_index_query(num, buf)<0) + exit(1); + passwd_update(num, buf); + return 0; + } + read(pwdfd, buf, sizeof(userec_t)); + close(pwdfd); + return 0; } int -passwd_apply2(int (*fptr)(int, userec_t *)) +passwd_apply(int (*fptr) (int, userec_t *)) { - int i; + int i; userec_t user; - for(i = 0; i < MAX_USERS; i++){ + for (i = 0; i < MAX_USERS; i++) { passwd_query(i + 1, &user); - if((*fptr)(i, &user) == QUIT) + if ((*fptr) (i, &user) == QUIT) return QUIT; } return 0; diff --git a/mbbsd/user.c b/mbbsd/user.c index d5c1d167..394f5a92 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1434,7 +1434,7 @@ static int usercounter, totalusers; static ushort u_list_special; static int -u_list_CB(userec_t * uentp) +u_list_CB(int num, userec_t * uentp) { static int i; char permstr[8], *ptr; @@ -1517,7 +1517,7 @@ u_list() if (genbuf[0] != '2') u_list_special = PERM_BASIC | PERM_CHAT | PERM_PAGE | PERM_POST | PERM_LOGINOK | PERM_BM; } - u_list_CB(NULL); + u_list_CB(0, NULL); if (passwd_apply(u_list_CB) == -1) { outs(msg_nobody); return XEASY; diff --git a/util/reaper.c b/util/reaper.c index 03f7a694..2fc587e0 100644 --- a/util/reaper.c +++ b/util/reaper.c @@ -55,7 +55,7 @@ int main(int argc, char **argv) attach_SHM(); if(passwd_init()) exit(1); - passwd_apply2(check); + passwd_apply(check); return 0; } |