summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h3
-rw-r--r--mbbsd/admin.c5
-rw-r--r--mbbsd/cache.c4
-rw-r--r--mbbsd/mbbsd.c1
-rw-r--r--mbbsd/passwd.c112
-rw-r--r--mbbsd/register.c2
-rw-r--r--mbbsd/user.c3
-rw-r--r--util/uhash_loader.c3
8 files changed, 18 insertions, 115 deletions
diff --git a/include/proto.h b/include/proto.h
index 8d90a1b0..31c068bc 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -659,14 +659,11 @@ 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_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);
-int passwd_query_money(int num);
int initcuser(char *userid);
int freecuser();
diff --git a/mbbsd/admin.c b/mbbsd/admin.c
index 654f045f..efea1be5 100644
--- a/mbbsd/admin.c
+++ b/mbbsd/admin.c
@@ -130,7 +130,7 @@ search_key_user(char *passwdfile, int mode)
if (ch == 's' && !mode) {
if ((ch = searchuser(user.userid))) {
setumoney(ch, user.money);
- passwd_index_update(ch, &user);
+ passwd_update(ch, &user);
fclose(fp1);
return 0;
} else {
@@ -148,7 +148,7 @@ search_key_user(char *passwdfile, int mode)
fprintf(stderr, "本站人口已達飽和!\n");
exit(1);
}
- if (passwd_index_update(allocid, &user) == -1) {
+ if (passwd_update(allocid, &user) == -1) {
fprintf(stderr, "客滿了,再見!\n");
exit(1);
}
@@ -1068,7 +1068,6 @@ scan_register_form(char *regfile, int automode, int neednum)
strncat(genbuf, "\n", sizeof(genbuf));
log_file(buf, genbuf, 1);
passwd_update(unum, &muser);
- passwd_index_update(unum, &muser);
if ((fout = fopen(logfile, "a"))) {
for (n = 0; field[n]; n++)
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 261cfa5f..288c38cf 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -476,10 +476,6 @@ demoney(int money)
int
moneyof(int uid)
{ /* ptt 改進金錢處理效率 */
- if(SHM->money[uid - 1] < 0)
- {
- SHM->money[uid - 1] = passwd_query_money(uid);
- }
return SHM->money[uid - 1];
}
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index 3ef7f0da..0e4624b0 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -178,7 +178,6 @@ u_exit(char *mode)
cuser->numlogins = --cuser->numlogins;
/* Leeym 上站停留時間限制式 */
}
- passwd_index_update(usernum, cuser);
passwd_update(usernum, cuser);
log_usies(mode, NULL);
}
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index c2cb7aee..7058f12b 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -53,67 +53,23 @@ passwd_update_money(int num)
/* update money only
Ptt: don't call it directly, call deumoney() */
{
- userec_t user;
- int pwdfd, money = moneyof(num);
- char path[256];
-
- if (num < 1 || num > MAX_USERS)
- return -1;
-
- 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_query_money(int num)
-/* query money only
- Ptt: don't call it directly, call moneyof() */
-{
- userec_t user;
- int pwdfd, money;
- char path[256];
-
- if (num < 1 || num > MAX_USERS)
+ int pwdfd;
+ int money=moneyof(num);
+ userec_t u;
+ if (num < 1 || num > MAX_USERS)
return -1;
- sethomefile(path, getuserid(num), ".passwd");
-
- if ((pwdfd = open(path, O_RDONLY)) < 0)
- {
- if(passwd_index_query(num, &user)<0) // tempory code, will be removed
- return 0;
- return user.money;
- }
- if(lseek(pwdfd, (off_t)((int)&user.money - (int)&user), SEEK_SET) >= 0)
- if(read(pwdfd, &money, sizeof(int))==-1)
- money=0;
- close(pwdfd);
- if(money<0)
- {
- if(passwd_index_query(num, &user)<0) // tempory code, will be removed
- return 0;
- return user.money;
- }
-
- return money;
+ if ((pwdfd = open(fn_passwd, O_WRONLY)) < 0)
+ exit(1);
+ lseek(pwdfd, sizeof(userec_t) * (num - 1) +
+ ((int)&u.money - (int)&u), SEEK_SET);
+ write(pwdfd, &money, sizeof(int));
+ close(pwdfd);
+ return 0;
}
int
-passwd_index_update(int num, userec_t * buf)
+passwd_update(int num, userec_t * buf)
{
int pwdfd;
if (num < 1 || num > MAX_USERS)
@@ -128,24 +84,7 @@ passwd_index_update(int num, userec_t * buf)
}
int
-passwd_update(int num, userec_t * buf)
-{
- int pwdfd;
- char path[256];
-
- if(!buf->userid[0]) return -1;
-
- sethomefile(path, buf->userid, ".passwd");
- buf->money = moneyof(num);
- if ((pwdfd = open(path, O_WRONLY|O_CREAT, 0600)) < 0)
- return -1;
- write(pwdfd, buf, sizeof(userec_t));
- close(pwdfd);
- return 0;
-}
-
-int
-passwd_index_query(int num, userec_t * buf)
+passwd_query(int num, userec_t * buf)
{
int pwdfd;
if (num < 1 || num > MAX_USERS)
@@ -171,31 +110,6 @@ int initcuser(char *userid)
}
int
-passwd_query(int num, userec_t * buf)
-{
- int pwdfd;
- char path[256], *userid;
-
- if (num < 1 || num > MAX_USERS)
- return -1;
- userid = getuserid(num);
-
- if(userid[0]=='\0') return -1;
-
- sethomefile(path, userid, ".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_apply(int (*fptr) (int, userec_t *))
{
int i;
diff --git a/mbbsd/register.c b/mbbsd/register.c
index 04da1f05..10ba80f9 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -274,7 +274,7 @@ new_register()
fprintf(stderr, "本站人口已達飽和!\n");
exit(1);
}
- if (passwd_index_update(allocid, &newuser) == -1) {
+ if (passwd_update(allocid, &newuser) == -1) {
fprintf(stderr, "客滿了,再見!\n");
exit(1);
}
diff --git a/mbbsd/user.c b/mbbsd/user.c
index 4d8e46c5..6245ef42 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -15,7 +15,7 @@ kill_user(int num)
memset(&u, 0, sizeof(u));
log_usies("KILL", getuserid(num));
setuserid(num, "");
- passwd_index_update(num, &u);
+ passwd_update(num, &u);
return 0;
}
int
@@ -620,7 +620,6 @@ uinfo_query(userec_t * u, int real, int unum)
if (money_change)
setumoney(unum, x.money);
passwd_update(unum, &x);
- passwd_index_update(unum, &x);
if (money_change) {
strlcpy(genbuf, "boards/S/Security", sizeof(genbuf));
stampfile(genbuf, &fhdr);
diff --git a/util/uhash_loader.c b/util/uhash_loader.c
index 7c2f9beb..86c47414 100644
--- a/util/uhash_loader.c
+++ b/util/uhash_loader.c
@@ -121,8 +121,7 @@ void add_to_uhash(int n, userec_t *user)
{
int *p, h = string_hash(user->userid);
strcpy(SHM->userid[n], user->userid);
- SHM->money[n] = -1;
- //user->money;
+ SHM->money[n] = user->money;
p = &(SHM->hash_head[h]);