diff options
-rw-r--r-- | pttbbs/include/proto.h | 2 | ||||
-rw-r--r-- | pttbbs/mbbsd/cal.c | 94 | ||||
-rw-r--r-- | pttbbs/mbbsd/chicken.c | 13 | ||||
-rw-r--r-- | pttbbs/mbbsd/gamble.c | 26 | ||||
-rw-r--r-- | pttbbs/mbbsd/menu.c | 2 |
5 files changed, 101 insertions, 36 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 77895399..0838f2e5 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -124,6 +124,8 @@ const char * postperm_msg(const char *bname); /* cal */ const char* money_level(int money); int vice(int money, const char* item); +int pay(int money, const char *item, ...); +int pay_as(int uid, int money, const char *item, ...); int lockutmpmode(int unmode, int state); int unlockutmpmode(void); int x_file(void); diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 2686ba5e..9956e24f 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -57,28 +57,82 @@ unlockutmpmode(void) return 0; } -/* 使用錢的函數 */ -#define VICE_NEW "vice.new" - -/* Heat:發票 */ -int -vice(int money, const char *item) -{ - char buf[128]; - unsigned int viceserial = (currutmp->lastact % 10000) * 10000 + - random() % 10000; +static int +do_pay(int uid, int money, const char *item, const char *reason) +{ + int oldm, newm; + const char *userid; + + assert(money != 0); + userid = getuserid(uid); + assert(userid); + assert(reason); + + // if we cannot find user, abort + if (!userid) + return -1; + + oldm = moneyof(uid); + newm = deumoney(uid, -money); + if (uid == usernum) + reload_money(); + +#ifdef FN_RECENTVICE + + char buf[PATHLEN]; + sethomefile(buf, userid, FN_RECENTVICE); + rotate_text_logfile(buf, SZ_RECENTVICE, 0.2); + syncnow(); + log_filef(buf, LOG_CREAT, "%s %s $%d ($%d => $%d) %s\n", + Cdatelite(&now), + money >= 0 ? "支出" : "收入", + money >= 0 ? money : -money, + oldm, newm, reason); +#endif - // new logic: do not send useless vice tickets - demoney(-money); - if (money < VICE_MIN) - return 0; + return newm; +} + +int +pay_as(int uid, int money, const char *item, ...) +{ + va_list ap; + char reason[STRLEN*3] =""; + + if (!money) + return 0; + + if (item) { + va_start(ap, item); + vsnprintf(reason, sizeof(reason)-1, item, ap); + va_end(ap); + } + + return do_pay(uid, money, item, reason); +} + +int +pay(int money, const char *item, ...) +{ + va_list ap; + char reason[STRLEN*3] =""; + + if (!money) + return 0; + + if (item) { + va_start(ap, item); + vsnprintf(reason, sizeof(reason)-1, item, ap); + va_end(ap); + } + + return do_pay(usernum, money, item, reason); +} - setuserfile(buf, VICE_NEW); - log_filef(buf, LOG_CREAT, "%8.8d\n", viceserial); - snprintf(buf, sizeof(buf), - "%s 花了$%d 編號[%08d]", item, money, viceserial); - mail_id(cuser.userid, buf, "etc/vice.txt", BBSMNAME "經濟部"); - return 0; +// compatible mode: vice +int +vice(int money, const char *item) { + return pay(money, item); } static int diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index e5d74b06..42ef48b5 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -455,7 +455,7 @@ ch_hit(chicken_t *mychicken) //static void -ch_buyitem(int money, const char *picture, int *item, int haveticket) +ch_buyitem(int money, const char *picture, int *item) { int num = 0; char buf[5]; @@ -468,10 +468,7 @@ ch_buyitem(int money, const char *picture, int *item, int haveticket) reload_money(); if (cuser.money/money >= num) { *item += num; - if( haveticket ) - vice(money * num, "購買寵物"); - else - demoney(-money * num); + vice(money * num, "購買寵物"); show_chicken_picture(picture); pressanykey(); } else { @@ -817,7 +814,7 @@ select_menu(int age GCC_UNUSED, chicken_t *mychicken) break; case '7': ch_buyitem(food_price[(int)mychicken->type], CHICKEN_PIC "/food", - &mychicken->food, 1); + &mychicken->food); break; case '8': ch_eatoo(mychicken); @@ -827,11 +824,11 @@ select_menu(int age GCC_UNUSED, chicken_t *mychicken) break; case 'O': case 'o': - ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo, 1); + ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo); break; case 'M': case 'm': - ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine, 1); + ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine); break; case 'N': case 'n': diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 87848f5a..b275d02d 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -138,7 +138,8 @@ append_ticket_record(const char *direct, int ch, int n, int count) } void -buy_ticket_ui(int money, const char *picture, int *item, int haveticket) +buy_ticket_ui(int money, const char *picture, int *item, + int type, const char *title) { int num = 0; char buf[5]; @@ -157,10 +158,11 @@ buy_ticket_ui(int money, const char *picture, int *item, int haveticket) } *item += num; - if( haveticket ) - vice(money * num, "賭盤項目"); - else - demoney(-money * num); + + // TODO uncomment this when we enable detail logs someday + // vice(money * num, "%s賭盤[種類%d,張數%d]", title, type+1, num); + demoney(-money * num); + // XXX magic numbers 5, 14... show_file(picture, 5, 14, SHOWFILE_ALLOW_ALL); pressanykey(); @@ -213,7 +215,8 @@ ticket(int bid) continue; n = 0; - buy_ticket_ui(price, "etc/buyticket", &n, 0); + buy_ticket_ui(price, "etc/buyticket", &n, ch, + bh ? bh->brdname : BBSMNAME); if (bid && !dashf(fn_ticket)) goto doesnt_catch_up; @@ -229,8 +232,12 @@ ticket(int bid) doesnt_catch_up: price = price * n; - if (price > 0) + // XXX 這是因為停止下注所以退錢? 感覺好危險+race condition + if (price > 0) { + // TODO enable this for detail log + // vice_to(currutmp->uid, -price, "下注失敗退費"); deumoney(currutmp->uid, price); + } vmsg("板主已經停止下注了 不能賭嚕"); unlockutmpmode(); return -1; @@ -328,7 +335,10 @@ openticket(int bid) forBM = money * 0.0005; if(forBM > 500) forBM = 500; + // XXX enable this for detail log + // vice(-forBM, "%s 賭場抽頭", bh->brdname); demoney(forBM); + mail_redenvelop("[賭場抽頭]", cuser.userid, forBM, NULL); money = ticket[bet] ? money * 0.95 / ticket[bet] : 9999999; } else { @@ -395,6 +405,8 @@ openticket(int bid) continue; if ((uid = searchuser(userid, userid)) == 0) continue; + // XXX enable this for detail log + // vice_to(uid, -(money * i), BBSMNAME "賭場 - 彩票[%s]", betname[mybet]); deumoney(uid, money * i); mail_id(userid, buf, "etc/ticket.win", BBSMNAME "賭場"); } diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index d18057ac..58791b3e 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -674,7 +674,7 @@ static const commands_t userlist[] = { {u_customize, PERM_BASIC, "UUCustomize 個人化設定"}, {u_info, PERM_LOGINOK, "IInfo 設定個人資料與密碼"}, {calendar, PERM_LOGINOK, "CCalendar 行事曆"}, - {u_loginview, PERM_BASIC, "VVLogin View 選擇進站畫面"}, + {u_loginview, PERM_BASIC, "VVLogin View 選擇進站畫面"}, {u_myfiles, PERM_LOGINOK, "MMy Files 【個人檔案】 (名片,簽名檔...)"}, {u_mylogs, PERM_LOGINOK, "LLMy Logs 【個人記錄】 (最近上線...)"}, {u_cloak, PERM_LOGINOK, "KKCloak 隱身術"}, |