summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-30 04:11:24 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-30 04:11:24 +0800
commit95f0b420db24db279e1fb25b26973acf229e53e8 (patch)
tree72bd3843dbb180d2d78d998aa59431bffaf1b044 /mbbsd
parent1091228603cdb191d3c02e0f22468310140d0f32 (diff)
downloadpttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.gz
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.bz2
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.lz
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.xz
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.zst
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.zip
faster passwd by lower the lseek.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1627 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/mbbsd.c1
-rw-r--r--mbbsd/passwd.c84
-rw-r--r--mbbsd/user.c4
3 files changed, 63 insertions, 26 deletions
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;