summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h1
-rw-r--r--mbbsd/cal.c39
-rw-r--r--mbbsd/talk.c19
3 files changed, 31 insertions, 28 deletions
diff --git a/include/proto.h b/include/proto.h
index 1859dff8..3c52ee35 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -176,6 +176,7 @@ int unlockutmpmode(void);
int x_file(void);
int give_money(void);
int p_sysinfo(void);
+int do_give_money(char *id, int uid, int money);
int p_give(void);
int p_cloak(void);
int p_from(void);
diff --git a/mbbsd/cal.c b/mbbsd/cal.c
index 0c5c61ca..9ce5de3f 100644
--- a/mbbsd/cal.c
+++ b/mbbsd/cal.c
@@ -395,27 +395,19 @@ give_tax(int money)
return (tax <= 0) ? 1 : tax;
}
-int
-p_give(void)
+int do_give_money(char *id, int uid, int money)
{
- int money, tax;
- char id[IDLEN + 1], money_buf[20];
+ int tax;
#ifdef PLAY_ANGEL
userec_t xuser;
#endif
- move(1, 0);
- usercomplete("這位幸運兒的id:", id);
- if (!id[0] || !strcmp(cuser.userid, id) ||
- !getdata(2, 0, "要給多少錢:", money_buf, 7, LCECHO))
- return 0;
- money = atoi(money_buf);
reload_money();
if (money > 0 && cuser.money >= money) {
tax = give_tax(money);
if (money - tax <= 0)
- return 0; /* 繳完稅就沒錢給了 */
- deumoney(searchuser(id, id), money - tax); // TODO if searchuser(id) return 0
+ return -1; /* 繳完稅就沒錢給了 */
+ deumoney(uid, money - tax);
demoney(-money);
log_file(FN_MONEY, LOG_CREAT | LOG_VF, "%-12s 給 %-12s %d\t(稅後 %d)\t%s",
cuser.userid, id, money, money - tax, ctime4(&now));
@@ -430,8 +422,29 @@ p_give(void)
#endif
mail_redenvelop(cuser.userid, id, money - tax,
getans("要自行書寫紅包袋嗎?[y/N]"));
+ return 0;
}
- return 0;
+ return -1;
+}
+
+int
+p_give(void)
+{
+ int uid;
+ char id[IDLEN + 1], money_buf[20];
+
+ move(1, 0);
+ usercomplete("這位幸運兒的id:", id);
+ if (!id[0] || !strcmp(cuser.userid, id) ||
+ !getdata(2, 0, "要給多少錢:", money_buf, 7, LCECHO)) {
+ vmsg("交易取消!");
+ return -1;
+ }
+ if ((uid = searchuser(id, id)) == 0) {
+ vmsg("查無此人!");
+ return -1;
+ }
+ return do_give_money(id, uid, atoi(money_buf));
}
int
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index 06a366da..bcf16cf0 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -2657,21 +2657,10 @@ userlist(void)
redrawall = redraw = 1;
break;
}
- reload_money();
-
- if (ch > cuser.money) {
- outs(ANSI_COLOR(41) " 現金不足~~" ANSI_RESET);
- } else {
- deumoney(uentp->uid, ch - give_tax(ch));
- log_file(FN_MONEY, LOG_CREAT | LOG_VF,
- "%s\t給%s\t%d\t(稅後 %d)\t%s\n", cuser.userid,
- uentp->userid, ch,
- ch-give_tax(ch),
- ctime4(&currutmp->lastact));
- mail_redenvelop(cuser.userid, uentp->userid,
- ch - give_tax(ch), 'Y');
- vmsgf(" 嗯..還剩下 %d 錢..", demoney(-ch));
- }
+ if (do_give_money(uentp->userid, uentp->uid, ch) < 0)
+ vmsgf("交易失敗,還剩下 %d 錢", SHM->money[usernum - 1]);
+ else
+ vmsgf("交易成功\,還剩下 %d 錢", SHM->money[usernum - 1]);
} else {
clrtoeol();
vmsg(" 交易取消! ");